|
|
package com.glxp.api.controller.inout;
|
|
|
|
|
|
import cn.hutool.core.thread.ThreadUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.glxp.api.annotation.CusRedissonAnnotation;
|
|
|
import com.glxp.api.constant.*;
|
|
|
import com.glxp.api.entity.basic.*;
|
|
|
import com.glxp.api.entity.collect.IoCollectCode;
|
|
|
import com.glxp.api.entity.collect.IoCollectOrder;
|
|
|
import com.glxp.api.entity.collect.IoCollectOrderOrigin;
|
|
|
import com.glxp.api.entity.inv.InvProductDetailEntity;
|
|
|
import com.glxp.api.exception.JsonException;
|
|
|
import com.glxp.api.req.collect.CollectOrderBizRequest;
|
|
|
import com.glxp.api.req.collect.CollectOrderRequest;
|
|
|
import com.glxp.api.res.collect.CollectOrderBizResponse;
|
|
|
import com.glxp.api.res.collect.IoCollectOrderResponse;
|
|
|
import com.glxp.api.res.inout.IoOrderDetailCodeResponse;
|
|
|
import com.glxp.api.res.inout.VailCodeResultResponse;
|
|
|
import com.glxp.api.service.collect.*;
|
|
|
import com.glxp.api.service.inout.impl.IoCodeService;
|
|
|
import com.glxp.api.service.inv.impl.InvProductDetailService;
|
|
|
import org.aspectj.weaver.ast.Var;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
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.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.controller.BaseController;
|
|
|
import com.glxp.api.entity.auth.AuthAdmin;
|
|
|
import com.glxp.api.entity.auth.InvWarehouseEntity;
|
|
|
import com.glxp.api.entity.inout.*;
|
|
|
import com.glxp.api.req.basic.CompanyProductRelevanceRequest;
|
|
|
import com.glxp.api.req.inout.*;
|
|
|
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.res.inv.InvPlaceDetailResponse;
|
|
|
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.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.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.BindingResult;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@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
|
|
|
IoAddInoutService ioAddInoutService;
|
|
|
@Resource
|
|
|
IoOrderDetailCodeService ioOrderDetailCodeService;
|
|
|
@Resource
|
|
|
IoCheckInvService checkInvService;
|
|
|
@Resource
|
|
|
IoSplitFifoCodeService splitFifoCodeService;
|
|
|
@Resource
|
|
|
IoCollectOriginService collectOriginService;
|
|
|
@Resource
|
|
|
IoCollectOrderService collectOrderService;
|
|
|
@Resource
|
|
|
IoCollectCodeService ioCollectCodeService;
|
|
|
@Resource
|
|
|
IoSplitFifoInvService ioSplitFifoInvService;
|
|
|
|
|
|
@Resource
|
|
|
IoCollectOrderBackupService ioCollectOrderBackupService;
|
|
|
|
|
|
/**
|
|
|
* PDA-----单据上传
|
|
|
*/
|
|
|
@RepeatSubmit()
|
|
|
@AuthRuleAnnotation("")
|
|
|
@PostMapping("udiwms/pda/inout/order/upload")
|
|
|
@Log(title = "单据管理", businessType = BusinessType.INSERT)
|
|
|
public BaseResponse pdaUploadOrder(@RequestBody PdaPostOrderRequest pdaPostOrderRequest) {
|
|
|
|
|
|
if (pdaPostOrderRequest == null) {
|
|
|
return ResultVOUtils.error(500, "提交参数不能为空!");
|
|
|
}
|
|
|
if (pdaPostOrderRequest.getOrderEntity() == null) {
|
|
|
return ResultVOUtils.error(500, "提交单据不能为空!");
|
|
|
}
|
|
|
if (pdaPostOrderRequest.getCodeTempEntities() == null) {
|
|
|
return ResultVOUtils.error(500, "单据未扫码,请检查后提交!");
|
|
|
}
|
|
|
IoOrderEntity orderEntity = pdaPostOrderRequest.getOrderEntity();
|
|
|
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction());
|
|
|
|
|
|
if (bussinessTypeEntity.getCheckWebNew() == 0) {
|
|
|
return ioAddInoutService.creatOrderByPda(pdaPostOrderRequest);
|
|
|
} else if (bussinessTypeEntity.getCheckWebNew() == 1 || bussinessTypeEntity.getCheckWebNew() == 2) {
|
|
|
return ioAddInoutService.waitOrderByPda(pdaPostOrderRequest);
|
|
|
} else if (bussinessTypeEntity.getCheckWebNew() == 3) {
|
|
|
return ioAddInoutService.checkCodeResultByPda(bussinessTypeEntity.getCheckWebNewType(), pdaPostOrderRequest);
|
|
|
}
|
|
|
|
|
|
return ResultVOUtils.success("上传成功,等待后台处理");
|
|
|
}
|
|
|
|
|
|
//前端扫码完整性校验
|
|
|
@AuthRuleAnnotation("")
|
|
|
@PostMapping("warehouse/inout/enterCodeBillNo")
|
|
|
public BaseResponse enterCodeBillNo(@RequestBody AddEnterCodeRequest addEnterCodeRequest) {
|
|
|
if (StrUtil.isEmpty(addEnterCodeRequest.getCode())) {
|
|
|
return ResultVOUtils.error(500, "单据号不能为空!");
|
|
|
}
|
|
|
String code = addEnterCodeRequest.getCode();
|
|
|
IoCollectOrderResponse collectOrder = collectOrderService.unionSearch(null, addEnterCodeRequest.getBusType(), code);
|
|
|
if (collectOrder == null) {
|
|
|
//查询原始单据查到为异常提示
|
|
|
IoCollectOrderOrigin ioCollectOrigin = collectOriginService.getOrderByCode(code);
|
|
|
if (ioCollectOrigin != null) {
|
|
|
BaseResponse response = ResultVOUtils.error(501, "单据已下载,业务不匹配");
|
|
|
response.setData(code);
|
|
|
return response;
|
|
|
}
|
|
|
//=============================================//
|
|
|
//本地数据库 无此单据时 触发 用billNo 到 处方下载方法 进行下载
|
|
|
CollectOrderRequest collectOrderRequest = new CollectOrderRequest();
|
|
|
collectOrderRequest.setBusType(addEnterCodeRequest.getBusType());
|
|
|
collectOrderRequest.setWorkPlaceCode(addEnterCodeRequest.getWorkPlaceCode());
|
|
|
collectOrderRequest.setBillNo(code);
|
|
|
BaseResponse baseResponse = collectOriginService.downloadOrderV2(collectOrderRequest);
|
|
|
if (ResultEnum.SUCCESS.getCode() == baseResponse.getCode()) {
|
|
|
collectOrder = collectOrderService.unionSearch(null, null, code);
|
|
|
//=============================================//
|
|
|
if (collectOrder == null) {
|
|
|
BaseResponse response = ResultVOUtils.error(501, "查无此单据号,先选择要处理的单据");
|
|
|
response.setData(code);
|
|
|
return response;
|
|
|
}
|
|
|
collectOrder.setWorkPlaceCode(addEnterCodeRequest.getWorkPlaceCode());
|
|
|
collectOrder.setBusType(addEnterCodeRequest.getBusType());
|
|
|
IoCollectOrder ioCollectOrder = new IoCollectOrder();
|
|
|
BeanUtils.copyProperties(collectOrder, ioCollectOrder);
|
|
|
collectOrderService.updateById(ioCollectOrder);
|
|
|
|
|
|
BaseResponse response = ResultVOUtils.error(601, code);
|
|
|
response.setData(collectOrder);
|
|
|
return response;
|
|
|
} else {
|
|
|
BaseResponse response = ResultVOUtils.error(501, baseResponse.getMessage());
|
|
|
response.setData(code);
|
|
|
return response;
|
|
|
}
|
|
|
} else {
|
|
|
BaseResponse response = ResultVOUtils.error(601, code);
|
|
|
response.setData(collectOrder);
|
|
|
return response;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//前端扫码完整性校验
|
|
|
@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;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
// TODO: 2024/9/13 首次无单进入的时候报错提示,不需要执行校验
|
|
|
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 (IntUtil.value(udiEntity.getProductType()) == 2) {
|
|
|
//药品
|
|
|
udiEntity.setCode(code);
|
|
|
return ResultVOUtils.success(udiEntity);
|
|
|
}
|
|
|
|
|
|
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 (checkUdi.getAllowNoSerial() != null && !checkUdi.getAllowNoSerial() && 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());
|
|
|
}
|
|
|
udiEntity.setCode(code);
|
|
|
return ResultVOUtils.success(udiEntity);
|
|
|
} 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) + "是否继续添加?");
|
|
|
udiEntity.setCode(code);
|
|
|
baseResponse.setData(udiEntity);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
}
|
|
|
BaseResponse baseResponse = ResultVOUtils.error(502, "校验未完成,缺少" + lostMsg.substring(1));
|
|
|
udiEntity.setCode(code);
|
|
|
baseResponse.setData(udiEntity);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
|
@PostMapping("warehouse/inout/batchVailCode")
|
|
|
public BaseResponse batchVailCode(@RequestBody AddEnterCodeRequest addEnterCodeRequest) {
|
|
|
List<String> codeList = addEnterCodeRequest.getCodeList();
|
|
|
if (CollUtil.isEmpty(codeList))
|
|
|
return ResultVOUtils.error(500, "追溯码不能为空");
|
|
|
codeList = codeList.stream().distinct().collect(Collectors.toList());
|
|
|
List<VailCodeResultResponse> vailCodeResultResponses = new ArrayList<>();
|
|
|
List<String> prefixes = Arrays.asList("01", "11", "17", "10", "21");
|
|
|
//判断是否多段扫码
|
|
|
String mutiCode = filterAndConcatenate(codeList, prefixes);
|
|
|
UdiEntity temp = FilterUdiUtils.getUdi(mutiCode);
|
|
|
if (temp != null) {
|
|
|
codeList.clear();
|
|
|
codeList.add(mutiCode);
|
|
|
}
|
|
|
for (String code : codeList) {
|
|
|
VailCodeResultResponse vailCodeResultResponse = new VailCodeResultResponse();
|
|
|
UdiEntity udiEntity = FilterUdiUtils.getUdi(code);
|
|
|
vailCodeResultResponse.setCode(code);
|
|
|
vailCodeResultResponse.setStatus(1);
|
|
|
vailCodeResultResponse.setErrMsg("解析正确");
|
|
|
vailCodeResultResponses.add(vailCodeResultResponse);
|
|
|
if (udiEntity == null) {
|
|
|
vailCodeResultResponse.setStatus(2);
|
|
|
vailCodeResultResponse.setErrMsg("追溯码格式错误");
|
|
|
continue;
|
|
|
}
|
|
|
UdiRelevanceResponse checkUdi = udiRelevanceService.selectByNameCode(udiEntity.getUdi());
|
|
|
if (checkUdi == null) {
|
|
|
vailCodeResultResponse.setStatus(2);
|
|
|
vailCodeResultResponse.setErrMsg("产品字典不存在此产品");
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
return ResultVOUtils.success(vailCodeResultResponses);
|
|
|
}
|
|
|
|
|
|
|
|
|
public static String filterAndConcatenate(List<String> codeList, List<String> prefixes) {
|
|
|
Set<String> matchedPrefixes = new HashSet<>();
|
|
|
StringBuilder concatenatedResult = new StringBuilder();
|
|
|
for (String prefix : prefixes) {
|
|
|
for (String code : codeList) {
|
|
|
if (code.length() >= 2 && code.startsWith(prefix)) {
|
|
|
if (!matchedPrefixes.contains(prefix)) {
|
|
|
matchedPrefixes.add(prefix);
|
|
|
concatenatedResult.append(code);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
UdiEntity udiEntity = FilterUdiUtils.getUdi(concatenatedResult.toString());
|
|
|
if (udiEntity != null && StrUtil.isNotEmpty(udiEntity.getBatchNo())) {
|
|
|
if (concatenatedResult.toString().endsWith("10" + udiEntity.getBatchNo())) {
|
|
|
concatenatedResult.append("\u001D");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return concatenatedResult.toString();
|
|
|
}
|
|
|
|
|
|
|
|
|
@RepeatSubmit()
|
|
|
@AuthRuleAnnotation("")
|
|
|
@PostMapping("warehouse/inout/batchAddCode")
|
|
|
@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 = addDrugOrder(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);
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
//前端扫码提交(耗材器械)
|
|
|
@RepeatSubmit()
|
|
|
@AuthRuleAnnotation("")
|
|
|
@PostMapping("warehouse/inout/addOrderWeb")
|
|
|
@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 addDrugOrder(addOrderRequest, udiEntity, code);
|
|
|
} else {
|
|
|
return addMaterOrder(addOrderRequest, udiEntity, code);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Resource
|
|
|
IoSplitFifoCodeService fifoCodeService;
|
|
|
@Resource
|
|
|
IoSplitCodeService splitCodeService;
|
|
|
|
|
|
@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, "序列号与批次号不能同时为空!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//是否校验产品采购类型 :1:校验;2.无需校验
|
|
|
if (IntUtil.value(bussinessTypeEntity.getVailProductAttributes()) == 1) {
|
|
|
Integer purType = IntUtil.value(udiInfoEntity.getPurType()); //1:普通入账产品;2.预验收产品。3:寄售产品
|
|
|
int actionType = IntUtil.value(bussinessTypeEntity.getActionType()); //1:带票(正常);2.预验收。3:寄售
|
|
|
if (purType != actionType) {
|
|
|
//包装友好提示
|
|
|
String msg = "";
|
|
|
switch (actionType) {
|
|
|
case 1:
|
|
|
msg = "普通入账产品";
|
|
|
break;
|
|
|
case 2:
|
|
|
msg = "预验收产品";
|
|
|
break;
|
|
|
case 3:
|
|
|
msg = "寄售产品";
|
|
|
break;
|
|
|
}
|
|
|
String msg2 = "";
|
|
|
switch (purType) {
|
|
|
case 1:
|
|
|
msg2 = "普通入账产品";
|
|
|
break;
|
|
|
case 2:
|
|
|
msg2 = "预验收产品";
|
|
|
break;
|
|
|
case 3:
|
|
|
msg2 = "寄售产品";
|
|
|
break;
|
|
|
}
|
|
|
return ResultVOUtils.error(500, "单据只允许录入" + msg + ",当前录入产品为" + msg2 + ",请检查后重试!");
|
|
|
}
|
|
|
|
|
|
if (bussinessTypeEntity != null && udiInfoEntity != null) {
|
|
|
//是否校验耗材材质 1:高值耗材;2.普通耗材
|
|
|
if (IntUtil.value(bussinessTypeEntity.getVailHcType()) == 1) {
|
|
|
}
|
|
|
if (IntUtil.value(udiInfoEntity.getHcType()) != 1) {
|
|
|
return ResultVOUtils.error(500, "单据只允许录入高值耗材" + ",请检查后重试!");
|
|
|
}
|
|
|
} else if (IntUtil.value(bussinessTypeEntity.getVailHcType()) == 2) {
|
|
|
if (IntUtil.value(udiInfoEntity.getHcType()) != 2) {
|
|
|
return ResultVOUtils.error(500, "单据只允许录入普通耗材" + ",请检查后重试!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//是否开启校验扫码 :0:不校验;1:只允许录入扫码产品;2:只允许录入不扫码产品
|
|
|
if (IntUtil.value(bussinessTypeEntity.getCodeCheck() == 1)) {
|
|
|
if (IntUtil.value(udiInfoEntity.getRequireScanCode()) != 1) {
|
|
|
return ResultVOUtils.error(500, "单据只允许录入需要扫码产品" + ",请检查后重试!");
|
|
|
}
|
|
|
} else if (IntUtil.value(bussinessTypeEntity.getCodeCheck() == 2)) {
|
|
|
if (IntUtil.value(udiInfoEntity.getRequireScanCode()) != 0) {
|
|
|
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());
|
|
|
//判断层级标识是否正确
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
if (IntUtil.value(udiRelevanceResponse.getUseMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getUseLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
if (IntUtil.value(udiRelevanceResponse.getDistributeMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getDistributeLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
}
|
|
|
//近效期提醒
|
|
|
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(533, "当前追溯码已存在!");
|
|
|
}
|
|
|
//校验码表是否已经存在追溯码 io_code_temp
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getSerialNo())) {
|
|
|
IoCodeTempEntity codeTempEntity1 = codeTempService.selectByCode(code, udiEntity.getBatchNo(), bussinessTypeEntity.getAction());
|
|
|
if (codeTempEntity1 != null) {
|
|
|
return ResultVOUtils.error(533, "扫码重复或当前追溯码已存在草稿单据中!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} else if (bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_RETURN)) {
|
|
|
|
|
|
IoSplitFifoCodeEntity fifoCodeEntity = fifoCodeService.findByCode(code, null);
|
|
|
if (fifoCodeEntity == null) {
|
|
|
return ResultVOUtils.error(500, "当前追溯码未上货!");
|
|
|
}
|
|
|
//校验码表是否已经存在追溯码 io_code_temp
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getSerialNo())) {
|
|
|
IoCodeTempEntity codeTempEntity1 = codeTempService.selectByCode(code, udiEntity.getBatchNo(), bussinessTypeEntity.getAction());
|
|
|
if (codeTempEntity1 != null) {
|
|
|
return ResultVOUtils.error(533, "扫码重复或当前追溯码已存在草稿单据中!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//校验预验收是否已存在
|
|
|
if (bussinessTypeEntity.getActionType() == ConstantStatus.ACTION_TYPE_PREIN && bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_PUT)) {
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getSerialNo())) {
|
|
|
int count = invPreinProductDetailService.findCountByCode(code);
|
|
|
if (count > 0) {
|
|
|
return ResultVOUtils.error(500, "预验收库存已存在此UDI码,请检查后重试!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//校验预验收库存是否已存在
|
|
|
if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 2)) {
|
|
|
if (bussinessTypeEntity.getBackPreinType() == 1 && bussinessTypeEntity.isPreInBack()) {//按单出库&& bussinessTypeEntity.isPreInBack()
|
|
|
String orderIds = addOrderRequest.getCheckPreInOrders();
|
|
|
if (StrUtil.isNotEmpty(orderIds)) {
|
|
|
String[] orderIdArray = orderIds.split(",");
|
|
|
List<String> 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, "未选择预验收入库单,请先选择预验收入库单!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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, "当前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, "重复扫码!");
|
|
|
}
|
|
|
// IoCodeTempEntity codeTempEntity = isExitToatal(code, codeEnttitys);
|
|
|
//校验库存
|
|
|
BaseResponse invRes = null;
|
|
|
if (IntUtil.value(bussinessTypeEntity.getUseDyCount()) == 2) {
|
|
|
if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 2)) { //校验预验收库存
|
|
|
invRes = checkInvService.checkPreInInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
if (bussinessTypeEntity.isAdvancePreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 3)) { //校验寄售库存
|
|
|
invRes = checkInvService.checkPreInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
if (bussinessTypeEntity.isVailInv() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 1)) {
|
|
|
invRes = checkInvService.checkInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
} else {
|
|
|
if (bussinessTypeEntity.isScanPreIn()) { //校验预验收库存
|
|
|
invRes = checkInvService.checkPreInInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
} else if (bussinessTypeEntity.isAdvancePreIn()) { //校验寄售库存
|
|
|
invRes = checkInvService.checkPreInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
} else {
|
|
|
invRes = checkInvService.checkInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (invRes != null) {
|
|
|
return invRes;
|
|
|
}
|
|
|
|
|
|
if (bussinessTypeEntity.getCheckWebNew() == 1 && bussinessTypeEntity.isCheckEnable()) {
|
|
|
String errMsg = ioCheckInoutService.checkCode(genDetaiEntity);
|
|
|
if (errMsg != null) {
|
|
|
return ResultVOUtils.error(500, errMsg);
|
|
|
} else
|
|
|
codeTempService.updateById(exitLocalEntity);
|
|
|
} else if (bussinessTypeEntity.getCheckWebNew() == 2 && bussinessTypeEntity.isCheckEnable()) {
|
|
|
String errMsg = ioCheckInoutService.checkNoPiCode(genDetaiEntity);
|
|
|
if (errMsg != null) {
|
|
|
return ResultVOUtils.error(500, errMsg);
|
|
|
} else
|
|
|
codeTempService.updateById(exitLocalEntity);
|
|
|
} else {
|
|
|
boolean update = true;
|
|
|
String priceFifo = systemParamConfigService.selectValueByParamKey("price_fifo");
|
|
|
if (IntUtil.value(priceFifo) > 0) {
|
|
|
if (bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)) {
|
|
|
//1.获取当前批次已出库数量
|
|
|
Integer outCount = invProductDetailService.selectCountByInBatch(exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), bussinessTypeEntity, exitLocalEntity.getInBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_OUT);
|
|
|
//2.获取当前批次入库数量
|
|
|
Integer inCount = invProductDetailService.selectCountByInBatch(exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), bussinessTypeEntity, exitLocalEntity.getInBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_PUT);
|
|
|
if ((IntUtil.value(inCount) - IntUtil.value(outCount) - IntUtil.value(exitLocalEntity.getReCount())) < 0) {
|
|
|
InvProductDetailEntity nextInvProduct = invProductDetailService.selectNextInBatch(bussinessTypeEntity, exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_PUT, exitLocalEntity.getInBatchNo());
|
|
|
if (nextInvProduct != null) {
|
|
|
genDetaiEntity.setPrice(nextInvProduct.getPrice());
|
|
|
genDetaiEntity.setInBatchNo(nextInvProduct.getInBatchNo());
|
|
|
codeTempService.insert(genDetaiEntity);
|
|
|
update = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// checkPrice();
|
|
|
}
|
|
|
}
|
|
|
if (update) {
|
|
|
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 (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(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, "当前供应商不存在此配送产品!");
|
|
|
}
|
|
|
|
|
|
//校验供应商是否配送此产品
|
|
|
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.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 (IntUtil.value(bussinessTypeEntity.getUseDyCount()) == 2) {
|
|
|
if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse.getId(), 2)) { //校验预验收库存
|
|
|
BaseResponse invRes = checkInvService.checkPreInInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
}
|
|
|
if (bussinessTypeEntity.isAdvancePreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse.getId(), 3)) { //校验寄售库存
|
|
|
BaseResponse invRes = checkInvService.checkPreInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
}
|
|
|
if (bussinessTypeEntity.isVailInv() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse.getId(), 1)) {
|
|
|
BaseResponse invRes = checkInvService.checkInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if (bussinessTypeEntity.isScanPreIn()) { //校验预验收库存
|
|
|
BaseResponse invRes = checkInvService.checkPreInInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
} else if (bussinessTypeEntity.isAdvancePreIn()) { //校验寄售库存
|
|
|
BaseResponse invRes = checkInvService.checkPreInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
} else {
|
|
|
BaseResponse invRes = checkInvService.checkInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//预出库退货校验队列库存
|
|
|
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, "当前工位库存库存不足");
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
//是否边扫边校验
|
|
|
if (bussinessTypeEntity.getCheckWebNew() == 1 && bussinessTypeEntity.isCheckEnable()) {
|
|
|
String errMsg = ioCheckInoutService.checkCode(codeEnttity);
|
|
|
if (errMsg != null) {
|
|
|
return ResultVOUtils.error(500, errMsg);
|
|
|
} else
|
|
|
codeTempService.insert(codeEnttity);
|
|
|
} else if (bussinessTypeEntity.getCheckWebNew() == 2 && bussinessTypeEntity.isCheckEnable()) {
|
|
|
String errMsg = ioCheckInoutService.checkNoPiCode(codeEnttity);
|
|
|
if (errMsg != null) {
|
|
|
return ResultVOUtils.error(500, errMsg);
|
|
|
} else
|
|
|
codeTempService.insert(codeEnttity);
|
|
|
} else {
|
|
|
checkPrice(codeEnttity, bussinessTypeEntity, inBatch, codeEnttitys);
|
|
|
codeTempService.insert(codeEnttity);
|
|
|
}
|
|
|
}
|
|
|
addCodeResult.setOrderId(orderId);
|
|
|
transInoutService.genOrderDetailCode(orderEntity, genDetaiEntity);
|
|
|
return ResultVOUtils.success(addCodeResult);
|
|
|
}
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
RelCodeBatchService relCodeBatchService;
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public BaseResponse addDrugOrder(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());
|
|
|
|
|
|
//判断层级标识是否正确
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
if (IntUtil.value(udiRelevanceResponse.getUseMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getUseLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
if (IntUtil.value(udiRelevanceResponse.getDistributeMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getDistributeLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//近效期提醒
|
|
|
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(533, "当前追溯码已存在!");
|
|
|
}
|
|
|
|
|
|
IoSplitCodeEntity splitCodeEntity = splitCodeService.findByCode(code);
|
|
|
if (splitCodeEntity != null) {//&& StrUtil.isNotEmpty(splitCodeEntity.getSerialNo())
|
|
|
return ResultVOUtils.error(533, "当前追溯码已存在拆零库存!");
|
|
|
}
|
|
|
|
|
|
//校验码表是否已经存在追溯码 io_code_temp
|
|
|
IoCodeTempEntity codeTempEntity = codeTempService.selectByCode(code, udiEntity.getBatchNo(), bussinessTypeEntity.getAction());
|
|
|
if (codeTempEntity != null) {
|
|
|
return ResultVOUtils.error(533, "扫码重复或当前追溯码已存在草稿单据中!");
|
|
|
}
|
|
|
|
|
|
} else if (bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_RETURN)) {
|
|
|
IoSplitFifoCodeEntity fifoCodeEntity = fifoCodeService.findByCode(code, null);
|
|
|
if (fifoCodeEntity == null) {
|
|
|
return ResultVOUtils.error(500, "当前追溯码未上货!");
|
|
|
}
|
|
|
|
|
|
IoSplitCodeEntity splitCodeEntity = splitCodeService.findByCode(code);
|
|
|
if (splitCodeEntity != null) {//&& StrUtil.isNotEmpty(splitCodeEntity.getSerialNo())
|
|
|
return ResultVOUtils.error(533, "当前追溯码已经拆零,无法退货!");
|
|
|
}
|
|
|
|
|
|
//校验码表是否已经存在追溯码 io_code_temp
|
|
|
IoCodeTempEntity codeTempEntity = codeTempService.selectByCode(code, udiEntity.getBatchNo(), bussinessTypeEntity.getAction());
|
|
|
if (codeTempEntity != null) {
|
|
|
return ResultVOUtils.error(533, "扫码重复或当前追溯码已存在草稿单据中!");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
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, "重复扫码!");
|
|
|
}
|
|
|
//校验库存
|
|
|
BaseResponse invRes = null;
|
|
|
if (IntUtil.value(bussinessTypeEntity.getUseDyCount()) == 2) {
|
|
|
if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 2)) { //校验预验收库存
|
|
|
invRes = checkInvService.checkPreInInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
if (bussinessTypeEntity.isAdvancePreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 3)) { //校验寄售库存
|
|
|
invRes = checkInvService.checkPreInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
if (bussinessTypeEntity.isVailInv() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse, 1)) {
|
|
|
invRes = checkInvService.checkInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
} else {
|
|
|
if (bussinessTypeEntity.isScanPreIn()) { //校验预验收库存
|
|
|
invRes = checkInvService.checkPreInInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
} else if (bussinessTypeEntity.isAdvancePreIn()) { //校验寄售库存
|
|
|
invRes = checkInvService.checkPreInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
} else {
|
|
|
invRes = checkInvService.checkInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (invRes != null) {
|
|
|
return invRes;
|
|
|
}
|
|
|
|
|
|
if (bussinessTypeEntity.getCheckWebNew() == 1 && bussinessTypeEntity.isCheckEnable()) {
|
|
|
String errMsg = ioCheckInoutService.checkCode(genDetaiEntity);
|
|
|
if (errMsg != null) {
|
|
|
return ResultVOUtils.error(500, errMsg);
|
|
|
} else
|
|
|
codeTempService.updateById(exitLocalEntity);
|
|
|
} else if (bussinessTypeEntity.getCheckWebNew() == 2 && bussinessTypeEntity.isCheckEnable()) {
|
|
|
String errMsg = ioCheckInoutService.checkNoPiCode(genDetaiEntity);
|
|
|
if (errMsg != null) {
|
|
|
return ResultVOUtils.error(500, errMsg);
|
|
|
} else
|
|
|
codeTempService.updateById(exitLocalEntity);
|
|
|
} else {
|
|
|
boolean update = true;
|
|
|
String priceFifo = systemParamConfigService.selectValueByParamKey("price_fifo");
|
|
|
if (IntUtil.value(priceFifo) > 0) {
|
|
|
if (bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_OUT)) {
|
|
|
//1.获取当前批次已出库数量
|
|
|
Integer outCount = invProductDetailService.selectCountByInBatch(exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), bussinessTypeEntity, exitLocalEntity.getInBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_OUT);
|
|
|
//2.获取当前批次入库数量
|
|
|
Integer inCount = invProductDetailService.selectCountByInBatch(exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), bussinessTypeEntity, exitLocalEntity.getInBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_PUT);
|
|
|
if ((IntUtil.value(inCount) - IntUtil.value(outCount) - IntUtil.value(exitLocalEntity.getReCount())) < 0) {
|
|
|
InvProductDetailEntity nextInvProduct = invProductDetailService.selectNextInBatch(bussinessTypeEntity, exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_PUT, exitLocalEntity.getInBatchNo());
|
|
|
if (nextInvProduct != null) {
|
|
|
genDetaiEntity.setPrice(nextInvProduct.getPrice());
|
|
|
genDetaiEntity.setInBatchNo(nextInvProduct.getInBatchNo());
|
|
|
codeTempService.insert(genDetaiEntity);
|
|
|
update = false;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// checkPrice();
|
|
|
}
|
|
|
}
|
|
|
if (update) {
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (IntUtil.value(bussinessTypeEntity.getUseDyCount()) == 2) {
|
|
|
if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse.getId(), 2)) { //校验预验收库存
|
|
|
BaseResponse invRes = checkInvService.checkPreInInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
}
|
|
|
if (bussinessTypeEntity.isAdvancePreIn() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse.getId(), 3)) { //校验寄售库存
|
|
|
BaseResponse invRes = checkInvService.checkPreInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
}
|
|
|
if (bussinessTypeEntity.isVailInv() && checkDiAttribute(bussinessTypeEntity, udiRelevanceResponse.getId(), 1)) {
|
|
|
BaseResponse invRes = checkInvService.checkInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
}
|
|
|
} else {
|
|
|
if (bussinessTypeEntity.isScanPreIn()) { //校验预验收库存
|
|
|
BaseResponse invRes = checkInvService.checkPreInInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
} else if (bussinessTypeEntity.isAdvancePreIn()) { //校验寄售库存
|
|
|
BaseResponse invRes = checkInvService.checkPreInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
} else {
|
|
|
BaseResponse invRes = checkInvService.checkInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//是否边扫边校验
|
|
|
if (bussinessTypeEntity.getCheckWebNew() == 1 && bussinessTypeEntity.isCheckEnable()) {
|
|
|
String errMsg = ioCheckInoutService.checkCode(codeEnttity);
|
|
|
if (errMsg != null) {
|
|
|
return ResultVOUtils.error(500, errMsg);
|
|
|
} else
|
|
|
codeTempService.insert(codeEnttity);
|
|
|
// 查询是否存在药品关联信息 后将结果更新至 temp表
|
|
|
relCodeBatchService.threadUpdateIoCodeTempEntity(code);
|
|
|
// } else if (bussinessTypeEntity.getCheckWebNew() == 2 && bussinessTypeEntity.isCheckEnable()) {
|
|
|
} else if (IntUtil.value(addOrderRequest.getOrderType()) == ConstantStatus.ORDER_TYPE_WAIT && bussinessTypeEntity.isCheckEnable()) {
|
|
|
String errMsg = ioCheckInoutService.checkDrugNoPiCode(codeEnttity);
|
|
|
if (errMsg != null) {
|
|
|
return ResultVOUtils.error(500, errMsg);
|
|
|
} else
|
|
|
codeTempService.insert(codeEnttity);
|
|
|
// 异步调用 查询是否存在药品关联信息 后将结果更新至 temp表
|
|
|
relCodeBatchService.threadUpdateIoCodeTempEntity(code);
|
|
|
} else {
|
|
|
checkPrice(codeEnttity, bussinessTypeEntity, inBatch, codeEnttitys);
|
|
|
codeTempService.insert(codeEnttity);
|
|
|
// 查询是否存在药品关联信息 后将结果更新至 temp表
|
|
|
relCodeBatchService.threadUpdateIoCodeTempEntity(code);
|
|
|
}
|
|
|
}
|
|
|
addCodeResult.setOrderId(orderId);
|
|
|
transInoutService.genOrderDetailCode(orderEntity, genDetaiEntity);
|
|
|
return ResultVOUtils.success(addCodeResult);
|
|
|
}
|
|
|
|
|
|
//前端扫码提交(药品)
|
|
|
@RepeatSubmit()
|
|
|
@AuthRuleAnnotation("")
|
|
|
@PostMapping("warehouse/inout/drug/addOrderWeb")
|
|
|
@CusRedissonAnnotation(cacheName = RedissonCacheKey.WEB_ADD_CODE, key = {"#addOrderRequest.corpOrderId", "#addOrderRequest.code"}, timeOutMsg = "系统正在处理,请勿重复扫码")
|
|
|
@Log(title = "单据管理", businessType = BusinessType.INSERT)
|
|
|
public BaseResponse addDrugOrderWeb(@RequestBody AddOrderRequest addOrderRequest, BindingResult bindingResult) {
|
|
|
if (bindingResult.hasErrors()) {
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
|
}
|
|
|
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());
|
|
|
}
|
|
|
return addDrugOrder(addOrderRequest, udiEntity, code);
|
|
|
}
|
|
|
|
|
|
public void checkPrice(IoCodeTempEntity codeTempEntity, BasicBussinessTypeEntity bussinessTypeEntity, String
|
|
|
inBatch, List<IoCodeTempEntity> codeTempEntities) {
|
|
|
String priceFifo = systemParamConfigService.selectValueByParamKey("price_fifo");
|
|
|
if (IntUtil.value(priceFifo) > 0) {
|
|
|
//入库时添加入库批号
|
|
|
if (bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_PUT)) {
|
|
|
codeTempEntity.setInBatchNo(inBatch);
|
|
|
codeTempService.updateById(codeTempEntity);
|
|
|
} else {
|
|
|
ioAddInoutService.checkPrice(codeTempEntity, bussinessTypeEntity, codeTempEntities);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//校验条码完整性
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
//校验供应商是否配送此产品
|
|
|
public BaseResponse checkCorp(IoCodeTempEntity codeEnttity, BasicBussinessTypeEntity
|
|
|
bussinessTypeEntity, String unitFk) {
|
|
|
CompanyProductRelevanceRequest companyProductRelevanceRequest = new CompanyProductRelevanceRequest();
|
|
|
UdiEntity udiEntity = FilterUdiUtils.getUdi(codeEnttity.getCode());
|
|
|
companyProductRelevanceRequest.setNameCode(udiEntity.getUdi());
|
|
|
companyProductRelevanceRequest.setProductsType(codeEnttity.getProductType());
|
|
|
if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) {
|
|
|
companyProductRelevanceRequest.setUnitFk(unitFk);
|
|
|
List<UdiRlSupResponse> datas = udiRlSupService.filterUdiGp(companyProductRelevanceRequest);
|
|
|
if (datas.size() <= 0) {
|
|
|
return ResultVOUtils.error(500, "当前供应商不存在此配送产品!");
|
|
|
}
|
|
|
} else {
|
|
|
List<UdiRlSupResponse> datas = udiRlSupService.filterUdiGp(companyProductRelevanceRequest);
|
|
|
if (datas.size() <= 0) {
|
|
|
return ResultVOUtils.error(500, "此产品无指定供应商,请检查后添加!");
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
//校验产品ID唯一性
|
|
|
public BaseResponse checkRelId(IoCodeTempEntity codeEnttity, String unitFk) {
|
|
|
|
|
|
List<UdiRelevanceResponse> 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;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 检验药品ID唯一性
|
|
|
*
|
|
|
* @param codeEnttity
|
|
|
* @param unitFk
|
|
|
* @return
|
|
|
*/
|
|
|
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 BaseResponse checkSupId(BasicBussinessTypeEntity bussinessTypeEntity, IoCodeTempEntity
|
|
|
codeEnttity, String unitFk) {
|
|
|
String 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);
|
|
|
}
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 判断本单是否存在
|
|
|
*
|
|
|
* @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 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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* ]=
|
|
|
* 获取本单存在条码总和
|
|
|
*
|
|
|
* @param code
|
|
|
* @param codeEnttityList
|
|
|
* @return
|
|
|
*/
|
|
|
public IoCodeTempEntity isExitToatal(String code, List<IoCodeTempEntity> codeEnttityList) {
|
|
|
List<IoCodeTempEntity> codeTempEntities = isExitLocalList(code, codeEnttityList);
|
|
|
if (CollUtil.isNotEmpty(codeTempEntities)) {
|
|
|
IoCodeTempEntity codeTempEntity = codeTempEntities.get(0);
|
|
|
if (codeTempEntities.size() > 1) {
|
|
|
for (int i = 1; i < codeTempEntities.size(); i++) {
|
|
|
codeTempEntity.setCount(IntUtil.value(codeTempEntities.get(i).getCount()) + IntUtil.value(codeTempEntity.getCount()));
|
|
|
codeTempEntity.setReCount(IntUtil.value(codeTempEntities.get(i).getReCount()) + IntUtil.value(codeTempEntity.getReCount()));
|
|
|
}
|
|
|
}
|
|
|
return codeTempEntity;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
|
@GetMapping("admin/warehouse/inout/findErrorByOrderId")
|
|
|
public BaseResponse findErrorByOrderId(FilterCodeRequest filterCodeRequest) {
|
|
|
if (StrUtil.isEmpty(filterCodeRequest.getOrderId())) {
|
|
|
return ResultVOUtils.error(500, "单据号不能为空!");
|
|
|
}
|
|
|
List<IoCodeTempResponse> list = codeTempService.findCodeList(filterCodeRequest);
|
|
|
for (IoCodeTempResponse ioSplitCodeResponse : list) {
|
|
|
if (StrUtil.isEmpty(ioSplitCodeResponse.getGgxh())) {
|
|
|
ioSplitCodeResponse.setGgxh(ioSplitCodeResponse.getBzgg());
|
|
|
|
|
|
}
|
|
|
}
|
|
|
PageInfo<IoCodeTempResponse> pageInfo = new PageInfo<>(list);
|
|
|
PageSimpleResponse<IoCodeTempResponse> 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("绑定成功");
|
|
|
}
|
|
|
|
|
|
|
|
|
@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());
|
|
|
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction());
|
|
|
UdiRelevanceResponse udiRelevanceResponses = udiRelevanceService.selectByNameCode(codeTempEntity.getNameCode());
|
|
|
|
|
|
if (codeTempEntity.getMyCount() > 1) {
|
|
|
codeTempEntity.setCount(codeTempEntity.getMyCount() - 1);
|
|
|
codeTempEntity.setReCount(codeTempEntity.getMyReCount() - udiCalCountUtil.getActCount(bussinessTypeEntity, udiRelevanceResponses));
|
|
|
codeTempService.updateById(codeTempEntity);
|
|
|
} else {
|
|
|
codeTempService.deleteById(id);
|
|
|
}
|
|
|
|
|
|
//更新扫码详情
|
|
|
IoOrderDetailCodeEntity orderDetailCodeEntity = ioOrderDetailCodeService.findByUnique(orderEntity.getBillNo(), codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getPrice());
|
|
|
if (orderDetailCodeEntity != null) {
|
|
|
//扫码数量-1
|
|
|
int orderCount = IntUtil.value(orderDetailCodeEntity.getCount());
|
|
|
int orderReCount = IntUtil.value(orderDetailCodeEntity.getReCount());
|
|
|
if (orderCount > 1) {
|
|
|
orderDetailCodeEntity.setCount(orderCount - 1);
|
|
|
orderDetailCodeEntity.setReCount(orderReCount - udiCalCountUtil.getActCount(bussinessTypeEntity, udiRelevanceResponses));
|
|
|
ioOrderDetailCodeService.update(orderDetailCodeEntity);
|
|
|
} else {
|
|
|
ioOrderDetailCodeService.deleteById(orderDetailCodeEntity.getId());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
boolean r1 = orderDetailBizService.isExit(orderEntity.getBillNo());
|
|
|
boolean r2 = ioOrderDetailCodeService.isExit(orderEntity.getBillNo());
|
|
|
if (!r1 && !r2) {
|
|
|
if (StrUtil.isNotEmpty(orderDetailCodeEntity.getOrderIdFk()))
|
|
|
orderService.deleteByBillNo(orderDetailCodeEntity.getOrderIdFk());
|
|
|
}
|
|
|
|
|
|
orderEntity.setUpdateUser(getUserId() + "");
|
|
|
orderEntity.setUpdateTime(new Date());
|
|
|
orderService.update(orderEntity);
|
|
|
return ResultVOUtils.success("删除成功!");
|
|
|
}
|
|
|
|
|
|
|
|
|
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());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
@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<IoCodeTempEntity> 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.getReCount() * udiCalCountUtil.getActCount(codeTempEntity.getNameCode()));
|
|
|
codeTempService.updateById(codeTempEntity);
|
|
|
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(tempEntity.getAction());
|
|
|
BaseResponse invRes = null;
|
|
|
if (bussinessTypeEntity.isScanPreIn() && checkDiAttribute(bussinessTypeEntity, codeTempEntity.getRelId(), 2)) { //校验预验收库存
|
|
|
invRes = checkInvService.checkPreInInv(bussinessTypeEntity, codeTempEntity, true);
|
|
|
} else if (bussinessTypeEntity.isAdvancePreIn() && checkDiAttribute(bussinessTypeEntity, codeTempEntity.getRelId(), 3)) { //校验寄售库存
|
|
|
invRes = checkInvService.checkPreInv(bussinessTypeEntity, codeTempEntity, true);
|
|
|
} else if (bussinessTypeEntity.isAdvancePreIn() && checkDiAttribute(bussinessTypeEntity, codeTempEntity.getRelId(), 1)) {
|
|
|
invRes = checkInvService.checkInv(bussinessTypeEntity, codeTempEntity, true);
|
|
|
}
|
|
|
if (invRes != null) {
|
|
|
codeTempService.updateById(tempEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
|
|
|
|
|
|
int count = tempEntity.getCount() - codeTempEntity.getCount();
|
|
|
|
|
|
//更新扫码详情
|
|
|
IoOrderDetailCodeEntity orderDetailCodeEntity = ioOrderDetailCodeService.findByUnique(codeTempEntity.getOrderId(), codeTempEntity.getRelId(), codeTempEntity.getBatchNo(), codeTempEntity.getPrice());
|
|
|
if (orderDetailCodeEntity != null) {
|
|
|
//扫码数量-1
|
|
|
int orderCount = orderDetailCodeEntity.getCount();
|
|
|
orderDetailCodeEntity.setCount(orderCount - count);
|
|
|
|
|
|
int reCount = count * udiCalCountUtil.getActCount(codeTempEntity.getNameCode());
|
|
|
orderDetailCodeEntity.setReCount(IntUtil.value(orderDetailCodeEntity.getReCount()) - reCount);
|
|
|
ioOrderDetailCodeService.update(orderDetailCodeEntity);
|
|
|
}
|
|
|
int b = codeTempService.updateById(codeTempEntity);
|
|
|
|
|
|
|
|
|
if (b > 0)
|
|
|
return ResultVOUtils.success("修改成功");
|
|
|
else return ResultVOUtils.error(500, "修改失败!");
|
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
|
@PostMapping("warehouse/inout/checkTempCode")
|
|
|
public BaseResponse checkTempCode(@RequestBody IoCodeTempEntity codeTempEntity) {
|
|
|
|
|
|
Boolean falg = codeTempService.checkTempCode(codeTempEntity);
|
|
|
if (!falg) {
|
|
|
return ResultVOUtils.error(999, "该产品已存在,请勿重复录入");
|
|
|
}
|
|
|
return ResultVOUtils.success();
|
|
|
}
|
|
|
|
|
|
|
|
|
//pda扫码校验
|
|
|
//前端扫码提交
|
|
|
@RepeatSubmit()
|
|
|
@AuthRuleAnnotation("")
|
|
|
@PostMapping("warehouse/inout/pdaAddCode")
|
|
|
@Log(title = "单据管理", businessType = BusinessType.INSERT)
|
|
|
public BaseResponse pdaAddCode(@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<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());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//过期提醒:
|
|
|
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(605, "当前产品临近过期,距过期还剩" + time + "天,无法添加!");
|
|
|
return ResultVOUtils.error(505, "当前产品临近过期,距过期还剩" + time + "天,是否确定继续添加?");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
//校验预验收是否已存在
|
|
|
if (bussinessTypeEntity.getActionType() == ConstantStatus.ACTION_TYPE_PREIN && bussinessTypeEntity.getMainAction().equals(ConstantType.TYPE_PUT)) {
|
|
|
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 && bussinessTypeEntity.isPreInBack()) {//按单出库&& bussinessTypeEntity.isPreInBack()
|
|
|
String orderIds = addOrderRequest.getCheckPreInOrders();
|
|
|
if (StrUtil.isNotEmpty(orderIds)) {
|
|
|
String[] orderIdArray = orderIds.split(",");
|
|
|
List<String> 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, "未选择预验收入库单,请先选择预验收入库单!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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<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);
|
|
|
genDetaiEntity.setReCount(udiCalCountUtil.getActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
|
exitLocalEntity.setCount(exitLocalEntity.getMyCount() + 1);
|
|
|
exitLocalEntity.setReCount(exitLocalEntity.getMyCount() * udiCalCountUtil.getActCount(udiRelevanceResponses.get(0)));
|
|
|
|
|
|
|
|
|
if (!StringUtils.isBlank(exitLocalEntity.getSerialNo())) {
|
|
|
return ResultVOUtils.error(500, "重复扫码!");
|
|
|
}
|
|
|
|
|
|
BaseResponse invRes = null;
|
|
|
if (bussinessTypeEntity.isScanPreIn()) { //校验预验收库存
|
|
|
invRes = checkInvService.checkPreInInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
} else if (bussinessTypeEntity.isAdvancePreIn()) { //校验寄售库存
|
|
|
invRes = checkInvService.checkPreInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
} else {
|
|
|
invRes = checkInvService.checkInv(bussinessTypeEntity, genDetaiEntity, false);
|
|
|
}
|
|
|
if (invRes != null) {
|
|
|
return invRes;
|
|
|
}
|
|
|
|
|
|
|
|
|
if (bussinessTypeEntity.getCheckWebNew() == 1 && bussinessTypeEntity.isCheckEnable()) {
|
|
|
String errMsg = ioCheckInoutService.checkCode(genDetaiEntity);
|
|
|
if (errMsg != null) {
|
|
|
return ResultVOUtils.error(500, errMsg);
|
|
|
} else
|
|
|
codeTempService.updateById(exitLocalEntity);
|
|
|
} else if (bussinessTypeEntity.getCheckWebNew() == 2 && 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.setWarehouseCode(addOrderRequest.getCurSpaceCode());
|
|
|
codeEnttity.setPreSpaceCode(addOrderRequest.getPreCurSpaceCode());
|
|
|
codeEnttity.setPreInSpaceCode(addOrderRequest.getCheckPreInSpaceCode());
|
|
|
codeEnttity.setRelId(addOrderRequest.getRelId());
|
|
|
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, "当前上货只允许录入拆零产品!");
|
|
|
// }
|
|
|
//计算实际数量
|
|
|
codeEnttity.setReCount(IntUtil.value(codeEnttity.getMyReCount()) + 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 (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.isScanPreIn()) { //校验预验收库存
|
|
|
BaseResponse invRes = checkInvService.checkPreInInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
} else if (bussinessTypeEntity.isAdvancePreIn()) { //校验寄售库存
|
|
|
BaseResponse invRes = checkInvService.checkPreInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
} else {
|
|
|
BaseResponse invRes = checkInvService.checkInv(bussinessTypeEntity, codeEnttity, false);
|
|
|
if (invRes != null) {
|
|
|
deleteEmptyBillNo(orderEntity);
|
|
|
return invRes;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//是否边扫边校验
|
|
|
if (bussinessTypeEntity.getCheckWebNew() == 1 && bussinessTypeEntity.isCheckEnable()) {
|
|
|
String errMsg = ioCheckInoutService.checkCode(codeEnttity);
|
|
|
if (errMsg != null) {
|
|
|
return ResultVOUtils.error(500, errMsg);
|
|
|
} else
|
|
|
codeTempService.insert(codeEnttity);
|
|
|
} else if (bussinessTypeEntity.getCheckWebNew() == 2 && 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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param purType 1:入账库;2:预验收库;3:寄售库
|
|
|
*/
|
|
|
public boolean checkDiAttribute(BasicBussinessTypeEntity bussinessTypeEntity, UdiRelevanceResponse
|
|
|
udiRelevanceEntity, Integer purType) {
|
|
|
if (bussinessTypeEntity.getUseDyCount() == 2) {
|
|
|
if (IntUtil.value(udiRelevanceEntity.getPurType()) == IntUtil.value(purType)) {
|
|
|
return true;
|
|
|
} else
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
public boolean checkDiAttribute(BasicBussinessTypeEntity bussinessTypeEntity, Long relId, Integer purType) {
|
|
|
if (bussinessTypeEntity.getUseDyCount() == 2) {
|
|
|
if (udiRelevanceService.findPurType(relId) == IntUtil.value(purType)) {
|
|
|
return true;
|
|
|
} else
|
|
|
return false;
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 工位上货选入完成单据
|
|
|
*/
|
|
|
@AuthRuleAnnotation("")
|
|
|
@PostMapping("warehouse/inout/batchAddCodeByOrderFinish")
|
|
|
@Log(title = "单据管理", businessType = BusinessType.INSERT)
|
|
|
public BaseResponse batchAddCodeByOrderFinish(@RequestBody AddOrderCodeRequest addOrderCodeRequest, BindingResult bindingResult) {
|
|
|
|
|
|
if (bindingResult.hasErrors()) {
|
|
|
return ResultVOUtils.error(ResultEnum.PARAM_VERIFY_FALL, bindingResult.getFieldError().getDefaultMessage());
|
|
|
}
|
|
|
|
|
|
String orderFinishBillNo = addOrderCodeRequest.getOrderFinishBillNo();
|
|
|
// List<IoCollectCode> list = ioCollectCodeService.list(new LambdaUpdateWrapper<IoCollectCode>().eq(IoCollectCode::getBillNo, orderFinishBillNo));
|
|
|
CollectOrderBizRequest collectOrderBizRequest = new CollectOrderBizRequest();
|
|
|
collectOrderBizRequest.setOrderIdFk(orderFinishBillNo);
|
|
|
List<CollectOrderBizResponse> collectOrderBizResponses = ioCollectOrderBackupService.combieOrderDetail(collectOrderBizRequest);
|
|
|
if (CollUtil.isEmpty(collectOrderBizResponses)) return ResultVOUtils.error(500, "未找到已完成单的码明细");
|
|
|
List<String> codeList = new ArrayList<>();
|
|
|
collectOrderBizResponses.forEach(item -> {
|
|
|
String code = item.getFinishUdiCode();
|
|
|
if (StrUtil.isNotBlank(code) && code.contains(";")) {
|
|
|
List<String> partsList = Arrays.asList(code.split(";"));
|
|
|
codeList.addAll(partsList);
|
|
|
} else {
|
|
|
Integer reCountObj = item.getScanCount();
|
|
|
int reCount = reCountObj != null ? reCountObj : 0; // 如果reCountObj为null,则默认为0次迭代
|
|
|
for (int i = 0; i < reCount; i++) {
|
|
|
codeList.add(code);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
});
|
|
|
addOrderCodeRequest.setCodeList(codeList);
|
|
|
addOrderCodeRequest.setCorpOrderId(orderFinishBillNo);
|
|
|
|
|
|
AddCodeResult addCodeResult = new AddCodeResult();
|
|
|
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);
|
|
|
if (IntUtil.value(udiEntity.getProductType()) == 2) {
|
|
|
baseResponse = addDrugOrder(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);
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|