Kaynağa Gözat

江津预测模块升级

1037015548@qq.com 2 ay önce
ebeveyn
işleme
022651df15

+ 7 - 7
sql.properties

@@ -5,18 +5,18 @@ spring.datasource.data.password=kpr.23417.postgres
 spring.datasource.data.driver-class-name=org.postgis.DriverWrapper
 
 #pgsql Ë®Á¿Ô¤²âÊý¾Ý¿âÔ´
-#spring.datasource.db2.jdbc-url=jdbc:postgresql_postGIS://119.96.165.176:5432/water_volume_prediction?useSSL=false&useAffectedRows=false&allowMultiQueries=true
+#spring.datasource.db2.jdbc-url=jdbc:postgresql_postGIS://140.246.183.164:5432/water_volume_prediction?useSSL=false&useAffectedRows=false&allowMultiQueries=true
 #spring.datasource.db2.username=postgres
 #spring.datasource.db2.password=kpr.23417.postgres
 #spring.datasource.db2.driver-class-name=org.postgis.DriverWrapper
-spring.datasource.db2.jdbc-url=jdbc:postgresql_postGIS://10.101.5.50:5432/water_volume_prediction?useSSL=false&useAffectedRows=false&allowMultiQueries=true
-#spring.datasource.db2.jdbc-url=jdbc:postgresql_postGIS://10.101.3.104:5432/water_volume_prediction_jiangjin?useSSL=false&useAffectedRows=false&allowMultiQueries=true
+#spring.datasource.db2.jdbc-url=jdbc:postgresql_postGIS://10.101.5.50:5432/water_volume_prediction?useSSL=false&useAffectedRows=false&allowMultiQueries=true
+spring.datasource.db2.jdbc-url=jdbc:postgresql_postGIS://10.101.3.104:5432/water_volume_prediction_jiangjin2?useSSL=false&useAffectedRows=false&allowMultiQueries=true
 spring.datasource.db2.username=postgres
-spring.datasource.db2.password=ygt.23417.postgres
-#spring.datasource.db2.password=kpr.23417.postgres
+#spring.datasource.db2.password=ygt.23417.postgres
+spring.datasource.db2.password=kpr.23417.postgres
 spring.datasource.db2.driver-class-name=org.postgis.DriverWrapper
-#spring,database.name=water_volume_prediction_jiangjin
-spring,database.name=water_volume_prediction
+spring,database.name=water_volume_prediction_jiangjin2
+#spring,database.name=water_volume_prediction
 
 spring.datasource.child2pg.jdbc-url=jdbc:postgresql_postGIS://10.101.5.50:5432/water_level_prediction?useSSL=false&useAffectedRows=false&allowMultiQueries=true
 spring.datasource.child2pg.username=postgres

+ 137 - 7
src/main/java/com/shkpr/service/aimodelpower/bizmgr/KprAimTapWaterBizFun.java

@@ -1,5 +1,6 @@
 package com.shkpr.service.aimodelpower.bizmgr;
 
+import com.alibaba.fastjson.JSONObject;
 import com.global.base.log.LogLevelFlag;
 import com.global.base.log.LogPrintMgr;
 import com.global.base.tools.FastJsonUtil;
@@ -287,7 +288,7 @@ public class KprAimTapWaterBizFun {
                 //声明总数据的数据数组
                 List<Map<String,Object>> newRecordAll = Collections.synchronizedList(new LinkedList<Map<String,Object>>());
                 //TODO ②开启多线程并发处理各水厂设备的数据
-                System.out.println("开始时间:"+TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(),TimeTool.TIMESTAMP_FORMAT));
+                System.out.println("比对远通原始数据开始时间:"+TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(),TimeTool.TIMESTAMP_FORMAT));
                 System.out.println("进行中:......");
                 final CountDownLatch latch = new CountDownLatch(configList.size());
                 for(Map<String,Object> item:configList){
@@ -296,8 +297,8 @@ public class KprAimTapWaterBizFun {
                             @Override
                             public void function() {
                                 //TODO 根据当前配置信息item 查询远通数据中的历史数据
-                                //TODO 首先查询当前水厂设备的2023-01-01之后到最新数据的数据总数,然后分页形式获取数据
-                                Integer itemCount = getWaterTapWaterApi().getTabWaterHistoryCount(" WHERE TAG_CODE = '"+item.get("collcation_tag")+"' and QCQUISITION_TIME >= to_date('2023-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')");
+                                //TODO 首先查询当前水厂设备的2025-01-01之后到最新数据的数据总数,然后分页形式获取数据
+                                Integer itemCount = getWaterTapWaterApi().getTabWaterHistoryCount(" WHERE TAG_CODE = '"+item.get("collcation_tag")+"' and QCQUISITION_TIME >= to_date('2025-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')");
                                 if(itemCount!=null&&itemCount>0) {
                                     //TODO 优化 以分页方式查询所有,初始分页行数定为2000查询速率较好
                                     int pageNum = itemCount%2000==0?itemCount/2000:(itemCount/2000)+1;//总页数
@@ -315,7 +316,7 @@ public class KprAimTapWaterBizFun {
                                         }else{
                                             limitNew = 2000;
                                         }
-                                        List<Map<String,Object>> tapWaterHistoryList = getWaterTapWaterApi().getPageZILAISHUI_HISTORY2(limitNew,offset," AND TAG_CODE = '"+item.get("collcation_tag")+"' and QCQUISITION_TIME >= to_date('2023-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')");
+                                        List<Map<String,Object>> tapWaterHistoryList = getWaterTapWaterApi().getPageZILAISHUI_HISTORY2(limitNew,offset," AND TAG_CODE = '"+item.get("collcation_tag")+"' and QCQUISITION_TIME >= to_date('2025-01-01 00:00:00', 'yyyy-mm-dd hh24:mi:ss')");
                                         if(!CollectionUtils.isEmpty(tapWaterHistoryList)){
                                             //TODO 循环远通水量数据列表,查询数据不存在的话就插入
                                             for (int j = 0; j < tapWaterHistoryList.size(); j++) {
@@ -356,7 +357,7 @@ public class KprAimTapWaterBizFun {
                     }
                 }
                 latch.await();
-                System.out.println("结束时间:"+TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(),TimeTool.TIMESTAMP_FORMAT));
+                System.out.println("比对远通原始数据结束时间:"+TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(),TimeTool.TIMESTAMP_FORMAT));
             }
         }catch(Exception ex){
             LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR
@@ -388,8 +389,8 @@ public class KprAimTapWaterBizFun {
                             @Override
                             public void function() {
                                 //TODO 根据当前配置信息item 查询远通数据中的历史数据
-                                //TODO 首先查询当前水厂设备的从2023-01-01之后到得到数据
-                                LocalDateTime startDateTime = LocalDateTime.of(2023, 01, 01, 00, 00, 00);
+                                //TODO 首先查询当前水厂设备的从2025-01-01之后到得到数据
+                                LocalDateTime startDateTime = LocalDateTime.of(2025, 01, 01, 00, 00, 00);
 
                                 //TODO 需计算的循环天数
                                 Long days = 0L;
@@ -551,4 +552,133 @@ public class KprAimTapWaterBizFun {
                             , ex.getLocalizedMessage()));
         }
     }
+
+    //TODO 初始化添加计算泵每日的小时数据
+    public static void initWaterPumpReacordAll(String startFindTime){
+        //TODO ① 首先查询水厂设备配置信息
+        try {
+
+            System.out.println("添加小时泵数据开始时间:"+ TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(),TimeTool.TIMESTAMP_FORMAT));
+            System.out.println("添加小时泵数据起始时间:("+startFindTime+")进行中:......");
+            List<Map<String, Object>> configList = getWaterTapWaterApi().getWaterPumpCollectionConfigList(null);
+            if (!CollectionUtils.isEmpty(configList)) {
+                //TODO 按照设备分组
+                Map<Object, List<Map<String, Object>>> groupedData =
+                        configList.stream().collect(Collectors.groupingBy(item -> item.get("device_code")));
+                final CountDownLatch latch = new CountDownLatch(groupedData.keySet().size());
+
+                //TODO 外层循环组织机构
+                for (Object key:groupedData.keySet()){
+                    try{
+                        new Thread(() -> {
+                            //TODO 根据当前配置信息item 查询远通数据中的历史数据
+                            //TODO 首先查询当前水厂设备的从startFindTime之后到得到数据
+                            LocalDateTime startDateTime = LocalDateTime.parse(startFindTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+
+                            //TODO 需计算的循环天数
+                            Long days = 0L;
+                            days = Duration.between(startDateTime, LocalDateTime.now()).toDays();
+                            days+=1;
+
+                            //TODO 此循环天数每一天所查的是所有设备每小时数据合
+                            final CountDownLatch latch2 = new CountDownLatch(days.intValue());
+                            for(Long k = 0L;k<days;k++) {
+                                LocalDateTime newStartDateTime = startDateTime.minusDays(-k.intValue());
+                                String startDate = newStartDateTime.format(formater);
+                                String endDate = newStartDateTime.minusDays(-1).format(formater);
+                                try {
+                                    new Thread(() -> {
+
+                                        List<Map<String, Object>> deviceList = groupedData.get(key);
+
+                                        //TODO 循环获取该天该水厂每个设备数据
+
+                                        //TODO 查询当前天日期内每小时的设备数据
+                                        for (int i = 0; i < 24; i++) {
+                                            String startTime = newStartDateTime.withHour(i).format(formater);
+                                            //TODO 需要加个05分把endTime的整点数据查出来
+                                            String endTime = newStartDateTime.minusHours(-(i + 1)).withMinute(5).withSecond(0).format(formater);
+                                            //TODO 此循环计算该小时所有设备的泵数据
+                                            for (Map<String, Object> item : deviceList) {
+                                                // 定义字符串日期时间的格式
+                                                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+                                                // 解析字符串以创建 LocalDateTime 实例
+                                                LocalDateTime dateTime = LocalDateTime.parse(endTime, formatter);
+                                                Integer itemCount = getWaterTapWaterApi().getTabWaterHistoryCount(
+                                                        " WHERE 1=1 AND TAG_CODE = '" + item.get("collcation_tag") + "' " +
+                                                                " and QCQUISITION_TIME >= to_date('" + startDate + "', 'yyyy-mm-dd hh24:mi:ss')" +
+                                                                " and QCQUISITION_TIME <= to_date('" + endDate + "', 'yyyy-mm-dd hh24:mi:ss')" +
+                                                                " AND ABS(" +
+                                                                "        (QCQUISITION_TIME - TRUNC(QCQUISITION_TIME, 'HH')) * 24 * 60 " +
+                                                                "      ) <= 5");//查询 -- 采集时间接近整点,误差在5分钟内
+                                                if (itemCount != null && itemCount > 0) {
+                                                    List<Map<String, Object>> tapWaterHistoryList = getWaterTapWaterApi().getPageZILAISHUI_HISTORY2(itemCount, 0,
+                                                            " AND TAG_CODE = '" + item.get("collcation_tag") + "' " +
+                                                                    " and QCQUISITION_TIME >= to_date('" + startTime + "', 'yyyy-mm-dd hh24:mi:ss')" +
+                                                                    " and QCQUISITION_TIME <= to_date('" + endTime + "', 'yyyy-mm-dd hh24:mi:ss')" +
+                                                                    " AND ABS( " +
+                                                                    "        (QCQUISITION_TIME - TRUNC(QCQUISITION_TIME, 'HH')) * 24 * 60 " +
+                                                                    "      ) <= 5 " +
+                                                                    " order by QCQUISITION_TIME");
+                                                    //TODO 这里需要注意泵数据的采集配置表设备号可能有多个,因此,要判断对应的standard_code做对应处理
+                                                    if (!CollectionUtils.isEmpty(tapWaterHistoryList) && tapWaterHistoryList.size() >= 1) {
+                                                        //TODO 数据库操作
+                                                        for (Map<String,Object> mapEntity:tapWaterHistoryList) {
+                                                            Map<String, Object> recordAllEntity = new HashMap<>();//需要添加的实体数据
+                                                            recordAllEntity.put("device_code", groupedData.get(key).get(0).get("device_code"));
+                                                            recordAllEntity.put("time", LocalDateTime.parse(mapEntity.get("QCQUISITION_TIME").toString(), formatter)
+                                                                    .withMinute(0).withSecond(0).format(formatter));//采集时间(小时的最后时间)
+                                                            if(item.get("standard_code").equals("active_energy")){
+                                                                recordAllEntity.put("active_energy",mapEntity.get("VAL"));
+                                                            }
+                                                            if(item.get("standard_code").equals("startup_state")){
+                                                                recordAllEntity.put("startup_state",mapEntity.get("VAL"));
+                                                            }
+                                                            if(item.get("standard_code").equals("phase_a_current")){
+                                                                if(ObjectUtils.isEmpty(mapEntity.get("VAL"))||"0".equals(mapEntity.get("VAL").toString())) {
+                                                                    recordAllEntity.put("startup_state", 0);
+                                                                }else{
+                                                                    recordAllEntity.put("startup_state", 1);
+                                                                }
+                                                            }
+                                                            //TODO 直接调用插入或者新增方法
+                                                            int insertCode = getWaterTapWaterApi().insertOrUpdateWaterPumpRecordAll(recordAllEntity);
+                                                            if (insertCode < 0) {
+                                                                System.out.print(String.format("Batch insertOrUpdateWaterPumpRecordAll 未成功:{%s} ",
+                                                                        JSONObject.toJSON(recordAllEntity)));
+                                                            }
+                                                        }
+                                                    }
+                                                }
+                                            }
+                                        }
+                                        latch2.countDown();
+
+                                    }).start();
+                                }catch(Exception ex){
+
+                                }
+                            }
+                            try {
+                                latch2.await();
+                            }catch(Exception ex){
+
+                            }
+                            latch.countDown();
+
+                        }).start();
+                    }catch(Exception ex){
+                        System.out.print(String.format("Batch" +
+                                        " initWaterReacordAll ERROR:{%s} "
+                                , ex.getLocalizedMessage()));
+                    }
+                }
+                latch.await();
+                System.out.println("添加小时泵数据检查机制("+startFindTime+")结束时间:"+TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(),TimeTool.TIMESTAMP_FORMAT));
+            }
+        }catch(Exception ex){
+            System.out.print(String.format("Batch initWaterCollecationReacordAll ERROR:{%s} "
+                    , ex.getLocalizedMessage()));
+        }
+    }
 }

