2 Commits abdb3ca869 ... 6d78b45969

Author SHA1 Message Date
  weijianghai 6d78b45969 feat: 河北价值管理平台北十车辆费用月数据入库定时任务、河北价值管理平台省内车辆费用月数据入库定时任务增加去重逻辑 1 week ago
  weijianghai 8013f56d4b feat: 添加车辆租赁费定时任务 1 month ago

+ 10 - 0
readme.md

@@ -212,6 +212,16 @@ curl --location 'http://127.0.0.1:39110/jobs/runJob' \
 }'
 ```
 
+##### 河北成本管理系统车辆租赁费用数据入库定时任务
+
+```shell
+curl --location 'http://127.0.0.1:39110/jobs/runJob' \
+--header 'Content-Type: application/json' \
+--data '{
+    "jobName": "CAR_ZU_LIN_JOB"
+}'
+```
+
 #### 车辆策略
 
 ##### 车效大屏建设数据定时任务

+ 8 - 0
src/main/java/com/nokia/finance/tasks/config/JobConfig.java

@@ -240,6 +240,14 @@ public class JobConfig {
      * 河北成本管理系统车辆服务费数据归档路径
      */
     private String carFuWuFeiHistoryPath;
+    /**
+     * 河北成本管理系统车辆租赁费用数据路径
+     */
+    private String carZuLinSourcePath;
+    /**
+     * 河北成本管理系统车辆租赁费用数据归档路径
+     */
+    private String carZuLinHistoryPath;
     /**
      * 策略输出临时路径
      */

+ 4 - 0
src/main/java/com/nokia/finance/tasks/enums/JobEnum.java

@@ -137,5 +137,9 @@ public enum JobEnum {
      * 房产大屏出租收入统计定时任务
      */
     HOUSE_RENTAL_INCOME_JOB,
+    /**
+     * 河北成本管理系统车辆租赁费用数据入库定时任务
+     */
+    CAR_ZU_LIN_JOB,
     ;
 }

+ 90 - 0
src/main/java/com/nokia/finance/tasks/jobs/car/chengben/CarZuLinJob.java

@@ -0,0 +1,90 @@
+package com.nokia.finance.tasks.jobs.car.chengben;
+
+import com.nokia.finance.tasks.common.exception.MyRuntimeException;
+import com.nokia.finance.tasks.config.JobConfig;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Stream;
+
+/**
+ * 河北成本管理系统车辆租赁费用数据入库定时任务
+ */
+@Slf4j
+@Service
+public class CarZuLinJob {
+    private final JobConfig jobConfig;
+
+    public CarZuLinJob(JobConfig jobConfig) {
+        this.jobConfig = jobConfig;
+    }
+
+    /**
+     * 执行任务
+     */
+    @Scheduled(cron = "0 36 6 12 * ?")
+    public void runJob() {
+        // 数据目录
+        Path dir = Paths.get(jobConfig.getCarZuLinSourcePath());
+        try (Stream<Path> stream = Files.list(dir)) {
+            // 获取数据目录下的文件列表
+            List<Path> pathList = stream.filter(t -> !t.toString().endsWith(".MD5")).sorted().toList();
+            log.info("河北成本管理系统车辆租赁费用数据文件列表: {}", pathList);
+            if (CollectionUtils.isEmpty(pathList)) {
+                throw new MyRuntimeException("河北成本管理系统车辆租赁费用数据没有文件");
+            }
+            for (Path path : pathList) {
+                CompletableFuture.runAsync(() -> {
+                    try {
+                        singleJob(path);
+                    } catch (Exception e) {
+                        throw new MyRuntimeException(e);
+                    }
+                }).get(1, TimeUnit.MINUTES);
+            }
+        } catch (InterruptedException e) {
+            log.error("线程中断: {}", e, e);
+            Thread.currentThread().interrupt();
+        } catch (Exception e) {
+            log.error(e.toString(), e);
+        }
+    }
+
+    /**
+     * 处理单个文件
+     *
+     * @param path 文件路径
+     */
+    public void singleJob(Path path) throws IOException {
+        if (Files.size(path) == 0) {
+            move(path);
+            throw new MyRuntimeException(path.getFileName() + " 空文件");
+        }
+        move(path);
+    }
+
+    /**
+     * 移动源文件到历史文件夹
+     *
+     * @param path 源文件路径
+     */
+    public void move(Path path) throws IOException {
+        if (Files.exists(Paths.get(path + ".MD5"))) {
+            Files.move(Paths.get(path + ".MD5"),
+                    Paths.get(jobConfig.getCarZuLinHistoryPath(), path.getFileName().toString() + ".MD5"),
+                    StandardCopyOption.REPLACE_EXISTING);
+        }
+        Files.move(path, Paths.get(jobConfig.getCarZuLinHistoryPath(), path.getFileName().toString()),
+                StandardCopyOption.REPLACE_EXISTING);
+    }
+}

+ 15 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/shujucangku/CarFeeBsJob.java

@@ -28,8 +28,12 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.stream.Stream;
 
 /**
@@ -155,7 +159,17 @@ public class CarFeeBsJob {
         for (Map<String, String> map : list) {
             map.put("source", path.getFileName().toString());
         }
-        return list;
+        // 去重
+        return list.stream()
+                .filter(distinctByKey(map -> map.get("month_id") + map.get("area_no") + map.get("kpi_id"))).toList();
+    }
+
+    /**
+     * 去重
+     */
+    private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
+        Set<Object> set = ConcurrentHashMap.newKeySet();
+        return t -> set.add(keyExtractor.apply(t));
     }
 
     /**

+ 15 - 1
src/main/java/com/nokia/finance/tasks/jobs/car/shujucangku/CarFeeHbJob.java

@@ -31,8 +31,12 @@ import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
+import java.util.function.Function;
+import java.util.function.Predicate;
 import java.util.stream.Stream;
 
 /**
@@ -188,7 +192,17 @@ public class CarFeeHbJob {
             map.put("second_org_name", secondOrgName);
             map.put("source", path.getFileName().toString());
         }
-        return list;
+        // 去重
+        return list.stream()
+                .filter(distinctByKey(map -> map.get("month_id") + map.get("area_no") + map.get("kpi_id"))).toList();
+    }
+
+    /**
+     * 去重
+     */
+    private static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
+        Set<Object> set = ConcurrentHashMap.newKeySet();
+        return t -> set.add(keyExtractor.apply(t));
     }
 
     /**

+ 3 - 0
src/main/java/com/nokia/finance/tasks/service/JobService.java

@@ -11,6 +11,7 @@ import com.nokia.finance.tasks.jobs.car.chengben.CarQiTaJob;
 import com.nokia.finance.tasks.jobs.car.chengben.CarRanYouJob;
 import com.nokia.finance.tasks.jobs.car.chengben.CarSiCheGongYongJob;
 import com.nokia.finance.tasks.jobs.car.chengben.CarWeiXiuJob;
+import com.nokia.finance.tasks.jobs.car.chengben.CarZuLinJob;
 import com.nokia.finance.tasks.jobs.car.cxdp.CarCxdpJob;
 import com.nokia.finance.tasks.jobs.car.ruixing.CarBaoFeiJob;
 import com.nokia.finance.tasks.jobs.car.ruixing.CarBaseDataDayJob;
@@ -82,6 +83,7 @@ public class JobService {
     private final HouseBuildingAreaStatJob houseBuildingAreaStatJob;
     private final HouseBuildingLandCountJob houseBuildingLandCountJob;
     private final HouseRentalIncomeJob houseRentalIncomeJob;
+    private final CarZuLinJob carZuLinJob;
 
     @Transactional(timeout = 300, rollbackFor = Exception.class)
     public R<Object> runJob(RunJobDto dto) {
@@ -123,6 +125,7 @@ public class JobService {
             case HOUSE_BUILDING_AREA_STAT_JOB -> houseBuildingAreaStatJob.runJob();
             case HOUSE_BUILDING_LAND_COUNT_JOB -> houseBuildingLandCountJob.runJob();
             case HOUSE_RENTAL_INCOME_JOB -> houseRentalIncomeJob.runJob();
+            case CAR_ZU_LIN_JOB -> carZuLinJob.runJob();
         }
         return R.ok();
     }

+ 10 - 6
src/main/resources/application-dev.yml

@@ -7,16 +7,16 @@ logging:
 spring:
   datasource:
     driver-class-name: org.postgresql.Driver
-#    username: postgres
-#    password: Test!234
+    username: postgres
+    password: Test!234
 #    url: jdbc:postgresql://127.0.0.1:5432/financialdb
-#    url: jdbc:postgresql://192.168.65.128:5432/financialdb
+    url: jdbc:postgresql://192.168.65.128:5432/financialdb
 #    url: jdbc:postgresql://172.16.107.5:5432/financialdb
 #    username: finance
 #    password: Finance@unicom23
-    url: jdbc:postgresql://192.168.50.3:15432/financialdb
-    username: postgres
-    password: NFQCgBA6YhNvgAqG6THw
+#    url: jdbc:postgresql://192.168.50.3:15432/financialdb
+#    username: postgres
+#    password: NFQCgBA6YhNvgAqG6THw
 minio:
   accessKey: house-car
   bucket: house-car
@@ -138,6 +138,10 @@ job:
     car-fu-wu-fei-source-path: data/jzftp/HE_M_MTC_VEHICLE_CHARGE/
     # 河北成本管理系统车辆服务费数据归档路径
     car-fu-wu-fei-history-path: data/history/jzftp/HE_M_MTC_VEHICLE_CHARGE/
+    # 河北成本管理系统车辆租赁费用数据路径
+    car-zu-lin-source-path: data/jzftp/HE_M_MTC_VEHICLE_RENT/
+    # 河北成本管理系统车辆租赁费用数据归档路径
+    car-zu-lin-history-path: data/history/jzftp/HE_M_MTC_VEHICLE_RENT/
     # 策略输出临时路径
     temp-output-dir: temp-output/
 # 车辆报告配置

+ 4 - 0
src/main/resources/application-prod.yml

@@ -129,6 +129,10 @@ job:
     car-fu-wu-fei-source-path: /data/jzftp/HE_M_MTC_VEHICLE_CHARGE/
     # 河北成本管理系统车辆服务费数据归档路径
     car-fu-wu-fei-history-path: /data/history/jzftp/HE_M_MTC_VEHICLE_CHARGE/
+    # 河北成本管理系统车辆租赁费用数据路径
+    car-zu-lin-source-path: /data/jzftp/HE_M_MTC_VEHICLE_RENT/
+    # 河北成本管理系统车辆租赁费用数据归档路径
+    car-zu-lin-history-path: /data/history/jzftp/HE_M_MTC_VEHICLE_RENT/
     # 策略输出临时路径
     temp-output-dir: temp-output/
 # 车辆报告配置