Browse Source

风电发电功率、光伏发电功率、火电发电功率计划值曲线求和

xusl 1 năm trước cách đây
mục cha
commit
3e1d329c7d

+ 13 - 3
src/main/java/com/jiayue/vpp/controller/MengxiVppRealTimePlanDataController.java

@@ -17,8 +17,10 @@ import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletResponse;
+import java.math.BigDecimal;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 【风-光-火-储能 实时明细表】Controller
@@ -70,11 +72,19 @@ public class MengxiVppRealTimePlanDataController extends BaseController {
         });
         Map<String, Object> map = new HashMap<>();
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        List<String> times = new ArrayList<>();
+        Set<String> settime = new HashSet<>();
         List<String> plan = new ArrayList<>();
         for (MengxiVppRealTimePlanData m : list) {
-            times.add(simpleDateFormat.format(new Date(m.getTime().getTime())));
-            plan.add(String.valueOf(m.getPlan()));
+            settime.add(simpleDateFormat.format(new Date(m.getTime().getTime())));
+        }
+        List<String> times = new ArrayList<>(settime);
+        // 对List进行排序
+        Collections.sort(times);
+        for (String t : times) {
+            // 求和
+            List<MengxiVppRealTimePlanData> filterList = list.stream().filter(n -> simpleDateFormat.format(n.getTime()).equals(t)).collect(Collectors.toList());
+            BigDecimal sum = filterList.stream().map(s->new BigDecimal(s.getPlan().longValue())).reduce(BigDecimal.ZERO, BigDecimal::add);
+            plan.add(sum.toString());
         }
         map.put("times", times);
         map.put("plan", plan);