TaskFinishController.java
3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.huaheng.api.wcs.controller;
import com.huaheng.api.wcs.domain.TaskFinishDomain;
import com.huaheng.api.wcs.domain.WcsTask;
import com.huaheng.api.wcs.service.taskFinish.TaskFinishService;
import com.huaheng.common.support.Convert;
import static com.huaheng.pc.receipt.receiptHeader.controller.ReceiptHeaderController .PassbackMap;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections.MapUtils;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.time.LocalTime;
/**任务完成
* wcs向wms传递数据
* @author ricard
* @date 2019/10/11
*
*/
@RestController
@RequestMapping("/API/WMS/v2")
public class TaskFinishController extends BaseController {
@Resource
private TaskFinishService taskFinishService;
@Log(title = "wcs任务完成", action = BusinessType.INSERT)
@PostMapping("/complete")
@ApiOperation("wcs任务完成")
@ApiLogger(apiName = "wcs任务完成", from="WCS")
@ResponseBody
@Cacheable(cacheNames = "complete#10", key = "#taskFinishDomain.taskNo",unless = "#result == null ")
public AjaxResult complete(@RequestBody TaskFinishDomain taskFinishDomain) {
// 检查是否在受限时间段内
if (isInRestrictedTime()) {
return AjaxResult.error("不能在单据回传时间内完成任务");
}
String taskKey = "PassBackMap";
if (MapUtils.getBoolean(PassbackMap, taskKey, false)) {
return AjaxResult.error("不能同时访问");
}
PassbackMap.put(taskKey, true);
AjaxResult ajaxResult = handleMultiProcess("complete",new MultiProcessListener() {
@Override
public AjaxResult doProcess() {
try {
AjaxResult ajaxResult = taskFinishService.completeTaskByWCS(taskFinishDomain);
return ajaxResult;
} catch (Exception e) {
return AjaxResult.error(e.getMessage());
} finally {
PassbackMap.put(taskKey, false);
}
}
});
return ajaxResult;
}
/**
* 检查当前时间是否在受限时间段内
* 受限时间段:
* 1. 每天8:59:30 至 9:01:00
* 2. 每天12:59:30 至 13:01:00
*/
private boolean isInRestrictedTime() {
LocalTime now = LocalTime.now();
// 第一个限制时间段:8:59:30 到 9:01:00
LocalTime firstStart = LocalTime.of(8, 59, 30);
LocalTime firstEnd = LocalTime.of(9, 1, 0);
// 第二个限制时间段:12:59:30 到 13:01:00
LocalTime secondStart = LocalTime.of(12, 59, 30);
LocalTime secondEnd = LocalTime.of(13, 1, 0);
// 检查当前时间是否在任意一个限制时间段内
boolean inFirstPeriod = now.isAfter(firstStart) && now.isBefore(firstEnd);
boolean inSecondPeriod = now.isAfter(secondStart) && now.isBefore(secondEnd);
return inFirstPeriod || inSecondPeriod;
}
}