|
@@ -0,0 +1,50 @@
|
|
|
+package com.zjugis.business.job;
|
|
|
+
|
|
|
+import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+import com.zjugis.business.bean.entity.ProjectCost;
|
|
|
+import com.zjugis.business.service.ProjectCostService;
|
|
|
+import com.zjugis.business.service.ProjectService;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.time.LocalDate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author ljy
|
|
|
+ * @version 1.0
|
|
|
+ * @date 2024/4/28 9:17
|
|
|
+ */
|
|
|
+@Component
|
|
|
+@Slf4j
|
|
|
+public class ProjectCostJob {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ProjectCostService projectCostService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ ProjectService projectService;
|
|
|
+
|
|
|
+
|
|
|
+ @XxlJob("projectCostJob")
|
|
|
+ public void projectCostJob(){
|
|
|
+ LocalDate now = LocalDate.now();
|
|
|
+ int year = now.getYear();
|
|
|
+ int month = now.getMonthValue();
|
|
|
+ LocalDate today = LocalDate.of(year, month, 1);
|
|
|
+ List<String> records = projectService.selectAllIds();
|
|
|
+ List<String> ids = projectCostService.selectCurMonthProjectIds(year, month);
|
|
|
+ List<String> notInIds = records.stream().filter(id -> !ids.contains(id)).collect(Collectors.toList());
|
|
|
+ List<ProjectCost> insertBatch = new ArrayList<>(notInIds.size());
|
|
|
+ for (String id : notInIds) {
|
|
|
+ ProjectCost entity = new ProjectCost();
|
|
|
+ entity.setProjectId(id);
|
|
|
+ entity.setCountDate(today);
|
|
|
+ insertBatch.add(entity);
|
|
|
+ }
|
|
|
+ projectCostService.insertBatch(insertBatch);
|
|
|
+ }
|
|
|
+}
|