Browse Source

完善电度计算方式

hfxc226 2 years ago
parent
commit
e42916e93a

+ 13 - 3
platform-common/src/main/java/com/platform/common/util/DateUtils.java

@@ -465,8 +465,8 @@ public class DateUtils {
 
     public static void main(String[] args) {
         Calendar calendar = Calendar.getInstance();
-        calendar.set(2022,0,1,0,2, 30);
-        getLastDay(calendar);
+        calendar.set(2022,11-2,1,0,2, 30);
+        getLastMonth(calendar);
     }
 
     /**
@@ -638,7 +638,7 @@ public class DateUtils {
     }
 
     /**
-     * 获取前一天时间*
+     * 获取前一天时间
      * @param calendar
      */
     public static void getLastDay(Calendar calendar){
@@ -646,5 +646,15 @@ public class DateUtils {
         SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         System.out.println("一个小时前的时间:" + df.format(calendar.getTime()));
     }
+
+    /**
+     * 获取上个月时间
+     * @param calendar
+     */
+    public static void getLastMonth(Calendar calendar){
+        calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH) - 1);
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        System.out.println("上个月的时间:" + df.format(calendar.getTime()));
+    }
 }
 

+ 8 - 2
platform-iec/src/main/java/com/ydl/iec/util/MySqlUtil.java

@@ -26,11 +26,17 @@ public class MySqlUtil {
     //是否连接数据库
     public static String mysql_open = "false";
     //数据库连接地址
-    public static String mysql_url = "jdbc:mysql://192.168.16.222:3306/hitch-sb";
+    public static String mysql_url = "jdbc:mysql://123.60.19.203:5006/hitch-sb";
     //用户名
     public static String mysql_username = "root";
     //密码
-    public static String mysql_password = "mydm888";
+    public static String mysql_password = "mysql?MYSQLmoniu123";
+    //数据库连接地址
+    // public static String mysql_url = "jdbc:mysql://192.168.16.222:3306/hitch-sb";
+    //用户名
+    // public static String mysql_username = "root";
+    //密码
+    // public static String mysql_password = "mydm888";
     //驱动名称
     public static String mysql_driver = "com.mysql.cj.jdbc.Driver";
     // 采集数据,结构:遥测最低,遥测最高;电度最低,电度最高

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

@@ -217,13 +217,17 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
         }
         sysDictList.sort(Comparator.comparing(SysDict::getSort));
         record.setSbName("G01");
+        // 如果是月的,只查0点的数据
+        if(!isDay){
+            record.setHour(0);
+        }
         List<RemoteDegreeLogVO> list = remoteDegreeLogMapper.selectList(record);
         JSONArray jSONArray = new JSONArray();
         if (isDay) {// 日报,需要减去上个小时的
             // 找到前天晚上23点的
             RemoteDegreeLogDTO lastDay = BeanConverterUtil.copyObjectProperties(record, RemoteDegreeLogDTO.class);
             Calendar calendar = Calendar.getInstance();
-            calendar.set(lastDay.getYear(), lastDay.getMonth() - 1, lastDay.getDay()-1);
+            calendar.set(lastDay.getYear(), lastDay.getMonth() - 1, lastDay.getDay());
             DateUtils.getLastDay(calendar);
             lastDay.setYear(calendar.get(Calendar.YEAR));
             lastDay.setMonth(calendar.get(Calendar.MONTH) + 1);
@@ -249,7 +253,7 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
                                     if(i == 0){// 从昨天找
                                         Optional<RemoteDegreeLogVO> lastR = lastList.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum())).findFirst();
                                         if(lastR.isPresent()){
-                                            log.info(lastR.get().toString());
+                                            log.info(JSONObject.toJSONString(lastR.get()));
                                             positiveTotal = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()));
                                         }
                                     }else{// 从今天上个时间找,减去上个小时的数据
@@ -265,7 +269,7 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
                                     if(i == 0){// 从昨天找
                                         Optional<RemoteDegreeLogVO> lastR = lastList.stream().filter(item -> item.getPositionNum().equals(degreeLog.getPositionNum())).findFirst();
                                         if(lastR.isPresent()){
-                                            log.info(lastR.get().toString());
+                                            log.info(JSONObject.toJSONString(lastR.get()));
                                             negativeTotal = negativeTotal.subtract(new BigDecimal(lastR.get().getResult()));
                                         }
                                     }else{// 从今天上个时间找,减去上个小时的数据
@@ -284,9 +288,19 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
                 jsonObject.put("lines", lineArray);
                 jSONArray.add(jsonObject);
             }
-        } else {
+        } else {// 月:统计每天的:需要当天0点减去前天0点的
             LocalDate localDate = LocalDate.of(record.getYear(), record.getMonth(), 1);
             int days = localDate.lengthOfMonth();
+
+            // 找到前天晚上0点的
+            RemoteDegreeLogDTO lastDay = BeanConverterUtil.copyObjectProperties(record, RemoteDegreeLogDTO.class);
+            Calendar calendar = Calendar.getInstance();
+            calendar.set(lastDay.getYear(), lastDay.getMonth() - 2, 1);
+            lastDay.setYear(calendar.get(Calendar.YEAR));
+            lastDay.setMonth(calendar.get(Calendar.MONTH) + 1);
+            lastDay.setDay(calendar.getActualMaximum(Calendar.DATE));
+            List<RemoteDegreeLogVO> lastList = remoteDegreeLogMapper.selectList(lastDay);
+
             for (int i = 1; i <= days; i++) {
                 JSONObject jsonObject = new JSONObject();
                 jsonObject.put("time", i);
@@ -304,9 +318,38 @@ public class BigScreenSbInfoServiceImpl extends BaseServiceImpl<SbInfoMapper, Sb
                             if (degreeLog.getDay().equals(i)) {
                                 if (degreeLog.getType().equals(1)) {
                                     positiveTotal = positiveTotal.add(new BigDecimal(degreeLog.getResult()));
-                                } else {
-                                    negativeTotal = negativeTotal.add(new BigDecimal(degreeLog.getResult()));
+                                    // 找到上个时间
+                                    if(i == 0){// 从上个月最后一天找
+                                        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()));
+                                        }
+                                    }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 = positiveTotal.subtract(new BigDecimal(lastR.get().getResult()));
+                                        }
+                                    }
                                 }
+                                /*else {
+                                    negativeTotal = negativeTotal.add(new BigDecimal(degreeLog.getResult()));
+                                    // 找到上个时间
+                                    if(i == 0){// 从昨天找
+                                        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()));
+                                        }
+                                    }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(JSONObject.toJSONString(lastR.get()));
+                                            negativeTotal = negativeTotal.subtract(new BigDecimal(lastR.get().getResult()));
+                                        }
+                                    }
+                                }*/
                             }
                         }
                     }