|
|
@@ -515,16 +515,24 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
return capacity.get();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
+ /* @Override
|
|
|
public Map<Long, BigDecimal> queryCapacities(List<Long> deptIds) {
|
|
|
Map<Long, BigDecimal> capacityPair = new HashMap<>();
|
|
|
// 找到当前小队下的 电驱增压机 分类下设备的产能 计算 运行时效
|
|
|
DictTypeDO dictType = dictTypeService.getDictType("rq_iot_charger_device_category");
|
|
|
if (ObjUtil.isNotEmpty(dictType)) {
|
|
|
if (StrUtil.isNotBlank(dictType.getRemark())) {
|
|
|
+ // 可能统计多个设备的产能 remark 是逗号分隔的数据
|
|
|
+ List<Long> deviceCategoryIdLongs = Arrays.stream(dictType.getRemark().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(s -> s.matches("\\d+")) // 过滤出纯数字字符串
|
|
|
+ .map(Long::valueOf)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ // 查询队伍下维护了产能的已知类别的设备 累加所有产能
|
|
|
IotDevicePageReqVO capacityReqVO = new IotDevicePageReqVO();
|
|
|
capacityReqVO.setDeptIds(deptIds);
|
|
|
- capacityReqVO.setAssetClass(Long.valueOf(dictType.getRemark()));
|
|
|
+ // capacityReqVO.setAssetClass(Long.valueOf(dictType.getRemark()));
|
|
|
+ capacityReqVO.setAssetClasses(deviceCategoryIdLongs);
|
|
|
List<IotDeviceDO> capacityDevices = iotDeviceMapper.selectList(capacityReqVO);
|
|
|
if (CollUtil.isNotEmpty(capacityDevices)) {
|
|
|
// 解析每个设备的 扩展属性 找出 已经设置 了产能的设备并提取值
|
|
|
@@ -544,13 +552,99 @@ public class IotRhDailyReportServiceImpl implements IotRhDailyReportService {
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
+ // 如果相同的部门下有多个设备维护过产能 累加所有设备的产能
|
|
|
+
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return capacityPair;
|
|
|
+ } */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询队伍下设备产能
|
|
|
+ * @param deptIds
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<Long, BigDecimal> queryCapacities(List<Long> deptIds) {
|
|
|
+ Map<Long, BigDecimal> capacityPair = new HashMap<>();
|
|
|
+
|
|
|
+ // 找到当前小队下的 电驱增压机 分类下设备的产能 计算 运行时效
|
|
|
+ DictTypeDO dictType = dictTypeService.getDictType("rq_iot_charger_device_category");
|
|
|
+ if (ObjUtil.isNotEmpty(dictType) && StrUtil.isNotBlank(dictType.getRemark())) {
|
|
|
+ // 可能统计多个设备的产能 remark 是逗号分隔的数据
|
|
|
+ List<Long> deviceCategoryIdLongs = Arrays.stream(dictType.getRemark().split(","))
|
|
|
+ .map(String::trim)
|
|
|
+ .filter(s -> s.matches("\\d+")) // 过滤出纯数字字符串
|
|
|
+ .map(Long::valueOf)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 查询队伍下维护了产能的已知类别的设备
|
|
|
+ IotDevicePageReqVO capacityReqVO = new IotDevicePageReqVO();
|
|
|
+ capacityReqVO.setDeptIds(deptIds);
|
|
|
+ capacityReqVO.setAssetClasses(deviceCategoryIdLongs);
|
|
|
+
|
|
|
+ List<IotDeviceDO> capacityDevices = iotDeviceMapper.selectList(capacityReqVO);
|
|
|
+
|
|
|
+ if (CollUtil.isNotEmpty(capacityDevices)) {
|
|
|
+ // 使用Map按部门分组累加产能
|
|
|
+ Map<Long, List<IotDeviceDO>> devicesByDept = capacityDevices.stream()
|
|
|
+ .collect(Collectors.groupingBy(IotDeviceDO::getDeptId));
|
|
|
+
|
|
|
+ // 遍历每个部门的设备列表
|
|
|
+ for (Map.Entry<Long, List<IotDeviceDO>> entry : devicesByDept.entrySet()) {
|
|
|
+ Long deptId = entry.getKey();
|
|
|
+ List<IotDeviceDO> deptDevices = entry.getValue();
|
|
|
+
|
|
|
+ // 累加当前部门下所有设备的产能
|
|
|
+ BigDecimal deptTotalCapacity = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ for (IotDeviceDO device : deptDevices) {
|
|
|
+ BigDecimal deviceCapacity = extractCapacityFromDevice(device);
|
|
|
+ deptTotalCapacity = deptTotalCapacity.add(deviceCapacity);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将部门总产能放入结果Map
|
|
|
+ capacityPair.put(deptId, deptTotalCapacity);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return capacityPair;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 从设备中提取产能值
|
|
|
+ */
|
|
|
+ private BigDecimal extractCapacityFromDevice(IotDeviceDO device) {
|
|
|
+ if (StrUtil.isBlank(device.getTemplateJson())) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Gson gson = new Gson();
|
|
|
+ Type listType = new TypeToken<List<IotDeviceProperty>>(){}.getType();
|
|
|
+ List<IotDeviceProperty> deviceProperties = gson.fromJson(device.getTemplateJson(), listType);
|
|
|
+
|
|
|
+ if (CollUtil.isEmpty(deviceProperties)) {
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查找产能属性并返回其值
|
|
|
+ return deviceProperties.stream()
|
|
|
+ .filter(property -> "产能".equals(property.getName()))
|
|
|
+ .filter(property -> StrUtil.isNotBlank(property.getValue()))
|
|
|
+ .findFirst() // 假设每个设备只有一个产能属性,如果有多个可以改为求和
|
|
|
+ .map(property -> new BigDecimal(property.getValue()))
|
|
|
+ .orElse(BigDecimal.ZERO);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 解析JSON失败时返回0
|
|
|
+ System.out.println("{} 解析设备模板JSON失败,设备ID: {}" + e.getMessage());
|
|
|
+ return BigDecimal.ZERO;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
@Override
|
|
|
public PageResult<IotRhDailyReportDO> dailyReportSummary(IotRhDailyReportPageReqVO pageReqVO) {
|