|
@@ -11,6 +11,8 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
|
|
import cn.iocoder.yudao.module.pms.ThingsModelDTO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.TableDataInfo;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotdevicerunlog.vo.IotDeviceRunLogRespVO;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.iotmodeltemplateattrs.vo.IotModelTemplateAttrsPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceSaveReqVO;
|
|
@@ -18,13 +20,17 @@ import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotInfoClassifyDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotTreeDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmodel.IotModelDO;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotInfoClassifyMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.IotTreeMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.TDDeviceMapper;
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.iotdevicerunlog.IotDeviceRunLogMapper;
|
|
|
import cn.iocoder.yudao.module.pms.dal.mysql.iotmodel.IotModelMapper;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotbom.IotBomService;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotdevicebom.IotDeviceBomService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotdevicerunlog.IotDeviceRunLogService;
|
|
|
+import cn.iocoder.yudao.module.pms.service.iotmodeltemplateattrs.IotModelTemplateAttrsService;
|
|
|
import cn.iocoder.yudao.module.pms.service.yanfan.ThingsModelService;
|
|
|
import cn.iocoder.yudao.module.pms.service.yanfan.YfDeviceService;
|
|
|
import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
|
|
@@ -85,6 +91,12 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|
|
private String yanfanUrl;
|
|
|
@Autowired
|
|
|
private IotDeviceBomService iotDeviceBomService;
|
|
|
+ @Resource
|
|
|
+ private IotModelTemplateAttrsService iotModelTemplateAttrsService;
|
|
|
+ @Resource
|
|
|
+ private IotDeviceRunLogService iotDeviceRunLogService;
|
|
|
+ @Resource
|
|
|
+ private IotDeviceRunLogMapper iotDeviceRunLogMapper;
|
|
|
|
|
|
@Override
|
|
|
public List<IotDeviceDO> getMapDevice() {
|
|
@@ -357,21 +369,124 @@ public class IotDeviceServiceImpl implements IotDeviceService {
|
|
|
@Override
|
|
|
public List<IotDeviceRespVO> deviceAssociateBomList(IotDevicePageReqVO pageReqVO) {
|
|
|
List<IotDeviceRespVO> devices = iotDeviceMapper.deviceAssociateBomList(pageReqVO.getDeviceIds(), pageReqVO.getBomFlag());
|
|
|
+ // 调整 累计运行时间 累计运行里程 的逻辑 模板属性中涉及多个累计运行时长 累计运行里程 的 这里不需要赋值
|
|
|
+ // 查询所有设备的设备分类
|
|
|
+ // 查询设备分类对应的运行记录模板中的多个累计类型的属性列表(匹配相应的累计运行时长 累计运行里程的值)
|
|
|
+ Set<Long> deviceCategoryIds = new HashSet<>();
|
|
|
+ // 设备id集合 根据设备id查询所有正常的 累计时长 累计公里数
|
|
|
+ Set<Long> deviceIds = new HashSet<>();
|
|
|
+ // 运行记录模板中涉及多个累计时长 公里数属性的设备id集合
|
|
|
+ Set<Long> multipleAttrDeviceIds = new HashSet<>();
|
|
|
+ // 运行记录模板中涉及多个累计时长 公里数属性名称集合
|
|
|
+ Set<String> multipleAttrNames = new HashSet<>();
|
|
|
+ // 设备对应的设备分类 key设备id value设备分类id
|
|
|
+ Map<Long, Long> deviceCategoryPair = new HashMap<>();
|
|
|
+ // k设备id v设备分类包含的模板中与累计运行时长、累计运行公里数相关的属性集合
|
|
|
+ Map<Long, List<IotModelTemplateAttrsDO>> deviceAttrsPair = new HashMap<>();
|
|
|
// 查询所有 设备boms节点的所有上级节点名称 拼接出 全路径 的bom节点
|
|
|
List<Long> bomNodeIds = new ArrayList<>();
|
|
|
+ // key设备id value设备对应的运行记录模板中涉及多个累计时长累计公里数的属性集合
|
|
|
+ Map<Long, List<IotDeviceRunLogRespVO>> deviceRunLogPair = new HashMap<>();
|
|
|
if (CollUtil.isNotEmpty(devices)) {
|
|
|
+ // 设备运行模板中正常的 累计时长 累计里程 集合
|
|
|
+ Map<Long, IotDeviceRunLogRespVO> deviceRunLogMap = new HashMap<>();
|
|
|
devices.forEach(device -> {
|
|
|
+ deviceIds.add(device.getId());
|
|
|
bomNodeIds.add(Long.valueOf(device.getBomNodeId()));
|
|
|
+ deviceCategoryIds.add(device.getAssetClass());
|
|
|
+ deviceCategoryPair.put(device.getId(), device.getAssetClass());
|
|
|
});
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(deviceCategoryIds)) {
|
|
|
+ // 查询设备分类id集合对应的运行记录模板中涉及 累计运行时长、累计运行公里数 的属性
|
|
|
+ IotModelTemplateAttrsPageReqVO reqVO = new IotModelTemplateAttrsPageReqVO();
|
|
|
+ reqVO.setMultipleFlag("Y");
|
|
|
+ reqVO.setDeviceCategoryIds(new ArrayList<>(deviceCategoryIds));
|
|
|
+ reqVO.setIsSum(1); // 累计属性标识
|
|
|
+ List<IotModelTemplateAttrsDO> accumulatedAttrs = iotModelTemplateAttrsService.getIotDeviceTemplateAttrs(reqVO);
|
|
|
+ // k设备分类id v设备分类包含的模板中 多个 累计运行时长 累计运行公里数相关的属性集合
|
|
|
+ Map<Long, List<IotModelTemplateAttrsDO>> accumulatedAttrPair = new HashMap<>();
|
|
|
+ if (CollUtil.isNotEmpty(accumulatedAttrs)) {
|
|
|
+ accumulatedAttrs.forEach(attr -> {
|
|
|
+ if (accumulatedAttrPair.containsKey(attr.getDeviceCategoryId())) {
|
|
|
+ List<IotModelTemplateAttrsDO> tempAttrs = accumulatedAttrPair.get(attr.getDeviceCategoryId());
|
|
|
+ tempAttrs.add(attr);
|
|
|
+ accumulatedAttrPair.put(attr.getDeviceCategoryId(), tempAttrs);
|
|
|
+ } else {
|
|
|
+ List<IotModelTemplateAttrsDO> tempAttrs = new ArrayList<>();
|
|
|
+ tempAttrs.add(attr);
|
|
|
+ accumulatedAttrPair.put(attr.getDeviceCategoryId(), tempAttrs);
|
|
|
+ }
|
|
|
+ multipleAttrNames.add(attr.getName());
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (CollUtil.isNotEmpty(accumulatedAttrPair)) {
|
|
|
+ accumulatedAttrPair.forEach((k,v) -> {
|
|
|
+ // k设备分类id v设备分类包含的模板中 多个累计运行时长 累计运行公里数 相关的属性集合
|
|
|
+ deviceCategoryPair.forEach((ik, iv) -> {
|
|
|
+ // ik设备id iv设备分类id
|
|
|
+ if (iv.equals(k)) {
|
|
|
+ // key设备id value设备分类包含的模板中 多个累计运行时长 累计运行公里数 相关的属性集合
|
|
|
+ deviceAttrsPair.put(ik, v);
|
|
|
+ multipleAttrDeviceIds.add(ik);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ // 根据设备id集合查询正常的 累计时长 累计公里数
|
|
|
+ deviceRunLogMap = iotDeviceRunLogService.getDeviceRunLogMap(new ArrayList<>(deviceIds));
|
|
|
+
|
|
|
+ // 根据设备id 运行记录模板属性名称 查询对应的 累计运行时长 累计运行公里数
|
|
|
+ if (CollUtil.isNotEmpty(multipleAttrDeviceIds) && CollUtil.isNotEmpty(multipleAttrNames)) {
|
|
|
+ List<IotDeviceRunLogRespVO> accumulatedData = iotDeviceRunLogMapper.multipleAccumulatedData(multipleAttrDeviceIds, multipleAttrNames);
|
|
|
+ // 组装每个设备对应的属性 累计时长 累计里程 集合
|
|
|
+ if (CollUtil.isNotEmpty(accumulatedData)) {
|
|
|
+ accumulatedData.forEach(data -> {
|
|
|
+ if (deviceRunLogPair.containsKey(data.getDeviceId())) {
|
|
|
+ List<IotDeviceRunLogRespVO> tempRunLogs = deviceRunLogPair.get(data.getDeviceId());
|
|
|
+ tempRunLogs.add(data);
|
|
|
+ deviceRunLogPair.put(data.getDeviceId(), tempRunLogs);
|
|
|
+ } else {
|
|
|
+ List<IotDeviceRunLogRespVO> tempRunLogs = new ArrayList<>();
|
|
|
+ tempRunLogs.add(data);
|
|
|
+ deviceRunLogPair.put(data.getDeviceId(), tempRunLogs);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 查询 bomNodeIds 集合中每个bom节点的所有上级节点
|
|
|
Map<Long, String> bomFullPaths = iotDeviceBomService.buildBomFullPaths(bomNodeIds);
|
|
|
+ Map<Long, IotDeviceRunLogRespVO> finalDeviceRunLogMap = deviceRunLogMap;
|
|
|
devices.forEach(device -> {
|
|
|
if (bomFullPaths.containsKey(Long.valueOf(device.getBomNodeId()))) {
|
|
|
if (StrUtil.isNotBlank(bomFullPaths.get(Long.valueOf(device.getBomNodeId())))) {
|
|
|
device.setName(bomFullPaths.get(Long.valueOf(device.getBomNodeId())));
|
|
|
}
|
|
|
}
|
|
|
+ if (deviceRunLogPair.containsKey(device.getId())) {
|
|
|
+ // 区分开 时间 里程 的累计属性列表 便于前端选择
|
|
|
+ List<IotDeviceRunLogRespVO> mileageRunLogs = new ArrayList<>();
|
|
|
+ List<IotDeviceRunLogRespVO> timeRunLogs = deviceRunLogPair.get(device.getId());
|
|
|
+ timeRunLogs.forEach(log -> {
|
|
|
+ log.setType(1);
|
|
|
+ IotDeviceRunLogRespVO tempRunLog = new IotDeviceRunLogRespVO();
|
|
|
+ BeanUtils.copyProperties(log, tempRunLog);
|
|
|
+ tempRunLog.setType(2);
|
|
|
+ mileageRunLogs.add(tempRunLog);
|
|
|
+ });
|
|
|
+ device.setTimeAccumulatedAttrs(timeRunLogs);
|
|
|
+ device.setMileageAccumulatedAttrs(mileageRunLogs);
|
|
|
+ }
|
|
|
+ // 这里只赋值正常的 累计时长 累计公里数 多个累计属性的需要在保养配置中选择
|
|
|
+ if (CollUtil.isNotEmpty(finalDeviceRunLogMap) && finalDeviceRunLogMap.containsKey(device.getId())) {
|
|
|
+ IotDeviceRunLogRespVO tempRunLog = finalDeviceRunLogMap.get(device.getId());
|
|
|
+ device.setTotalRunTime(tempRunLog.getTotalRunTime());
|
|
|
+ device.setTotalMileage(tempRunLog.getTotalMileage());
|
|
|
+ }
|
|
|
});
|
|
|
+
|
|
|
}
|
|
|
return devices;
|
|
|
}
|