Эх сурвалжийг харах

feat: 睿行车辆用车月统计数据入库定时任务从文件名提取账期

weijianghai 1 жил өмнө
parent
commit
91d0451f57

+ 27 - 11
src/main/java/com/nokia/finance/tasks/jobs/car/ruixing/CarYongCheJob.java

@@ -38,6 +38,8 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Stream;
 
 /**
@@ -215,6 +217,20 @@ public class CarYongCheJob {
      * @param list 数据
      */
     public List<Map<String, String>> dataProcessing(Path path, List<Map<String, String>> list) {
+        // 从文件名提取日期
+        String regex = "\\d{6}";
+        Pattern pattern = Pattern.compile(regex);
+        Matcher matcher = pattern.matcher(path.getFileName().toString());
+        String dateString;
+        if (matcher.find()) {
+            dateString = matcher.group() + "01";
+        } else {
+            throw new MyRuntimeException(path.getFileName() + " 提取日期失败");
+        }
+        LocalDate localDate = LocalDate.parse(dateString, DateTimeFormatter.ofPattern("yyyyMMdd"));
+        String yearMonth = localDate.format(DateTimeFormatter.ofPattern("yyyyMM"));
+        String year = String.valueOf(localDate.getYear());
+        String month = String.valueOf(localDate.getMonthValue());
         List<OrganizationPo> secondOrgs = organizationService.getSecondOrgs();
         List<OrganizationPo> thirdOrgs = organizationService.getThirdOrgs();
         Map<String, OrganizationPo> orgMap = organizationService.getOrgMap(secondOrgs, thirdOrgs);
@@ -225,17 +241,17 @@ public class CarYongCheJob {
         Map<String, AreaPo> areaMap = areaService.getAreaMap(cities, districts);
         Map<String, List<AreaPo>> districtListMap = areaService.getDistrictListMap(cities, districts);
         for (Map<String, String> map : list) {
-            String yearMonth = "";
-            String year = "";
-            String month = "";
-            String chuFaShiJian = map.get("chu_fa_shi_jian");
-            if (StringUtils.hasText(chuFaShiJian)) {
-                LocalDateTime localDateTime = LocalDateTime.parse(chuFaShiJian,
-                        DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-                yearMonth = localDateTime.format(DateTimeFormatter.ofPattern("yyyyMM"));
-                year = String.valueOf(localDateTime.getYear());
-                month = String.valueOf(localDateTime.getMonthValue());
-            }
+//            String yearMonth = "";
+//            String year = "";
+//            String month = "";
+//            String chuFaShiJian = map.get("chu_fa_shi_jian");
+//            if (StringUtils.hasText(chuFaShiJian)) {
+//                LocalDateTime localDateTime = LocalDateTime.parse(chuFaShiJian,
+//                        DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+//                yearMonth = localDateTime.format(DateTimeFormatter.ofPattern("yyyyMM"));
+//                year = String.valueOf(localDateTime.getYear());
+//                month = String.valueOf(localDateTime.getMonthValue());
+//            }
             map.put("year_month", yearMonth);
             map.put("year_no", year);
             map.put("month_no", month);