From e1801ce0013e2831e9598ca070052fa9e43ab439 Mon Sep 17 00:00:00 2001 From: liuxy Date: Wed, 21 Aug 2024 17:30:05 +0800 Subject: [PATCH] =?UTF-8?q?rev=EF=BC=9A=E5=85=A5=E5=BA=93=E5=8D=95?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=BA=BA=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/StIvtIostorinvServiceImpl.java | 324 ++++++++++-------- .../util/impl/InBoxManageServiceImpl.java | 13 +- .../acs/service/impl/AcsToWmsServiceImpl.java | 6 + 3 files changed, 199 insertions(+), 144 deletions(-) diff --git a/lms/nladmin-system/src/main/java/org/nl/b_lms/storage_manage/ios/service/iostorInv/impl/StIvtIostorinvServiceImpl.java b/lms/nladmin-system/src/main/java/org/nl/b_lms/storage_manage/ios/service/iostorInv/impl/StIvtIostorinvServiceImpl.java index 4b348944f..4eff639dc 100644 --- a/lms/nladmin-system/src/main/java/org/nl/b_lms/storage_manage/ios/service/iostorInv/impl/StIvtIostorinvServiceImpl.java +++ b/lms/nladmin-system/src/main/java/org/nl/b_lms/storage_manage/ios/service/iostorInv/impl/StIvtIostorinvServiceImpl.java @@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; +import lombok.SneakyThrows; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.nl.b_lms.pdm.bi.slittingproductionplan.service.IPdmBiSlittingproductionplanService; @@ -52,6 +53,8 @@ import org.nl.wms.sch.service.dto.PointDto; import org.nl.wms.sch.tasks.InTask; import org.nl.wms.st.inbill.service.StorPublicService; import org.nl.wms.st.returns.service.impl.InAndOutRetrunServiceImpl; +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; @@ -61,6 +64,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.math.BigDecimal; import java.util.*; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; /** @@ -123,6 +127,8 @@ public class StIvtIostorinvServiceImpl extends ServiceImpl JSONObject - JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(whereJson)); - // 分配明细集合 - ArrayList list = (ArrayList) whereJson.get("tableMater"); - // 类型转换:linkenHashMap -> JSONObject - JSONObject jsonDis = list.stream() - .map(row -> JSONObject.parseObject(JSON.toJSONString(row))) - .collect(Collectors.toList()).get(0); - // 判断当前木箱是否已经分配过货位 - StIvtIostorinvdis disDao = iStIvtIostorinvdisService.getById(jsonDis.getString("iostorinvdis_id")); - if (ObjectUtil.isNotEmpty(disDao.getStruct_id())) { - throw new BadRequestException("该木箱已经分配过货位,无法继续分配!"); - } - // 主表实体类 - StIvtIostorinv mstDao = this.getById(disDao.getIostorinv_id()); - // 用于锁定货位 - JSONObject jsonLock = new JSONObject(); - ArrayList paramLockList = new ArrayList<>(); - // 仓位对象 - JSONObject jsonAttr; - // 是否自动分配货位 - Boolean checked = jsonObject.getBoolean("checked"); - String height = ""; - if (ObjectUtil.isNotEmpty(checked) && checked) { - // 自动分配: 根据仓库、库区匹配一个合适的仓位 - JSONObject attrParam = new JSONObject(); - attrParam.put("stor_id", jsonObject.getString("stor_id")); - attrParam.put("sect_id", jsonObject.getString("sect_id")); - attrParam.put("material_id", disDao.getMaterial_id()); - attrParam.put("box_no", disDao.getBox_no()); - BstIvtBoxinfo boxDao = getBstIvtBoxinfo(whereJson); - if (boxDao == null) { - throw new BadRequestException("未找到该木箱信息!"); - } - jsonObject.put("box_no",boxDao.getBox_no()); - jsonObject.put("vehicle_type",boxDao.getVehicle_type()); - attrParam.put("vehicle_type", boxDao.getVehicle_type()); - //根据木箱高度,判断入库仓位的高度 - String heightLevel1 = iSysParamService.findByCode("height_level_1").getValue(); - String heightLevel2 = iSysParamService.findByCode("height_level_2").getValue(); - String box_high = boxDao.getBox_high(); - if (Integer.parseInt(box_high) <= Integer.parseInt(heightLevel1)) { - height = "('1','2','3')"; - } else if (Integer.parseInt(box_high) > Integer.parseInt(heightLevel1) && Integer.parseInt(box_high) <= Integer.parseInt(heightLevel2)) { - height = "('2','3')"; - } else { - height = "('3')"; - } - attrParam.put("height", height); - JSONObject jsonSect = sectTab.query("sect_id = '" + jsonObject.getString("sect_id") + "'").uniqueResult(0); - // 判断是否是虚拟区 - if (jsonSect.getString("sect_type_attr").equals(IOSEnum.SECT_TYPE.code("虚拟区"))) { - jsonAttr = attrTab.query("sect_id = '" + jsonObject.getString("sect_id") + "' AND lock_type = '1' AND is_delete = '0' AND IFNULL( storagevehicle_code, '' ) = ''").uniqueResult(0); - } else { - jsonAttr = inBussManageService.getOneStruct(attrParam); - } - } else { - // 指定分配 - jsonAttr = attrTab.query("struct_id = '" + jsonDis.getString("struct_id") + "'").uniqueResult(0); - } - if (ObjectUtil.isEmpty(jsonAttr)) { - throw new BadRequestException("没有可用仓位!"); - } - // 调用业务处理类锁定货位 - paramLockList.add(jsonAttr.getString("struct_code")); - jsonLock.put("inv_type", mstDao.getBill_type()); - jsonLock.put("inv_id", mstDao.getIostorinv_id()); - jsonLock.put("inv_code", mstDao.getBill_code()); - jsonLock.put("lock_type", IOSEnum.LOCK_TYPE.code("入库锁")); - jsonLock.put("operate", IOSEnum.IO_TYPE.code("入库")); - inBussManageService.lockStruct(paramLockList, jsonLock); - // 判断是否虚拟区 - String work_status; - Long task_id = null; - JSONObject jsonSect = sectTab.query("sect_id = '" + jsonAttr.getString("sect_id") + "'").uniqueResult(0); - if (jsonSect.getString("sect_type_attr").equals(IOSEnum.SECT_TYPE.code("虚拟区"))) { - // 虚拟区:执行状态为完成 - work_status = IOSEnum.WORK_STATUS.code("完成"); - task_id = IdUtil.getLongId(); - } else { - work_status = IOSEnum.WORK_STATUS.code("未生成"); - } - // 更新分配明细 - iStIvtIostorinvdisService.update( - new UpdateWrapper().lambda() - .set(StIvtIostorinvdis::getStruct_id, jsonAttr.getString("struct_id")) - .set(StIvtIostorinvdis::getStruct_code, jsonAttr.getString("struct_code")) - .set(StIvtIostorinvdis::getStruct_name, jsonAttr.getString("struct_name")) - .set(StIvtIostorinvdis::getSect_id, jsonAttr.getString("sect_id")) - .set(StIvtIostorinvdis::getSect_code, jsonAttr.getString("sect_code")) - .set(StIvtIostorinvdis::getSect_name, jsonAttr.getString("sect_name")) - .set(StIvtIostorinvdis::getWork_status, work_status) - .set(StIvtIostorinvdis::getTask_id, task_id) - .eq(StIvtIostorinvdis::getIostorinv_id, disDao.getIostorinv_id()) - .eq(StIvtIostorinvdis::getBox_no, disDao.getBox_no()) - ); - // 更新库存 - List disDaoList = iStIvtIostorinvdisService.list( - new QueryWrapper().lambda() - .eq(StIvtIostorinvdis::getIostorinv_id, disDao.getIostorinv_id()) - .eq(StIvtIostorinvdis::getBox_no, disDao.getBox_no()) - ); - upateIvt(disDaoList, mstDao, IOSEnum.IVT_CHANGE.code("加待入")); - // 更新明细状态 - iStIvtIostorinvdtlService.updateStatus(disDao.getIostorinvdtl_id()); - // 更新主表状态 - StIvtIostorinv mst = updateMstStatus(disDao.getIostorinv_id()); - mst.setDis_optid(Long.parseLong(SecurityUtils.getCurrentUserId())); - mst.setDis_optname(SecurityUtils.getCurrentNickName()); - mst.setDis_time(DateUtil.now()); - this.updateById(mst); - // 判断是否自动下发任务 - if (jsonObject.getString("is_send").equals(IOSEnum.IS_NOTANDYES.code("是")) && ObjectUtil.isNotEmpty(jsonObject.getString("is_send"))) { - JSONObject jsonSend = new JSONObject(); - StIvtIostorinvdtl dtlDao = iStIvtIostorinvdtlService.list( - new QueryWrapper().lambda() - .eq(StIvtIostorinvdtl::getIostorinv_id, mst.getIostorinv_id()) - ).get(0); - List disList = iStIvtIostorinvdisService.list( + RLock lock = redissonClient.getLock(StIvtIostorinvServiceImpl.class.getName()); + boolean tryLock = lock.tryLock(5, TimeUnit.SECONDS); + try { + if (tryLock) { + // 仓位表 + WQLObject attrTab = WQLObject.getWQLObject("st_ivt_structattr"); + // 库区表 + WQLObject sectTab = WQLObject.getWQLObject("st_ivt_sectattr"); + // 参数类型转换 Map-> JSONObject + JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(whereJson)); + // 分配明细集合 + ArrayList list = (ArrayList) whereJson.get("tableMater"); + // 类型转换:linkenHashMap -> JSONObject + JSONObject jsonDis = list.stream() + .map(row -> JSONObject.parseObject(JSON.toJSONString(row))) + .collect(Collectors.toList()).get(0); + // 判断当前木箱是否已经分配过货位 + StIvtIostorinvdis disDao = iStIvtIostorinvdisService.getById(jsonDis.getString("iostorinvdis_id")); + if (ObjectUtil.isNotEmpty(disDao.getStruct_id())) { + throw new BadRequestException("该木箱已经分配过货位,无法继续分配!"); + } + // 主表实体类 + StIvtIostorinv mstDao = this.getById(disDao.getIostorinv_id()); + // 用于锁定货位 + JSONObject jsonLock = new JSONObject(); + ArrayList paramLockList = new ArrayList<>(); + // 仓位对象 + JSONObject jsonAttr; + // 是否自动分配货位 + Boolean checked = jsonObject.getBoolean("checked"); + String height = ""; + if (ObjectUtil.isNotEmpty(checked) && checked) { + // 自动分配: 根据仓库、库区匹配一个合适的仓位 + JSONObject attrParam = new JSONObject(); + attrParam.put("stor_id", jsonObject.getString("stor_id")); + attrParam.put("sect_id", jsonObject.getString("sect_id")); + attrParam.put("material_id", disDao.getMaterial_id()); + attrParam.put("box_no", disDao.getBox_no()); + BstIvtBoxinfo boxDao = getBstIvtBoxinfo(whereJson); + if (boxDao == null) { + throw new BadRequestException("未找到该木箱信息!"); + } + jsonObject.put("box_no",boxDao.getBox_no()); + jsonObject.put("vehicle_type",boxDao.getVehicle_type()); + attrParam.put("vehicle_type", boxDao.getVehicle_type()); + //根据木箱高度,判断入库仓位的高度 + String heightLevel1 = iSysParamService.findByCode("height_level_1").getValue(); + String heightLevel2 = iSysParamService.findByCode("height_level_2").getValue(); + String box_high = boxDao.getBox_high(); + if (Integer.parseInt(box_high) <= Integer.parseInt(heightLevel1)) { + height = "('1','2','3')"; + } else if (Integer.parseInt(box_high) > Integer.parseInt(heightLevel1) && Integer.parseInt(box_high) <= Integer.parseInt(heightLevel2)) { + height = "('2','3')"; + } else { + height = "('3')"; + } + attrParam.put("height", height); + JSONObject jsonSect = sectTab.query("sect_id = '" + jsonObject.getString("sect_id") + "'").uniqueResult(0); + // 判断是否是虚拟区 + if (jsonSect.getString("sect_type_attr").equals(IOSEnum.SECT_TYPE.code("虚拟区"))) { + jsonAttr = attrTab.query("sect_id = '" + jsonObject.getString("sect_id") + "' AND lock_type = '1' AND is_delete = '0' AND IFNULL( storagevehicle_code, '' ) = ''").uniqueResult(0); + } else { + jsonAttr = inBussManageService.getOneStruct(attrParam); + } + } else { + // 指定分配 + jsonAttr = attrTab.query("struct_id = '" + jsonDis.getString("struct_id") + "'").uniqueResult(0); + } + if (ObjectUtil.isEmpty(jsonAttr)) { + throw new BadRequestException("没有可用仓位!"); + } + // 调用业务处理类锁定货位 + paramLockList.add(jsonAttr.getString("struct_code")); + jsonLock.put("inv_type", mstDao.getBill_type()); + jsonLock.put("inv_id", mstDao.getIostorinv_id()); + jsonLock.put("inv_code", mstDao.getBill_code()); + jsonLock.put("lock_type", IOSEnum.LOCK_TYPE.code("入库锁")); + jsonLock.put("operate", IOSEnum.IO_TYPE.code("入库")); + inBussManageService.lockStruct(paramLockList, jsonLock); + // 判断是否虚拟区 + String work_status; + Long task_id = null; + JSONObject jsonSect = sectTab.query("sect_id = '" + jsonAttr.getString("sect_id") + "'").uniqueResult(0); + if (jsonSect.getString("sect_type_attr").equals(IOSEnum.SECT_TYPE.code("虚拟区"))) { + // 虚拟区:执行状态为完成 + work_status = IOSEnum.WORK_STATUS.code("完成"); + task_id = IdUtil.getLongId(); + } else { + work_status = IOSEnum.WORK_STATUS.code("未生成"); + } + // 更新分配明细 + iStIvtIostorinvdisService.update( + new UpdateWrapper().lambda() + .set(StIvtIostorinvdis::getStruct_id, jsonAttr.getString("struct_id")) + .set(StIvtIostorinvdis::getStruct_code, jsonAttr.getString("struct_code")) + .set(StIvtIostorinvdis::getStruct_name, jsonAttr.getString("struct_name")) + .set(StIvtIostorinvdis::getSect_id, jsonAttr.getString("sect_id")) + .set(StIvtIostorinvdis::getSect_code, jsonAttr.getString("sect_code")) + .set(StIvtIostorinvdis::getSect_name, jsonAttr.getString("sect_name")) + .set(StIvtIostorinvdis::getWork_status, work_status) + .set(StIvtIostorinvdis::getTask_id, task_id) + .eq(StIvtIostorinvdis::getIostorinv_id, disDao.getIostorinv_id()) + .eq(StIvtIostorinvdis::getBox_no, disDao.getBox_no()) + ); + // 更新库存 + List disDaoList = iStIvtIostorinvdisService.list( + new QueryWrapper().lambda() + .eq(StIvtIostorinvdis::getIostorinv_id, disDao.getIostorinv_id()) + .eq(StIvtIostorinvdis::getBox_no, disDao.getBox_no()) + ); + upateIvt(disDaoList, mstDao, IOSEnum.IVT_CHANGE.code("加待入")); + // 更新明细状态 + iStIvtIostorinvdtlService.updateStatus(disDao.getIostorinvdtl_id()); + // 更新主表状态 + StIvtIostorinv mst = updateMstStatus(disDao.getIostorinv_id()); + mst.setDis_optid(Long.parseLong(SecurityUtils.getCurrentUserId())); + mst.setDis_optname(SecurityUtils.getCurrentNickName()); + mst.setDis_time(DateUtil.now()); + this.updateById(mst); + // 判断是否自动下发任务 + if (jsonObject.getString("is_send").equals(IOSEnum.IS_NOTANDYES.code("是")) && ObjectUtil.isNotEmpty(jsonObject.getString("is_send"))) { + JSONObject jsonSend = new JSONObject(); + StIvtIostorinvdtl dtlDao = iStIvtIostorinvdtlService.list( + new QueryWrapper().lambda() + .eq(StIvtIostorinvdtl::getIostorinv_id, mst.getIostorinv_id()) + ).get(0); + List disList = iStIvtIostorinvdisService.list( new QueryWrapper().lambda() .eq(StIvtIostorinvdis::getIostorinv_id, mst.getIostorinv_id()) ).stream().map(row -> JSONObject.parseObject(JSON.toJSONString(row), LinkedHashMap.class)) - .collect(Collectors.toList()); - jsonSend.put("dtl_row", JSONObject.parseObject(JSON.toJSONString(dtlDao))); - jsonSend.put("tableMater", disList); - jsonSend.put("point_code", jsonObject.getString("point_code")); - jsonSend.put("stor_id", mst.getStor_id()); - //成品入库托盘类型 - jsonSend.put("vehicle_code", jsonObject.getString("box_no")); - jsonSend.put("vehicle_code2", jsonObject.getString("vehicle_code")); - JSONObject param = new JSONObject(); - param.put("containerType", jsonObject.getString("vehicle_type")); - param.put("heightLevel", height); - jsonSend.put("request_param", param.toString()); - String task_id1 = this.setPoint(jsonSend); - // 下发任务 - JSONObject sendJson = new JSONObject(); - sendJson.put("task_id", task_id1); - this.reIssueTask(sendJson); + .collect(Collectors.toList()); + jsonSend.put("dtl_row", JSONObject.parseObject(JSON.toJSONString(dtlDao))); + jsonSend.put("tableMater", disList); + jsonSend.put("point_code", jsonObject.getString("point_code")); + jsonSend.put("stor_id", mst.getStor_id()); + //成品入库托盘类型 + jsonSend.put("vehicle_code", jsonObject.getString("box_no")); + jsonSend.put("vehicle_code2", jsonObject.getString("vehicle_code")); + JSONObject param = new JSONObject(); + param.put("containerType", jsonObject.getString("vehicle_type")); + param.put("heightLevel", height); + jsonSend.put("request_param", param.toString()); + String task_id1 = this.setPoint(jsonSend); + // 下发任务 + JSONObject sendJson = new JSONObject(); + sendJson.put("task_id", task_id1); + this.reIssueTask(sendJson); + } + } else { + throw new BadRequestException("有入库单据正在分配中,请稍后在试"); + } + } finally { + if (tryLock) { + lock.unlock(); + } } } @@ -648,6 +667,20 @@ public class StIvtIostorinvServiceImpl extends ServiceImpl list = (ArrayList) whereJson.get("tableData"); + + List rows = list.stream() + .map(row -> JSONObject.parseObject(JSON.toJSONString(row))) + .collect(Collectors.toList()); + if (ObjectUtil.isEmpty(rows)) { + throw new BadRequestException("出入库明细不能为空!"); + } + + JSONObject jsonSub = WQLObject.getWQLObject("pdm_bi_subpackagerelation") + .query("package_box_sn = '" + rows.get(0).getString("package_box_sn") + "'") + .uniqueResult(0); + // 仓库信息 StorattrDto storattrDto = storattrService.findById(Long.parseLong((String) whereJson.get("stor_id"))); @@ -655,9 +688,14 @@ public class StIvtIostorinvServiceImpl extends ServiceImpl