|
|
|
|
@ -6,7 +6,9 @@ import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
|
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
@ -23,7 +25,6 @@ import org.dromara.rfid.helper.RfidReadRecordTableHelper;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -61,7 +62,7 @@ public class RfidDeviceServiceImpl implements IRfidDeviceService {
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public TableDataInfo<RfidDeviceVo> queryPageList(RfidDeviceBo bo, PageQuery pageQuery) {
|
|
|
|
|
LambdaQueryWrapper<RfidDevice> lqw = buildQueryWrapper(bo);
|
|
|
|
|
Wrapper<RfidDevice> lqw = buildQueryWrapper(bo);
|
|
|
|
|
// 使用自定义 Mapper XML + MyBatis-Plus Wrapper 进行分页查询
|
|
|
|
|
Page<RfidDeviceVo> result = baseMapper.selectCustomRfidDeviceVoPage(pageQuery.build(), lqw);
|
|
|
|
|
return TableDataInfo.build(result);
|
|
|
|
|
@ -75,7 +76,7 @@ public class RfidDeviceServiceImpl implements IRfidDeviceService {
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public List<RfidDeviceVo> queryList(RfidDeviceBo bo) {
|
|
|
|
|
LambdaQueryWrapper<RfidDevice> lqw = buildQueryWrapper(bo);
|
|
|
|
|
Wrapper<RfidDevice> lqw = buildQueryWrapper(bo);
|
|
|
|
|
// 使用自定义 Mapper XML + MyBatis-Plus Wrapper 查询列表
|
|
|
|
|
return baseMapper.selectCustomRfidDeviceVoList(lqw);
|
|
|
|
|
}
|
|
|
|
|
@ -94,28 +95,50 @@ public class RfidDeviceServiceImpl implements IRfidDeviceService {
|
|
|
|
|
return baseMapper.countCustomRfidDevice(wrapper);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private LambdaQueryWrapper<RfidDevice> buildQueryWrapper(RfidDeviceBo bo) {
|
|
|
|
|
Map<String, Object> params = bo.getParams();
|
|
|
|
|
LambdaQueryWrapper<RfidDevice> lqw = Wrappers.lambdaQuery();
|
|
|
|
|
lqw.orderByAsc(RfidDevice::getId);
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getDeviceCode()), RfidDevice::getDeviceCode, bo.getDeviceCode());
|
|
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getDeviceName()), RfidDevice::getDeviceName, bo.getDeviceName());
|
|
|
|
|
lqw.eq(bo.getLocationId() != null, RfidDevice::getLocationId, bo.getLocationId());
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getDeviceAddress()), RfidDevice::getDeviceAddress, bo.getDeviceAddress());
|
|
|
|
|
lqw.eq(bo.getDevicePort() != null, RfidDevice::getDevicePort, bo.getDevicePort());
|
|
|
|
|
lqw.eq(bo.getReadFrequency() != null, RfidDevice::getReadFrequency, bo.getReadFrequency());
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getOnlineStatus()), RfidDevice::getOnlineStatus, bo.getOnlineStatus());
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getAlarmStatus()), RfidDevice::getAlarmStatus, bo.getAlarmStatus());
|
|
|
|
|
if (StringUtils.isNotBlank(bo.getIsMarked())) {
|
|
|
|
|
lqw.apply("t.is_marked = {0}", bo.getIsMarked());
|
|
|
|
|
}
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getCreatedBy()), RfidDevice::getCreatedBy, bo.getCreatedBy());
|
|
|
|
|
lqw.eq(bo.getCreatedAt() != null, RfidDevice::getCreatedAt, bo.getCreatedAt());
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getUpdatedBy()), RfidDevice::getUpdatedBy, bo.getUpdatedBy());
|
|
|
|
|
lqw.eq(bo.getUpdatedAt() != null, RfidDevice::getUpdatedAt, bo.getUpdatedAt());
|
|
|
|
|
private Wrapper<RfidDevice> buildQueryWrapper(RfidDeviceBo bo) {
|
|
|
|
|
QueryWrapper<RfidDevice> lqw = Wrappers.query();
|
|
|
|
|
lqw.orderByAsc("t.id");
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getDeviceCode()), "t.device_code", bo.getDeviceCode());
|
|
|
|
|
lqw.like(StringUtils.isNotBlank(bo.getDeviceName()), "t.device_name", bo.getDeviceName());
|
|
|
|
|
appendLocationScopeCondition(lqw, bo.getLocationId());
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getDeviceAddress()), "t.device_address", bo.getDeviceAddress());
|
|
|
|
|
lqw.eq(bo.getDevicePort() != null, "t.device_port", bo.getDevicePort());
|
|
|
|
|
lqw.eq(bo.getReadFrequency() != null, "t.read_frequency", bo.getReadFrequency());
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getOnlineStatus()), "t.online_status", bo.getOnlineStatus());
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getAlarmStatus()), "t.alarm_status", bo.getAlarmStatus());
|
|
|
|
|
// 设备表与位置表都有 is_marked 字段,显式指定 t 别名,避免连表查询出现歧义。
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getIsMarked()), "t.is_marked", bo.getIsMarked());
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getCreatedBy()), "t.created_by", bo.getCreatedBy());
|
|
|
|
|
lqw.eq(bo.getCreatedAt() != null, "t.created_at", bo.getCreatedAt());
|
|
|
|
|
lqw.eq(StringUtils.isNotBlank(bo.getUpdatedBy()), "t.updated_by", bo.getUpdatedBy());
|
|
|
|
|
lqw.eq(bo.getUpdatedAt() != null, "t.updated_at", bo.getUpdatedAt());
|
|
|
|
|
return lqw;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 追加位置范围筛选。
|
|
|
|
|
* <p>
|
|
|
|
|
* 设备只绑定到 3-工位;左侧树点到 1-车间或 2-工序时,需要展开到其所有叶子工位,
|
|
|
|
|
* 避免按父节点 id 精确匹配导致列表为空。
|
|
|
|
|
*/
|
|
|
|
|
private void appendLocationScopeCondition(QueryWrapper<RfidDevice> lqw, Long locationId) {
|
|
|
|
|
if (locationId == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
lqw.and(wrapper -> wrapper
|
|
|
|
|
.eq("t.location_id", locationId)
|
|
|
|
|
.or()
|
|
|
|
|
.apply("""
|
|
|
|
|
exists (
|
|
|
|
|
select 1
|
|
|
|
|
from rfid_location leaf
|
|
|
|
|
where leaf.id = t.location_id
|
|
|
|
|
and leaf.location_type = '3'
|
|
|
|
|
and find_in_set({0}, leaf.ancestors) > 0
|
|
|
|
|
)
|
|
|
|
|
""", locationId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 新增设备信息
|
|
|
|
|
*
|
|
|
|
|
@ -153,14 +176,14 @@ public class RfidDeviceServiceImpl implements IRfidDeviceService {
|
|
|
|
|
*/
|
|
|
|
|
private void validEntityBeforeSave(RfidDevice entity){
|
|
|
|
|
// 业务编号 deviceCode 唯一校验
|
|
|
|
|
// if (StringUtils.isNotBlank(entity.getDeviceCode())) {
|
|
|
|
|
// boolean exists = baseMapper.existsRfidDevice(Wrappers.<RfidDevice>lambdaQuery()
|
|
|
|
|
// .eq(RfidDevice::getDeviceCode, entity.getDeviceCode())
|
|
|
|
|
// .ne(entity.getId() != null, RfidDevice::getId, entity.getId()));
|
|
|
|
|
// if (exists) {
|
|
|
|
|
// throw new ServiceException("设备编号已存在");
|
|
|
|
|
// }
|
|
|
|
|
// }
|
|
|
|
|
if (StringUtils.isNotBlank(entity.getDeviceCode())) {
|
|
|
|
|
boolean exists = baseMapper.existsRfidDevice(Wrappers.<RfidDevice>lambdaQuery()
|
|
|
|
|
.eq(RfidDevice::getDeviceCode, entity.getDeviceCode())
|
|
|
|
|
.ne(entity.getId() != null, RfidDevice::getId, entity.getId()));
|
|
|
|
|
if (exists) {
|
|
|
|
|
throw new ServiceException("设备编号已存在");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IP地址 deviceAddress 唯一校验
|
|
|
|
|
if (StringUtils.isNotBlank(entity.getDeviceAddress())) {
|
|
|
|
|
|