fix: 锁细粒度扩大

This commit is contained in:
2025-08-07 19:58:32 +08:00
parent 746833151f
commit 661595c790

View File

@@ -285,12 +285,17 @@ public class SlitterServiceImpl implements SlitterService {
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public JSONObject acsFinishLoadShaft(JSONObject param) { public JSONObject acsFinishLoadShaft(JSONObject param) {
log.info("ACS申请套管完成参数: {}", param);
String msg = ""; String msg = "";
JSONObject res = new JSONObject(); JSONObject res = new JSONObject();
// 穿拔轴位 // 穿拔轴位
String deviceCode = param.getString("device_code"); String deviceCode = param.getString("device_code");
List<String> stepTipLogs = getRedisListValue("ERROR" + deviceCode); List<String> stepTipLogs = getRedisListValue("ERROR" + deviceCode);
// 枷锁
RLock lock = redissonClient.getLock("doAcsFinishLoadShaft");
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
try {
if (tryLock) {
log.info("ACS申请套管完成参数: {}", param);
// 纸管 // 纸管
String weight1 = param.getString("weight1"); String weight1 = param.getString("weight1");
String material1 = param.getString("material1"); String material1 = param.getString("material1");
@@ -329,12 +334,6 @@ public class SlitterServiceImpl implements SlitterService {
List<BstIvtCutpointivt> exceptionPoints = bcutpointivtService.getAreaNotTaskPointByStatus("1", "1", "0", "0"); List<BstIvtCutpointivt> exceptionPoints = bcutpointivtService.getAreaNotTaskPointByStatus("1", "1", "0", "0");
if (exceptionPoints.size() > 0) { if (exceptionPoints.size() > 0) {
BstIvtCutpointivt exceptionPoint = exceptionPoints.get(0); BstIvtCutpointivt exceptionPoint = exceptionPoints.get(0);
// 枷锁
RLock lockPointR = redissonClient.getLock(exceptionPoint.getPoint_code());
boolean tryLockPointR = lockPointR.tryLock(0, TimeUnit.SECONDS);
try {
if (tryLockPointR) {
// 需要枷锁
JSONObject exParam = new JSONObject(); JSONObject exParam = new JSONObject();
exParam.put("point_code1", startPoint.getPoint_code()); exParam.put("point_code1", startPoint.getPoint_code());
exParam.put("point_code2", ObjectUtil.isEmpty(exceptionPoint.getQzz_no1()) exParam.put("point_code2", ObjectUtil.isEmpty(exceptionPoint.getQzz_no1())
@@ -351,14 +350,6 @@ public class SlitterServiceImpl implements SlitterService {
res.put("status", HttpStatus.HTTP_OK); res.put("status", HttpStatus.HTTP_OK);
res.put("message", "创建送至异常处理位!"); res.put("message", "创建送至异常处理位!");
return res; return res;
} else {
throw new BadRequestException("系统繁忙,稍后在试!");
}
} finally {
if (tryLockPointR) {
lockPointR.unlock();
}
}
} else { } else {
stepTipLogs.add("套轴完成->[" + collect + "]对应的分切计划状态已更改,无暂存位置,创建任务失败!"); stepTipLogs.add("套轴完成->[" + collect + "]对应的分切计划状态已更改,无暂存位置,创建任务失败!");
redisUtils.set("ERROR" + deviceCode, stepTipLogs); redisUtils.set("ERROR" + deviceCode, stepTipLogs);
@@ -375,7 +366,6 @@ public class SlitterServiceImpl implements SlitterService {
res.put("message", "请求成功"); res.put("message", "请求成功");
res.put("msg", msg); res.put("msg", msg);
return res; return res;
// throw new BadRequestException("[" + collect + "]对应的分切计划状态已更改,无暂存位置!");
} }
} }
// 分切计划设置纸卷重量 // 分切计划设置纸卷重量
@@ -442,11 +432,6 @@ public class SlitterServiceImpl implements SlitterService {
} }
} }
if (ObjectUtil.isNotEmpty(cutPoint)) { if (ObjectUtil.isNotEmpty(cutPoint)) {
// 枷锁
RLock lockPoint = redissonClient.getLock(cutPoint.getPoint_code());
boolean tryLockPoint = lockPoint.tryLock(0, TimeUnit.SECONDS);
try {
if (tryLockPoint) {
// 创建任务 // 创建任务
JSONObject taskParam = new JSONObject(); JSONObject taskParam = new JSONObject();
taskParam.put("point_code1", startPoint.getPoint_code()); taskParam.put("point_code1", startPoint.getPoint_code());
@@ -458,18 +443,17 @@ public class SlitterServiceImpl implements SlitterService {
taskParam.put("product_area", SlitterConstant.SLITTER_TASK_AREA); taskParam.put("product_area", SlitterConstant.SLITTER_TASK_AREA);
taskParam.put("immediateNotifyAcs", "1"); taskParam.put("immediateNotifyAcs", "1");
trussSendAirShaftTask.createTask(taskParam); trussSendAirShaftTask.createTask(taskParam);
}
} else { } else {
stepTipLogs.add("套轴完成->系统繁忙,稍后在试!"); stepTipLogs.add("套轴完成->系统繁忙,稍后在试!");
redisUtils.set("ERROR" + deviceCode, stepTipLogs); redisUtils.set("ERROR" + deviceCode, stepTipLogs);
throw new BadRequestException("系统繁忙,稍后在试!"); throw new BadRequestException("系统繁忙,稍后在试!");
} }
} finally { } finally {
if (tryLockPoint) { if (tryLock) {
lockPoint.unlock(); lock.unlock();
} }
} }
}
res.put("status", HttpStatus.HTTP_OK); res.put("status", HttpStatus.HTTP_OK);
res.put("message", "请求成功"); res.put("message", "请求成功");
res.put("msg", msg); res.put("msg", msg);