Browse Source

feat: pdsc,项目阶段定时任务

zhangkai 5 months ago
parent
commit
c168c65a67

+ 7 - 0
nationrel-module-pdsc-api/pom.xml

@@ -19,12 +19,19 @@
             <groupId>org.springframework.cloud</groupId>
             <artifactId>spring-cloud-starter-openfeign</artifactId>
         </dependency>
+
         <!-- sentinel限流熔断降级-->
         <dependency>
             <groupId>com.alibaba.cloud</groupId>
             <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
         </dependency>
 
+        <!-- 引入定时任务依赖 -->
+        <dependency>
+            <groupId>org.jeecgframework.boot</groupId>
+            <artifactId>jeecg-boot-starter3-job</artifactId>
+        </dependency>
+
     </dependencies>
     <build>
         <plugins>

+ 67 - 0
nationrel-module-pdsc-biz/src/main/java/com/nationrel/modules/pdsc/xxljob/ProjectStageJobHandler.java

@@ -0,0 +1,67 @@
+package com.nationrel.modules.pdsc.xxljob;
+
+import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.util.ObjectUtil;
+import com.nationrel.modules.pdsc.entity.ProjectInfo;
+import com.nationrel.modules.pdsc.enums.ProjectStatuseEnum;
+import com.nationrel.modules.pdsc.service.IProjectInfoService;
+import com.xxl.job.core.biz.model.ReturnT;
+import com.xxl.job.core.handler.annotation.XxlJob;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+
+/**
+ * 项目阶段定时任务
+ */
+@Component
+@Slf4j
+public class ProjectStageJobHandler {
+
+    @Autowired
+    private IProjectInfoService projectInfoService;
+
+    @XxlJob(value = "projectStageJob")
+    public ReturnT<String> projectStageJobHandler(String params) {
+        List<ProjectInfo> projectInfos = projectInfoService.list().stream().filter(v ->
+                ObjectUtil.equals(ProjectStatuseEnum.UNDER_PREPARATION.getType(), v.getStatus())).toList();
+        projectInfos.forEach(v -> {
+            v.setProjectStage(getProjectStage(v));
+        });
+        if (CollectionUtil.isNotEmpty(projectInfos)) {
+            projectInfoService.updateBatchById(projectInfos);
+        }
+        return ReturnT.SUCCESS;
+    }
+
+    private String getProjectStage(ProjectInfo projectInfo) {
+        DateTime currentDay = DateUtil.parseDate(DateUtil.today());
+        DateTime zeroLevelTime = DateUtil.date(projectInfo.getZeroLevelTime());
+        DateTime oneLevelTime = DateUtil.date(projectInfo.getOneLevelTime());
+        DateTime twoLevelTime = DateUtil.date(projectInfo.getTwoLevelTime());
+        DateTime threeLevelTime = DateUtil.date(projectInfo.getThreeLevelTime());
+        DateTime fourLevelTime = DateUtil.date(projectInfo.getFourLevelTime());
+        DateTime fiveLevelTime = DateUtil.date(projectInfo.getFiveLevelTime());
+        DateTime sixLevelTime = DateUtil.date(projectInfo.getSixLevelTime());
+        if (DateUtil.compare(currentDay, zeroLevelTime) < 0 || DateUtil.compare(currentDay, zeroLevelTime) == 0) {
+            return "0";
+        } else if (DateUtil.compare(currentDay, oneLevelTime) < 0 || DateUtil.compare(currentDay, oneLevelTime) == 0) {
+            return "1";
+        } else if (DateUtil.compare(currentDay, twoLevelTime) < 0 || DateUtil.compare(currentDay, twoLevelTime) == 0) {
+            return "2";
+        } else if (DateUtil.compare(currentDay, threeLevelTime) < 0 || DateUtil.compare(currentDay, threeLevelTime) == 0) {
+            return "3";
+        } else if (DateUtil.compare(currentDay, fourLevelTime) < 0 || DateUtil.compare(currentDay, fourLevelTime) == 0) {
+            return "4";
+        } else if (DateUtil.compare(currentDay, fiveLevelTime) < 0 || DateUtil.compare(currentDay, fiveLevelTime) == 0) {
+            return "5";
+        } else if (DateUtil.compare(currentDay, sixLevelTime) < 0 || DateUtil.compare(currentDay, sixLevelTime) == 0) {
+            return "6";
+        }
+        return "0";
+    }
+}