fix:状态变更添加等待锁
This commit is contained in:
@@ -0,0 +1,46 @@
|
|||||||
|
package org.nl.wms.common.util;
|
||||||
|
|
||||||
|
import lombok.SneakyThrows;
|
||||||
|
import org.nl.exception.BadRequestException;
|
||||||
|
import org.nl.utils.SpringContextHolder;
|
||||||
|
import org.redisson.api.RLock;
|
||||||
|
import org.redisson.api.RedissonClient;
|
||||||
|
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @author ZZQ
|
||||||
|
* @Date 2023/3/27 10:30
|
||||||
|
*/
|
||||||
|
public class RedissonUtils {
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param process 业务代码
|
||||||
|
* @param key
|
||||||
|
* @param seconds 尝试获取锁的等待时间,允许为空
|
||||||
|
*/
|
||||||
|
@SneakyThrows
|
||||||
|
public static void lock(Consumer process, String key, Integer seconds){
|
||||||
|
RedissonClient redissonClient = SpringContextHolder.getBean(RedissonClient.class);
|
||||||
|
RLock lock = redissonClient.getLock(key);
|
||||||
|
boolean isLock;
|
||||||
|
if (seconds == null){
|
||||||
|
isLock = lock.tryLock();
|
||||||
|
}else {
|
||||||
|
isLock = lock.tryLock(seconds, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
if (isLock){
|
||||||
|
process.accept(null);
|
||||||
|
} else {
|
||||||
|
throw new BadRequestException("The current business is being processed key:"+key);
|
||||||
|
}
|
||||||
|
}finally {
|
||||||
|
if (isLock){
|
||||||
|
lock.unlock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ import org.nl.utils.SecurityUtils;
|
|||||||
import org.nl.utils.SpringContextHolder;
|
import org.nl.utils.SpringContextHolder;
|
||||||
import org.nl.wms.basedata.master.constant.MaterOptTypeEnum;
|
import org.nl.wms.basedata.master.constant.MaterOptTypeEnum;
|
||||||
import org.nl.wms.basedata.master.service.MaterialbaseService;
|
import org.nl.wms.basedata.master.service.MaterialbaseService;
|
||||||
|
import org.nl.wms.common.util.RedissonUtils;
|
||||||
import org.nl.wms.pcs.Enum.ProcStatusEnum;
|
import org.nl.wms.pcs.Enum.ProcStatusEnum;
|
||||||
import org.nl.wms.pcs.Enum.ReceiveStatusEnum;
|
import org.nl.wms.pcs.Enum.ReceiveStatusEnum;
|
||||||
import org.nl.wms.ql.Enum.QlBillStatusEnum;
|
import org.nl.wms.ql.Enum.QlBillStatusEnum;
|
||||||
@@ -783,6 +784,13 @@ public class InspectionsheetmstServiceImpl implements InspectionsheetmstService
|
|||||||
* 并按照原单据标识查到到货单并进行汇总实际数量 : 明细表原单据标识 = 到货单明细标识
|
* 并按照原单据标识查到到货单并进行汇总实际数量 : 明细表原单据标识 = 到货单明细标识
|
||||||
*/
|
*/
|
||||||
String inspection_id = jsonWhere.getString("inspection_id");
|
String inspection_id = jsonWhere.getString("inspection_id");
|
||||||
|
RedissonUtils.lock(
|
||||||
|
a->{
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
Long currentUserId = SecurityUtils.getCurrentUserId();
|
Long currentUserId = SecurityUtils.getCurrentUserId();
|
||||||
String nickName = SecurityUtils.getNickName();
|
String nickName = SecurityUtils.getNickName();
|
||||||
String now = DateUtil.now();
|
String now = DateUtil.now();
|
||||||
@@ -887,10 +895,10 @@ public class InspectionsheetmstServiceImpl implements InspectionsheetmstService
|
|||||||
.addParam("material_id", jsonDtl.getString("material_id"))
|
.addParam("material_id", jsonDtl.getString("material_id"))
|
||||||
.addParam("pcsn", jsonDtl.getString("pcsn"))
|
.addParam("pcsn", jsonDtl.getString("pcsn"))
|
||||||
.process().uniqueResult(0);
|
.process().uniqueResult(0);
|
||||||
if(ivt_now != null){
|
if (ivt_now != null) {
|
||||||
double frozen_qty = ivt_now.getDouble("frozen_qty");
|
double frozen_qty = ivt_now.getDouble("frozen_qty");
|
||||||
double warehousing_qty = ivt_now.getDouble("warehousing_qty");
|
double warehousing_qty = ivt_now.getDouble("warehousing_qty");
|
||||||
if(frozen_qty!=0 || warehousing_qty != 0){
|
if (frozen_qty != 0 || warehousing_qty != 0) {
|
||||||
throw new BadRequestException("此批次物料库存冻结数或待入数不为0,有未完成的单据,请稍后再试!");
|
throw new BadRequestException("此批次物料库存冻结数或待入数不为0,有未完成的单据,请稍后再试!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1026,6 +1034,9 @@ public class InspectionsheetmstServiceImpl implements InspectionsheetmstService
|
|||||||
param.put("tableData", ivtArrAll);
|
param.put("tableData", ivtArrAll);
|
||||||
checkOutBillService.insertDtlByJson(param);
|
checkOutBillService.insertDtlByJson(param);
|
||||||
}
|
}
|
||||||
|
},inspection_id,2
|
||||||
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user