Commit c3e1d2ba5415910f93e4cd29d943762abac5ddc9
1 parent
4be4b653
定时任务并发串行设定提交
Signed-off-by: TanYibin <5491541@qq.com>
Showing
8 changed files
with
110 additions
and
129 deletions
huaheng-wms-core/src/main/java/org/jeecg/modules/message/job/SendMsgJob.java
@@ -8,9 +8,11 @@ import org.jeecg.modules.message.handle.ISendMsgHandle; | @@ -8,9 +8,11 @@ import org.jeecg.modules.message.handle.ISendMsgHandle; | ||
8 | import org.jeecg.modules.message.handle.enums.SendMsgStatusEnum; | 8 | import org.jeecg.modules.message.handle.enums.SendMsgStatusEnum; |
9 | import org.jeecg.modules.message.handle.enums.SendMsgTypeEnum; | 9 | import org.jeecg.modules.message.handle.enums.SendMsgTypeEnum; |
10 | import org.jeecg.modules.message.service.ISysMessageService; | 10 | import org.jeecg.modules.message.service.ISysMessageService; |
11 | +import org.quartz.DisallowConcurrentExecution; | ||
11 | import org.quartz.Job; | 12 | import org.quartz.Job; |
12 | import org.quartz.JobExecutionContext; | 13 | import org.quartz.JobExecutionContext; |
13 | import org.quartz.JobExecutionException; | 14 | import org.quartz.JobExecutionException; |
15 | +import org.quartz.PersistJobDataAfterExecution; | ||
14 | import org.springframework.beans.factory.annotation.Autowired; | 16 | import org.springframework.beans.factory.annotation.Autowired; |
15 | 17 | ||
16 | import com.alibaba.fastjson.JSON; | 18 | import com.alibaba.fastjson.JSON; |
@@ -23,6 +25,8 @@ import lombok.extern.slf4j.Slf4j; | @@ -23,6 +25,8 @@ import lombok.extern.slf4j.Slf4j; | ||
23 | */ | 25 | */ |
24 | 26 | ||
25 | @Slf4j | 27 | @Slf4j |
28 | +@PersistJobDataAfterExecution | ||
29 | +@DisallowConcurrentExecution | ||
26 | public class SendMsgJob implements Job { | 30 | public class SendMsgJob implements Job { |
27 | 31 | ||
28 | @Autowired | 32 | @Autowired |
huaheng-wms-core/src/main/java/org/jeecg/modules/quartz/job/AsyncJob.java
@@ -11,9 +11,9 @@ import org.quartz.*; | @@ -11,9 +11,9 @@ import org.quartz.*; | ||
11 | * @author: taoyan | 11 | * @author: taoyan |
12 | * @date: 2020年06月19日 | 12 | * @date: 2020年06月19日 |
13 | */ | 13 | */ |
14 | +@Slf4j | ||
14 | @PersistJobDataAfterExecution | 15 | @PersistJobDataAfterExecution |
15 | @DisallowConcurrentExecution | 16 | @DisallowConcurrentExecution |
16 | -@Slf4j | ||
17 | public class AsyncJob implements Job { | 17 | public class AsyncJob implements Job { |
18 | 18 | ||
19 | @Override | 19 | @Override |
huaheng-wms-core/src/main/java/org/jeecg/modules/quartz/job/SampleJob.java
1 | package org.jeecg.modules.quartz.job; | 1 | package org.jeecg.modules.quartz.job; |
2 | 2 | ||
3 | import org.jeecg.common.util.DateUtils; | 3 | import org.jeecg.common.util.DateUtils; |
4 | +import org.quartz.DisallowConcurrentExecution; | ||
4 | import org.quartz.Job; | 5 | import org.quartz.Job; |
5 | import org.quartz.JobExecutionContext; | 6 | import org.quartz.JobExecutionContext; |
6 | import org.quartz.JobExecutionException; | 7 | import org.quartz.JobExecutionException; |
8 | +import org.quartz.PersistJobDataAfterExecution; | ||
7 | 9 | ||
8 | import lombok.extern.slf4j.Slf4j; | 10 | import lombok.extern.slf4j.Slf4j; |
9 | 11 | ||
@@ -12,11 +14,13 @@ import lombok.extern.slf4j.Slf4j; | @@ -12,11 +14,13 @@ import lombok.extern.slf4j.Slf4j; | ||
12 | * @Author Scott | 14 | * @Author Scott |
13 | */ | 15 | */ |
14 | @Slf4j | 16 | @Slf4j |
17 | +@PersistJobDataAfterExecution | ||
18 | +@DisallowConcurrentExecution | ||
15 | public class SampleJob implements Job { | 19 | public class SampleJob implements Job { |
16 | 20 | ||
17 | @Override | 21 | @Override |
18 | public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { | 22 | public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { |
19 | log.info(" Job Execution key:" + jobExecutionContext.getJobDetail().getKey()); | 23 | log.info(" Job Execution key:" + jobExecutionContext.getJobDetail().getKey()); |
20 | - log.info(String.format(" Jeecg-Boot 普通定时任务 SampleJob ! 时间:" + DateUtils.getTimestamp())); | 24 | + log.info(String.format(" Jeecg-Boot 普通定时任务 SampleJob! 时间:" + DateUtils.getTimestamp())); |
21 | } | 25 | } |
22 | } | 26 | } |
huaheng-wms-core/src/main/java/org/jeecg/modules/quartz/job/SampleParamJob.java
1 | package org.jeecg.modules.quartz.job; | 1 | package org.jeecg.modules.quartz.job; |
2 | 2 | ||
3 | import org.jeecg.common.util.DateUtils; | 3 | import org.jeecg.common.util.DateUtils; |
4 | +import org.quartz.DisallowConcurrentExecution; | ||
4 | import org.quartz.Job; | 5 | import org.quartz.Job; |
5 | import org.quartz.JobExecutionContext; | 6 | import org.quartz.JobExecutionContext; |
6 | import org.quartz.JobExecutionException; | 7 | import org.quartz.JobExecutionException; |
8 | +import org.quartz.PersistJobDataAfterExecution; | ||
7 | 9 | ||
8 | import lombok.extern.slf4j.Slf4j; | 10 | import lombok.extern.slf4j.Slf4j; |
9 | 11 | ||
@@ -12,6 +14,8 @@ import lombok.extern.slf4j.Slf4j; | @@ -12,6 +14,8 @@ import lombok.extern.slf4j.Slf4j; | ||
12 | * @Author Scott | 14 | * @Author Scott |
13 | */ | 15 | */ |
14 | @Slf4j | 16 | @Slf4j |
17 | +@PersistJobDataAfterExecution | ||
18 | +@DisallowConcurrentExecution | ||
15 | public class SampleParamJob implements Job { | 19 | public class SampleParamJob implements Job { |
16 | 20 | ||
17 | /** | 21 | /** |
@@ -26,6 +30,6 @@ public class SampleParamJob implements Job { | @@ -26,6 +30,6 @@ public class SampleParamJob implements Job { | ||
26 | @Override | 30 | @Override |
27 | public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { | 31 | public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { |
28 | log.info(" Job Execution key:" + jobExecutionContext.getJobDetail().getKey()); | 32 | log.info(" Job Execution key:" + jobExecutionContext.getJobDetail().getKey()); |
29 | - log.info(String.format("welcome %s! Jeecg-Boot 带参数定时任务 SampleParamJob ! 时间:" + DateUtils.now(), this.parameter)); | 33 | + log.info(String.format("welcome %s! Jeecg-Boot 带参数定时任务 SampleParamJob! 时间:" + DateUtils.now(), this.parameter)); |
30 | } | 34 | } |
31 | } | 35 | } |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/monitor/job/ErpTask.java
@@ -13,9 +13,11 @@ import org.jeecg.modules.wms.receipt.receiptHeader.service.IReceiptHeaderService | @@ -13,9 +13,11 @@ import org.jeecg.modules.wms.receipt.receiptHeader.service.IReceiptHeaderService | ||
13 | import org.jeecg.modules.wms.shipment.shipmentHeader.entity.ShipmentHeader; | 13 | import org.jeecg.modules.wms.shipment.shipmentHeader.entity.ShipmentHeader; |
14 | import org.jeecg.modules.wms.shipment.shipmentHeader.service.IShipmentHeaderService; | 14 | import org.jeecg.modules.wms.shipment.shipmentHeader.service.IShipmentHeaderService; |
15 | import org.jeecg.utils.constant.QuantityConstant; | 15 | import org.jeecg.utils.constant.QuantityConstant; |
16 | +import org.quartz.DisallowConcurrentExecution; | ||
16 | import org.quartz.Job; | 17 | import org.quartz.Job; |
17 | import org.quartz.JobExecutionContext; | 18 | import org.quartz.JobExecutionContext; |
18 | import org.quartz.JobExecutionException; | 19 | import org.quartz.JobExecutionException; |
20 | +import org.quartz.PersistJobDataAfterExecution; | ||
19 | 21 | ||
20 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 22 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
21 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 23 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
@@ -28,52 +30,43 @@ import lombok.extern.slf4j.Slf4j; | @@ -28,52 +30,43 @@ import lombok.extern.slf4j.Slf4j; | ||
28 | */ | 30 | */ |
29 | 31 | ||
30 | @Slf4j | 32 | @Slf4j |
33 | +@PersistJobDataAfterExecution | ||
34 | +@DisallowConcurrentExecution | ||
31 | public class ErpTask implements Job { | 35 | public class ErpTask implements Job { |
32 | 36 | ||
33 | @Resource | 37 | @Resource |
34 | private IReceiptHeaderService receiptHeaderService; | 38 | private IReceiptHeaderService receiptHeaderService; |
39 | + | ||
35 | @Resource | 40 | @Resource |
36 | private IShipmentHeaderService shipmentHeaderService; | 41 | private IShipmentHeaderService shipmentHeaderService; |
42 | + | ||
37 | @Resource | 43 | @Resource |
38 | private IErpService erpService; | 44 | private IErpService erpService; |
39 | - // 并发控制 | ||
40 | - Map<String, Boolean> runningTaskMap = new HashMap<>(); | ||
41 | 45 | ||
42 | @Override | 46 | @Override |
43 | public void execute(JobExecutionContext context) throws JobExecutionException { | 47 | public void execute(JobExecutionContext context) throws JobExecutionException { |
44 | - String taskKey = "ErpTask"; | ||
45 | - if (MapUtils.getBoolean(runningTaskMap, taskKey, false)) { | ||
46 | - return; | ||
47 | - } | ||
48 | - try { | ||
49 | - runningTaskMap.put(taskKey, true); | ||
50 | - LambdaQueryWrapper<ReceiptHeader> receiptHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); | ||
51 | - receiptHeaderLambdaQueryWrapper.eq(ReceiptHeader::getFirstStatus, QuantityConstant.RECEIPT_HEADER_COMPLETED).eq(ReceiptHeader::getLastStatus, | ||
52 | - QuantityConstant.RECEIPT_HEADER_COMPLETED); | ||
53 | - List<ReceiptHeader> receiptHeaderList = receiptHeaderService.list(receiptHeaderLambdaQueryWrapper); | ||
54 | - for (ReceiptHeader receiptHeader : receiptHeaderList) { | ||
55 | - try { | ||
56 | - erpService.backReceipt(receiptHeader); | ||
57 | - } catch (Exception e) { | ||
58 | - e.printStackTrace(); | ||
59 | - } | 48 | + LambdaQueryWrapper<ReceiptHeader> receiptHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); |
49 | + receiptHeaderLambdaQueryWrapper.eq(ReceiptHeader::getFirstStatus, QuantityConstant.RECEIPT_HEADER_COMPLETED).eq(ReceiptHeader::getLastStatus, | ||
50 | + QuantityConstant.RECEIPT_HEADER_COMPLETED); | ||
51 | + List<ReceiptHeader> receiptHeaderList = receiptHeaderService.list(receiptHeaderLambdaQueryWrapper); | ||
52 | + for (ReceiptHeader receiptHeader : receiptHeaderList) { | ||
53 | + try { | ||
54 | + erpService.backReceipt(receiptHeader); | ||
55 | + } catch (Exception e) { | ||
56 | + e.printStackTrace(); | ||
60 | } | 57 | } |
58 | + } | ||
61 | 59 | ||
62 | - LambdaQueryWrapper<ShipmentHeader> shipmentHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); | ||
63 | - shipmentHeaderLambdaQueryWrapper.eq(ShipmentHeader::getFirstStatus, QuantityConstant.RECEIPT_HEADER_COMPLETED).eq(ShipmentHeader::getLastStatus, | ||
64 | - QuantityConstant.RECEIPT_HEADER_COMPLETED); | ||
65 | - List<ShipmentHeader> shipmentHeaderList = shipmentHeaderService.list(shipmentHeaderLambdaQueryWrapper); | ||
66 | - for (ShipmentHeader shipmentHeader : shipmentHeaderList) { | ||
67 | - try { | ||
68 | - erpService.backShipment(shipmentHeader); | ||
69 | - } catch (Exception e) { | ||
70 | - e.printStackTrace(); | ||
71 | - } | 60 | + LambdaQueryWrapper<ShipmentHeader> shipmentHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); |
61 | + shipmentHeaderLambdaQueryWrapper.eq(ShipmentHeader::getFirstStatus, QuantityConstant.RECEIPT_HEADER_COMPLETED).eq(ShipmentHeader::getLastStatus, | ||
62 | + QuantityConstant.RECEIPT_HEADER_COMPLETED); | ||
63 | + List<ShipmentHeader> shipmentHeaderList = shipmentHeaderService.list(shipmentHeaderLambdaQueryWrapper); | ||
64 | + for (ShipmentHeader shipmentHeader : shipmentHeaderList) { | ||
65 | + try { | ||
66 | + erpService.backShipment(shipmentHeader); | ||
67 | + } catch (Exception e) { | ||
68 | + e.printStackTrace(); | ||
72 | } | 69 | } |
73 | - } catch (Exception e) { | ||
74 | - e.printStackTrace(); | ||
75 | - } finally { | ||
76 | - runningTaskMap.put(taskKey, false); | ||
77 | } | 70 | } |
78 | } | 71 | } |
79 | } | 72 | } |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/monitor/job/MesTask.java
@@ -11,9 +11,11 @@ import org.jeecg.modules.wms.api.mes.servuce.IMesService; | @@ -11,9 +11,11 @@ import org.jeecg.modules.wms.api.mes.servuce.IMesService; | ||
11 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; | 11 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; |
12 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; | 12 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; |
13 | import org.jeecg.utils.constant.QuantityConstant; | 13 | import org.jeecg.utils.constant.QuantityConstant; |
14 | +import org.quartz.DisallowConcurrentExecution; | ||
14 | import org.quartz.Job; | 15 | import org.quartz.Job; |
15 | import org.quartz.JobExecutionContext; | 16 | import org.quartz.JobExecutionContext; |
16 | import org.quartz.JobExecutionException; | 17 | import org.quartz.JobExecutionException; |
18 | +import org.quartz.PersistJobDataAfterExecution; | ||
17 | 19 | ||
18 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 20 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
19 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 21 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
@@ -24,14 +26,15 @@ import lombok.extern.slf4j.Slf4j; | @@ -24,14 +26,15 @@ import lombok.extern.slf4j.Slf4j; | ||
24 | * @author 游杰 | 26 | * @author 游杰 |
25 | */ | 27 | */ |
26 | @Slf4j | 28 | @Slf4j |
29 | +@PersistJobDataAfterExecution | ||
30 | +@DisallowConcurrentExecution | ||
27 | public class MesTask implements Job { | 31 | public class MesTask implements Job { |
28 | 32 | ||
29 | @Resource | 33 | @Resource |
30 | private IMesService mesService; | 34 | private IMesService mesService; |
35 | + | ||
31 | @Resource | 36 | @Resource |
32 | private ITaskHeaderService taskHeaderService; | 37 | private ITaskHeaderService taskHeaderService; |
33 | - // 并发控制 | ||
34 | - Map<String, Boolean> runningTaskMap = new HashMap<>(); | ||
35 | 38 | ||
36 | /** | 39 | /** |
37 | * 找到完成状态的,没有回传成功的所有任务,然后回传信息给MES | 40 | * 找到完成状态的,没有回传成功的所有任务,然后回传信息给MES |
@@ -40,43 +43,32 @@ public class MesTask implements Job { | @@ -40,43 +43,32 @@ public class MesTask implements Job { | ||
40 | */ | 43 | */ |
41 | @Override | 44 | @Override |
42 | public void execute(JobExecutionContext context) throws JobExecutionException { | 45 | public void execute(JobExecutionContext context) throws JobExecutionException { |
43 | - String taskKey = "MesTask"; | ||
44 | - if (MapUtils.getBoolean(runningTaskMap, taskKey, false)) { | ||
45 | - return; | ||
46 | - } | ||
47 | - try { | ||
48 | - runningTaskMap.put(taskKey, true); | ||
49 | - LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); | ||
50 | - taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED).ne(TaskHeader::getBackMes, QuantityConstant.MES_SEND_OK) | ||
51 | - .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_WHOLERECEIPT, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT) | ||
52 | - .le(TaskHeader::getBackMesTimes, QuantityConstant.MAX_MES_TRY_TIMES); | ||
53 | - List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper); | ||
54 | - for (TaskHeader taskHeader : taskHeaderList) { | ||
55 | - try { | ||
56 | - taskHeaderService.addMesTryTimes(taskHeader); | ||
57 | - mesService.backMesReceipt(taskHeader); | ||
58 | - } catch (Exception e) { | ||
59 | - e.printStackTrace(); | ||
60 | - } | 46 | + LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); |
47 | + taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED).ne(TaskHeader::getBackMes, QuantityConstant.MES_SEND_OK) | ||
48 | + .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_WHOLERECEIPT, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT) | ||
49 | + .le(TaskHeader::getBackMesTimes, QuantityConstant.MAX_MES_TRY_TIMES); | ||
50 | + List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper); | ||
51 | + for (TaskHeader taskHeader : taskHeaderList) { | ||
52 | + try { | ||
53 | + taskHeaderService.addMesTryTimes(taskHeader); | ||
54 | + mesService.backMesReceipt(taskHeader); | ||
55 | + } catch (Exception e) { | ||
56 | + e.printStackTrace(); | ||
61 | } | 57 | } |
58 | + } | ||
62 | 59 | ||
63 | - taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); | ||
64 | - taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED).ne(TaskHeader::getBackMes, QuantityConstant.MES_SEND_OK) | ||
65 | - .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_WHOLESHIPMENT, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT) | ||
66 | - .le(TaskHeader::getBackMesTimes, QuantityConstant.MAX_MES_TRY_TIMES); | ||
67 | - taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper); | ||
68 | - for (TaskHeader taskHeader : taskHeaderList) { | ||
69 | - try { | ||
70 | - taskHeaderService.addMesTryTimes(taskHeader); | ||
71 | - mesService.backMesShipment(taskHeader); | ||
72 | - } catch (Exception e) { | ||
73 | - e.printStackTrace(); | ||
74 | - } | 60 | + taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); |
61 | + taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED).ne(TaskHeader::getBackMes, QuantityConstant.MES_SEND_OK) | ||
62 | + .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_WHOLESHIPMENT, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT) | ||
63 | + .le(TaskHeader::getBackMesTimes, QuantityConstant.MAX_MES_TRY_TIMES); | ||
64 | + taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper); | ||
65 | + for (TaskHeader taskHeader : taskHeaderList) { | ||
66 | + try { | ||
67 | + taskHeaderService.addMesTryTimes(taskHeader); | ||
68 | + mesService.backMesShipment(taskHeader); | ||
69 | + } catch (Exception e) { | ||
70 | + e.printStackTrace(); | ||
75 | } | 71 | } |
76 | - } catch (Exception e) { | ||
77 | - e.printStackTrace(); | ||
78 | - } finally { | ||
79 | - runningTaskMap.put(taskKey, false); | ||
80 | } | 72 | } |
81 | } | 73 | } |
82 | } | 74 | } |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/monitor/job/MesTryTask.java
@@ -11,9 +11,11 @@ import org.jeecg.modules.wms.api.mes.servuce.IMesService; | @@ -11,9 +11,11 @@ import org.jeecg.modules.wms.api.mes.servuce.IMesService; | ||
11 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; | 11 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; |
12 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; | 12 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; |
13 | import org.jeecg.utils.constant.QuantityConstant; | 13 | import org.jeecg.utils.constant.QuantityConstant; |
14 | +import org.quartz.DisallowConcurrentExecution; | ||
14 | import org.quartz.Job; | 15 | import org.quartz.Job; |
15 | import org.quartz.JobExecutionContext; | 16 | import org.quartz.JobExecutionContext; |
16 | import org.quartz.JobExecutionException; | 17 | import org.quartz.JobExecutionException; |
18 | +import org.quartz.PersistJobDataAfterExecution; | ||
17 | 19 | ||
18 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 20 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
19 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 21 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
@@ -24,14 +26,15 @@ import lombok.extern.slf4j.Slf4j; | @@ -24,14 +26,15 @@ import lombok.extern.slf4j.Slf4j; | ||
24 | * @author 游杰 | 26 | * @author 游杰 |
25 | */ | 27 | */ |
26 | @Slf4j | 28 | @Slf4j |
29 | +@PersistJobDataAfterExecution | ||
30 | +@DisallowConcurrentExecution | ||
27 | public class MesTryTask implements Job { | 31 | public class MesTryTask implements Job { |
28 | 32 | ||
29 | @Resource | 33 | @Resource |
30 | private IMesService mesService; | 34 | private IMesService mesService; |
35 | + | ||
31 | @Resource | 36 | @Resource |
32 | private ITaskHeaderService taskHeaderService; | 37 | private ITaskHeaderService taskHeaderService; |
33 | - // 并发控制 | ||
34 | - Map<String, Boolean> runningTaskMap = new HashMap<>(); | ||
35 | 38 | ||
36 | /** | 39 | /** |
37 | * 找到完成状态的,没有回传成功的所有任务,然后回传信息给MES | 40 | * 找到完成状态的,没有回传成功的所有任务,然后回传信息给MES |
@@ -40,43 +43,32 @@ public class MesTryTask implements Job { | @@ -40,43 +43,32 @@ public class MesTryTask implements Job { | ||
40 | */ | 43 | */ |
41 | @Override | 44 | @Override |
42 | public void execute(JobExecutionContext context) throws JobExecutionException { | 45 | public void execute(JobExecutionContext context) throws JobExecutionException { |
43 | - String taskKey = "MesTrYTask"; | ||
44 | - if (MapUtils.getBoolean(runningTaskMap, taskKey, false)) { | ||
45 | - return; | ||
46 | - } | ||
47 | - try { | ||
48 | - runningTaskMap.put(taskKey, true); | ||
49 | - LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); | ||
50 | - taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED).ne(TaskHeader::getBackMes, QuantityConstant.MES_SEND_OK) | ||
51 | - .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_WHOLERECEIPT, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT) | ||
52 | - .gt(TaskHeader::getBackMesTimes, QuantityConstant.MAX_MES_TRY_TIMES); | ||
53 | - List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper); | ||
54 | - for (TaskHeader taskHeader : taskHeaderList) { | ||
55 | - try { | ||
56 | - taskHeaderService.addMesTryTimes(taskHeader); | ||
57 | - mesService.backMesReceipt(taskHeader); | ||
58 | - } catch (Exception e) { | ||
59 | - e.printStackTrace(); | ||
60 | - } | 46 | + LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); |
47 | + taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED).ne(TaskHeader::getBackMes, QuantityConstant.MES_SEND_OK) | ||
48 | + .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_WHOLERECEIPT, QuantityConstant.TASK_TYPE_SUPPLEMENTRECEIPT) | ||
49 | + .gt(TaskHeader::getBackMesTimes, QuantityConstant.MAX_MES_TRY_TIMES); | ||
50 | + List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper); | ||
51 | + for (TaskHeader taskHeader : taskHeaderList) { | ||
52 | + try { | ||
53 | + taskHeaderService.addMesTryTimes(taskHeader); | ||
54 | + mesService.backMesReceipt(taskHeader); | ||
55 | + } catch (Exception e) { | ||
56 | + e.printStackTrace(); | ||
61 | } | 57 | } |
58 | + } | ||
62 | 59 | ||
63 | - taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); | ||
64 | - taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED).ne(TaskHeader::getBackMes, QuantityConstant.MES_SEND_OK) | ||
65 | - .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_WHOLESHIPMENT, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT) | ||
66 | - .gt(TaskHeader::getBackMesTimes, QuantityConstant.MAX_MES_TRY_TIMES); | ||
67 | - taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper); | ||
68 | - for (TaskHeader taskHeader : taskHeaderList) { | ||
69 | - try { | ||
70 | - taskHeaderService.addMesTryTimes(taskHeader); | ||
71 | - mesService.backMesShipment(taskHeader); | ||
72 | - } catch (Exception e) { | ||
73 | - e.printStackTrace(); | ||
74 | - } | 60 | + taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); |
61 | + taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_COMPLETED).ne(TaskHeader::getBackMes, QuantityConstant.MES_SEND_OK) | ||
62 | + .in(TaskHeader::getTaskType, QuantityConstant.TASK_TYPE_WHOLESHIPMENT, QuantityConstant.TASK_TYPE_SORTINGSHIPMENT) | ||
63 | + .gt(TaskHeader::getBackMesTimes, QuantityConstant.MAX_MES_TRY_TIMES); | ||
64 | + taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper); | ||
65 | + for (TaskHeader taskHeader : taskHeaderList) { | ||
66 | + try { | ||
67 | + taskHeaderService.addMesTryTimes(taskHeader); | ||
68 | + mesService.backMesShipment(taskHeader); | ||
69 | + } catch (Exception e) { | ||
70 | + e.printStackTrace(); | ||
75 | } | 71 | } |
76 | - } catch (Exception e) { | ||
77 | - e.printStackTrace(); | ||
78 | - } finally { | ||
79 | - runningTaskMap.put(taskKey, false); | ||
80 | } | 72 | } |
81 | } | 73 | } |
82 | } | 74 | } |
huaheng-wms-core/src/main/java/org/jeecg/modules/wms/monitor/job/WcsTask.java
@@ -12,9 +12,11 @@ import org.jeecg.modules.wms.framework.service.IHuahengMultiHandlerService; | @@ -12,9 +12,11 @@ import org.jeecg.modules.wms.framework.service.IHuahengMultiHandlerService; | ||
12 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; | 12 | import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; |
13 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; | 13 | import org.jeecg.modules.wms.task.taskHeader.service.ITaskHeaderService; |
14 | import org.jeecg.utils.constant.QuantityConstant; | 14 | import org.jeecg.utils.constant.QuantityConstant; |
15 | +import org.quartz.DisallowConcurrentExecution; | ||
15 | import org.quartz.Job; | 16 | import org.quartz.Job; |
16 | import org.quartz.JobExecutionContext; | 17 | import org.quartz.JobExecutionContext; |
17 | import org.quartz.JobExecutionException; | 18 | import org.quartz.JobExecutionException; |
19 | +import org.quartz.PersistJobDataAfterExecution; | ||
18 | 20 | ||
19 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | 21 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
20 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; | 22 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
@@ -27,38 +29,28 @@ import lombok.extern.slf4j.Slf4j; | @@ -27,38 +29,28 @@ import lombok.extern.slf4j.Slf4j; | ||
27 | */ | 29 | */ |
28 | 30 | ||
29 | @Slf4j | 31 | @Slf4j |
32 | +@PersistJobDataAfterExecution | ||
33 | +@DisallowConcurrentExecution | ||
30 | public class WcsTask implements Job { | 34 | public class WcsTask implements Job { |
31 | 35 | ||
32 | - // 并发控制 | ||
33 | - Map<String, Boolean> runningTaskMap = new HashMap<>(); | ||
34 | @Resource | 36 | @Resource |
35 | private ITaskHeaderService taskHeaderService; | 37 | private ITaskHeaderService taskHeaderService; |
38 | + | ||
36 | @Resource | 39 | @Resource |
37 | private IHuahengMultiHandlerService huahengMultiHandlerService; | 40 | private IHuahengMultiHandlerService huahengMultiHandlerService; |
38 | 41 | ||
39 | @Override | 42 | @Override |
40 | public void execute(JobExecutionContext context) throws JobExecutionException { | 43 | public void execute(JobExecutionContext context) throws JobExecutionException { |
41 | - log.info(String.format(" Jeecg-Boot 执行任务! 时间:" + DateUtils.getTimestamp())); | ||
42 | - String taskKey = "RyTask"; | ||
43 | - if (MapUtils.getBoolean(runningTaskMap, taskKey, false)) { | ||
44 | - return; | ||
45 | - } | ||
46 | - try { | ||
47 | - runningTaskMap.put(taskKey, true); | ||
48 | - LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); | ||
49 | - taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_BUILD).eq(TaskHeader::getAgvTaskId, 0); | ||
50 | - List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper); | ||
51 | - for (TaskHeader taskHeader : taskHeaderList) { | ||
52 | - try { | ||
53 | - huahengMultiHandlerService.sendTaskToWcs(taskHeader); | ||
54 | - } catch (Exception e) { | ||
55 | - e.printStackTrace(); | ||
56 | - } | 44 | + log.info(String.format(" WcsTask 执行任务! 时间:" + DateUtils.getTimestamp())); |
45 | + LambdaQueryWrapper<TaskHeader> taskHeaderLambdaQueryWrapper = Wrappers.lambdaQuery(); | ||
46 | + taskHeaderLambdaQueryWrapper.eq(TaskHeader::getStatus, QuantityConstant.TASK_STATUS_BUILD).eq(TaskHeader::getAgvTaskId, 0); | ||
47 | + List<TaskHeader> taskHeaderList = taskHeaderService.list(taskHeaderLambdaQueryWrapper); | ||
48 | + for (TaskHeader taskHeader : taskHeaderList) { | ||
49 | + try { | ||
50 | + huahengMultiHandlerService.sendTaskToWcs(taskHeader); | ||
51 | + } catch (Exception e) { | ||
52 | + e.printStackTrace(); | ||
57 | } | 53 | } |
58 | - } catch (Exception e) { | ||
59 | - e.printStackTrace(); | ||
60 | - } finally { | ||
61 | - runningTaskMap.put(taskKey, false); | ||
62 | } | 54 | } |
63 | } | 55 | } |
64 | } | 56 | } |