Prechádzať zdrojové kódy

完善电度采集,负值都取绝对值然后计算

hfxc226 6 mesiacov pred
rodič
commit
a8d32b8c6c

+ 11 - 6
platform-service/src/main/java/com/platform/service/big/impl/BigScreenSbInfoServiceImpl.java

@@ -260,12 +260,12 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
                                         Optional<RemoteDegreeLogVO> lastR = lastList.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum())).findFirst();
                                         if(lastR.isPresent()){
                                             log.info(JSONObject.toJSONString(lastR.get()));
-                                            positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()));
+                                            positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()).abs());
                                         }
                                     }else{// 从今天上个时间找,减去上个小时的数据
                                         Optional<RemoteDegreeLogVO> lastR = list.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum()) && item.getHour().equals(degreeLog.getHour()-1)).findFirst();
                                         if(lastR.isPresent()){
-                                            positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()));
+                                            positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()).abs());
                                         }
                                     }
                                     dictJsonObject.put("positive", positiveTotal.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue());
@@ -276,12 +276,12 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
                                         Optional<RemoteDegreeLogVO> lastR = lastList.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum())).findFirst();
                                         if(lastR.isPresent()){
                                             log.info(JSONObject.toJSONString(lastR.get()));
-                                            negativeTotal = negativeTotal.subtract(new BigDecimal(lastR.get().getResult()));
+                                            negativeTotal = negativeTotal.subtract(new BigDecimal(lastR.get().getResult()).abs());
                                         }
                                     }else{// 从今天上个时间找,减去上个小时的数据
                                         Optional<RemoteDegreeLogVO> lastR = list.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum()) && item.getHour().equals(degreeLog.getHour()-1)).findFirst();
                                         if(lastR.isPresent()){
-                                            negativeTotal = negativeTotal.subtract(new BigDecimal(lastR.get().getResult()));
+                                            negativeTotal = negativeTotal.subtract(new BigDecimal(lastR.get().getResult()).abs());
                                         }
                                     }
                                     dictJsonObject.put("negative", negativeTotal.divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP).doubleValue());
@@ -308,6 +308,11 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
             lastDay.setDay(calendar.getActualMaximum(Calendar.DATE));
             List<RemoteDegreeLogVO> lastList = remoteDegreeLogMapper.selectList(lastDay);
 
+            // 全部取绝对值,有负数的去掉
+            for (RemoteDegreeLogVO degreeLog : lastList) {
+                degreeLog.setResult(degreeLog.getResult().replace("-", ""));
+            }
+
             for (int i = 1; i <= days; i++) {
                 JSONObject jsonObject = new JSONObject();
                 jsonObject.put("time", i);
@@ -333,13 +338,13 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
                                         Optional<RemoteDegreeLogVO> lastR = lastList.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum())).findFirst();
                                         if(lastR.isPresent()){
                                             //log.info("1: " + degreeLog.getDay() + "," + degreeLog.getDay() + ","+ degreeLog.getDay() + ","+ lastR.get().getDay());
-                                            positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()));
+                                            positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()).abs());
                                         }
                                     }else{// 从后天时间找,减去昨天的数据
                                         Optional<RemoteDegreeLogVO> lastR = list.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum()) && item.getDay().equals(degreeLog.getDay()+1)).findFirst();
                                         if(lastR.isPresent()){
                                             //log.info("2: " + degreeLog.getDay() + "," + lastR.get().getDay());
-                                            positiveTotal = new BigDecimal(lastR.get().getResult()).subtract(positiveTotal);
+                                            positiveTotal = new BigDecimal(lastR.get().getResult()).abs().subtract(positiveTotal);
                                         }
                                     }
                                 }