chenshudong 1 месяц назад
Родитель
Сommit
9cbf6e0203

+ 43 - 0
airport-common/src/main/java/com/sundot/airport/common/config/PersonnelAsyncConfig.java

@@ -0,0 +1,43 @@
1
+package com.sundot.airport.common.config;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.scheduling.annotation.EnableAsync;
6
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
7
+
8
+import java.util.concurrent.Executor;
9
+import java.util.concurrent.ThreadPoolExecutor;
10
+
11
+/**
12
+ * 非干部月度考核异步配置
13
+ *
14
+ * @author ruoyi
15
+ */
16
+@Configuration
17
+@EnableAsync
18
+public class PersonnelAsyncConfig {
19
+
20
+    // 核心线程池大小
21
+    private int corePoolSize = 50;
22
+    // 最大可创建的线程数
23
+    private int maxPoolSize = 200;
24
+    // 队列最大长度
25
+    private int queueCapacity = 1000;
26
+    // 线程池维护线程所允许的空闲时间
27
+    private int keepAliveSeconds = 300;
28
+
29
+    @Bean(name = "personnelAsyncExecutor")
30
+    public Executor personnelAsyncExecutor() {
31
+        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
32
+        executor.setMaxPoolSize(maxPoolSize);
33
+        executor.setCorePoolSize(corePoolSize);
34
+        executor.setQueueCapacity(queueCapacity);
35
+        executor.setKeepAliveSeconds(keepAliveSeconds);
36
+        executor.setThreadNamePrefix("personnel-event-async-"); // 线程名前缀
37
+        // 线程池对拒绝任务(无线程可用)的处理策略
38
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
39
+        executor.initialize();
40
+        return executor;
41
+    }
42
+
43
+}

+ 26 - 0
airport-common/src/main/java/com/sundot/airport/common/event/PersonnelEvent.java

@@ -0,0 +1,26 @@
1
+package com.sundot.airport.common.event;
2
+
3
+import org.springframework.context.ApplicationEvent;
4
+
5
+/**
6
+ * 非干部月度考核事件
7
+ *
8
+ * @author ruoyi
9
+ */
10
+public class PersonnelEvent extends ApplicationEvent {
11
+
12
+    /**
13
+     * 非干部月度考核月份
14
+     */
15
+    private String month;
16
+
17
+    public PersonnelEvent(Object source, String month) {
18
+        super(source);
19
+        this.month = month;
20
+    }
21
+
22
+    public String getMonth() {
23
+        return month;
24
+    }
25
+
26
+}

+ 53 - 0
airport-personnel/src/main/java/com/sundot/airport/personnel/listener/PersonnelEventListener.java

@@ -0,0 +1,53 @@
1
+package com.sundot.airport.personnel.listener;
2
+
3
+import com.sundot.airport.common.event.PersonnelEvent;
4
+import com.sundot.airport.personnel.domain.PersonnelNonCadreMonthlyAssessment;
5
+import com.sundot.airport.personnel.service.IPersonnelNonCadreMonthlyAssessmentService;
6
+import lombok.extern.slf4j.Slf4j;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.context.event.EventListener;
9
+import org.springframework.scheduling.annotation.Async;
10
+import org.springframework.stereotype.Component;
11
+
12
+import java.util.Comparator;
13
+import java.util.List;
14
+import java.util.stream.Collectors;
15
+
16
+/**
17
+ * 非干部月度考核事件监听器
18
+ *
19
+ * @author sundot
20
+ */
21
+@Slf4j
22
+@Component
23
+public class PersonnelEventListener {
24
+
25
+    @Autowired
26
+    private IPersonnelNonCadreMonthlyAssessmentService personnelNonCadreMonthlyAssessmentService;
27
+
28
+    /**
29
+     * 异步处理事件
30
+     */
31
+    @Async("personnelAsyncExecutor")  // 关键:标记为异步方法
32
+    @EventListener  // 监听PersonnelEvent事件
33
+    public void handlePersonnel(PersonnelEvent event) {
34
+        long start = System.currentTimeMillis();
35
+        String month = event.getMonth();
36
+        log.info("【异步处理】开始非干部月度考核【month={}】", month);
37
+        PersonnelNonCadreMonthlyAssessment query = new PersonnelNonCadreMonthlyAssessment();
38
+        query.setAssessmentMonthStart(month);
39
+        List<PersonnelNonCadreMonthlyAssessment> list = personnelNonCadreMonthlyAssessmentService.selectPersonnelNonCadreMonthlyAssessmentList(query);
40
+        list = list.stream()
41
+                .sorted(Comparator.comparing(PersonnelNonCadreMonthlyAssessment::getAssessmentMonth))
42
+                .collect(Collectors.toList());
43
+        list.forEach(item -> {
44
+            PersonnelNonCadreMonthlyAssessment data = personnelNonCadreMonthlyAssessmentService.selectPersonnelNonCadreMonthlyAssessmentById(item.getId());
45
+            // 完善数据
46
+            personnelNonCadreMonthlyAssessmentService.doImprove(data);
47
+            // 修改非干部月度考核-仅更新主表数据
48
+            personnelNonCadreMonthlyAssessmentService.updatePersonnelNonCadreMonthlyAssessmentOnly(data);
49
+        });
50
+        long end = System.currentTimeMillis();
51
+        log.info("【异步处理】完成非干部月度考核【month={}】,耗时【{}】", month, end - start);
52
+    }
53
+}

