From 6e25e7a11d89c49e8b28a1ea151576ae4c4a7d16 Mon Sep 17 00:00:00 2001
From: dengzedong <dengzedong@email>
Date: 星期四, 08 五月 2025 17:21:31 +0800
Subject: [PATCH] EnableFeignClients ArcDataApi

---
 ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunPowerMaxdemandTask.java |  150 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 150 insertions(+), 0 deletions(-)

diff --git a/ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunPowerMaxdemandTask.java b/ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunPowerMaxdemandTask.java
new file mode 100644
index 0000000..076de83
--- /dev/null
+++ b/ansteel-biz/src/main/java/com/iailab/module/ansteel/job/task/RunPowerMaxdemandTask.java
@@ -0,0 +1,150 @@
+package com.iailab.module.ansteel.job.task;
+
+import com.iailab.module.ansteel.common.utils.DecimalUtil;
+import com.iailab.module.ansteel.power.entity.PowerDemandEntity;
+import com.iailab.module.ansteel.power.entity.PowerMaxdemandDetEntity;
+import com.iailab.module.ansteel.power.entity.PowerMaxdemandMainEntity;
+import com.iailab.module.ansteel.power.entity.PowerNetDropdownEntity;
+import com.iailab.module.ansteel.power.service.PowerDemandService;
+import com.iailab.module.ansteel.power.service.PowerMaxdemandDetService;
+import com.iailab.module.ansteel.power.service.PowerMaxdemandMainService;
+import com.iailab.module.ansteel.power.service.PowerNetDropdownService;
+import com.iailab.module.data.api.point.DataPointApi;
+import com.iailab.module.data.api.point.dto.ApiPointValueDTO;
+import com.iailab.module.data.api.point.dto.ApiPointValueQueryDTO;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.*;
+
+/**
+ * 检查每天的需量与这个月的最大值比较
+ * 如果大于,则保存
+ * 每天23:59执行
+ *
+ * @author PanZhibao
+ * @Description
+ * @createTime 2025年05月08日
+ */
+@Component("runPowerMaxdemandTask")
+public class RunPowerMaxdemandTask implements ITask {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private PowerDemandService powerDemandService;
+
+    @Autowired
+    private PowerMaxdemandMainService powerMaxdemandMainService;
+
+    @Autowired
+    private PowerNetDropdownService powerNetDropdownService;
+
+    @Autowired
+    private PowerMaxdemandDetService powerMaxdemandDetService;
+
+    @Resource
+    private DataPointApi dataPointApi;
+
+    @Override
+    public void run(String params) {
+        logger.info("RunPowerMaxdemandTask start");
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.MILLISECOND, 0);
+        calendar.set(Calendar.SECOND, 0);
+        Date nowTime = calendar.getTime();
+        calendar.set(Calendar.MINUTE, 0);
+        calendar.set(Calendar.HOUR_OF_DAY, 0);
+        Date dayStart = calendar.getTime();
+        calendar.set(Calendar.DAY_OF_MONTH, 1);
+        Date monStart = calendar.getTime();
+        try {
+            Map<String, Object> params0 = new HashMap<>();
+            List<PowerDemandEntity> demandList = powerDemandService.list(params0);
+            if (CollectionUtils.isEmpty(demandList)) {
+                logger.info("demandList is empty");
+                return;
+            }
+            for (PowerDemandEntity demand : demandList) {
+                // 查询今天的最大需量
+                ApiPointValueQueryDTO pointValueQuery0 = new ApiPointValueQueryDTO();
+                pointValueQuery0.setStart(dayStart);
+                pointValueQuery0.setEnd(nowTime);
+                pointValueQuery0.setPointNo(demand.getCurDemand());
+                Map<String, Object> maxValue = dataPointApi.queryPointMaxValue(pointValueQuery0);
+                BigDecimal todayMax = BigDecimal.ZERO;
+                if (CollectionUtils.isEmpty(maxValue) && maxValue.containsKey(demand.getCurDemand())) {
+                    todayMax = new BigDecimal(maxValue.get(demand.getCurDemand()).toString());
+                }
+
+                List<ApiPointValueDTO> valueList = dataPointApi.queryPointHistoryValue(pointValueQuery0);
+                if (CollectionUtils.isEmpty(valueList)) {
+                    logger.info("valueList is empty");
+                    continue;
+                }
+                Date occurTime = new Date(nowTime.getTime());
+                for (ApiPointValueDTO apiPointValueDTO : valueList) {
+                    if (Math.abs(apiPointValueDTO.getV() - todayMax.doubleValue()) < 0.001) {
+                        occurTime = apiPointValueDTO.getT();
+                        break;
+                    }
+                }
+
+                // 查询本月需量发生记录
+                BigDecimal monthMax = powerMaxdemandMainService.getMax(demand.getCode(), monStart, nowTime);
+
+                // 保存记录
+                if (todayMax.compareTo(monthMax) <= 0) {
+                    continue;
+                }
+                PowerMaxdemandMainEntity mainEntity = new PowerMaxdemandMainEntity();
+                mainEntity.setCode(demand.getCode());
+                mainEntity.setName(demand.getName());
+                mainEntity.setOccurTime(occurTime);
+                mainEntity.setMaxDemand(todayMax);
+                String mainId = powerMaxdemandMainService.add(mainEntity);
+
+                Map<String, Object> params1 = new HashMap<>();
+                params1.put("pCode", demand.getCode());
+                List<PowerNetDropdownEntity> dropdownList = powerNetDropdownService.list(params1);
+                if (CollectionUtils.isEmpty(dropdownList)) {
+                    logger.info("dropdownList is empty");
+                    continue;
+                }
+                for (PowerNetDropdownEntity dropdown : dropdownList) {
+                    if (StringUtils.isBlank(dropdown.getExt1())) {
+                        continue;
+                    }
+                    Calendar calendar1 = Calendar.getInstance();
+                    calendar1.setTime(occurTime);
+                    calendar1.add(Calendar.MINUTE, 1);
+                    ApiPointValueQueryDTO pointValueQuery1 = new ApiPointValueQueryDTO();
+                    pointValueQuery1.setStart(occurTime);
+                    pointValueQuery1.setEnd(calendar1.getTime());
+                    pointValueQuery1.setPointNo(dropdown.getExt1());
+                    List<ApiPointValueDTO> valueList1 = dataPointApi.queryPointHistoryValue(pointValueQuery1);
+                    if (CollectionUtils.isEmpty(valueList1)) {
+                        logger.info("valueList1 is empty");
+                        continue;
+                    }
+                    PowerMaxdemandDetEntity detEntity = new PowerMaxdemandDetEntity();
+                    detEntity.setRelId(mainId);
+                    detEntity.setCode(dropdown.getNodeCode());
+                    detEntity.setName(dropdown.getNodeName());
+                    detEntity.setOccurTime(occurTime);
+                    detEntity.setMaxDemand(BigDecimal.valueOf(valueList1.get(0).getV()));
+                    powerMaxdemandDetService.add(detEntity);
+                }
+            }
+            logger.info("RunPowerMaxdemandTask end");
+        } catch (Exception e) {
+            logger.error("RunPowerMaxdemandTask error", e);
+            e.printStackTrace();
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3