|
|
package com.glxp.api.controller.inout;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.glxp.api.annotation.CusRedissonAnnotation;
|
|
|
import com.glxp.api.constant.*;
|
|
|
import com.glxp.api.dao.inout.IoOrderDetailCodeDao;
|
|
|
import com.glxp.api.entity.basic.*;
|
|
|
import com.glxp.api.entity.collect.*;
|
|
|
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.collect.RelCodeDetailResponse;
|
|
|
import com.glxp.api.res.inout.*;
|
|
|
import com.glxp.api.service.collect.*;
|
|
|
import com.glxp.api.service.collect.RelCodeDetailService;
|
|
|
import com.glxp.api.service.inout.impl.IoCodeService;
|
|
|
import com.glxp.api.service.inv.impl.InvProductServiceNew;
|
|
|
import com.glxp.api.vo.basic.InvProductNewVo;
|
|
|
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.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
|
|
|
InvProductServiceNew invProductServiceNew;
|
|
|
@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
|
|
|
IoCollectOrderBizOriginService collectOrderBizOriginService;
|
|
|
@Resource
|
|
|
IoCollectOrderOriginService collectOrderOriginService;
|
|
|
@Resource
|
|
|
IoCollectOrderService collectOrderService;
|
|
|
@Resource
|
|
|
IoCollectCodeService ioCollectCodeService;
|
|
|
@Resource
|
|
|
IoSplitFifoInvService ioSplitFifoInvService;
|
|
|
|
|
|
@Resource
|
|
|
SysWorkplaceQueueService sysWorkplaceQueueService;
|
|
|
|
|
|
@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) {
|
|
|
//进行删除 重新匹配
|
|
|
collectOrderOriginService.remove(new LambdaQueryWrapper<IoCollectOrderOrigin>().eq(IoCollectOrderOrigin::getBillNo, ioCollectOrigin.getBillNo()));
|
|
|
collectOrderBizOriginService.remove(new LambdaQueryWrapper<IoCollectOrderBizOrigin>().eq(IoCollectOrderBizOrigin::getOrderIdFk, ioCollectOrigin.getBillNo()));
|
|
|
}
|
|
|
//=============================================//
|
|
|
//本地数据库 无此单据时 触发 用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) {
|
|
|
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 if (addEnterCodeRequest.getBusType().startsWith("SC")) {
|
|
|
BaseResponse baseResponse2 = collectOrderService.importSpmsUdi(collectOrderRequest);
|
|
|
if (baseResponse2.getCode() == 20000) {
|
|
|
collectOrder = collectOrderService.unionSearch(null, null, code);
|
|
|
//=============================================//
|
|
|
if (collectOrder != null) {
|
|
|
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;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
BaseResponse response = ResultVOUtils.error(501, "未找到匹配单据或单据存在未对照产品");
|
|
|
response.setData(code);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
BaseResponse response = ResultVOUtils.error(601, code);
|
|
|
response.setData(collectOrder);
|
|
|
return response;
|
|
|
}
|
|
|
|
|
|
BaseResponse response = ResultVOUtils.error(501, "未找到匹配单据");
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
UdiRelevanceResponse checkUdi = udiRelevanceService.selectByNameCode(udiEntity.getUdi());
|
|
|
if (checkUdi == null) {
|
|
|
return ResultVOUtils.error(500, "耗材字典不存在此产品!");
|
|
|
}
|
|
|
|
|
|
if (IntUtil.value(udiEntity.getProductType()) == 2) {
|
|
|
//药品
|
|
|
udiEntity.setCode(code);
|
|
|
AddEnterCodeResponse addEnterCodeResponse = setAddEnterCodeResponse(udiEntity, checkUdi);
|
|
|
return ResultVOUtils.success(addEnterCodeResponse);
|
|
|
}
|
|
|
|
|
|
if (StrUtil.isNotEmpty(udiEntity.getBatchNo())) {
|
|
|
if (code.endsWith("10" + udiEntity.getBatchNo())) {
|
|
|
code = code + "\u001D";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
|
|
AddEnterCodeResponse addEnterCodeResponse = setAddEnterCodeResponse(udiEntity, checkUdi);
|
|
|
return ResultVOUtils.success(addEnterCodeResponse);
|
|
|
} 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);
|
|
|
AddEnterCodeResponse addEnterCodeResponse = setAddEnterCodeResponse(udiEntity, checkUdi);
|
|
|
baseResponse.setData(addEnterCodeResponse);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
}
|
|
|
BaseResponse baseResponse = ResultVOUtils.error(502, "校验未完成,缺少" + lostMsg.substring(1));
|
|
|
udiEntity.setCode(code);
|
|
|
AddEnterCodeResponse addEnterCodeResponse = setAddEnterCodeResponse(udiEntity, checkUdi);
|
|
|
baseResponse.setData(addEnterCodeResponse);
|
|
|
return baseResponse;
|
|
|
}
|
|
|
|
|
|
|
|
|
public AddEnterCodeResponse setAddEnterCodeResponse(UdiEntity udiEntity, UdiRelevanceResponse checkUdi) {
|
|
|
AddEnterCodeResponse addEnterCodeResponse = new AddEnterCodeResponse();
|
|
|
BeanUtils.copyProperties(udiEntity, addEnterCodeResponse);
|
|
|
addEnterCodeResponse.setBzgg(checkUdi.getBzgg());
|
|
|
addEnterCodeResponse.setCpmctymc(checkUdi.getCpmctymc());
|
|
|
addEnterCodeResponse.setPrepnSpec(checkUdi.getPrepnSpec());
|
|
|
addEnterCodeResponse.setPrepnUnit(checkUdi.getPrepnUnit());
|
|
|
addEnterCodeResponse.setPackUnit(checkUdi.getPackUnit());
|
|
|
addEnterCodeResponse.setGgxh(checkUdi.getGgxh());
|
|
|
return addEnterCodeResponse;
|
|
|
}
|
|
|
|
|
|
|
|
|
@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");
|
|
|
if (hasMoreThanTwoPrefixes(codeList, prefixes.toArray(new String[0]))) {
|
|
|
//判断是否多段扫码
|
|
|
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 boolean hasMoreThanTwoPrefixes(List<String> codes, String[] prefixes) {
|
|
|
int uniquePrefixCount = 0;
|
|
|
boolean[] prefixFound = new boolean[prefixes.length];
|
|
|
for (String code : codes) {
|
|
|
for (int i = 0; i < prefixes.length; i++) {
|
|
|
if (code.startsWith(prefixes[i]) && !prefixFound[i]) {
|
|
|
prefixFound[i] = true;
|
|
|
uniquePrefixCount++;
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return uniquePrefixCount > 1;
|
|
|
}
|
|
|
|
|
|
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) {
|
|
|
try {
|
|
|
baseResponse = addDrugOrder(addOrderRequest, udiEntity, code);
|
|
|
} catch (JsonException e) {
|
|
|
if (e.getCode() == 507) {
|
|
|
baseResponse = ResultVOUtils.error(e.getCode(), e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
} 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;
|
|
|
@Resource
|
|
|
private IoOrderDetailCodeDao orderDetailCodeDao;
|
|
|
|
|
|
@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 (udiRelevanceResponse.getUseMaxLevel() != null && IntUtil.value(udiRelevanceResponse.getUseMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
|
|
|
if (udiRelevanceResponse.getUseMaxLevel() == null && IntUtil.value(udiRelevanceResponse.getPackLevel()) > 1) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getUseLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
if (udiRelevanceResponse.getDistributeMaxLevel() != null && IntUtil.value(udiRelevanceResponse.getDistributeMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
|
|
|
if (udiRelevanceResponse.getDistributeMaxLevel() == null && IntUtil.value(udiRelevanceResponse.getPackLevel()) > 1) {
|
|
|
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, "扫码重复或当前追溯码已存在草稿单据中!");
|
|
|
}
|
|
|
} else {
|
|
|
//校验工位库存
|
|
|
List<IoCodeTempEntity> codeTempEntities = codeTempService.findByOrderId(addOrderRequest.getBillNo());
|
|
|
for (IoCodeTempEntity codeTempEntity : codeTempEntities) {
|
|
|
//校验工位库存
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
codeTempEntity.setReCount(IntUtil.value(codeTempEntity.getMyReCount()) + udiCalCountUtil.getUseActCount(udiRelevanceResponse));
|
|
|
} else {
|
|
|
codeTempEntity.setReCount(IntUtil.value(codeTempEntity.getMyReCount()) + udiCalCountUtil.getCirActCount(udiRelevanceResponse));
|
|
|
}
|
|
|
if (fifoCodeEntity.getTotalCount() < codeTempEntity.getReCount()) {
|
|
|
return ResultVOUtils.error(500, "当前码库存不足!");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
//校验预验收是否已存在
|
|
|
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 = invProductServiceNew.selectCountByInBatch(exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), bussinessTypeEntity, exitLocalEntity.getInBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_OUT);
|
|
|
//2.获取当前批次入库数量
|
|
|
Integer inCount = invProductServiceNew.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) {
|
|
|
InvProductNewVo nextInvProduct = invProductServiceNew.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) {
|
|
|
UdiRelevanceResponse udiRelevanceResponse1 = udiRelevanceService.selectByNameCode(udiEntity.getUdi());
|
|
|
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);
|
|
|
codeEnttity.setPrice(udiRelevanceResponse1.getPrice());
|
|
|
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);
|
|
|
try {
|
|
|
transInoutService.genOrderDetailCode(orderEntity, genDetaiEntity);
|
|
|
} catch (JsonException e) {
|
|
|
if (e.getCode() == 507) {
|
|
|
return ResultVOUtils.error(e.getCode(), e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
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 (udiRelevanceResponse.getUseMaxLevel() != null && IntUtil.value(udiRelevanceResponse.getUseMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
|
|
|
if (udiRelevanceResponse.getUseMaxLevel() == null && IntUtil.value(udiRelevanceResponse.getPackLevel()) > 1) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
if (IntUtil.value(udiRelevanceResponse.getPackLevel()) < IntUtil.value(udiRelevanceResponse.getUseLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
if (udiRelevanceResponse.getDistributeMaxLevel() != null && IntUtil.value(udiRelevanceResponse.getDistributeMaxLevel()) < IntUtil.value(udiRelevanceResponse.getPackLevel())) {
|
|
|
return ResultVOUtils.error(500, "当前产品不支持采集该包装层级追溯码!");
|
|
|
}
|
|
|
|
|
|
if (udiRelevanceResponse.getDistributeMaxLevel() == null && IntUtil.value(udiRelevanceResponse.getPackLevel()) > 1) {
|
|
|
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, "当前药品追溯码已存在,且存在异常未处理!");
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isNotBlank(exitLocalEntity.getSerialNo())) {
|
|
|
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)));
|
|
|
}
|
|
|
|
|
|
//校验库存
|
|
|
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 = invProductServiceNew.selectCountByInBatch(exitLocalEntity.getRelId() + "", exitLocalEntity.getBatchNo(), bussinessTypeEntity, exitLocalEntity.getInBatchNo(), exitLocalEntity.getInvCode(), ConstantType.TYPE_OUT);
|
|
|
//2.获取当前批次入库数量
|
|
|
Integer inCount = invProductServiceNew.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) {
|
|
|
InvProductNewVo nextInvProduct = invProductServiceNew.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) {
|
|
|
if (codeTempService.ieExitRel(code, orderId)) {
|
|
|
return ResultVOUtils.error(500, "当前追溯码已上传关联关系,请勿重复扫码!");
|
|
|
}
|
|
|
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.setPrice(udiRelevanceResponse.getPrice());
|
|
|
codeEnttity.setProductType(2);
|
|
|
codeEnttity.setCount(1);
|
|
|
RelCodeDetailResponse codeRelEntity = relCodeDetailService.findByCode(code);
|
|
|
if (codeRelEntity != null) {
|
|
|
codeEnttity.setParentCode(codeRelEntity.getParentCode());
|
|
|
RelCodeDetail relCodeDetail = relCodeDetailService.getOneByCode(codeRelEntity.getParentCode());
|
|
|
if (relCodeDetail != null) {
|
|
|
codeEnttity.setGrantPaCode(relCodeDetail.getParentCode());
|
|
|
}
|
|
|
// if (StrUtil.isEmpty(codeEnttity.getBatchNo())) {
|
|
|
//当关联关系存在的时候 以关联关系的批次号为准
|
|
|
codeEnttity.setBatchNo(codeRelEntity.getBatchNo());
|
|
|
codeEnttity.setExpireDate(codeRelEntity.getMadeDate() + "");
|
|
|
codeEnttity.setExpireDate(codeRelEntity.getValidateDate() + "");
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
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, "当前供应商不存在此配送产品!");
|
|
|
}
|
|
|
if (!(bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_RETURN) || bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_OUT))) {
|
|
|
//校验供应商是否配送此产品
|
|
|
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.setWorkPlaceQueueCode(addOrderRequest.getWorkPlaceQueueCode());
|
|
|
orderEntity.setProductType(2);
|
|
|
orderService.insertOrder(orderEntity);
|
|
|
}
|
|
|
|
|
|
if (bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_OUT)) {
|
|
|
// 判断货位里面是否有相同产品
|
|
|
if (orderEntity != null && StrUtil.isNotEmpty(orderEntity.getWorkPlaceQueueCode())) {
|
|
|
SysWorkplaceQueue workplaceQueue = sysWorkplaceQueueService.getOne(new LambdaQueryWrapper<SysWorkplaceQueue>()
|
|
|
.eq(SysWorkplaceQueue::getCode, orderEntity.getWorkPlaceQueueCode()));
|
|
|
if (workplaceQueue != null) {
|
|
|
//判断槽位产品是否一样
|
|
|
if (StrUtil.isNotBlank(workplaceQueue.getRelId())) {
|
|
|
if (!udiRelevanceResponse.getId().equals(Long.parseLong(workplaceQueue.getRelId()))) {
|
|
|
// orderService.deleteByBillNo(orderId);
|
|
|
UdiRelevanceResponse udiRelevanceResponse1 = udiRelevanceService.selectByRelId(workplaceQueue.getRelId());
|
|
|
return ResultVOUtils.error(507, "上货产品不符!" + "当前取货槽已被" + udiRelevanceResponse1.getCpmctymc() + "使用");
|
|
|
}
|
|
|
} else {
|
|
|
//判断产品是否已经绑定其他槽位
|
|
|
// SysWorkplaceQueue workplaceQueue1 = sysWorkplaceQueueService.getOne(new LambdaQueryWrapper<SysWorkplaceQueue>().eq(SysWorkplaceQueue::getRelId, udiRelevanceResponse.getId()));
|
|
|
// if (workplaceQueue1 != null) {
|
|
|
// if (!orderEntity.getWorkPlaceQueueCode().equals(workplaceQueue1.getCode())) {
|
|
|
//// orderService.deleteByBillNo(orderId);
|
|
|
// return ResultVOUtils.error(507, "当前产品已绑定在" + workplaceQueue1.getCode() + "取货槽");
|
|
|
// }
|
|
|
// }
|
|
|
}
|
|
|
} else {
|
|
|
return ResultVOUtils.error(500, "取货槽位不存在!");
|
|
|
}
|
|
|
if (orderEntity != null && CollUtil.isNotEmpty(codeEnttitys)) {
|
|
|
boolean isSame = false;
|
|
|
for (IoCodeTempEntity ioOrderDetailCodeEntity : codeEnttitys) {
|
|
|
if (ioOrderDetailCodeEntity.getRelId().equals(udiRelevanceResponse.getId())) {
|
|
|
isSame = true;
|
|
|
}
|
|
|
}
|
|
|
if (!isSame)
|
|
|
// orderService.deleteByBillNo(orderId);
|
|
|
return ResultVOUtils.error(507, "上货产品不符!");
|
|
|
}
|
|
|
//校验完成 获取当前槽位 绑定产品
|
|
|
SysWorkplaceQueue sysWorkplaceQueue = sysWorkplaceQueueService.getOne(new LambdaQueryWrapper<SysWorkplaceQueue>()
|
|
|
.eq(SysWorkplaceQueue::getCode, orderEntity.getWorkPlaceQueueCode()));
|
|
|
if (sysWorkplaceQueue.getRelId() == null) {
|
|
|
sysWorkplaceQueue.setRelId(udiRelevanceResponse.getId() + "");
|
|
|
sysWorkplaceQueueService.updateById(sysWorkplaceQueue);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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表
|
|
|
updateRelCode(bussinessTypeEntity, code);
|
|
|
// 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表
|
|
|
updateRelCode(bussinessTypeEntity, code);
|
|
|
// relCodeBatchService.threadUpdateIoCodeTempEntity(code);
|
|
|
} else {
|
|
|
checkPrice(codeEnttity, bussinessTypeEntity, inBatch, codeEnttitys);
|
|
|
codeTempService.insert(codeEnttity);
|
|
|
updateRelCode(bussinessTypeEntity, code);
|
|
|
|
|
|
// 查询是否存在药品关联信息 后将结果更新至 temp表
|
|
|
// relCodeBatchService.threadUpdateIoCodeTempEntity(code);
|
|
|
}
|
|
|
}
|
|
|
addCodeResult.setOrderId(orderId);
|
|
|
transInoutService.genOrderDetailCode(orderEntity, genDetaiEntity);
|
|
|
return ResultVOUtils.success(addCodeResult);
|
|
|
}
|
|
|
|
|
|
|
|
|
public void updateRelCode(BasicBussinessTypeEntity bussinessTypeEntity, String code) {
|
|
|
if (!(bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_OUT) || bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_RETURN)))
|
|
|
relCodeBatchService.threadUpdateIoCodeTempEntity(code);
|
|
|
}
|
|
|
|
|
|
@Resource
|
|
|
RelCodeDetailService relCodeDetailService;
|
|
|
|
|
|
//前端扫码提交(药品)
|
|
|
@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());
|
|
|
}
|
|
|
RelCodeDetailResponse codeRelEntity = null;
|
|
|
if (StrUtil.isEmpty(udiEntity.getBatchNo())) {
|
|
|
IoCodeLostEntity codeLostEntity = codeLostService.findByCode(code);
|
|
|
if (codeLostEntity != null) {
|
|
|
udiEntity.setBatchNo(codeLostEntity.getBatchNo());
|
|
|
udiEntity.setProduceDate(codeLostEntity.getProduceDate());
|
|
|
udiEntity.setExpireDate(codeLostEntity.getExpireDate());
|
|
|
} else {
|
|
|
codeRelEntity = relCodeDetailService.findByCode(code);
|
|
|
if (codeRelEntity != null) {
|
|
|
udiEntity.setBatchNo(codeRelEntity.getBatchNo());
|
|
|
udiEntity.setProduceDate(MsDateUtil.formatDate(codeRelEntity.getMadeDate(), "yyMMdd"));
|
|
|
udiEntity.setExpireDate(MsDateUtil.formatDate(codeRelEntity.getValidateDate(), "yyMMdd"));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
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绑定多个产品西信息
|
|
|
String code = ";";
|
|
|
for (UdiRelevanceResponse udiRelevanceResponse : udiRelevanceEntities) {
|
|
|
code = code + udiRelevanceResponse.getMainId() + ";";
|
|
|
}
|
|
|
BaseResponse baseResponse = ResultVOUtils.error(502, "层级编码绑定多个第三方产品ID" + code.substring(1) + ",请检查后重试");
|
|
|
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) {
|
|
|
|
|
|
if ((bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_OUT) || bussinessTypeEntity.getAction().equals(ConstantType.SPLIT_RETURN)))
|
|
|
return null;
|
|
|
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());
|
|
|
|
|
|
}
|
|
|
}
|
|
|
if (list.size() == 0 || list == null) {
|
|
|
return codeTempService.findCodes(filterCodeRequest);
|
|
|
}
|
|
|
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码异常,未录入!");
|
|
|
}
|
|
|
codeTempService.removeCodeById(codeTempEntity);
|
|
|
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()));
|
|
|
List<UdiRelevanceResponse> udiRelevanceResponses = udiRelevanceService.selectGroupByNameCode(codeTempEntity.getNameCode(), null);
|
|
|
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(codeTempEntity.getAction());
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
codeTempEntity.setReCount(codeTempEntity.getMyCount() * udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
|
|
|
} else {
|
|
|
codeTempEntity.setReCount(codeTempEntity.getMyCount() * udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
|
|
|
}
|
|
|
|
|
|
codeTempService.updateById(codeTempEntity);
|
|
|
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;
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
reCount = count * udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0));
|
|
|
} else {
|
|
|
reCount = count * udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0));
|
|
|
}
|
|
|
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);
|
|
|
|
|
|
if (bussinessTypeEntity.isUse()) {
|
|
|
genDetaiEntity.setReCount(udiCalCountUtil.getUseActCount(udiRelevanceResponses.get(0)));
|
|
|
} else {
|
|
|
genDetaiEntity.setReCount(udiCalCountUtil.getCirActCount(udiRelevanceResponses.get(0)));
|
|
|
}
|
|
|
|
|
|
exitLocalEntity.setCount(exitLocalEntity.getMyCount() + 1);
|
|
|
// exitLocalEntity.setReCount(exitLocalEntity.getMyCount() * udiCalCountUtil.getActCount(udiRelevanceResponses.get(0)));
|
|
|
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 (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, "当前上货只允许录入拆零产品!");
|
|
|
// }
|
|
|
//计算实际数量
|
|
|
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());
|
|
|
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 (code != null && code.length() > 0 && code.charAt(0) == ',') {
|
|
|
code = code.substring(1);
|
|
|
}
|
|
|
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++) {
|
|
|
if (StrUtil.isNotBlank(code)) {
|
|
|
codeList.add(code);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
});
|
|
|
List<String> codeOnelist = new ArrayList();
|
|
|
// 检查该码的所有一级码并且加入进去
|
|
|
for (String code : codeList) {
|
|
|
List<RelCodeDetail> list = relCodeDetailService.getAllNextOne(code);
|
|
|
if (list != null && list.size() > 0) {
|
|
|
for (RelCodeDetail relCodeDetail : list) {
|
|
|
codeOnelist.add(relCodeDetail.getCurCode());
|
|
|
}
|
|
|
} else {
|
|
|
codeOnelist.add(code);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
addOrderCodeRequest.setCodeList(codeOnelist);
|
|
|
addOrderCodeRequest.setCorpOrderId(orderFinishBillNo);
|
|
|
CollectOrderBizResponse response = collectOrderBizResponses.get(0);
|
|
|
//TODO 这里是获取已完成订单的 批次号
|
|
|
if (response.getBatchNo() != null) {
|
|
|
addOrderCodeRequest.setBatchNo(response.getBatchNo());
|
|
|
addOrderCodeRequest.setProduceDate(response.getProductDate());
|
|
|
addOrderCodeRequest.setExpireDate(response.getExpireDate());
|
|
|
}
|
|
|
|
|
|
AddCodeResult addCodeResult = new AddCodeResult();
|
|
|
if (CollUtil.isEmpty(codeOnelist))
|
|
|
return ResultVOUtils.error(500, "追溯码不能为空");
|
|
|
List<VailCodeResultResponse> vailCodeResultResponses = new ArrayList<>();
|
|
|
for (String code : codeOnelist) {
|
|
|
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) {
|
|
|
try {
|
|
|
baseResponse = addDrugOrder(addOrderRequest, udiEntity, code);
|
|
|
} catch (JsonException e) {
|
|
|
if (e.getCode() == 507) {
|
|
|
baseResponse = ResultVOUtils.error(e.getCode(), e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} 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);
|
|
|
}
|
|
|
|
|
|
@AuthRuleAnnotation("")
|
|
|
@PostMapping("warehouse/inout/deleteCodesTempBycodes")
|
|
|
@Log(title = "单据管理", businessType = BusinessType.DELETE)
|
|
|
public BaseResponse deleteCodesTempByCodes(@RequestBody AddEnterCodeRequest addEnterCodeRequest) {
|
|
|
List<String> codeList = addEnterCodeRequest.getCodeList();
|
|
|
String orderId = addEnterCodeRequest.getOrderId();
|
|
|
IoOrderEntity order = orderService.findByBillNo(orderId);
|
|
|
if (order == null)
|
|
|
return ResultVOUtils.error(500, "单据不存在");
|
|
|
if (CollUtil.isEmpty(codeList))
|
|
|
return ResultVOUtils.error(500, "追溯码不能为空");
|
|
|
//器械的码 可能会是一样的
|
|
|
List<IoCodeTempEntity> ioCodeTempEntities = codeTempService.selectByCodes(codeList, orderId);
|
|
|
if (CollUtil.isEmpty(ioCodeTempEntities))
|
|
|
return ResultVOUtils.error(500, "当前追溯码不存在");
|
|
|
for (IoCodeTempEntity codeTempEntity : ioCodeTempEntities) {
|
|
|
codeTempService.removeCodeById(codeTempEntity);
|
|
|
}
|
|
|
return ResultVOUtils.success("删除成功!");
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|