Browse Source

设备电量排序列表

missMyLove 3 năm trước cách đây
mục cha
commit
0f2284ee20

+ 2 - 2
src/main/java/com/comtika/safe/entity/mobile/help/EleHelp.java

@@ -10,11 +10,11 @@ import lombok.Data;
 @Data
 public class EleHelp {
     private String key;
-    private Integer value;
+    private int value = 0;
 
     public EleHelp(){}
     public EleHelp(String key,Integer value){
         this.key = key;
-        this.value = value;
+        if (value != null) this.value = value;
     }
 }

+ 12 - 5
src/main/java/com/comtika/safe/service/mobile/impl/MobileServiceImpl.java

@@ -166,12 +166,10 @@ public class MobileServiceImpl implements IMobileService {
         // 这里查询数据
         List<EleTotalHelp> sumTotalList = fadMessageConfDao.findTerminalEleTotalList(help.getTerminalId(),help.getStartTime(),help.getEndTime()+DateTimeUtils.ONE_DAY);
         Map<String,Integer> res = new HashMap<>();
-        Set<String> keys = new HashSet<>();
         sumTotalList.forEach(s->{
             // 处理时间
             if(s.getCreateTime() == null) return;
             String key = DateTimeUtils.formatDate(new Date(s.getCreateTime()), DateTimeUtils.FORMAT_YMD);
-            keys.add(key);
             int inc = calEle(s.getEndEle(), s.getStartEle());
             if(res.containsKey(key)){
                 res.put(key,res.get(key)+inc);
@@ -179,10 +177,19 @@ public class MobileServiceImpl implements IMobileService {
                 res.put(key,inc);
             }
         });
+        // 处理数据
+        List<String> keys = new ArrayList<>();
+        long startTime = help.getStartTime();
+        long endTime = help.getEndTime();
+        while (startTime <= endTime){
+            keys.add(DateTimeUtils.formatDate(new Date(startTime), DateTimeUtils.FORMAT_YMD));
+            startTime += DateTimeUtils.ONE_DAY;
+        }
         List<EleHelp> list = new ArrayList<>();
-        for(String key:keys){
-            Integer integer = res.get(key);
-            list.add(new EleHelp(key,integer));
+        int size = keys.size();
+        for(int i=0;i<size;i++){
+            String key = keys.get(i);
+            list.add(new EleHelp(key,res.get(key)));
         }
         return RespWrapper.makeSuccessResp(list);
     }