+ 16 - 0
airport-personnel/src/main/java/com/sundot/airport/personnel/service/IPersonnelNonCadreMonthlyAssessmentService.java

@@ -61,6 +61,22 @@ public interface IPersonnelNonCadreMonthlyAssessmentService extends IService<Per
61 61
     public int deletePersonnelNonCadreMonthlyAssessmentById(Long id);
62 62
 
63 63
     /**
64
+     * 完善数据
65
+     *
66
+     * @param personnelNonCadreMonthlyAssessment 完善数据
67
+     * @return 完善数据
68
+     */
69
+    public void doImprove(PersonnelNonCadreMonthlyAssessment personnelNonCadreMonthlyAssessment);
70
+
71
+    /**
72
+     * 修改非干部月度考核-仅更新主表数据
73
+     *
74
+     * @param personnelNonCadreMonthlyAssessment 非干部月度考核
75
+     * @return 结果
76
+     */
77
+    public int updatePersonnelNonCadreMonthlyAssessmentOnly(PersonnelNonCadreMonthlyAssessment personnelNonCadreMonthlyAssessment);
78
+
79
+    /**
64 80
      * 自动生成指定月份非干部月度考核
65 81
      *
66 82
      * @param month 月份值

+ 24 - 7
airport-personnel/src/main/java/com/sundot/airport/personnel/service/impl/PersonnelNonCadreMonthlyAssessmentServiceImpl.java

@@ -24,6 +24,7 @@ import com.sundot.airport.common.enums.BasePerformanceIndicatorLeaveTypeEnum;
24 24
 import com.sundot.airport.common.enums.BasePerformanceIndicatorQcDeptTypeEnum;
25 25
 import com.sundot.airport.common.enums.BasePerformanceIndicatorRewardPunishmentTypeTypeEnum;
26 26
 import com.sundot.airport.common.enums.RoleTypeEnum;
27
+import com.sundot.airport.common.event.PersonnelEvent;
27 28
 import com.sundot.airport.common.exception.ServiceException;
28 29
 import com.sundot.airport.common.utils.DateUtils;
29 30
 import com.sundot.airport.common.utils.MonthUtils;
@@ -36,6 +37,7 @@ import com.sundot.airport.system.domain.BasePerformanceIndicatorCategory;
36 37
 import com.sundot.airport.system.service.IBasePerformanceIndicatorCategoryService;
37 38
 import com.sundot.airport.system.service.ISysUserService;
38 39
 import org.springframework.beans.factory.annotation.Autowired;
40
+import org.springframework.context.ApplicationEventPublisher;
39 41
 import org.springframework.stereotype.Service;
40 42
 import com.sundot.airport.personnel.mapper.PersonnelNonCadreMonthlyAssessmentMapper;
41 43
 import com.sundot.airport.personnel.domain.PersonnelNonCadreMonthlyAssessment;
@@ -65,6 +67,8 @@ public class PersonnelNonCadreMonthlyAssessmentServiceImpl extends ServiceImpl<P
65 67
     private IBasePerformanceIndicatorCategoryService basePerformanceIndicatorCategoryService;
66 68
     @Autowired
67 69
     private ISysUserService sysUserService;
70
+    @Autowired
71
+    private ApplicationEventPublisher eventPublisher;
68 72
 
69 73
     /**
70 74
      * 查询非干部月度考核
@@ -95,8 +99,6 @@ public class PersonnelNonCadreMonthlyAssessmentServiceImpl extends ServiceImpl<P
95 99
                 });
96 100
             }
97 101
         }
98
-        // 完善数据
99
-        doImprove(result);
100 102
         return result;
101 103
     }
102 104
 
@@ -128,6 +130,8 @@ public class PersonnelNonCadreMonthlyAssessmentServiceImpl extends ServiceImpl<P
128 130
             throw new ServiceException("该用户已存在该考核月份的考核记录");
129 131
         }
130 132
         personnelNonCadreMonthlyAssessment.setCreateTime(DateUtils.getNowDate());
133
+        // 完善数据
134
+        doImprove(personnelNonCadreMonthlyAssessment);
131 135
         int result = personnelNonCadreMonthlyAssessmentMapper.insertPersonnelNonCadreMonthlyAssessment(personnelNonCadreMonthlyAssessment);
132 136
         if (CollUtil.isNotEmpty(personnelNonCadreMonthlyAssessment.getPersonnelMonthlyAssessmentIndicatorDetailList())) {
133 137
             personnelNonCadreMonthlyAssessment.getPersonnelMonthlyAssessmentIndicatorDetailList().forEach(personnelMonthlyAssessmentIndicatorDetail -> {
@@ -145,8 +149,7 @@ public class PersonnelNonCadreMonthlyAssessmentServiceImpl extends ServiceImpl<P
145 149
                 }
146 150
             });
147 151
         }
148
-        PersonnelNonCadreMonthlyAssessment dto = selectPersonnelNonCadreMonthlyAssessmentById(personnelNonCadreMonthlyAssessment.getId());
149
-        personnelNonCadreMonthlyAssessmentMapper.updatePersonnelNonCadreMonthlyAssessment(dto);
152
+        eventPublisher.publishEvent(new PersonnelEvent(this, personnelNonCadreMonthlyAssessment.getAssessmentMonth()));
150 153
         return result;
151 154
     }
152 155
 
@@ -174,6 +177,8 @@ public class PersonnelNonCadreMonthlyAssessmentServiceImpl extends ServiceImpl<P
174 177
                 personnelMonthlyAssessmentIndicatorRewardPunishmentDetailService.removeBatchByIds(personnelMonthlyAssessmentIndicatorRewardPunishmentDetailListOld);
175 178
             }
176 179
         }
180
+        // 完善数据
181
+        doImprove(personnelNonCadreMonthlyAssessment);
177 182
         // 新增新数据
178 183
         if (CollUtil.isNotEmpty(personnelNonCadreMonthlyAssessment.getPersonnelMonthlyAssessmentIndicatorDetailList())) {
179 184
             personnelNonCadreMonthlyAssessment.getPersonnelMonthlyAssessmentIndicatorDetailList().forEach(personnelMonthlyAssessmentIndicatorDetail -> {
@@ -195,8 +200,7 @@ public class PersonnelNonCadreMonthlyAssessmentServiceImpl extends ServiceImpl<P
195 200
                 }
196 201
             });
197 202
         }
198
-        PersonnelNonCadreMonthlyAssessment dto = selectPersonnelNonCadreMonthlyAssessmentById(personnelNonCadreMonthlyAssessment.getId());
199
-        personnelNonCadreMonthlyAssessmentMapper.updatePersonnelNonCadreMonthlyAssessment(dto);
203
+        eventPublisher.publishEvent(new PersonnelEvent(this, personnelNonCadreMonthlyAssessment.getAssessmentMonth()));
200 204
         return result;
201 205
     }
202 206
 
@@ -258,7 +262,8 @@ public class PersonnelNonCadreMonthlyAssessmentServiceImpl extends ServiceImpl<P
258 262
      * @param result 非干部月度考核
259 263
      * @return 非干部月度考核
260 264
      */
