Quellcode durchsuchen

实现最后一个可实现的健康检测

ximinghao vor 3 Monaten
Ursprung
Commit
d2ec25d5b0

+ 74 - 4
src/main/java/com/skyversation/xjcy/Timer.java

@@ -1,19 +1,89 @@
 package com.skyversation.xjcy;
 
+import com.alibaba.fastjson.JSONObject;
+import com.skyversation.xjcy.bean.Enterprise;
+import com.skyversation.xjcy.bean.EnterpriseEconomic;
+import com.skyversation.xjcy.bean.LeaseDetail;
+import com.skyversation.xjcy.computer.EnterpriseHealthComputer;
+import com.skyversation.xjcy.dms.DMSColumn;
+import com.skyversation.xjcy.dms.DMSQuery;
+import com.skyversation.xjcy.dms.DMSService;
+import com.skyversation.xjcy.oauth.AuthService;
+import com.skyversation.xjcy.service.InvestmentPreCountService;
 import com.skyversation.xjcy.service.ParkPreCountService;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
 import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.MonthDay;
+import java.util.Arrays;
+import java.util.List;
 
 @Component
 //放一些定时器的简单类
 public class Timer {
-    @Resource
-    ParkPreCountService parkPreCountService;
+
+    private final ParkPreCountService parkPreCountService;
+    private final InvestmentPreCountService investmentPreCountService;
+    private final DMSService dMSService;
+    private final AuthService authService;
+
+    public Timer(ParkPreCountService parkPreCountService, InvestmentPreCountService investmentPreCountService, DMSService dMSService, AuthService authService) {
+        this.parkPreCountService = parkPreCountService;
+        this.investmentPreCountService = investmentPreCountService;
+        this.dMSService = dMSService;
+        this.authService = authService;
+    }
 
     //@Scheduled(fixedRate = 5000)
-    public void countPark(){
+    public void countPark() {
         parkPreCountService.updateAllRoom();
     }
+
+    public void countInvestment() {
+        investmentPreCountService.updateAllTarget();
+    }
+
+    @Scheduled(cron = "0 5 0 * * ?")
+    public void checkEnterpriseHealth(){
+        LocalDate now = LocalDate.now();
+        LocalDateTime actuallyTime = now.minusDays(1).atTime(23,59,59,9999);
+//        LocalDateTime actuallyTime = LocalDateTime.of(2025,9,30,23,59,59,9999);
+
+        List<Enterprise> enterprises = dMSService.query(authService.getToken(), DMSQuery.ENTERPRISE, Enterprise.class,actuallyTime.toLocalDate());
+        List<LeaseDetail> leaseDetails = dMSService.query(authService.getToken(), DMSQuery.LAST_LEASE_DETAIL, LeaseDetail.class,actuallyTime.toLocalDate());
+        List<EnterpriseEconomic> enterpriseEconomics = dMSService.query(authService.getToken(), DMSQuery.ECONOMIC, EnterpriseEconomic.class,actuallyTime.toLocalDate());
+
+        EnterpriseHealthComputer enterpriseHealthComputer = new EnterpriseHealthComputer(enterprises);
+
+        enterpriseHealthComputer.putLease(leaseDetails);
+        enterpriseHealthComputer.putEnterpriseEconomics(enterpriseEconomics);
+
+        //everyDay
+        enterpriseHealthComputer.computeLeaseOutDate(actuallyTime);
+
+        //atSeasonEnd
+        MonthDay[] seasonEnd = new MonthDay[]{
+                MonthDay.of(3, 31),
+                MonthDay.of(6, 30),
+                MonthDay.of(9, 30),
+                MonthDay.of(12, 31),
+        };
+        if (Arrays.stream(seasonEnd).anyMatch(end -> end.getMonth()==actuallyTime.getMonth()&&end.getDayOfMonth()==actuallyTime.getDayOfMonth())) {
+            enterpriseHealthComputer.computeOutputRise(actuallyTime);
+            enterpriseHealthComputer.computeTaxRise(actuallyTime);
+            enterpriseHealthComputer.computeTaxDive(actuallyTime);
+        }
+
+
+        List<JSONObject> results = enterpriseHealthComputer.getResultJsons();
+        for (JSONObject result : results) {
+            boolean success = dMSService.insertToDms(result, authService.getToken(), DMSColumn.ENTERPRISE_HEALTH);
+            if (!success) {
+                System.out.println("保存失败");
+            }
+        }
+    }
 }

+ 65 - 24
src/main/java/com/skyversation/xjcy/computer/EnterpriseHealthComputer.java

@@ -4,14 +4,14 @@ import com.alibaba.fastjson.JSONObject;
 import com.skyversation.xjcy.bean.Enterprise;
 import com.skyversation.xjcy.bean.EnterpriseEconomic;
 import com.skyversation.xjcy.bean.EnterpriseHealth;
+import com.skyversation.xjcy.bean.LeaseDetail;
 import lombok.Getter;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.rmi.dgc.Lease;
 import java.text.DecimalFormat;
-import java.time.LocalDateTime;
-import java.time.MonthDay;
-import java.time.YearMonth;
+import java.time.*;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.function.Function;
@@ -241,6 +241,11 @@ public class EnterpriseHealthComputer {
      */
     Map<String, Map<YearMonth, EnterpriseEconomic>> enterpriseEconomics;
 
+    /**
+     * 企业租赁数据映射:企业ID->租赁数据list
+     */
+    Map<String, List<LeaseDetail>> enterpriseLeases;
+
     // ==================== 构造方法 ====================
 
     /**
@@ -274,20 +279,35 @@ public class EnterpriseHealthComputer {
                         EnterpriseEconomic::getCEnterpriseId,
                         Collectors.toMap(
                                 enterpriseEconomic -> YearMonth.parse(enterpriseEconomic.getCYearMonth(), economicYearMonthFormat),
-                                Function.identity()
+                                Function.identity(),
+                                (a,b)->a
                         )
                 ));
     }
 
+    /**
+     * 添加企业租赁数据
+     *
+     * @param leases 企业租赁数据集合
+     */
+    public void putLease(Collection<LeaseDetail> leases) {
+        enterpriseLeases = leases.stream().collect(Collectors.groupingBy(
+                LeaseDetail::getCEnterpriseCode,
+                Collectors.toList()
+        ));
+    }
+
+    // ================ 计算方法 ================
+
     /**
      * 计算税收上升情况
      *
-     * @param now 当前时间
+     * @param time 当前时间
      */
     @SuppressWarnings("DuplicatedCode")
-    public void computeTaxRise(LocalDateTime now) {
+    public void computeTaxRise(LocalDateTime time) {
         //最近四个季节
-        List<Season> seasons = getLastFourSeason(now);
+        List<Season> seasons = getLastFourSeason(time);
         //四个季节的上一年同季节
         List<Season> previousYearSeasons = seasons.stream().map(s -> s.minusSeasons(4)).collect(Collectors.toList());
         for (Enterprise enterprise : enterprises) {
@@ -306,7 +326,7 @@ public class EnterpriseHealthComputer {
                         HealthType.TAX_RISE.getDefaultName()+simpleDecimalFormat.format(riseRate.subtract(BigDecimal.ONE)),
                         HealthType.TAX_RISE.getDefaultDescribe(),
                         HealthType.TAX_RISE,
-                        now, seasons.get(0).getStartTime(), seasons.get(seasons.size() - 1).getEndTime());
+                        time, seasons.get(0).getStartTime(), seasons.get(seasons.size() - 1).getEndTime());
             }
         }
     }
@@ -314,12 +334,12 @@ public class EnterpriseHealthComputer {
     /**
      * 计算产出上升情况
      *
-     * @param now 当前时间
+     * @param time 当前时间
      */
     @SuppressWarnings("DuplicatedCode")
-    public void computeOutputRise(LocalDateTime now) {
+    public void computeOutputRise(LocalDateTime time) {
         //最近四个季节
-        List<Season> seasons = getLastFourSeason(now);
+        List<Season> seasons = getLastFourSeason(time);
         //四个季节的上一年同季节
         List<Season> previousYearSeasons = seasons.stream().map(s -> s.minusSeasons(4)).collect(Collectors.toList());
         for (Enterprise enterprise : enterprises) {
@@ -340,7 +360,7 @@ public class EnterpriseHealthComputer {
                         HealthType.OUTPUT_RISE.getDefaultName()+simpleDecimalFormat.format(riseRate.subtract(BigDecimal.ONE)),
                         HealthType.OUTPUT_RISE.getDefaultDescribe(),
                         HealthType.OUTPUT_RISE,
-                        now, seasons.get(0).getStartTime(), seasons.get(seasons.size() - 1).getEndTime());
+                        time, seasons.get(0).getStartTime(), seasons.get(seasons.size() - 1).getEndTime());
             }
         }
 
@@ -349,10 +369,10 @@ public class EnterpriseHealthComputer {
     /**
      * 计算税收跳水情况
      *
-     * @param now 当前时间
+     * @param time 当前时间
      */
-    public void computeTaxDive(LocalDateTime now) {
-        Season season = getLastSeason(now);
+    public void computeTaxDive(LocalDateTime time) {
+        Season season = getLastSeason(time);
         Season previousYearSeason = season.minusSeasons(4);
         for (Enterprise enterprise : enterprises) {
             List<EnterpriseEconomic> seasonEconomic = getEconomicBySeason(enterprise,season);
@@ -374,7 +394,7 @@ public class EnterpriseHealthComputer {
             if (seasonTax.compareTo(previousYearSeasonTax) < 0) {
                 BigDecimal divide = seasonTax.divide(previousYearSeasonTax, RoundingMode.HALF_UP);
                 if (divide.compareTo(BigDecimal.valueOf(7,1))<0){
-                    putResult(enterprise,HealthType.TAX_DIVE,now,season.getStartTime(),season.getEndTime());
+                    putResult(enterprise,HealthType.TAX_DIVE,time,season.getStartTime(),season.getEndTime());
                 }
             }
 
@@ -382,6 +402,31 @@ public class EnterpriseHealthComputer {
         }
     }
 
+    /**
+     * 计算租赁即将过期情况
+     *
+     * @param time 当前时间
+     */
+    public void computeLeaseOutDate(LocalDateTime time) {
+        LocalDate nowDate = time.toLocalDate();
+        for (Enterprise enterprise : enterprises) {
+            String enterpriseCode = enterprise.getCUnifiedSocialCreditCode();
+            if (enterpriseCode==null || enterpriseCode.isEmpty()) continue;
+            List<LeaseDetail> leases =enterpriseLeases.get(enterpriseCode);
+            if (leases==null) continue;
+            boolean leasesAlmostOutDate = leases.stream()
+                    .filter(Objects::nonNull)
+                    .filter(leaseDetail -> !leaseDetail.getStartDate().isAfter(nowDate))
+                    .map(LeaseDetail::getCEndDate)
+                    .filter(Objects::nonNull)
+                    .filter(t-> !t.isBefore(nowDate))
+                    .anyMatch(t-> Duration.between(nowDate.atStartOfDay(),t.atStartOfDay()).toDays()<30);
+            if (leasesAlmostOutDate) {
+                putResult(enterprise,HealthType.LEASE_EXPIRY,time,nowDate.atStartOfDay(),nowDate.plusDays(1).atStartOfDay());
+            }
+        }
+    }
+
     // ==================== 私有方法 ====================
 
     /**
@@ -394,14 +439,12 @@ public class EnterpriseHealthComputer {
      * @param computeTime 计算时间
      * @param healthStart 健康开始时间
      * @param healthEnd   健康结束时间
-     * @return 企业健康对象
      */
-    private EnterpriseHealth putResult(Enterprise enterprise, String title, String describe, HealthType type, LocalDateTime computeTime,
-                                       LocalDateTime healthStart, LocalDateTime healthEnd) {
+    private void putResult(Enterprise enterprise, String title, String describe, HealthType type, LocalDateTime computeTime,
+                           LocalDateTime healthStart, LocalDateTime healthEnd) {
         EnterpriseHealth result = new EnterpriseHealth(title, describe, type.value, computeTime,
                 healthStart, healthEnd, enterprise.getCUnifiedSocialCreditCode());
         results.add(result);
-        return result;
     }
 
     /**
@@ -412,14 +455,12 @@ public class EnterpriseHealthComputer {
      * @param computeTime 计算时间
      * @param healthStart 健康开始时间
      * @param healthEnd   健康结束时间
-     * @return 企业健康对象
      */
-    private EnterpriseHealth putResult(Enterprise enterprise, HealthType type, LocalDateTime computeTime,
-                                       LocalDateTime healthStart, LocalDateTime healthEnd) {
+    private void putResult(Enterprise enterprise, HealthType type, LocalDateTime computeTime,
+                           LocalDateTime healthStart, LocalDateTime healthEnd) {
         EnterpriseHealth result = new EnterpriseHealth(type.defaultName, type.defaultDescribe, type.value, computeTime,
                 healthStart, healthEnd, enterprise.getCUnifiedSocialCreditCode());
         results.add(result);
-        return result;
     }
 
     /**

+ 6 - 0
src/main/java/com/skyversation/xjcy/dms/DMSQuery.java

@@ -38,6 +38,12 @@ public enum DMSQuery {
             return request;
         }
     },
+    ECONOMIC(DMSColumn.ENTERPRISE_ECONOMIC, EnterpriseEconomic.class) {
+        @Override
+        public DMSRequest preRequest(LocalDate now) {
+            return new DMSRequest();
+        }
+    },
     ORDER(DMSColumn.ORDER, Order.class) {
         @Override
         public DMSRequest preRequest(LocalDate now) {