From 842b7d096e93bf2480f89abb43d0cd9b22e20463 Mon Sep 17 00:00:00 2001 From: XMnhwj_BackTechnologyDevelopment <3512363680@qq.com> Date: Tue, 26 Mar 2024 10:58:09 +0800 Subject: [PATCH] =?UTF-8?q?2024-03-26=2010:58:00=20=E8=83=BD=E6=BA=90?= =?UTF-8?q?=E6=B6=88=E8=80=97=E6=B5=8B=E7=AE=97=E6=A8=A1=E5=9E=8B=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dky/utils/entity/SysModelParam.java | 55 ++++++++ .../main/java/com/dky/security/SM4Utils.java | 2 +- .../dky/stirtpar/StirparModelCalculate.java | 126 ++++++++++++++---- .../electricConsumeStirpatCoefficient.json | 46 ------- .../energyConsumeStirpatCoefficient.json | 42 ------ 5 files changed, 153 insertions(+), 118 deletions(-) create mode 100644 dntd-common/src/main/java/com/dky/utils/entity/SysModelParam.java delete mode 100644 dntd-tool/src/main/resources/electricConsumeStirpatCoefficient.json delete mode 100644 dntd-tool/src/main/resources/energyConsumeStirpatCoefficient.json diff --git a/dntd-common/src/main/java/com/dky/utils/entity/SysModelParam.java b/dntd-common/src/main/java/com/dky/utils/entity/SysModelParam.java new file mode 100644 index 0000000..4ca9947 --- /dev/null +++ b/dntd-common/src/main/java/com/dky/utils/entity/SysModelParam.java @@ -0,0 +1,55 @@ +package com.dky.utils.entity; + +public class SysModelParam { + + /** 序号 */ + private Integer id ; + /** 系数名称 */ + private String paramName ; + /** 系数值 */ + private Double paramValue ; + /** 该系数适用于【0能源, 1电力】 */ + private Integer paramModel ; + + public SysModelParam() { } + + public SysModelParam(Integer id, String paramName, Double paramValue, Integer paramModel) { + this.id = id; + this.paramName = paramName; + this.paramValue = paramValue; + this.paramModel = paramModel; + } + + /** 序号 */ + public Integer getId(){ + return this.id; + } + /** 序号 */ + public void setId(Integer id){ + this.id=id; + } + /** 系数名称 */ + public String getParamName(){ + return this.paramName; + } + /** 系数名称 */ + public void setParamName(String paramName){ + this.paramName=paramName; + } + /** 系数值 */ + public Double getParamValue(){ + return this.paramValue; + } + /** 系数值 */ + public void setParamValue(Double paramValue){ + this.paramValue=paramValue; + } + /** 该系数适用于【0能源, 1电力】 */ + public Integer getParamModel(){ + return this.paramModel; + } + /** 该系数适用于【0能源, 1电力】 */ + public void setParamModel(Integer paramModel){ + this.paramModel=paramModel; + } +} \ No newline at end of file diff --git a/dntd-tool/src/main/java/com/dky/security/SM4Utils.java b/dntd-tool/src/main/java/com/dky/security/SM4Utils.java index 82ad3ae..c5586f2 100644 --- a/dntd-tool/src/main/java/com/dky/security/SM4Utils.java +++ b/dntd-tool/src/main/java/com/dky/security/SM4Utils.java @@ -17,7 +17,7 @@ public class SM4Utils { Security.addProvider(new BouncyCastleProvider()); } - public final static String SM4_KEY = "dfd2b0581fc9244e51100c5cf02defc8064a45686eb2e4ddfd44cdab2ef908b2"; + public final static String SM4_KEY = "1100fba8ee67ddf1f6f4e37c500dc10eee1bf15827ae3837810e30f402fa0bc6"; private static final String ALGORITHM = "AES/ECB/PKCS5Padding"; diff --git a/dntd-tool/src/main/java/com/dky/stirtpar/StirparModelCalculate.java b/dntd-tool/src/main/java/com/dky/stirtpar/StirparModelCalculate.java index 360b619..19ce4d1 100644 --- a/dntd-tool/src/main/java/com/dky/stirtpar/StirparModelCalculate.java +++ b/dntd-tool/src/main/java/com/dky/stirtpar/StirparModelCalculate.java @@ -1,25 +1,30 @@ package com.dky.stirtpar; +import cn.hutool.json.JSONArray; import cn.hutool.json.JSONObject; import com.dky.modelI.DntdModelI; import com.dky.utils.CalculateUtils; import com.dky.utils.entity.SysDeviceHeatScene; +import com.dky.utils.entity.SysModelParam; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class StirparModelCalculate implements DntdModelI { - DecimalFormat df = new DecimalFormat("#.00"); + static DecimalFormat df = new DecimalFormat("#.00"); /** * 计算热源消耗总量 - * @param provinceCode 省份编码 + * @param list 参数列表 * @param peopleNum 人口 * @param averageGdp 人均GDP * @param U 城市化率 @@ -27,16 +32,36 @@ public class StirparModelCalculate implements DntdModelI { * @param II 工业能源强度 * @return */ - public static Double energyConsumeStirCoefficient(String provinceCode, Integer peopleNum, Double averageGdp, Double U, Double I, Double II) { - JSONObject jo = (JSONObject) toJSON("energyConsumeStirpatCoefficient.json").get(provinceCode); - Double a = Double.parseDouble(jo.get("a").toString()); - Double b1 = Double.parseDouble(jo.get("b1").toString()); - Double b2 = Double.parseDouble(jo.get("b2").toString()); - Double b3 = Double.parseDouble(jo.get("b3").toString()); - Double b4 = Double.parseDouble(jo.get("b4").toString()); - Double b5 = Double.parseDouble(jo.get("b5").toString()); - Double b6 = Double.parseDouble(jo.get("b6").toString()); - Double e = Double.parseDouble(jo.get("e").toString()); + public static Double energyConsumeStirCoefficient(List list, Integer peopleNum, Double averageGdp, Double U, Double I, Double II) { + List mapList = getThisModel(0, list); + Double a = 1.0; + Double b1 = 1.0; + Double b2 = 1.0; + Double b3 = 1.0; + Double b4 = 1.0; + Double b5 = 1.0; + Double b6 = 1.0; + Double e = 1.0; + + for (Map param : mapList){ + if ("a".equals(param.get("key"))) { + a = (Double) param.get("value"); + } else if ("b1".equals(param.get("key"))) { + b1 = (Double) param.get("value"); + } else if ("b2".equals(param.get("key"))) { + b2 = (Double) param.get("value"); + } else if ("b3".equals(param.get("key"))) { + b3 = (Double) param.get("value"); + } else if ("b4".equals(param.get("key"))) { + b4 = (Double) param.get("value"); + } else if ("b55".equals(param.get("key"))) { + b5 = (Double) param.get("value"); + } else if ("b6".equals(param.get("key"))) { + b6 = (Double) param.get("value"); + } else if ("e".equals(param.get("key"))) { + e = (Double) param.get("value"); + } + } Double add1 = CalculateUtils.add(a, b1 * Math.log(peopleNum)); Double add2 = CalculateUtils.add(add1, b2 * Math.log(U)); @@ -46,12 +71,12 @@ public class StirparModelCalculate implements DntdModelI { Double add6 = CalculateUtils.add(add5, b6 * Math.log(II)); Double add7 = CalculateUtils.add(add6, e); - return Math.round(Math.exp(add7) * 100) / 100.0; + return Math.exp(add7); } /** * 计算电耗消耗总量 - * @param provinceCode 省份编码 + * @param list 参数列表 * @param CT 能源消耗量 * @param peopleNum 人口 * @param averageGdp 人均GDP @@ -60,17 +85,39 @@ public class StirparModelCalculate implements DntdModelI { * @param T 年均温度 * @return */ - public static Double electricConsumeStirCoefficient(String provinceCode, Double CT, Integer peopleNum, Double averageGdp, Double U, Double PR, Double T) { - JSONObject jo = (JSONObject) toJSON("electricConsumeStirpatCoefficient.json").get(provinceCode); - Double a = Double.parseDouble(jo.get("a").toString()); - Double b1 = Double.parseDouble(jo.get("b1").toString()); - Double b2 = Double.parseDouble(jo.get("b2").toString()); - Double b3 = Double.parseDouble(jo.get("b3").toString()); - Double b4 = Double.parseDouble(jo.get("b4").toString()); - Double b5 = Double.parseDouble(jo.get("b5").toString()); - Double b6 = Double.parseDouble(jo.get("b6").toString()); - Double b7 = Double.parseDouble(jo.get("b7").toString()); - Double e = Double.parseDouble(jo.get("e").toString()); + public static Double electricConsumeStirCoefficient(List list, Double CT, Integer peopleNum, Double averageGdp, Double U, Double PR, Double T) { + List mapList = getThisModel(1, list); + Double a = 1.0; + Double b1 = 1.0; + Double b2 = 1.0; + Double b3 = 1.0; + Double b4 = 1.0; + Double b5 = 1.0; + Double b6 = 1.0; + Double b7 = 1.0; + Double e = 1.0; + + for (Map param : mapList){ + if ("a".equals(param.get("key"))) { + a = (Double) param.get("value"); + } else if ("b1".equals(param.get("key"))) { + b1 = (Double) param.get("value"); + } else if ("b2".equals(param.get("key"))) { + b2 = (Double) param.get("value"); + } else if ("b3".equals(param.get("key"))) { + b3 = (Double) param.get("value"); + } else if ("b4".equals(param.get("key"))) { + b4 = (Double) param.get("value"); + } else if ("b55".equals(param.get("key"))) { + b5 = (Double) param.get("value"); + } else if ("b6".equals(param.get("key"))) { + b6 = (Double) param.get("value"); + } else if ("b7".equals(param.get("key"))) { + b7 = (Double) param.get("value"); + } else if ("e".equals(param.get("key"))) { + e = (Double) param.get("value"); + } + } Double add1 = CalculateUtils.add(a, b1 * Math.log(CT)); Double add2 = CalculateUtils.add(add1, b2 * Math.log(peopleNum)); @@ -81,7 +128,7 @@ public class StirparModelCalculate implements DntdModelI { Double add7 = CalculateUtils.add(add6, b7 * Math.log(T)); Double add8 = CalculateUtils.add(add7, e); - return add8; + return Math.exp(add8); } @@ -127,7 +174,12 @@ public class StirparModelCalculate implements DntdModelI { e.printStackTrace(); } - String provinceCode = jsonObject.get("provinceCode").toString(); + List sysParamList = new ArrayList<>(); + JSONArray specArray = jsonObject.getJSONArray("sysModelParam"); + for (int i = 0; i < specArray.size(); i++) { + SysModelParam devSpec = specArray.getJSONObject(i).toBean(SysModelParam.class); + sysParamList.add(devSpec); + } Integer peopleNum = Integer.parseInt(new DecimalFormat("#").format(energyInfo.get("peopleNum"))); Double averageGdp = Double.parseDouble(energyInfo.get("averageGdp").toString()); Double U = Double.parseDouble(energyInfo.get("ut").toString()); @@ -138,9 +190,25 @@ public class StirparModelCalculate implements DntdModelI { Double T = Double.parseDouble(electricInfo.get("T").toString()); JSONObject resultJsonObject = new JSONObject(); - resultJsonObject.put("CT", df.format(energyConsumeStirCoefficient(provinceCode, peopleNum, averageGdp, U, I, II))); - resultJsonObject.put("CE", df.format(electricConsumeStirCoefficient(provinceCode, CT, peopleNum, averageGdp, U, PR, T))); + resultJsonObject.put("CT", df.format(energyConsumeStirCoefficient(sysParamList, peopleNum, averageGdp, U, I, II))); + resultJsonObject.put("CE", df.format(electricConsumeStirCoefficient(sysParamList, CT, peopleNum, averageGdp, U, PR, T))); return resultJsonObject; } + + public static List getThisModel(Integer args, List list) { + List ary = new ArrayList<>(); + + list.forEach((param) -> { + if (param.getParamModel().equals(args)) { + Map map = new HashMap<>(); + map.put("key", param.getParamName()); + map.put("value", param.getParamValue()); + ary.add(map); + } + }); + + return ary; + } + } diff --git a/dntd-tool/src/main/resources/electricConsumeStirpatCoefficient.json b/dntd-tool/src/main/resources/electricConsumeStirpatCoefficient.json deleted file mode 100644 index 02fcefe..0000000 --- a/dntd-tool/src/main/resources/electricConsumeStirpatCoefficient.json +++ /dev/null @@ -1,46 +0,0 @@ -{ - "110000": { - "a": 1, - "b1": 2, - "b2": 3, - "b3": 4, - "b4": 5, - "b5": 6, - "b6": 7, - "b7": 9, - "e": 8 - }, - "120000": { - "a": 1, - "b1": 2, - "b2": 3, - "b3": 4, - "b4": 5, - "b5": 6, - "b6": 7, - "b7": 9, - "e": 8 - }, - "310000": { - "a": 1, - "b1": 2, - "b2": 3, - "b3": 4, - "b4": 5, - "b5": 6, - "b6": 7, - "b7": 9, - "e": 8 - }, - "500000": { - "a": 1, - "b1": 2, - "b2": 3, - "b3": 4, - "b4": 5, - "b5": 6, - "b6": 7, - "b7": 9, - "e": 8 - } -} \ No newline at end of file diff --git a/dntd-tool/src/main/resources/energyConsumeStirpatCoefficient.json b/dntd-tool/src/main/resources/energyConsumeStirpatCoefficient.json deleted file mode 100644 index a6b84f9..0000000 --- a/dntd-tool/src/main/resources/energyConsumeStirpatCoefficient.json +++ /dev/null @@ -1,42 +0,0 @@ -{ - "110000": { - "a": 1, - "b1": 2, - "b2": 3, - "b3": 4, - "b4": 5, - "b5": 6, - "b6": 7, - "e": 8 - }, - "120000": { - "a": 1, - "b1": 2, - "b2": 3, - "b3": 4, - "b4": 5, - "b5": 6, - "b6": 7, - "e": 8 - }, - "310000": { - "a": 1, - "b1": 2, - "b2": 3, - "b3": 4, - "b4": 5, - "b5": 6, - "b6": 7, - "e": 8 - }, - "500000": { - "a": 1, - "b1": 2, - "b2": 3, - "b3": 4, - "b4": 5, - "b5": 6, - "b6": 7, - "e": 8 - } -} \ No newline at end of file