wangmiaomiao 8 months ago
parent
commit
ba4bc55e50

+ 14 - 5
slibra-common/src/main/java/com/slibra/common/DecimalUtils.java

@@ -1,10 +1,12 @@
 package com.slibra.common;
 
+import com.alibaba.fastjson2.JSON;
 import com.alibaba.fastjson2.JSONArray;
 import com.slibra.common.utils.StringUtils;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 import java.util.Objects;
@@ -40,13 +42,10 @@ public class DecimalUtils {
     }
 
     public static String getAbsForArray(String list, int length) {
-        if ( Objects.isNull( list ) ) {
+        if (StringUtils.isBlank(list)) {
             return null;
         }
-
-        List<BigDecimal> arrayStr = JSONArray.parseArray(list, BigDecimal.class).stream().map(num -> getAbsAndScale(num, length)).collect(Collectors.toList());
-
-        return arrayStr.toString();
+        return JSONArray.parseArray(list, BigDecimal.class).stream().map(num -> getAbsAndScale(num, length)).collect(Collectors.toList()).toString();
     }
 
 
@@ -54,5 +53,15 @@ public class DecimalUtils {
         System.out.println(getAbsAndScale(null, 3));
         System.out.println(getAbsAndScale(new BigDecimal("33.33333"), 3));
         System.out.println(getAbsAndScale(new BigDecimal("-33.33333"), 3));
+        List<Double> list = new ArrayList<>();
+        list.add(1.1D);
+        list.add(1.2D);
+        list.add(1.3D);
+        System.out.println(list.toString());
+        System.out.println(JSON.toJSONString(list));
+
+        System.out.println(getAbsForArray("a", 1));
+
+        System.out.println(new BigDecimal(1.1).divide(new BigDecimal(1.3), 0, RoundingMode.HALF_UP));
     }
 }

+ 2 - 2
slibra-common/src/main/java/com/slibra/common/utils/format/WaterFormat.java

