|
|
@@ -1,6 +1,7 @@
|
|
|
package cn.iocoder.yudao.module.pms.service;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.ObjUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
|
|
|
import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
@@ -543,25 +544,50 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|
|
|
|
|
@Override
|
|
|
public List<IotDeviceDO> getDevicesByDepts(IotDevicePageReqVO reqVO) {
|
|
|
+ if (ObjUtil.isEmpty(reqVO)) {
|
|
|
+ throw new ServiceException(IOT_DEPT_NOT_SELECTED);
|
|
|
+ }
|
|
|
// 如果 reqVO.getDeptIds 有值 就是根据选择的部门 查询部门下所有设备
|
|
|
// 考虑到设备调拨的情况 可以修改 成查询所选部门所属公司下所有设备
|
|
|
if (CollUtil.isEmpty(reqVO.getDeviceIds()) && CollUtil.isEmpty(reqVO.getDeptIds())) {
|
|
|
throw new ServiceException(IOT_DEPT_NOT_SELECTED);
|
|
|
}
|
|
|
+ List<IotDeviceDO> rdDevices = new ArrayList<>();
|
|
|
if (CollUtil.isNotEmpty(reqVO.getDeptIds())) {
|
|
|
// 查询选择的部门 选择的部门所属的公司 属于 瑞都 163l 则查询所有瑞都下的设备
|
|
|
+ // 但是 所选队伍 下的所有设备 需要显示在列表最上面
|
|
|
List<Long> deptIds = reqVO.getDeptIds();
|
|
|
Long randomDeptId = deptIds.get(0);
|
|
|
// 查询 瑞都下的所有 部门
|
|
|
Set<Long> childDeptIds = deptService.getChildDeptIdListFromCache(163l);
|
|
|
if (childDeptIds.contains(randomDeptId)) {
|
|
|
+ // 施工队伍 属于 瑞都 163l 则查询所有瑞都下的设备
|
|
|
reqVO.setDeptIds(new ArrayList<>(childDeptIds));
|
|
|
+ // 查询所选施工队伍下所有设备
|
|
|
+ IotDevicePageReqVO rdReqVO = new IotDevicePageReqVO();
|
|
|
+ rdReqVO.setDeptIds(deptIds);
|
|
|
+ rdDevices = iotDeviceMapper.selectSimpleList(rdReqVO, null);
|
|
|
}
|
|
|
}
|
|
|
AtomicReference<List<IotDeviceDO>> devices = new AtomicReference<>(new ArrayList<>());
|
|
|
// 忽略数据权限
|
|
|
+ List<IotDeviceDO> finalRdDevices = rdDevices;
|
|
|
DataPermissionUtils.executeIgnore(() -> {
|
|
|
- devices.set(iotDeviceMapper.selectSimpleList(reqVO, null));
|
|
|
+ List<IotDeviceDO> resultDevices = iotDeviceMapper.selectSimpleList(reqVO, null);
|
|
|
+ devices.set(resultDevices);
|
|
|
+ // 如果瑞都日报任务 将施工队伍所属设备显示到设备列表前面
|
|
|
+ if (CollUtil.isNotEmpty(resultDevices) && CollUtil.isNotEmpty(finalRdDevices)) {
|
|
|
+ // 提取 finalRdDevices 的id集合(快速判断)
|
|
|
+ Set<Long> rdDeviceIds = finalRdDevices.stream()
|
|
|
+ .map(IotDeviceDO::getId)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ // 排序:finalRdDevices 中的元素排前面,保持原有相对顺序
|
|
|
+ resultDevices.sort(Comparator.comparingInt(u -> rdDeviceIds.contains(u.getId()) ? 0 : 1));
|
|
|
+
|
|
|
+ // 更新结果集
|
|
|
+ devices.set(resultDevices);
|
|
|
+ }
|
|
|
});
|
|
|
return devices.get();
|
|
|
}
|