1.增加秘钥错误返回码
2.将计算成本和效率占比调成可输入
3.将合同容量系数设置静态常量
4.优化返回,返回设备列表
5.清除不必要代码
master
林颖晨 1 year ago
parent a253c3a9c3
commit 470756724a
  1. 3
      dntd-common/src/main/java/com/dky/utils/enums/Code.java
  2. 24
      dntd-model-buildheating/src/main/java/com/dky/calculate/BuildHeatingAdvantage.java
  3. 18
      dntd-model-buildheating/src/main/java/com/dky/calculate/SchemeRating.java
  4. 111
      dntd-tool/src/main/java/com/dky/generate/BuildHeatingSence.java
  5. 7
      dntd-tool/src/main/java/com/dky/tool/ModelTool.java

@ -6,7 +6,8 @@ public enum Code {
SUCCESS(1001, "成功"),
KEY_EXPIRATION(1002, "密钥已过期"),
KEY_UNAUTHORIZED(1003, "密钥本机未授权");
KEY_UNAUTHORIZED(1003, "密钥未在本机授权"),
KEY_CONTEXT_ERROR(1004, "密钥错误");
/**

@ -0,0 +1,24 @@
package com.dky.calculate;
//方案优势
public class BuildHeatingAdvantage {
//安全性
public static String safety(){
return "精准控温";
}
//经济性
public static 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 static String intelligence() {
return "以电锅炉替代和实现精准控温。";
}
// 环保性
public static String environment(Double yearReduceCarbon) {
return "本次改造方案减排" + yearReduceCarbon + "吨";
}
}

@ -8,8 +8,12 @@ import java.util.concurrent.atomic.AtomicReference;
public class SchemeRating {
public static Map<Double, List<MatchedDevice>> getOptimalList(List<Map<String, List<List<MatchedDevice>>>> list) {
/**
* 计算效率和成本评分
* @param list
* @return
*/
public static Map<Double, List<MatchedDevice>> getOptimalList(List<Map<String, List<List<MatchedDevice>>>> list,Double costRatio,Double effRatio) {
Map<Double, List<MatchedDevice>> optimalMap = new HashMap<>();
list.parallelStream().forEach(stringListMap -> {
// 区分热泵、电锅炉
@ -29,9 +33,8 @@ public class SchemeRating {
for (MatchedDevice device : plan) {
cost = cost + ((device.getCount() * device.getDeviceHeatScene().getDevPrice()) + (device.getCount()) * device.getDeviceHeatScene().getDevSubstituteLaborCost() * device.getDeviceHeatScene().getDevServiceLife());
}
rating.set(((1 - ((v1[0] - eff) / v1[0])) * 100 * 0.8) + ((1 - ((cost - v1[1]) / v1[1])) * 100 * 0.2));
// System.out.println("方案: " + plan + ",评分 = " + rating + "\n");
//3、效率成本公式:(1-(选择效率最大-当前值)/效率最大值)*100*0.8 +(1-(当前值-选择成本最小)/成本最小值)*100*0.2。
rating.set(((1 - ((v1[0] - eff) / v1[0])) * 100 * effRatio) + ((1 - ((cost - v1[1]) / v1[1])) * 100 * costRatio));
optimalMap.put(rating.get(), plan);
}
});
@ -42,6 +45,11 @@ public class SchemeRating {
return optimalMap;
}
/**
* 获取最优评分
* @param map
* @return
*/
public static List<MatchedDevice> getOptimalScheme(Map<Double, List<MatchedDevice>> map) {
Set<Double> keySet = map.keySet();
Double maxValue = keySet.iterator().next();

@ -19,6 +19,10 @@ public class BuildHeatingSence implements DntdModelI {
DecimalFormat decimalFormat = new DecimalFormat("#.00");
//首先A=由运行/合同容量折合成kW(x0.9)x85%,
static final Double COEFFICIENT_1 = 0.9;
static final Double COEFFICIENT_2 = 0.85;
@Override
public JSONObject createReport(JSONObject jsonObject2) {
List<SysDeviceHeatScene> list = ModelTool.specList;
@ -36,10 +40,13 @@ public class BuildHeatingSence implements DntdModelI {
// 上年运行费用(万元)
Double lastYearFee = Double.parseDouble(buildInfo.get("lastYearFee").toString());
Double A = runCapacity * 0.9 * 0.85;
// A=由运行/合同容量折合成kW(x0.9)x85%,
Double A = runCapacity * COEFFICIENT_1 * COEFFICIENT_2;
// 冗余容量
Double B = A - lastYearNeed;
//投入供热设备总功率C
AtomicReference<Double> C = new AtomicReference<>();
//投入供热设备总功率C1
AtomicReference<Double> C1 = new AtomicReference<>();
List<Map<String, List<List<MatchedDevice>>>> calScheme = Scheme.calScheme(heatingArea, list);
List<Map<String, Double>> mapsC = CalC.getC(calScheme);
@ -54,24 +61,36 @@ public class BuildHeatingSence implements DntdModelI {
}
});
}
Double D = lastYearNeed + C.get();
Double D1 = lastYearNeed + C1.get();
List<MatchedDevice> matchedDeviceList;
Map<Double, List<MatchedDevice>> listMap;
// 判断只能用热泵
Double costRatio = 0.2;
Double effRatio = 0.8;
//获取计算占比
try{
Double costRatio1 = Double.parseDouble(jsonObject2.get("costRatio").toString());
Double effRatio1 = Double.parseDouble(jsonObject2.get("effRatio").toString());
if(costRatio1 < 1 && costRatio1 + costRatio1 == 1){
costRatio = costRatio1;
effRatio = effRatio1;
}
}catch (Exception e){
e.printStackTrace();
}
if (D1 < A && A < D) {
// 判断只能用热泵
List<SysDeviceHeatScene> deviceList = new ArrayList<>();
list.parallelStream().forEach((sysDeviceHeatScene -> {
if (!sysDeviceHeatScene.getDevTechType().contains("电锅炉")) {
deviceList.add(sysDeviceHeatScene);
}
}));
listMap = SchemeRating.getOptimalList(Scheme.calScheme(heatingArea, deviceList));
listMap = SchemeRating.getOptimalList(Scheme.calScheme(heatingArea, deviceList),costRatio,effRatio);
matchedDeviceList = SchemeRating.getOptimalScheme(listMap);
} else {
listMap = SchemeRating.getOptimalList(calScheme);
listMap = SchemeRating.getOptimalList(calScheme,costRatio,effRatio);
matchedDeviceList = SchemeRating.getOptimalScheme(listMap);
}
@ -85,44 +104,50 @@ public class BuildHeatingSence implements DntdModelI {
});
JSONObject jsonObject = new JSONObject();
AtomicReference<String> planInfos = new AtomicReference<>();
AtomicReference<String> devTechType = new AtomicReference<>();
AtomicReference<String> devSubType = new AtomicReference<>();
AtomicReference<String> devCount = new AtomicReference<>();
AtomicReference<String> devPrice = new AtomicReference<>();
AtomicReference<Double> startCost = new AtomicReference<>(0.0);
AtomicReference<Double> runCost = new AtomicReference<>(0.0);
AtomicReference<Double> allCost = new AtomicReference<>(0.0);
AtomicReference<Double> calculateAnnualCarbon = new AtomicReference<>(0.0);
AtomicReference<Double> electric = new AtomicReference<>(0.0);
matchedDeviceList.parallelStream().forEach((matchedDevice -> {
planInfos.set(planInfos.get() + "设备: " + matchedDevice.getDeviceHeatScene().getDevType() + ",技术: " + matchedDevice.getDeviceHeatScene().getDevTechType() + ",数量 = " + matchedDevice.getCount() + "。");
devTechType.set(devTechType.get() + "设备: " + matchedDevice.getDeviceHeatScene().getDevType() + ",技术: " + matchedDevice.getDeviceHeatScene().getDevTechType() + "。");
devSubType.set(devSubType.get() + "设备: " + matchedDevice.getDeviceHeatScene().getDevType() + ",设备细类: " + matchedDevice.getDeviceHeatScene().getDevSubType() + "。");
devCount.set(devCount.get() + "设备: " + matchedDevice.getDeviceHeatScene().getDevType() + ",数量 = " + matchedDevice.getCount() + "。");
devPrice.set(devPrice.get() + "设备: " + matchedDevice.getDeviceHeatScene().getDevType() + ",单价 = " + matchedDevice.getDeviceHeatScene().getDevPrice() + "。");
startCost.set(startCost.get() + (matchedDevice.getCount() * matchedDevice.getDeviceHeatScene().getDevPrice()));
runCost.set(runCost.get() + (BuildHeatingModel.getRunCost(matchedDevice.getCount(), matchedDevice.getDeviceHeatScene().getDevPower(), days, matchedDevice.getDeviceHeatScene().getDevSubstituteLaborCost())));
allCost.set(allCost.get() + (BuildHeatingModel.getYearCost(matchedDevice.getCount(), matchedDevice.getDeviceHeatScene().getDevPrice(), matchedDevice.getDeviceHeatScene().getDevServiceLife(), matchedDevice.getDeviceHeatScene().getDevPower(), days, matchedDevice.getDeviceHeatScene().getDevSubstituteLaborCost())));
calculateAnnualCarbon.set(calculateAnnualCarbon.get() + (BuildHeatingModel.calculateAnnualCarbonReduction(lastYearFee, matchedDevice.getDeviceHeatScene().getLaborCost(), matchedDevice.getCount(), matchedDevice.getDeviceHeatScene().getDevPower(), days)));
electric.set(electric.get() + (BuildHeatingModel.getElectric(matchedDevice.getCount(), matchedDevice.getDeviceHeatScene().getDevPower(), days)));
}));
jsonObject.put("startCost", decimalFormat.format(startCost.get()));
jsonObject.put("yearRunCost", decimalFormat.format(runCost.get()));
jsonObject.put("yearCost", decimalFormat.format(allCost.get()));
jsonObject.put("calculate", decimalFormat.format(calculateAnnualCarbon.get()));
jsonObject.put("electric", decimalFormat.format(electric.get()));
jsonObject.put("planInfos", planInfos.get().replace("null",""));
jsonObject.put("devTechType", devTechType.get().replace("null",""));
jsonObject.put("devSubType", devSubType.get().replace("null",""));
jsonObject.put("devCount", devCount.get().replace("null",""));
jsonObject.put("devPrice", devPrice.get().replace("null",""));
jsonObject.put("devCost", decimalFormat.format(startCost.get()));
jsonObject.put("safety", "精准控温");
Double startCost = 0.0;
Double runCost = 0.0;
Double allCost = 0.0;
Double calculateAnnualCarbon = 0.0;
Double electric = 0.0;
List<HashMap<String,Object>> deviceList = new ArrayList<>();
//封装整体情况
for (MatchedDevice matchedDevice : matchedDeviceList){
HashMap<String, Object> map = new HashMap<>();
map.put("devSubType",matchedDevice.getDeviceHeatScene().getDevSubType());
map.put("devTechType",matchedDevice.getDeviceHeatScene().getDevTechType());
map.put("devCount",matchedDevice.getCount());
map.put("devPrice",matchedDevice.getDeviceHeatScene().getDevPrice());
deviceList.add(map);
startCost = startCost + (matchedDevice.getCount() * matchedDevice.getDeviceHeatScene().getDevPrice());
runCost = runCost + (BuildHeatingModel.getRunCost(matchedDevice.getCount(), matchedDevice.getDeviceHeatScene().getDevPower(), days, matchedDevice.getDeviceHeatScene().getDevSubstituteLaborCost()));
allCost = allCost + (BuildHeatingModel.getYearCost(matchedDevice.getCount(), matchedDevice.getDeviceHeatScene().getDevPrice(), matchedDevice.getDeviceHeatScene().getDevServiceLife(), matchedDevice.getDeviceHeatScene().getDevPower(), days, matchedDevice.getDeviceHeatScene().getDevSubstituteLaborCost()));
calculateAnnualCarbon = calculateAnnualCarbon + (BuildHeatingModel.calculateAnnualCarbonReduction(lastYearFee, matchedDevice.getDeviceHeatScene().getLaborCost(), matchedDevice.getCount(), matchedDevice.getDeviceHeatScene().getDevPower(), days));
electric = electric + (BuildHeatingModel.getElectric(matchedDevice.getCount(), matchedDevice.getDeviceHeatScene().getDevPower(), days));
}
//初次投资费用
jsonObject.put("startCost", decimalFormat.format(startCost));
//年运行费用
jsonObject.put("yearRunCost", decimalFormat.format(runCost));
//年总费用
jsonObject.put("yearCost", decimalFormat.format(allCost));
//年减碳量
jsonObject.put("calculate", decimalFormat.format(calculateAnnualCarbon));
//替代电量
jsonObject.put("electric", decimalFormat.format(electric));
//封装需配置设备情况
jsonObject.put("deviceList",deviceList);
//封装方案优势
jsonObject.put("safety", BuildHeatingAdvantage.safety());
jsonObject.put("economy", BuildHeatingAdvantage.economy(startCost, allCost, runCost, lastYearFee));
jsonObject.put("intelligence", BuildHeatingAdvantage.intelligence());
jsonObject.put("environment", BuildHeatingAdvantage.environment(Double.valueOf(decimalFormat.format(calculateAnnualCarbon))));
//封装方案评分
jsonObject.put("matchedDeviceList", maps);
jsonObject.put("economy", Advantage.economy(startCost.get(), allCost.get(), runCost.get(), lastYearFee));
jsonObject.put("intelligence", Advantage.intelligence());
jsonObject.put("environment", Advantage.environment(Double.valueOf(decimalFormat.format(calculateAnnualCarbon.get()))));
return jsonObject;
}

@ -19,7 +19,6 @@ import java.util.Map;
public class ModelTool {
public static List<SysDeviceHeatScene> specList = new ArrayList<>();
// public static List<DevPrice> priceList = new ArrayList<>();
// 制热锅炉,单功率单价,单位。建缓冲区。List实体。
public ModelTool(JSONObject list) {
@ -28,11 +27,6 @@ public class ModelTool {
SysDeviceHeatScene devSpec = specArray.getJSONObject(i).toBean(SysDeviceHeatScene.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();
@ -72,6 +66,7 @@ public class ModelTool {
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
jsonObjectResult = ResponseUtil.createResponse(Code.KEY_CONTEXT_ERROR.getCode(), Code.KEY_CONTEXT_ERROR.getDesc(), null);
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();

Loading…
Cancel
Save