@@ -90,10 +90,10 @@ public class WaterFormat {
         decisionReq.setBodIn(DecimalUtils.getAbsAndScale(daily.getJsBod5(), INT_0));
         if(!Objects.isNull(jsBod5)){
             if(!Objects.isNull(tpIn) && tpIn.compareTo(new BigDecimal("0")) >0){
-                decisionReq.setC(DecimalUtils.getAbsAndScale(jsBod5.divide(tpIn, 4, RoundingMode.HALF_UP), INT_0));
+                decisionReq.setC(jsBod5.divide(tpIn, INT_0, RoundingMode.HALF_UP));
             }
             if(!Objects.isNull(tnIn) && tnIn.compareTo(new BigDecimal("0")) >0){
-                decisionReq.setC(DecimalUtils.getAbsAndScale(jsBod5.divide(tnIn, 4, RoundingMode.HALF_UP), INT_0));
+                decisionReq.setC(jsBod5.divide(tnIn, INT_0, RoundingMode.HALF_UP));
             }
         }
         // decisionReq.setT(DecimalUtils.getAbsAndScale(daily.getJsSw(), MyConstants.INT_0));

+ 12 - 12
slibra-quartz/src/main/java/com/slibra/quartz/business/JsCsFormatData.java

@@ -32,32 +32,32 @@ public class JsCsFormatData {
         HashMap<Object, Object> temp1 = new HashMap<>();
         BigDecimal jsSlq = tXinyiIndustry.getJsSlq();
         temp1.put("value", DecimalUtils.getAbsAndScale(jsSlq, INT_2));
-        temp1.put("exceed", jsSlq.compareTo(normConfig.getJsslSjz()) >0);
+        temp1.put("exceed", !Objects.isNull(jsSlq) && jsSlq.compareTo(normConfig.getJsslSjz()) >0);
         jsData.put("流量", temp1);
         HashMap<Object, Object> temp2 = new HashMap<>();
         BigDecimal jsCod = tXinyiIndustry.getJsCod();
         temp2.put("value", DecimalUtils.getAbsAndScale(jsCod, INT_2));
-        temp2.put("exceed", jsCod.compareTo(normConfig.getJscodSjz()) > 0);
+        temp2.put("exceed", !Objects.isNull(jsCod) && jsCod.compareTo(normConfig.getJscodSjz()) > 0);
         jsData.put("COD", temp2);
         HashMap<Object, Object> temp3 = new HashMap<>();
         BigDecimal jsNh3 = tXinyiIndustry.getJsNh3();
         temp3.put("value", DecimalUtils.getAbsAndScale(jsNh3, INT_2));
-        temp3.put("exceed", jsNh3.compareTo(normConfig.getJsadSjz()) > 0);
+        temp3.put("exceed", !Objects.isNull(jsNh3) && jsNh3.compareTo(normConfig.getJsadSjz()) > 0);
         jsData.put("NH3-N", temp3);
         HashMap<Object, Object> temp4 = new HashMap<>();
         BigDecimal jsTp = tXinyiIndustry.getJsTp();
         temp4.put("value", DecimalUtils.getAbsAndScale(jsTp, INT_2));
-        temp4.put("exceed", jsTp.compareTo(normConfig.getJszlSjz()) > 0);
+        temp4.put("exceed", !Objects.isNull(jsTp) && jsTp.compareTo(normConfig.getJszlSjz()) > 0);
         jsData.put("TP", temp4);
         HashMap<Object, Object> temp5 = new HashMap<>();
         BigDecimal jsSs = tXinyiIndustry.getJsSs();
         temp5.put("value", DecimalUtils.getAbsAndScale(jsSs, INT_2));
-        temp5.put("exceed", jsSs.compareTo(normConfig.getJsssSjz()) > 0);
+        temp5.put("exceed", !Objects.isNull(jsSs) && jsSs.compareTo(normConfig.getJsssSjz()) > 0);
         jsData.put("SS", temp5);
         HashMap<Object, Object> temp6 = new HashMap<>();
         BigDecimal jsTn = tXinyiIndustry.getJsTn();
         temp6.put("value", DecimalUtils.getAbsAndScale(jsTn, INT_2));
-        temp6.put("exceed", jsTn.compareTo(normConfig.getJszdSjz()) > 0);
+        temp6.put("exceed", !Objects.isNull(jsTn) && jsTn.compareTo(normConfig.getJszdSjz()) > 0);
         jsData.put("TN", temp6);
         return jsData;
     }
@@ -70,7 +70,7 @@ public class JsCsFormatData {
         HashMap<Object, Object> temp1 = new HashMap<>();
         BigDecimal csCod = tXinyiIndustry.getCsCod();
         temp1.put("value", DecimalUtils.getAbsAndScale(csCod, INT_2));
-        temp1.put("exceed", csCod.compareTo(normConfig.getCscodGkz()) > 0);
+        temp1.put("exceed", !Objects.isNull(csCod) && csCod.compareTo(normConfig.getCscodGkz()) > 0);
         csData.put("COD", temp1);
 
         // 好氧池硝酸盐 | 二沉池正磷酸盐 | 连续监测 - 化验室
@@ -88,13 +88,13 @@ public class JsCsFormatData {
             HashMap<Object, Object> temp4 = new HashMap<>();
 
             temp2.put("value", DecimalUtils.getAbsAndScale(hl1Jqr, INT_2));
-            temp2.put("exceed", Objects.isNull(hl1Jqr) ?  false : hl1Jqr.compareTo(normConfig.getCszzGkz()) > 0);
+            temp2.put("exceed", !Objects.isNull(hl1Jqr) && hl1Jqr.compareTo(normConfig.getCszzGkz()) > 0);
 
             temp3.put("value", DecimalUtils.getAbsAndScale(hl2Jqr, INT_2));
-            temp3.put("exceed", Objects.isNull(hl2Jqr) ?  false : hl1Jqr.compareTo(normConfig.getCszzGkz()) > 0);
+            temp3.put("exceed", !Objects.isNull(hl2Jqr) && hl2Jqr.compareTo(normConfig.getCszzGkz()) > 0);
 
             temp4.put("value", DecimalUtils.getAbsAndScale(tpRccJqr, INT_2));
-            temp4.put("exceed", Objects.isNull(tpRccJqr) ? false : csTp.compareTo(normConfig.getCszlGkz()) > 0);
+            temp4.put("exceed", !Objects.isNull(tpRccJqr) && tpRccJqr.compareTo(normConfig.getCszlGkz()) > 0);
 
             csData.put("HYC1", temp2);
             csData.put("HYC2", temp3);
@@ -105,14 +105,14 @@ public class JsCsFormatData {
         HashMap<Object, Object> temp3 = new HashMap<>();
         BigDecimal csNh3 = tXinyiIndustry.getCsNh3();
         temp3.put("value", DecimalUtils.getAbsAndScale(csNh3, INT_2));
-        temp3.put("exceed", csNh3.compareTo(normConfig.getCsadGkz()) > 0);
+        temp3.put("exceed", !Objects.isNull(csNh3) && csNh3.compareTo(normConfig.getCsadGkz()) > 0);
         csData.put("NH3-N", temp3);
 
         // 出水SS | 在线仪表 - 工业
         HashMap<Object, Object> temp5 = new HashMap<>();
         BigDecimal csSs = tXinyiIndustry.getCsSs();
         temp5.put("value", DecimalUtils.getAbsAndScale(csSs, INT_2));
-        temp5.put("exceed", csSs.compareTo(normConfig.getCsssGkz()) > 0);
+        temp5.put("exceed", !Objects.isNull(csSs) && csSs.compareTo(normConfig.getCsssGkz()) > 0);
         csData.put("SS", temp5);
 
         return csData;

+ 2 - 2
slibra-quartz/src/main/java/com/slibra/quartz/task/AsyncTask.java

@@ -1330,13 +1330,13 @@ public class AsyncTask {
                         BigDecimal no3Hlj1Jqr = tXinyiRobot.getNo3Hlj1Jqr();
                         BigDecimal no3Hlj2Jqr = tXinyiRobot.getNo3Hlj2Jqr();
                         if(!Objects.isNull(no3Hlj1Jqr) && !Objects.isNull(no3Hlj2Jqr)){
-                            decisionReq.setTnOff((no3Hlj1Jqr.add(no3Hlj2Jqr)).divide((new BigDecimal("2").multiply(ROBOT_HY_DIVIDE)), NUMBER_SCALE_4, RoundingMode.HALF_UP));
+                            decisionReq.setTnOff((no3Hlj1Jqr.add(no3Hlj2Jqr)).divide((new BigDecimal("2").multiply(ROBOT_HY_DIVIDE)), INT_0, RoundingMode.HALF_UP));
                         }
 
                         //总磷
                         BigDecimal tpRccJqr = tXinyiRobot.getTpRccJqr();
                         if(!Objects.isNull(tpRccJqr)){
-                            decisionReq.setTpOff(tpRccJqr.divide(ROBOT_HY_DIVIDE, NUMBER_SCALE_4, RoundingMode.HALF_UP));
+                            decisionReq.setTpOff(tpRccJqr.divide(ROBOT_HY_DIVIDE, INT_0, RoundingMode.HALF_UP));
                         }
                     }
                 }