+ 448 - 28
src/main/java/com/shkpr/service/aimodelpower/bizmgr/KprAimWaterCollecationBizFun.java

@@ -7,7 +7,9 @@ import com.global.base.log.LogPrintMgr;
 import com.global.base.tools.FastJsonUtil;
 import com.shkpr.service.aimodelpower.commtools.ProbabilityAlgorithm;
 import com.shkpr.service.aimodelpower.commtools.TimeTool;
+import com.shkpr.service.aimodelpower.constants.LogFlagBusiType;
 import com.shkpr.service.aimodelpower.dbdao.DBMgrProxy;
+import com.shkpr.service.aimodelpower.dbdao.shizilaishuiDataSource.WaterZILAISHUIDao;
 import com.shkpr.service.aimodelpower.dbdao.shizilaishuiDataSource.service.intef.WaterCollecationService;
 import com.shkpr.service.aimodelpower.dbdao.shizilaishuiDataSource.service.intef.WaterTapWaterService;
 import com.shkpr.service.aimodelpower.dto.ResponseCode;
@@ -18,7 +20,9 @@ import com.shkpr.service.aimodelpower.globalmgr.ThreadTaskMgr;
 import com.shkpr.service.aimodelpower.globalmgr.TraceLogMgr;
 import com.shkpr.service.aimodelpower.jsonbean.zilaishui.*;
 import com.shkpr.service.aimodelpower.services.ServiceMgrProxy;
+import org.apache.commons.collections.MapUtils;
 import org.springframework.util.CollectionUtils;
+import org.springframework.util.ObjectUtils;
 import org.springframework.util.StringUtils;
 
 import java.io.*;
@@ -29,6 +33,8 @@ import java.time.format.DateTimeFormatter;
 import java.time.temporal.TemporalAdjusters;
 import java.util.*;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.stream.Collectors;
 
@@ -333,16 +339,34 @@ public class KprAimWaterCollecationBizFun {
         }
     }
 
+    /**
+     * 通过 orgId 查找对应的 orgName
+     *
+     * @param workZoneIds Map 集合
+     * @param orgId       指定的 orgId
+     * @return Optional<String> 对应的 orgName
+     */
+    public static Optional<String> findOrgNameByOrgId(Map<String, String> workZoneIds, String orgId) {
+        return workZoneIds.entrySet()
+                .stream()
+                .filter(entry -> orgId.equals(entry.getValue())) // 过滤出值等于 orgId 的条目
+                .map(Map.Entry::getKey) // 提取键(orgName)
+                .findFirst(); // 返回第一个匹配的 orgName
+    }
+    private static double parseDouble(Object value) {
+        return value == null ? 0.0 : Double.parseDouble(value.toString());
+    }
     //TODO 查询日取水量预测接口
 
     /**
      * 1.传入水厂Id及起止日期(日期格式为YYYY-MM-DD),返回日期内,每天的预测取水量数据和实际取水量数据
      * 2.同时返回指定截止日期之后,未来4天的预测水量数据和实际水量(如没有,则返回为空数据)
      */
