rev:添加锁:保障wms申请任务时只有一个
This commit is contained in:
@@ -11,8 +11,10 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.nl.acs.ext.wms.data.CancelTaskRequest;
|
||||
import org.nl.acs.ext.wms.data.CreateTaskRequest;
|
||||
import org.nl.acs.ext.wms.data.CreateTaskResponse;
|
||||
import org.nl.acs.ext.wms.service.WmsToAcsService;
|
||||
//import org.nl.modules.logging.InterfaceLogType;
|
||||
import org.nl.common.exception.BadRequestException;
|
||||
import org.nl.common.logging.annotation.Log;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -22,6 +24,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
/**
|
||||
* @author ludj
|
||||
@@ -34,13 +38,29 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class WmsToAcsController {
|
||||
private final WmsToAcsService wmstoacsService;
|
||||
private ReentrantLock lock = new ReentrantLock();
|
||||
|
||||
@PostMapping("/task")
|
||||
@Log(value = "ACS接收WMS任务")
|
||||
@ApiOperation("接收WMS任务")
|
||||
@SaIgnore
|
||||
public ResponseEntity<Object> createFromWms(@RequestBody List<CreateTaskRequest> reqs) {
|
||||
return new ResponseEntity<>(wmstoacsService.crateTask(reqs), HttpStatus.OK);
|
||||
CreateTaskResponse response = new CreateTaskResponse();
|
||||
try {
|
||||
if (lock.tryLock() || lock.tryLock(2, TimeUnit.SECONDS)){
|
||||
response = wmstoacsService.crateTask(reqs);
|
||||
Thread.sleep(50000);
|
||||
}else {
|
||||
throw new BadRequestException("当前acs正在执行创建任务稍后再试");
|
||||
}
|
||||
}catch (Exception ex){
|
||||
throw new BadRequestException("当前acs正在执行创建任务稍后再试");
|
||||
}finally {
|
||||
if (lock.isHeldByCurrentThread() && lock.isLocked()){
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
return new ResponseEntity<>(response, HttpStatus.OK);
|
||||
}
|
||||
|
||||
@PostMapping("/cancelTask")
|
||||
|
||||
Reference in New Issue
Block a user