|
@@ -1,33 +1,23 @@
|
|
|
package cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill;
|
|
package cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill;
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
-import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
|
|
-import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
|
|
|
|
-import cn.iocoder.yudao.module.pms.controller.admin.iotmodel.vo.IotModelPageReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmodeltemplateattrs.vo.IotModelTemplateAttrsRespVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmodeltemplateattrs.vo.IotModelTemplateAttrsRespVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.*;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotopeationfill.vo.*;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrhdailyreport.vo.IotRhDailyReportSaveReqVO;
|
|
|
-import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportPageReqVO;
|
|
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportSaveReqVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotrydailyreport.vo.IotRyDailyReportSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.DeviceVO;
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.DeviceVO;
|
|
|
-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.IotDeviceRespVO;
|
|
|
-import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountDataDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountDataDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountListDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotcountdata.IotCountListDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicecountdata.IotDeviceCountData;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicecountdata.IotDeviceCountData;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotdevicerunlog.IotDeviceRunLogDO;
|
|
|
-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.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO1;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotModelTemplateAttrsDO1;
|
|
|
-import cn.iocoder.yudao.module.pms.dal.dataobject.iotmodeltemplateattrs.IotThingsModelDO;
|
|
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.iotopeationfill.IotOpeationFillOrderDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.YfDeviceDO;
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.yanfan.YfDeviceDO;
|
|
|
|
|
|
|
|
-import cn.iocoder.yudao.module.pms.enums.ErrorCodeConstant;
|
|
|
|
|
import cn.iocoder.yudao.module.pms.service.IDeviceService;
|
|
import cn.iocoder.yudao.module.pms.service.IDeviceService;
|
|
|
import cn.iocoder.yudao.module.pms.service.iotopeationfill.IotOpeationFillService;
|
|
import cn.iocoder.yudao.module.pms.service.iotopeationfill.IotOpeationFillService;
|
|
|
|
|
|
|
@@ -37,7 +27,7 @@ import cn.iocoder.yudao.module.pms.service.yanfan.YfDeviceService;
|
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
import com.aliyun.tea.utils.StringUtils;
|
|
import com.aliyun.tea.utils.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
-import lombok.Data;
|
|
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
@@ -49,7 +39,6 @@ import io.swagger.v3.oas.annotations.Parameter;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
|
|
|
import javax.annotation.security.PermitAll;
|
|
import javax.annotation.security.PermitAll;
|
|
|
-import javax.validation.constraints.*;
|
|
|
|
|
import javax.validation.*;
|
|
import javax.validation.*;
|
|
|
import javax.servlet.http.*;
|
|
import javax.servlet.http.*;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
@@ -60,6 +49,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
import java.time.LocalTime;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
|
@@ -80,6 +70,7 @@ import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
|
|
@RestController
|
|
@RestController
|
|
|
@RequestMapping("/rq/iot-opeation-fill")
|
|
@RequestMapping("/rq/iot-opeation-fill")
|
|
|
@Validated
|
|
@Validated
|
|
|
|
|
+@Slf4j
|
|
|
public class IotOpeationFillController {
|
|
public class IotOpeationFillController {
|
|
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
@@ -361,61 +352,7 @@ public class IotOpeationFillController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 处理累计逻辑
|
|
|
|
|
- */
|
|
|
|
|
- /*private void processSummationLogic(List<IotOpeationFillSaveReqVO> allFillData) {
|
|
|
|
|
- // 按modelId分组,便于查找
|
|
|
|
|
- Map<Long, List<IotOpeationFillSaveReqVO>> modelIdMap = allFillData.stream()
|
|
|
|
|
- .filter(fill -> fill.getModelId() != null)
|
|
|
|
|
- .collect(Collectors.groupingBy(IotOpeationFillSaveReqVO::getModelId));
|
|
|
|
|
-
|
|
|
|
|
- // 找出需要累计的数据
|
|
|
|
|
- List<IotOpeationFillSaveReqVO> sumDataList = allFillData.stream()
|
|
|
|
|
- .filter(fill -> {
|
|
|
|
|
- if (fill.getIsSum() != 1) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- String defaultValue = fill.getDefaultValue();
|
|
|
|
|
- // 同时检查null和空字符串
|
|
|
|
|
- if (defaultValue == null || defaultValue.isEmpty()) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 如果还需要排除纯空格的情况
|
|
|
|
|
- if (defaultValue.trim().isEmpty()) {
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return true;
|
|
|
|
|
- })
|
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
- for (IotOpeationFillSaveReqVO fill : sumDataList) {
|
|
|
|
|
- try {
|
|
|
|
|
- Long refModelId = Long.parseLong(fill.getDefaultValue());
|
|
|
|
|
- List<IotOpeationFillSaveReqVO> targetFills = modelIdMap.get(refModelId);
|
|
|
|
|
|
|
|
|
|
- if (CollectionUtils.isEmpty(targetFills)) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- for (IotOpeationFillSaveReqVO targetFill : targetFills) {
|
|
|
|
|
- if (fill.getSumId() == 1) {
|
|
|
|
|
- // 需要累加的情况
|
|
|
|
|
- processAccumulation(fill, targetFill);
|
|
|
|
|
- } else if (fill.getSumId() == 0) {
|
|
|
|
|
- // 直接赋值的情况
|
|
|
|
|
- fill.setTotalRunTime(new BigDecimal(targetFill.getFillContent()));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } catch (NumberFormatException e) {
|
|
|
|
|
- //log.warn("DefaultValue转换失败: {}", fill.getDefaultValue());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 处理累计逻辑(优化后:批量查询历史数据)
|
|
* 处理累计逻辑(优化后:批量查询历史数据)
|
|
@@ -428,9 +365,7 @@ public class IotOpeationFillController {
|
|
|
|
|
|
|
|
// 筛选需要累计的数据(不变)
|
|
// 筛选需要累计的数据(不变)
|
|
|
List<IotOpeationFillSaveReqVO> sumDataList = allFillData.stream()
|
|
List<IotOpeationFillSaveReqVO> sumDataList = allFillData.stream()
|
|
|
- .filter(fill -> 1 == fill.getIsSum()
|
|
|
|
|
- && StringUtils.isEmpty(fill.getDefaultValue())
|
|
|
|
|
- && StringUtils.isEmpty(fill.getDefaultValue().trim()))
|
|
|
|
|
|
|
+ .filter(fill -> 1 == fill.getIsSum())
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(sumDataList)) {
|
|
if (CollectionUtils.isEmpty(sumDataList)) {
|
|
@@ -592,23 +527,6 @@ public class IotOpeationFillController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 批量保存日志
|
|
|
|
|
- */
|
|
|
|
|
- /*private void batchSaveLogs(List<IotDeviceRunLogDO> logDOList) {
|
|
|
|
|
- for (IotDeviceRunLogDO log : logDOList) {
|
|
|
|
|
- IotDeviceRunLogDO existingData = iotOpeationFillService.reportData(log);
|
|
|
|
|
- if (existingData == null) {
|
|
|
|
|
- iotOpeationFillService.insertLog1(log);
|
|
|
|
|
- } else {
|
|
|
|
|
- if (log.getIsSum() == 0) {
|
|
|
|
|
- iotOpeationFillService.updateLog(log);
|
|
|
|
|
- } else {
|
|
|
|
|
- iotOpeationFillService.updateSumLog(log);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 批量保存日志(优化后:批量查询+批量插入+批量更新)
|
|
* 批量保存日志(优化后:批量查询+批量插入+批量更新)
|
|
@@ -685,38 +603,7 @@ public class IotOpeationFillController {
|
|
|
return deptMap;
|
|
return deptMap;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 生成日报
|
|
|
|
|
- */
|
|
|
|
|
- /*private void generateDailyReports(List<IotDeviceRunLogDO> logDOList,
|
|
|
|
|
- Map<String, Set<Long>> deptMap,
|
|
|
|
|
- LocalDate createDate,
|
|
|
|
|
- Integer userId) {
|
|
|
|
|
- // 按设备分组处理
|
|
|
|
|
- Map<Long, List<IotDeviceRunLogDO>> deviceLogsMap = logDOList.stream()
|
|
|
|
|
- .collect(Collectors.groupingBy(IotDeviceRunLogDO::getDeviceId));
|
|
|
|
|
-
|
|
|
|
|
- for (Map.Entry<Long, List<IotDeviceRunLogDO>> entry : deviceLogsMap.entrySet()) {
|
|
|
|
|
- List<IotDeviceRunLogDO> deviceLogs = entry.getValue();
|
|
|
|
|
- if (CollectionUtils.isEmpty(deviceLogs)) {
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- IotDeviceRunLogDO sampleLog = deviceLogs.get(0);
|
|
|
|
|
- IotOpeationFillDO reportQuery = new IotOpeationFillDO();
|
|
|
|
|
- reportQuery.setDeviceId(sampleLog.getDeviceId());
|
|
|
|
|
- reportQuery.setCreateTime(sampleLog.getCreateTime());
|
|
|
|
|
-
|
|
|
|
|
- IotOpeationFillDO fillStatus = iotOpeationFillService.isReport(reportQuery);
|
|
|
|
|
- fillStatus.setUserId(userId);
|
|
|
|
|
|
|
|
|
|
- if (fillStatus != null && fillStatus.getIsReport() != null &&
|
|
|
|
|
- fillStatus.getIsReport() == 1) {
|
|
|
|
|
-
|
|
|
|
|
- processDepartmentReport(deviceLogs, fillStatus, deptMap, createDate);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }*/
|
|
|
|
|
private void generateDailyReports(List<IotDeviceRunLogDO> logDOList,
|
|
private void generateDailyReports(List<IotDeviceRunLogDO> logDOList,
|
|
|
Map<String, Set<Long>> deptMap,
|
|
Map<String, Set<Long>> deptMap,
|
|
|
LocalDate createDate,
|
|
LocalDate createDate,
|
|
@@ -761,22 +648,7 @@ public class IotOpeationFillController {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 处理部门日报生成
|
|
|
|
|
- */
|
|
|
|
|
- /*private void processDepartmentReport(List<IotDeviceRunLogDO> deviceLogs,
|
|
|
|
|
- IotOpeationFillDO fillStatus,
|
|
|
|
|
- Map<String, Set<Long>> deptMap,
|
|
|
|
|
- LocalDate createDate) {
|
|
|
|
|
- Set<Long> rhIdList = deptMap.get("RH");
|
|
|
|
|
- Set<Long> ryIdList = deptMap.get("RY");
|
|
|
|
|
|
|
|
|
|
- if (rhIdList.contains(fillStatus.getDeptId())) {
|
|
|
|
|
- generateRhDailyReport(deviceLogs, fillStatus, createDate);
|
|
|
|
|
- } else if (ryIdList.contains(fillStatus.getDeptId())) {
|
|
|
|
|
- generateRyDailyReport(deviceLogs, fillStatus, createDate);
|
|
|
|
|
- }
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 处理部门日报生成(新增descMap缓存)
|
|
* 处理部门日报生成(新增descMap缓存)
|
|
@@ -796,33 +668,7 @@ public class IotOpeationFillController {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 生成RH日报
|
|
|
|
|
- */
|
|
|
|
|
- /*private void generateRhDailyReport(List<IotDeviceRunLogDO> deviceLogs,
|
|
|
|
|
- IotOpeationFillDO fillStatus,
|
|
|
|
|
- LocalDate createDate) {
|
|
|
|
|
- IotRhDailyReportSaveReqVO saveReqVO = new IotRhDailyReportSaveReqVO();
|
|
|
|
|
- Map<String, Object> reportData = BeanUtil.beanToMap(saveReqVO);
|
|
|
|
|
-
|
|
|
|
|
- for (IotDeviceRunLogDO log : deviceLogs) {
|
|
|
|
|
- IotDeviceRunLogDO descDO = iotOpeationFillService.getDesc(log);
|
|
|
|
|
- if (descDO != null && descDO.getPointName() != null) {
|
|
|
|
|
- String pointName = descDO.getPointName();
|
|
|
|
|
- if (reportData.containsKey(pointName)) {
|
|
|
|
|
- reportData.put(pointName, log.getFillContent());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- IotRhDailyReportSaveReqVO finalReport = BeanUtil.mapToBean(reportData,
|
|
|
|
|
- IotRhDailyReportSaveReqVO.class, false);
|
|
|
|
|
- finalReport.setDeptId(fillStatus.getDeptId());
|
|
|
|
|
- finalReport.setFillOrderCreateTime(createDate.atStartOfDay());
|
|
|
|
|
- finalReport.setCreator(String.valueOf(fillStatus.getUserId()));
|
|
|
|
|
|
|
|
|
|
- iotRhDailyReportService.createIotRhDailyReport(finalReport);
|
|
|
|
|
- }*/
|
|
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 生成RH日报(使用缓存的descMap)
|
|
* 生成RH日报(使用缓存的descMap)
|
|
@@ -849,38 +695,7 @@ public class IotOpeationFillController {
|
|
|
iotRhDailyReportService.createIotRhDailyReport(finalReport);
|
|
iotRhDailyReportService.createIotRhDailyReport(finalReport);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * 生成RY日报
|
|
|
|
|
- */
|
|
|
|
|
- /*private void generateRyDailyReport(List<IotDeviceRunLogDO> deviceLogs,
|
|
|
|
|
- IotOpeationFillDO fillStatus,
|
|
|
|
|
- LocalDate createDate) {
|
|
|
|
|
- IotRyDailyReportSaveReqVO saveReqVO = new IotRyDailyReportSaveReqVO();
|
|
|
|
|
- Map<String, Object> reportData = BeanUtil.beanToMap(saveReqVO);
|
|
|
|
|
-
|
|
|
|
|
- for (IotDeviceRunLogDO log : deviceLogs) {
|
|
|
|
|
- IotDeviceRunLogDO descDO = iotOpeationFillService.getDesc(log);
|
|
|
|
|
- if (descDO != null && descDO.getPointName() != null) {
|
|
|
|
|
- String pointName = descDO.getPointName();
|
|
|
|
|
- if (reportData.containsKey(pointName)) {
|
|
|
|
|
- reportData.put(pointName, log.getFillContent());
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- IotRyDailyReportSaveReqVO finalReport = BeanUtil.mapToBean(reportData,
|
|
|
|
|
- IotRyDailyReportSaveReqVO.class, false);
|
|
|
|
|
- finalReport.setDeptId(fillStatus.getDeptId());
|
|
|
|
|
- finalReport.setFillOrderCreateTime(createDate.atStartOfDay());
|
|
|
|
|
- finalReport.setCreator(String.valueOf(fillStatus.getUserId()));
|
|
|
|
|
-
|
|
|
|
|
- if (fillStatus.getDeviceCategoryId() != null &&
|
|
|
|
|
- fillStatus.getDeviceCategoryId() == 228) {
|
|
|
|
|
- finalReport.setProjectClassification("2");
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- iotRyDailyReportService.createIotRyDailyReport(finalReport);
|
|
|
|
|
- }*/
|
|
|
|
|
private void generateRyDailyReport(List<IotDeviceRunLogDO> deviceLogs,
|
|
private void generateRyDailyReport(List<IotDeviceRunLogDO> deviceLogs,
|
|
|
IotOpeationFillDO fillStatus,
|
|
IotOpeationFillDO fillStatus,
|
|
|
LocalDate createDate,
|
|
LocalDate createDate,
|
|
@@ -1087,258 +902,299 @@ public class IotOpeationFillController {
|
|
|
|
|
|
|
|
//**************
|
|
//**************
|
|
|
|
|
|
|
|
- // 新VO类,用于返回包含属性详情的分页结果
|
|
|
|
|
- @Data
|
|
|
|
|
- public class IotOpeationFillWithAttrsVO extends IotOpeationFillDO {
|
|
|
|
|
- // 保留IotOpeationFillDO的所有属性
|
|
|
|
|
- // 新增属性详情字段
|
|
|
|
|
- private List<IotModelTemplateAttrsDO1> attrsDetail;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
@GetMapping("/orderFillpage1")
|
|
@GetMapping("/orderFillpage1")
|
|
|
@Operation(summary = "获得运行记录填报分页")
|
|
@Operation(summary = "获得运行记录填报分页")
|
|
|
@PreAuthorize("@ss.hasPermission('rq:iot-opeation-fill:query')")
|
|
@PreAuthorize("@ss.hasPermission('rq:iot-opeation-fill:query')")
|
|
|
- public CommonResult<PageResult<IotOpeationFillWithAttrsVO>> getIotOpeationFillWithAttrsPage1(@Valid IotOpeationFillPageVO pageReqVO) throws SQLException {
|
|
|
|
|
- // 1. 获取分页数据
|
|
|
|
|
- PageResult<IotOpeationFillDO> fillList = iotOpeationFillService.fillListPage(pageReqVO);
|
|
|
|
|
-
|
|
|
|
|
- // 2. 转换为新的VO类型(包含属性详情)
|
|
|
|
|
- List<IotOpeationFillWithAttrsVO> resultList = new ArrayList<>();
|
|
|
|
|
-
|
|
|
|
|
- for (IotOpeationFillDO fillDO : fillList.getList()) {
|
|
|
|
|
- IotOpeationFillWithAttrsVO vo = BeanUtils.toBean(fillDO, IotOpeationFillWithAttrsVO.class);
|
|
|
|
|
|
|
+ public CommonResult<PageResult<IotOpeationFillWithAttrsVO>> getIotOpeationFillWithAttrsPage1(
|
|
|
|
|
+ @Valid IotOpeationFillPageVO pageReqVO) throws Exception {
|
|
|
|
|
|
|
|
- // 3. 为每个分页项获取属性详情
|
|
|
|
|
- IotModelTemplateAttrsRespVO attrsReqVO = new IotModelTemplateAttrsRespVO();
|
|
|
|
|
- attrsReqVO.setDeviceId(fillDO.getDeviceId());
|
|
|
|
|
- attrsReqVO.setDeviceCode(fillDO.getDeviceCode()); // 假设分页接口返回了deviceCode
|
|
|
|
|
- attrsReqVO.setCreateTime(fillDO.getCreateTime().toLocalDate());
|
|
|
|
|
- attrsReqVO.setDeviceCategoryId(fillDO.getDeviceCategoryId());
|
|
|
|
|
|
|
+ // 1. 分页查询主数据(不变)
|
|
|
|
|
+ PageResult<IotOpeationFillDO> fillPage = iotOpeationFillService.fillListPage(pageReqVO);
|
|
|
|
|
+ List<IotOpeationFillDO> fillList = fillPage.getList();
|
|
|
|
|
+ /*if (CollectionUtils.isEmpty(fillList)) {
|
|
|
|
|
+ return success(BeanUtils.toBean(fillList, IotOpeationFillWithAttrsVO.class));
|
|
|
|
|
|
|
|
|
|
+ }*/
|
|
|
|
|
|
|
|
- // 4. 调用原属性详情逻辑
|
|
|
|
|
- List<IotModelTemplateAttrsDO1> attrsDetail = getAttrsDetail(attrsReqVO);
|
|
|
|
|
- vo.setAttrsDetail(attrsDetail);
|
|
|
|
|
-
|
|
|
|
|
- resultList.add(vo);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 2. 批量预处理参数,避免循环中重复操作
|
|
|
|
|
+ //List<Long> deviceIds = fillList.stream().map(IotOpeationFillDO::getDeviceId).distinct().collect(Collectors.toList());
|
|
|
|
|
+ List<String> deviceCodes = fillList.stream().map(IotOpeationFillDO::getDeviceCode).distinct().collect(Collectors.toList());
|
|
|
|
|
+ //Set<LocalDate> createDates = fillList.stream().map(doObj -> doObj.getCreateTime().toLocalDate()).collect(Collectors.toSet());
|
|
|
|
|
|
|
|
- // 5. 创建新的分页结果
|
|
|
|
|
- PageResult<IotOpeationFillWithAttrsVO> pageResult = new PageResult<>(
|
|
|
|
|
- resultList,
|
|
|
|
|
- fillList.getTotal()
|
|
|
|
|
|
|
+ // 3. 批量查询公共数据(一次查询,全局复用)
|
|
|
|
|
+ // 3.1 批量查询设备状态(判断是否为虚拟设备)
|
|
|
|
|
+ List<YfDeviceDO> allDevice = yfDeviceService.getAllDevice(); // 仅查1次,而非循环中查N次
|
|
|
|
|
+ Map<String, YfDeviceDO> deviceStatusMap = allDevice.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
|
+ YfDeviceDO::getSerialNumber,
|
|
|
|
|
+ Function.identity(),
|
|
|
|
|
+ (oldVal, newVal) -> newVal
|
|
|
|
|
+ ));
|
|
|
|
|
+ // 3.2 批量查询isReport状态(避免循环查询)
|
|
|
|
|
+ Map<Long, Integer> deviceReportMap = iotOpeationFillService.batchGetIsReport(
|
|
|
|
|
+ fillList.stream().map(doObj -> {
|
|
|
|
|
+ IotOpeationFillDO query = new IotOpeationFillDO();
|
|
|
|
|
+ query.setDeviceId(doObj.getDeviceId());
|
|
|
|
|
+ query.setCreateTime(doObj.getCreateTime().toLocalDate().atStartOfDay());
|
|
|
|
|
+ return query;
|
|
|
|
|
+ }).collect(Collectors.toList())
|
|
|
);
|
|
);
|
|
|
|
|
+ // 3.3 批量查询orderDO数据
|
|
|
|
|
+ Map<Long, IotOpeationFillDO> deviceOrderMap = iotOpeationFillService.batchGetOrderDO(
|
|
|
|
|
+ fillList.stream().map(doObj -> {
|
|
|
|
|
+ IotOpeationFillDO query = new IotOpeationFillDO();
|
|
|
|
|
+ query.setDeviceId(doObj.getDeviceId());
|
|
|
|
|
+ query.setCreateTime(doObj.getCreateTime().toLocalDate().atStartOfDay());
|
|
|
|
|
+ return query;
|
|
|
|
|
+ }).collect(Collectors.toList())
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 并行处理分页数据(利用多核CPU,非IO密集型操作适合并行)
|
|
|
|
|
+ List<IotOpeationFillWithAttrsVO> resultList = fillList.parallelStream().map(fillDO -> {
|
|
|
|
|
+ try {
|
|
|
|
|
+ IotOpeationFillWithAttrsVO vo = BeanUtils.toBean(fillDO, IotOpeationFillWithAttrsVO.class);
|
|
|
|
|
+ LocalDate createDate = fillDO.getCreateTime().toLocalDate();
|
|
|
|
|
+
|
|
|
|
|
+ // 构建参数VO
|
|
|
|
|
+ IotModelTemplateAttrsRespVO attrsReqVO = new IotModelTemplateAttrsRespVO();
|
|
|
|
|
+ attrsReqVO.setDeviceId(fillDO.getDeviceId());
|
|
|
|
|
+ attrsReqVO.setDeviceCode(fillDO.getDeviceCode());
|
|
|
|
|
+ attrsReqVO.setCreateTime(createDate);
|
|
|
|
|
+ attrsReqVO.setDeviceCategoryId(fillDO.getDeviceCategoryId());
|
|
|
|
|
+ // 调用优化后的属性详情查询(带缓存和批量查询)
|
|
|
|
|
+ List<IotModelTemplateAttrsDO1> attrsDetail = getAttrsDetailOptimized(
|
|
|
|
|
+ attrsReqVO, deviceStatusMap, deviceReportMap, deviceOrderMap);
|
|
|
|
|
+
|
|
|
|
|
+ vo.setAttrsDetail(attrsDetail);
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("处理设备[{}]属性详情失败", fillDO.getDeviceId(), e);
|
|
|
|
|
+ // 降级处理:返回空属性详情,避免整个分页失败
|
|
|
|
|
+ IotOpeationFillWithAttrsVO vo = BeanUtils.toBean(fillDO, IotOpeationFillWithAttrsVO.class);
|
|
|
|
|
+ vo.setAttrsDetail(Collections.emptyList());
|
|
|
|
|
+ return vo;
|
|
|
|
|
+ }
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
|
|
|
|
|
+ // 5. 构建返回结果
|
|
|
|
|
+ PageResult<IotOpeationFillWithAttrsVO> pageResult = new PageResult<>(resultList, fillPage.getTotal());
|
|
|
return success(pageResult);
|
|
return success(pageResult);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 提取属性详情逻辑为私有方法
|
|
|
|
|
- private List<IotModelTemplateAttrsDO1> getAttrsDetail(IotModelTemplateAttrsRespVO vo) throws SQLException {
|
|
|
|
|
- // 以下是您原getAttrs接口的核心逻辑,保持不变
|
|
|
|
|
- //判断是否为虚拟设备
|
|
|
|
|
- //如果是走原来逻辑
|
|
|
|
|
- //不是走虚拟设备逻辑
|
|
|
|
|
- IotOpeationFillDO fillDO = new IotOpeationFillDO();
|
|
|
|
|
- fillDO.setDeviceId(vo.getDeviceId());
|
|
|
|
|
- fillDO.setCreateTime(vo.getCreateTime().atStartOfDay());
|
|
|
|
|
- IotOpeationFillDO fillDO1 = iotOpeationFillService.isReport(fillDO);
|
|
|
|
|
-
|
|
|
|
|
- List<IotModelTemplateAttrsDO1> result = new ArrayList<>();
|
|
|
|
|
- List<IotModelTemplateAttrsDO> list = iotOpeationFillService.getAttrsById(vo);
|
|
|
|
|
-
|
|
|
|
|
- if (fillDO1.getIsReport() != null && fillDO1.getIsReport() == 1) {
|
|
|
|
|
- IotOpeationFillDO fillDO2 = iotOpeationFillService.orderDO(fillDO);
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 优化后的属性详情查询:批量查询+缓存复用+减少冗余计算
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<IotModelTemplateAttrsDO1> getAttrsDetailOptimized(
|
|
|
|
|
+ IotModelTemplateAttrsRespVO vo,
|
|
|
|
|
+ Map<String, YfDeviceDO> deviceStatusMap,
|
|
|
|
|
+ Map<Long, Integer> deviceReportMap,
|
|
|
|
|
+ Map<Long, IotOpeationFillDO> deviceOrderMap) throws SQLException {
|
|
|
|
|
+
|
|
|
|
|
+ Long deviceId = vo.getDeviceId();
|
|
|
|
|
+ String deviceCode = vo.getDeviceCode();
|
|
|
|
|
+ LocalDate createDate = vo.getCreateTime();
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 复用批量查询结果(避免重复数据库查询)
|
|
|
|
|
+ Integer isReport = deviceReportMap.getOrDefault(deviceId, 0);
|
|
|
|
|
+ IotOpeationFillDO fillDO2 = deviceOrderMap.get(deviceId);
|
|
|
|
|
+ YfDeviceDO yfDevice = deviceStatusMap.get(deviceCode);
|
|
|
|
|
+ boolean isVirtualDevice = yfDevice != null && yfDevice.getStatus() == 3;
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 批量查询属性模板(一次查询)
|
|
|
|
|
+ List<IotModelTemplateAttrsDO> attrsList = iotOpeationFillService.getAttrsByIdBatch(
|
|
|
|
|
+ Collections.singletonList(vo)); // 可扩展为多设备批量查询
|
|
|
|
|
+
|
|
|
|
|
+ if (CollectionUtils.isEmpty(attrsList)) {
|
|
|
|
|
+ return Collections.emptyList();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- List<IotOpeationFillDO> reportList = new ArrayList<>();
|
|
|
|
|
- List<IotOpeationFillDO> reportList1 = new ArrayList<>();
|
|
|
|
|
|
|
+ // 3. 按isReport分支处理(优化数据查询逻辑)
|
|
|
|
|
+ if (isReport != null && isReport == 1) {
|
|
|
|
|
+ handleReportDeviceAttrs(attrsList, fillDO2);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ handleNormalDeviceAttrs(attrsList, vo, isVirtualDevice, createDate);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (fillDO2 != null) {
|
|
|
|
|
- reportList = iotOpeationFillService.reportList(fillDO2);
|
|
|
|
|
- reportList1 = iotOpeationFillService.reportList1(fillDO2);
|
|
|
|
|
|
|
+ // 4. 分组处理(提前分组,避免重复流处理)
|
|
|
|
|
+ List<IotModelTemplateAttrsDO> sumList = new ArrayList<>();
|
|
|
|
|
+ List<IotModelTemplateAttrsDO> nonSumList = new ArrayList<>();
|
|
|
|
|
+ for (IotModelTemplateAttrsDO attrsDO : attrsList) {
|
|
|
|
|
+ if (attrsDO.getIsSum() == 1) {
|
|
|
|
|
+ sumList.add(attrsDO);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ nonSumList.add(attrsDO);
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- for (IotModelTemplateAttrsDO attrsDO : list) {
|
|
|
|
|
- List<IotOpeationFillDO> cxLixt = reportList.stream().filter(e -> e.getOrgName().equals(attrsDO.getName())).collect(Collectors.toList());
|
|
|
|
|
- //虚拟设备取值
|
|
|
|
|
- List<IotOpeationFillDO> cxLixt1 = reportList1.stream().filter(e -> e.getOrgName().equals(attrsDO.getName())).collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- if (cxLixt.size() > 0) {
|
|
|
|
|
- // 使用Map按orgName分组存储累加结果
|
|
|
|
|
- Map<String, String> orgNameToFillContent = new HashMap<>();
|
|
|
|
|
-
|
|
|
|
|
- for (IotOpeationFillDO reportData : cxLixt) {
|
|
|
|
|
- IotDeviceRunLogDO report = new IotDeviceRunLogDO();
|
|
|
|
|
- report.setDeviceId(reportData.getDeviceId());
|
|
|
|
|
- report.setPointName(reportData.getOrgName());
|
|
|
|
|
- report.setCreateTime(reportData.getCreateTime());
|
|
|
|
|
-
|
|
|
|
|
- IotDeviceRunLogDO reportCx = iotOpeationFillService.reportData(report);
|
|
|
|
|
-
|
|
|
|
|
- String currentContent = "";
|
|
|
|
|
- if (reportCx == null) {
|
|
|
|
|
- attrsDO.setFillContent("");
|
|
|
|
|
- } else {
|
|
|
|
|
- currentContent = reportCx.getFillContent() != null ? reportCx.getFillContent() : "";
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 获取当前orgName
|
|
|
|
|
- String orgName = reportData.getOrgName();
|
|
|
|
|
-
|
|
|
|
|
- // 累加相同orgName的内容
|
|
|
|
|
- if (orgNameToFillContent.containsKey(orgName)) {
|
|
|
|
|
- String existingContent = orgNameToFillContent.get(orgName);
|
|
|
|
|
-
|
|
|
|
|
- double existingValue = safeParseInt(existingContent);
|
|
|
|
|
- double currentValue = safeParseInt(currentContent);
|
|
|
|
|
-
|
|
|
|
|
- if ((existingValue + currentValue) == 0) {
|
|
|
|
|
- orgNameToFillContent.put(orgName, "");
|
|
|
|
|
- } else {
|
|
|
|
|
- orgNameToFillContent.put(orgName, String.valueOf(existingValue + currentValue));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- orgNameToFillContent.put(orgName, currentContent);
|
|
|
|
|
- }
|
|
|
|
|
- attrsDO.setFillContent(orgNameToFillContent.get(reportData.getOrgName()));
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if (cxLixt1.size() > 0) {
|
|
|
|
|
- for (IotOpeationFillDO reportData : cxLixt1) {
|
|
|
|
|
- IotDeviceRunLogDO report = new IotDeviceRunLogDO();
|
|
|
|
|
- report.setDeviceId(reportData.getDeviceId());
|
|
|
|
|
- report.setPointName(reportData.getOrgName());
|
|
|
|
|
- report.setCreateTime(reportData.getCreateTime());
|
|
|
|
|
- IotDeviceRunLogDO reportCx = iotOpeationFillService.reportData(report);
|
|
|
|
|
-
|
|
|
|
|
- String currentContent = "";
|
|
|
|
|
- if (reportCx != null) {
|
|
|
|
|
- currentContent = reportCx.getFillContent() != null ? reportCx.getFillContent() : "";
|
|
|
|
|
- attrsDO.setFillContent(currentContent);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 5. 构建结果(减少对象创建)
|
|
|
|
|
+ IotModelTemplateAttrsDO1 resultDO = new IotModelTemplateAttrsDO1();
|
|
|
|
|
+ resultDO.setSumList(sumList);
|
|
|
|
|
+ resultDO.setNonSumList(nonSumList);
|
|
|
|
|
+ return Collections.singletonList(resultDO);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理虚拟设备(isReport=1)的属性详情
|
|
|
|
|
+ */
|
|
|
|
|
+ private void handleReportDeviceAttrs(List<IotModelTemplateAttrsDO> attrsList, IotOpeationFillDO fillDO2) throws SQLException {
|
|
|
|
|
+ if (fillDO2 == null) {
|
|
|
|
|
+ attrsList.forEach(attrsDO -> {
|
|
|
|
|
+ attrsDO.setFillContent("");
|
|
|
attrsDO.setIsCollection(0);
|
|
attrsDO.setIsCollection(0);
|
|
|
attrsDO.setIsSum(0);
|
|
attrsDO.setIsSum(0);
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- List<YfDeviceDO> allDevice = yfDeviceService.getAllDevice();
|
|
|
|
|
-
|
|
|
|
|
- LocalTime localTime = LocalTime.of(0, 0, 0);
|
|
|
|
|
- LocalTime localTime1 = LocalTime.of(23, 59, 59);
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- LocalDateTime start = LocalDateTime.of(vo.getCreateTime(), localTime);
|
|
|
|
|
- LocalDateTime end = LocalDateTime.of(vo.getCreateTime(), localTime1);
|
|
|
|
|
|
|
+ // 批量查询reportList和reportList1(一次查询,避免循环)
|
|
|
|
|
+ List<IotOpeationFillDO> reportList = iotOpeationFillService.reportList(fillDO2);
|
|
|
|
|
+ List<IotOpeationFillDO> reportList1 = iotOpeationFillService.reportList1(fillDO2);
|
|
|
|
|
+
|
|
|
|
|
+ // 构建属性名到数据的映射(提前分组,避免重复stream过滤)
|
|
|
|
|
+ Map<String, List<IotOpeationFillDO>> reportDataMap = reportList.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(IotOpeationFillDO::getOrgName));
|
|
|
|
|
+ Map<String, List<IotOpeationFillDO>> reportDataMap1 = reportList1.stream()
|
|
|
|
|
+ .collect(Collectors.groupingBy(IotOpeationFillDO::getOrgName));
|
|
|
|
|
+
|
|
|
|
|
+ // 批量收集需要查询的runLog参数
|
|
|
|
|
+ List<IotDeviceRunLogDO> runLogQueries = new ArrayList<>();
|
|
|
|
|
+ reportList.forEach(reportData -> {
|
|
|
|
|
+ IotDeviceRunLogDO query = new IotDeviceRunLogDO();
|
|
|
|
|
+ query.setDeviceId(reportData.getDeviceId());
|
|
|
|
|
+ query.setPointName(reportData.getOrgName());
|
|
|
|
|
+ query.setCreateTime(reportData.getCreateTime());
|
|
|
|
|
+ //query.setExt1(reportData.getOrgName()); // 存储orgName用于后续映射
|
|
|
|
|
+ runLogQueries.add(query);
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
- Timestamp startTime = Timestamp.valueOf(start);
|
|
|
|
|
- Timestamp endTime = Timestamp.valueOf(end);
|
|
|
|
|
|
|
+ // 批量查询runLog数据(一次查询,替代循环查询)
|
|
|
|
|
+ Map<Long, String> runLogFillContentMap = new HashMap<>();
|
|
|
|
|
+ if (!runLogQueries.isEmpty()) {
|
|
|
|
|
+ List<IotDeviceRunLogDO> runLogList = iotOpeationFillService.batchReportData(runLogQueries);
|
|
|
|
|
+ runLogFillContentMap = runLogList.stream()
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
|
+ logDO -> logDO.getDeviceId(), // orgName
|
|
|
|
|
+ logDO -> logDO.getFillContent() != null ? logDO.getFillContent() : "",
|
|
|
|
|
+ (v1, v2) -> v1 // 冲突时取第一个
|
|
|
|
|
+ ));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- List<YfDeviceDO> existList = allDevice.stream().filter(e -> e.getStatus() == 3).collect(Collectors.toList());
|
|
|
|
|
- boolean exists1 = existList.stream().anyMatch(yfDeviceDO -> yfDeviceDO.getSerialNumber().equals(vo.getDeviceCode()));
|
|
|
|
|
|
|
+ // 处理属性数据
|
|
|
|
|
+ for (IotModelTemplateAttrsDO attrsDO : attrsList) {
|
|
|
|
|
+ String attrName = attrsDO.getName();
|
|
|
|
|
+ List<IotOpeationFillDO> cxList = reportDataMap.getOrDefault(attrName, Collections.emptyList());
|
|
|
|
|
+ List<IotOpeationFillDO> cxList1 = reportDataMap1.getOrDefault(attrName, Collections.emptyList());
|
|
|
|
|
+
|
|
|
|
|
+ // 处理reportList数据(累加逻辑)
|
|
|
|
|
+ if (!cxList.isEmpty()) {
|
|
|
|
|
+ double total = 0;
|
|
|
|
|
+ for (IotOpeationFillDO reportData : cxList) {
|
|
|
|
|
+ String content = runLogFillContentMap.getOrDefault(reportData.getOrgName(), "");
|
|
|
|
|
+ total += safeParseInt(content);
|
|
|
|
|
+ }
|
|
|
|
|
+ attrsDO.setFillContent(total == 0 ? "" : String.valueOf(total));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- IotDeviceRunLogDO logDO1 = new IotDeviceRunLogDO();
|
|
|
|
|
- logDO1.setDeviceId(vo.getDeviceId());
|
|
|
|
|
- LocalTime local = LocalTime.of(12, 0);
|
|
|
|
|
- logDO1.setCreateTime(LocalDateTime.of(vo.getCreateTime(), local));
|
|
|
|
|
|
|
+ // 处理reportList1数据(覆盖逻辑)
|
|
|
|
|
+ if (!cxList1.isEmpty()) {
|
|
|
|
|
+ IotOpeationFillDO reportData = cxList1.get(0); // 取第一条(原逻辑未处理多条,这里保持一致)
|
|
|
|
|
+ String content = runLogFillContentMap.getOrDefault(reportData.getOrgName(), "");
|
|
|
|
|
+ attrsDO.setFillContent(content);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (exists1) {
|
|
|
|
|
- for (IotModelTemplateAttrsDO attrsDO : list) {
|
|
|
|
|
- DeviceVO dv = new DeviceVO();
|
|
|
|
|
- dv.setDeviceName(vo.getDeviceCode().toLowerCase());
|
|
|
|
|
- dv.setColName(attrsDO.getModelAttr());
|
|
|
|
|
- dv.setTs(startTime);
|
|
|
|
|
- dv.setTs1(endTime);
|
|
|
|
|
|
|
+ attrsDO.setIsCollection(0);
|
|
|
|
|
+ attrsDO.setIsSum(0);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- DeviceVO deviceVO = iDeviceService.getYesInfo(dv);
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 处理普通设备(isReport!=1)的属性详情
|
|
|
|
|
+ */
|
|
|
|
|
+ private void handleNormalDeviceAttrs(List<IotModelTemplateAttrsDO> attrsList,
|
|
|
|
|
+ IotModelTemplateAttrsRespVO vo,
|
|
|
|
|
+ boolean isVirtualDevice,
|
|
|
|
|
+ LocalDate createDate) throws SQLException {
|
|
|
|
|
+
|
|
|
|
|
+ Long deviceId = vo.getDeviceId();
|
|
|
|
|
+ String deviceCode = vo.getDeviceCode();
|
|
|
|
|
+
|
|
|
|
|
+ // 构建时间参数(一次计算,全局复用)
|
|
|
|
|
+ LocalDateTime start = LocalDateTime.of(createDate, LocalTime.MIN);
|
|
|
|
|
+ LocalDateTime end = LocalDateTime.of(createDate, LocalTime.MAX);
|
|
|
|
|
+ Timestamp startTime = Timestamp.valueOf(start);
|
|
|
|
|
+ Timestamp endTime = Timestamp.valueOf(end);
|
|
|
|
|
+ LocalDateTime midDay = LocalDateTime.of(createDate, LocalTime.of(12, 0));
|
|
|
|
|
+
|
|
|
|
|
+ // 批量收集DeviceVO查询参数
|
|
|
|
|
+ List<DeviceVO> deviceVOQueries = new ArrayList<>();
|
|
|
|
|
+ List<IotDeviceRunLogDO> logDOQueries = new ArrayList<>();
|
|
|
|
|
+ for (IotModelTemplateAttrsDO attrsDO : attrsList) {
|
|
|
|
|
+ if (isVirtualDevice) {
|
|
|
|
|
+ DeviceVO dv = new DeviceVO();
|
|
|
|
|
+ dv.setDeviceName(deviceCode.toLowerCase());
|
|
|
|
|
+ dv.setColName(attrsDO.getModelAttr());
|
|
|
|
|
+ dv.setTs(startTime);
|
|
|
|
|
+ dv.setTs1(endTime);
|
|
|
|
|
+ //dv.setExt1(attrsDO.getId().toString()); // 存储属性ID用于映射
|
|
|
|
|
+ deviceVOQueries.add(dv);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (!StringUtils.isEmpty(deviceVO) && !deviceVO.getEarliestData().equals("0.0")) {
|
|
|
|
|
- attrsDO.setFillContent(
|
|
|
|
|
- String.valueOf(Double.parseDouble(deviceVO.getLatestData()) - Double.parseDouble(deviceVO.getEarliestData())));
|
|
|
|
|
- attrsDO.setTotalRunTime(BigDecimal.valueOf(Double.parseDouble(deviceVO.getLatestData())));
|
|
|
|
|
- /**
|
|
|
|
|
- * 设置为数采
|
|
|
|
|
- */
|
|
|
|
|
- attrsDO.setIsCollection(1);
|
|
|
|
|
- } else {
|
|
|
|
|
- logDO1.setPointName(attrsDO.getName());
|
|
|
|
|
- IotDeviceRunLogDO logInfo = iotOpeationFillService.getLogInfo(logDO1);
|
|
|
|
|
- IotDeviceRunLogDO maxLog = iotOpeationFillService.getMaxFillInfo(logDO1);
|
|
|
|
|
- if (!StringUtils.isEmpty(logInfo)) {
|
|
|
|
|
|
|
+ IotDeviceRunLogDO logDO = new IotDeviceRunLogDO();
|
|
|
|
|
+ logDO.setDeviceId(deviceId);
|
|
|
|
|
+ logDO.setPointName(attrsDO.getName());
|
|
|
|
|
+ logDO.setCreateTime(midDay);
|
|
|
|
|
+ //logDO.setExt1(attrsDO.getId().toString()); // 存储属性ID用于映射
|
|
|
|
|
+ logDOQueries.add(logDO);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- attrsDO.setFillContent(logInfo.getFillContent());
|
|
|
|
|
|
|
+ // 批量查询(替代循环查询)
|
|
|
|
|
+ Map<String, DeviceVO> deviceVOMap = new HashMap<>();
|
|
|
|
|
+ if (isVirtualDevice && !deviceVOQueries.isEmpty()) {
|
|
|
|
|
+ List<DeviceVO> deviceVOList = iDeviceService.batchGetYesInfo(deviceVOQueries);
|
|
|
|
|
+ deviceVOMap = deviceVOList.stream()
|
|
|
|
|
+ .filter(voObj -> !StringUtils.isEmpty(voObj.getEarliestData()) && !"0.0".equals(voObj.getEarliestData()))
|
|
|
|
|
+ .collect(Collectors.toMap(DeviceVO::getDeviceName, Function.identity()));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (StringUtils.isEmpty(maxLog)) {
|
|
|
|
|
- attrsDO.setTotalRunTime(BigDecimal.valueOf(0));
|
|
|
|
|
- } else {
|
|
|
|
|
- attrsDO.setTotalRunTime(maxLog.getTotalRunTime());
|
|
|
|
|
- }
|
|
|
|
|
- /**
|
|
|
|
|
- * 设置为非数采
|
|
|
|
|
- */
|
|
|
|
|
- attrsDO.setIsCollection(0);
|
|
|
|
|
|
|
+ // 批量查询logInfo和maxLog
|
|
|
|
|
+ Map<String, IotDeviceRunLogDO> logInfoMap = new HashMap<>();
|
|
|
|
|
+ Map<String, IotDeviceRunLogDO> maxLogMap = new HashMap<>();
|
|
|
|
|
+ if (!logDOQueries.isEmpty()) {
|
|
|
|
|
+ logInfoMap = iotOpeationFillService.batchGetLogInfo(logDOQueries).stream()
|
|
|
|
|
+ .collect(Collectors.toMap(IotDeviceRunLogDO::getPointName, Function.identity()));
|
|
|
|
|
+ maxLogMap = iotOpeationFillService.batchGetMaxFillInfo(logDOQueries).stream()
|
|
|
|
|
+ .collect(Collectors.toMap(IotDeviceRunLogDO::getPointName, Function.identity()));
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- } else {
|
|
|
|
|
- attrsDO.setFillContent("");
|
|
|
|
|
- if (StringUtils.isEmpty(maxLog)) {
|
|
|
|
|
- attrsDO.setTotalRunTime(BigDecimal.valueOf(0));
|
|
|
|
|
- } else {
|
|
|
|
|
- attrsDO.setTotalRunTime(maxLog.getTotalRunTime());
|
|
|
|
|
- }
|
|
|
|
|
- /**
|
|
|
|
|
- * 设置为非数采
|
|
|
|
|
- */
|
|
|
|
|
- attrsDO.setIsCollection(0);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 处理属性数据
|
|
|
|
|
+ for (IotModelTemplateAttrsDO attrsDO : attrsList) {
|
|
|
|
|
+ String attrId = attrsDO.getId().toString();
|
|
|
|
|
+ String attrName = attrsDO.getName();
|
|
|
|
|
+ if (isVirtualDevice) {
|
|
|
|
|
+ DeviceVO deviceVO = deviceVOMap.get(attrId);
|
|
|
|
|
+ if (deviceVO != null) {
|
|
|
|
|
+ // 数采设备逻辑
|
|
|
|
|
+ double diff = Double.parseDouble(deviceVO.getLatestData()) - Double.parseDouble(deviceVO.getEarliestData());
|
|
|
|
|
+ attrsDO.setFillContent(String.valueOf(diff));
|
|
|
|
|
+ attrsDO.setTotalRunTime(BigDecimal.valueOf(Double.parseDouble(deviceVO.getLatestData())));
|
|
|
|
|
+ attrsDO.setIsCollection(1);
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
- } else {
|
|
|
|
|
- for (IotModelTemplateAttrsDO attrsDO : list) {
|
|
|
|
|
- logDO1.setPointName(attrsDO.getName());
|
|
|
|
|
- IotDeviceRunLogDO logInfo = iotOpeationFillService.getLogInfo(logDO1);
|
|
|
|
|
- IotDeviceRunLogDO maxLog = iotOpeationFillService.getMaxFillInfo(logDO1);
|
|
|
|
|
- if (!StringUtils.isEmpty(logInfo)) {
|
|
|
|
|
-
|
|
|
|
|
- attrsDO.setFillContent(logInfo.getFillContent());
|
|
|
|
|
- attrsDO.setTotalRunTime(logInfo.getTotalRunTime());
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 设置为非数采
|
|
|
|
|
- */
|
|
|
|
|
- attrsDO.setIsCollection(0);
|
|
|
|
|
-
|
|
|
|
|
- } else {
|
|
|
|
|
- attrsDO.setFillContent("");
|
|
|
|
|
- if (StringUtils.isEmpty(maxLog)) {
|
|
|
|
|
- attrsDO.setTotalRunTime(BigDecimal.valueOf(0));
|
|
|
|
|
- } else {
|
|
|
|
|
- attrsDO.setTotalRunTime(maxLog.getTotalRunTime());
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- /**
|
|
|
|
|
- * 设置为非数采
|
|
|
|
|
- */
|
|
|
|
|
- attrsDO.setIsCollection(0);
|
|
|
|
|
-
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ // 非数采设备逻辑
|
|
|
|
|
+ IotDeviceRunLogDO logInfo = logInfoMap.get(attrName);
|
|
|
|
|
+ IotDeviceRunLogDO maxLog = maxLogMap.get(attrName);
|
|
|
|
|
|
|
|
|
|
+ if (logInfo != null) {
|
|
|
|
|
+ attrsDO.setFillContent(logInfo.getFillContent());
|
|
|
|
|
+ attrsDO.setTotalRunTime(logInfo.getTotalRunTime() != null ? logInfo.getTotalRunTime() : BigDecimal.ZERO);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ attrsDO.setFillContent("");
|
|
|
|
|
+ attrsDO.setTotalRunTime(maxLog != null ? maxLog.getTotalRunTime() : BigDecimal.ZERO);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ attrsDO.setIsCollection(0);
|
|
|
}
|
|
}
|
|
|
- List<IotModelTemplateAttrsDO> sumList = list.stream().filter(e -> e.getIsSum() == 1).collect(Collectors.toList());
|
|
|
|
|
- List<IotModelTemplateAttrsDO> nonSumList = list.stream().filter(e -> e.getIsSum() == 0).collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
- IotModelTemplateAttrsDO1 sum = new IotModelTemplateAttrsDO1();
|
|
|
|
|
- sum.setSumList(sumList);
|
|
|
|
|
- sum.setNonSumList(nonSumList);
|
|
|
|
|
-
|
|
|
|
|
- result.add(sum);
|
|
|
|
|
-
|
|
|
|
|
- return result;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|