From a611078a51c0de9e1c848914e8fafcab651667b0 Mon Sep 17 00:00:00 2001 From: "xiangwei.zhang" <752558143@qq.com> Date: Fri, 20 Dec 2024 14:46:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81=E5=86=B2?= =?UTF-8?q?=E7=AA=81=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../serviceimpl/busi/MesSpotCheckOrderService.java | 71 +++++++++++++++------- 1 file changed, 49 insertions(+), 22 deletions(-) diff --git a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesSpotCheckOrderService.java b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesSpotCheckOrderService.java index 0b96830..c9a2aec 100644 --- a/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesSpotCheckOrderService.java +++ b/modules/i3plus-ext-mes-pcn-apiservice/src/main/java/cn/estsh/i3plus/ext/mes/pcn/apiservice/serviceimpl/busi/MesSpotCheckOrderService.java @@ -11,6 +11,7 @@ import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesSpotCheckOrderModel; import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords; import cn.estsh.i3plus.icloud.core.sdk.ICoreUtilCloud; import cn.estsh.i3plus.mes.pcn.api.iservice.busi.ISyncFuncService; +import cn.estsh.i3plus.mes.pcn.util.DateUtil; import cn.estsh.i3plus.platform.common.convert.ConvertBean; import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum; import cn.estsh.i3plus.platform.common.tool.TimeTool; @@ -29,7 +30,6 @@ import cn.estsh.impp.framework.boot.exception.ImppBusiException; import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; import cn.estsh.impp.framework.boot.util.ValidatorBean; import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections.map.HashedMap; import org.apache.commons.collections4.ListUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -39,6 +39,7 @@ import org.springframework.util.StringUtils; import java.util.*; import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @Description : @@ -86,13 +87,16 @@ public class MesSpotCheckOrderService implements IMesSpotCheckOrderService { @Autowired private MesEquipmentRepository mesEquipmentRepository; + @Autowired + private MesEquipmentSpotCheckTagRepository mesEquipmentSpotCheckTagRepository; + @Override public ListPager querySpotCheckOrder(MesSpotCheckOrder spotCheckOrder, Pager pager) { DdlPackBean packBean = getDdlPackBean(spotCheckOrder); - DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{"createDatetime"}, packBean); pager = PagerHelper.getPager(pager, spotCheckOrderRepository.findByHqlWhereCount(packBean)); + DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue(),CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{"status","createDatetime"}, packBean); List resultList = spotCheckOrderRepository.findByHqlWherePage(packBean, pager); if (CollectionUtils.isEmpty(resultList)) { return new ListPager<>(resultList, pager); @@ -203,16 +207,19 @@ public class MesSpotCheckOrderService implements IMesSpotCheckOrderService { //校验点检单 checkSpotCheckOrder(model.getSpotCheckOrder()); - //点检单类型为产品首检时 需要判断单据的条码是否都扫描完成 - if (model.getSpotCheckOrder().getSpotCheckOrderType() == MesExtEnumUtil.SPOT_CHECK_ORDER_TYPE.FIRST_PRODUCT_INSPECTION.getValue()) { - - List partNoList = model.getOrderPartList().stream().filter(k -> StringUtils.isEmpty(k.getSn())).map(k -> k.getPartNo()).collect(Collectors.toList()); - if (!CollectionUtils.isEmpty(partNoList)) { - throw new ImppBusiException(String.format("剩余物料号【%s】对应的条码未扫描,请扫描完成后再完成质检", partNoList)); + //点检单类型为产品首检,产品末检时 需要判断单据的条码是否都扫描完成 + if (Stream.of(MesExtEnumUtil.EQUIPMENT_CHECK_ORDER_TYPE.FIRST_INSPECTION.getValue(),MesExtEnumUtil.EQUIPMENT_CHECK_ORDER_TYPE.END_INSPECTION.getValue()).collect(Collectors.toList()).contains(model.getSpotCheckOrder().getSpotCheckOrderType())) { + Optional orderPartOptional = model.getOrderPartList().stream().filter(k -> !StringUtils.isEmpty(k.getSn())).findFirst(); + if (!orderPartOptional.isPresent()) { + throw new ImppBusiException("未扫描条码,请扫描条码后再查询设备数据,请检查数据"); } } //根据设备代码获取EQUIP_ID MesEquipment mesEquipment = mesEquipmentExtService.getMesEquipment(org, model.getSpotCheckOrder().getEquipCode()); + + //是否允许开始点检 + allowSpotCheckOrder(model.getSpotCheckOrder(), org, mesEquipment.getEquipId()); + Map> setMap = null; //实际值地址数据Map Map> realMap = null; @@ -230,13 +237,19 @@ public class MesSpotCheckOrderService implements IMesSpotCheckOrderService { //获取设定值设备数据 List setEquipmentLogList = new ArrayList<>(); for (List tmp : ListUtils.partition(setEquipVariableIdList, MesCommonConstant.MAX_PAGER_SIZE)) { - setEquipmentLogList.addAll(mesEquipmentLogExtService.getEquipmentLogCollectList(org, mesEquipment.getEquipId(), MesExtEnumUtil.EQUIP_VARIABLE_NEED_NEW_VALUE.TRUE.getValue(), MesExtEnumUtil.EQUIP_VARIABLE_TYPE.PROCESS_FINISH.getValue(), tmp)); + List equipmentLogCollectList = mesEquipmentLogExtService.getEquipmentLogCollectList(org, mesEquipment.getEquipId(), MesExtEnumUtil.EQUIP_VARIABLE_NEED_NEW_VALUE.TRUE.getValue(), MesExtEnumUtil.EQUIP_VARIABLE_TYPE.PROCESS_FINISH.getValue(), tmp); + if(!CollectionUtils.isEmpty(equipmentLogCollectList)){ + setEquipmentLogList.addAll(equipmentLogCollectList); + } } //设定值地址数据Map setMap = setEquipmentLogList.stream().collect(Collectors.groupingBy(MesEquipVariableCollectContext::getEquipVariableId)); for (List tmp : ListUtils.partition(realEquipVariableIdList, MesCommonConstant.MAX_PAGER_SIZE)) { - realEquipmentLogList.addAll(mesEquipmentLogExtService.getEquipmentLogCollectList(org,mesEquipment.getEquipId(), MesExtEnumUtil.EQUIP_VARIABLE_NEED_NEW_VALUE.TRUE.getValue(), MesExtEnumUtil.EQUIP_VARIABLE_TYPE.PROCESS_FINISH.getValue(), tmp)); + List equipmentLogCollectList = mesEquipmentLogExtService.getEquipmentLogCollectList(org, mesEquipment.getEquipId(), MesExtEnumUtil.EQUIP_VARIABLE_NEED_NEW_VALUE.TRUE.getValue(), MesExtEnumUtil.EQUIP_VARIABLE_TYPE.PROCESS_FINISH.getValue(), tmp); + if(!CollectionUtils.isEmpty(equipmentLogCollectList)){ + realEquipmentLogList.addAll(equipmentLogCollectList); + } } //实际值地址数据Map realMap = realEquipmentLogList.stream().collect(Collectors.groupingBy(MesEquipVariableCollectContext::getEquipVariableId)); @@ -298,12 +311,11 @@ public class MesSpotCheckOrderService implements IMesSpotCheckOrderService { //校验点检单 MesSpotCheckOrder spotCheckOrder = checkSpotCheckOrder(model.getSpotCheckOrder()); - //点检单类型为产品首检时 需要判断单据的条码是否都扫描完成 - if (model.getSpotCheckOrder().getSpotCheckOrderType() == MesExtEnumUtil.SPOT_CHECK_ORDER_TYPE.FIRST_PRODUCT_INSPECTION.getValue()) { - - List partNoList = model.getOrderPartList().stream().filter(k -> StringUtils.isEmpty(k.getSn())).map(k -> k.getPartNo()).collect(Collectors.toList()); - if (!CollectionUtils.isEmpty(partNoList)) { - throw new ImppBusiException(String.format("剩余物料号【%s】对应的条码未扫描,请扫描完成后再完成质检", partNoList)); + //点检单类型为产品首检,产品末检时 需要判断单据的条码是否都扫描完成 + if (Stream.of(MesExtEnumUtil.EQUIPMENT_CHECK_ORDER_TYPE.FIRST_INSPECTION.getValue(),MesExtEnumUtil.EQUIPMENT_CHECK_ORDER_TYPE.END_INSPECTION.getValue()).collect(Collectors.toList()).contains(model.getSpotCheckOrder().getSpotCheckOrderType())) { + Optional orderPartOptional = model.getOrderPartList().stream().filter(k -> !StringUtils.isEmpty(k.getSn())).findFirst(); + if (!orderPartOptional.isPresent()) { + throw new ImppBusiException("未扫描条码,请扫描条码后再查询设备数据,请检查数据"); } } model.getOrderPartList().forEach(k -> { @@ -593,15 +605,13 @@ public class MesSpotCheckOrderService implements IMesSpotCheckOrderService { } private DdlPackBean getDdlPackBean(MesSpotCheckOrder spotCheckOrder) { - - List statusList = new ArrayList<>(); - statusList.add(MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.CREATE.getValue()); - statusList.add(MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.COMPLETE.getValue()); + String createDateTime = TimeTool.pareDateToString(DateUtil.addDays(new Date(), -(Objects.isNull(spotCheckOrder.getDays()) ? MesPcnExtConstWords.SEVEN : spotCheckOrder.getDays()))); DdlPackBean packBean = DdlPackBean.getDdlPackBean(spotCheckOrder.getOrganizeCode()); DdlPreparedPack.getStringLikerPack(spotCheckOrder.getWorkCenterCode(), "workCenterCode", packBean); DdlPreparedPack.getStringLikerPack(spotCheckOrder.getWorkCellCode(), "workCellCode", packBean); DdlPreparedPack.getStringLikerPack(spotCheckOrder.getSpotCheckOrderNo(), "spotCheckOrderNo", packBean); - DdlPreparedPack.getInPackList(statusList, "status", packBean); + DdlPreparedPack.getStringEqualPack(spotCheckOrder.getEquipCode(), "equipCode", packBean); + packBean.setWhereAppend(packBean.getWhereAppend() + String.format(" and (model.status = %s or (model.status = %s and model.createDatetime >= '%s'))", MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.CREATE.getValue(), MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.COMPLETE.getValue(), createDateTime)); return packBean; } @@ -665,5 +675,22 @@ public class MesSpotCheckOrderService implements IMesSpotCheckOrderService { } } - + private void allowSpotCheckOrder(MesSpotCheckOrder spotCheckOrder, String org, Integer equipId) { + if(Objects.isNull(spotCheckOrder) || StringUtils.isEmpty(spotCheckOrder.getSpotCheckCode()) || StringUtils.isEmpty(org)){ + return; + } + DdlPackBean packBean = DdlPackBean.getDdlPackBean(org); + DdlPreparedPack.getStringEqualPack(spotCheckOrder.getSpotCheckCode(),"spotCheckCode",packBean); + MesEquipmentSpotCheckTag equipmentSpotCheckTag = mesEquipmentSpotCheckTagRepository.getByProperty(packBean); + if(Objects.isNull(equipmentSpotCheckTag)){ + return; + } + List equipmentLogCollectList = mesEquipmentLogExtService.getEquipmentLogCollectList(org, equipId, MesExtEnumUtil.EQUIP_VARIABLE_NEED_NEW_VALUE.TRUE.getValue(), MesExtEnumUtil.EQUIP_VARIABLE_TYPE.PROCESS_FINISH.getValue(), Stream.of(equipmentSpotCheckTag.getEquipVariableId()).collect(Collectors.toList())); + if(CollectionUtils.isEmpty(equipmentLogCollectList)){ + throw new ImppBusiException(String.format("点检项目代码【%s】设备地址【%s】未查询到设备返回值,请检查数据!", spotCheckOrder.getSpotCheckCode(),equipmentSpotCheckTag.getTagName())); + } + if (!equipmentLogCollectList.iterator().next().getEquipVariableValue().equals(equipmentSpotCheckTag.getSuccessValue())) { + throw new ImppBusiException(String.format("点检项目代码【%s】设备地址【%s】设备返回值【%s】与理论成功值【%s】不匹配,请检查数据!", spotCheckOrder.getSpotCheckCode(),equipmentSpotCheckTag.getTagName(),equipmentLogCollectList.iterator().next().getEquipVariableValue(),equipmentSpotCheckTag.getSuccessValue())); + } + } }