package com.glxp.api.controller.inout; import cn.hutool.Hutool; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import com.github.pagehelper.PageInfo; import com.glxp.api.annotation.AuthRuleAnnotation; import com.glxp.api.annotation.Log; import com.glxp.api.common.enums.ResultEnum; import com.glxp.api.common.res.BaseResponse; import com.glxp.api.common.util.ResultVOUtils; import com.glxp.api.constant.BusinessType; import com.glxp.api.constant.Constant; import com.glxp.api.constant.ConstantStatus; import com.glxp.api.constant.ConstantType; import com.glxp.api.controller.BaseController; import com.glxp.api.entity.auth.AuthAdmin; import com.glxp.api.entity.auth.InvWarehouseEntity; import com.glxp.api.entity.basic.BasicBussinessTypeEntity; import com.glxp.api.entity.basic.BasicCorpEntity; import com.glxp.api.entity.basic.UdiEntity; import com.glxp.api.entity.basic.UdiProductEntity; import com.glxp.api.entity.inout.*; import com.glxp.api.entity.inv.InvPreInProductDetailEntity; import com.glxp.api.entity.inv.InvPreProductDetailEntity; import com.glxp.api.entity.inv.InvPreinDetailEntity; import com.glxp.api.entity.purchase.SupCertEntity; import com.glxp.api.entity.purchase.SupProductEntity; import com.glxp.api.entity.system.SystemParamConfigEntity; import com.glxp.api.req.basic.CompanyProductRelevanceRequest; import com.glxp.api.req.inout.AddEnterCodeRequest; import com.glxp.api.req.inout.AddOrderRequest; import com.glxp.api.req.inout.FilterCodeRequest; import com.glxp.api.req.inout.PostOrderRequest; import com.glxp.api.res.PageSimpleResponse; import com.glxp.api.res.basic.UdiRelevanceResponse; import com.glxp.api.res.basic.UdiRlSupResponse; import com.glxp.api.res.inout.AddCodeResult; import com.glxp.api.res.inout.IoCodeTempResponse; import com.glxp.api.service.auth.InvWarehouseService; import com.glxp.api.service.basic.*; import com.glxp.api.service.inout.*; import com.glxp.api.service.inv.*; import com.glxp.api.service.purchase.SupCertService; import com.glxp.api.service.purchase.SupProductService; import com.glxp.api.service.system.SystemParamConfigService; import com.glxp.api.util.*; import com.glxp.api.util.udi.FilterUdiUtils; import com.glxp.api.util.udi.UdiCalCountUtil; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Locale; @RestController public class IoCodeTempController extends BaseController { @Resource private IoCodeTempService codeTempService; @Resource private IoOrderService orderService; @Resource private IBasicBussinessTypeService basicBussinessTypeService; @Resource IoAddInoutService transInoutService; @Resource private SystemParamConfigService systemParamConfigService; @Resource UdiRelevanceService udiRelevanceService; @Resource UdiProductService udiProductService; @Resource BasicCorpService basicUnitMaintainService; @Resource GennerOrderUtils gennerOrderUtils; @Resource UdiCalCountUtil udiCalCountUtil; @Resource UdiRlSupService udiRlSupService; @Resource InvWarehouseService invWarehouseService; @Resource IoCheckInoutService ioCheckInoutService; @Resource InvPreinProductDetailService invPreinProductDetailService; @Resource InvProductDetailService invProductDetailService; @Resource IoCodeLostService codeLostService; @Resource IoOrderDetailBizService orderDetailBizService; @Resource IoCodeService codeService; @Resource InvPreProductDetailService invPreProductDetailService; //手持端扫码单据上传调用接口 @AuthRuleAnnotation("") @PostMapping("warehouse/inout/postOrders") @Log(title = "单据管理", businessType = BusinessType.INSERT) public BaseResponse postOrders(@RequestBody PostOrderRequest postOrderRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } Long userId = getUserId(); try { PostOrderRequest inPostOrder = new PostOrderRequest(); List inPostOrders = new ArrayList<>(); PostOrderRequest outPostOrder = new PostOrderRequest(); List outPostOrders = new ArrayList<>(); List postOrders = postOrderRequest.getPostOrders(); if (postOrders != null && postOrders.size() > 0) { for (PostOrderRequest.PostOrder postOrder : postOrders) { BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(postOrder.getOrderBean().getType()); if (bussinessTypeEntity.isOutToSpms()) { outPostOrders.add(postOrder); } else { inPostOrders.add(postOrder); } } } BeanUtils.copyProperties(postOrderRequest, inPostOrder); BeanUtils.copyProperties(postOrderRequest, outPostOrder); inPostOrder.setPostOrders(inPostOrders); outPostOrder.setPostOrders(outPostOrders); if (CollUtil.isNotEmpty(inPostOrders)) { inPostOrder.setCustomerId(getCustomerId()); inPostOrder.setUserId(userId); transInoutService.creatOrderByPda(inPostOrder); } } catch (Exception e) { return ResultVOUtils.error(ResultEnum.NOT_NETWORK); } return ResultVOUtils.success("上传成功,等待后台处理"); } @Resource SupProductService supProductService; @Resource SupCertService supCertService; //前端扫码完整性校验 @AuthRuleAnnotation("") @PostMapping("warehouse/inout/enterCode") public BaseResponse addEndterCode(@RequestBody AddEnterCodeRequest addEnterCodeRequest) { if (StrUtil.isEmpty(addEnterCodeRequest.getCode())) { return ResultVOUtils.error(500, "条码不能为空!"); } String code = ""; String originCode = addEnterCodeRequest.getOriginCode(); if (originCode == null) originCode = ""; code = originCode + addEnterCodeRequest.getCode(); String newCode = addEnterCodeRequest.getCode(); //重复判断 if (StrUtil.isNotEmpty(addEnterCodeRequest.getOriginCode())) { String tempOriginCode = addEnterCodeRequest.getOriginCode(); if (tempOriginCode.endsWith("\u001D")) { tempOriginCode = tempOriginCode.replace("\u001D", ""); } UdiEntity originUdiEntity = FilterUdiUtils.getUdi(tempOriginCode); if (StrUtil.isNotEmpty(newCode)) { if (newCode.startsWith("10")) { if (StrUtil.isNotEmpty(originUdiEntity.getBatchNo())) { BaseResponse baseResponse = ResultVOUtils.error(501, "批次号重复添加"); baseResponse.setData(originCode); return baseResponse; } else { String msg = checkNewCode(originUdiEntity, newCode); if (msg != null) { BaseResponse baseResponse = ResultVOUtils.error(501, msg); baseResponse.setData(originCode); return baseResponse; } } } else if (newCode.startsWith("17")) { if (StrUtil.isNotEmpty(originUdiEntity.getExpireDate())) { BaseResponse baseResponse = ResultVOUtils.error(501, "失效日期重复添加"); baseResponse.setData(originCode); return baseResponse; } else { String msg = checkNewCode(originUdiEntity, newCode); if (msg != null) { BaseResponse baseResponse = ResultVOUtils.error(501, msg); baseResponse.setData(originCode); return baseResponse; } } } else if (newCode.startsWith("11")) { if (StrUtil.isNotEmpty(originUdiEntity.getProduceDate())) { BaseResponse baseResponse = ResultVOUtils.error(501, "生产日期重复添加"); baseResponse.setData(originCode); return baseResponse; } else { String msg = checkNewCode(originUdiEntity, newCode); if (msg != null) { BaseResponse baseResponse = ResultVOUtils.error(501, msg); baseResponse.setData(originCode); return baseResponse; } } } else if (newCode.startsWith("21")) { if (StrUtil.isNotEmpty(originUdiEntity.getSerialNo())) { BaseResponse baseResponse = ResultVOUtils.error(501, "序列号重复添加"); baseResponse.setData(originCode); return baseResponse; } else { String msg = checkNewCode(originUdiEntity, newCode); if (msg != null) { BaseResponse baseResponse = ResultVOUtils.error(501, msg); baseResponse.setData(originCode); return baseResponse; } } } else { BaseResponse baseResponse = ResultVOUtils.error(501, "格式错误"); baseResponse.setData(originCode); return baseResponse; } } } UdiEntity udiEntity = FilterUdiUtils.getUdi(code); if (udiEntity == null) { String sptmtodi = systemParamConfigService.selectValueByParamKey(Constant.SPTM_TO_DI); if (sptmtodi.equals("1")) { if (code.length() == 13) { UdiProductEntity udiProductEntity = udiProductService.findBySptm(code); if (udiProductEntity != null) { BaseResponse baseResponse = ResultVOUtils.error(508, "UDI码格式错误"); baseResponse.setData(udiProductEntity); return baseResponse; } } } BaseResponse baseResponse = ResultVOUtils.error(501, "UDI码格式错误"); baseResponse.setData(originCode); return baseResponse; } if (StrUtil.isNotEmpty(udiEntity.getBatchNo())) { if (code.endsWith("10" + udiEntity.getBatchNo())) { code = code + "\u001D"; } } UdiRelevanceResponse checkUdi = udiRelevanceService.selectByNameCode(udiEntity.getUdi()); if (checkUdi == null) { return ResultVOUtils.error(500, "耗材字典不存在此产品!"); } boolean checkSuccess = true; String lostMsg = ""; //校验条码完整性 if ("是".equals(checkUdi.getScbssfbhph()) && StrUtil.isEmpty(udiEntity.getBatchNo())) { checkSuccess = false; lostMsg = lostMsg + ",批次号"; } if ("是".equals(checkUdi.getScbssfbhscrq()) && StrUtil.isEmpty(udiEntity.getProduceDate())) { checkSuccess = false; lostMsg = lostMsg + ",生产日期"; } if ("是".equals(checkUdi.getScbssfbhsxrq()) && StrUtil.isEmpty(udiEntity.getExpireDate())) { checkSuccess = false; lostMsg = lostMsg + ",失效日期"; } if (("是".equals(checkUdi.getScbssfbhxlh()) && StrUtil.isEmpty(udiEntity.getSerialNo())) ) { checkSuccess = false; lostMsg = lostMsg + ",序列号"; } if (StrUtil.isNotEmpty(udiEntity.getSerialNo()) && udiEntity.getSerialNo().length() > 20) { return ResultVOUtils.error(504, "序列号超出20位!"); } if (StrUtil.isNotEmpty(udiEntity.getBatchNo()) && udiEntity.getBatchNo().length() > 20) { return ResultVOUtils.error(504, "批次号超出20位!"); } if (StrUtil.isEmpty(udiEntity.getSerialNo()) && StrUtil.isEmpty(udiEntity.getBatchNo())) { checkSuccess = false; } if (checkSuccess) { if (code.endsWith("\u001D")) { code = code.substring(0, code.length() - "\u001D".length()); } return ResultVOUtils.success(code); } else { if (newCode.startsWith("21") || (StrUtil.isNotEmpty(udiEntity.getSerialNo()) && newCode.contains("21" + udiEntity.getSerialNo()))) { if (StrUtil.isEmpty(lostMsg)) { lostMsg = ","; } BaseResponse baseResponse = ResultVOUtils.error(503, "条码完整性错误,缺少" + lostMsg.substring(1) + "是否继续添加?"); baseResponse.setData(code); return baseResponse; } } BaseResponse baseResponse = ResultVOUtils.error(502, "校验未完成"); baseResponse.setData(code); return baseResponse; } public String checkNewCode(UdiEntity originEnity, String newCode) { UdiEntity newEntity = FilterUdiUtils.getUdi(originEnity.getUdi() + newCode); if (newEntity == null || originEnity == null) { return null; } if (StrUtil.isNotEmpty(originEnity.getBatchNo()) && StrUtil.isNotEmpty(newEntity.getBatchNo())) { return "批次号重复添加!"; } if (StrUtil.isNotEmpty(originEnity.getProduceDate()) && StrUtil.isNotEmpty(newEntity.getProduceDate())) { return "生产日期重复添加!"; } if (StrUtil.isNotEmpty(originEnity.getExpireDate()) && StrUtil.isNotEmpty(newEntity.getExpireDate())) { return "失效日期重复添加!"; } if (StrUtil.isNotEmpty(originEnity.getSerialNo()) && StrUtil.isNotEmpty(newEntity.getSerialNo())) { return "序列号重复添加!"; } return null; } //前端扫码提交 @AuthRuleAnnotation("") @PostMapping("warehouse/inout/addOrderWeb") @Log(title = "单据管理", businessType = BusinessType.INSERT) public BaseResponse addOrderWeb(@RequestBody AddOrderRequest addOrderRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } AddCodeResult addCodeResult = new AddCodeResult(); BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(addOrderRequest.getAction()); InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(addOrderRequest.getInvCode()); String code = addOrderRequest.getCode(); if (StringUtils.isBlank(code)) return ResultVOUtils.error(ResultEnum.DATA_ERROR); if (code.endsWith("\u001D")) { code = code.replace("\u001D", ""); } UdiEntity udiEntity = FilterUdiUtils.getUdi(code); if (udiEntity == null) return ResultVOUtils.error(500, "无效条码!"); if (StrUtil.isNotEmpty(addOrderRequest.getBatchNo())) { udiEntity.setBatchNo(addOrderRequest.getBatchNo()); } if (StrUtil.isNotEmpty(addOrderRequest.getProduceDate())) { udiEntity.setProduceDate(addOrderRequest.getProduceDate()); } if (StrUtil.isNotEmpty(addOrderRequest.getExpireDate())) { udiEntity.setExpireDate(addOrderRequest.getExpireDate()); } if (StrUtil.isNotEmpty(addOrderRequest.getSerialNo())) { udiEntity.setSerialNo(addOrderRequest.getSerialNo()); } if (StrUtil.isNotEmpty(udiEntity.getSerialNo()) && udiEntity.getSerialNo().length() > 20) { return ResultVOUtils.error(500, "无效条码!序列号超出最大范围"); } if (StrUtil.isNotEmpty(udiEntity.getBatchNo()) && udiEntity.getBatchNo().length() > 20) { return ResultVOUtils.error(500, "无效条码!批次号超出最大范围"); } //批次号校验 //判断此产品是否开启允许无批次号 UdiProductEntity udiInfoEntity = udiProductService.findByNameCode(udiEntity.getUdi()); if (udiInfoEntity == null) { return ResultVOUtils.error(500, "耗材字典不存在此产品!"); } if (!IntUtil.value(udiInfoEntity.getAllowNoBatch())) { if (StrUtil.isEmpty(udiEntity.getSerialNo()) && StrUtil.isEmpty(udiEntity.getBatchNo())) { return ResultVOUtils.error(500, "序列号与批次号不能同时为空!"); } } String orderId = addOrderRequest.getBillNo(); //三期校验 if (bussinessTypeEntity.isCodeFillCheck()) { BaseResponse checkOriginCodeRes = checkOriginCode(udiEntity); if (checkOriginCodeRes != null) { IoCodeLostEntity codeLostEntity = codeLostService.findByCode(code); if (codeLostEntity == null) { if (StrUtil.isNotEmpty(orderId)) { List ioCodeEnttities = codeTempService.findByOrderId(orderId); IoCodeTempEntity ioCodeEnttity = isExitLocal(code, ioCodeEnttities); if (ioCodeEnttity == null) { return checkOriginCodeRes; } } else return checkOriginCodeRes; } else { udiEntity.setBatchNo(codeLostEntity.getBatchNo()); udiEntity.setExpireDate(codeLostEntity.getExpireDate()); udiEntity.setProduceDate(codeLostEntity.getProduceDate()); } if (StrUtil.isNotEmpty(orderId)) { List ioCodeEnttities = codeTempService.findByOrderId(orderId); IoCodeTempEntity ioCodeEnttity = isExitLocal(code, ioCodeEnttities); if (ioCodeEnttity == null) { return checkOriginCodeRes; } } else return checkOriginCodeRes; } } //过期提醒: // SystemParamConfigEntity expireParamConfigEntity = systemParamConfigService.selectByParamKey("expire_date_tip"); if (bussinessTypeEntity.getCheckExpire() == 1 && !addOrderRequest.isIgnoreExpire()) { if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) { String expireDate = "20" + udiEntity.getExpireDate(); long expireTime = DateUtil.parseDateExpire(expireDate); if (expireTime - System.currentTimeMillis() < 0) { return ResultVOUtils.error(504, "当前产品已过期,是否确定继续添加?"); } } } if (bussinessTypeEntity.getCheckExpire() == 2) { if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) { String expireDate = "20" + udiEntity.getExpireDate(); long expireTime = DateUtil.parseDateExpire(expireDate); if (expireTime - System.currentTimeMillis() < 0) { return ResultVOUtils.error(604, "当前产品已过期,无法添加?"); } } } UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByNameCode(udiEntity.getUdi()); //近效期提醒 // SystemParamConfigEntity recentParamConfigEntity = systemParamConfigService.selectByParamKey("recent_date_tip"); long recent = 0; if (udiRelevanceResponse.getRecentDateTime() != null) recent = udiRelevanceResponse.getRecentDateTime().longValue(); if (bussinessTypeEntity.getCheckVailDate() == 1 && recent > 0 && !addOrderRequest.isIgnoreRecentExpire()) { if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) { String expireDate = "20" + udiEntity.getExpireDate(); long expireTime = DateUtil.parseDateExpire(expireDate); long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000); long resultTime = expireTime - System.currentTimeMillis(); if (resultTime > 0) { long time = resultTime / (24 * 60 * 60 * 1000); if (resultTime < recentTieme) { return ResultVOUtils.error(505, "当前产品临近过期,距过期还剩" + time + "天,是否确定继续添加?"); } } } } if (bussinessTypeEntity.getCheckVailDate() == 2 && recent > 0) { if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) { String expireDate = "20" + udiEntity.getExpireDate(); long expireTime = DateUtil.parseDateExpire(expireDate); long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000); long resultTime = expireTime - System.currentTimeMillis(); if (resultTime > 0) { long time = resultTime / (24 * 60 * 60 * 1000); if (resultTime < recentTieme) { return ResultVOUtils.error(605, "当前产品临近过期,距过期还剩" + time + "天,无法添加!"); } } } } //校验预验收是否已存在 if (bussinessTypeEntity.getActionType() == ConstantStatus.ACTION_TYPE_PREIN) { if (StrUtil.isNotEmpty(udiEntity.getSerialNo())) { int count = invPreinProductDetailService.findCountByCode(code); if (count > 0) { return ResultVOUtils.error(500, "预验收库存已存在此UDI码,请检查后重试!"); } } } //校验预验收库存是否已存在 if (bussinessTypeEntity.isScanPreIn()) { if (bussinessTypeEntity.getBackPreinType() == 1) {//按单出库 String orderIds = addOrderRequest.getCheckPreInOrders(); if (StrUtil.isNotEmpty(orderIds)) { String[] orderIdArray = orderIds.split(","); List orderList = CollUtil.toList(orderIdArray); int count = codeService.findByOrderIdsCount(orderList, code); if (count <= 0) { return ResultVOUtils.error(500, "非预验收单产品或预验收库存数量不足!"); } if (StrUtil.isNotEmpty(orderId)) {//非首次添加 if (StrUtil.isEmpty(udiEntity.getSerialNo())) {//该单据已有该产品 //无序列号,则可能存在多个预验收入库单 IoCodeTempEntity codeTempEntity = codeTempService.findByUnique(orderId, code); if (codeTempEntity != null) { if (count < (codeTempEntity.getMyCount() + 1)) { return ResultVOUtils.error(500, "超出预验收库存数量"); } } } else { if (count < 1) { return ResultVOUtils.error(500, "预验收库存数量不足"); } } } } else { return ResultVOUtils.error(500, "未选择预验收入库单,请先选择预验收入库单!"); } } else { //按库存出库 int preInCount = invPreinProductDetailService.findCountByCode(code); InvPreInProductDetailEntity invPreinDetailEntity = invPreinProductDetailService.findUseOneByCode(code); if (preInCount <= 0) { return ResultVOUtils.error(500, "预验收库存数量不足!"); } else { if (StrUtil.isNotEmpty(invPreinDetailEntity.getBatchNo()) && StrUtil.isNotEmpty(addOrderRequest.getBatchNo()) && !invPreinDetailEntity.getBatchNo().equals(addOrderRequest.getBatchNo())) { return ResultVOUtils.error(500, "当前批次号与预验收录入批次号不匹配!"); } if (StrUtil.isNotEmpty(orderId)) {//非首次添加 if (StrUtil.isEmpty(udiEntity.getSerialNo())) {//该单据已有该产品 //无序列号,则可能存在多个预验收入库单 IoCodeTempEntity codeTempEntity = codeTempService.findByUnique(orderId, code); if (codeTempEntity != null) { if (preInCount < (codeTempEntity.getMyCount() + 1)) { return ResultVOUtils.error(500, "超出预验收库存数量"); } } } else { if (preInCount < 1) { return ResultVOUtils.error(500, "预验收库存数量不足"); } } } } } } // 是否检验寄售库存 if (bussinessTypeEntity.isAdvancePreIn()) { int preInCount = invPreProductDetailService.findCountByCode(code); InvPreProductDetailEntity invPreinDetailEntity = invPreProductDetailService.findUseOneByCode(code); if (preInCount <= 0) { return ResultVOUtils.error(500, "寄售库存数量不足!"); } else { if (StrUtil.isNotEmpty(invPreinDetailEntity.getBatchNo()) && StrUtil.isNotEmpty(addOrderRequest.getBatchNo()) && !invPreinDetailEntity.getBatchNo().equals(addOrderRequest.getBatchNo())) { return ResultVOUtils.error(500, "当前批次号与预验收录入批次号不匹配!"); } if (StrUtil.isNotEmpty(orderId)) {//非首次添加 if (StrUtil.isEmpty(udiEntity.getSerialNo())) {//该单据已有该产品 //无序列号,则可能存在多个预验收入库单 IoCodeTempEntity codeTempEntity = codeTempService.findByUnique(orderId, code); if (codeTempEntity != null) { if (preInCount < (codeTempEntity.getMyCount() + 1)) { return ResultVOUtils.error(500, "超出寄售存数量"); } } } else { if (preInCount < 1) { return ResultVOUtils.error(500, "寄售库存数量不足"); } } } } } if (addOrderRequest.getFromCorp() == null) { BasicCorpEntity basicCorpEntity = basicUnitMaintainService.selectByName(addOrderRequest.getFromCorp()); if (basicCorpEntity == null && bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_INPUT && bussinessTypeEntity.isGenUnit()) { basicCorpEntity = new BasicCorpEntity(); basicCorpEntity.setErpId(CustomUtil.getUnitId()); addOrderRequest.setFromCorp((basicCorpEntity.getErpId())); basicCorpEntity.setCorpType(ConstantStatus.CORP_SICK); basicCorpEntity.setOutType(ConstantStatus.CORP_SICK_SICK); basicCorpEntity.setName(addOrderRequest.getFromCorp()); addOrderRequest.setFromCorp(basicCorpEntity.getName()); basicCorpEntity.setId(IdUtil.getSnowflakeNextId()); basicUnitMaintainService.insert(basicCorpEntity); } } //先生成扫码单据 IoOrderEntity orderEntity = orderService.findByBillNo(orderId); if (StringUtils.isBlank(orderId) || orderEntity == null) { String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd")); orderId = orderNo; } List codeEnttitys = codeTempService.findByOrderId(orderId); IoCodeTempEntity exitLocalEntity = null; IoCodeTempEntity genDetaiEntity = new IoCodeTempEntity(); List udiRelevanceResponses = null; if (codeEnttitys.size() > 0) { exitLocalEntity = isExitLocal(code, codeEnttitys); if (exitLocalEntity != null) { if (StrUtil.isEmpty(exitLocalEntity.getSupId()) || exitLocalEntity.getRelId() == null) { return ResultVOUtils.error(500, "当前UDI码已存在,且存在异常未处理!"); } udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(exitLocalEntity.getNameCode(), null); BeanUtils.copyProperties(exitLocalEntity, genDetaiEntity); genDetaiEntity.setCount(1); genDetaiEntity.setReCount(udiCalCountUtil.getActCount(udiRelevanceResponses.get(0))); exitLocalEntity.setCount(exitLocalEntity.getMyCount() + 1); exitLocalEntity.setReCount(exitLocalEntity.getMyCount() * udiCalCountUtil.getActCount(udiRelevanceResponses.get(0))); if (StringUtils.isNotBlank(exitLocalEntity.getSerialNo())) { return ResultVOUtils.error(500, "重复扫码!"); } BaseResponse invRes = checkInv(bussinessTypeEntity, exitLocalEntity); if (invRes != null) { return invRes; } if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_NORMAL && bussinessTypeEntity.isCheckEnable()) { String errMsg = ioCheckInoutService.checkCode(genDetaiEntity); if (errMsg != null) { return ResultVOUtils.error(500, errMsg); } else codeTempService.updateById(exitLocalEntity); } else if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_WAIT && bussinessTypeEntity.isCheckEnable()) { String errMsg = ioCheckInoutService.checkNoPiCode(genDetaiEntity); if (errMsg != null) { return ResultVOUtils.error(500, errMsg); } else codeTempService.updateById(exitLocalEntity); } else { codeTempService.updateById(exitLocalEntity); } } } if (exitLocalEntity == null) { IoCodeTempEntity codeEnttity = new IoCodeTempEntity(); codeEnttity.setCode(code); codeEnttity.setOrderId(orderId); codeEnttity.setCorpOrderId(addOrderRequest.getCorpOrderId()); codeEnttity.setCreateTime(new Date()); codeEnttity.setUpdateTime(new Date()); codeEnttity.setMainAction(bussinessTypeEntity.getMainAction()); codeEnttity.setAction(bussinessTypeEntity.getAction()); codeEnttity.setNameCode(udiEntity.getUdi()); codeEnttity.setBatchNo(udiEntity.getBatchNo()); codeEnttity.setProduceDate(udiEntity.getProduceDate()); codeEnttity.setExpireDate(udiEntity.getExpireDate()); codeEnttity.setSerialNo(udiEntity.getSerialNo()); codeEnttity.setDeptCode(invWarehouseEntity.getParentId()); codeEnttity.setInvCode(addOrderRequest.getInvCode()); codeEnttity.setCount(1); String unitFk = null; if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) { unitFk = addOrderRequest.getFromCorp(); } //产品是否可以以使用单元入库 udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(codeEnttity.getNameCode(), false); if (udiRelevanceResponses.size() >= 1) { // UdiRelevanceResponse udiRelevanceResponse = udiRelevanceResponses.get(0); if (udiRelevanceResponse == null) { return ResultVOUtils.error(500, "该产品信息未维护!"); } else if (!udiRelevanceResponse.getUseDy() && udiRelevanceResponse.getDiType() == ConstantStatus.DITYPE_SYDY) { return ResultVOUtils.error(500, "该产品不允许以使用单元入库!"); } if (bussinessTypeEntity.isVailDispatch() && !udiRelevanceResponse.isDispatch()) { return ResultVOUtils.error(500, "该产品不可配送,请联系院方!"); } if (bussinessTypeEntity.getVailGroupBuy() == 1 && !udiRelevanceResponse.isGroupBuy()) { //只采集集采产品 return ResultVOUtils.error(500, bussinessTypeEntity.getName() + "只允许录入集采产品!"); } if (bussinessTypeEntity.getVailGroupBuy() == 2 && udiRelevanceResponse.isGroupBuy()) { //只采集非集采产品 return ResultVOUtils.error(500, bussinessTypeEntity.getName() + "只允许录入非集采产品!"); } //计算实际数量 codeEnttity.setReCount(codeEnttity.getMyCount() * udiCalCountUtil.getActCount(udiRelevanceResponse)); } else if (udiRelevanceResponses.size() == 0) { if (unitFk == null) return ResultVOUtils.error(500, "耗材字典不存在此产品!"); else return ResultVOUtils.error(500, "当前供应商不存在此配送产品!"); } //校验供应商是否配送此产品 BaseResponse corpResponse = checkCorp(codeEnttity, bussinessTypeEntity, unitFk); if (corpResponse != null) { return corpResponse; } IoOrderEntity isExit = orderService.findByBillNo(orderId); if (isExit == null) { orderEntity = new IoOrderEntity(); orderEntity.setBillNo(orderId); orderEntity.setCorpOrderId(addOrderRequest.getCorpOrderId()); orderEntity.setMainAction(bussinessTypeEntity.getMainAction()); orderEntity.setAction(bussinessTypeEntity.getAction()); orderEntity.setFromCorp(addOrderRequest.getFromCorp()); if (StrUtil.isNotEmpty(addOrderRequest.getFromInvCode())) { InvWarehouseEntity invWarehouseEntity1 = invWarehouseService.findByInvSubByCode(addOrderRequest.getFromInvCode()); orderEntity.setFromDeptCode(invWarehouseEntity1.getParentId()); } orderEntity.setFromInvCode(addOrderRequest.getFromInvCode()); orderEntity.setFromType(ConstantStatus.FROM_WEBNEW); orderEntity.setStatus(ConstantStatus.ORDER_STATUS_TEMP_SAVE); orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_DRAFT); AuthAdmin authAdmin = getUser(); orderEntity.setCreateUser(authAdmin.getId() + ""); orderEntity.setCreateTime(new Date()); orderEntity.setUpdateUser(authAdmin.getId() + ""); orderEntity.setUpdateTime(new Date()); orderEntity.setCustomerId(authAdmin.getCustomerId() + ""); orderEntity.setDeptCode(invWarehouseEntity.getParentId()); orderEntity.setCheckPreInOrders(addOrderRequest.getCheckPreInOrders()); orderEntity.setInvCode(addOrderRequest.getInvCode()); orderEntity.setOrderType(addOrderRequest.getOrderType()); orderEntity.setBusType(bussinessTypeEntity.getBusType()); orderService.insertOrder(orderEntity); } if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_NORMAL && bussinessTypeEntity.isCheckEnable() && bussinessTypeEntity.getCheckWebNew() != 0) { boolean isBillExit = orderDetailBizService.isExit(orderEntity.getBillNo()); if (!isBillExit) { orderService.deleteByBillNo(orderEntity.getBillNo()); return ResultVOUtils.error(500, "请先录入业务详情"); } } BaseResponse baseResponse = checkRelId(codeEnttity, unitFk); if (bussinessTypeEntity.getCheckCertExpire() == 2 && udiRelevanceResponse.isNeedCert()) { SupProductEntity supProductEntity = supProductService.findExitByManufactury(udiRelevanceResponse.getCpmctymc(), udiRelevanceResponse.getManufactory()); if (supProductEntity != null && (supProductEntity.getAuditStatus() == ConstantStatus.AUDIT_PASS || supProductEntity.getAuditStatus() == ConstantStatus.AUDIT_CHANGE_PASS)) { List supCertEntities = supCertService.findByProductId(supProductEntity.getProductId()); if (CollUtil.isNotEmpty(supCertEntities)) { Date curDate = new Date(); for (SupCertEntity supCertEntity : supCertEntities) { if (supCertEntity.getExpireDate() != null && supCertEntity.getExpireDate().compareTo(curDate) < 0) { return ResultVOUtils.error(500, "产品资质证书已过期!"); } } } } else { if (supProductEntity == null) { return ResultVOUtils.error(500, "产品资质证书未维护!"); } else { return ResultVOUtils.error(500, "产品资质证书未通过审核!"); } } } BaseResponse invRes = checkInv(bussinessTypeEntity, codeEnttity); if (invRes != null) { return invRes; } genDetaiEntity = codeEnttity; if (baseResponse == null) { baseResponse = checkSupId(bussinessTypeEntity, codeEnttity, unitFk); if (baseResponse != null) return baseResponse; } else { if (baseResponse.getCode() == 501) { return baseResponse; } else if (baseResponse.getCode() == 502) { return baseResponse; } checkSupId(bussinessTypeEntity, codeEnttity, unitFk); return baseResponse; } //是否边扫边校验 if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_NORMAL && bussinessTypeEntity.isCheckEnable()) { String errMsg = ioCheckInoutService.checkCode(codeEnttity); if (errMsg != null) { return ResultVOUtils.error(500, errMsg); } else codeTempService.insert(codeEnttity); } else if (addOrderRequest.getOrderType() == ConstantStatus.ORDER_TYPE_WAIT && bussinessTypeEntity.isCheckEnable()) { String errMsg = ioCheckInoutService.checkNoPiCode(codeEnttity); if (errMsg != null) { return ResultVOUtils.error(500, errMsg); } else codeTempService.insert(codeEnttity); } else { codeTempService.insert(codeEnttity); } } addCodeResult.setOrderId(orderId); transInoutService.genOrderDetailCode(orderEntity, genDetaiEntity); return ResultVOUtils.success(addCodeResult); } //校验条码完整性 public BaseResponse checkOriginCode(UdiEntity udiEntity) { //校验条码的完整性 String errMsg = ""; UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByNameCode(udiEntity.getUdi()); if (udiRelevanceResponse == null) { return ResultVOUtils.error(501, "耗材字典不存在此产品!"); } if (StrUtil.isEmpty(udiEntity.getBatchNo()) && !udiRelevanceResponse.getAllowNoBatch()) { errMsg = errMsg + ",批次号"; } if (StrUtil.isEmpty(udiEntity.getProduceDate()) && !udiRelevanceResponse.getAllowNoProduct()) { errMsg = errMsg + ",生产日期"; } if (StrUtil.isEmpty(udiEntity.getExpireDate()) && !udiRelevanceResponse.getAllowNoExpire()) { errMsg = errMsg + ",失效日期"; } if (StrUtil.isEmpty(udiEntity.getSerialNo()) && !udiRelevanceResponse.getAllowNoSerial()) { errMsg = errMsg + ",序列号"; } if (StrUtil.isNotEmpty(errMsg)) { BaseResponse baseResponse = ResultVOUtils.error(507, "产品三期缺失请补齐" + errMsg.substring(1) + ""); baseResponse.setData(udiEntity); return baseResponse; } return null; } //校验条码完整性 public BaseResponse checkCodeIntegrity(UdiRelevanceResponse checkUdi, UdiEntity udiEntity) { String lostMsg = ""; //校验条码完整性 if ("是".equals(checkUdi.getScbssfbhph()) && StrUtil.isEmpty(udiEntity.getBatchNo())) { lostMsg = lostMsg + ",批次号"; } if ("是".equals(checkUdi.getScbssfbhscrq()) && StrUtil.isEmpty(udiEntity.getProduceDate())) { lostMsg = lostMsg + ",生产日期"; } if ("是".equals(checkUdi.getScbssfbhsxrq()) && StrUtil.isEmpty(udiEntity.getExpireDate())) { lostMsg = lostMsg + ",失效日期"; } if (("是".equals(checkUdi.getScbssfbhxlh()) && StrUtil.isEmpty(udiEntity.getSerialNo())) ) { lostMsg = lostMsg + ",序列号"; } if (StrUtil.isNotEmpty(udiEntity.getSerialNo()) && udiEntity.getSerialNo().length() > 20) { return ResultVOUtils.error(504, "序列号超出20位!"); } if (StrUtil.isNotEmpty(udiEntity.getBatchNo()) && udiEntity.getBatchNo().length() > 20) { return ResultVOUtils.error(504, "批次号超出20位!"); } if (StrUtil.isEmpty(udiEntity.getSerialNo()) && StrUtil.isEmpty(udiEntity.getBatchNo())) { lostMsg = "批次号与序列号不能同时为空!"; } if (StrUtil.isNotEmpty(lostMsg)) return ResultVOUtils.error(500, lostMsg); else return null; } //校验供应商是否配送此产品 public BaseResponse checkCorp(IoCodeTempEntity codeEnttity, BasicBussinessTypeEntity bussinessTypeEntity, String unitFk) { CompanyProductRelevanceRequest companyProductRelevanceRequest = new CompanyProductRelevanceRequest(); UdiEntity udiEntity = FilterUdiUtils.getUdi(codeEnttity.getCode()); companyProductRelevanceRequest.setNameCode(udiEntity.getUdi()); if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) { companyProductRelevanceRequest.setUnitFk(unitFk); boolean exist = udiRlSupService.findExist(companyProductRelevanceRequest); if (!exist) { return ResultVOUtils.error(500, "当前供应商不存在此配送产品!"); } } else { boolean exist = udiRlSupService.findExist(companyProductRelevanceRequest); if (!exist) { return ResultVOUtils.error(500, "此产品无指定供应商,请检查后添加!"); } } return null; } //校验产品ID唯一性 public BaseResponse checkRelId(IoCodeTempEntity codeEnttity, String unitFk) { List udiRelevanceEntities = udiRelevanceService.selectAllByNameCode(codeEnttity.getNameCode(), unitFk); if (udiRelevanceEntities != null && udiRelevanceEntities.size() > 1 && codeEnttity.getRelId() == null) {//同一个DI绑定多个产品西信息 codeEnttity.setRelId(null); codeEnttity.setStatus(ConstantStatus.ORDER_DETAIL_DI_MUTI); codeTempService.insert(codeEnttity); codeEnttity = codeTempService.findByUnique(codeEnttity.getOrderId(), codeEnttity.getCode()); BaseResponse baseResponse = ResultVOUtils.error(502, "DI绑定多个产品ID,请指定对应产品"); baseResponse.setData(codeEnttity); return baseResponse; } else if (udiRelevanceEntities == null || udiRelevanceEntities.size() == 0) {//未找到产品信息,一般不会出现 codeEnttity.setRelId(null); codeEnttity.setStatus(2); return ResultVOUtils.error(501, "耗材字典不存在此产品!"); } else { codeEnttity.setStatus(0); if (codeEnttity.getRelId() == null) codeEnttity.setRelId(udiRelevanceEntities.get(0).getId()); } return null; } //校验供应商唯一性 public BaseResponse checkSupId(BasicBussinessTypeEntity bussinessTypeEntity, IoCodeTempEntity codeEnttity, String unitFk) { String originSupId = unitFk; // if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) { // if (unitFk != null) // originSupId = unitFk; // } if (originSupId != null) { codeEnttity.setSupId(originSupId); } else { IoCodeEntity ioCodeEntity = new IoCodeEntity(); BeanUtils.copyProperties(codeEnttity, ioCodeEntity); String supId = transInoutService.checkInvExitSup(ioCodeEntity); if (supId == null) { supId = transInoutService.checkExitSup(codeEnttity.getRelId()); } if (supId == null) { codeEnttity.setSupId(null); BaseResponse baseResponse = ResultVOUtils.error(503, "该产品未绑定供应商,请指定对应的供应商"); baseResponse.setData(codeEnttity); return baseResponse; } else if ("MUTI".equals(supId)) { codeEnttity.setSupId(null); BaseResponse baseResponse = ResultVOUtils.error(503, "该产品绑定多个供应商,请指定对应的供应商"); baseResponse.setData(codeEnttity); return baseResponse; } else { codeEnttity.setSupId(supId); } } codeTempService.updateById(codeEnttity); return null; } //判断本单是否存在 public IoCodeTempEntity isExitLocal(String code, List codeEnttityList) { UdiEntity udiEntity = FilterUdiUtils.getUdi(code); for (int i = 0; i < codeEnttityList.size(); i++) { IoCodeTempEntity drugCodeSelectEntity = codeEnttityList.get(i); if (codeEnttityList.get(i).getCode().equals(code)) { if (StrUtil.emptyIfNull(drugCodeSelectEntity.getSerialNo()).equals(StrUtil.emptyIfNull(udiEntity.getSerialNo()))) { return drugCodeSelectEntity; } } // UdiEntity originUdiEntity = FilterUdiUtils.getUdi(drugCodeSelectEntity.getCode()); if (!StrUtil.emptyIfNull(drugCodeSelectEntity.getNameCode()).equals(StrUtil.emptyIfNull(udiEntity.getUdi()))) { continue; } if (!StrUtil.emptyIfNull(drugCodeSelectEntity.getBatchNo()).toUpperCase(Locale.ROOT).equals(StrUtil.emptyIfNull(udiEntity.getBatchNo()).toUpperCase(Locale.ROOT))) { continue; } if (!StrUtil.emptyIfNull(drugCodeSelectEntity.getProduceDate()).equals(StrUtil.emptyIfNull(udiEntity.getProduceDate()))) { continue; } if (!StrUtil.emptyIfNull(drugCodeSelectEntity.getExpireDate()).equals(StrUtil.emptyIfNull(udiEntity.getExpireDate()))) { continue; } if (!StrUtil.emptyIfNull(drugCodeSelectEntity.getSerialNo()).equals(StrUtil.emptyIfNull(udiEntity.getSerialNo()))) { continue; } return drugCodeSelectEntity; } return null; } public BaseResponse checkInv(BasicBussinessTypeEntity bussinessTypeEntity, IoCodeTempEntity codeTempEntity) { if (bussinessTypeEntity.isVailInv() && bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)) { if (bussinessTypeEntity.getActionType() == ConstantStatus.ACTION_TYPE_ADVANCE) { // int count = invPreProductDetailService.vailStockCount(code); //todo 寄售 // if (count < 0) { // return ResultVOUtils.error(500, "当前库存不足,不允许0库存出库"); // } } else { int count = invProductDetailService.vailStockCount(codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getSupId(), codeTempEntity.getDeptCode(), codeTempEntity.getInvCode(), null); if (count <= 0) { return ResultVOUtils.error(500, "当前库存不足,不允许0库存出库"); } else { //查询此单据已扫描的条码数量 if (codeTempEntity.getMyReCount() > count) { return ResultVOUtils.error(500, "当前库存不足,不允许0库存出库"); } } } } return null; } @AuthRuleAnnotation("") @GetMapping("admin/warehouse/inout/findErrorByOrderId") public BaseResponse findErrorByOrderId(FilterCodeRequest filterCodeRequest) { if (StrUtil.isEmpty(filterCodeRequest.getOrderId())) { return ResultVOUtils.error(500, "单据号不能为空!"); } List list = codeTempService.findCodeList(filterCodeRequest); PageInfo pageInfo = new PageInfo<>(list); PageSimpleResponse pageSimpleResponse = new PageSimpleResponse<>(); pageSimpleResponse.setTotal(pageInfo.getTotal()); pageSimpleResponse.setList(pageInfo.getList()); return ResultVOUtils.success(pageSimpleResponse); } @AuthRuleAnnotation("") @PostMapping("/udiwms/addCode/updateBindSup") @Log(title = "单据管理", businessType = BusinessType.UPDATE) public BaseResponse updateBindSup(@RequestBody IoCodeTempEntity codeSaveRequest, BindingResult bindingResult) { if (bindingResult.hasErrors()) { return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage()); } //更新供应商 IoCodeTempEntity codeTempEntity = codeTempService.selectById(codeSaveRequest.getId()); if (StrUtil.isNotEmpty(codeSaveRequest.getMySupId())) { codeTempEntity.setSupId(codeSaveRequest.getMySupId()); codeTempService.updateById(codeSaveRequest); } if (StrUtil.isNotEmpty(codeSaveRequest.getSupId())) { codeTempEntity.setSupId(codeSaveRequest.getSupId()); codeTempService.updateById(codeSaveRequest); } //更新耗材字典 if (codeSaveRequest.getRelId() != null) { BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(codeTempEntity.getAction()); BaseResponse baseResponse = checkSupId(bussinessTypeEntity, codeTempEntity, codeTempEntity.getSupId()); if (baseResponse != null) return baseResponse; codeTempEntity.setRelId(codeSaveRequest.getRelId()); int reCount = udiCalCountUtil.getActCount(codeTempEntity); // codeTempEntity.setReCount(reCount); } IoOrderEntity orderEntity = orderService.findByBillNo(codeTempEntity.getOrderId()); BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction()); //todo 可能会出问题 if (orderEntity.getOrderType() == ConstantStatus.ORDER_TYPE_NORMAL && bussinessTypeEntity.isCheckEnable() && bussinessTypeEntity.getCheckWebNew() == 1) { String errMsg = ioCheckInoutService.checkCode(codeTempEntity); if (errMsg != null) { return ResultVOUtils.error(500, errMsg); } else codeTempService.updateById(codeTempEntity); } else { codeTempService.updateById(codeTempEntity); } ioAddInoutService.genOrderDetailCode(orderEntity, codeTempEntity); return ResultVOUtils.success("绑定成功"); } @Resource IoAddInoutService ioAddInoutService; @Resource IoOrderDetailCodeService ioOrderDetailCodeService; @AuthRuleAnnotation("") @GetMapping("warehouse/inout/deleteCodesTempById") @Log(title = "单据管理", businessType = BusinessType.DELETE) public BaseResponse deleteCodesTempById(@RequestParam("id") Integer id) { IoCodeTempEntity codeTempEntity = codeTempService.selectById(id); if (codeTempEntity == null) { return ResultVOUtils.error(506, "UDI码异常,未录入!"); } IoOrderEntity orderEntity = orderService.findByBillNo(codeTempEntity.getOrderId()); if (codeTempEntity.getMyCount() > 1) { codeTempEntity.setCount(codeTempEntity.getMyCount() - 1); codeTempEntity.setReCount(codeTempEntity.getMyReCount() - udiCalCountUtil.getActCount(codeTempEntity.getNameCode())); codeTempService.updateById(codeTempEntity); } else { codeTempService.deleteById(id); } //更新扫码详情 IoOrderDetailCodeEntity orderDetailCodeEntity = ioOrderDetailCodeService.findByUnique(orderEntity.getBillNo(), codeTempEntity.getRelId(), codeTempEntity.getBatchNo()); if (orderDetailCodeEntity != null) { //扫码数量-1 int orderCount = orderDetailCodeEntity.getCount(); int orderReCount = orderDetailCodeEntity.getReCount(); if (orderCount > 1) { orderDetailCodeEntity.setCount(orderCount - 1); orderDetailCodeEntity.setReCount(orderReCount - udiCalCountUtil.getActCount(codeTempEntity.getNameCode())); ioOrderDetailCodeService.update(orderDetailCodeEntity); } else { ioOrderDetailCodeService.deleteById(orderDetailCodeEntity.getId()); } } boolean r1 = orderDetailBizService.isExit(orderEntity.getBillNo()); boolean r2 = ioOrderDetailCodeService.isExit(orderEntity.getBillNo()); if (!r1 && !r2) { orderService.deleteByBillNo(orderDetailCodeEntity.getOrderIdFk()); } orderEntity.setUpdateUser(getUserId() + ""); orderEntity.setUpdateTime(new Date()); orderService.update(orderEntity); return ResultVOUtils.success("删除成功!"); } @AuthRuleAnnotation("") @PostMapping("warehouse/inout/saveTempCode") @Log(title = "单据管理", businessType = BusinessType.UPDATE) public BaseResponse saveCode(@RequestBody IoCodeTempEntity codeTempEntity) { if (codeTempEntity.getCount() == null) codeTempEntity.setCount(1); if (StrUtil.isNotEmpty(codeTempEntity.getSerialNo()) && codeTempEntity.getSerialNo().length() > 20) { return ResultVOUtils.error(500, "无效条码!序列号超出最大范围"); } if (StrUtil.isNotEmpty(codeTempEntity.getBatchNo()) && codeTempEntity.getBatchNo().length() > 20) { return ResultVOUtils.error(500, "无效条码!批次号超出最大范围"); } if (StrUtil.isBlank(codeTempEntity.getSerialNo()) && StrUtil.isBlank(codeTempEntity.getBatchNo())) { return ResultVOUtils.error(500, "批次号不能为空!"); } if (StrUtil.isNotEmpty(codeTempEntity.getSerialNo())) { List codeTempEntityList = codeTempService.findByOrderId(codeTempEntity.getOrderId()); for (IoCodeTempEntity object : codeTempEntityList) { if (object.getId() != codeTempEntity.getId() && object.getCode().equals(codeTempEntity.getCode()) && StrUtil.nullToEmpty(object.getCode()).equals(codeTempEntity.getSerialNo())) { return ResultVOUtils.error(500, "条码重复!"); } } } if (codeTempEntity.getMyCount() <= 0) { return ResultVOUtils.error(500, "数量需要大于0"); } IoCodeTempEntity tempEntity = codeTempService.selectById(codeTempEntity.getId()); codeTempEntity.setReCount(codeTempEntity.getMyCount() * udiCalCountUtil.getActCount(codeTempEntity.getNameCode())); int count = tempEntity.getCount() - codeTempEntity.getCount(); //更新扫码详情 IoOrderDetailCodeEntity orderDetailCodeEntity = ioOrderDetailCodeService.findByUnique(codeTempEntity.getOrderId(), codeTempEntity.getRelId(), codeTempEntity.getBatchNo()); if (orderDetailCodeEntity != null) { //扫码数量-1 int orderCount = orderDetailCodeEntity.getCount(); orderDetailCodeEntity.setCount(orderCount - count); orderDetailCodeEntity.setReCount(orderDetailCodeEntity.getCount() * udiCalCountUtil.getActCount(codeTempEntity.getNameCode())); ioOrderDetailCodeService.update(orderDetailCodeEntity); } int b = codeTempService.updateById(codeTempEntity); if (b > 0) return ResultVOUtils.success("修改成功"); else return ResultVOUtils.error(500, "修改失败!"); } }