fix:全部分配加上并发锁

This commit is contained in:
zhouz
2025-10-27 13:41:26 +08:00
parent b0a3594abc
commit 62dc82d6a2

View File

@@ -3,6 +3,7 @@ package org.nl.wms.st.outbill.rest;
import cn.dev33.satoken.annotation.SaIgnore;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.nl.b_lms.storage_manage.ios.enums.IOSEnum;
import org.nl.b_lms.storage_manage.ios.service.iostorInv.IStIvtIostorinvOutService;
@@ -12,9 +13,12 @@ import org.nl.b_lms.storage_manage.ios.service.iostorInv.util.service.InBussMana
import org.nl.b_lms.storage_manage.ios.service.iostorInv.util.service.LashManageService;
import org.nl.b_lms.storage_manage.ios.service.iostorInv.util.service.OutBoxManageService;
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.st.inbill.service.CheckOutBillService;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
@@ -26,6 +30,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@RestController
@RequiredArgsConstructor
@@ -52,6 +57,9 @@ public class CheckOutBillController {
private final OutBoxManageService outBoxManageService;
@Autowired
private RedissonClient redissonClient;
@GetMapping
@Log("查询出库单")
@@ -114,12 +122,25 @@ public class CheckOutBillController {
@PostMapping("/allDiv")
@Log("出库单全部分配")
@SneakyThrows
public ResponseEntity<Object> allDiv(@RequestBody JSONObject whereJson) {
if (whereJson.getString("stor_id").equals(IOSEnum.STOR_ID.code("二期"))) {
iStIvtIostorinvOutService.allDiv(whereJson);
} else {
checkOutBillService.allDiv(whereJson);
String iostorinv_id = whereJson.getString("iostorinv_id");
RLock lock = redissonClient.getLock("allDiv----"+iostorinv_id);
boolean tryLock = lock.tryLock(0, 60, TimeUnit.SECONDS);
try {
if (tryLock) {
if (whereJson.getString("stor_id").equals(IOSEnum.STOR_ID.code("二期"))) {
iStIvtIostorinvOutService.allDiv(whereJson);
} else {
checkOutBillService.allDiv(whereJson);
}
} else {
throw new BadRequestException("当前出库单当前正在分配库存中,请勿重复操作!");
}
} finally {
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@@ -211,13 +232,13 @@ public class CheckOutBillController {
@Log("一键设置")
public ResponseEntity<Object> allSetPoint(@RequestBody JSONObject whereJson) {
RedissonUtils.lock(c->{
RedissonUtils.lock(c -> {
if (whereJson.getString("stor_id").equals(IOSEnum.STOR_ID.code("二期"))) {
iStIvtIostorinvOutService.allSetPoint2(whereJson);
} else {
checkOutBillService.allSetPointByNoTran(whereJson);
}
},"出库一键设置",1,120,null);
}, "出库一键设置", 1, 120, null);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@@ -375,7 +396,7 @@ public class CheckOutBillController {
@PostMapping("/updataIsOverdue")
@Log("更新是否超期")
public ResponseEntity<Object> updataIsOverdue(@RequestBody JSONObject whereJson) {
return new ResponseEntity<>(checkOutBillService.updataIsOverdue(whereJson),HttpStatus.OK);
return new ResponseEntity<>(checkOutBillService.updataIsOverdue(whereJson), HttpStatus.OK);
}
@PostMapping("/importExcel")