瀏覽代碼

优化AGC页面限电时间列表

王波 1 月之前
父節點
當前提交
5bc8af0441

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

@@ -96,41 +96,9 @@ public class AgcDeviateController {
                                           @RequestParam(value = "endTs") long endTs,
                                           @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                           @RequestParam(value = "pageSize", defaultValue = "10") 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<>();
 
-        DecimalFormat df = new DecimalFormat("0.0000000"); // 创建一个保留8位小数的 DecimalFormat 实例
-
-        for (PowerLosses pl : List) {
-            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); // 设置格式化后的值
-            } catch (NumberFormatException e) {
-                // 处理无法解析为double的情况
-                dto.setXdss("0.0000000"); // 假设默认值为0.0000000,与DecimalFormat的格式一致
-            }
-
-            dto.setRecordDate(pl.getRecordDate());
-            dtos.add(dto);
-        }
-
-        return dtos;
+        List<PowerLossesDTO> agcxd = agcDeviateService.getAgcxd(startTs, endTs, pageNum, pageSize);
+        return agcxd;
     }
 
     /**

+ 60 - 1
runeconomy-xk/src/main/java/com/gyee/runeconomy/service/agc/AgcDeviateService.java

@@ -2,11 +2,16 @@ package com.gyee.runeconomy.service.agc;
 
 
 import cn.hutool.core.lang.TypeReference;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.gyee.runeconomy.config.GyeeConfig;
 import com.gyee.runeconomy.controller.agc.AgcDeviateTag;
 import com.gyee.runeconomy.controller.agc.AiPoints;
 import com.gyee.runeconomy.controller.agc.FileService;
 import com.gyee.runeconomy.init.CacheContext;
+import com.gyee.runeconomy.model.PowerLosses;
+import com.gyee.runeconomy.model.PowerLossesDTO;
+import com.gyee.runeconomy.service.PowerLossesService;
 import com.gyee.runeconomy.util.realtimesource.feign.IDataAdapter;
 import com.gyee.runeconomy.util.realtimesource.feign.RemoteServiceBuilder;
 import com.gyee.runeconomy.util.realtimesource.feign.TsDoubleTsData;
@@ -17,6 +22,11 @@ import org.springframework.stereotype.Component;
 
 import javax.annotation.Resource;
 import java.io.File;
+import java.text.DecimalFormat;
+import java.time.Instant;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -57,7 +67,8 @@ public class AgcDeviateService {
     private IDataAdapter iDataAdapter;
     @Autowired
     private RemoteServiceBuilder remoteService;
-
+    @Resource
+    private PowerLossesService powerLossService;
     /**
      * 获取agc曲线偏差分析需要的数据
      *
@@ -247,4 +258,52 @@ public class AgcDeviateService {
         return fileService.getFromFile(ls.get(ran), new TypeReference<List<AgcDeviateTag>>() {
         });
     }
+
+    /**
+     * 限电时间列表
+     * @param startTs
+     * @param endTs
+     * @param pageNum
+     * @param pageSize
+     * @return
+     */
+    public List<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<>();
+
+        DecimalFormat df = new DecimalFormat("0.0000000"); // 创建一个保留8位小数的 DecimalFormat 实例
+
+        for (PowerLosses pl : List) {
+            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); // 设置格式化后的值
+            } catch (NumberFormatException e) {
+                // 处理无法解析为double的情况
+                dto.setXdss("0.0000000"); // 假设默认值为0.0000000,与DecimalFormat的格式一致
+            }
+
+            dto.setRecordDate(pl.getRecordDate());
+            dtos.add(dto);
+        }
+
+        return dtos;
+    }
+
 }