|
|
|
@ -0,0 +1,471 @@
|
|
|
|
|
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesContainerSnBindService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesContainerSnService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch.MesNumberRuleMatchRegularExpressionService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch.containerbind.ContainerBindManager;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.rulematch.containerbind.checkqty.MesAbstractContainerBindCheckQtyService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesContainerPartsModel;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesContainerSnBindModel;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.tool.TimeTool;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.*;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.bean.recyclablepackage.MesRecyclablePackageBinding;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.*;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.recyclablepackage.MesRecyclablePackageBindingRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesContainerSnService containerSnService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesContainerTypeRepository containerTypeRDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesContainerTypePartRepository containerTypePartRDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesContainerSnPartRepository containerSnPartRDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesContainerPackageRepository containerPackageRDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesContainerPackageDetailRepository containerPackageDetailRDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesProduceSnRepository produceSnRDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesContainerPackageDetailBindingRepository detailBindingRDao;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesNumberRuleMatchRegularExpressionService matchRegularService;
|
|
|
|
|
|
|
|
|
|
private MesContainerType getMesContainerType(String organizeCode, String containerTypeCode) {
|
|
|
|
|
MesContainerType containerType = null;
|
|
|
|
|
if (!StringUtils.isEmpty(organizeCode) && StringUtils.isEmpty(containerTypeCode)) {
|
|
|
|
|
containerType = containerTypeRDao.getByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerTypeCode"},
|
|
|
|
|
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerTypeCode});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return containerType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesContainerPackage getContainerPackage(MesContainerSnBindModel model, MesContainerSn containerSn) {
|
|
|
|
|
MesContainerPackage containerPackage = containerPackageRDao.getByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"},
|
|
|
|
|
new Object[]{model.getOrganizeCode(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn.getContainerSn()});
|
|
|
|
|
return containerPackage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<MesContainerPackageDetail> getContainerPackageDetail(MesContainerSnBindModel model, MesContainerSn containerSn) {
|
|
|
|
|
List<MesContainerPackageDetail> packageDetails = containerPackageDetailRDao.findByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"},
|
|
|
|
|
new Object[]{model.getOrganizeCode(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn.getContainerSn()});
|
|
|
|
|
return packageDetails;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<MesContainerPartsModel> getContainerParts(String organizeCode, String containerTypeCode, String containerSn) {
|
|
|
|
|
List<MesContainerPartsModel> result = new ArrayList<>();
|
|
|
|
|
List<MesContainerSnPart> snPartList = containerSnPartRDao.findByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerTypeCode", "containerSn"},
|
|
|
|
|
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerTypeCode, containerSn});
|
|
|
|
|
if (!CollectionUtils.isEmpty(snPartList)) {
|
|
|
|
|
for (MesContainerSnPart snPart : snPartList) {
|
|
|
|
|
MesContainerPartsModel model = MesContainerPartsModel.builder()
|
|
|
|
|
.partNo(snPart.getPartNo())
|
|
|
|
|
.partName(snPart.getPartName())
|
|
|
|
|
.matchType(snPart.getMatchType())
|
|
|
|
|
.matchRule(snPart.getMatchRule())
|
|
|
|
|
.qty(snPart.getQty())
|
|
|
|
|
.build();
|
|
|
|
|
result.add(model);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
List<MesContainerTypePart> partList = containerTypePartRDao.findByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerTypeCode"},
|
|
|
|
|
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerTypeCode});
|
|
|
|
|
if (!CollectionUtils.isEmpty(partList)) {
|
|
|
|
|
for (MesContainerTypePart partPart : partList) {
|
|
|
|
|
MesContainerPartsModel model = MesContainerPartsModel.builder()
|
|
|
|
|
.partNo(partPart.getPartNo())
|
|
|
|
|
.partName(partPart.getPartName())
|
|
|
|
|
.matchType(partPart.getMatchType())
|
|
|
|
|
.matchRule(partPart.getMatchRule())
|
|
|
|
|
.qty(partPart.getQty())
|
|
|
|
|
.build();
|
|
|
|
|
result.add(model);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesContainerPartsModel getContainerPartsByPartNo(String organizeCode, String containerTypeCode, String containerSn, String partNo) {
|
|
|
|
|
MesContainerPartsModel model = null;
|
|
|
|
|
MesContainerSnPart snPart = containerSnPartRDao.getByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerTypeCode", "containerSn", "partNo"},
|
|
|
|
|
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerTypeCode, containerSn, partNo});
|
|
|
|
|
if (snPart != null) {
|
|
|
|
|
model = MesContainerPartsModel.builder()
|
|
|
|
|
.partNo(snPart.getPartNo())
|
|
|
|
|
.partName(snPart.getPartName())
|
|
|
|
|
.matchType(snPart.getMatchType())
|
|
|
|
|
.matchRule(snPart.getMatchRule())
|
|
|
|
|
.qty(snPart.getQty())
|
|
|
|
|
.build();
|
|
|
|
|
} else {
|
|
|
|
|
MesContainerTypePart typePart = containerTypePartRDao.getByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerTypeCode", "partNo"},
|
|
|
|
|
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerTypeCode, partNo});
|
|
|
|
|
if (typePart != null) {
|
|
|
|
|
model = MesContainerPartsModel.builder()
|
|
|
|
|
.partNo(typePart.getPartNo())
|
|
|
|
|
.partName(typePart.getPartName())
|
|
|
|
|
.matchType(typePart.getMatchType())
|
|
|
|
|
.matchRule(typePart.getMatchRule())
|
|
|
|
|
.qty(typePart.getQty())
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesContainerPartsModel getContainerPartsByBarcode(String organizeCode, String containerTypeCode, String containerSn, String barcode) {
|
|
|
|
|
MesContainerPartsModel model = null;
|
|
|
|
|
List<MesContainerSnPart> snPartList = containerSnPartRDao.findByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerTypeCode", "containerSn"},
|
|
|
|
|
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerTypeCode, containerSn});
|
|
|
|
|
if (!CollectionUtils.isEmpty(snPartList)) {
|
|
|
|
|
for (MesContainerSnPart snPart : snPartList) {
|
|
|
|
|
if (StringUtils.isEmpty(snPart.getMatchRule())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, Object> reulst = matchRegularService.matchNumberRule(organizeCode, barcode, "", snPart.getMatchRule());
|
|
|
|
|
if (reulst != null && Objects.equals(reulst.get(MesPcnExtConstWords.RESULT), true)) {
|
|
|
|
|
model = MesContainerPartsModel.builder()
|
|
|
|
|
.partNo(snPart.getPartNo())
|
|
|
|
|
.partName(snPart.getPartName())
|
|
|
|
|
.matchType(snPart.getMatchType())
|
|
|
|
|
.matchRule(snPart.getMatchRule())
|
|
|
|
|
.qty(snPart.getQty())
|
|
|
|
|
.build();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (model == null) {
|
|
|
|
|
List<MesContainerTypePart> partList = containerTypePartRDao.findByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerTypeCode"},
|
|
|
|
|
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerTypeCode});
|
|
|
|
|
if (!CollectionUtils.isEmpty(partList)) {
|
|
|
|
|
for (MesContainerTypePart typePart : partList) {
|
|
|
|
|
if (StringUtils.isEmpty(typePart.getMatchRule())) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, Object> reulst = matchRegularService.matchNumberRule(organizeCode, barcode, "", typePart.getMatchRule());
|
|
|
|
|
if (reulst != null && Objects.equals(reulst.get(MesPcnExtConstWords.RESULT), true)) {
|
|
|
|
|
model = MesContainerPartsModel.builder()
|
|
|
|
|
.partNo(typePart.getPartNo())
|
|
|
|
|
.partName(typePart.getPartName())
|
|
|
|
|
.matchType(typePart.getMatchType())
|
|
|
|
|
.matchRule(typePart.getMatchRule())
|
|
|
|
|
.qty(typePart.getQty())
|
|
|
|
|
.build();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MesContainerSnBindModel doScanContainer(MesContainerSnBindModel model) {
|
|
|
|
|
//校验容器条码
|
|
|
|
|
MesContainerSn containerSn = containerSnService.checkContainerSn(model.getOrganizeCode(), model.getContainerSn());
|
|
|
|
|
MesContainerType containerType = containerTypeRDao.getByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerTypeCode"},
|
|
|
|
|
new Object[]{model.getOrganizeCode(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn.getContainerTypeCode()});
|
|
|
|
|
if (containerType == null) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器类型代码【%s】信息不存在,请检查容器类型主数据", containerSn.getContainerTypeCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Objects.equals(containerType.getBindIsChoosePart(), CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue())) {
|
|
|
|
|
List<MesContainerPartsModel> partsModelList = getContainerParts(model.getOrganizeCode(), containerType.getContainerTypeCode(), containerSn.getContainerSn());
|
|
|
|
|
if (CollectionUtils.isEmpty(partsModelList)) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】或容器类型代码【%s】未维护与容器关系,请检查数据", containerSn.getContainerSn(), containerType.getContainerTypeCode());
|
|
|
|
|
}
|
|
|
|
|
model.setContainerParts(partsModelList);
|
|
|
|
|
model.setBindIsChoosePart(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
} else {
|
|
|
|
|
model.setBindIsChoosePart(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MesContainerPackage containerPackage = containerPackageRDao.getByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"},
|
|
|
|
|
new Object[]{model.getOrganizeCode(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn.getContainerSn()});
|
|
|
|
|
if (containerPackage != null) {
|
|
|
|
|
List<MesContainerPackageDetail> packageDetails = containerPackageDetailRDao.findByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"},
|
|
|
|
|
new Object[]{model.getOrganizeCode(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn.getContainerSn()});
|
|
|
|
|
model.setPackageDetails(packageDetails);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
model.setContainerPackage(containerPackage);
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MesContainerSnBindModel doScanBarcode(MesContainerSnBindModel model) {
|
|
|
|
|
//校验容器条码
|
|
|
|
|
MesContainerSn containerSn = containerSnService.checkContainerSn(model.getOrganizeCode(), model.getContainerSn());
|
|
|
|
|
MesContainerType containerType = containerTypeRDao.getByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerTypeCode"},
|
|
|
|
|
new Object[]{model.getOrganizeCode(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn.getContainerTypeCode()});
|
|
|
|
|
if (containerType == null) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器类型代码【%s】信息不存在,请检查容器类型主数据", containerSn.getContainerTypeCode());
|
|
|
|
|
}
|
|
|
|
|
if (containerType.getMixType() == null) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器类型代码【%s】未配置混包类型,请检查容器类型主数据", containerSn.getContainerTypeCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<MesContainerPackageDetail> packageDetails;
|
|
|
|
|
MesContainerPackage containerPackage = containerPackageRDao.getByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"},
|
|
|
|
|
new Object[]{model.getOrganizeCode(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn.getContainerSn()});
|
|
|
|
|
if (containerPackage == null) {
|
|
|
|
|
containerPackage = createContainerPackage(model, containerType);
|
|
|
|
|
packageDetails = new ArrayList<>();
|
|
|
|
|
} else {
|
|
|
|
|
if (Objects.equals(containerPackage.getPackageStatus(), MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_20.getValue())) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】已关箱,不能再进行上料", containerSn.getContainerSn());
|
|
|
|
|
}
|
|
|
|
|
packageDetails = containerPackageDetailRDao.findByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"},
|
|
|
|
|
new Object[]{model.getOrganizeCode(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn.getContainerSn()});
|
|
|
|
|
}
|
|
|
|
|
for (MesContainerPackageDetail packageDetail : packageDetails) {
|
|
|
|
|
if (Objects.equals(packageDetail.getBarCode(), model.getBarCode())) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】与条码【%s】已绑定,请检查数据", containerSn.getContainerSn(), model.getBarCode());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MesContainerPartsModel containerPart = checkProduceSn(model.getOrganizeCode(), containerSn, model.getBarCode(), model.getPartNo());
|
|
|
|
|
containerPart.setContainerType(containerType.getContainerType());
|
|
|
|
|
containerPart.setContainerPackage(containerPackage);
|
|
|
|
|
// 调用策略校验条码与容器是否可以绑定
|
|
|
|
|
Map<String, Object> matchResult = ContainerBindManager.INSTANCE.matchNumberRule(model.getOrganizeCode(), model.getBarCode(), containerPart);
|
|
|
|
|
assert matchResult != null;
|
|
|
|
|
if (Objects.equals(matchResult.get(MesPcnExtConstWords.RESULT), false)) {
|
|
|
|
|
MesPcnException.throwMesBusiException(matchResult.get(MesPcnExtConstWords.MESSAGE).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MesContainerPackageDetail packageDetail = createContainerPackageDetail(model, containerPackage, containerPart, matchResult);
|
|
|
|
|
packageDetails.add(packageDetail);
|
|
|
|
|
|
|
|
|
|
MesAbstractContainerBindCheckQtyService checkQtyService = ContainerBindManager.INSTANCE.getCheckQtyService(MesExtEnumUtil.CONTAINER_TYPE_MIX_TYPE.getByValue(containerType.getMixType()));
|
|
|
|
|
Map<String, Object> checkQtyResult = checkQtyService.doCheck(model.getOrganizeCode(), containerPackage, packageDetails, containerPart, getContainerParts(model.getOrganizeCode(), containerType.getContainerTypeCode(), containerSn.getContainerSn()));
|
|
|
|
|
if (checkQtyResult != null && Objects.equals(checkQtyResult.get(MesPcnExtConstWords.RESULT), false)) {
|
|
|
|
|
MesPcnException.throwMesBusiException(checkQtyResult.get(MesPcnExtConstWords.MESSAGE).toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MesContainerPackageDetailBinding binding = createContainerPackageDetailBinding(containerPackage, packageDetail, MesExtEnumUtil.CONTAINER_RAW_SN_BINDING_STATUS.BINDING, model.getUserName());
|
|
|
|
|
|
|
|
|
|
model.setContainerPackage(containerPackage);
|
|
|
|
|
model.setPackageDetails(packageDetails);
|
|
|
|
|
model.addPackageDetailBinding(binding);
|
|
|
|
|
saveContainerPackage(model);
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void saveContainerPackage(MesContainerSnBindModel model) {
|
|
|
|
|
MesContainerPackage containerPackage = model.getContainerPackage();
|
|
|
|
|
if (containerPackage != null) {
|
|
|
|
|
containerPackage.setQty(model.getPackageDetails().size());
|
|
|
|
|
containerPackageRDao.save(containerPackage);
|
|
|
|
|
}
|
|
|
|
|
if (!CollectionUtils.isEmpty(model.getPackageDetails())) {
|
|
|
|
|
containerPackageDetailRDao.saveAll(model.getPackageDetails());
|
|
|
|
|
}
|
|
|
|
|
if (!CollectionUtils.isEmpty(model.getBindingList())) {
|
|
|
|
|
detailBindingRDao.saveAll(model.getBindingList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MesContainerSnBindModel doClear(MesContainerSnBindModel model) {
|
|
|
|
|
//校验容器条码
|
|
|
|
|
MesContainerSn containerSn = containerSnService.checkContainerSn(model.getOrganizeCode(), model.getContainerSn());
|
|
|
|
|
MesContainerPackage containerPackage = getContainerPackage(model, containerSn);
|
|
|
|
|
if (containerPackage == null) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】未生成容器条码上料主表,请检查数据", containerSn.getContainerSn());
|
|
|
|
|
}
|
|
|
|
|
List<MesContainerPackageDetail> packageDetails = getContainerPackageDetail(model, containerSn);
|
|
|
|
|
if (CollectionUtils.isEmpty(packageDetails)) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】不包含上料明细数据,请检查数据", containerSn.getContainerSn());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(model.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(containerSn.getContainerSn(),"containerSn",ddlPackBean);
|
|
|
|
|
containerPackageDetailRDao.updateByProperties(new String[]{"modifyUser", "modifyDatetime", "isDeleted"},
|
|
|
|
|
new Object[]{model.getUserName(), TimeTool.getNowTime(true), CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()}, ddlPackBean);
|
|
|
|
|
|
|
|
|
|
containerPackage.setPackageStatus(MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_30.getValue());
|
|
|
|
|
ConvertBean.serviceModelUpdate(containerPackage, model.getUserName());
|
|
|
|
|
containerPackageRDao.update(containerPackage);
|
|
|
|
|
|
|
|
|
|
for (MesContainerPackageDetail packageDetail : packageDetails) {
|
|
|
|
|
MesContainerPackageDetailBinding binding = createContainerPackageDetailBinding(containerPackage, packageDetail, MesExtEnumUtil.CONTAINER_RAW_SN_BINDING_STATUS.UN_BINDING, model.getUserName());
|
|
|
|
|
detailBindingRDao.insert(binding);
|
|
|
|
|
}
|
|
|
|
|
model.setPackageDetails(new ArrayList<>());
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MesContainerSnBindModel doDeleteDetails(MesContainerSnBindModel model) {
|
|
|
|
|
//校验容器条码
|
|
|
|
|
MesContainerSn containerSn = containerSnService.checkContainerSn(model.getOrganizeCode(), model.getContainerSn());
|
|
|
|
|
MesContainerPackage containerPackage = getContainerPackage(model, containerSn);
|
|
|
|
|
if (containerPackage == null) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】未生成容器条码上料主表,请检查数据", containerSn.getContainerSn());
|
|
|
|
|
}
|
|
|
|
|
List<MesContainerPackageDetail> packageDetails = getContainerPackageDetail(model, containerSn);
|
|
|
|
|
if (CollectionUtils.isEmpty(packageDetails)) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】不包含上料明细数据,请检查数据", containerSn.getContainerSn());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Long> deleteDetailIds = new ArrayList<>();
|
|
|
|
|
Map<String, MesContainerPackageDetail> detailMap = packageDetails.stream().collect(Collectors.toMap(MesContainerPackageDetail::getBarCode, item -> item));
|
|
|
|
|
for (MesContainerPackageDetail detail : model.getPackageDetails()) {
|
|
|
|
|
MesContainerPackageDetail dbDetail = detailMap.get(detail.getBarCode());
|
|
|
|
|
if (null == dbDetail) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】未与条码【%s】进行绑定,请检查数据", containerSn.getContainerSn(), detail.getBarCode());
|
|
|
|
|
}
|
|
|
|
|
MesContainerPackageDetailBinding binding = createContainerPackageDetailBinding(containerPackage, dbDetail, MesExtEnumUtil.CONTAINER_RAW_SN_BINDING_STATUS.UN_BINDING, model.getUserName());
|
|
|
|
|
detailBindingRDao.insert(binding);
|
|
|
|
|
|
|
|
|
|
deleteDetailIds.add(dbDetail.getId());
|
|
|
|
|
detailMap.remove(dbDetail.getBarCode());
|
|
|
|
|
}
|
|
|
|
|
containerPackageDetailRDao.deleteWeaklyByIds(deleteDetailIds.toArray(new Long[0]), model.getUserName());
|
|
|
|
|
|
|
|
|
|
containerPackage.setPackageStatus(MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_30.getValue());
|
|
|
|
|
ConvertBean.serviceModelUpdate(containerPackage, model.getUserName());
|
|
|
|
|
containerPackageRDao.update(containerPackage);
|
|
|
|
|
|
|
|
|
|
model.setPackageDetails(new ArrayList<>(detailMap.values()));
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MesContainerSnBindModel doClosePackage(MesContainerSnBindModel model) {
|
|
|
|
|
//校验容器条码
|
|
|
|
|
MesContainerSn containerSn = containerSnService.checkContainerSn(model.getOrganizeCode(), model.getContainerSn());
|
|
|
|
|
MesContainerPackage containerPackage = getContainerPackage(model, containerSn);
|
|
|
|
|
if (containerPackage == null) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】未生成容器条码上料主表,请检查数据", containerSn.getContainerSn());
|
|
|
|
|
}
|
|
|
|
|
if (Objects.equals(containerPackage.getPackageStatus(), MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_20.getValue())) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】已关箱,请务重复操作!", containerSn.getContainerSn());
|
|
|
|
|
}
|
|
|
|
|
List<MesContainerPackageDetail> packageDetails = getContainerPackageDetail(model, containerSn);
|
|
|
|
|
for (MesContainerPackageDetail detail : packageDetails) {
|
|
|
|
|
MesContainerPackageDetailBinding binding = createContainerPackageDetailBinding(containerPackage, detail, MesExtEnumUtil.CONTAINER_RAW_SN_BINDING_STATUS.CLOSE, model.getUserName());
|
|
|
|
|
detailBindingRDao.insert(binding);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
containerPackage.setPackageStatus(MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_20.getValue());
|
|
|
|
|
ConvertBean.serviceModelUpdate(containerPackage, model.getUserName());
|
|
|
|
|
containerPackageRDao.update(containerPackage);
|
|
|
|
|
|
|
|
|
|
model.setPackageDetails(packageDetails);
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesContainerPartsModel checkProduceSn(String organizeCode, MesContainerSn containerSn, String barCode, String partNo) {
|
|
|
|
|
MesContainerPartsModel model;
|
|
|
|
|
MesProduceSn produceSn = produceSnRDao.getByProperty(
|
|
|
|
|
new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "productSn"},
|
|
|
|
|
new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), barCode});
|
|
|
|
|
if (produceSn != null) {
|
|
|
|
|
// 自制件条码
|
|
|
|
|
model = getContainerPartsByPartNo(organizeCode, containerSn.getContainerTypeCode(), containerSn.getContainerSn(), produceSn.getPartNo());
|
|
|
|
|
if (model != null) {
|
|
|
|
|
model.setBarcode(barCode);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
model = getContainerPartsByBarcode(organizeCode, containerSn.getContainerTypeCode(), containerSn.getContainerSn(), barCode);
|
|
|
|
|
if (model != null) {
|
|
|
|
|
model.setBarcode(barCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (model == null) {
|
|
|
|
|
MesPcnException.throwMesBusiException("容器条码【%s】或容器类型代码【%s】未维护与零件关系,请检查数据", containerSn.getContainerSn(), containerSn.getContainerTypeCode());
|
|
|
|
|
}
|
|
|
|
|
if (!StringUtils.isEmpty(partNo) && !Objects.equals(partNo, model.getPartNo())) {
|
|
|
|
|
MesPcnException.throwMesBusiException("条码【%s】的零件号【%s】与选择的零件不匹配,请检查数据", barCode, produceSn.getPartNo());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return model;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesContainerPackage createContainerPackage(MesContainerSnBindModel model, MesContainerType containerType) {
|
|
|
|
|
MesContainerPackage containerPackage = new MesContainerPackage();
|
|
|
|
|
containerPackage.setOrganizeCode(model.getOrganizeCode());
|
|
|
|
|
containerPackage.setContainerSn(model.getContainerSn());
|
|
|
|
|
containerPackage.setPackageStatus(MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_10.getValue());
|
|
|
|
|
containerPackage.setQty(0);
|
|
|
|
|
ConvertBean.serviceModelInitialize(containerPackage, model.getUserName());
|
|
|
|
|
return containerPackage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesContainerPackageDetail createContainerPackageDetail(MesContainerSnBindModel model, MesContainerPackage containerPackage, MesContainerPartsModel containerPart, Map<String, Object> matchResult) {
|
|
|
|
|
Object qty = matchResult.get(MesPcnExtConstWords.QTY);
|
|
|
|
|
Object dataType = matchResult.get(MesPcnExtConstWords.DATA_TYPE);
|
|
|
|
|
MesContainerPackageDetail detail = new MesContainerPackageDetail();
|
|
|
|
|
detail.setOrganizeCode(containerPackage.getOrganizeCode());
|
|
|
|
|
detail.setPid(containerPackage.getId());
|
|
|
|
|
detail.setContainerSn(containerPackage.getContainerSn());
|
|
|
|
|
detail.setPartNo(containerPart.getPartNo());
|
|
|
|
|
detail.setPartName(containerPart.getPartName());
|
|
|
|
|
detail.setBarCode(model.getBarCode());
|
|
|
|
|
detail.setQty(qty != null ? (double)qty : 1);
|
|
|
|
|
detail.setLoadPartTime(TimeTool.getNowTime(true));
|
|
|
|
|
detail.setLotNo(StringUtils.isEmpty(containerPart.getLotNo()) ? TimeTool.getNowTime("yyyy-MM-dd") : containerPart.getLotNo());
|
|
|
|
|
detail.setMatchType(containerPart.getMatchType());
|
|
|
|
|
detail.setDataType(dataType != null ? (int)dataType : null);
|
|
|
|
|
detail.setSnStatus(MesExtEnumUtil.CONTAINER_BARCODE_STATUS.STATUS_10.getValue());
|
|
|
|
|
|
|
|
|
|
ConvertBean.serviceModelInitialize(detail, model.getUserName());
|
|
|
|
|
return detail;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MesContainerPackageDetailBinding createContainerPackageDetailBinding(MesContainerPackage containerPackage, MesContainerPackageDetail packageDetail, MesExtEnumUtil.CONTAINER_RAW_SN_BINDING_STATUS snBindingStatus, String userName) {
|
|
|
|
|
MesContainerPackageDetailBinding binding = new MesContainerPackageDetailBinding();
|
|
|
|
|
binding.setOrganizeCode(containerPackage.getOrganizeCode());
|
|
|
|
|
binding.setPid(containerPackage.getId());
|
|
|
|
|
binding.setSourceId(packageDetail.getId());
|
|
|
|
|
binding.setContainerSn(containerPackage.getContainerSn());
|
|
|
|
|
binding.setBarCode(packageDetail.getBarCode());
|
|
|
|
|
binding.setQty(packageDetail.getQty());
|
|
|
|
|
binding.setSnStatus(snBindingStatus.getValue());
|
|
|
|
|
binding.setMatchType(packageDetail.getMatchType());
|
|
|
|
|
ConvertBean.serviceModelInitialize(binding, userName);
|
|
|
|
|
return binding;
|
|
|
|
|
}
|
|
|
|
|
}
|