You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
udi-spms-java/src/main/java/com/glxp/api/service/inout/IoAddInoutService.java

691 lines
34 KiB
Java

2 years ago
package com.glxp.api.service.inout;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
2 years ago
import com.glxp.api.common.enums.ResultEnum;
import com.glxp.api.common.res.BaseResponse;
import com.glxp.api.common.util.ResultVOUtils;
import com.glxp.api.constant.Constant;
import com.glxp.api.constant.ConstantStatus;
import com.glxp.api.dao.inout.IoOrderDetailCodeDao;
2 years ago
import com.glxp.api.entity.basic.BasicBussinessTypeEntity;
import com.glxp.api.entity.basic.BasicCorpEntity;
import com.glxp.api.entity.basic.UdiEntity;
import com.glxp.api.entity.basic.UdiRlSupEntity;
import com.glxp.api.entity.inout.*;
import com.glxp.api.entity.inv.InvProductDetailEntity;
import com.glxp.api.entity.system.SystemParamConfigEntity;
import com.glxp.api.req.basic.FilterCompanyProductRelevanceRequest;
import com.glxp.api.entity.inout.PdaCodeEntity;
import com.glxp.api.req.inout.PostOrderRequest;
import com.glxp.api.res.basic.UdiRelevanceResponse;
import com.glxp.api.service.basic.BasicCorpService;
import com.glxp.api.service.basic.IBasicBussinessTypeService;
import com.glxp.api.service.basic.UdiRelevanceService;
import com.glxp.api.service.basic.UdiRlSupService;
import com.glxp.api.service.inv.InvProductDetailService;
import com.glxp.api.service.system.SystemParamConfigService;
import com.glxp.api.util.CustomUtil;
import com.glxp.api.util.DateUtil;
import com.glxp.api.util.GennerOrderUtils;
import com.glxp.api.util.OrderNoTypeBean;
import com.glxp.api.util.udi.FilterUdiUtils;
import com.glxp.api.util.udi.UdiCalCountUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Service
public class IoAddInoutService {
@Resource
private IBasicBussinessTypeService basicBussinessTypeService;
@Resource
private IoOrderService orderService;
@Resource
GennerOrderUtils gennerOrderUtils;
@Resource
IoCodeService codeService;
@Resource
IoCodeTempService codeTempService;
@Resource
UdiRlSupService udiRlSupService;
@Resource
IoOrderDetailCodeService orderDetailCodeService;
@Resource
UdiRelevanceService udiRelevanceService;
@Resource
InvProductDetailService invProductDetailService;
@Resource
BasicCorpService basicCorpService;
@Resource
IoCheckInoutService ioCheckInoutService;
@Resource
SystemParamConfigService systemParamConfigService;
@Resource
IoOrderDetailBizService orderDetailBizService;
@Resource
private IoOrderDetailCodeDao orderDetailCodeDao;
2 years ago
//新增扫码单据处理
public void dealProcess(IoOrderEntity orderEntity) {
orderEntity.setErrMsg("正在处理!");
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_PROCESSING);
orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_POST);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
List<IoOrderEntity> orderEntities = orderService.isExitRepeat(orderEntity.getCorpOrderId(), orderEntity.getBillNo());
if (CollUtil.isNotEmpty(orderEntities)) {
orderEntity.setErrMsg("单据重复上传");
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
return;
}
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(orderEntity.getAction());
if (bussinessTypeEntity == null) {
orderEntity.setErrMsg("单据类型不存在");
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
return;
}
if (StrUtil.isEmpty(orderEntity.getFromCorp()) && StrUtil.isEmpty(orderEntity.getFromInvCode())) {
orderEntity.setErrMsg("未选择往来单位");
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
return;
} else if (StrUtil.isNotEmpty(orderEntity.getFromCorp())) {
if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_INPUT && bussinessTypeEntity.isGenUnit()) {
BasicCorpEntity basicCorpEntity = basicCorpService.selectByName(orderEntity.getFromCorp());
if (basicCorpEntity == null) {
basicCorpEntity = new BasicCorpEntity();
basicCorpEntity.setErpId(CustomUtil.getUnitId());
basicCorpEntity.setCorpType(ConstantStatus.CORP_SICK);
basicCorpEntity.setOutType(ConstantStatus.CORP_SICK_SICK);
basicCorpEntity.setName(orderEntity.getFromCorp());
}
orderEntity.setFromCorp(basicCorpEntity.getErpId());
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
basicCorpService.insertBasicUnitMaintain(basicCorpEntity);
}
}
if (StrUtil.isEmpty(orderEntity.getInvCode())) {
orderEntity.setErrMsg("未选择当前仓库信息");
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
return;
}
List<IoCodeTempEntity> filterList = codeTempService.findByOrderId(orderEntity.getBillNo());
List<IoCodeTempEntity> insertList = new ArrayList<>();
for (int j = 0; j < filterList.size(); j++) {
IoCodeTempEntity warehouseEntity = filterList.get(j);
String result = checkOrderRepeatCode(warehouseEntity, filterList);
if (result == null) {
insertList.add(warehouseEntity);
} else {
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
insertList.clear();
return;
}
if (bussinessTypeEntity.isCodeFillCheck()) {
//三期校验
String checkOriginMsg = checkOriginCode(warehouseEntity);
if (StrUtil.isNotEmpty(checkOriginMsg)) {
orderEntity.setErrMsg(checkOriginMsg);
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
insertList.clear();
return;
}
2 years ago
}
2 years ago
//产品是否已维护已关联
if ((warehouseEntity.getRelId() == null)) {
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderEntity.setErrMsg("udi码" + warehouseEntity.getCode() + "上传时对照数据丢失,请选择对!");
orderService.update(orderEntity);
return;
}
//产品是否指定供应商
if (StrUtil.isEmpty(warehouseEntity.getSupId())) {
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderEntity.setErrMsg("udi码" + warehouseEntity.getCode() + "未指定供应商!");
orderService.update(orderEntity);
return;
}
//校验是否是当前供应商
if (bussinessTypeEntity.getCorpType() == ConstantStatus.CORP_TYPE_OUT) {
UdiRlSupEntity udiRlSupEntity = udiRlSupService.findByUdiRlIdUnitFk(warehouseEntity.getRelId() + "", orderEntity.getFromCorp());
if (udiRlSupEntity == null) {
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderEntity.setErrMsg("udi码" + warehouseEntity.getCode() + "当前供应商不存在此配送产品");
orderService.update(orderEntity);
return;
}
}
//产品是否可以以使用单元入库
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectGroupById(warehouseEntity.getRelId());
if (udiRelevanceResponse == null) {
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderEntity.setErrMsg("udi码" + warehouseEntity.getCode() + "该产品信息未维护");
orderService.update(orderEntity);
return;
} else if (!udiRelevanceResponse.getUseDy() && udiRelevanceResponse.getDiType() == ConstantStatus.DITYPE_SYDY) {
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderEntity.setErrMsg("udi码" + warehouseEntity.getCode() + "该产品不允许以使用单元入库");
orderService.update(orderEntity);
return;
}
}
if (CollUtil.isNotEmpty(insertList)) {
//生成扫码单据详情
if (!orderDetailCodeService.isExit(orderEntity.getBillNo())) {
for (IoCodeTempEntity codeTempEntity : insertList) {
genOrderDetailCode(orderEntity, codeTempEntity);
}
}
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK);
orderEntity.setUpdateTime(new Date());
orderEntity.setErrMsg("");
orderService.update(orderEntity);
} else {
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderEntity.setErrMsg("未添加UDI码");
orderService.update(orderEntity);
}
}
//新增业务单据处理
public void dealBusProcess(IoOrderEntity orderEntity) {
orderEntity.setErrMsg("正在处理!");
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_PROCESSING);
orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_POST);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
List<IoOrderEntity> orderEntities = orderService.isExitRepeat(orderEntity.getCorpOrderId(), orderEntity.getBillNo());
if (CollUtil.isNotEmpty(orderEntities)) {
orderEntity.setErrMsg("单据重复上传");
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
return;
}
if (StrUtil.isEmpty(orderEntity.getFromCorp()) && StrUtil.isEmpty(orderEntity.getFromInvCode())) {
orderEntity.setErrMsg("未选择往来单位");
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
return;
}
if (StrUtil.isEmpty(orderEntity.getInvCode())) {
orderEntity.setErrMsg("未选择当前仓库信息");
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
return;
}
String errMsg = "";
List<IoOrderDetailBizEntity> orderDetailBizEntities = orderDetailBizService.findByOrderId(orderEntity.getBillNo());
if (CollUtil.isNotEmpty(orderDetailBizEntities)) {
for (IoOrderDetailBizEntity orderDetailBizEntity : orderDetailBizEntities) {
if (StrUtil.isEmpty(orderDetailBizEntity.getSupId())) {
errMsg = errMsg + orderDetailBizEntity.getCoName() + "未绑定供应商;";
}
if (orderDetailBizEntity.getBindRlFk() == null) {
errMsg = errMsg + orderDetailBizEntity.getCoName() + "未绑定耗材字典编码;";
}
}
}
if (StrUtil.isNotEmpty(errMsg)) {
orderEntity.setErrMsg(errMsg);
orderEntity.setStatus(ConstantStatus.ORDER_STATS_ERROR);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
return;
}
orderEntity.setStatus(ConstantStatus.ORDER_STATUS_CHECK);
orderEntity.setDealStatus(ConstantStatus.ORDER_DEAL_POST);
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
return;
}
//生成扫码单据详情
public void genOrderDetailCode(IoOrderEntity orderEntity, IoCodeTempEntity codeTempEntity) {
List<IoOrderDetailCodeEntity> ioOrderDetailCodeEntities = orderDetailCodeDao.selectList(new QueryWrapper<IoOrderDetailCodeEntity>().select("id", "count", "reCount", "bindRlFk", "batchNo").eq("orderIdFk", orderEntity.getBillNo()));
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectSupGroupById(codeTempEntity.getRelId());
// UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectGroupById(codeTempEntity.getRelId());
2 years ago
if (CollUtil.isEmpty(ioOrderDetailCodeEntities)) {
orderDetailCodeService.insert(buildEntity(orderEntity, codeTempEntity, udiRelevanceResponse));
} else {
boolean isUpdate = false;
for (IoOrderDetailCodeEntity orderDetailCodeEntity : ioOrderDetailCodeEntities) {
if (orderDetailCodeEntity.getBindRlFk().longValue() == udiRelevanceResponse.getId().longValue()
&&
StrUtil.trimToEmpty(orderDetailCodeEntity.getBatchNo()).equals(StrUtil.trimToEmpty(codeTempEntity.getBatchNo()))) {
orderDetailCodeEntity.setCount(orderDetailCodeEntity.getCount() + codeTempEntity.getMyCount());
orderDetailCodeEntity.setReCount(orderDetailCodeEntity.getReCount() + codeTempEntity.getMyReCount());
UpdateWrapper<IoOrderDetailCodeEntity> updateWrapper = new UpdateWrapper<>();
updateWrapper.set("count", orderDetailCodeEntity.getCount()).set("reCount", orderDetailCodeEntity.getReCount());
orderDetailCodeDao.updateCount(orderDetailCodeEntity);
2 years ago
isUpdate = true;
break;
}
}
if (!isUpdate) {
orderDetailCodeService.insert(buildEntity(orderEntity, codeTempEntity, udiRelevanceResponse));
}
}
}
//平衡补单
public BaseResponse supplementOrder(String orderId) {
IoOrderEntity order = orderService.findByBillNo(orderId);
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(order.getAction());
if (StrUtil.isBlank(bussinessTypeEntity.getSupplementOrderType())) {
2 years ago
// return ResultVOUtils.error(ResultEnum.valueOf("此类型单据不可补单"));
return ResultVOUtils.error(ResultEnum.NOT_NETWORK, "此类型单据不可补单");
2 years ago
}
IoOrderEntity supplementOrder = new IoOrderEntity();
BeanUtil.copyProperties(order, supplementOrder);
//生成补单单号,互填单号
String supplementOrderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd"));
supplementOrder.setSupplementNo(orderId);
order.setSupplementNo(supplementOrderNo);
supplementOrder.setBillNo(supplementOrderNo);
supplementOrder.setCorpOrderId(CustomUtil.getId() + "x");
//修改状态
SystemParamConfigEntity systemParamConfigEntity = systemParamConfigService.selectByParamKey("additional_auto_submit");
if ("1".equals(systemParamConfigEntity.getParamValue())) {
supplementOrder.setStatus(ConstantStatus.ORDER_STATUS_PROCESS); //设置状态为补录单据
} else {
supplementOrder.setStatus(ConstantStatus.ORDER_STATUS_ADDITIONAL); //设置状态为补录单据
}
//交换往来信息
supplementOrder.setFromDeptCode(order.getDeptCode());
supplementOrder.setFromInvCode(order.getInvCode());
supplementOrder.setInvCode(order.getFromInvCode());
supplementOrder.setDeptCode(order.getFromDeptCode());
supplementOrder.setFromType(ConstantStatus.FROM_PEACE_CHANGE);
//设置往来信息
BasicBussinessTypeEntity supplementType = basicBussinessTypeService.findByAction(bussinessTypeEntity.getSupplementOrderType());
supplementOrder.setMainAction(supplementType.getMainAction());
supplementOrder.setAction(supplementType.getAction());
supplementOrder.setBusType(supplementType.getBusType());
2 years ago
//复制码表
List<IoCodeEntity> codes = codeService.findByOrderId(orderId);
List<IoCodeTempEntity> supplementCodes = new ArrayList<>();
codes.forEach(
code -> {
IoCodeTempEntity supplementCode = new IoCodeTempEntity();
BeanUtil.copyProperties(code, supplementCode);
supplementCode.setId(null);
supplementCode.setInvCode(order.getFromInvCode());
supplementCode.setDeptCode(order.getFromDeptCode());
supplementCode.setOrderId(supplementOrderNo);
supplementCode.setAction(supplementType.getAction());
supplementCode.setMainAction(supplementType.getMainAction());
supplementCodes.add(supplementCode);
}
);
//更新数据
orderService.insertOrder(supplementOrder);
orderService.update(order);
codeTempService.insertBatch(supplementCodes);
dealProcess(supplementOrder);
if (!ioCheckInoutService.checkManual(supplementOrder.getBillNo())) {
ioCheckInoutService.check(supplementOrder.getBillNo());
}
return ResultVOUtils.success();
}
//手持终端上传生成扫码单据
public void creatOrderByPda(PostOrderRequest postOrderRequest) {
List<PostOrderRequest.PostOrder> postOrders = postOrderRequest.getPostOrders();
if (postOrders != null && postOrders.size() > 0) {
for (int i = 0; i < postOrders.size(); i++) {
PostOrderRequest.PostOrder postOrder = postOrders.get(i);
//创建单据
PdaOrderEntity pdaOrderEntity = postOrder.getOrderBean();
IoOrderEntity orderEntity = null;
if (StrUtil.isNotEmpty(pdaOrderEntity.getDocid())) {
orderEntity = orderService.findByBillNo(pdaOrderEntity.getDocid());
}
if (orderEntity != null) {
//已包含业务单据校验
orderEntity.setUpdateUser(postOrderRequest.getUserId() + "");
orderEntity.setUpdateTime(new Date());
orderService.update(orderEntity);
List<PdaCodeEntity> pdaCodeEntities = postOrder.getCodes();
if (pdaCodeEntities != null && pdaCodeEntities.size() > 0) {
PdaCodeEntity pdaCodeEntity = pdaCodeEntities.get(0);
//写入条码
List<IoCodeTempEntity> ioCodeEnttities = new ArrayList<>();
for (int index = 0; index < pdaCodeEntities.size(); index++) {
IoCodeTempEntity codeEnttity = new IoCodeTempEntity();
BeanUtils.copyProperties(pdaCodeEntities.get(index), codeEnttity);
codeEnttity.setAction(orderEntity.getAction());
codeEnttity.setMainAction(orderEntity.getMainAction());
codeEnttity.setDeptCode(orderEntity.getDeptCode());
codeEnttity.setOrderId(orderEntity.getBillNo());
codeEnttity.setInvCode(orderEntity.getInvCode());
codeEnttity.setReCount(codeEnttity.getCount() * udiCalCountUtil.getActCount(codeEnttity.getNameCode()));
2 years ago
codeEnttity.setUpdateTime(new Date());
codeEnttity.setCreateTime(DateUtil.parseDate(pdaCodeEntity.getActDate()));
ioCodeEnttities.add(codeEnttity);
}
codeTempService.insertBatch(ioCodeEnttities);
dealProcess(orderEntity);
if (!ioCheckInoutService.checkManual(orderEntity.getBillNo())) {
ioCheckInoutService.check(orderEntity.getBillNo());
}
}
} else {
//创建新单据
BasicBussinessTypeEntity bussinessTypeEntity = basicBussinessTypeService.findByAction(pdaOrderEntity.getType());
String orderNo = gennerOrderUtils.createScOrderNo(new OrderNoTypeBean(Constant.SCAN_ORDER + StrUtil.trimToEmpty(bussinessTypeEntity.getPrefix()), "yyyyMMdd"));
IoOrderEntity orderSaveRequest = new IoOrderEntity();
orderSaveRequest.setBillNo(orderNo);
orderSaveRequest.setMainAction(pdaOrderEntity.getInout());
orderSaveRequest.setAction(pdaOrderEntity.getType());
orderSaveRequest.setCorpOrderId(pdaOrderEntity.getOrder());
orderSaveRequest.setFromCorp(pdaOrderEntity.getFromCorpID());
orderSaveRequest.setCustomerId(postOrderRequest.getCustomerId());
orderSaveRequest.setFromDeptCode(pdaOrderEntity.getFromDeptCode());
orderSaveRequest.setFromInvCode(pdaOrderEntity.getFromInvCode());
orderSaveRequest.setDeptCode(pdaOrderEntity.getDeptCode());
orderSaveRequest.setInvCode(pdaOrderEntity.getInvCode());
orderSaveRequest.setStatus(ConstantStatus.ORDER_STATUS_PROCESS);
orderSaveRequest.setDealStatus(ConstantStatus.ORDER_DEAL_POST);
orderSaveRequest.setCreateUser(postOrderRequest.getUserId() + "");
orderSaveRequest.setUpdateUser(postOrderRequest.getUserId() + "");
orderSaveRequest.setUpdateTime(new Date());
orderSaveRequest.setBusType(bussinessTypeEntity.getBusType());
2 years ago
orderSaveRequest.setOrderType(ConstantStatus.ORDER_TYPE_SCAN);
if (postOrder.getErpOrders() != null && postOrder.getErpOrders().size() > 0)
orderSaveRequest.setFromType(ConstantStatus.FROM_PDAED);
else
orderSaveRequest.setFromType(ConstantStatus.FROM_PDAUN);
List<PdaCodeEntity> pdaCodeEntities = postOrder.getCodes();
if (pdaCodeEntities != null && pdaCodeEntities.size() > 0) {
PdaCodeEntity pdaCodeEntity = pdaCodeEntities.get(0);
if (pdaCodeEntity.getActDate() != null) {
orderSaveRequest.setCreateTime(DateUtil.parseDate(pdaCodeEntity.getActDate()));
}
//写入条码
List<IoCodeTempEntity> ioCodeEnttities = new ArrayList<>();
for (int index = 0; index < pdaCodeEntities.size(); index++) {
IoCodeTempEntity codeEnttity = new IoCodeTempEntity();
BeanUtils.copyProperties(pdaCodeEntities.get(index), codeEnttity);
codeEnttity.setAction(orderSaveRequest.getAction());
codeEnttity.setMainAction(orderSaveRequest.getMainAction());
codeEnttity.setDeptCode(orderSaveRequest.getDeptCode());
codeEnttity.setOrderId(orderSaveRequest.getBillNo());
codeEnttity.setInvCode(orderSaveRequest.getInvCode());
codeEnttity.setReCount(codeEnttity.getCount() * udiCalCountUtil.getActCount(codeEnttity.getNameCode()));
2 years ago
codeEnttity.setUpdateTime(new Date());
codeEnttity.setCreateTime(DateUtil.parseDate(pdaCodeEntity.getActDate()));
ioCodeEnttities.add(codeEnttity);
}
codeTempService.insertBatch(ioCodeEnttities);
}
orderService.insertOrder(orderSaveRequest);
dealProcess(orderSaveRequest);
if (!ioCheckInoutService.checkManual(orderEntity.getBillNo())) {
ioCheckInoutService.check(orderEntity.getBillNo());
}
}
}
}
}
@Resource
UdiCalCountUtil udiCalCountUtil;
//校验条码关联供应商
public String checkExitSup(Long relId) {
FilterCompanyProductRelevanceRequest filterCompanyProductRelevanceRequest = new FilterCompanyProductRelevanceRequest();
filterCompanyProductRelevanceRequest.setUdiRlIdFk(relId + "");
List<UdiRlSupEntity> companyProductRelevanceEntities = udiRlSupService.filterCompanyProductRelevance(filterCompanyProductRelevanceRequest);
if (companyProductRelevanceEntities != null && companyProductRelevanceEntities.size() == 1) {
UdiRlSupEntity udiRlSupEntity = companyProductRelevanceEntities.get(0);
return udiRlSupEntity.getUnitFk();
} else if (companyProductRelevanceEntities != null && companyProductRelevanceEntities.size() > 1) {
String unitFk = companyProductRelevanceEntities.get(0).getUnitFk();
boolean isMuti = false;
for (UdiRlSupEntity udiRlSupEntity : companyProductRelevanceEntities) {
if (!unitFk.equals(udiRlSupEntity.getUnitFk())) {
isMuti = true;
break;
}
}
if (isMuti)
return "MUTI"; //绑定多个供应商
else
return unitFk;
}
return null;
}
public String checkInvExitSup(IoCodeEntity codeEnttity) {
String supId = checkNorInv(codeEnttity);
if (supId == null) {
return checkPreInv(codeEnttity);
}
return supId;
}
//查普通库存 todo
public String checkNorInv(IoCodeEntity codeEnttity) {
// FilterInvWarehouseRequest filterInvWarehouseRequest = new FilterInvWarehouseRequest();
// filterInvWarehouseRequest.setLevel(1);
// filterInvWarehouseRequest.setAdvanceType(false);
// List<InvWarehouseEntity> invWarehouseEntities = invWarehouseService.filterInvWarehouse(filterInvWarehouseRequest);
// List<String> codes = new ArrayList<>();
// if (!invWarehouseEntities.isEmpty()) {
// for (InvWarehouseEntity invWarehouseEntity : invWarehouseEntities) {
// codes.add(invWarehouseEntity.getCode());
// }
// }
// FilterInvProductRequest filterInvProductDetailRequest = new FilterInvProductRequest();
// filterInvProductDetailRequest.setRelIdFk(codeEnttity.getRelId());
// filterInvProductDetailRequest.setBatchNo(codeEnttity.getBatchNo());
// filterInvProductDetailRequest.setInvCodes(codes);
// List<InvProductEntity> invProductEntities = invProductService.filterInvProduct(filterInvProductDetailRequest);
// if (invProductEntities.size() > 0) {
// String supId = invProductEntities.get(0).getSupId();
// int count = 0;
// for (InvProductEntity invProductEntity : invProductEntities) {
// if (!supId.equals(invProductEntity.getSupId())) {
// return null;
// }
// count = count + (invProductEntity.getInCount() - invProductEntity.getOutCount());
// }
// if (count > 0)
// return supId;
// }
return null;
}
//查寄售库存 todo
public String checkPreInv(IoCodeEntity codeEnttity) {
// FilterInvWarehouseRequest filterInvWarehouseRequest = new FilterInvWarehouseRequest();
// filterInvWarehouseRequest.setLevel(1);
// filterInvWarehouseRequest.setAdvanceType(true);
// List<InvWarehouseEntity> invWarehouseEntities = invWarehouseService.filterInvWarehouse(filterInvWarehouseRequest);
// List<String> codes = new ArrayList<>();
// if (!invWarehouseEntities.isEmpty()) {
// for (InvWarehouseEntity invWarehouseEntity : invWarehouseEntities) {
// codes.add(invWarehouseEntity.getCode());
// }
// }
// FilterInvProductRequest filterInvProductDetailRequest = new FilterInvProductRequest();
// filterInvProductDetailRequest.setRelIdFk(codeEnttity.getRelId());
// filterInvProductDetailRequest.setBatchNo(codeEnttity.getBatchNo());
// filterInvProductDetailRequest.setInvCodes(codes);
// List<InvProductEntity> invProductEntities = invPreProductService.filterInvProduct(filterInvProductDetailRequest);
// if (invProductEntities.size() > 0) {
// String supId = invProductEntities.get(0).getSupId();
// int count = 0;
// for (InvProductEntity invProductEntity : invProductEntities) {
// if (!supId.equals(invProductEntity.getSupId())) {
// return null;
// }
// count = count + (invProductEntity.getInCount() - invProductEntity.getOutCount());
// }
// if (count > 0)
// return supId;
// }
return null;
}
//查询本单是否有重复条码
public String checkOrderRepeatCode(IoCodeTempEntity codeEntity, List<IoCodeTempEntity> filterList) {
int count = 0;
if (filterList != null) {
for (IoCodeTempEntity temp : filterList) {
if (temp.getCode().equals(codeEntity.getCode())) {
count = count + 1;
}
}
}
if (count > 1) {
return codeEntity.getCode() + "条码重复";
} else
return null;
}
public String checkOriginCode(IoCodeTempEntity warehouseEntity) {
UdiEntity udiEntity = FilterUdiUtils.getUdi(warehouseEntity.getCode());
//校验条码的完整性
String errMsg = "";
UdiRelevanceResponse udiRelevanceResponse = udiRelevanceService.selectByNameCode(udiEntity.getUdi());
if (udiRelevanceResponse == null) {
return "耗材字典不存在此产品";
}
InvProductDetailEntity invProductDetailEntity = invProductDetailService.sortFindByCode(warehouseEntity.getCode());
if (invProductDetailEntity != null) {
if (StrUtil.isEmpty(warehouseEntity.getBatchNo())) {
warehouseEntity.setBatchNo(invProductDetailEntity.getBatchNo());
}
if (StrUtil.isEmpty(warehouseEntity.getProduceDate())) {
warehouseEntity.setProduceDate(invProductDetailEntity.getProduceDate());
}
if (StrUtil.isEmpty(warehouseEntity.getExpireDate())) {
warehouseEntity.setExpireDate(invProductDetailEntity.getExpireDate());
}
}
if (StrUtil.isEmpty(warehouseEntity.getBatchNo()) && !udiRelevanceResponse.getAllowNoBatch()) {
errMsg = errMsg + ",批次号";
}
if (StrUtil.isEmpty(warehouseEntity.getProduceDate()) && !udiRelevanceResponse.getAllowNoProduct()) {
errMsg = errMsg + ",生产日期";
}
if (StrUtil.isEmpty(warehouseEntity.getExpireDate()) && !udiRelevanceResponse.getAllowNoExpire()) {
errMsg = errMsg + ",失效日期";
}
if (StrUtil.isNotEmpty(errMsg)) {
return "UDI码" + warehouseEntity.getCode() + "产品三期缺失请补齐" + errMsg.substring(1) + "";
}
return null;
}
IoOrderDetailCodeEntity buildEntity(IoOrderEntity orderEntity, IoCodeTempEntity codeTempEntity, UdiRelevanceResponse udiRelevanceResponse) {
IoOrderDetailCodeEntity ioOrderDetailCodeEntity = new IoOrderDetailCodeEntity();
ioOrderDetailCodeEntity.setOrderIdFk(orderEntity.getBillNo());
ioOrderDetailCodeEntity.setBindRlFk(udiRelevanceResponse.getId());
ioOrderDetailCodeEntity.setUuidFk(udiRelevanceResponse.getUuid());
ioOrderDetailCodeEntity.setBatchNo(codeTempEntity.getBatchNo());
ioOrderDetailCodeEntity.setNameCode(codeTempEntity.getNameCode());
ioOrderDetailCodeEntity.setProductDate(codeTempEntity.getProduceDate());
ioOrderDetailCodeEntity.setExpireDate(codeTempEntity.getExpireDate());
ioOrderDetailCodeEntity.setCoName(udiRelevanceResponse.getCpmctymc());
ioOrderDetailCodeEntity.setCertCode(udiRelevanceResponse.getZczbhhzbapzbh());
ioOrderDetailCodeEntity.setYlqxzcrbarmc(udiRelevanceResponse.getYlqxzcrbarmc());
ioOrderDetailCodeEntity.setManufacturer(udiRelevanceResponse.getManufactory());
ioOrderDetailCodeEntity.setMeasname(udiRelevanceResponse.getMeasname());
ioOrderDetailCodeEntity.setSpec(udiRelevanceResponse.getGgxh());
ioOrderDetailCodeEntity.setSupId(codeTempEntity.getSupId());
ioOrderDetailCodeEntity.setPrice(udiRelevanceResponse.getPrice());
ioOrderDetailCodeEntity.setCount(codeTempEntity.getCount());
ioOrderDetailCodeEntity.setReCount(codeTempEntity.getMyReCount());
return ioOrderDetailCodeEntity;
}
}