|
|
|
@ -0,0 +1,940 @@
|
|
|
|
|
package com.glxp.api.controller.inout;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.glxp.api.annotation.AuthRuleAnnotation;
|
|
|
|
|
import com.glxp.api.annotation.CusRedissonAnnotation;
|
|
|
|
|
import com.glxp.api.annotation.Log;
|
|
|
|
|
import com.glxp.api.annotation.RepeatSubmit;
|
|
|
|
|
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.*;
|
|
|
|
|
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.UdiEntity;
|
|
|
|
|
import com.glxp.api.entity.basic.UdiProductEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoCodeLostEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoCodeTempEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoOrderEntity;
|
|
|
|
|
import com.glxp.api.entity.inout.IoSplitFifoCodeEntity;
|
|
|
|
|
import com.glxp.api.entity.inv.InvProductDetailEntity;
|
|
|
|
|
import com.glxp.api.req.inout.AddOrderCodeRequest;
|
|
|
|
|
import com.glxp.api.req.inout.AddOrderRequest;
|
|
|
|
|
import com.glxp.api.res.basic.UdiRelevanceResponse;
|
|
|
|
|
import com.glxp.api.res.inout.AddCodeResult;
|
|
|
|
|
import com.glxp.api.res.inout.VailCodeResultResponse;
|
|
|
|
|
import com.glxp.api.service.auth.InvWarehouseService;
|
|
|
|
|
import com.glxp.api.service.basic.*;
|
|
|
|
|
import com.glxp.api.service.collect.IoCollectCodeService;
|
|
|
|
|
import com.glxp.api.service.collect.IoCollectOrderService;
|
|
|
|
|
import com.glxp.api.service.collect.IoCollectOriginService;
|
|
|
|
|
import com.glxp.api.service.inout.*;
|
|
|
|
|
import com.glxp.api.service.inout.impl.IoCodeService;
|
|
|
|
|
import com.glxp.api.service.inv.InvPreinProductDetailService;
|
|
|
|
|
import com.glxp.api.service.inv.impl.InvProductDetailService;
|
|
|
|
|
import com.glxp.api.service.system.SystemParamConfigService;
|
|
|
|
|
import com.glxp.api.util.GennerOrderUtils;
|
|
|
|
|
import com.glxp.api.util.IntUtil;
|
|
|
|
|
import com.glxp.api.util.MsDateUtil;
|
|
|
|
|
import com.glxp.api.util.OrderNoTypeBean;
|
|
|
|
|
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.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
public class WorkPutController extends BaseController {
|
|
|
|
|
@Resource
|
|
|
|
|
IoSplitFifoCodeService fifoCodeService;
|
|
|
|
|
@Resource
|
|
|
|
|
private IoCodeTempService codeTempService;
|
|
|
|
|
@Resource
|
|
|
|
|
private IoOrderService orderService;
|
|
|
|
|
@Resource
|
|
|
|
|
private IBasicBussinessTypeService basicBussinessTypeService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoAddInoutService transInoutService;
|
|
|
|
|
@Resource
|
|
|
|
|
UdiRelevanceService udiRelevanceService;
|
|
|
|
|
@Resource
|
|
|
|
|
UdiProductService udiProductService;
|
|
|
|
|
@Resource
|
|
|
|
|
GennerOrderUtils gennerOrderUtils;
|
|
|
|
|
@Resource
|
|
|
|
|
UdiCalCountUtil udiCalCountUtil;
|
|
|
|
|
@Resource
|
|
|
|
|
InvWarehouseService invWarehouseService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoCodeLostService codeLostService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoOrderDetailBizService orderDetailBizService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoAddInoutService ioAddInoutService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoOrderDetailCodeService ioOrderDetailCodeService;
|
|
|
|
|
@Resource
|
|
|
|
|
IoSplitFifoCodeService splitFifoCodeService;
|
|
|
|
|
|
|
|
|
|
//前端扫码提交(耗材器械)
|
|
|
|
|
@RepeatSubmit()
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
|
|
|
@PostMapping("work/inout/single/addCode")
|
|
|
|
|
@CusRedissonAnnotation(cacheName = RedissonCacheKey.WEB_ADD_CODE, key = {"#addOrderRequest.corpOrderId", "#addOrderRequest.code"}, timeOutMsg = "系统正在处理,请勿重复扫码")
|
|
|
|
|
@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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
IoOrderEntity ioOrderEntity = orderService.findCorpOrderId(addOrderRequest.getCorpOrderId());
|
|
|
|
|
if (ioOrderEntity != null) {
|
|
|
|
|
addOrderRequest.setBillNo(ioOrderEntity.getBillNo());
|
|
|
|
|
}
|
|
|
|
|
//TODO 退货校验是否有库存 提示产品不存在
|
|
|
|
|
if (StrUtil.equals("return", addOrderRequest.getSplitType())) {
|
|
|
|
|
//ioSplitFifoInvService.getOne(new LambdaQueryWrapper<IoSplitFifoInv>().eq(IoSplitFifoInv::getInvCode,"").last("limit 1"));
|
|
|
|
|
}
|
|
|
|
|
if (IntUtil.value(udiEntity.getProductType()) == 2) {
|
|
|
|
|
return adddGrugOrder(addOrderRequest, udiEntity, code);
|
|
|
|
|
} else {
|
|
|
|
|
return addMaterOrder(addOrderRequest, udiEntity, code);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RepeatSubmit()
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
|
|
|
@PostMapping("work/inout/batch/AddCode")
|
|
|
|
|
@CusRedissonAnnotation(cacheName = RedissonCacheKey.WEB_ADD_CODE, key = {"#addOrderCodeRequest.corpOrderId", "#addOrderCodeRequest.codeList"}, timeOutMsg = "系统正在处理,请勿重复提交")
|
|
|
|
|
@Log(title = "单据管理", businessType = BusinessType.INSERT)
|
|
|
|
|
public BaseResponse batchAddCode(@RequestBody AddOrderCodeRequest addOrderCodeRequest, BindingResult bindingResult) {
|
|
|
|
|
|
|
|
|
|
if (bindingResult.hasErrors()) {
|
|
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
|
|
|
}
|
|
|
|
|
AddCodeResult addCodeResult = new AddCodeResult();
|
|
|
|
|
List<String> codeList = addOrderCodeRequest.getCodeList();
|
|
|
|
|
if (CollUtil.isEmpty(codeList))
|
|
|
|
|
return ResultVOUtils.error(500, "追溯码不能为空");
|
|
|
|
|
List<VailCodeResultResponse> vailCodeResultResponses = new ArrayList<>();
|
|
|
|
|
for (String code : codeList) {
|
|
|
|
|
VailCodeResultResponse vailCodeResultResponse = new VailCodeResultResponse();
|
|
|
|
|
AddOrderRequest addOrderRequest = new AddOrderRequest();
|
|
|
|
|
BeanUtils.copyProperties(addOrderCodeRequest, addOrderRequest);
|
|
|
|
|
addOrderRequest.setBillNo(addCodeResult.getOrderId());
|
|
|
|
|
if (StringUtils.isBlank(code)) return ResultVOUtils.error(ResultEnum.DATA_ERROR);
|
|
|
|
|
code = code.trim();
|
|
|
|
|
if (code.endsWith("\u001D")) {
|
|
|
|
|
code = code.replace("\u001D", "");
|
|
|
|
|
}
|
|
|
|
|
UdiEntity udiEntity = FilterUdiUtils.getUdi(code);
|
|
|
|
|
if (udiEntity == null) {
|
|
|
|
|
vailCodeResultResponse.setCode(code);
|
|
|
|
|
vailCodeResultResponse.setStatus(2);
|
|
|
|
|
vailCodeResultResponse.setErrMsg("无效条码");
|
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AuthAdmin authAdmin = getUser();
|
|
|
|
|
addOrderRequest.setInvCode(authAdmin.getLocInvCode());
|
|
|
|
|
if (IntUtil.value(addOrderCodeRequest.getInoutType()) == 2) {
|
|
|
|
|
addOrderRequest.setAction(ConstantType.SPLIT_RETURN);
|
|
|
|
|
} else {
|
|
|
|
|
addOrderRequest.setAction(ConstantType.SPLIT_OUT);
|
|
|
|
|
}
|
|
|
|
|
addOrderRequest.setFromCorp(ConstantType.SPLIT_CORP);
|
|
|
|
|
|
|
|
|
|
BaseResponse baseResponse = null;
|
|
|
|
|
addOrderRequest.setCode(code);
|
|
|
|
|
IoOrderEntity ioOrderEntity = orderService.findCorpOrderId(addOrderCodeRequest.getCorpOrderId());
|
|
|
|
|
if (ioOrderEntity != null) {
|
|
|
|
|
addOrderRequest.setBillNo(ioOrderEntity.getBillNo());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IntUtil.value(udiEntity.getProductType()) == 2) {
|
|
|
|
|
baseResponse = adddGrugOrder(addOrderRequest, udiEntity, code);
|
|
|
|
|
} else {
|
|
|
|
|
baseResponse = addMaterOrder(addOrderRequest, udiEntity, code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (baseResponse.getCode() == 20000) {
|
|
|
|
|
vailCodeResultResponse.setCode(code);
|
|
|
|
|
vailCodeResultResponse.setStatus(1);
|
|
|
|
|
vailCodeResultResponse.setErrMsg("正确");
|
|
|
|
|
AddCodeResult temp = (AddCodeResult) baseResponse.getData();
|
|
|
|
|
addCodeResult.setOrderId(temp.getOrderId());
|
|
|
|
|
addOrderRequest.setBillNo(temp.getOrderId());
|
|
|
|
|
} else {
|
|
|
|
|
vailCodeResultResponse.setCode(code);
|
|
|
|
|
vailCodeResultResponse.setStatus(2);
|
|
|
|
|
vailCodeResultResponse.setErrMsg(baseResponse.getMessage());
|
|
|
|
|
}
|
|
|
|
|
vailCodeResultResponses.add(vailCodeResultResponse);
|
|
|
|
|
}
|
|
|
|
|
addCodeResult.setVailCodeResultResponses(vailCodeResultResponses);
|
|
|
|
|
return ResultVOUtils.success(addCodeResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public BaseResponse addMaterOrder(AddOrderRequest addOrderRequest, UdiEntity udiEntity, String code) {
|
|
|
|
|
|
|
|
|
|
AddCodeResult addCodeResult = new AddCodeResult();
|
|
|
|
|
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(addOrderRequest.getAction());
|
|
|
|
|
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(addOrderRequest.getInvCode());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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<IoCodeTempEntity> 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<IoCodeTempEntity> ioCodeEnttities = codeTempService.findByOrderId(orderId);
|
|
|
|
|
IoCodeTempEntity ioCodeEnttity = isExitLocal(code, ioCodeEnttities);
|
|
|
|
|
if (ioCodeEnttity == null) {
|
|
|
|
|
return checkOriginCodeRes;
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
return checkOriginCodeRes;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
BaseResponse checkOriginCodeRes = checkOriginCode(udiEntity);
|
|
|
|
|
if (checkOriginCodeRes != null) {
|
|
|
|
|
IoCodeLostEntity codeLostEntity = codeLostService.findByCode(code);
|
|
|
|
|
if (codeLostEntity != null) {
|
|
|
|
|
udiEntity.setBatchNo(codeLostEntity.getBatchNo());
|
|
|
|
|
udiEntity.setExpireDate(codeLostEntity.getExpireDate());
|
|
|
|
|
udiEntity.setProduceDate(codeLostEntity.getProduceDate());
|
|
|
|
|
checkOriginCodeRes = checkOriginCode(udiEntity);
|
|
|
|
|
if (checkOriginCodeRes != null)
|
|
|
|
|
return checkOriginCodeRes;
|
|
|
|
|
} else
|
|
|
|
|
return checkOriginCodeRes;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//过期提醒:
|
|
|
|
|
if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 1 && !addOrderRequest.isIgnoreExpire()) {
|
|
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
|
|
|
|
|
String expireDate = "20" + udiEntity.getExpireDate();
|
|
|
|
|
long expireTime = MsDateUtil.parseDateExpire(expireDate);
|
|
|
|
|
if (expireTime - System.currentTimeMillis() < 0) {
|
|
|
|
|
return ResultVOUtils.error(504, "当前产品已过期,是否确定继续添加?");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 2) {
|
|
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
|
|
|
|
|
String expireDate = "20" + udiEntity.getExpireDate();
|
|
|
|
|
long expireTime = MsDateUtil.parseDateExpire(expireDate);
|
|
|
|
|
if (expireTime - System.currentTimeMillis() < 0) {
|
|
|
|
|
return ResultVOUtils.error(604, "当前产品已过期,无法添加!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByNameCode(udiEntity.getUdi());
|
|
|
|
|
|
|
|
|
|
//近效期提醒
|
|
|
|
|
long recent = 0;
|
|
|
|
|
if (udiRelevanceResponse.getRecentDateTime() != null)
|
|
|
|
|
recent = udiRelevanceResponse.getRecentDateTime().longValue();
|
|
|
|
|
if (IntUtil.value(bussinessTypeEntity.getCheckVailDate()) == 1 && recent > 0 && !addOrderRequest.isIgnoreRecentExpire() && udiRelevanceResponse.getIsDateBy() == 2) {
|
|
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
|
|
|
|
|
String expireDate = "20" + udiEntity.getExpireDate();
|
|
|
|
|
long expireTime = MsDateUtil.parseDateExpire(expireDate);
|
|
|
|
|
long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000);
|
|
|
|
|
long resultTime = expireTime - System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
if (resultTime > 0) {
|
|
|
|
|
long time = resultTime / (60 * 60 * 1000);
|
|
|
|
|
// long time = resultTime / (24 * 60 * 60 * 1000);
|
|
|
|
|
if (resultTime < recentTieme) {
|
|
|
|
|
return ResultVOUtils.error(505, "当前产品临近过期,距过期还剩" + time + "时,是否确定继续添加?");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IntUtil.value(bussinessTypeEntity.getCheckVailDate()) == 1 && recent > 0 && !addOrderRequest.isIgnoreRecentExpire() && udiRelevanceResponse.getIsDateBy() == 1) {
|
|
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
|
|
|
|
|
String expireDate = "20" + udiEntity.getExpireDate();
|
|
|
|
|
long expireTime = MsDateUtil.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.getAction().equals(ConstantType.SPLIT_OUT)) {
|
|
|
|
|
IoSplitFifoCodeEntity fifoCodeEntity = fifoCodeService.findByCode(code, null);
|
|
|
|
|
if (fifoCodeEntity != null && StrUtil.isNotEmpty(fifoCodeEntity.getSerialNo())) {
|
|
|
|
|
return ResultVOUtils.error(500, "当前追溯码已存在!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//先生成扫码单据
|
|
|
|
|
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<IoCodeTempEntity> codeEnttitys = codeTempService.findByOrderId(orderId);
|
|
|
|
|
IoCodeTempEntity exitLocalEntity = null;
|
|
|
|
|
IoCodeTempEntity genDetaiEntity = new IoCodeTempEntity();
|
|
|
|
|
List<UdiRelevanceResponse> 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);
|
|
|
|
|
|
|
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
|
|
genDetaiEntity.setReCount(udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
} else {
|
|
|
|
|
genDetaiEntity.setReCount(udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exitLocalEntity.setCount(exitLocalEntity.getMyCount() + 1);
|
|
|
|
|
|
|
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
|
|
exitLocalEntity.setReCount(IntUtil.value(exitLocalEntity.getMyReCount()) * udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
} else {
|
|
|
|
|
exitLocalEntity.setReCount(IntUtil.value(exitLocalEntity.getMyReCount()) * udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isBlank(exitLocalEntity.getSerialNo())) {
|
|
|
|
|
return ResultVOUtils.error(500, "重复扫码!");
|
|
|
|
|
}
|
|
|
|
|
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.setWarehouseCode(addOrderRequest.getCurSpaceCode());
|
|
|
|
|
codeEnttity.setPreSpaceCode(addOrderRequest.getPreCurSpaceCode());
|
|
|
|
|
codeEnttity.setProductType(1);
|
|
|
|
|
codeEnttity.setPreInSpaceCode(addOrderRequest.getCheckPreInSpaceCode());
|
|
|
|
|
codeEnttity.setRelId(addOrderRequest.getRelId());
|
|
|
|
|
codeEnttity.setFifoSplit(addOrderRequest.getFifoSplit());
|
|
|
|
|
codeEnttity.setCount(1);
|
|
|
|
|
String unitFk = null;
|
|
|
|
|
if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) {
|
|
|
|
|
unitFk = addOrderRequest.getFromCorp();
|
|
|
|
|
} else if (StrUtil.isNotEmpty(addOrderRequest.getSelectSupId())) {
|
|
|
|
|
unitFk = addOrderRequest.getSelectSupId();
|
|
|
|
|
}
|
|
|
|
|
//产品是否禁用
|
|
|
|
|
udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(codeEnttity.getNameCode(), false);
|
|
|
|
|
if (udiRelevanceResponses.size() >= 1) {
|
|
|
|
|
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 (IntUtil.value(addOrderRequest.getFifoSplit()) == 2 && IntUtil.value(udiRelevanceResponse.getSplitEnable())) {
|
|
|
|
|
// return ResultVOUtils.error(500, "当前上货只允许录入整取产品!");
|
|
|
|
|
// }
|
|
|
|
|
// if (IntUtil.value(addOrderRequest.getFifoSplit()) == 1 && !IntUtil.value(udiRelevanceResponse.getSplitEnable())) {
|
|
|
|
|
// return ResultVOUtils.error(500, "当前上货只允许录入拆零产品!");
|
|
|
|
|
// }
|
|
|
|
|
//计算实际数量
|
|
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
|
|
codeEnttity.setReCount(IntUtil.value(codeEnttity.getMyReCount()) + udiCalCountUtil.getUseActCount(udiRelevanceResponse));
|
|
|
|
|
} else {
|
|
|
|
|
codeEnttity.setReCount(IntUtil.value(codeEnttity.getMyReCount()) + udiCalCountUtil.getCirActCount(udiRelevanceResponse));
|
|
|
|
|
}
|
|
|
|
|
} else if (udiRelevanceResponses.size() == 0) {
|
|
|
|
|
if (unitFk == null)
|
|
|
|
|
return ResultVOUtils.error(500, "耗材字典不存在此产品!");
|
|
|
|
|
else
|
|
|
|
|
return ResultVOUtils.error(500, "当前供应商不存在此配送产品!");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
orderEntity.setSickerAdNum(addOrderRequest.getSickerAdNum());
|
|
|
|
|
orderEntity.setWorkPlaceCode(addOrderRequest.getWorkPlaceCode());
|
|
|
|
|
orderEntity.setProductType(1);
|
|
|
|
|
orderEntity.setFifoSplit(addOrderRequest.getFifoSplit());
|
|
|
|
|
orderEntity.setSplitBusType(addOrderRequest.getSplitBusType());
|
|
|
|
|
orderService.insertOrder(orderEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IntUtil.value(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 (baseResponse != null) {
|
|
|
|
|
// deleteEmptyBillNo(orderEntity);
|
|
|
|
|
// }
|
|
|
|
|
// 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 (bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_RETURN)) {
|
|
|
|
|
IoSplitFifoCodeEntity ioSplitFifoCodeEntity = splitFifoCodeService.findByCode(codeEnttity.getCode(), orderEntity.getWorkPlaceCode());
|
|
|
|
|
if (ioSplitFifoCodeEntity == null)
|
|
|
|
|
return ResultVOUtils.error(500, "当前工位库存库存不足");
|
|
|
|
|
|
|
|
|
|
if (ioSplitFifoCodeEntity.getScanCount() < codeEnttity.getCount()) {
|
|
|
|
|
return ResultVOUtils.error(500, "当前工位库存库存不足");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
codeTempService.insert(codeEnttity);
|
|
|
|
|
}
|
|
|
|
|
addCodeResult.setOrderId(orderId);
|
|
|
|
|
transInoutService.genOrderDetailCode(orderEntity, genDetaiEntity);
|
|
|
|
|
return ResultVOUtils.success(addCodeResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public BaseResponse adddGrugOrder(AddOrderRequest addOrderRequest, UdiEntity udiEntity, String code) {
|
|
|
|
|
AddCodeResult addCodeResult = new AddCodeResult();
|
|
|
|
|
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(addOrderRequest.getAction());
|
|
|
|
|
InvWarehouseEntity invWarehouseEntity = invWarehouseService.findByInvSubByCode(addOrderRequest.getInvCode());
|
|
|
|
|
|
|
|
|
|
//批次号校验
|
|
|
|
|
//判断此产品是否开启允许无批次号
|
|
|
|
|
UdiProductEntity udiInfoEntity = udiProductService.findByNameCode(udiEntity.getUdi());
|
|
|
|
|
if (udiInfoEntity == null) {
|
|
|
|
|
return ResultVOUtils.error(500, "药品字典不存在此产品!");
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isEmpty(udiEntity.getBatchNo())) {
|
|
|
|
|
IoCodeLostEntity codeLostEntity = codeLostService.findByCode(addOrderRequest.getCode());
|
|
|
|
|
if (codeLostEntity != null) {
|
|
|
|
|
udiEntity.setBatchNo(codeLostEntity.getBatchNo());
|
|
|
|
|
udiEntity.setProduceDate(codeLostEntity.getProduceDate());
|
|
|
|
|
udiEntity.setExpireDate(codeLostEntity.getExpireDate());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
String orderId = addOrderRequest.getBillNo();
|
|
|
|
|
|
|
|
|
|
//过期提醒:
|
|
|
|
|
if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 1 && !addOrderRequest.isIgnoreExpire()) {
|
|
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
|
|
|
|
|
String expireDate = "20" + udiEntity.getExpireDate();
|
|
|
|
|
long expireTime = MsDateUtil.parseDateExpire(expireDate);
|
|
|
|
|
if (expireTime - System.currentTimeMillis() < 0) {
|
|
|
|
|
return ResultVOUtils.error(504, "当前产品已过期,是否确定继续添加?");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (IntUtil.value(bussinessTypeEntity.getCheckExpire()) == 2) {
|
|
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
|
|
|
|
|
String expireDate = "20" + udiEntity.getExpireDate();
|
|
|
|
|
long expireTime = MsDateUtil.parseDateExpire(expireDate);
|
|
|
|
|
if (expireTime - System.currentTimeMillis() < 0) {
|
|
|
|
|
return ResultVOUtils.error(604, "当前产品已过期,无法添加!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByNameCode(udiEntity.getUdi());
|
|
|
|
|
|
|
|
|
|
//近效期提醒
|
|
|
|
|
long recent = 0;
|
|
|
|
|
if (udiRelevanceResponse.getRecentDateTime() != null)
|
|
|
|
|
recent = udiRelevanceResponse.getRecentDateTime().longValue();
|
|
|
|
|
if (IntUtil.value(bussinessTypeEntity.getCheckVailDate()) == 1 && recent > 0 && !addOrderRequest.isIgnoreRecentExpire() && udiRelevanceResponse.getIsDateBy() == 2) {
|
|
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
|
|
|
|
|
String expireDate = "20" + udiEntity.getExpireDate();
|
|
|
|
|
long expireTime = MsDateUtil.parseDateExpire(expireDate);
|
|
|
|
|
long recentTieme = Math.abs(recent * 24 * 60 * 60 * 1000);
|
|
|
|
|
long resultTime = expireTime - System.currentTimeMillis();
|
|
|
|
|
|
|
|
|
|
if (resultTime > 0) {
|
|
|
|
|
long time = resultTime / (60 * 60 * 1000);
|
|
|
|
|
if (resultTime < recentTieme) {
|
|
|
|
|
return ResultVOUtils.error(505, "当前产品临近过期,距过期还剩" + time + "时,是否确定继续添加?");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IntUtil.value(bussinessTypeEntity.getCheckVailDate()) == 1 && recent > 0 && !addOrderRequest.isIgnoreRecentExpire() && udiRelevanceResponse.getIsDateBy() == 1) {
|
|
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getExpireDate())) {
|
|
|
|
|
String expireDate = "20" + udiEntity.getExpireDate();
|
|
|
|
|
long expireTime = MsDateUtil.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.getAction().equals(ConstantType.SPLIT_OUT)) {
|
|
|
|
|
IoSplitFifoCodeEntity fifoCodeEntity = fifoCodeService.findByCode(code, null);
|
|
|
|
|
if (fifoCodeEntity != null && StrUtil.isNotEmpty(fifoCodeEntity.getSerialNo())) {
|
|
|
|
|
return ResultVOUtils.error(500, "当前追溯码已存在!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (addOrderRequest.getFromCorp() == null || StrUtil.isNotEmpty(addOrderRequest.getSickerAdNum())) {
|
|
|
|
|
String fromCorp = ioAddInoutService.updateCorp(bussinessTypeEntity, addOrderRequest.getFromCorp(), addOrderRequest.getSickerAdNum());
|
|
|
|
|
addOrderRequest.setFromCorp(fromCorp);
|
|
|
|
|
}
|
|
|
|
|
//先生成扫码单据
|
|
|
|
|
IoOrderEntity orderEntity = orderService.findByBillNo(orderId);
|
|
|
|
|
String inBatch = "";
|
|
|
|
|
if (StringUtils.isBlank(orderId) || orderEntity == null) {
|
|
|
|
|
String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd"));
|
|
|
|
|
orderId = orderNo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inBatch = orderId.substring((Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix())).length());
|
|
|
|
|
List<IoCodeTempEntity> codeEnttitys = codeTempService.findByOrderId(orderId);
|
|
|
|
|
IoCodeTempEntity exitLocalEntity = null;
|
|
|
|
|
IoCodeTempEntity genDetaiEntity = new IoCodeTempEntity();
|
|
|
|
|
List<UdiRelevanceResponse> 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, "当前药品追溯码已存在,且存在异常未处理!");
|
|
|
|
|
}
|
|
|
|
|
udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(exitLocalEntity.getNameCode(), null);
|
|
|
|
|
|
|
|
|
|
BeanUtils.copyProperties(exitLocalEntity, genDetaiEntity);
|
|
|
|
|
genDetaiEntity.setCount(1);
|
|
|
|
|
|
|
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
|
|
genDetaiEntity.setReCount(udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
} else {
|
|
|
|
|
genDetaiEntity.setReCount(udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
exitLocalEntity.setCount(exitLocalEntity.getMyCount() + 1);
|
|
|
|
|
|
|
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
|
|
exitLocalEntity.setReCount(exitLocalEntity.getMyReCount() * udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
} else {
|
|
|
|
|
exitLocalEntity.setReCount(exitLocalEntity.getMyReCount() * udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!StringUtils.isBlank(exitLocalEntity.getSerialNo())) {
|
|
|
|
|
return ResultVOUtils.error(500, "重复扫码!");
|
|
|
|
|
}
|
|
|
|
|
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.setWarehouseCode(addOrderRequest.getCurSpaceCode());
|
|
|
|
|
codeEnttity.setPreSpaceCode(addOrderRequest.getPreCurSpaceCode());
|
|
|
|
|
codeEnttity.setPreInSpaceCode(addOrderRequest.getCheckPreInSpaceCode());
|
|
|
|
|
codeEnttity.setRelId(addOrderRequest.getRelId());
|
|
|
|
|
codeEnttity.setFifoSplit(addOrderRequest.getFifoSplit());
|
|
|
|
|
codeEnttity.setProductType(2);
|
|
|
|
|
codeEnttity.setCount(1);
|
|
|
|
|
String unitFk = null;
|
|
|
|
|
if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) {
|
|
|
|
|
unitFk = addOrderRequest.getFromCorp();
|
|
|
|
|
} else if (StrUtil.isNotEmpty(addOrderRequest.getSelectSupId())) {
|
|
|
|
|
unitFk = addOrderRequest.getSelectSupId();
|
|
|
|
|
}
|
|
|
|
|
//产品是否禁用
|
|
|
|
|
udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(codeEnttity.getNameCode(), false);
|
|
|
|
|
if (udiRelevanceResponses.size() >= 1) {
|
|
|
|
|
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() + "单只允许录入非集采产品!");
|
|
|
|
|
// }
|
|
|
|
|
// if (IntUtil.value(addOrderRequest.getFifoSplit()) == 2 && IntUtil.value(udiRelevanceResponse.getSplitEnable())) {
|
|
|
|
|
// return ResultVOUtils.error(500, "当前上货只允许录入整取产品!");
|
|
|
|
|
// }
|
|
|
|
|
// if (IntUtil.value(addOrderRequest.getFifoSplit()) == 1 && !IntUtil.value(udiRelevanceResponse.getSplitEnable())) {
|
|
|
|
|
// return ResultVOUtils.error(500, "当前上货只允许录入拆零产品!");
|
|
|
|
|
// }
|
|
|
|
|
//计算实际数量
|
|
|
|
|
|
|
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
|
|
codeEnttity.setReCount(codeEnttity.getMyReCount() + udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
} else {
|
|
|
|
|
codeEnttity.setReCount(codeEnttity.getMyReCount() + udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
}
|
|
|
|
|
} 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());
|
|
|
|
|
orderEntity.setSickerAdNum(addOrderRequest.getSickerAdNum());
|
|
|
|
|
orderEntity.setWorkPlaceCode(addOrderRequest.getWorkPlaceCode());
|
|
|
|
|
orderEntity.setSplitBusType(addOrderRequest.getSplitBusType());
|
|
|
|
|
orderEntity.setFifoSplit(addOrderRequest.getFifoSplit());
|
|
|
|
|
orderEntity.setSplitBusType(addOrderRequest.getSplitBusType());
|
|
|
|
|
orderEntity.setProductType(2);
|
|
|
|
|
orderService.insertOrder(orderEntity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IntUtil.value(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 = checkDrugRelId(codeEnttity, unitFk);
|
|
|
|
|
if (baseResponse != null) {
|
|
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
// }
|
|
|
|
|
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()) && !IntUtil.value(udiRelevanceResponse.getAllowNoSerial())) {
|
|
|
|
|
errMsg = errMsg + ",序列号";
|
|
|
|
|
}
|
|
|
|
|
if (StrUtil.isNotEmpty(errMsg)) {
|
|
|
|
|
BaseResponse baseResponse = ResultVOUtils.error(507, "产品三期缺失请补齐" + errMsg.substring(1) + "");
|
|
|
|
|
baseResponse.setData(udiEntity);
|
|
|
|
|
return baseResponse;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断本单是否存在
|
|
|
|
|
*
|
|
|
|
|
* @param code
|
|
|
|
|
* @param codeEnttityList
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public IoCodeTempEntity isExitLocal(String code, List<IoCodeTempEntity> codeEnttityList) {
|
|
|
|
|
List<IoCodeTempEntity> codeTempEntities = isExitLocalList(code, codeEnttityList);
|
|
|
|
|
if (CollUtil.isNotEmpty(codeTempEntities)) {
|
|
|
|
|
return codeTempEntities.get(0);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public BaseResponse checkDrugRelId(IoCodeTempEntity codeEnttity, String unitFk) {
|
|
|
|
|
|
|
|
|
|
List<UdiRelevanceResponse> udiRelevanceEntities = udiRelevanceService.selectDrugsByNameCode(codeEnttity, 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 List<IoCodeTempEntity> isExitLocalList(String code, List<IoCodeTempEntity> codeEnttityList) {
|
|
|
|
|
UdiEntity udiEntity = FilterUdiUtils.getUdi(code);
|
|
|
|
|
List<IoCodeTempEntity> codeTempEntities = codeEnttityList.stream()
|
|
|
|
|
.filter(item -> {
|
|
|
|
|
if (item.getCode().equals(code)) {
|
|
|
|
|
if (StrUtil.emptyIfNull(item.getSerialNo()).equals(StrUtil.emptyIfNull(udiEntity.getSerialNo()))) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (!StrUtil.emptyIfNull(item.getNameCode()).equals(StrUtil.emptyIfNull(udiEntity.getUdi()))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!StrUtil.emptyIfNull(item.getBatchNo()).toUpperCase(Locale.ROOT).equals(StrUtil.emptyIfNull(udiEntity.getBatchNo()).toUpperCase(Locale.ROOT))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!StrUtil.emptyIfNull(item.getProduceDate()).equals(StrUtil.emptyIfNull(udiEntity.getProduceDate()))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!StrUtil.emptyIfNull(item.getExpireDate()).equals(StrUtil.emptyIfNull(udiEntity.getExpireDate()))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!StrUtil.emptyIfNull(item.getSerialNo()).equals(StrUtil.emptyIfNull(udiEntity.getSerialNo()))) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}).sorted(Comparator.comparing(IoCodeTempEntity::getInBatchNo)).collect(Collectors.toList());
|
|
|
|
|
Collections.reverse(codeTempEntities);
|
|
|
|
|
return codeTempEntities;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deleteEmptyBillNo(IoOrderEntity orderEntity) {
|
|
|
|
|
boolean r1 = orderDetailBizService.isExit(orderEntity.getBillNo());
|
|
|
|
|
boolean r2 = ioOrderDetailCodeService.isExit(orderEntity.getBillNo());
|
|
|
|
|
boolean r3 = codeTempService.isExit(orderEntity.getBillNo());
|
|
|
|
|
if (!r1 && !r2 && !r3) {
|
|
|
|
|
orderService.deleteByBillNo(orderEntity.getBillNo());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|