Browse Source

优化AGC页面限电时间列表

王波 1 month ago
parent
commit
254d8de485

+ 3 - 2
runeconomy-xk/src/main/java/com/gyee/runeconomy/controller/agc/AgcDeviateController.java

@@ -1,5 +1,6 @@
 package com.gyee.runeconomy.controller.agc;
 
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gyee.runeconomy.config.GyeeConfig;
 import com.gyee.runeconomy.model.PowerLossesDTO;
 import com.gyee.runeconomy.model.StatusTime;
@@ -59,12 +60,12 @@ public class AgcDeviateController {
      * @return
      */
     @GetMapping("/xdloss")
-    public List<PowerLossesDTO> getxdData(@RequestParam(value = "startTs") long startTs,
+    public Page<PowerLossesDTO> getxdData(@RequestParam(value = "startTs") long startTs,
                                           @RequestParam(value = "endTs") long endTs,
                                           @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                           @RequestParam(value = "pageSize", defaultValue = "10") int pageSize) {
 
-        List<PowerLossesDTO> agcxd = agcDeviateService.getAgcxd(startTs, endTs, pageNum, pageSize);
+        Page<PowerLossesDTO> agcxd = agcDeviateService.getAgcxd(startTs, endTs, pageNum, pageSize);
         return agcxd;
     }
 

+ 2 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/PowerLossesService.java

@@ -6,6 +6,7 @@ import com.gyee.runeconomy.model.PowerLosses;
 import com.baomidou.mybatisplus.extension.service.IService;
 
 import java.time.LocalDateTime;
+import java.util.List;
 
 /**
  * <p>
@@ -18,4 +19,5 @@ import java.time.LocalDateTime;
 public interface PowerLossesService extends IService<PowerLosses> {
 
     IPage<PowerLosses> pageList(Page<PowerLosses> page, LocalDateTime startTs, LocalDateTime endTs);
+    List<PowerLosses> pageTotalList(LocalDateTime startTs, LocalDateTime endTs);
 }

+ 20 - 17
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/agc/AgcDeviateService.java

@@ -295,45 +295,48 @@ public class AgcDeviateService {
      * @param pageSize
      * @return
      */
-    public List<PowerLossesDTO> getAgcxd(long startTs, long endTs, int pageNum, int pageSize) {
+    public Page<PowerLossesDTO> getAgcxd(long startTs, long endTs,int pageNum, int pageSize) {
 
-        // 将时间戳转换为LocalDateTime
         LocalDateTime startDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(startTs), ZoneId.systemDefault());
         LocalDateTime endDateTime = LocalDateTime.ofInstant(Instant.ofEpochMilli(endTs), ZoneId.systemDefault());
         Page<PowerLosses> page = new Page<>(pageNum, pageSize);
         IPage<PowerLosses> list = powerLossService.pageList(page, startDateTime, endDateTime);
-        list.setTotal(list.getRecords().size());
-        List<PowerLosses> List = list.getRecords();
-        List<PowerLossesDTO> dtos = new ArrayList<>();
+        List<PowerLosses> powerLosses = powerLossService.pageTotalList(startDateTime, endDateTime);
+
 
-        DecimalFormat df = new DecimalFormat("0.0000000"); // 创建一个保留8位小数的 DecimalFormat 实例
+        // 使用dto列表替换原始记录列表
+        List<PowerLossesDTO> dtos = new ArrayList<>();
+        DecimalFormat df = new DecimalFormat("0.0000000");
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
 
-        for (PowerLosses pl : List) {
+        for (PowerLosses pl : list.getRecords()) {
             PowerLossesDTO dto = new PowerLossesDTO();
             dto.setId(pl.getId());
-
-            // 使用DateTimeFormatter格式化日期时间
-            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");
             dto.setStartTime(pl.getStartTime().format(formatter));
             dto.setEndTime(pl.getEndTime().format(formatter));
 
             try {
-                double xddl = Double.parseDouble(pl.getXdss()); // 将字符串转换为double
-                double xddlDivided = xddl / 10000; // 进行除法运算
-                String xd = df.format(xddlDivided); // 使用DecimalFormat格式化结果
-                dto.setXdss(xd); // 设置格式化后的值
+                double xddl = Double.parseDouble(pl.getXdss());
+                double xddlDivided = xddl / 10000;
+                String xd = df.format(xddlDivided);
+                dto.setXdss(xd);
             } catch (NumberFormatException e) {
-                // 处理无法解析为double的情况
-                dto.setXdss("0.0000000"); // 假设默认值为0.0000000,与DecimalFormat的格式一致
+                dto.setXdss("0.0000000");
             }
 
             dto.setRecordDate(pl.getRecordDate());
             dtos.add(dto);
         }
 
-        return dtos;
+        // 创建一个新的IPage对象并设置dtos为记录
+        Page<PowerLossesDTO> dtoPage = new Page<>(pageNum, pageSize);
+        dtoPage.setRecords(dtos);
+        dtoPage.setTotal(powerLosses.size());
+
+        return dtoPage;
     }
 
+
     public Map<String, List<SpeedPowerAnalysis>> getWindturbineData(long startTs, long endTs, String windturbineId, int interval) throws Exception {
 
         //切换数据库

+ 11 - 0
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/impl/PowerLossesServiceImpl.java

@@ -11,6 +11,8 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
+import java.util.Collections;
+import java.util.List;
 
 /**
  * <p>
@@ -34,4 +36,13 @@ public class PowerLossesServiceImpl extends ServiceImpl<PowerLossesMapper, Power
                 .orderByAsc(PowerLosses::getId); // 明确指定排序
         return powerLossesMapper.selectPage(page, queryWrapper);
     }
+
+    @Override
+    public List<PowerLosses> pageTotalList(LocalDateTime startTs, LocalDateTime endTs) {
+        QueryWrapper<PowerLosses> queryWrapper = new QueryWrapper<>();
+        queryWrapper.lambda()
+                .ge(PowerLosses::getStartTime, startTs)
+                .le(PowerLosses::getEndTime, endTs);
+        return powerLossesMapper.selectList(queryWrapper);
+    }
 }