From 93a2743b1505537b5b079a4a3de43a4ced2a9d73 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 27 Jun 2025 17:01:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8A=E6=96=99=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../busi/MesContainerSnBindServiceImpl.java | 55 ++++++++----- ...ationFeedContainerPackageDetailStepService.java | 94 ++++++++++++++++------ 2 files changed, 103 insertions(+), 46 deletions(-) diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesContainerSnBindServiceImpl.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesContainerSnBindServiceImpl.java index 90a411b..5629d03 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesContainerSnBindServiceImpl.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesContainerSnBindServiceImpl.java @@ -14,6 +14,7 @@ import cn.estsh.i3plus.platform.common.convert.ConvertBean; import cn.estsh.i3plus.platform.common.tool.TimeTool; import cn.estsh.i3plus.platform.common.util.MesConstWords; import cn.estsh.i3plus.pojo.base.bean.DdlPackBean; +import cn.estsh.i3plus.pojo.base.codemaker.SnowflakeIdMaker; import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack; import cn.estsh.i3plus.pojo.mes.bean.*; @@ -53,6 +54,8 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService private MesContainerSnStationRepository containerSnStationRDao; @Autowired private EntityManager entityManager; + @Autowired + private SnowflakeIdMaker snowflakeIdMaker; private MesContainerPackage getContainerPackage(MesContainerSnBindModel model, MesContainerSn containerSn) { MesContainerPackage containerPackage = containerPackageRDao.getByProperty( @@ -319,31 +322,37 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService * @param bStep 是否为工步上料 * @param username 用户名 */ - private void autoOpenContainerSn(String organizeCode, String containerSn, boolean bStep, String username) { + private MesContainerPackage autoOpenContainerSn(String organizeCode, String containerSn, boolean bStep, String username) { MesContainerPackage containerPackage = containerPackageRDao.getByProperty( new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"}, new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn}); if (containerPackage == null) { - return; + return null; } List bottomPackageDetails = new ArrayList<>(); getBottomPackageDetails(organizeCode, containerPackage, bottomPackageDetails); - boolean isAllDeduction = true; + List deductionDetails = new ArrayList<>(); for (MesContainerPackageDetail packageDetail : bottomPackageDetails) { - if (!Objects.equals(packageDetail.getSnStatus(), MesExtEnumUtil.CONTAINER_BARCODE_STATUS.STATUS_20.getValue())) { - isAllDeduction = false; + if (Objects.equals(packageDetail.getSnStatus(), MesExtEnumUtil.CONTAINER_BARCODE_STATUS.STATUS_20.getValue())) { + deductionDetails.add(packageDetail); } } - if (isAllDeduction) { - MesContainerPackageDetail detail = containerPackageDetailRDao.getByProperty( - new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "barCode"}, - new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerPackage.getContainerSn()}); - if (detail != null) { + if (!deductionDetails.isEmpty()) { + // 扣减完成的条码与容器进行解绑 + for (MesContainerPackageDetail detail : deductionDetails) { + if (detailBindingRDao.isExitByProperty(new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "pid", "barCode", "snStatus"}, + new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerPackage.getId(), detail.getBarCode(), MesExtEnumUtil.CONTAINER_RAW_SN_BINDING_STATUS.UN_BINDING.getValue()})) { + continue; + } MesContainerPackageDetailBinding binding = createContainerPackageDetailBinding(containerPackage, detail, MesExtEnumUtil.CONTAINER_RAW_SN_BINDING_STATUS.UN_BINDING, username); detailBindingRDao.insert(binding); - containerPackageDetailRDao.deleteWeaklyById(detail.getId(), username); } + // 容器置为拆箱状态。 + containerPackage.setPackageStatus(MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_30.getValue()); + } + // 全部扣减完成 + if (!deductionDetails.isEmpty() && deductionDetails.size() == bottomPackageDetails.size()) { containerPackageRDao.deleteWeaklyById(containerPackage.getId(), username); // 非工步上料,需要将容器与站点解绑! if (!bStep) { @@ -354,7 +363,9 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService new Object[]{username, TimeTool.getNowTime(true), CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()}, ddlPackBean); } + return null; } + return containerPackage; } @Override @@ -371,12 +382,9 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService if (containerType.getMixType() == null) { MesPcnException.throwMesBusiException("容器类型代码【%s】未配置混包类型,请检查容器类型主数据", containerSn.getContainerTypeCode()); } - autoOpenContainerSn(organizeCode, containerSn.getContainerSn(), bStep, model.getUserName()); + MesContainerPackage containerPackage = autoOpenContainerSn(organizeCode, containerSn.getContainerSn(), bStep, model.getUserName()); List packageDetails; - MesContainerPackage containerPackage = containerPackageRDao.getByProperty( - new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"}, - new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerSn.getContainerSn()}); if (containerPackage == null) { containerPackage = createContainerPackage(model, containerType); packageDetails = new ArrayList<>(); @@ -406,7 +414,7 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService bottomPackageDetails = checkContainerBarcode(organizeCode, model.getBarCode(), oldPackageDetails); } else { if (Objects.equals(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue(), containerType.getIsAllowRecursion())) { - MesPcnException.throwBusiException("容器条码【%s】不能零件条码,请重新扫描!", containerSn.getContainerSn()); + MesPcnException.throwBusiException("容器条码【%s】不能扫描原料条码,请重新扫描!", containerSn.getContainerSn()); } bottomPackageDetails = new ArrayList<>(); } @@ -459,11 +467,11 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService containerPackageRDao.save(containerPackage); } if (!CollectionUtils.isEmpty(model.getPackageDetails())) { - if (containerPackage != null) { - for (MesContainerPackageDetail packageDetail : model.getPackageDetails()) { - packageDetail.setPid(containerPackage.getId()); - } - } +// if (containerPackage != null) { +// for (MesContainerPackageDetail packageDetail : model.getPackageDetails()) { +// packageDetail.setPid(containerPackage.getId()); +// } +// } containerPackageDetailRDao.saveAll(model.getPackageDetails()); } if (!CollectionUtils.isEmpty(model.getBindingList())) { @@ -537,7 +545,9 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService if (Objects.equals(containerPackage.getPackageStatus(), MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_20.getValue())) { MesPcnException.throwMesBusiException("容器条码【%s】已关箱,请务重复操作!", containerSn.getContainerSn()); } - List packageDetails = getContainerPackageDetail(model, containerSn); + List packageDetails = containerPackageDetailRDao.findByProperty( + new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "pid"}, + new Object[]{model.getOrganizeCode(), CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), containerPackage.getId()}); for (MesContainerPackageDetail detail : packageDetails) { MesContainerPackageDetailBinding binding = createContainerPackageDetailBinding(containerPackage, detail, MesExtEnumUtil.CONTAINER_RAW_SN_BINDING_STATUS.CLOSE, model.getUserName()); detailBindingRDao.insert(binding); @@ -607,6 +617,7 @@ public class MesContainerSnBindServiceImpl implements IMesContainerSnBindService containerPackage.setContainerSn(model.getContainerSn()); containerPackage.setPackageStatus(MesExtEnumUtil.CONTAINER_PACKAGE_STATUS.STATUS_10.getValue()); ConvertBean.serviceModelInitialize(containerPackage, model.getUserName()); + containerPackageRDao.insert(containerPackage); return containerPackage; } diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesStationFeedContainerPackageDetailStepService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesStationFeedContainerPackageDetailStepService.java index 9e34248..fff443a 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesStationFeedContainerPackageDetailStepService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/step/MesStationFeedContainerPackageDetailStepService.java @@ -1,10 +1,10 @@ package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.step; +import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesConfigService; import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesContainerSnBindService; import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionDispatchContextStepService; import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesProductionProcessContextStepService; import cn.estsh.i3plus.ext.mes.pcn.pojo.context.MesProductionProcessContext; -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.mes.pcn.serviceimpl.fsm.BaseStepService; @@ -23,7 +23,9 @@ import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; -import java.util.*; +import java.util.Comparator; +import java.util.List; +import java.util.Objects; /** * @Description : 零件条码绑定装配件站点容器工步 @@ -49,6 +51,8 @@ public class MesStationFeedContainerPackageDetailStepService extends BaseStepSer private MesContainerPackageRepository containerPackageRDao; @Autowired private MesContainerSnRepository containerSnRDao; + @Autowired + private MesConfigRepository mesConfigRepository; @Override public StepResult execute(StationRequestBean reqBean) { @@ -58,15 +62,6 @@ public class MesStationFeedContainerPackageDetailStepService extends BaseStepSer StepResult stepResult = StepResult.getSuccessComplete(); final String organizeCode = reqBean.getOrganizeCode(); - //扫描信息置空 - String barcode = reqBean.resetScanInfo(reqBean.getScanInfo()); - if (StringUtils.isEmpty(barcode)) stepSendGuideAndThrowEx(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), "请扫描上料条码!"); - - if (containerSnRDao.isExitByProperty(new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"}, - new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), barcode})) { - stepSendGuideAndThrowEx(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), String.format("不能扫描容器条码【%s】,请重新扫描!", barcode)); - } - //获取工位当前设备信息 MesProductionProcessContext productionProcessContext = productionProcessContextStepService.dispatchCurCellEquipment(reqBean); @@ -75,16 +70,31 @@ public class MesStationFeedContainerPackageDetailStepService extends BaseStepSer stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), productionProcessContext.getMessage()); } + //扫描信息置空 + String barcode = reqBean.resetScanInfo(reqBean.getScanInfo()); + if (StringUtils.isEmpty(barcode)) stepSendGuideAndThrowEx(reqBean, resultBean.writeDbLog(MesPcnEnumUtil.WORK_CELL_SCAN_MONITOR_LOG_TYPE.PROCESS.getValue()), "请扫描原料条码!"); + + if (containerSnRDao.isExitByProperty(new String[]{MesPcnExtConstWords.ORGANIZE_CODE, MesPcnExtConstWords.IS_DELETED, MesPcnExtConstWords.IS_VALID, "containerSn"}, + new Object[]{organizeCode, CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), CommonEnumUtil.IS_VAILD.VAILD.getValue(), barcode})) { + return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_FEEDING), String.format("不能扫描容器条码[%s],请重新扫描!", barcode)); + } + final String lastFeedContainerSn = productionDispatchContextStepService.getMatchStationFeedContainerSnContext(reqBean); + if (executeClosePackage(organizeCode, barcode, lastFeedContainerSn, reqBean.getUserInfo())) { + return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "原料条码上料成功!"); + } + //获取站点用于缺料时进行上料绑定 List stationList = productionDispatchContextStepService.getMatchStationContext(reqBean); if (CollectionUtils.isEmpty(stationList)) { - stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), "容器条码扣减装配件时验证设备未关联支持上料的站点"); + return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_FEEDING), "容器条码扣减装配件时验证设备未关联支持上料的站点"); } - final String lastFeedContainerSn = productionDispatchContextStepService.getMatchStationFeedContainerSnContext(reqBean); if (!StringUtils.isEmpty(lastFeedContainerSn)) { - if (executeFeedPartSn(reqBean, lastFeedContainerSn, barcode)) { - return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "零件条码上料成功!"); + int feedResult = executeFeedPartSn(reqBean, lastFeedContainerSn, barcode); + if (feedResult == 1) { + return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "原料条码上料成功!"); + } else if (feedResult == 2) { + return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_FEEDING), "原料条码上料成功,请继续扫描上料条码或扫描强制封箱条码!"); } } @@ -94,21 +104,47 @@ public class MesStationFeedContainerPackageDetailStepService extends BaseStepSer if (CollectionUtils.isEmpty(containerSnStations)) { continue; } - containerSnStations.sort(Comparator.comparing(MesContainerSnStation::getTopContainerSn)); + containerSnStations.sort(Comparator.comparing(MesContainerSnStation::getContainerSn)); for (MesContainerSnStation containerSnStation : containerSnStations) { - final String feedContainerSn = containerSnStation.getTopContainerSn(); + final String feedContainerSn = containerSnStation.getContainerSn(); if (Objects.equals(feedContainerSn, lastFeedContainerSn)) { continue; } - if (executeFeedPartSn(reqBean, feedContainerSn, barcode)) { - return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "零件条码上料成功!"); + int feedResult = executeFeedPartSn(reqBean, feedContainerSn, barcode); + if (feedResult == 1) { + return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "原料条码上料成功!"); + } else if (feedResult == 2) { + return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_FEEDING), "原料条码上料成功,请继续扫描上料条码或扫描强制封箱条码!"); } } } - stepExpSendMsgAndThrowEx(reqBean, resultBean.writeDbLog(), "未匹配到可上料的容器!"); - return stepSuccessCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult, "零件条码上料成功!"); + return stepNonCompleteAndSendMsgReturn(reqBean, resultBean.writeDbLog(), stepResult.nextTriggerEvent(MesPcnExtConstWords.NEXT_TRIGGER_EVENT_FEEDING), "未匹配到可上料的容器,请重新扫描上料条码!"); + } + + private boolean executeClosePackage(String organizeCode, String barcode, String lastFeedContainerSn, String userName) { + if (StringUtils.isEmpty(lastFeedContainerSn)) { + return false; + } + MesConfig config = mesConfigRepository.getByProperty( + new String[]{"cfgKey", "organizeCode", "isValid", "isDeleted"}, + new Object[]{"STEP_STATION_FEED_CONTAINER_PACKAGE_DETAIL", organizeCode, CommonEnumUtil.IS_VAILD.VAILD.getValue(), CommonEnumUtil.IS_DEAL.NO.getValue()}); + if (config == null) { + return false; + } + String closeSn = config.getCfgValue(); + if (StringUtils.isEmpty(closeSn) || !Objects.equals(closeSn, barcode)) { + return false; + } + + MesContainerSnBindModel model = MesContainerSnBindModel.builder() + .organizeCode(organizeCode) + .userName(userName) + .containerSn(lastFeedContainerSn) + .build(); + containerSnBindService.doClosePackage(model); + return true; } private List getMesContainerSnStation(String organizeCode, String station) { @@ -118,7 +154,14 @@ public class MesStationFeedContainerPackageDetailStepService extends BaseStepSer return containerSnStations; } - private boolean executeFeedPartSn(StationRequestBean reqBean, String containerSn, String barcode) { + /** + * 0未上料成功;1上料成功满箱自动关箱;2上料成功未满箱 + * @param reqBean + * @param containerSn + * @param barcode + * @return + */ + private int executeFeedPartSn(StationRequestBean reqBean, String containerSn, String barcode) { final String organizeCode = reqBean.getOrganizeCode(); MesContainerSnBindModel model = MesContainerSnBindModel.builder() .organizeCode(organizeCode) @@ -131,10 +174,13 @@ public class MesStationFeedContainerPackageDetailStepService extends BaseStepSer final String lastFeedContainerSn = hasFullPackage(organizeCode, containerSn) ? "" : containerSn; //加料后容器还未满,保存最近使用的站点 productionDispatchContextStepService.dispatchMatchStationFeedContainerSnContext(reqBean, lastFeedContainerSn); + if (StringUtils.isEmpty(lastFeedContainerSn)) { + return 1; + } } catch (Exception ignored) { - return false; + return 0; } - return true; + return 2; } private boolean hasFullPackage(String organizeCode, String containerSn) {