261
-    private void doImprove(PersonnelNonCadreMonthlyAssessment result) {
265
+    @Override
266
+    public void doImprove(PersonnelNonCadreMonthlyAssessment result) {
262 267
         List<BasePerformanceIndicatorCategory> indicatorCategoryyList = basePerformanceIndicatorCategoryService.selectBasePerformanceIndicatorCategoryListTree(new BasePerformanceIndicatorCategory());
263 268
         // 红线指标
264 269
         BasePerformanceIndicatorCategory redLineIndexCategory = indicatorCategoryyList.stream().filter(item -> StrUtil.equals("红线指标", item.getName())).findFirst().orElse(null);
@@ -844,6 +849,18 @@ public class PersonnelNonCadreMonthlyAssessmentServiceImpl extends ServiceImpl<P
844 849
     }
845 850
 
846 851
     /**
852
+     * 修改非干部月度考核-仅更新主表数据
853
+     *
854
+     * @param personnelNonCadreMonthlyAssessment 非干部月度考核
855
+     * @return 结果
856
+     */
857
+    @Override
858
+    public int updatePersonnelNonCadreMonthlyAssessmentOnly(PersonnelNonCadreMonthlyAssessment personnelNonCadreMonthlyAssessment) {
859
+        personnelNonCadreMonthlyAssessment.setUpdateTime(DateUtils.getNowDate());
860
+        return personnelNonCadreMonthlyAssessmentMapper.updatePersonnelNonCadreMonthlyAssessment(personnelNonCadreMonthlyAssessment);
861
+    }
862
+
863
+    /**
847 864
      * 自动生成指定月份非干部月度考核
848 865
      *
849 866
      * @param month 月份值