|
|
|
@ -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<MesSpotCheckOrder> 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<MesEquipmentSpotCheckDetail> 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<MesEquipmentSpotCheckPart> 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<String> 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<MesSpotCheckOrderResult> 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<MesSpotCheckOrderPart> 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) {
|
|
|
|
|
|
|
|
|
|
//校验点检单
|
|
|
|
|