-    public static ResponseRes selectTbWaterList(JPTbMWater jpTbMWater){
+    public static ResponseRes selectTbWaterList(JPTbMWater jpTbMWater,Integer level,Map<String, Map<String, List<String>>> result
+    ,Map<String,String> workZonIds){
         ResponseRes responseRes = new ResponseRes();
         List<Map<String,Object>> list =new ArrayList<>();
-        if("water_volume_prediction_jiangjin".equals(databaseName)){
+        if("water_volume_prediction_jiangjin2".equals(databaseName)){
             Map<String, Object> map = new HashMap<>();
             map.put("id", null);
             map.put("date", null);
@@ -387,13 +411,113 @@ public class KprAimWaterCollecationBizFun {
         responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
         responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
         try {
-            //
-            List<Map<String, Object>> resList = getWaterTapWaterApi().getTbMWater(jpTbMWater.getIsPage(),
-                    jpTbMWater.getLimit(), jpTbMWater.getOffset(), jpTbMWater.getForDateStr());
-            if(!CollectionUtils.isEmpty(resList)){
-                responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
-                responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
-                responseRes.setResdata(resList);
+            if ("water_volume_prediction".equals(databaseName)){
+                //TODO 自来水分了二级泵房,要做查询数据处理,点击水厂查询条件时,查询其下的泵房数据 再相加,
+                //TODO 点击泵房则就查泵房的数据 ,无需做处理
+                List<String> childList = new ArrayList<>();//要查询的组织机构名称集合
+                List<String> childIdList = new ArrayList<>();//要查询的组织机构id集合
+                if (level==1){
+                    //TODO 一级已经没有数据了(水厂), 查询一级的话则是将其下的供水数据相加
+                    //TODO 查询二级,及其二级带的三级
+                    Optional zoneNameOpt = findOrgNameByOrgId(workZonIds,jpTbMWater.getOrgId());
+                    if(zoneNameOpt.isPresent()){
+                        String zoneName = zoneNameOpt.get().toString();
+                        Map<String, List<String>> childMap = result.get(zoneName);//二级
+                        Collection<List<String>> child2Map = childMap.values();//三级
+                        // 添加二级组织机构名称(childMap 的 keySet)
+                        childList.addAll(childMap.keySet());
+                        // 添加三级组织机构名称(child2Map 的所有 List<String>)
+                        for (List<String> child2List : child2Map) {
+                            childList.addAll(child2List);
+                        }
+                    }
+                }else if(level==2){
+                    //TODO 如果是二级,就查询其自身,看看其下还有没有集合,有的话就查其下的所有集合,没有的话就查其自身
+                    Optional zoneNameOpt = findOrgNameByOrgId(workZonIds,jpTbMWater.getOrgId());
+                    if(zoneNameOpt.isPresent()) {
+                        String zoneName = zoneNameOpt.get().toString();
+                        List<String> childMap = new ArrayList<>();//三级
+                        // 遍历第一级 Map
+                        for (Map.Entry<String, Map<String, List<String>>> entry : result.entrySet()) {
+                            Map<String, List<String>> nestedMap = entry.getValue();
+                            // 检查第二级键
+                            if (nestedMap.containsKey(zoneName)) {
+                                childMap = nestedMap.get(zoneName);
+                            }
+                        }
+                        if(childMap.size()>0) {
+                            // 添三级组织机构名称(childMap 的 keySet)
+                            childList.addAll(childMap);
+                        }else{
+                            childList.add(zoneName);
+                        }
+                    }
+                }else if(level==3){
+                    LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_INTERNAL.toStrValue(), mStrClassName, ""
+                            , "5555");
+                    //TODO 如果是三级,就查询其自身
+                    Optional zoneNameOpt = findOrgNameByOrgId(workZonIds,jpTbMWater.getOrgId());
+                    if(zoneNameOpt.isPresent()) {
+                        String zoneName = zoneNameOpt.get().toString();
+                        childList.add(zoneName);
+                    }
+                }
+                //TODO 开始查询
+                // 结果集合,存储 childList 对应的组织机构 ID
+                // 遍历 childList,从 workZonIds 中获取对应的 ID
+                for (String orgName : childList) {
+                    String orgId = workZonIds.get(orgName);
+                    if (orgId != null) { // 避免空值
+                        childIdList.add(orgId);
+                    }
+                }
+                List<Map<String,Object>> newResList = new ArrayList<>();
+                int index = 0;
+                for (String orgId:childIdList){
+                    jpTbMWater.setOrgId(orgId);
+                    jpTbMWater.checkValid();
+                    List<Map<String, Object>> resList = getWaterTapWaterApi().getTbMWater(jpTbMWater.getIsPage(),
+                            jpTbMWater.getLimit(), jpTbMWater.getOffset(), jpTbMWater.getForDateStr() + " ORDER BY \"Date\" ASC ");
+                    if(!CollectionUtils.isEmpty(newResList)&&!CollectionUtils.isEmpty(resList)){
+                        //TODO 说明要查询的分区不止一个,则把原来有的数据与新查的数据相加,因为按Date排了序所以一致
+                        for (int i=0;i<newResList.size();i++){
+                            newResList.get(i).put("LastActualWaterWithdrawals",
+                                    parseDouble(newResList.get(i).get("LastActualWaterWithdrawals")) +
+                                            parseDouble(resList.get(i).get("LastActualWaterWithdrawals")));
+                            newResList.get(i).put("LastActualWaterSupply",
+                                    parseDouble(newResList.get(i).get("LastActualWaterSupply")) +
+                                            parseDouble(resList.get(i).get("LastActualWaterSupply")));
+                            newResList.get(i).put("ActualWaterWithdrawals",
+                                    parseDouble(newResList.get(i).get("ActualWaterWithdrawals")) +
+                                            parseDouble(resList.get(i).get("ActualWaterWithdrawals")));
+                            newResList.get(i).put("ActualWaterSupply",
+                                    parseDouble(newResList.get(i).get("ActualWaterSupply")) +
+                                            parseDouble(resList.get(i).get("ActualWaterSupply")));
+                            newResList.get(i).put("ForecastWaterWithdrawals",
+                                    parseDouble(newResList.get(i).get("ForecastWaterWithdrawals")) +
+                                            parseDouble(resList.get(i).get("ForecastWaterWithdrawals")));
+                            newResList.get(i).put("ForecastActualWaterSupply",
+                                    parseDouble(newResList.get(i).get("ForecastActualWaterSupply")) +
+                                            parseDouble(resList.get(i).get("ForecastActualWaterSupply")));
+                        }
+                    }else {
+                        newResList.addAll(resList);
+                    }
+                    index++;
+                }
+                if (!CollectionUtils.isEmpty(newResList)) {
+                    responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
+                    responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
+                    responseRes.setResdata(newResList);
+                }
+            }else {
+                List<Map<String, Object>> resList = getWaterTapWaterApi().getTbMWater(jpTbMWater.getIsPage(),
+                        jpTbMWater.getLimit(), jpTbMWater.getOffset(), jpTbMWater.getForDateStr());
+                if (!CollectionUtils.isEmpty(resList)) {
+                    responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
+                    responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
+                    responseRes.setResdata(resList);
+                }
             }
             return responseRes;
         }catch(Exception ex){
@@ -408,10 +532,13 @@ public class KprAimWaterCollecationBizFun {
     /**
      * 传入水厂id及日期,返回指定日期内的小时取水量预测数据和实际小时取水量数据
      */
-    public static ResponseRes selectTbHourWaterList(JPTbMHourWater jpTbMHourWater){
+    public static ResponseRes selectTbHourWaterList(JPTbMHourWater jpTbMHourWater,Integer level,Map<String, Map<String, List<String>>> result
+            ,Map<String,String> workZonIds){
+        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_INTERNAL.toStrValue(), mStrClassName, ""
+                , "2222");
         ResponseRes responseRes = new ResponseRes();
         List<Map<String, Object>> list = new ArrayList<>();
-        if("water_volume_prediction_jiangjin".equals(databaseName)){
+        if("water_volume_prediction_jiangjin2".equals(databaseName)){
             Map<String, Object> map = new HashMap<>();
             map.put("id", null);
             map.put("date", null);
@@ -446,13 +573,128 @@ public class KprAimWaterCollecationBizFun {
         responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
         responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
         try {
-            //
-            List<Map<String, Object>> resList = getWaterTapWaterApi().getTbMHourwater(jpTbMHourWater.getIsPage(),
-                    jpTbMHourWater.getLimit(), jpTbMHourWater.getOffset(), jpTbMHourWater.getForDateStr());
-            if(!CollectionUtils.isEmpty(resList)){
-                responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
-                responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
-                responseRes.setResdata(resList);
+            if ("water_volume_prediction".equals(databaseName)){
+                LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_INTERNAL.toStrValue(), mStrClassName, ""
+                        , "3333");
+//TODO 自来水分了二级泵房,要做查询数据处理,点击水厂查询条件时,查询其下的泵房数据 再相加,
+                //TODO 点击泵房则就查泵房的数据 ,无需做处理
+                List<String> childList = new ArrayList<>();//要查询的组织机构名称集合
+                List<String> childIdList = new ArrayList<>();//要查询的组织机构id集合
+                if (level==1){
+                    LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_INTERNAL.toStrValue(), mStrClassName, ""
+                            , "4444");
+                    //TODO 一级已经没有数据了(水厂), 查询一级的话则是将其下的供水数据相加
+                    //TODO 查询二级,及其二级带的三级
+                    Optional zoneNameOpt = findOrgNameByOrgId(workZonIds,jpTbMHourWater.getOrgId());
+                    if(zoneNameOpt.isPresent()){
+                        String zoneName = zoneNameOpt.get().toString();
+                        Map<String, List<String>> childMap = result.get(zoneName);//二级
+                        Collection<List<String>> child2Map = childMap.values();//三级
+                        // 添加二级组织机构名称(childMap 的 keySet)
+                        childList.addAll(childMap.keySet());
+                        // 添加三级组织机构名称(child2Map 的所有 List<String>)
+                        for (List<String> child2List : child2Map) {
+                            childList.addAll(child2List);
+                        }
+                    }
+                }else if(level==2){
+                    //TODO 如果是二级,就查询其自身,看看其下还有没有集合,有的话就查其下的所有集合,没有的话就查其自身
+                    Optional zoneNameOpt = findOrgNameByOrgId(workZonIds,jpTbMHourWater.getOrgId());
+                    if(zoneNameOpt.isPresent()) {
+                        String zoneName = zoneNameOpt.get().toString();
+                        List<String> childMap = new ArrayList<>();//三级
+                        // 遍历第一级 Map
+                        for (Map.Entry<String, Map<String, List<String>>> entry : result.entrySet()) {
+                            Map<String, List<String>> nestedMap = entry.getValue();
+                            // 检查第二级键
+                            if (nestedMap.containsKey(zoneName)) {
+                                childMap = nestedMap.get(zoneName);
+                            }
+                        }
+                        if(childMap.size()>0) {
+                            // 添三级组织机构名称(childMap 的 keySet)
+                            childList.addAll(childMap);
+                        }else{
+                            childList.add(zoneName);
+                        }
+                    }
+                }else if(level==3){
+                    LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_INTERNAL.toStrValue(), mStrClassName, ""
+                            , "5555");
+                    //TODO 如果是三级,就查询其自身
+                    Optional zoneNameOpt = findOrgNameByOrgId(workZonIds,jpTbMHourWater.getOrgId());
+                    if(zoneNameOpt.isPresent()) {
+                        String zoneName = zoneNameOpt.get().toString();
+                        childList.add(zoneName);
+                    }
+                }
+                //TODO 开始查询
+                // 结果集合,存储 childList 对应的组织机构 ID
+                // 遍历 childList,从 workZonIds 中获取对应的 ID
+                for (String orgName : childList) {
+                    String orgId = workZonIds.get(orgName);
+                    if (orgId != null) { // 避免空值
+                        childIdList.add(orgId);
+                    }
+                }
+                List<Map<String,Object>> newResList = new ArrayList<>();
+                int index = 0;
+                for (String orgId:childIdList){
+                    LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_INTERNAL.toStrValue(), mStrClassName, ""
+                            , "6666");
+                    jpTbMHourWater.setOrgId(orgId);
+                    jpTbMHourWater.checkValid();
+                    List<Map<String, Object>> resList = getWaterTapWaterApi().getTbMHourwater(jpTbMHourWater.getIsPage(),
+                            jpTbMHourWater.getLimit(), jpTbMHourWater.getOffset(), jpTbMHourWater.getForDateStr()+ " ORDER BY \"Date\",\"Hour\" ASC ");
+                    if(!CollectionUtils.isEmpty(newResList)&&!CollectionUtils.isEmpty(resList)){
+                        //TODO 说明要查询的分区不止一个,则&把原来有的数据与新查的数据相加,因为按Date排了序所以一致
+                        for (int i=0;i<newResList.size();i++){
+                            newResList.get(i).put("HourForecastWaterWithdrawals",
+                                    parseDouble(newResList.get(i).get("HourForecastWaterWithdrawals")) +
+                                            parseDouble(resList.get(i).get("HourForecastWaterWithdrawals")));
+                            newResList.get(i).put("HourForecastActualWaterSupply",
+                                    parseDouble(newResList.get(i).get("HourForecastActualWaterSupply")) +
+                                            parseDouble(resList.get(i).get("HourForecastActualWaterSupply")));
+                            newResList.get(i).put("WaterWithdrawalsEnergy",
+                                    parseDouble(newResList.get(i).get("WaterWithdrawalsEnergy")) +
+                                            parseDouble(resList.get(i).get("WaterWithdrawalsEnergy")));
+                            newResList.get(i).put("WaterSupplyEnergy",
+                                    parseDouble(newResList.get(i).get("WaterSupplyEnergy")) +
+                                            parseDouble(resList.get(i).get("WaterSupplyEnergy")));
+                            newResList.get(i).put("RealWaterWithdrawalsEnergy",
+                                    parseDouble(newResList.get(i).get("RealWaterWithdrawalsEnergy")) +
+                                            parseDouble(resList.get(i).get("RealWaterWithdrawalsEnergy")));
+                            newResList.get(i).put("RealWaterSupplyEnergy",
+                                    parseDouble(newResList.get(i).get("RealWaterSupplyEnergy")) +
+                                            parseDouble(resList.get(i).get("RealWaterSupplyEnergy")));
+                            newResList.get(i).put("HourActualWaterWithdrawals",
+                                    parseDouble(newResList.get(i).get("HourActualWaterWithdrawals")) +
+                                            parseDouble(resList.get(i).get("HourActualWaterWithdrawals")));
+                            newResList.get(i).put("HourActualWaterSupply",
+                                    parseDouble(newResList.get(i).get("HourActualWaterSupply")) +
+                                            parseDouble(resList.get(i).get("HourActualWaterSupply")));
+                        }
+                    }else {
+                        newResList.addAll(resList);
+                    }
+                    index++;
+                }
+                if (!CollectionUtils.isEmpty(newResList)) {
+                    LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO, LogFlagBusiType.BUSI_INTERNAL.toStrValue(), mStrClassName, ""
+                            , "7777");
+                    responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
+                    responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
+                    responseRes.setResdata(newResList);
+                }
+            }else {
+                //
+                List<Map<String, Object>> resList = getWaterTapWaterApi().getTbMHourwater(jpTbMHourWater.getIsPage(),
+                        jpTbMHourWater.getLimit(), jpTbMHourWater.getOffset(), jpTbMHourWater.getForDateStr());
+                if (!CollectionUtils.isEmpty(resList)) {
+                    responseRes.setRescode(ResponseCode.RESULT_NORMAL.toStrCode());
+                    responseRes.setResmsg(ResponseCode.RESULT_NORMAL.toStrMsg());
+                    responseRes.setResdata(resList);
+                }
             }
             return responseRes;
         }catch(Exception ex){
@@ -476,7 +718,7 @@ public class KprAimWaterCollecationBizFun {
         entity.setPumpId(null);
         entity.setSubType(subType);
         List<Map<String, Object>> defaultRes = new ArrayList<>();
-        if("water_volume_prediction_jiangjin".equals(databaseName)){
+        if("water_volume_prediction_jiangjin2".equals(databaseName)){
             Map<String, Object> map = new HashMap<>();
             map.put("id", null);
             map.put("date", null);
@@ -568,7 +810,7 @@ public class KprAimWaterCollecationBizFun {
         entity.setPumpId(null);
         entity.setSubType(subType);
         List<Map<String, Object>> defaultRes = new ArrayList<>();
-        if("water_volume_prediction_jiangjin".equals(databaseName)){
+        if("water_volume_prediction_jiangjin2".equals(databaseName)){
             Map<String, Object> map = new HashMap<>();
             map.put("id", null);
             map.put("date", null);
@@ -607,7 +849,7 @@ public class KprAimWaterCollecationBizFun {
             //
             List<Map<String, Object>> resList = getWaterTapWaterApi().getTbMHourwaterWatersupply(jpTbMHourWater.getIsPage(),
                     jpTbMHourWater.getLimit(), jpTbMHourWater.getOffset(), jpTbMHourWater.getForDateStr());
-            if("water_volume_prediction_jiangjin".equals(databaseName)){
+            if("water_volume_prediction_jiangjin2".equals(databaseName)){
                 //TODO 按水厂分组
                 Map<Object, List<Map<String, Object>>> groupedData =
                         resList.stream().collect(Collectors.groupingBy(item -> item.get("zone_id")));
@@ -642,7 +884,6 @@ public class KprAimWaterCollecationBizFun {
                 }
                 return responseRes;
             }else {
-                //TODO 按水厂分组
                 Map<Object, List<Map<String, Object>>> groupedData =
                         resList.stream().collect(Collectors.groupingBy(item -> item.get("orgId")));
                 //TODO 查询水厂的取水泵,然后将数据拼接
@@ -900,6 +1141,111 @@ public class KprAimWaterCollecationBizFun {
         }
     }
 
+    //TODO 跑+1天
+    public static void insertYucePump(String monthNow){
+        System.out.println("添加预测泵组优化小时数据正在进行"+ TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(),TimeTool.TIMESTAMP_FORMAT));
+        try {
+            //先获取配置项 根据配置项来进行逻辑添加
+            String yearStr = "";
+            String monthStr ="";
+            if(!StringUtils.isEmpty(monthNow)){
+                yearStr = monthNow.split("-")[0];
+                monthStr = monthNow.split("-")[1];
+            }
+            LocalDateTime startDate = LocalDateTime.now().withYear(Integer.valueOf(yearStr))
+                    .withMonth(Integer.valueOf(monthStr)).withHour(0).withMinute(0).withSecond(0).withNano(0);
+
+            List<Map<String,Object>> orgConfig = getWaterTapWaterApi().getOrgConfig(false,0,0," AND org_name not like '%水厂'");
+            //TODO 总体逻辑: 先查询指定月上一年的每日平均值,再按平均值的上下啊百分比去插入指定的浮动百分比数据
+            for (int i = 0;i<1;i++){
+                LocalDateTime dateNow = startDate.minusDays(-i);//当前循环时间
+                 //TODO 数据库操作 A 调用对应时间预测接口 B 在修改实际值
+                 DateTimeFormatter formatter2 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+                 String dateStr = dateNow.withYear(LocalDateTime.now().getYear()).toLocalDate().format(formatter2);
+                 //TODO A
+                 for (Map<String,Object> org : orgConfig) {
+                     JP3TPHour tpHour = new JP3TPHour();
+                     tpHour.setOrgId(org.get("org_id").toString());
+                     tpHour.setDate(dateStr);
+                     LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_INFO
+                             , mStrClassName
+                             , mStrClassName
+                             , String.format("执行未来预测泵组优化小时数据" + FastJsonUtil.toJSON(tpHour) + "调用"));
+                     try {
+                         ResponseRes<String> tpRes = ServiceMgrProxy.getInstance()
+                                 .applyCloud3tpServiceApi().dayHourPump(tpHour);
+                         if (ResponseCode.RESULT_BAD.toStrCode().equals(tpRes.getRescode())) {
+                             LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR
+                                     , mStrClassName
+                                     , mStrClassName
+                                     , String.format("预测泵小时数据" + dateStr + "调用失败 ERROR:{%s} ",
+                                             tpRes.getResdata()));
+                         }
+                     } catch (Exception ex) {
+                         LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR
+                                 , mStrClassName
+                                 , mStrClassName
+                                 , String.format("预测泵小时数据" + dateStr + "调用异常 ERROR:{%s} ",
+                                         ex.getLocalizedMessage()));
+                     }
+                 }
+            }
+            System.out.println("调用预测模型泵组优化小时数据结束"+ TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(),TimeTool.TIMESTAMP_FORMAT));
+        }catch(Exception ex){
+            ex.printStackTrace();
+        }
+    }
+
+    //TODO 跑泵组数据插入预测实际值
+    public static void insertYucePumpReal(String monthNow,int monthDay){
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        System.out.println("添加实际值");
+        try {
+            //先获取配置项 根据配置项来进行逻辑添加
+            String yearStr = "";
+            String monthStr = "";
+            if (!StringUtils.isEmpty(monthNow)) {
+                yearStr = monthNow.split("-")[0];
+                monthStr = monthNow.split("-")[1];
+            }
+            LocalDateTime startDate = LocalDateTime.now().withYear(Integer.valueOf(yearStr))
+                    .withMonth(Integer.valueOf(monthStr)).withDayOfMonth(monthDay).withHour(0).withMinute(0).withSecond(0).withNano(0);
+            LocalDateTime endDate = LocalDateTime.now().withMinute(0).withSecond(0).withNano(0);
+            //TODO 查询开始时间开始的原始数据
+            List<Map<String,Object>> recordAllRes = getWaterTapApi()
+                    .getPumpCollectionRecordAllListAll(" WHERE 1=1 " +
+                            " AND \"time\"::timestamp BETWEEN  '"+startDate.format(formatter)+"' "+"AND '"+endDate.format(formatter)+"'");
+            for (Map<String,Object> recordAll:recordAllRes){
+                //TODO 查询对应Day和hour对应的预测数据是否存在, 存在的话就修改实际值状态
+                List<Map<String, Object>> resList = getWaterTapWaterApi().getTbMHourwaterWatersupply(true,
+                        1, 0, "AND \"PumpID\" = '"+recordAll.get("device_code")+"' AND \"Date\" = '"+LocalDateTime.parse(recordAll.get("time").toString(), formatter).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
+                        +"' AND \"Hour\" = '"+LocalDateTime.parse(recordAll.get("time").toString(), formatter).format(DateTimeFormatter.ofPattern("HH:mm:ss"))+"'");
+                if(!CollectionUtils.isEmpty(resList)){
+                    //TODO 说明存在,则修改
+                    Map<String,Object> oldMap = resList.get(0);
+                    if(!ObjectUtils.isEmpty(recordAll.get("startup_state"))){
+                        oldMap.put("RealPumpStatus",recordAll.get("startup_state"));
+                    }else if (!ObjectUtils.isEmpty(recordAll.get("active_energy"))){
+                        oldMap.put("RealPumpStatus",1);
+                    }else{
+                        oldMap.put("RealPumpStatus",0);
+                    }
+                    oldMap.remove("ID");
+                    int res = getWaterTapApi().insertOrUpdateTbmHourwaterWatersupply(oldMap);
+                    if(res<0){
+                        LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR
+                                , mStrClassName
+                                , mStrClassName
+                                ,"修改泵实际状态数据失败");
+                    }
+                }
+            }
+            System.out.println("泵数据实际值修改完成");
+        }catch(Exception ex){
+            ex.printStackTrace();
+        }
+    }
+
     //TODO 定时任务 定时添加预测数据 废弃
     public static void insertYuceDataScheduled(String monthNow){
         System.out.println("添加预测日数据正在进行"+ TimeTool.convertUTC2DateStr(TimeTool.getCurMsUTC(),TimeTool.TIMESTAMP_FORMAT));
@@ -1280,22 +1626,22 @@ public class KprAimWaterCollecationBizFun {
 //                                                            }else{
 //                                                                map.put("PumpStatus",1);
 //                                                            }
-                                                            map.put("PumpStatus",algorithm.getNextValue());
-                                                            map.put("HourForecastActualWaterSupply",splitRandomYuce.get(kIndex));//预测泵的供水量
-                                                            map.put("PumpWater",splitRandom.get(kIndex));//实际泵的供水量
+//                                                            map.put("PumpStatus",algorithm.getNextValue());
+//                                                            map.put("HourForecastActualWaterSupply",splitRandomYuce.get(kIndex));//预测泵的供水量/
+//                                                            map.put("PumpWater",splitRandom.get(kIndex));//实际泵的供水量
 //                                                            if(splitRandom.get(kIndex)==0){
 //                                                                //TODO 说明泵实际值为0,状态为关
 //                                                                map.put("RealPumpStatus",0);
 //                                                            }else{
 //                                                                map.put("RealPumpStatus",1);
 //                                                            }
-                                                            map.put("RealPumpStatus",algorithm.getNextValue());
+//                                                            map.put("RealPumpStatus",algorithm.getNextValue());
 
                                                             map.put("PumpEnergy",splitRandomYuce.get(kIndex)/1000*180);
                                                             map.put("RealPumpEnergy",splitRandom.get(kIndex)/1000*200);
-                                                            map.put("LastModifyTime", LocalDateTime.now().format(formatter));
+//                                                            map.put("LastModifyTime", LocalDateTime.now().format(formatter));
                                                             map.put("orgId", orgId);
-                                                            //TODO 添加or修改
+                                                            //TODO 添加or修改 暂时注释
                                                             Integer insertRes2 = getWaterTapApi().insertOrUpdateTbmHourwaterWatersupply(map);
                                                             if (insertRes2 < 1) {
                                                                 LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR
@@ -1416,4 +1762,78 @@ public class KprAimWaterCollecationBizFun {
             return responseRes;
         }
     }
+
+    //TODO 重新计算原始小时数据的用电量
+    //TODO 逻辑:有小时读数的 按小时读数去算, 没有的话就按额定功率*1h去作为用电量
+    public static void initPumpPowerZero(){
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        //TODO 首先查询出所有的设备
+        System.out.println("计算原始小时数据的用电量....");
+        List<Map<String, Object>> configList = getWaterTapApi().getWaterPumpCollectionConfigList("");
+        List<Map<String, Object>> energyList = getWaterTapApi().getWatertPumpEnergy("");
+        if (!CollectionUtils.isEmpty(configList) && !CollectionUtils.isEmpty(energyList)) {
+            // 按照设备分组
+            Map<Object, List<Map<String, Object>>> groupedData = configList.stream()
+                    .collect(Collectors.groupingBy(item -> item.get("device_code")));
+
+            final CountDownLatch latch = new CountDownLatch(groupedData.keySet().size());
+            ExecutorService executor = Executors.newFixedThreadPool(groupedData.keySet().size()); // 使用线程池
+
+            for (Object config : groupedData.keySet()) {
+                try {
+                    List<Map<String, Object>> recordAll = getWaterTapApi().getWaterPumpRecordAllListAll(
+                            "WHERE device_code ='" + config + "' " +
+                                    " AND \"time\"::timestamp BETWEEN  '" + LocalDateTime.now().minusDays(2).withHour(0).withMinute(0).withSecond(0).withNano(0).format(formatter) + "' " + "AND '" + LocalDateTime.now().format(formatter) + "'" +
+                                    " ORDER BY time ASC ");
+                    if (CollectionUtils.isEmpty(recordAll)) {
+                        continue; // 如果设备没有数据,跳过
+                    }
+
+                    // 遍历 recordAll 中的每条记录
+                    for (int i = 1; i < recordAll.size(); i++) {
+                        Map<String, Object> currentRecord = recordAll.get(i);
+                        Map<String, Object> previousRecord = recordAll.get(i - 1);
+
+                        Double currentEnergy = (Double) currentRecord.get("active_energy");
+                        Double previousEnergy = (Double) previousRecord.get("active_energy");
+
+                        double powerConsumption = 0.0;
+
+                        if (currentEnergy != null && previousEnergy != null) {
+                            // 情况1:累计电量读数都非空
+                            powerConsumption = currentEnergy - previousEnergy;
+                        } else {
+                            // 情况2:累计电量读数有一个为空
+                            String deviceCode = (String) currentRecord.get("device_code");
+                            Optional<Map<String, Object>> targetMap = energyList.stream()
+                                    .filter(map -> deviceCode.equals(map.get("PumpID"))) // 过滤条件
+                                    .findFirst();
+                            if (targetMap.isPresent()) {
+                                Map<String, Object> resultMap = targetMap.get();
+                                Object ratedPower = resultMap.get(deviceCode);
+                                if (ratedPower != null) {
+                                    powerConsumption = Double.valueOf(ratedPower.toString()) * 1; // 用电量 = 额定功率 × 1
+                                } else {
+                                    powerConsumption = 0.0; // 额定功率未找到,用电量为 0
+                                }
+                            } else {
+                                powerConsumption = 500 + (Math.random() - 0.5) * 200; // 额定功率未找到,用电量为 0
+                            }
+                        }
+
+                        // 更新当前记录的用电量字段
+                        currentRecord.put("power_cons", powerConsumption);
+                        int res = getWaterTapApi().insertOrUpdateWaterPumpRecordAll(currentRecord);
+                        if (res <= 0) {
+                            System.out.println("修改小时用电量失败");
+                        }
+                    }
+                } catch (Exception ex) {
+
+                }
+            }
+            System.out.println("修改小时用电量完成");
+        }
+
+    }
 }

+ 39 - 0
src/main/java/com/shkpr/service/aimodelpower/commtools/ProbabilityAlgorithm.java

@@ -0,0 +1,39 @@
+package com.shkpr.service.aimodelpower.commtools;
+
+import java.util.Random;
+
+/**
+ * @ClassName ProbabilityAlgorithm
+ * @Description: TODO
+ * @Author LX
+ * @Date 2024/12/23
+ * @Version V1.0
+ **/
+public class ProbabilityAlgorithm {
+    private final Random random;
+    private final double probabilityOfOne;
+
+    /**
+     * 构造函数
+     *
+     * @param probabilityOfOne 1出现的概率,应该在0到1之间
+     */
+    public ProbabilityAlgorithm(double probabilityOfOne) {
+        if (probabilityOfOne < 0 || probabilityOfOne > 1) {
+            throw new IllegalArgumentException("Probability must be between 0 and 1");
+        }
+        this.random = new Random();
+        this.probabilityOfOne = probabilityOfOne;
+    }
+
+    /**
+     * 获取返回值0或1
+     *
+     * @return 0或1,基于设定的概率
+     */
+    public int getNextValue() {
+        double rand = random.nextDouble();
+        return (rand < probabilityOfOne) ? 1 : 0;
+    }
+
+}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 346 - 56
src/main/java/com/shkpr/service/aimodelpower/controllerapi/WaterCollecationController.java


+ 4 - 4
src/main/java/com/shkpr/service/aimodelpower/dbdao/shizilaishuiDataSource/WaterCollecationDao.java

@@ -33,7 +33,7 @@ public class WaterCollecationDao {
     //TODO 查询样本及预测水量表;支持是否分页
     public List<Map<String,Object>> getTbMWater(boolean isPage,int limit,int offset,String extend){
             String sql = "";
-            if ("water_volume_prediction_jiangjin".equals(KprAimWaterCollecationBizFun.databaseName)){
+            if ("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
                 sql = "SELECT " +
                         " a.\"id\",to_char(a.\"date\", 'YYYY-MM-DD') AS \"date\",a.\"max_temperature\",a.\"min_temperature\",a.\"weather\",a.\"month\",a.\"week\",a.\"holiday\",a.\"last_actual_water_withdrawals\",a.\"last_actual_water_supply\",a.\"actual_water_withdrawals\",a.\"actual_water_supply\",a.\"forecast_water_withdrawals\",a.\"forecast_actual_water_supply\",a.\"is_abnormal\",a.\"is_forecast\",a.\"last_modify_time\",a.\"zone_id\" " +
                         " FROM tb_m_water AS a WHERE 1=1 ";
@@ -57,7 +57,7 @@ public class WaterCollecationDao {
     //TODO 查询小时水量预测表;支持是否分页
     public List<Map<String,Object>> getTbMHourwater(boolean isPage,int limit,int offset,String extend){
             String sql = "";
-            if ("water_volume_prediction_jiangjin".equals(KprAimWaterCollecationBizFun.databaseName)){
+            if ("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
                 sql = "SELECT " +
                         " a.\"id\",to_char(a.\"date\", 'YYYY-MM-DD') AS \"date\",a.\"hour\",a.\"hour_forecast_water_withdrawals\",a.\"hour_forecast_actual_water_supply\",a.\"water_withdrawals_energy\",a.\"water_supply_energy\",a.\"real_water_withdrawals_energy\",a.\"real_water_supply_energy\",a.\"last_modify_time\",a.\"zone_id\"," +
                         " a.\"hour_actual_water_withdrawals\",a.\"hour_actual_water_supply\" " +
@@ -83,7 +83,7 @@ public class WaterCollecationDao {
     //TODO 查询取水泵房电耗预测接口,支持是否分页
     public List<Map<String,Object>> getTbMHourwaterWaterwithdrawals(boolean isPage,int limit,int offset,String extend){
             String sql = "";
-            if ("water_volume_prediction_jiangjin".equals(KprAimWaterCollecationBizFun.databaseName)){
+            if ("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
                 sql = "SELECT " +
                         " to_char(a.\"date\", 'YYYY-MM-DD') AS \"date\",a.\"hour\",a.\"pump_id\",a.\"pump_status\",a.\"hour_forecast_water_withdrawals\",a.\"pump_water\",a.\"real_pump_status\",a.\"pump_energy\",a.\"real_pump_energy\",a.\"last_modify_time\",a.\"id\",a.\"zone_id\" " +
                         " FROM tb_m_hourwater_waterwithdrawals AS a WHERE 1=1 ";
@@ -107,7 +107,7 @@ public class WaterCollecationDao {
     //TODO 查询供水泵房电耗预测接口,支持是否分页
     public List<Map<String,Object>> getTbMHourwaterWatersupply(boolean isPage,int limit,int offset,String extend){
             String sql = "";
-            if ("water_volume_prediction_jiangjin".equals(KprAimWaterCollecationBizFun.databaseName)){
+            if ("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
                 sql = "SELECT " +
                         " a.\"id\",to_char(a.\"date\", 'YYYY-MM-DD') AS \"date\",a.\"hour\",a.\"pump_id\",a.\"pump_status\",a.\"hour_forecast_actual_water_supply\",a.\"pump_water\",a.\"real_pump_status\",a.\"pump_energy\",a.\"real_pump_energy\",a.\"last_modify_time\",a.\"zone_id\" " +
                         " FROM tb_m_hourwater_watersupply AS a WHERE 1=1 ";

+ 191 - 4
src/main/java/com/shkpr/service/aimodelpower/dbdao/shizilaishuiDataSource/WaterZILAISHUIDao.java

@@ -1,5 +1,6 @@
 package com.shkpr.service.aimodelpower.dbdao.shizilaishuiDataSource;
 
+import com.shkpr.service.aimodelpower.bizmgr.KprAimWaterCollecationBizFun;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
@@ -10,6 +11,7 @@ import org.springframework.util.StringUtils;
 
 import javax.annotation.Resource;
 import javax.sql.DataSource;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
@@ -35,6 +37,9 @@ public class WaterZILAISHUIDao {
     public Integer getTabWaterHistoryCount(String extend){
         try {
             String sql = "select count(1)  from cqda.V_SHIZILAISHUI_HISTORY2 ";
+            if("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
+                sql = "select count(1)  from cqda.V_JIANGJIN_HISTORY";
+            }
             if(!StringUtils.isEmpty(extend)){
                 sql += extend;
             }
@@ -47,16 +52,22 @@ public class WaterZILAISHUIDao {
     //TODO 分页获取历史水量数据
     public List<Map<String,Object>> getPageZILAISHUI_HISTORY2(int limit,int offset,String extend){
         try {
+            String tableName = "cqda.V_SHIZILAISHUI_HISTORY2";
+            String filedOrgName = "NAMA";
+            if("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
+                tableName = "cqda.V_JIANGJIN_HISTORY ";
+                filedOrgName = "ORG_NAME";
+            }
             String sql = "select " +
-                    " a.TAG_CODE,a.NAME,a.VAL,TO_CHAR(a.QCQUISITION_TIME,'yyyy-mm-dd hh24:mi:ss') AS QCQUISITION_TIME," +
+                    " a.TAG_CODE,a."+filedOrgName+",a.VAL,TO_CHAR(a.QCQUISITION_TIME,'yyyy-mm-dd hh24:mi:ss') AS QCQUISITION_TIME," +
                     " TO_CHAR(a.UPDATE_TIME,'yyyy-mm-dd hh24:mi:ss') AS UPDATE_TIME " +
-                    " from ( select t.*,rownum AS rownumber from cqda.V_SHIZILAISHUI_HISTORY2  t where rownum <= "+limit+") a " +
+                    " from ( select t.*,rownum AS rownumber from "+tableName+"  t where rownum <= "+limit+") a " +
                     " where rownumber > "+offset;
             if (!StringUtils.isEmpty(extend)) {
                 sql = "select " +
-                        " a.TAG_CODE,a.NAME,a.VAL,TO_CHAR(a.QCQUISITION_TIME,'yyyy-mm-dd hh24:mi:ss') AS QCQUISITION_TIME," +
+                        " a.TAG_CODE,a."+filedOrgName+",a.VAL,TO_CHAR(a.QCQUISITION_TIME,'yyyy-mm-dd hh24:mi:ss') AS QCQUISITION_TIME," +
                         " TO_CHAR(a.UPDATE_TIME,'yyyy-mm-dd hh24:mi:ss') AS UPDATE_TIME " +
-                        " from ( select t.*,rownum AS rownumber from cqda.V_SHIZILAISHUI_HISTORY2  t where rownum <= "+limit+" "+extend+") a " +
+                        " from ( select t.*,rownum AS rownumber from "+tableName+"  t where rownum <= "+limit+" "+extend+") a " +
                         " where rownumber >"+offset;
             }
             List<Map<String, Object>> tableData = oneTemplate.queryForList(sql);
@@ -128,6 +139,19 @@ public class WaterZILAISHUIDao {
             return null;
         }
     }
+    public List<Map<String,Object>> getPumpCollectionRecordAllListAll(String extend){
+        try{
+            String sql = "SELECT * FROM water_pump_record_all ";
+            if(!StringUtils.isEmpty(extend)){
+                sql += extend;
+            }
+            JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
+            List<Map<String,Object>> tableData = pgJdbc.queryForList(sql);
+            return tableData;
+        }catch(Exception ex){
+            return null;
+        }
+    }
 
     //TODO 插入自来水历史记录表
     public int insertWaterCollectionRecord(String extend){
@@ -416,4 +440,167 @@ public class WaterZILAISHUIDao {
             return -1;
         }
     }
+
+    /**
+     * TODO 泵组优化相关
+     */
+    //TODO 获取泵数据采集配置
+    public List<Map<String,Object>> getWaterPumpCollectionConfigList(String extend){
+        try{
+            String sql = "SELECT * FROM water_pump_collection_config ";
+            if(!StringUtils.isEmpty(extend)){
+                sql+=extend;
+            }
+            JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
+            List<Map<String, Object>> tableData = pgJdbc.queryForList(sql);
+            return tableData;
+        }catch(Exception ex){
+            return null;
+        }
+    }
+
+    //TODO 查询市自来水小时泵数据记录表·分页
+    public List<Map<String,Object>> getWaterPumpRecordAllList(int limit,int offset,String extend){
+        try{
+            String sql = "SELECT * FROM water_pump_record_all ";
+            if(!StringUtils.isEmpty(extend)){
+                sql += extend;
+            }
+            sql += " LIMIT " + limit + " OFFSET "+ offset;
+            JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
+            List<Map<String,Object>> tableData = pgJdbc.queryForList(sql);
+            return tableData;
+        }catch(Exception ex){
+            return null;
+        }
+    }
+
+    //TODO 查询市自来水小时泵数据记录表·不分页
+    public List<Map<String,Object>> getWaterPumpRecordAllListAll(String extend){
+        try{
+            String sql = "SELECT * FROM water_pump_record_all ";
+            if(!StringUtils.isEmpty(extend)){
+                sql += extend;
+            }
+            JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
+            List<Map<String,Object>> tableData = pgJdbc.queryForList(sql);
+            return tableData;
+        }catch(Exception ex){
+            return null;
+        }
+    }
+
+    public List<Map<String,Object>> getWatertPumpEnergy(String extend){
+        try{
+            String sql = "SELECT * FROM tb_m_pump_energy ";
+            if(!StringUtils.isEmpty(extend)){
+                sql += extend;
+            }
+            JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
+            List<Map<String,Object>> tableData = pgJdbc.queryForList(sql);
+            return tableData;
+        }catch(Exception ex){
+            return null;
+        }
+    }
+
+    //TODO 插入或修改自来水小时泵数据记录表
+    public int insertOrUpdateWaterPumpRecordAll(Map<String, Object> value) {
+        if (ObjectUtils.isEmpty(value) || ObjectUtils.isEmpty(value.get("device_code")) || ObjectUtils.isEmpty(value.get("time"))) {
+            // 确保 device_code 和 time 不为空,因为它们是复合键
+            return -1;
+        }
+
+        try {
+            StringBuilder sql = new StringBuilder("INSERT INTO water_pump_record_all (device_code, time");
+
+            // 动态添加字段
+            if (!ObjectUtils.isEmpty(value.get("active_energy"))) {
+                sql.append(", active_energy");
+            }
+            if (!ObjectUtils.isEmpty(value.get("startup_state"))) {
+                sql.append(", startup_state");
+            }
+            if (!ObjectUtils.isEmpty(value.get("power_cons"))) {
+                sql.append(", power_cons");
+            }
+
+            sql.append(") VALUES (?, ?");
+
+            // 动态添加占位符
+            if (!ObjectUtils.isEmpty(value.get("active_energy"))) {
+                sql.append(", ?");
+            }
+            if (!ObjectUtils.isEmpty(value.get("startup_state"))) {
+                sql.append(", ?");
+            }
+            if (!ObjectUtils.isEmpty(value.get("power_cons"))) {
+                sql.append(", ?");
+            }
+
+            sql.append(") ON CONFLICT (device_code, time) DO UPDATE SET ");
+
+            // 动态添加更新字段
+            boolean firstUpdateField = true;
+            if (!ObjectUtils.isEmpty(value.get("active_energy"))) {
+                if (!firstUpdateField) {
+                    sql.append(", ");
+                }
+                sql.append("active_energy = EXCLUDED.active_energy");
+                firstUpdateField = false;
+            }
+            if (!ObjectUtils.isEmpty(value.get("startup_state"))) {
+                if (!firstUpdateField) {
+                    sql.append(", ");
+                }
+                firstUpdateField = false;
+                sql.append("startup_state = EXCLUDED.startup_state");
+            }
+            if (!ObjectUtils.isEmpty(value.get("power_cons"))) {
+                if (!firstUpdateField) {
+                    sql.append(", ");
+                }
+                sql.append("power_cons = EXCLUDED.power_cons");
+            }
+
+            // 准备参数
+            List<Object> params = new ArrayList<>();
+            params.add(value.get("device_code"));
+            params.add(value.get("time"));
+            if (!ObjectUtils.isEmpty(value.get("active_energy"))) {
+                params.add(value.get("active_energy"));
+            }
+            if (!ObjectUtils.isEmpty(value.get("startup_state"))) {
+                params.add(value.get("startup_state"));
+            }
+            if (!ObjectUtils.isEmpty(value.get("power_cons"))) {
+                params.add(value.get("power_cons"));
+            }
+
+            // 执行 SQL 语句
+            JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
+            return pgJdbc.update(sql.toString(), params.toArray());
+
+        } catch (Exception ex) {
+            return -1;
+        }
+    }
+
+
+    //TODO 修改自来水小时泵数据记录表value
+    public int updateWaterPumpRecordAll(String value,String extend){
+        try{
+            String sql = "UPDATE water_level_record_all " +
+                    " SET \"value\" =  "+value+" " +
+                    " ";
+            if(!StringUtils.isEmpty(extend)){
+                sql = sql +extend;
+            }
+            JdbcTemplate pgJdbc = new JdbcTemplate(childDataSource);
+            Integer resCode = pgJdbc.update(sql);
+            return resCode;
+        }catch(Exception ex){
+            return -1;
+        }
+    }
 }

+ 48 - 0
src/main/java/com/shkpr/service/aimodelpower/dbdao/shizilaishuiDataSource/service/WaterTapWaterServiceImpl.java

@@ -142,6 +142,24 @@ public class WaterTapWaterServiceImpl implements WaterTapWaterService {
         }
         return arrRes;
     }
+    public List<Map<String, Object>> getPumpCollectionRecordAllListAll( String extend) {
+        int nCode = 0;
+        String strMsg = "Success";
+        List<Map<String, Object>> arrRes = null;
+        try {
+            arrRes = waterZILAISHUIDao.getPumpCollectionRecordAllListAll(extend);
+        }catch (Exception e){
+            nCode = LogLevelFlag.LOG_ERROR.ordinal();
+            strMsg = e.getLocalizedMessage();
+        }finally {
+//            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.valueFromInt(nCode)
+//                    , LogFlagBusiType.BUSI_CHILD_DB_TAP_WATER.toStrValue()
+//                    , mStrClassName
+//                    , String.format("Batch Query TabWaterHistory from database, code:{%d} msg:{%s} ..."
+//                            , nCode, strMsg));
+        }
+        return arrRes;
+    }
 
     @Override
     public Integer insertWaterCollectionRecord(String extend) {
@@ -310,4 +328,34 @@ public class WaterTapWaterServiceImpl implements WaterTapWaterService {
         }
         return arrRes;
     }
+
+    @Override
+    public List<Map<String, Object>> getWaterPumpCollectionConfigList(String extend) {
+        return waterZILAISHUIDao.getWaterPumpCollectionConfigList(extend);
+    }
+
+    @Override
+    public List<Map<String, Object>> getWaterPumpRecordAllList(int limit, int offset, String extend) {
+        return waterZILAISHUIDao.getWaterPumpRecordAllList(limit, offset, extend);
+    }
+
+    @Override
+    public List<Map<String, Object>> getWaterPumpRecordAllListAll(String extend) {
+        return waterZILAISHUIDao.getWaterPumpRecordAllListAll(extend);
+    }
+
+    @Override
+    public List<Map<String, Object>> getWatertPumpEnergy(String extend) {
+        return waterZILAISHUIDao.getWatertPumpEnergy(extend);
+    }
+
+    @Override
+    public int insertOrUpdateWaterPumpRecordAll(Map<String,Object> value) {
+        return waterZILAISHUIDao.insertOrUpdateWaterPumpRecordAll(value);
+    }
+
+    @Override
+    public int updateWaterPumpRecordAll(String value, String extend) {
+        return waterZILAISHUIDao.updateWaterPumpRecordAll(value, extend);
+    }
 }

+ 13 - 0
src/main/java/com/shkpr/service/aimodelpower/dbdao/shizilaishuiDataSource/service/intef/WaterTapWaterService.java

@@ -21,6 +21,8 @@ public interface WaterTapWaterService {
     public List<Map<String,Object>> getWaterCollectionRecordAllList(int limit,int offset,String extend);
     //TODO pgsql 查询市自来水小时用水量记录表·不分页
     public List<Map<String,Object>> getWaterCollectionRecordAllListAll(String extend);
+    //TODO pgsql 查询市自来水小时泵原始数据记录表·不分页
+    public List<Map<String,Object>> getPumpCollectionRecordAllListAll(String extend);
 
     //TODO pgsql 插入自来水历史记录表
     public Integer insertWaterCollectionRecord(String extend);
@@ -39,4 +41,15 @@ public interface WaterTapWaterService {
     public Integer insertOrUpdateTbmHourWater(Map<String,Object> value);
     //TODO 添加或修改日小时开泵预测表
     public Integer insertOrUpdateTbmHourwaterWatersupply(Map<String,Object> value);
+
+    /**
+     * TODO 泵组优化相关
+     */
+    //TODO 获取泵数据采集配置
+    public List<Map<String,Object>> getWaterPumpCollectionConfigList(String extend);
+    public List<Map<String,Object>> getWaterPumpRecordAllList(int limit,int offset,String extend);
+    public List<Map<String,Object>> getWaterPumpRecordAllListAll(String extend);
+    public List<Map<String,Object>> getWatertPumpEnergy(String extend);
+    public int insertOrUpdateWaterPumpRecordAll(Map<String,Object> value);
+    public int updateWaterPumpRecordAll(String value,String extend);
 }

+ 151 - 28
src/main/java/com/shkpr/service/aimodelpower/globalmgr/ScheduleTaskMgr.java

@@ -24,6 +24,7 @@ import java.sql.Time;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.TemporalAdjusters;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -127,7 +128,37 @@ public class ScheduleTaskMgr {
     public void executeTbMHourWaterNow() {
         String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
         KprAimWaterCollecationBizFun.insertYuceHourAddData(time);
-        KprAimWaterCollecationBizFun.insertYuceHourDataScheduled(time);
+//        KprAimWaterCollecationBizFun.insertYuceHourDataScheduled(time);
+    }
+
+    //TODO 每天每小时的20分执行预测当前月泵的日小时用电量数据
+    @Scheduled(cron = "0 20 * * * *")
+    public void executeTbMHourPumpPower() {
+        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
+        //TODO 实际调用调度模型的接口
+        KprAimWaterCollecationBizFun.initPumpPowerZero();
+    }
+    //TODO 每天每小时的25分执行预测当前月泵的日小时数据
+    @Scheduled(cron = "0 25 * * * *")
+    public void executeTbMHourPumpNow() {
+        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
+        //TODO 实际调用调度模型的接口
+        KprAimWaterCollecationBizFun.insertYucePump(time);
+    }
+    @Scheduled(cron = "0 35 * * * *")
+    public void executeTbMHour35PumpNow() {
+        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
+        //TODO 实际调用调度模型的接口
+        KprAimWaterCollecationBizFun.insertYucePump(time);
+    }
+    //TODO 每天每五分钟执行预测当前月泵的日实际小时数据
+    @Scheduled(cron = "0 30 * * * *")
+    public void executeTbMHourRealPumpNow() {
+        String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
+//                KprAimWaterCollecationBizFun.insertYuceHourData(time);
+        //TODO 实际调用调度模型的接口
+        KprAimWaterCollecationBizFun.insertYucePumpReal(time,LocalDateTime.now().getDayOfMonth());
+//        KprAimWaterCollecationBizFun.initPumpPowerCons();
     }
 
     //TODO 启动时执行 测试方法
@@ -146,31 +177,50 @@ public class ScheduleTaskMgr {
 //    }
 
 
-    //TODO 启动时执行一次 江津的就给注释掉
-//    @PostConstruct
-//    public void initOneTapWater(){
-//        Timer timer = new Timer();
-//        // 创建定时器任务
-//        TimerTask timerTask = new TimerTask() {
-//            @Override
-//            public void run() {
-//                KprAimTapWaterBizFun.initTapWaterData();
-//            }
-//        };
-//        timer.schedule(timerTask, 10000); // 10秒后执行一次
-//    }
-//
-//    @PostConstruct
-//    public void initWaterRecordAll(){
-//        Timer timer = new Timer();
-//        TimerTask timerTask1 = new TimerTask() {
-//            @Override
-//            public void run() {
-//                KprAimTapWaterBizFun.initWaterCollecationReacordAll();
-//            }
-//        };
-//        timer.schedule(timerTask1,11000);//11秒后执行一次
-//    }
+    //TODO 启动时执行一次一年的小时水量和原始水量数据
+    @PostConstruct
+    public void initOneTapWater(){
+        Timer timer = new Timer();
+        // 创建定时器任务
+        TimerTask timerTask = new TimerTask() {
+            @Override
+            public void run() {
+                KprAimTapWaterBizFun.initTapWaterData();
+            }
+        };
+        timer.schedule(timerTask, 10000); // 10秒后执行一次
+
+        Timer timer2 = new Timer();
+        // 创建定时器任务
+        TimerTask timerTask2 = new TimerTask() {
+            @Override
+            public void run() {
+                KprAimTapWaterBizFun.checkRecordData();
+            }
+        };
+        timer2.schedule(timerTask2, 10000); // 10秒后执行一次
+    }
+
+    @PostConstruct
+    public void initWaterRecordAll(){
+        Timer timer = new Timer();
+        TimerTask timerTask1 = new TimerTask() {
+            @Override
+            public void run() {
+                KprAimTapWaterBizFun.initWaterCollecationReacordAll();
+            }
+        };
+        timer.schedule(timerTask1,11000);//11秒后执行一次
+
+        Timer timer2 = new Timer();
+        TimerTask timerTask2 = new TimerTask() {
+            @Override
+            public void run() {
+                KprAimTapWaterBizFun.checkRecordAllData();
+            }
+        };
+        timer2.schedule(timerTask2,11000);//11秒后执行一次
+    }
 
     @PostConstruct
     public void initWaterDay(){
@@ -179,7 +229,7 @@ public class ScheduleTaskMgr {
             @Override
             public void run() {
                 String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
-                KprAimWaterCollecationBizFun.insertYuceDayData(time);
+//                KprAimWaterCollecationBizFun.insertYuceDayData(time);
                 KprAimWaterCollecationBizFun.insertYuceDayAddData(time);
             }
         };
@@ -195,11 +245,84 @@ public class ScheduleTaskMgr {
                 String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
 //                KprAimWaterCollecationBizFun.insertYuceHourData(time);
                 KprAimWaterCollecationBizFun.insertYuceHourAddData(time);
-                KprAimWaterCollecationBizFun.insertYuceHourDataScheduled(time);//江津的给注释掉
+                //TODO 实际调用调度模型的接口
+//                KprAimWaterCollecationBizFun.insertYucePump(time);
             }
         };
         timer.schedule(timerTask1,9000);//9秒后执行一次
+        Timer timer2 = new Timer();
+        TimerTask timerTask2 = new TimerTask() {
+            @Override
+            public void run() {
+                String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
+//                KprAimWaterCollecationBizFun.insertYuceHourDataScheduled(time);//江津的给注释掉
+            }
+        };
+        timer2.schedule(timerTask2,9000);//9秒后执行一次
     }
+    //TODO 启动时跑今天泵的数据,江津的先注释
+//    @PostConstruct
+//    public void initPumpFourDay(){
+//        Timer timer = new Timer();
+//        TimerTask timerTask1 = new TimerTask() {
+//            @Override
+//            public void run() {
+//                String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
+////                KprAimWaterCollecationBizFun.insertYuceHourData(time);
+//                //TODO 实际调用调度模型的接口
+//                KprAimWaterCollecationBizFun.insertYucePumpReal(time,1);
+//            }
+//        };
+//        timer.schedule(timerTask1,9000);//9秒后执行一次
+//    }
+//
+//    @PostConstruct
+//    public void initPumpPowerCons(){
+//        Timer timer = new Timer();
+//        TimerTask timerTask1 = new TimerTask() {
+//            @Override
+//            public void run() {
+//                String time = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM"));
+////                KprAimWaterCollecationBizFun.insertYuceHourData(time);
+//                //TODO 实际调用调度模型的接口
+//                KprAimWaterCollecationBizFun.initPumpPowerZero();
+//                KprAimWaterCollecationBizFun.insertYucePump(time);
+//            }
+//        };
+//        timer.schedule(timerTask1,9000);//9秒后执行一次
+//    }
+
+    //TODO 自来水的注释以下俩方法initPumpRecordAll checkPumpRecordAll
+    @PostConstruct
+    public void initPumpRecordAll(){
+        new Timer().schedule(new TimerTask() {
+            @Override
+            public void run() {
+                //当前时间到去年对应月份1号0点开始
+                LocalDateTime firstDayOfLastMonth = LocalDateTime.now().minusMonths(1) // 减去一个月
+                        .toLocalDate()   // 转换为 LocalDate
+                        .withDayOfMonth(1) // 设置为当月的第一天
+                        .atStartOfDay(); // 转换为当天的起始时间
+                String formattedDate = firstDayOfLastMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                KprAimTapWaterBizFun.initWaterPumpReacordAll(formattedDate);
+            }
+        },5000);
+    }
+
+    //TODO 每小时的10分执行原始小时泵数据计算
+    @Scheduled(cron = "0 10 * * * *")
+    public void checkPumpRecordAll(){
+        new Timer().schedule(new TimerTask() {
+            @Override
+            public void run() {
+                //当前时间到今天的0点开始
+                LocalDateTime firstDayOfLastMonth = LocalDate.now().atStartOfDay();//上个月0点
+                String formattedDate = firstDayOfLastMonth.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+                KprAimTapWaterBizFun.initWaterPumpReacordAll(formattedDate);
+            }
+        },5000);
+    }
+
     @PostConstruct
     public void initDatabaseName(){
         Timer timer = new Timer();

+ 1 - 1
src/main/java/com/shkpr/service/aimodelpower/jsonbean/zilaishui/JPTbMHourWater.java

@@ -41,7 +41,7 @@ public class JPTbMHourWater {
     private String forDateStr;
 
     public boolean checkValid(){
-        if ("water_volume_prediction_jiangjin".equals(KprAimWaterCollecationBizFun.databaseName)) {
+        if ("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)) {
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
             StringBuilder strSql = new StringBuilder("");
             if (!StringUtils.isEmpty(orgId)) {

+ 1 - 1
src/main/java/com/shkpr/service/aimodelpower/jsonbean/zilaishui/JPTbMWater.java

@@ -41,7 +41,7 @@ public class JPTbMWater {
     private String forDateStr;
 
     public boolean checkValid(){
-        if ("water_volume_prediction_jiangjin".equals(KprAimWaterCollecationBizFun.databaseName)){
+        if ("water_volume_prediction_jiangjin2".equals(KprAimWaterCollecationBizFun.databaseName)){
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
             if (startDate == null && endDate != null) {
                 return false;

+ 23 - 0
src/main/java/com/shkpr/service/aimodelpower/services/Cloud3tpService.java

@@ -49,6 +49,7 @@ public class Cloud3tpService {
 
     private String mDayDataSupply = "";
     private String mHourDataSupply = "";
+    private String mHourPump = "";
     private HttpHeaders headers = null;
 
     @PostConstruct
@@ -58,6 +59,7 @@ public class Cloud3tpService {
             mStrAddress += "/";
         mDayDataSupply = String.format("%s%s", mStrAddress, "PredictSupply");//预测日供水数据
         mHourDataSupply = String.format("%s%s", mStrAddress, "PredictHour");//预测小时供水数据
+        mHourPump = String.format("%s%s", mStrAddress, "PumpScheduling");//预测小时泵组优化预测数据
 
         headers = new HttpHeaders();
         headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
@@ -112,4 +114,25 @@ public class Cloud3tpService {
         return resResult;
     }
 
+    public ResponseRes<String> dayHourPump(final JP3TPHour jsonParam) throws Exception{
+        ResponseRes<String> resResult = new ResponseRes<String>();
+        resResult.setRescode(ResponseCode.RESULT_BAD.toStrCode());
+        resResult.setResmsg(MSG_FAILED);
+        resResult.setResdata("");
+
+        HttpEntity<String> request = new HttpEntity<>(jsonParam.toJsonStr(), headers);
+        try {
+            ResponseEntity<String> response = restTemplate.postForEntity(mHourPump, request, String.class);
+            if (response.getStatusCode() == HttpStatus.OK){
+                String strBody = response.getBody();
+                return FastJsonUtil.fromJSONByGson(strBody, ResponseRes.class);
+            }
+        }catch (Exception e){
+            LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_WARN, LogFlagBusiType.BUSI_CALL_DATA_AS.toStrValue(), strClassName, String.format("dayHourPredictSupply from Cloud3tpService(url:%s) failed(%s)...", mHourDataSupply, e.getMessage()));
+            //达到maxAttempts次数将返回RemoteAccessException
+            throw new RemoteAccessException("Retry...");
+        }
+        return resResult;
+    }
+
 }

Dosya farkı çok büyük olduğundan ihmal edildi
+ 9 - 3
src/main/resources/application.properties