fix:子卷质检加锁,绑定托盘时校验该托盘是否有被绑定过

This commit is contained in:
zhouz
2025-09-17 09:57:24 +08:00
parent 35a8e863fe
commit 4cade7b1ea
2 changed files with 171 additions and 154 deletions

View File

@@ -981,171 +981,184 @@ public class BstIvtPackageinfoivtServiceImpl extends ServiceImpl<BstIvtPackagein
*/
@Override
@Transactional(rollbackFor = Exception.class)
@SneakyThrows
public JSONObject update(JSONObject whereJson) {
JSONObject result = new JSONObject();
if (StringUtils.isBlank(whereJson.getString("ivt_status"))) {
throw new BadRequestException("子卷检验结果为空");
}
//"空","0","空载具","1","有子卷","2","合格品","3","管制品","4",人工卷,"5"
List<BstIvtPackageinfoivt> dtoList;
UpdateWrapper<BstIvtPackageinfoivt> updateWrapper = new UpdateWrapper<>();
//LMS获取MES称重后子卷信息
JSONObject jo = new JSONObject();
RLock lock = redissonClient.getLock("updatePackageInfo------"+whereJson.getString("container_name"));
boolean tryLock = lock.tryLock(0, TimeUnit.SECONDS);
try {
if (tryLock) {
JSONObject result = new JSONObject();
if (StringUtils.isBlank(whereJson.getString("ivt_status"))) {
throw new BadRequestException("子卷检验结果为空");
}
//"空","0","空载具","1","有子卷","2","合格品","3","管制品","4",人工卷,"5"
List<BstIvtPackageinfoivt> dtoList;
UpdateWrapper<BstIvtPackageinfoivt> updateWrapper = new UpdateWrapper<>();
//LMS获取MES称重后子卷信息
JSONObject jo = new JSONObject();
String is_error = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("is_error").getValue();
String point_code = whereJson.getString("pointCode");
if ("1".equals(is_error) && "ZXQ_137,ZXQ_138".contains(point_code) && ObjectUtils.isNotEmpty(point_code)) {
String ivt_status = whereJson.getString("ivt_status");
String container_name = whereJson.getString("container_name");
if (point_code.equals("ZXQ_137")) {
//只能进行绑定空
if (!whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code(""))) {
throw new BadRequestException("该点位只能设置为空!");
}
packageinfoivtService.update(new LambdaUpdateWrapper<BstIvtPackageinfoivt>()
.set(BstIvtPackageinfoivt::getIvt_status, ivt_status)
.eq(BstIvtPackageinfoivt::getPoint_code, point_code));
}
if (point_code.equals("ZXQ_138")) {
//只能进行绑定空
if (!whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("合格品"))) {
throw new BadRequestException("该点位只能绑定合格品!");
}
packageinfoivtService.update(new LambdaUpdateWrapper<BstIvtPackageinfoivt>()
.set(BstIvtPackageinfoivt::getIvt_status, PackageInfoIvtEnum.IVT_STATUS.code("有子卷"))
.set(BstIvtPackageinfoivt::getContainer_name, container_name)
.eq(BstIvtPackageinfoivt::getPoint_code, point_code));
}
} else {
//子卷质检合格品和管制品
if (StringUtils.isNotBlank(whereJson.getString("container_name")) && StringUtils.isBlank(whereJson.getString("pointCode"))) {
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("")) || whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("空载具")) || whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("有子卷"))) {
throw new BadRequestException("质检结果只能为合格品或管制品");
}
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("管制品"))) {
PdmBiSubpackagerelation one = subpackagerelationService.getOne(new QueryWrapper<PdmBiSubpackagerelation>()
.eq("container_name", whereJson.getString("container_name")));
if (one != null) {
throw new BadRequestException("包装关系存在,请先解绑MES及LMS包装关系");
String is_error = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("is_error").getValue();
String point_code = whereJson.getString("pointCode");
if ("1".equals(is_error) && "ZXQ_137,ZXQ_138".contains(point_code) && ObjectUtils.isNotEmpty(point_code)) {
String ivt_status = whereJson.getString("ivt_status");
String container_name = whereJson.getString("container_name");
if (point_code.equals("ZXQ_137")) {
//只能进行绑定空
if (!whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code(""))) {
throw new BadRequestException("该点位只能设置为空!");
}
packageinfoivtService.update(new LambdaUpdateWrapper<BstIvtPackageinfoivt>()
.set(BstIvtPackageinfoivt::getIvt_status, ivt_status)
.eq(BstIvtPackageinfoivt::getPoint_code, point_code));
}
}
dtoList = bstIvtPackageinfoivtMapper.selectList(new LambdaQueryWrapper<BstIvtPackageinfoivt>().eq(BstIvtPackageinfoivt::getContainer_name, whereJson.getString("container_name")));
if (ObjectUtils.isEmpty(dtoList)) {
throw new BadRequestException("子卷号或点位信息有误,请核对是否存在");
}
if (dtoList.size() > 1) {
result.put("status", org.springframework.http.HttpStatus.BAD_REQUEST.value());
result.put("message", "存在多个相同子卷号或点位信息有误,请核对是否存在!");
return result;
}
BstIvtPackageinfoivt packageinfoivt = dtoList.get(0);
if (packageinfoivt.getPoint_status().equals("4")) {
throw new BadRequestException("管制点设置子卷状态时需要选择点位");
}
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("合格品"))) {
if (packageinfoivt.getIvt_status().equals(PackageInfoIvtEnum.IVT_STATUS.code("管制品"))) {
throw new BadRequestException("当前子卷已设置为管制品");
}
//获取子卷最新信息
jo.put("container_name", whereJson.getString("container_name"));
lmsToMesService.getInspectionResult(jo);
//子卷下料信息MES传递给LMS
iPdmBiContainerinfoService.createSubInfoByContainer(whereJson.getString("container_name"));
/*
* 自动打标
*/
// 判断是否自动打标
String auto_table = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("AUTO_PRINT_TABLE").getValue();
if (auto_table.equals(IOSEnum.IS_NOTANDYES.code(""))) {
// 内标默认打印机
String within_table = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("WITHIN_PEINT_TWO").getValue();
JSONObject within_print = WQLObject.getWQLObject("pdm_bi_printinfo")
.query("print_name = '" + within_table + "'")
.uniqueResult(0);
// 管标默认打印机
String pipe_table = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("PIPE_PEINT_TWO").getValue();
JSONObject pipe_print = WQLObject.getWQLObject("pdm_bi_printinfo")
.query("print_name = '" + pipe_table + "'")
.uniqueResult(0);
// 组织数据
JSONObject param = new JSONObject();
param.put("pcsn", whereJson.getString("container_name"));
param.put("print_code", pipe_print.getString("print_id"));
printTableTwoService.pipeTable(param);
param.put("print_code", within_print.getString("print_id"));
printTableTwoService.withinTable(param);
if (point_code.equals("ZXQ_138")) {
//只能进行绑定空
if (!whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("合格品"))) {
throw new BadRequestException("该点位只能绑定合格品");
}
packageinfoivtService.update(new LambdaUpdateWrapper<BstIvtPackageinfoivt>()
.set(BstIvtPackageinfoivt::getIvt_status, PackageInfoIvtEnum.IVT_STATUS.code("有子卷"))
.set(BstIvtPackageinfoivt::getContainer_name, container_name)
.eq(BstIvtPackageinfoivt::getPoint_code, point_code));
}
}
PdmProductSpecServiceImpl.doRecord(SpecEnum.ZJ, MapOf.of("质检结果", whereJson.getString("ivt_status")), Boolean.TRUE, null, packageinfoivt.getContainer_name());
updateWrapper.set("container_name", packageinfoivt.getContainer_name());
updateWrapper.set("ivt_status", whereJson.getString("ivt_status"));
}
//复称
else if (StringUtils.isNotBlank(whereJson.getString("container_name")) && StringUtils.isNotBlank(whereJson.getString("pointCode"))) {
dtoList = bstIvtPackageinfoivtMapper.selectList(new LambdaQueryWrapper<BstIvtPackageinfoivt>().eq(BstIvtPackageinfoivt::getPoint_code, whereJson.getString("pointCode")));
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("合格品"))) {
//获取子卷最新信息
jo.put("container_name", whereJson.getString("container_name"));
lmsToMesService.getInspectionResult(jo);
//子卷下料信息MES传递给LMS
iPdmBiContainerinfoService.createSubInfoByContainer(whereJson.getString("container_name"));
updateWrapper.set("container_name", whereJson.getString("container_name"));
updateWrapper.set("ivt_status", PackageInfoIvtEnum.IVT_STATUS.code("合格品"));
} else {
result.put("status", org.springframework.http.HttpStatus.BAD_REQUEST.value());
result.put("message", "该点位只能放复称的合格品!");
return result;
//子卷质检合格品和管制品
if (StringUtils.isNotBlank(whereJson.getString("container_name")) && StringUtils.isBlank(whereJson.getString("pointCode"))) {
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("")) || whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("空载具")) || whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("有子卷"))) {
throw new BadRequestException("质检结果只能为合格品或管制品");
}
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("管制品"))) {
PdmBiSubpackagerelation one = subpackagerelationService.getOne(new QueryWrapper<PdmBiSubpackagerelation>()
.eq("container_name", whereJson.getString("container_name")));
if (one != null) {
throw new BadRequestException("包装关系存在,请先解绑MES及LMS包装关系");
}
}
dtoList = bstIvtPackageinfoivtMapper.selectList(new LambdaQueryWrapper<BstIvtPackageinfoivt>().eq(BstIvtPackageinfoivt::getContainer_name, whereJson.getString("container_name")));
if (ObjectUtils.isEmpty(dtoList)) {
throw new BadRequestException("子卷号或点位信息有误,请核对是否存在!");
}
if (dtoList.size() > 1) {
result.put("status", org.springframework.http.HttpStatus.BAD_REQUEST.value());
result.put("message", "存在多个相同子卷号或点位信息有误,请核对是否存在!");
return result;
}
BstIvtPackageinfoivt packageinfoivt = dtoList.get(0);
if (packageinfoivt.getPoint_status().equals("4")) {
throw new BadRequestException("管制点设置子卷状态时需要选择点位");
}
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("合格品"))) {
if (packageinfoivt.getIvt_status().equals(PackageInfoIvtEnum.IVT_STATUS.code("管制品"))) {
throw new BadRequestException("当前子卷已设置为管制品");
}
//获取子卷最新信息
jo.put("container_name", whereJson.getString("container_name"));
lmsToMesService.getInspectionResult(jo);
//子卷下料信息MES传递给LMS
iPdmBiContainerinfoService.createSubInfoByContainer(whereJson.getString("container_name"));
/*
* 自动打标
*/
// 判断是否自动打标
String auto_table = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("AUTO_PRINT_TABLE").getValue();
if (auto_table.equals(IOSEnum.IS_NOTANDYES.code(""))) {
// 内标默认打印机
String within_table = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("WITHIN_PEINT_TWO").getValue();
JSONObject within_print = WQLObject.getWQLObject("pdm_bi_printinfo")
.query("print_name = '" + within_table + "'")
.uniqueResult(0);
// 管标默认打印机
String pipe_table = SpringContextHolder.getBean(SysParamServiceImpl.class).findByCode("PIPE_PEINT_TWO").getValue();
JSONObject pipe_print = WQLObject.getWQLObject("pdm_bi_printinfo")
.query("print_name = '" + pipe_table + "'")
.uniqueResult(0);
// 组织数据
JSONObject param = new JSONObject();
param.put("pcsn", whereJson.getString("container_name"));
param.put("print_code", pipe_print.getString("print_id"));
printTableTwoService.pipeTable(param);
param.put("print_code", within_print.getString("print_id"));
printTableTwoService.withinTable(param);
}
}
PdmProductSpecServiceImpl.doRecord(SpecEnum.ZJ, MapOf.of("质检结果", whereJson.getString("ivt_status")), Boolean.TRUE, null, packageinfoivt.getContainer_name());
updateWrapper.set("container_name", packageinfoivt.getContainer_name());
updateWrapper.set("ivt_status", whereJson.getString("ivt_status"));
}
//复称
else if (StringUtils.isNotBlank(whereJson.getString("container_name")) && StringUtils.isNotBlank(whereJson.getString("pointCode"))) {
dtoList = bstIvtPackageinfoivtMapper.selectList(new LambdaQueryWrapper<BstIvtPackageinfoivt>().eq(BstIvtPackageinfoivt::getPoint_code, whereJson.getString("pointCode")));
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("合格品"))) {
//获取子卷最新信息
jo.put("container_name", whereJson.getString("container_name"));
lmsToMesService.getInspectionResult(jo);
//子卷下料信息MES传递给LMS
iPdmBiContainerinfoService.createSubInfoByContainer(whereJson.getString("container_name"));
updateWrapper.set("container_name", whereJson.getString("container_name"));
updateWrapper.set("ivt_status", PackageInfoIvtEnum.IVT_STATUS.code("合格品"));
} else {
result.put("status", org.springframework.http.HttpStatus.BAD_REQUEST.value());
result.put("message", "该点位只能放复称的合格品!");
return result;
}
}
//取放空载具
else if (StringUtils.isNotBlank(whereJson.getString("pointCode")) && StringUtils.isBlank(whereJson.getString("container_name"))) {
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("合格品")) || whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("管制品"))) {
throw new BadRequestException("人工管制点只能设置空载具或空点位");
}
String pointCode = whereJson.getString("pointCode");
if (StringUtils.isEmpty(pointCode)) {
throw new BadRequestException("人工管制点不能为空");
}
JSONObject task = new JSONObject();
task.put("point_code1", pointCode);
int count = taskService.count(new QueryWrapper<SchBaseTask>()
.eq("is_delete", "0")
.eq("point_code1", pointCode)
.lt("task_status", TaskStatusEnum.FINISHED.getCode()));
if (count > 0) {
throw new BadRequestException("当前人工管制点存在任务,稍后操作");
}
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("管制品"))) {
autoSendVehicleToDjq.getPointCode(task, PackageInfoIvtEnum.TASK_TYPE.code("补空(装箱区->待检区)"));
}
dtoList = bstIvtPackageinfoivtMapper.selectList(new LambdaQueryWrapper<BstIvtPackageinfoivt>().eq(BstIvtPackageinfoivt::getPoint_code, whereJson.getString("pointCode")));
updateWrapper.set("container_name", null);
updateWrapper.set("ivt_status", whereJson.getString("ivt_status"));
} else {
result.put("status", org.springframework.http.HttpStatus.BAD_REQUEST.value());
result.put("message", "请输入子卷号或管制点位信息!");
return result;
}
String pointCode = dtoList.get(0).getPoint_code();
if (dtoList.get(0).getPoint_status().equals(PackageInfoIvtEnum.POINT_STATUS.code("满轴缓存位"))) {
throw new BadRequestException("满轴缓存位无法设置子卷状态");
}
List<SchBaseTask> schBaseTasks = taskService.checkHaveTask(pointCode);
if (!CollectionUtils.isEmpty(schBaseTasks)) {
throw new BadRequestException("当前点位" + dtoList.get(0).getPoint_name() + "正在执行搬运任务" + schBaseTasks.stream().map(SchBaseTask::getTask_code).collect(Collectors.joining(",")));
}
updateWrapper.eq("point_code", pointCode);
updateWrapper.set("update_optid", Long.valueOf(SecurityUtils.getCurrentUserId()));
updateWrapper.set("update_optname", SecurityUtils.getCurrentNickName());
updateWrapper.set("update_time", DateUtil.now());
bstIvtPackageinfoivtMapper.update(null, updateWrapper);
}
}
//取放空载具
else if (StringUtils.isNotBlank(whereJson.getString("pointCode")) && StringUtils.isBlank(whereJson.getString("container_name"))) {
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("合格品")) || whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("管制品"))) {
throw new BadRequestException("人工管制点只能设置空载具或空点位");
}
String pointCode = whereJson.getString("pointCode");
if (StringUtils.isEmpty(pointCode)) {
throw new BadRequestException("人工管制点不能为空");
}
JSONObject task = new JSONObject();
task.put("point_code1", pointCode);
int count = taskService.count(new QueryWrapper<SchBaseTask>()
.eq("is_delete", "0")
.eq("point_code1", pointCode)
.lt("task_status", TaskStatusEnum.FINISHED.getCode()));
if (count > 0) {
throw new BadRequestException("当前人工管制点存在任务,稍后操作");
}
if (whereJson.getString("ivt_status").equals(PackageInfoIvtEnum.IVT_STATUS.code("管制品"))) {
autoSendVehicleToDjq.getPointCode(task, PackageInfoIvtEnum.TASK_TYPE.code("补空(装箱区->待检区)"));
}
dtoList = bstIvtPackageinfoivtMapper.selectList(new LambdaQueryWrapper<BstIvtPackageinfoivt>().eq(BstIvtPackageinfoivt::getPoint_code, whereJson.getString("pointCode")));
updateWrapper.set("container_name", null);
updateWrapper.set("ivt_status", whereJson.getString("ivt_status"));
} else {
result.put("status", org.springframework.http.HttpStatus.BAD_REQUEST.value());
result.put("message", "请输入子卷号或管制点位信息!");
result.put("status", org.springframework.http.HttpStatus.OK.value());
result.put("message", "检验成功!");
return result;
} else {
throw new BadRequestException("当前子卷【" + whereJson.getString("container_name") + "】正在质检中请稍后再试!");
}
String pointCode = dtoList.get(0).getPoint_code();
if (dtoList.get(0).getPoint_status().equals(PackageInfoIvtEnum.POINT_STATUS.code("满轴缓存位"))) {
throw new BadRequestException("满轴缓存位无法设置子卷状态");
} finally {
if (lock.isLocked() && lock.isHeldByCurrentThread()) {
lock.unlock();
}
List<SchBaseTask> schBaseTasks = taskService.checkHaveTask(pointCode);
if (!CollectionUtils.isEmpty(schBaseTasks)) {
throw new BadRequestException("当前点位" + dtoList.get(0).getPoint_name() + "正在执行搬运任务" + schBaseTasks.stream().map(SchBaseTask::getTask_code).collect(Collectors.joining(",")));
}
updateWrapper.eq("point_code", pointCode);
updateWrapper.set("update_optid", Long.valueOf(SecurityUtils.getCurrentUserId()));
updateWrapper.set("update_optname", SecurityUtils.getCurrentNickName());
updateWrapper.set("update_time", DateUtil.now());
bstIvtPackageinfoivtMapper.update(null, updateWrapper);
}
result.put("status", org.springframework.http.HttpStatus.OK.value());
result.put("message", "检验成功!");
return result;
}
/**

View File

@@ -132,6 +132,10 @@ public class InBoxManageServiceImpl implements InBoxManageService {
if (StrUtil.isEmpty(qty) || Double.parseDouble(qty) <= 0){
throw new BadRequestException("托盘【"+whereJson.getString("vehicle_code")+"】在系统的重量有误,请在载具维护页面中维护托盘实际重量!");
}
String pcsn = vehicle_ext.getString("pcsn");
if (ObjectUtil.isNotEmpty(pcsn)){
throw new BadRequestException("托盘【"+whereJson.getString("vehicle_code")+"】已经绑定了木箱【"+pcsn+"】,请进行核实!");
}
}
//查询仓库是否存在相同木箱