Jelajahi Sumber

上报数据增加默认查询类型及降序排列

fanxiaoyu 6 bulan lalu
induk
melakukan
c8f295c1fa

+ 34 - 1
cpp-admin/src/main/java/com/cpp/web/controller/reportData/ReportDataController.java

@@ -8,14 +8,21 @@ import com.cpp.web.domain.station.ElectricField;
 import com.cpp.web.service.datafactory.ParsingLogService;
 import com.cpp.web.service.reprtdata.ReportDataService;
 import com.cpp.web.service.station.ElectricFieldService;
+import com.sun.org.apache.regexp.internal.RE;
 import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
+import static org.hibernate.type.descriptor.java.JdbcTimestampTypeDescriptor.TIMESTAMP_FORMAT;
+
 @RestController
 @RequiredArgsConstructor
 @RequestMapping("reportData")
@@ -27,6 +34,8 @@ public class ReportDataController {
 
     private final ReportDataService reportDataService;
 
+    private static final SimpleDateFormat TIMESTAMP_FORMAT = new SimpleDateFormat("yyyyMMddHHmm");
+
 
     /**
      * 获取文件类型
@@ -90,7 +99,31 @@ public class ReportDataController {
                 resultList.add(parsingLogs);
             }
         }
-        resultList.stream().sorted(Comparator.comparing(ParsingLog::getFileName).reversed());
+        Comparator<ParsingLog> timestampComparator = new Comparator<ParsingLog>() {
+            @Override
+            public int compare(ParsingLog o1, ParsingLog o2) {
+                try {
+                    Date firstDate = TIMESTAMP_FORMAT.parse(extractAndParseTimestamp(o1.getFileName()));
+                    Date nextDate = TIMESTAMP_FORMAT.parse(extractAndParseTimestamp(o2.getFileName()));
+                    return nextDate.compareTo(firstDate);
+                } catch (ParseException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        };
+        // 排序
+        Collections.sort(resultList, timestampComparator);
         return R.ok(resultList);
     }
+
+    /**
+     *  提取文件名中的时间
+     * @param fileName
+     * @return
+     */
+    private static String extractAndParseTimestamp(String fileName) {
+        String[] fileNameParts = fileName.split("_");
+        String correctTimestampStr = fileNameParts[1]+fileNameParts[2];
+        return correctTimestampStr;
+    }
 }

+ 1 - 0
cpp-admin/src/main/java/com/cpp/web/service/datafactory/impl/ParsingLogServiceImpl.java

@@ -56,6 +56,7 @@ public class ParsingLogServiceImpl extends ServiceImpl<ParsingLogMapper, Parsing
         if (null != fileType && !"".equals(fileType)){
             wrapper.eq("file_type", fileType);
         }
+        wrapper.eq("data_sources","E1");
         wrapper.orderByDesc("file_name");
         return wrapper;
     }