fix:装箱入库与入库完成并发控制
This commit is contained in:
@@ -15,9 +15,11 @@ import org.nl.b_lms.sch.tasks.first_floor_area.auto.Prun;
|
||||
import org.nl.common.TableDataInfo;
|
||||
import org.nl.common.domain.query.PageQuery;
|
||||
import org.nl.common.enums.PackageInfoIvtEnum;
|
||||
import org.nl.common.utils.RedissonUtils;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.logging.annotation.Log;
|
||||
import org.nl.modules.wql.util.SpringContextHolder;
|
||||
import org.nl.wms.sch.manage.TaskStatusEnum;
|
||||
import org.redisson.api.RLock;
|
||||
import org.redisson.api.RedissonClient;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -171,22 +173,9 @@ public class PdmBiSubpackagerelationController {
|
||||
@Log("子卷装箱入库")
|
||||
//@SaCheckPermission("@el.check(updateEntityList)")
|
||||
public ResponseEntity<Object> zjInBoundConfirm(@RequestBody JSONObject whereJson) {
|
||||
RLock lock = redissonClient.getLock("zjInBound");
|
||||
boolean tryLock = false;
|
||||
try {
|
||||
tryLock = lock.tryLock(0, TimeUnit.SECONDS);
|
||||
if (tryLock) {
|
||||
pdmBiSubpackagerelationService.zjInBoundConfirm(whereJson);
|
||||
} else {
|
||||
log.info("子卷装箱入库操作正在执行被锁住。");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
RedissonUtils.lock(c->{
|
||||
pdmBiSubpackagerelationService.zjInBoundConfirm(whereJson);
|
||||
},"zjInBound",0,this,"装箱入库在操作,稍后再试");
|
||||
return new ResponseEntity<>(TableDataInfo.build(),HttpStatus.OK);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.nl.b_lms.storage_manage.database.service.dao.BstIvtBoxinfo;
|
||||
import org.nl.b_lms.storage_manage.ios.enums.IOSEnum;
|
||||
import org.nl.b_lms.storage_manage.ios.service.iostorInv.util.service.OutBoxManageService;
|
||||
import org.nl.common.enums.PackageInfoIvtEnum;
|
||||
import org.nl.common.utils.RedissonUtils;
|
||||
import org.nl.common.utils.SecurityUtils;
|
||||
import org.nl.modules.common.exception.BadRequestException;
|
||||
import org.nl.modules.wql.core.bean.WQLObject;
|
||||
@@ -209,11 +210,11 @@ public class TwoOutBoxTask extends AbstractAcsTask {
|
||||
map.put("update_optname", SecurityUtils.getCurrentNickName());
|
||||
map.put("update_time", DateUtil.now());
|
||||
WQLObject.getWQLObject("SCH_BASE_Task").update(map, "task_id = '" + taskObj.getString("task_id") + "'");
|
||||
|
||||
// 如果是完成则在下发一次
|
||||
if (status.equals(TaskStatusEnum.FINISHED.getCode())) {
|
||||
immediateNotifyAcs(null);
|
||||
}
|
||||
RedissonUtils.lock(c->{
|
||||
if (status.equals(TaskStatusEnum.FINISHED.getCode())) {
|
||||
immediateNotifyAcs(null);
|
||||
}
|
||||
},"zjInBound",10,this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -72,4 +72,25 @@ public class RedissonUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
@SneakyThrows
|
||||
public static void lock(Consumer process, String key, int secend, Object param,String throwinfo){
|
||||
RedissonClient redissonClient = SpringContextHolder.getBean(RedissonClient.class);
|
||||
RLock lock = redissonClient.getLock(key);
|
||||
boolean isLock;
|
||||
isLock = lock.tryLock(secend,secend+5,TimeUnit.SECONDS);
|
||||
try {
|
||||
if (isLock){
|
||||
process.accept(param);
|
||||
} else {
|
||||
throw new BadRequestException(throwinfo);
|
||||
}
|
||||
}catch (Exception ex){
|
||||
ex.printStackTrace();
|
||||
throw ex;
|
||||
}finally {
|
||||
if (isLock && lock.isHeldByCurrentThread()){
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user