commit 9f1fee2e04a6a243a26e2f346fec22b0f2700a42
Author: hwj_lyq <13366653694@163.com>
Date: Thu Dec 14 14:17:32 2023 +0800
1
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5ff6309
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..35410ca
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
new file mode 100644
index 0000000..1ad1b7f
--- /dev/null
+++ b/.idea/encodings.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..ce85f4e
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,19 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dntd-common/pom.xml b/dntd-common/pom.xml
new file mode 100644
index 0000000..b28eecb
--- /dev/null
+++ b/dntd-common/pom.xml
@@ -0,0 +1,28 @@
+
+
+ 4.0.0
+
+ com.dky
+ dntd-model-tool1
+ 1.0-SNAPSHOT
+
+
+ dntd-common
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+ cn.hutool
+ hutool-all
+ 5.4.5
+
+
+
+
\ No newline at end of file
diff --git a/dntd-common/src/main/java/com/dky/utils/ConfigReader.java b/dntd-common/src/main/java/com/dky/utils/ConfigReader.java
new file mode 100644
index 0000000..a40bca6
--- /dev/null
+++ b/dntd-common/src/main/java/com/dky/utils/ConfigReader.java
@@ -0,0 +1,22 @@
+package com.dky.utils;
+
+import java.io.*;
+import java.util.Properties;
+
+public class ConfigReader {
+ private static Properties prop = new Properties();
+
+ public static String getProperty(String key) {
+ InputStream input = ConfigReader.class.getClassLoader().getResourceAsStream("modelCode.properties");
+ if(input!= null) {
+ try {
+ prop.load(input);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }else {
+ throw new RuntimeException("Failed to find modelCode.properties");
+ }
+ return prop.getProperty(key);
+ }
+}
\ No newline at end of file
diff --git a/dntd-common/src/main/java/com/dky/utils/entity/DevPrice.java b/dntd-common/src/main/java/com/dky/utils/entity/DevPrice.java
new file mode 100644
index 0000000..2cdd125
--- /dev/null
+++ b/dntd-common/src/main/java/com/dky/utils/entity/DevPrice.java
@@ -0,0 +1,78 @@
+package com.dky.utils.entity;
+
+
+public class DevPrice {
+
+ private Integer id;
+ private String devType;
+ private Double devPrice;
+ private String priceUnit;
+ private Double unitVal;
+ private String unitUnit;
+ private String heatRange;
+ private String remark;
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getDevType() {
+ return devType;
+ }
+
+ public void setDevType(String devType) {
+ this.devType = devType;
+ }
+
+ public Double getDevPrice() {
+ return devPrice;
+ }
+
+ public void setDevPrice(Double devPrice) {
+ this.devPrice = devPrice;
+ }
+
+ public String getPriceUnit() {
+ return priceUnit;
+ }
+
+ public void setPriceUnit(String priceUnit) {
+ this.priceUnit = priceUnit;
+ }
+
+ public Double getUnitVal() {
+ return unitVal;
+ }
+
+ public void setUnitVal(Double unitVal) {
+ this.unitVal = unitVal;
+ }
+
+ public String getUnitUnit() {
+ return unitUnit;
+ }
+
+ public void setUnitUnit(String unitUnit) {
+ this.unitUnit = unitUnit;
+ }
+
+ public String getHeatRange() {
+ return heatRange;
+ }
+
+ public void setHeatRange(String heatRange) {
+ this.heatRange = heatRange;
+ }
+
+ public String getRemark() {
+ return remark;
+ }
+
+ public void setRemark(String remark) {
+ this.remark = remark;
+ }
+}
diff --git a/dntd-common/src/main/java/com/dky/utils/entity/DevSpec.java b/dntd-common/src/main/java/com/dky/utils/entity/DevSpec.java
new file mode 100644
index 0000000..3730310
--- /dev/null
+++ b/dntd-common/src/main/java/com/dky/utils/entity/DevSpec.java
@@ -0,0 +1,79 @@
+package com.dky.utils.entity;
+
+import cn.hutool.json.JSONObject;
+
+public class DevSpec {
+ //id
+ private Integer id;
+ //设备类型
+ private String devType;
+ //设备价格
+ private Double devModel;
+ //单位
+ private Double capacity;
+ //单元单位
+ private String output;
+ //制热范围
+ private String voltage;
+ //备注
+
+ public Integer getId() {
+ return id;
+ }
+
+ public void setId(Integer id) {
+ this.id = id;
+ }
+
+ public String getDevType() {
+ return devType;
+ }
+
+ public void setDevType(String devType) {
+ this.devType = devType;
+ }
+
+ public Double getDevModel() {
+ return devModel;
+ }
+
+ public void setDevModel(Double devModel) {
+ this.devModel = devModel;
+ }
+
+ public Double getCapacity() {
+ return capacity;
+ }
+
+ public void setCapacity(Double capacity) {
+ this.capacity = capacity;
+ }
+
+ public String getOutput() {
+ return output;
+ }
+
+ public void setOutput(String output) {
+ this.output = output;
+ }
+
+ public String getVoltage() {
+ return voltage;
+ }
+
+ public void setVoltage(String voltage) {
+ this.voltage = voltage;
+ }
+
+ @Override
+ public String toString() {
+ return "DevSpec{" +
+ "id=" + id +
+ ", devType='" + devType + '\'' +
+ ", devModel=" + devModel +
+ ", capacity=" + capacity +
+ ", output='" + output + '\'' +
+ ", voltage='" + voltage + '\'' +
+ '}';
+ }
+}
diff --git a/dntd-common/src/main/java/com/dky/utils/enums/Code.java b/dntd-common/src/main/java/com/dky/utils/enums/Code.java
new file mode 100644
index 0000000..a3fcddc
--- /dev/null
+++ b/dntd-common/src/main/java/com/dky/utils/enums/Code.java
@@ -0,0 +1,33 @@
+package com.dky.utils.enums;
+
+
+public enum Code {
+
+
+ SUCCESS(1001, "成功"),
+ KEY_EXPIRATION(1002, "密钥已过期"),
+ KEY_UNAUTHORIZED(1003, "密钥本机未授权");
+
+
+ /**
+ * 返回结果编码
+ */
+ private final Integer code;
+ /**
+ * 描述
+ */
+ private final String desc;
+
+ public Integer getCode() {
+ return code;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ Code(Integer code, String desc) {
+ this.code = code;
+ this.desc = desc;
+ }
+}
diff --git a/dntd-common/src/main/java/com/dky/utils/result/MatchedDevice.java b/dntd-common/src/main/java/com/dky/utils/result/MatchedDevice.java
new file mode 100644
index 0000000..5a75a68
--- /dev/null
+++ b/dntd-common/src/main/java/com/dky/utils/result/MatchedDevice.java
@@ -0,0 +1,37 @@
+package com.dky.utils.result;
+
+import com.dky.utils.entity.DevSpec;
+
+public class MatchedDevice {
+ private DevSpec devSpec;
+ private int count; // 匹配的设备数量
+
+ public MatchedDevice(DevSpec devSpec, int count) {
+ this.devSpec = devSpec;
+ this.count = count;
+ }
+
+ public DevSpec getDevSpec() {
+ return devSpec;
+ }
+
+ public void setDevSpec(DevSpec devSpec) {
+ this.devSpec = devSpec;
+ }
+
+ public int getCount() {
+ return count;
+ }
+
+ public void setCount(int count) {
+ this.count = count;
+ }
+
+ @Override
+ public String toString() {
+ return "MatchedDevice{" +
+ "devSpec=" + devSpec +
+ ", count=" + count +
+ '}';
+ }
+}
diff --git a/dntd-common/src/main/java/com/dky/utils/result/MatchedDeviceResult.java b/dntd-common/src/main/java/com/dky/utils/result/MatchedDeviceResult.java
new file mode 100644
index 0000000..080064a
--- /dev/null
+++ b/dntd-common/src/main/java/com/dky/utils/result/MatchedDeviceResult.java
@@ -0,0 +1,39 @@
+package com.dky.utils.result;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class MatchedDeviceResult {
+ private List matchedDevices;
+ private double totalPriceInTenThousand; // 总价,单位:万元
+
+ public MatchedDeviceResult(List matchedDevices, double totalPriceInTenThousand) {
+ this.matchedDevices = matchedDevices;
+ this.totalPriceInTenThousand = totalPriceInTenThousand;
+ }
+
+ public List getMatchedDevices() {
+ return matchedDevices;
+ }
+
+ public void setMatchedDevices(List matchedDevices) {
+ this.matchedDevices = matchedDevices;
+ }
+
+ public double getTotalPriceInTenThousand() {
+ return totalPriceInTenThousand;
+ }
+
+ public void setTotalPriceInTenThousand(double totalPriceInTenThousand) {
+ this.totalPriceInTenThousand = totalPriceInTenThousand;
+ }
+
+ @Override
+ public String toString() {
+ return "Result{" +
+ "matchedDevices=" + Arrays.toString(matchedDevices.toArray() )+
+ ", totalPriceInTenThousand=" + totalPriceInTenThousand +
+ '}';
+ }
+
+}
diff --git a/dntd-common/src/main/java/com/dky/utils/result/ResponseUtil.java b/dntd-common/src/main/java/com/dky/utils/result/ResponseUtil.java
new file mode 100644
index 0000000..5c59b41
--- /dev/null
+++ b/dntd-common/src/main/java/com/dky/utils/result/ResponseUtil.java
@@ -0,0 +1,14 @@
+package com.dky.utils.result;
+
+
+import cn.hutool.json.JSONObject;
+
+public class ResponseUtil {
+ public static JSONObject createResponse(int code, String message, Object data) {
+ JSONObject jsonObjectResult = new JSONObject();
+ jsonObjectResult.put("code", code);
+ jsonObjectResult.put("message", message);
+ jsonObjectResult.put("report", data);
+ return jsonObjectResult;
+ }
+}
\ No newline at end of file
diff --git a/dntd-model-heatboiler/pom.xml b/dntd-model-heatboiler/pom.xml
new file mode 100644
index 0000000..388f155
--- /dev/null
+++ b/dntd-model-heatboiler/pom.xml
@@ -0,0 +1,39 @@
+
+
+ 4.0.0
+
+ com.dky
+ dntd-model-tool1
+ 1.0-SNAPSHOT
+
+
+ dntd-model-heatboiler
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+ cn.hutool
+ hutool-all
+ 5.4.5
+
+
+ com.dky
+ dntd-modelI
+ 1.0-SNAPSHOT
+
+
+ com.dky
+ dntd-common
+ 1.0-SNAPSHOT
+
+
+
+
+
\ No newline at end of file
diff --git a/dntd-model-heatboiler/src/main/java/com/dky/calculate/Advantage.java b/dntd-model-heatboiler/src/main/java/com/dky/calculate/Advantage.java
new file mode 100644
index 0000000..ed07686
--- /dev/null
+++ b/dntd-model-heatboiler/src/main/java/com/dky/calculate/Advantage.java
@@ -0,0 +1,22 @@
+package com.dky.calculate;
+//方案优势
+public class Advantage {
+//安全性
+ public String safety(){
+ return "无";
+ }
+ //经济性
+ public String economy(Double firstInvestFee,Double yearTotalFee,Double yearRunFee,Double lastYearFee){
+ Double hsq = Math.round(firstInvestFee/yearTotalFee*100.0)/100.0;
+ double js = Math.round(lastYearFee - yearRunFee*100.0)/100.0;
+ return "本次改造投资回收期为"+hsq+"年,本改造方案相比较原技术节省年运行费用成本"+js+"元。";
+ }
+ //智能性
+ public String intelligence(){
+ return "以电锅炉替代和实现精准控温。";
+ }
+ //环保性
+ public String environment(Double yearReduceCarbon){
+ return "本次改造方案减排"+yearReduceCarbon+"吨";
+ }
+}
diff --git a/dntd-model-heatboiler/src/main/java/com/dky/calculate/Overall.java b/dntd-model-heatboiler/src/main/java/com/dky/calculate/Overall.java
new file mode 100644
index 0000000..e793a52
--- /dev/null
+++ b/dntd-model-heatboiler/src/main/java/com/dky/calculate/Overall.java
@@ -0,0 +1,30 @@
+package com.dky.calculate;
+
+
+public class Overall {
+
+ //年运行费用
+ public Double yearRunFee(Double yearEnergy,Double electricityPrice) {
+ // 1蒸吨蒸汽需要770kWh电。
+ //年总用电yearEnergy*770
+ //根据传入得替代前年能源用量计算出年用电量
+ //年用电量用电量乘以电价
+ return yearEnergy*770*electricityPrice;
+ }
+ //年总费用
+ public Double yearTotalFee(Double yearRunFee) {
+ // 年运行费用*系数+年运行费用。(10%)
+ return yearRunFee*0.1+yearRunFee;
+ }
+ //年减碳量(吨)
+ public Double yearReduceCarbon(Double yearEnergy) {
+ // 年用电量*1.229
+ return yearEnergy*770*1.229;
+ }
+ //替代电量
+ public Double replaceEnergy(Double yearEnergy) {
+
+ return yearEnergy*770;
+ }
+
+}
diff --git a/dntd-model-heatboiler/src/main/java/com/dky/calculate/RequireDevice.java b/dntd-model-heatboiler/src/main/java/com/dky/calculate/RequireDevice.java
new file mode 100644
index 0000000..42eeac8
--- /dev/null
+++ b/dntd-model-heatboiler/src/main/java/com/dky/calculate/RequireDevice.java
@@ -0,0 +1,61 @@
+package com.dky.calculate;
+
+import com.dky.utils.entity.DevSpec;
+import com.dky.utils.entity.DevPrice;
+import com.dky.utils.result.MatchedDevice;
+import com.dky.utils.result.MatchedDeviceResult;
+
+import java.util.*;
+
+public class RequireDevice {
+ public static MatchedDeviceResult matchDevices(double demandCapacity,List deviceList,List priceList) {
+ // 对设备按照容量从大到小排序
+ deviceList.sort((d1, d2) -> Double.compare(d2.getCapacity(), d1.getCapacity()));
+
+ double remainingCapacity = demandCapacity;
+ double totalPrice = 0;
+ List matchedDevices = new ArrayList<>();
+ // 遍历设备列表.根据需求容量匹配设备
+ for (DevSpec spec : deviceList) {
+ if (spec.getCapacity() <= remainingCapacity) {
+ int count = (int) Math.floor(remainingCapacity / spec.getCapacity());
+ remainingCapacity = remainingCapacity - (spec.getCapacity() * count);
+ matchedDevices.add(new MatchedDevice(spec, count));
+ if (count > 0) {
+ DevPrice price = priceList.stream()
+ .filter(p -> p.getId() == spec.getId())
+ .findFirst()
+ .orElse(null);
+
+ if (price != null) {
+ double devicePrice = price.getDevPrice() * count;
+ totalPrice += devicePrice;
+ }
+ }
+ }else {
+ for (int i = deviceList.size()-1; i >= 0; i--){
+ if (deviceList.get(i).getCapacity() >= remainingCapacity){
+ matchedDevices.add(new MatchedDevice(deviceList.get(i), 1));
+ int finalI = i;
+ DevPrice price = priceList.stream()
+ .filter(p -> p.getId() == deviceList.get(finalI).getId())
+ .findFirst()
+ .orElse(null);
+
+ if (price != null) {
+ double devicePrice = price.getDevPrice();
+ totalPrice += devicePrice;
+ }
+ break;
+ }
+ }
+ break;
+ }
+ if (remainingCapacity <= 0) {
+ break; // 当总容量已经满足需求时,跳出循环,不再选择其他设备
+ }
+ }
+
+ return new MatchedDeviceResult(matchedDevices, totalPrice);
+ }
+}
diff --git a/dntd-model-heatboiler/src/main/java/com/dky/entity/Heatboiler.java b/dntd-model-heatboiler/src/main/java/com/dky/entity/Heatboiler.java
new file mode 100644
index 0000000..278df10
--- /dev/null
+++ b/dntd-model-heatboiler/src/main/java/com/dky/entity/Heatboiler.java
@@ -0,0 +1,62 @@
+package com.dky.entity;
+
+public class Heatboiler {
+ private Double exportTemperature;
+ private String hotMedium;
+
+ private Double hotDevicePower;
+ //年能源用量
+ private Double yearEnergy;
+ //执行电价
+ private Double electricityPrice;
+ private OriginalDevice originalDevice;
+
+ public OriginalDevice getOriginalDevice() {
+ return originalDevice;
+ }
+
+ public void setOriginalDevice(OriginalDevice originalDevice) {
+ this.originalDevice = originalDevice;
+ }
+
+ public Double getYearEnergy() {
+ return yearEnergy;
+ }
+
+ public void setYearEnergy(Double yearEnergy) {
+ this.yearEnergy = yearEnergy;
+ }
+
+ public Double getElectricityPrice() {
+ return electricityPrice;
+ }
+
+ public void setElectricityPrice(Double electricityPrice) {
+ this.electricityPrice = electricityPrice;
+ }
+
+ public Double getExportTemperature() {
+ return exportTemperature;
+ }
+
+ public void setExportTemperature(Double exportTemperature) {
+ this.exportTemperature = exportTemperature;
+ }
+
+ public String getHotMedium() {
+ return hotMedium;
+ }
+
+ public void setHotMedium(String hotMedium) {
+ this.hotMedium = hotMedium;
+ }
+
+ public Double getHotDevicePower() {
+ return hotDevicePower;
+ }
+
+ public void setHotDevicePower(Double hotDevicePower) {
+ this.hotDevicePower = hotDevicePower;
+ }
+
+}
diff --git a/dntd-model-heatboiler/src/main/java/com/dky/entity/OriginalDevice.java b/dntd-model-heatboiler/src/main/java/com/dky/entity/OriginalDevice.java
new file mode 100644
index 0000000..51b2de6
--- /dev/null
+++ b/dntd-model-heatboiler/src/main/java/com/dky/entity/OriginalDevice.java
@@ -0,0 +1,40 @@
+package com.dky.entity;
+
+public class OriginalDevice {
+ private String deviceType;
+ private Integer deviceNum;
+ private String deviceEnergyType;
+ private Double lastYearFee;
+
+ public String getDeviceType() {
+ return deviceType;
+ }
+
+ public void setDeviceType(String deviceType) {
+ this.deviceType = deviceType;
+ }
+
+ public Integer getDeviceNum() {
+ return deviceNum;
+ }
+
+ public void setDeviceNum(Integer deviceNum) {
+ this.deviceNum = deviceNum;
+ }
+
+ public String getDeviceEnergyType() {
+ return deviceEnergyType;
+ }
+
+ public void setDeviceEnergyType(String deviceEnergyType) {
+ this.deviceEnergyType = deviceEnergyType;
+ }
+
+ public Double getLastYearFee() {
+ return lastYearFee;
+ }
+
+ public void setLastYearFee(Double lastYearFee) {
+ this.lastYearFee = lastYearFee;
+ }
+}
diff --git a/dntd-modelI/pom.xml b/dntd-modelI/pom.xml
new file mode 100644
index 0000000..9cdf78c
--- /dev/null
+++ b/dntd-modelI/pom.xml
@@ -0,0 +1,27 @@
+
+
+ 4.0.0
+
+ com.dky
+ dntd-model-tool1
+ 1.0-SNAPSHOT
+
+
+ dntd-modelI
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+ cn.hutool
+ hutool-all
+ 5.4.5
+
+
+
+
\ No newline at end of file
diff --git a/dntd-modelI/src/main/java/com/dky/modelI/DntdModelI.java b/dntd-modelI/src/main/java/com/dky/modelI/DntdModelI.java
new file mode 100644
index 0000000..6274d0e
--- /dev/null
+++ b/dntd-modelI/src/main/java/com/dky/modelI/DntdModelI.java
@@ -0,0 +1,7 @@
+package com.dky.modelI;
+
+import cn.hutool.json.JSONObject;
+
+public interface DntdModelI {
+ JSONObject createReport(JSONObject jsonObject);
+}
\ No newline at end of file
diff --git a/dntd-tool/pom.xml b/dntd-tool/pom.xml
new file mode 100644
index 0000000..78c2090
--- /dev/null
+++ b/dntd-tool/pom.xml
@@ -0,0 +1,82 @@
+
+
+ 4.0.0
+
+ com.dky
+ dntd-model-tool1
+ 1.0-SNAPSHOT
+
+
+ dntd-tool
+ 1.0-SNAPSHOT
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+ cn.hutool
+ hutool-all
+ 5.4.5
+
+
+ org.bouncycastle
+ bcprov-jdk15on
+ 1.68
+
+
+ com.dky
+ dntd-model-heatboiler
+ 1.0-SNAPSHOT
+
+
+ com.dky
+ dntd-modelI
+ 1.0-SNAPSHOT
+
+
+ com.dky
+ dntd-common
+ 1.0-SNAPSHOT
+
+
+ com.dky
+ dntd-model-buildsence
+ 1.0-SNAPSHOT
+
+
+
+
+
+ src/main/resources
+ true
+
+ *.properties
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ 3.8.1
+
+ 8
+ 8
+
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 3.1.0
+
+ xlsx
+
+
+
+
+
\ No newline at end of file
diff --git a/dntd-tool/src/main/java/com/dky/Test.java b/dntd-tool/src/main/java/com/dky/Test.java
new file mode 100644
index 0000000..cfb14c9
--- /dev/null
+++ b/dntd-tool/src/main/java/com/dky/Test.java
@@ -0,0 +1,63 @@
+package com.dky;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.dky.tool.ModelTool;
+import com.dky.utils.entity.DevPrice;
+import com.dky.utils.entity.DevSpec;
+
+public class Test {
+ public static void main(String[] args) {
+ JSONObject list = new JSONObject();
+ JSONArray devSpecList = new JSONArray();
+ JSONArray devPriceList = new JSONArray();
+ DevSpec specObj1 = new DevSpec();
+ DevSpec specObj2 = new DevSpec();
+ DevSpec specObj3 = new DevSpec();
+ specObj1.setId(1);
+ specObj1.setDevType("直热式电锅炉");
+ specObj1.setCapacity(1.5);
+ specObj2.setId(2);
+ specObj2.setDevType("直热式电锅炉");
+ specObj2.setCapacity(2.5);
+ specObj3.setId(3);
+ specObj3.setDevType("直热式电锅炉");
+ specObj3.setCapacity(3.0);
+ devSpecList.add(specObj1);
+ devSpecList.add(specObj2);
+ devSpecList.add(specObj3);
+ list.put("devSpecList",devSpecList);
+ DevPrice devPrice1 = new DevPrice();
+ DevPrice devPrice2 = new DevPrice();
+ DevPrice devPrice3 = new DevPrice();
+ devPrice1.setId(1);
+ devPrice1.setDevType("直热式电锅炉");
+ devPrice1.setDevPrice(0.05);
+ devPrice2.setId(2);
+ devPrice2.setDevType("直热式电锅炉");
+ devPrice2.setDevPrice(0.06);
+ devPrice3.setId(3);
+ devPrice3.setDevType("直热式电锅炉");
+ devPrice3.setDevPrice(0.07);
+ devPriceList.add(devPrice1);
+ devPriceList.add(devPrice2);
+ devPriceList.add(devPrice3);
+ list.put("devPriceList",devPriceList);
+ ModelTool modelTool = new ModelTool(list);
+ JSONObject param = new JSONObject();
+ param.put("type", "0101");
+ param.put("exportTemperature", 28);
+ param.put("hotMedium", "1");
+ param.put("hotDevicePower", "20.26");
+ param.put("yearEnergy", "20.26");
+ param.put("electricityPrice", "20.26");
+ param.put("originalDevice", new JSONObject()
+ .put("deviceType", "1")
+ .put("deviceNum", 2)
+ .put("deviceEnergyType", "1")
+ .put("lastYearFee", "76.25"));
+ String key = "vcH5hprSR9VkzneCzkBI3pD0D8plBBmLc927UW8/CY+NmfEi5e0zRH2iU6E8l1HCS/c+EVOzQeOGmgNshVgOpYUFUV5VUaECpWy6O2mE6fLeaeydA5tuGebX9kKp4UH6Oo5TeMC/mjQNpo8d1aho82+eIcOIE1CkVm9Ec875YrijyNz7P7hd9EYlnzJwVsf1Ks4Gzcnl0XRx2n3PN/tvCA==";
+ JSONObject jsonObject = modelTool.exeModel2Report(param,key);//exeModel2Report
+ System.out.println(jsonObject.toString());
+ }
+}
diff --git a/dntd-tool/src/main/java/com/dky/generate/HeatBoilerSence.java b/dntd-tool/src/main/java/com/dky/generate/HeatBoilerSence.java
new file mode 100644
index 0000000..faaf5e2
--- /dev/null
+++ b/dntd-tool/src/main/java/com/dky/generate/HeatBoilerSence.java
@@ -0,0 +1,84 @@
+package com.dky.generate;
+
+import cn.hutool.json.JSONObject;
+import com.dky.calculate.Advantage;
+import com.dky.calculate.Overall;
+import com.dky.calculate.RequireDevice;
+import com.dky.entity.Heatboiler;
+import com.dky.modelI.DntdModelI;
+import com.dky.tool.ModelTool;
+import com.dky.utils.entity.DevPrice;
+import com.dky.utils.entity.DevSpec;
+import com.dky.utils.result.MatchedDevice;
+import com.dky.utils.result.MatchedDeviceResult;
+
+import java.util.*;
+
+public class HeatBoilerSence implements DntdModelI {
+ @Override
+ public JSONObject createReport(JSONObject jsonObject) {
+ JSONObject jsonReport = new JSONObject();
+ Heatboiler heatboiler = jsonObject.toBean(Heatboiler.class);
+ //生成报告
+ List specList = ModelTool.specList;
+ List priceList = ModelTool.priceList;
+ MatchedDeviceResult matchedDeviceResult = RequireDevice.matchDevices(heatboiler.getHotDevicePower(), specList, priceList);
+ Overall overall = new Overall();
+ //初次投资费用(万元)
+ Double firstInvestFee = Math.round(matchedDeviceResult.getTotalPriceInTenThousand()*100.0)/100.0;
+ //年运行费用(万元)
+ Double yearRunFee = Math.round(overall.yearRunFee(heatboiler.getYearEnergy(), heatboiler.getElectricityPrice())*100.0)/100.0;
+ //年总费用(万元)
+ Double yearTotalFee = Math.round(overall.yearTotalFee(yearRunFee)*100.0)/100.0;
+ //年减碳(吨)
+ Double yearReduceCarbon = Math.round(overall.yearReduceCarbon(heatboiler.getYearEnergy())*100.0)/100.0;
+ //替代电量
+ Double replaceEnergy = Math.round(overall.replaceEnergy(heatboiler.getYearEnergy())*100.0)/100.0;
+ //需配置设备情况
+ //方案详情
+ String reportDetail = "用直热式电锅炉替代原设备";
+ //设备类型
+ String deviceType = "";
+ //设备规格
+ String deviceSpec = "";
+ //设备数量
+ String deviceNum = "";
+ //单位(元/台、元/套)
+ String unit = "";
+ Set devTypeSet = new HashSet<>();
+ for (MatchedDevice matchedDevice : matchedDeviceResult.getMatchedDevices()) {
+ devTypeSet.add(matchedDevice.getDevSpec().getDevType());
+ deviceSpec = deviceSpec + matchedDevice.getDevSpec().getDevType() + ":"+matchedDevice.getDevSpec().getCapacity()+"蒸吨、";
+ deviceNum = deviceNum + matchedDevice.getCount() + "台/"+matchedDevice.getDevSpec().getDevType()+";";
+ int devId = matchedDevice.getDevSpec().getId();
+ for (DevPrice devPrice : priceList) {
+ if (devId == devPrice.getId()) {
+ unit = unit+devPrice.getDevPrice()+"元/台;";
+ break;
+ }
+ }
+ }
+ for (String s : devTypeSet) {
+ deviceType = deviceType + s + "、";
+ }
+ Advantage advantage = new Advantage();
+ //总价
+ String totalPrice = matchedDeviceResult.getTotalPriceInTenThousand()+"万元";
+ jsonReport.put("firstInvestFee", firstInvestFee);
+ jsonReport.put("yearRunFee", yearRunFee);
+ jsonReport.put("yearTotalFee", yearTotalFee);
+ jsonReport.put("yearReduceCarbon", yearReduceCarbon);
+ jsonReport.put("replaceEnergy", replaceEnergy);
+ jsonReport.put("reportDetail", reportDetail);
+ jsonReport.put("deviceType", deviceType);
+ jsonReport.put("deviceSpec", deviceSpec);
+ jsonReport.put("deviceNum", deviceNum);
+ jsonReport.put("unit", unit);
+ jsonReport.put("totalPrice", totalPrice);
+ jsonReport.put("safety", advantage.safety());
+ jsonReport.put("economy", advantage.economy(firstInvestFee,yearTotalFee,yearRunFee,heatboiler.getOriginalDevice().getLastYearFee()));
+ jsonReport.put("intelligence", advantage.intelligence());
+ jsonReport.put("environment", advantage.environment(yearReduceCarbon));
+ return jsonReport;
+ }
+}
diff --git a/dntd-tool/src/main/java/com/dky/security/GetCpuInfo.java b/dntd-tool/src/main/java/com/dky/security/GetCpuInfo.java
new file mode 100644
index 0000000..3ad24f7
--- /dev/null
+++ b/dntd-tool/src/main/java/com/dky/security/GetCpuInfo.java
@@ -0,0 +1,75 @@
+package com.dky.security;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Scanner;
+
+public class GetCpuInfo {
+ /**
+ * 获取当前系统CPU序列,可区分linux系统和windows系统
+ */
+ public static String getCpuId() throws Exception {
+ String cpuId;
+ // 获取当前操作系统名称
+ String os = System.getProperty("os.name");
+ os = os.toUpperCase();
+
+ // linux系统用Runtime.getRuntime().exec()执行 dmidecode -t processor 查询cpu序列
+ // windows系统用 wmic cpu get ProcessorId 查看cpu序列
+ if ("LINUX".equals(os)) {
+ cpuId = getLinuxCpuId("dmidecode -t processor | grep 'ID'", "ID", ":");
+ } else {
+ cpuId = getWindowsCpuId();
+ }
+
+ return cpuId.toUpperCase().replace(" ", "");
+ }
+
+ /**
+ * 获取linux系统CPU序列
+ */
+ public static String getLinuxCpuId(String cmd, String record, String symbol) throws Exception {
+ String execResult = executeLinuxCmd(cmd);
+ String[] infos = execResult.split("\n");
+ for (String info : infos) {
+ info = info.trim();
+ if (info.indexOf(record) != -1) {
+ info.replace(" ", "");
+ String[] sn = info.split(symbol);
+ return sn[1];
+ }
+ }
+ return null;
+ }
+
+ public static String executeLinuxCmd(String cmd) throws Exception {
+ Runtime run = Runtime.getRuntime();
+ Process process;
+ process = run.exec(cmd);
+ InputStream in = process.getInputStream();
+ BufferedReader bs = new BufferedReader(new InputStreamReader(in));
+ StringBuffer out = new StringBuffer();
+ byte[] b = new byte[8192];
+ for (int n; (n = in.read(b)) != -1; ) {
+ out.append(new String(b, 0, n));
+ }
+ in.close();
+ process.destroy();
+ return out.toString();
+ }
+
+ /**
+ * 获取windows系统CPU序列
+ */
+ public static String getWindowsCpuId() throws Exception {
+ Process process = Runtime.getRuntime().exec(
+ new String[]{"wmic", "cpu", "get", "ProcessorId"});
+ process.getOutputStream().close();
+ Scanner sc = new Scanner(process.getInputStream());
+ sc.next();
+ String serial = sc.next();
+ return serial;
+ }
+
+}
diff --git a/dntd-tool/src/main/java/com/dky/security/SM4Utils.java b/dntd-tool/src/main/java/com/dky/security/SM4Utils.java
new file mode 100644
index 0000000..0771fbb
--- /dev/null
+++ b/dntd-tool/src/main/java/com/dky/security/SM4Utils.java
@@ -0,0 +1,74 @@
+package com.dky.security;
+
+import org.bouncycastle.jce.provider.BouncyCastleProvider;
+
+import javax.crypto.Cipher;
+import javax.crypto.spec.SecretKeySpec;
+import java.nio.charset.StandardCharsets;
+import java.security.Security;
+import java.util.ArrayList;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.Map;
+
+public class SM4Utils {
+ static {
+ Security.addProvider(new BouncyCastleProvider());
+ }
+
+ private static final String SM4_KEY = "sm4demo123456789"; // 16 bytes key
+ private static final String ALGORITHM = "AES/ECB/PKCS5Padding";
+
+ public static String encrypt(Map map) throws Exception {
+
+ Cipher cipher = Cipher.getInstance(ALGORITHM, "BC");
+ SecretKeySpec secretKey = new SecretKeySpec(SM4_KEY.getBytes(StandardCharsets.UTF_8), "AES");
+ cipher.init(Cipher.ENCRYPT_MODE, secretKey);
+ byte[] encrypted = cipher.doFinal(mapToString(map).getBytes(StandardCharsets.UTF_8));
+ return Base64.getEncoder().encodeToString(encrypted);
+ }
+
+ public static Map decrypt(String encrypted) throws Exception {
+ Cipher cipher = Cipher.getInstance(ALGORITHM, "BC");
+ SecretKeySpec secretKey = new SecretKeySpec(SM4_KEY.getBytes(StandardCharsets.UTF_8), "SM4");
+ cipher.init(Cipher.DECRYPT_MODE, secretKey);
+ byte[] decoded = Base64.getDecoder().decode(encrypted);
+ byte[] decrypted = cipher.doFinal(decoded);
+ return stringToMap(new String(decrypted, StandardCharsets.UTF_8));
+ }
+
+ private static String mapToString(Map map) {
+ StringBuilder sb = new StringBuilder();
+ for (Map.Entry entry : map.entrySet()) {
+ sb.append(entry.getKey()).append('=').append(entry.getValue()).append('&');
+ }
+ return sb.toString();
+ }
+
+ private static Map stringToMap(String str) {
+ Map map = new HashMap<>();
+ String[] entries = str.split("&");
+ for (String entry : entries) {
+ String[] keyValue = entry.split("=", 2);
+ if (keyValue.length == 2) {
+ map.put(keyValue[0], keyValue[1]);
+ }
+ }
+ return map;
+ }
+
+ public static void main(String[] args) throws Exception {
+ Map map = new HashMap<>();
+ ArrayList cpuIds = new ArrayList<>();
+ cpuIds.add("duahduejdiejidi");
+ cpuIds.add("ddnfjuufhurhffr");
+ cpuIds.add("frfrjfirjfirjfir");
+ cpuIds.add("BFEBFBFF000506E3");
+ cpuIds.add("BFEBFBFF000806EA");
+ map.put("name", "模型1工具");
+ map.put("cpuIds", cpuIds.toString());
+ map.put("expireTime","2024-12-16 00:00:00");
+ String encrypted = encrypt(map);
+ System.out.println(encrypted);
+ }
+}
\ No newline at end of file
diff --git a/dntd-tool/src/main/java/com/dky/tool/ModelTool.java b/dntd-tool/src/main/java/com/dky/tool/ModelTool.java
new file mode 100644
index 0000000..e1315b5
--- /dev/null
+++ b/dntd-tool/src/main/java/com/dky/tool/ModelTool.java
@@ -0,0 +1,80 @@
+package com.dky.tool;
+
+import cn.hutool.json.JSONArray;
+import cn.hutool.json.JSONObject;
+import com.dky.modelI.DntdModelI;
+import com.dky.security.GetCpuInfo;
+import com.dky.utils.ConfigReader;
+import com.dky.utils.enums.Code;
+import com.dky.utils.entity.DevSpec;
+import com.dky.utils.entity.DevPrice;
+import com.dky.utils.result.ResponseUtil;
+import java.lang.reflect.InvocationTargetException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+
+public class ModelTool {
+ public static List specList = new ArrayList<>();
+ public static List priceList = new ArrayList<>();
+ //制热锅炉,单功率单价,单位。建缓冲区。List实体。
+ public ModelTool(JSONObject list) {
+
+ JSONArray specArray = list.getJSONArray("devSpecList");
+ for (int i = 0; i < specArray.size(); i++) {
+ DevSpec devSpec = specArray.getJSONObject(i).toBean(DevSpec.class);
+ specList.add(devSpec);
+ }
+ JSONArray priceArray = list.getJSONArray("devPriceList");
+ for (int i = 0; i < priceArray.size(); i++) {
+ DevPrice devPrice = priceArray.getJSONObject(i).toBean(DevPrice.class);
+ priceList.add(devPrice);
+ }
+ }
+ public static JSONObject exeModel2Report(JSONObject jsonObject, String key) {
+ JSONObject jsonObjectResult = new JSONObject();
+ try {
+ // 根据给定的类名初始化类 加密不需要反实例化new
+ Class sm4UtilsClass = Class.forName("com.dky.security.SM4Utils");
+ // 实例化这个类
+ Object obj = sm4UtilsClass.newInstance();
+ // 调用指定方法
+ Map map = (Map) sm4UtilsClass.getMethod("decrypt", String.class).invoke(obj, key);
+ String cpuIds = (String) map.get("cpuIds");
+ String expireTime = (String) map.get("expireTime");
+ // 定义日期时间格式
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Date date = formatter.parse(expireTime);
+ //拿到解析后的cpuid。获取本地的cpuid.
+ String localCpuId = GetCpuInfo.getCpuId();
+ if (cpuIds.contains(localCpuId)){
+ if (new Date().before(date)){
+ //判断模型使用权限
+ // 根据给定的类名初始化类 加密不需要反实例化new
+ Class modelI = Class.forName("com.dky"+"."+ ConfigReader.getProperty(jsonObject.getStr("type")));
+ // 实例化这个类
+ DntdModelI modelI1 = (DntdModelI)modelI.newInstance();
+ // 调用指定方法
+ jsonObjectResult = modelI1.createReport(jsonObject);
+ }else {
+ jsonObjectResult = ResponseUtil.createResponse(Code.KEY_EXPIRATION.getCode(), Code.KEY_EXPIRATION.getDesc(), null);
+ }
+ }else {
+ jsonObjectResult = ResponseUtil.createResponse(Code.KEY_UNAUTHORIZED.getCode(), Code.KEY_UNAUTHORIZED.getDesc(), null);
+ }
+ } catch (ClassNotFoundException e) {
+ e.printStackTrace();
+ } catch (InstantiationException e) {
+ e.printStackTrace();
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return jsonObjectResult;
+ }
+}
\ No newline at end of file
diff --git a/dntd-tool/src/main/resources/modelCode.properties b/dntd-tool/src/main/resources/modelCode.properties
new file mode 100644
index 0000000..25eebae
--- /dev/null
+++ b/dntd-tool/src/main/resources/modelCode.properties
@@ -0,0 +1 @@
+0101=generate.HeatBoilerSence
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..5a09f68
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,61 @@
+
+
+ 4.0.0
+
+ com.dky
+ dntd-model-tool1
+ 1.0-SNAPSHOT
+ pom
+
+ dntd-tool
+ dntd-model-heatboiler
+ dntd-modelI
+ dntd-common
+
+
+
+ 8
+ 8
+ UTF-8
+
+
+
+
+
+ cn.hutool
+ hutool-all
+ 5.4.5
+
+
+
+
+
+
+
+ com.dwp
+ obfuscation
+ 1.0.0
+
+
+ compile
+
+ obfuscation
+
+
+
+
+ ${basedir}
+ ${basedir}/target/classes
+
+
+
+
+
+ src/main/resources/
+ true
+
+
+
+
\ No newline at end of file