|
@@ -1,5 +1,7 @@
|
|
|
package com.shkpr.service.aimodelpower.bizmgr;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.global.base.log.LogLevelFlag;
|
|
|
import com.global.base.log.LogPrintMgr;
|
|
|
import com.global.base.tools.FastJsonUtil;
|
|
@@ -45,6 +47,255 @@ public class KprAimWaterCollecationBizFun {
|
|
|
private static final String mStrClassName = "KprAimTapWaterBizFun";
|
|
|
private static final String EMPTY_NULL = "NULL";
|
|
|
|
|
|
+ static JSONObject pumpObj = JSONObject.parseObject("{\n" +
|
|
|
+ " \"UZD299F12944DC10957HJ\": {\n" +
|
|
|
+ " \"outRoom\": {\n" +
|
|
|
+ " \"pumps\": [\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"1\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"2\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"3\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"4\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"5\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"6\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"7\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " }\n" +
|
|
|
+ " ]\n" +
|
|
|
+ " }\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"UZD299F12DF5241082772\": {\n" +
|
|
|
+ " \"outRoom\": {\n" +
|
|
|
+ " \"pumps\": [\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"1\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"2\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"3\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"4\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"5\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"6\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"7\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"8\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"9\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"10\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " }\n" +
|
|
|
+ " ]\n" +
|
|
|
+ " }\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"UZD299F1301D04107668V\": {\n" +
|
|
|
+ " \"outRoom\": {\n" +
|
|
|
+ " \"pumps\": [\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"1\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"2\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"3\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"4\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"5\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"6\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"7\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"8\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " }\n" +
|
|
|
+ " ]\n" +
|
|
|
+ " }\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"UZD299F133DE5C1066A5L\": {\n" +
|
|
|
+ " \"outRoom\": {\n" +
|
|
|
+ " \"pumps\": [\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"1\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"2\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"3\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"4\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"5\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"6\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " }\n" +
|
|
|
+ " ]\n" +
|
|
|
+ " }\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"UZD299F1389E6010476AV\": {\n" +
|
|
|
+ " \"outRoom\": {\n" +
|
|
|
+ " \"pumps\": [\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"1\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"2\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"3\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"4\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"5\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"6\",\n" +
|
|
|
+ " \"status\": 0,\n" +
|
|
|
+ " \"forecastStatus\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"7\",\n" +
|
|
|
+ " \"status\": 1,\n" +
|
|
|
+ " \"forecastStatus\": 1\n" +
|
|
|
+ " }\n" +
|
|
|
+ " ]\n" +
|
|
|
+ " }\n" +
|
|
|
+ " },\n" +
|
|
|
+ " \"UZD299F139CB2410181HP\": {\n" +
|
|
|
+ " \"outRoom\": {\n" +
|
|
|
+ " \"pumps\": [\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"1\",\n" +
|
|
|
+ " \"status\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"2\",\n" +
|
|
|
+ " \"status\": 0\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"3\"\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"4\"\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"5\"\n" +
|
|
|
+ " },\n" +
|
|
|
+ " {\n" +
|
|
|
+ " \"label\": \"6\"\n" +
|
|
|
+ " }\n" +
|
|
|
+ " ]\n" +
|
|
|
+ " }\n" +
|
|
|
+ " }\n" +
|
|
|
+ "}");
|
|
|
+
|
|
|
public static WaterCollecationService getWaterTapWaterApi(){
|
|
|
return DBMgrProxy.getInstance().applyWaterCollecationService();
|
|
|
}
|
|
@@ -541,6 +792,9 @@ public class KprAimWaterCollecationBizFun {
|
|
|
String orgId = orgIdOptional.orElse(null);
|
|
|
if (!StringUtils.isEmpty(orgId)) {
|
|
|
//预测比对时间如果不是今年,则变为今年的时间
|
|
|
+ //TODO 取泵号
|
|
|
+ JSONObject pumpItem = (JSONObject)pumpObj.get(orgId);
|
|
|
+ JSONArray pumpArray = ((JSONObject)pumpItem.get("outRoom")).getJSONArray("pumps");
|
|
|
//TODO 一天24小时
|
|
|
for (int j = 0;j<24;j++) {
|
|
|
//TODO 数据库操作
|
|
@@ -583,6 +837,57 @@ public class KprAimWaterCollecationBizFun {
|
|
|
, String.format("Batch insertYuceDataScheduled ERROR:{%s} ",
|
|
|
"新增或修改失败"));
|
|
|
}
|
|
|
+
|
|
|
+ //TODO ③ 泵集合数据添加或修改
|
|
|
+ // 生成[1, pumpArray.size()]范围内的随机数
|
|
|
+ int randomNum = (int) (Math.random() * (pumpArray.size() - 1)) + 1;
|
|
|
+ List<Double> splitRandom = splitValueRandomlyWithZeros(Double.valueOf((hourActualWaterSupply==null
|
|
|
+ ?"0.0":hourActualWaterSupply)),pumpArray.size(),randomNum);//实际值随机数集合
|
|
|
+ List<Double> splitRandomYuce = splitValueRandomlyWithZeros((randomWater==null
|
|
|
+ ?0.0:randomWater),pumpArray.size(),randomNum);//预测值随机数集合
|
|
|
+ //泵集合
|
|
|
+ int kIndex = 0;
|
|
|
+ for (Object obj:pumpArray){
|
|
|
+ JSONObject itemObj = (JSONObject)obj;
|
|
|
+ Map<String,Object> map = new LinkedHashMap<>();
|
|
|
+ //TODO 泵状态根据值是否为0设置
|
|
|
+ map.put("Date", dateNow.withYear(LocalDateTime.now().getYear()).toLocalDate()
|
|
|
+ .format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
|
|
|
+ // 创建一个LocalTime实例,设置为指定小时,分钟和秒数为0
|
|
|
+ // 创建一个DateTimeFormatter用于格式化时间
|
|
|
+ map.put("Hour", time.format(formatter3));
|
|
|
+ map.put("PumpID",itemObj.get("label"));
|
|
|
+
|
|
|
+ if(splitRandom.get(kIndex)==0){
|
|
|
+ //TODO 说明泵实际值为0,状态为关
|
|
|
+ map.put("PumpStatus",0);
|
|
|
+ }else{
|
|
|
+ map.put("PumpStatus",1);
|
|
|
+ }
|
|
|
+ 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("PumpEnergy",splitRandomYuce.get(kIndex)/1000*180);
|
|
|
+ map.put("RealPumpEnergy",splitRandom.get(kIndex)/1000*200);
|
|
|
+ map.put("LastModifyTime", LocalDateTime.now().format(formatter));
|
|
|
+ map.put("orgId", orgId);
|
|
|
+ //TODO 添加or修改
|
|
|
+ Integer insertRes2 = getWaterTapApi().insertOrUpdateTbmHourwaterWatersupply(map);
|
|
|
+ if (insertRes2 < 1) {
|
|
|
+ LogPrintMgr.getInstance().printLogMsg(LogLevelFlag.LOG_ERROR
|
|
|
+ , mStrClassName
|
|
|
+ , mStrClassName
|
|
|
+ , String.format("Batch insertOrUpdateTbmHourwaterWatersupply ERROR:{%s} ",
|
|
|
+ "新增或修改失败"));
|
|
|
+ }
|
|
|
+ kIndex++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -609,4 +914,45 @@ public class KprAimWaterCollecationBizFun {
|
|
|
ex.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ //生成指定份额的随机数,并且带有0值
|
|
|
+ public static List<Double> splitValueRandomlyWithZeros(double totalValue, int parts, int zeroCount) {
|
|
|
+ if (zeroCount >= parts) {
|
|
|
+ throw new IllegalArgumentException("Zero count must be less than the number of parts.");
|
|
|
+ }
|
|
|
+
|
|
|
+ Random random = new Random();
|
|
|
+ List<Double> points = new ArrayList<>();
|
|
|
+ int nonZeroParts = parts - zeroCount;
|
|
|
+
|
|
|
+ // 添加初始点
|
|
|
+ points.add(0.0);
|
|
|
+
|
|
|
+ // 生成分割点
|
|
|
+ for (int i = 0; i < nonZeroParts - 1; i++) {
|
|
|
+ points.add(random.nextDouble() * totalValue);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加终点
|
|
|
+ points.add(totalValue);
|
|
|
+
|
|
|
+ // 排序
|
|
|
+ Collections.sort(points);
|
|
|
+
|
|
|
+ // 计算每份的大小
|
|
|
+ List<Double> splits = new ArrayList<>();
|
|
|
+ for (int i = 1; i < points.size(); i++) {
|
|
|
+ splits.add(points.get(i) - points.get(i - 1));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加0值份额
|
|
|
+ for (int i = 0; i < zeroCount; i++) {
|
|
|
+ splits.add(0.0);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 打乱列表,以确保0值分布均匀
|
|
|
+ Collections.shuffle(splits);
|
|
|
+
|
|
|
+ return splits;
|
|
|
+ }
|
|
|
}
|