Commit 01346728 authored by 刘林's avatar 刘林

fix(jg):处理管道计算总长度精度问题

parent 9a26c1af
...@@ -106,6 +106,7 @@ import java.io.*; ...@@ -106,6 +106,7 @@ import java.io.*;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
...@@ -2495,11 +2496,7 @@ public class CommonServiceImpl implements ICommonService { ...@@ -2495,11 +2496,7 @@ public class CommonServiceImpl implements ICommonService {
if (manageType.equals(UNIT) && !CollectionUtils.isEmpty(equips)) { if (manageType.equals(UNIT) && !CollectionUtils.isEmpty(equips)) {
//管道计算的是管道长度 //管道计算的是管道长度
if ("8000".equals(formData.getString("equListCode")) || "8000".equals(formData.getString("EQU_LIST_CODE"))) { if ("8000".equals(formData.getString("equListCode")) || "8000".equals(formData.getString("EQU_LIST_CODE"))) {
double pipeLength = equips.stream().filter(Objects::nonNull) formData.put("equNum", calTotalLength(equips) + "(m)");
.filter(map -> map.containsKey("pipeLength") && StringUtils.isNotEmpty((String) map.get("pipeLength")))
.mapToDouble(map -> Double.parseDouble((String) map.get("pipeLength")))
.sum();
formData.put("equNum", pipeLength + "(m)");
} else { } else {
//设备数量 //设备数量
formData.put("equNum", equipmentLists.size()); formData.put("equNum", equipmentLists.size());
...@@ -2599,6 +2596,12 @@ public class CommonServiceImpl implements ICommonService { ...@@ -2599,6 +2596,12 @@ public class CommonServiceImpl implements ICommonService {
return formData; return formData;
} }
public static String calTotalLength(List<Map<String, Object>> equList) {
double pipeLengthSum = equList.stream().map(r -> r.get("pipeLength")).filter(Objects::nonNull).mapToDouble(l -> Double.parseDouble(String.valueOf(l))).sum();
BigDecimal pipeLengthSumBig = new BigDecimal(String.valueOf(pipeLengthSum)).setScale(3, RoundingMode.HALF_UP);
return pipeLengthSumBig.toPlainString();
}
public List<JSONObject> buildFileForOverDesign(JSONObject jsonObject) { public List<JSONObject> buildFileForOverDesign(JSONObject jsonObject) {
List<JSONObject> formDataList = new ArrayList<>(); List<JSONObject> formDataList = new ArrayList<>();
if (jsonObject.containsKey("equipmentLists")) { if (jsonObject.containsKey("equipmentLists")) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment