diff --git a/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/spot/IMesSpotCheckOrderService.java b/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/spot/IMesSpotCheckOrderService.java index 082c5ec..c9d4e9f 100644 --- a/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/spot/IMesSpotCheckOrderService.java +++ b/modules/i3plus-ext-mes-pcn-api/src/main/java/cn/estsh/i3plus/ext/mes/pcn/api/busi/spot/IMesSpotCheckOrderService.java @@ -4,10 +4,8 @@ import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesSpotCheckOrderModel; import cn.estsh.i3plus.pojo.base.bean.ListPager; import cn.estsh.i3plus.pojo.base.common.Pager; import cn.estsh.i3plus.pojo.mes.bean.MesSpotCheckOrder; -import cn.estsh.i3plus.pojo.mes.bean.MesSpotCheckOrderPart; import io.swagger.annotations.ApiOperation; - -import java.util.List; +import org.apache.poi.ss.formula.functions.T; /** * @Description : @@ -79,5 +77,8 @@ public interface IMesSpotCheckOrderService { @ApiOperation("重新点检") void saveReCheck(MesSpotCheckOrderModel model, String org); + @ApiOperation(value = "新增信息", notes = "新增信息") + MesSpotCheckOrder insert(MesSpotCheckOrder bean); + } 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 d77466a..a2ac6e4 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 @@ -5,6 +5,7 @@ import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant; import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesSpotCheckOrderModel; import cn.estsh.i3plus.mes.pcn.api.iservice.busi.ISyncFuncService; import cn.estsh.i3plus.platform.common.convert.ConvertBean; +import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum; import cn.estsh.i3plus.platform.common.tool.TimeTool; import cn.estsh.i3plus.pojo.base.bean.DdlPackBean; import cn.estsh.i3plus.pojo.base.bean.ListPager; @@ -18,6 +19,8 @@ import cn.estsh.i3plus.pojo.mes.repository.*; import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil; import cn.estsh.impp.framework.boot.auth.AuthUtil; 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.collections4.ListUtils; import org.springframework.beans.BeanUtils; @@ -58,6 +61,14 @@ public class MesSpotCheckOrderService implements IMesSpotCheckOrderService { @Autowired private MesEquipmentLogRepository equipmentLogRepository; + @Autowired + private MesEquipmentSpotCheckRepository equipmentSpotCheckRepository; + @Autowired + private MesEquipmentSpotCheckDetailRepository equipmentSpotCheckDetailRepository; + @Autowired + private MesEquipmentSpotCheckPartRepository equipmentSpotCheckPartRepository; + + @Override public ListPager querySpotCheckOrder(MesSpotCheckOrder spotCheckOrder, Pager pager) { @@ -327,6 +338,122 @@ public class MesSpotCheckOrderService implements IMesSpotCheckOrderService { } @Override + public MesSpotCheckOrder insert(MesSpotCheckOrder bean) { +// onInsertBean(bean); + + // 数据校验 + ValidatorBean.checkNotNull(bean.getSpotCheckId(), "点检方案不能为空"); + + DdlPackBean packBean = DdlPackBean.getDdlPackBean(bean.getOrganizeCode()); + DdlPreparedPack.getNumEqualPack(bean.getSpotCheckId(), "spotCheckId", packBean); + DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.CREATE.getValue(), "status", packBean); + boolean flg = spotCheckOrderRepository.isExitByHql(packBean); + if (flg) { + throw ImppExceptionBuilder.newInstance() + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) + .setErrorDetail("存在相同配置状态为【%s】的点检单 id:【%s】,请检查数据", MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.CREATE.getDescription(), bean.getSpotCheckId()) + .build(); + } + + bean.setTaskResource(MesCommonConstant.SPOT_CHECK_ORDER_TASK_RESOURCE); + bean.setStatus(MesExtEnumUtil.SPOT_CHECK_ORDER_STATUS.CREATE.getValue()); + //查询点检方案 点检单点检方案 spotCheckId-id关联 + MesEquipmentSpotCheck equipmentSpotCheck = equipmentSpotCheckRepository.getById(bean.getSpotCheckId()); + + if (StringUtils.isEmpty(equipmentSpotCheck)) { + throw ImppExceptionBuilder.newInstance() + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) + .setErrorDetail("【%s】点检方案不存在,请检查数据", bean.getSpotCheckId()) + .build(); + } + + if (equipmentSpotCheck.getTriggerMode() == MesExtEnumUtil.EQUIPMENT_SPOT_CHECK_TRIGGER_MODE.TIME.getValue()) { + throw ImppExceptionBuilder.newInstance() + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) + .setErrorDetail("【%s】点检方案触发方式为【%s】,请勿手动创建", bean.getSpotCheckId(), MesExtEnumUtil.EQUIPMENT_SPOT_CHECK_TRIGGER_MODE.TIME.getDescription()) + .build(); + } + + //查询点检明细 主表明细表 spotCheckId-pid关联 + packBean = DdlPackBean.getDdlPackBean(bean.getOrganizeCode()); + DdlPreparedPack.getNumEqualPack(bean.getSpotCheckId(), "pid", packBean); + List detailList = equipmentSpotCheckDetailRepository.findByHqlWhere(packBean); + + if (CollectionUtils.isEmpty(detailList)) { + throw ImppExceptionBuilder.newInstance() + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) + .setErrorDetail("【%s】点检方案明细不存在,请检查数据", bean.getSpotCheckId()) + .build(); + } + + //查询点检零件 主表零件表 spotCheckId-pid关联 + List equipmentSpotCheckPartList = equipmentSpotCheckPartRepository.findByHqlWhere(packBean); + + if (CollectionUtils.isEmpty(equipmentSpotCheckPartList) && + equipmentSpotCheck.getSpotCheckOrderType() == MesExtEnumUtil.SPOT_CHECK_ORDER_TYPE.FIRST_PRODUCT_INSPECTION.getValue()) { + throw ImppExceptionBuilder.newInstance() + .setSystemID(CommonEnumUtil.SOFT_TYPE.MES.getCode()) + .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode()) + .setErrorDetail("【%s】点检方案类型为【%s】配置零件号为空,请检查数据", bean.getSpotCheckId(), MesExtEnumUtil.SPOT_CHECK_ORDER_TYPE.FIRST_PRODUCT_INSPECTION.getDescription()) + .build(); + } + + //生成单据号 + GenSerialNoModel genSerialNoModel = new GenSerialNoModel(MesCommonConstant.SPOT_CHECK_ORDER_NO_RULE); + List resultList = syncFuncService.syncSerialNo(genSerialNoModel, bean.getCreateUser(), bean.getOrganizeCode(), 1).getResultList(); + + //保存单据 + BeanUtils.copyProperties(equipmentSpotCheck, bean, "id"); +// bean.setSpotCheckOrderNo("SPOT_CHECK_ORDER_NO_0003"); + bean.setSpotCheckOrderNo(resultList.get(0)); + ConvertBean.serviceModelInitialize(bean, AuthUtil.getSessionUser().getUserName()); + bean = spotCheckOrderRepository.insert(bean); + + //保存单据明细 + List spotCheckOrderResults = new ArrayList<>(); + MesSpotCheckOrder finalBean = bean; + detailList.forEach(k -> { + MesSpotCheckOrderResult result = new MesSpotCheckOrderResult(); + BeanUtils.copyProperties(k, result, "id"); + result.setSpotCheckOrderNo(finalBean.getSpotCheckOrderNo()); + result.setPid(finalBean.getId()); + result.setWorkCenterCode(finalBean.getWorkCenterCode()); + result.setWorkCellCode(finalBean.getWorkCellCode()); + result.setSpotCheckItemId(k.getId()); + result.setTaskItemName(k.getSpotCheckItemName()); + result.setSpotCheckStandardValue(k.getStandardValue()); + ConvertBean.serviceModelInitialize(result, AuthUtil.getSessionUser().getUserName()); +// ConvertBean.serviceModelInitialize(result, "LML"); + spotCheckOrderResults.add(result); + }); + + //保存单据零件 + if (!CollectionUtils.isEmpty(equipmentSpotCheckPartList)) { + + List spotCheckOrderPartList = new ArrayList<>(); + equipmentSpotCheckPartList.forEach(k -> { + MesSpotCheckOrderPart spotCheckOrderPart = new MesSpotCheckOrderPart(); + spotCheckOrderPart.setSpotCheckOrderId(finalBean.getId()); + BeanUtils.copyProperties(k, spotCheckOrderPart, "id"); + ConvertBean.serviceModelInitialize(spotCheckOrderPart, AuthUtil.getSessionUser().getUserName()); +// ConvertBean.serviceModelInitialize(spotCheckOrderPart, "LML"); + spotCheckOrderPartList.add(spotCheckOrderPart); + }); +// spotCheckOrderPartService.insertBatch(spotCheckOrderPartList); + spotCheckOrderPartRepository.saveAll(spotCheckOrderPartList); + } + +// spotCheckOrderResultService.insertBatch(spotCheckOrderResults); + spotCheckOrderResultRepository.saveAll(spotCheckOrderResults); + + return bean; + } + + @Override public MesSpotCheckOrderModel querySpotCheckOrderResult(MesSpotCheckOrder spotCheckOrder) { //校验点检单 diff --git a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/constant/MesCommonConstant.java b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/constant/MesCommonConstant.java index ab9719e..16748bd 100644 --- a/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/constant/MesCommonConstant.java +++ b/modules/i3plus-ext-mes-pcn-pojo/src/main/java/cn/estsh/i3plus/ext/mes/pcn/pojo/constant/MesCommonConstant.java @@ -18,9 +18,14 @@ public class MesCommonConstant { public static final Integer FALSE_INTEGER = 2; - public static final String SPOT_CHECK_ORDER_NO_COPY_RULE = "SPOT_CHECK_ORDER_NO_COPY_RULE"; - + //分页最大值 public static final Integer MAX_PAGER_SIZE = 2000; + public static final String SPOT_CHECK_ORDER_TASK_RESOURCE = "MES"; + //点检单据号 + public static final String SPOT_CHECK_ORDER_NO_RULE = "SPOT_CHECK_ORDER_NO_RULE"; + //生成重新点检单据号 + public static final String SPOT_CHECK_ORDER_NO_COPY_RULE = "SPOT_CHECK_ORDER_NO_COPY_RULE"; + }