|
|
|
@ -0,0 +1,290 @@
|
|
|
|
|
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.busi;
|
|
|
|
|
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.api.base.IBaseMesService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.api.base.IMesEquipmentSpotCheckService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.api.busi.IMesSpotCheckOrderPartService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.api.busi.IMesSpotCheckOrderResultService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base.BaseMesService;
|
|
|
|
|
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.mes.api.iservice.busi.ISyncFuncService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
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.model.GenSerialNoModel;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesEquipmentSpotCheckDetailRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesEquipmentSpotCheckPartRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesSpotCheckOrderPartRepository;
|
|
|
|
|
import cn.estsh.i3plus.pojo.mes.repository.MesSpotCheckOrderResultRepository;
|
|
|
|
|
import cn.estsh.impp.framework.boot.auth.AuthUtil;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
|
import cn.estsh.impp.framework.boot.util.ValidatorBean;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class MesSpotCheckOrderService extends BaseMesService<MesSpotCheckOrder> implements IBaseMesService<MesSpotCheckOrder> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesEquipmentSpotCheckService equipmentSpotCheckService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesSpotCheckOrderResultService spotCheckOrderResultService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesSpotCheckOrderResultRepository spotCheckOrderResultRepository;
|
|
|
|
|
@Autowired
|
|
|
|
|
private IMesSpotCheckOrderPartService spotCheckOrderPartService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesSpotCheckOrderPartRepository spotCheckOrderPartRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesEquipmentSpotCheckDetailRepository equipmentSpotCheckDetailRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesEquipmentSpotCheckPartRepository equipmentSpotCheckPartRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private ISyncFuncService syncFuncService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MesSpotCheckOrder insert(MesSpotCheckOrder bean) {
|
|
|
|
|
onInsertBean(bean);
|
|
|
|
|
|
|
|
|
|
//查询点检方案 点检单点检方案 spotCheckId-id关联
|
|
|
|
|
MesEquipmentSpotCheck equipmentSpotCheck = equipmentSpotCheckService.get(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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//查询点检明细 主表明细表 spotCheckId-pid关联
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(bean.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getNumberBiggerEqualPack(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();
|
|
|
|
|
List<String> resultList = syncFuncService.syncSerialNo(genSerialNoModel, bean.getCreateUser(), bean.getOrganizeCode(), 1).getResultList();
|
|
|
|
|
|
|
|
|
|
//保存单据
|
|
|
|
|
BeanUtils.copyProperties(equipmentSpotCheck, bean, "id");
|
|
|
|
|
bean.setSpotCheckOrderNo(resultList.get(0));
|
|
|
|
|
// ConvertBean.serviceModelInitialize(bean, AuthUtil.getSessionUser().getUserName());
|
|
|
|
|
bean = baseRDao.insert(bean);
|
|
|
|
|
|
|
|
|
|
//保存单据明细
|
|
|
|
|
List<MesSpotCheckOrderResult> spotCheckOrderResults = new ArrayList<>();
|
|
|
|
|
MesSpotCheckOrder finalBean = bean;
|
|
|
|
|
detailList.forEach(k -> {
|
|
|
|
|
MesSpotCheckOrderResult result = new MesSpotCheckOrderResult();
|
|
|
|
|
BeanUtils.copyProperties(k, result, "id");
|
|
|
|
|
result.setPid(finalBean.getId());
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spotCheckOrderResultService.insertBatch(spotCheckOrderResults);
|
|
|
|
|
|
|
|
|
|
return bean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public MesSpotCheckOrder update(MesSpotCheckOrder bean) {
|
|
|
|
|
onUpdateBean(bean);
|
|
|
|
|
//获取点检单
|
|
|
|
|
MesSpotCheckOrder originBean = baseRDao.getById(bean.getId());
|
|
|
|
|
|
|
|
|
|
//获取点检单明细
|
|
|
|
|
DdlPackBean orderResultPackBean = DdlPackBean.getDdlPackBean(bean.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getNumEqualPack(bean.getId(), "pid", orderResultPackBean);
|
|
|
|
|
List<MesSpotCheckOrderResult> oldOrderResultList = spotCheckOrderResultRepository.findByHqlWhere(orderResultPackBean);
|
|
|
|
|
|
|
|
|
|
//软删点检单明细
|
|
|
|
|
oldOrderResultList.forEach(k -> {
|
|
|
|
|
k.setIsDeleted(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
ConvertBean.serviceModelUpdate(k, AuthUtil.getSessionUser().getUserName());
|
|
|
|
|
});
|
|
|
|
|
spotCheckOrderResultRepository.saveAll(oldOrderResultList);
|
|
|
|
|
|
|
|
|
|
//获取点检单零件号
|
|
|
|
|
List<MesSpotCheckOrderPart> oldOrderPartList = spotCheckOrderPartRepository.findByHqlWhere(orderResultPackBean);
|
|
|
|
|
|
|
|
|
|
//软删点检单零件号及条码
|
|
|
|
|
oldOrderPartList.forEach(k -> {
|
|
|
|
|
k.setIsDeleted(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
ConvertBean.serviceModelUpdate(k, AuthUtil.getSessionUser().getUserName());
|
|
|
|
|
});
|
|
|
|
|
spotCheckOrderPartRepository.saveAll(oldOrderPartList);
|
|
|
|
|
|
|
|
|
|
//获取点检方案 点检单点检方案 spotCheckId-id关联
|
|
|
|
|
MesEquipmentSpotCheck equipmentSpotCheck = equipmentSpotCheckService.get(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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//获取点检方案明细 主表明细表 spotCheckId-pid关联
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(bean.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getNumberBiggerEqualPack(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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<MesSpotCheckOrderResult> spotCheckOrderResults = new ArrayList<>();
|
|
|
|
|
MesSpotCheckOrder finalBean = bean;
|
|
|
|
|
detailList.forEach(k -> {
|
|
|
|
|
MesSpotCheckOrderResult result = new MesSpotCheckOrderResult();
|
|
|
|
|
BeanUtils.copyProperties(k, result, "id");
|
|
|
|
|
result.setPid(finalBean.getId());
|
|
|
|
|
ConvertBean.serviceModelInitialize(result, AuthUtil.getSessionUser().getUserName());
|
|
|
|
|
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());
|
|
|
|
|
spotCheckOrderPartList.add(spotCheckOrderPart);
|
|
|
|
|
});
|
|
|
|
|
spotCheckOrderPartService.insertBatch(spotCheckOrderPartList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
spotCheckOrderResultService.insertBatch(spotCheckOrderResults);
|
|
|
|
|
ConvertBean.serviceModelUpdate(bean, AuthUtil.getSessionUser().getUserName());
|
|
|
|
|
baseRDao.update(bean);
|
|
|
|
|
return originBean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void deleteWeaklyByIds(Long[] ids, String userName) {
|
|
|
|
|
|
|
|
|
|
for (Long id : ids) {
|
|
|
|
|
MesSpotCheckOrder bean = baseRDao.getById(id);
|
|
|
|
|
if (StringUtils.isEmpty(bean)) continue;
|
|
|
|
|
//获取点检方案明细
|
|
|
|
|
DdlPackBean packBean = DdlPackBean.getDdlPackBean(bean.getOrganizeCode());
|
|
|
|
|
DdlPreparedPack.getNumberBiggerEqualPack(bean.getSpotCheckId(), "pid", packBean);
|
|
|
|
|
List<MesEquipmentSpotCheckDetail> detailList = equipmentSpotCheckDetailRepository.findByHqlWhere(packBean);
|
|
|
|
|
detailList.forEach(k -> {
|
|
|
|
|
k.setIsDeleted(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
ConvertBean.serviceModelUpdate(k, AuthUtil.getSessionUser().getUserName());
|
|
|
|
|
});
|
|
|
|
|
equipmentSpotCheckDetailRepository.saveAll(detailList);
|
|
|
|
|
|
|
|
|
|
//获取点检方案零件 主表零件表 spotCheckId-pid关联
|
|
|
|
|
List<MesEquipmentSpotCheckPart> equipmentSpotCheckPartList = equipmentSpotCheckPartRepository.findByHqlWhere(packBean);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(equipmentSpotCheckPartList)) {
|
|
|
|
|
equipmentSpotCheckPartList.forEach(k -> {
|
|
|
|
|
k.setIsDeleted(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
|
|
|
|
|
ConvertBean.serviceModelUpdate(k, AuthUtil.getSessionUser().getUserName());
|
|
|
|
|
});
|
|
|
|
|
equipmentSpotCheckPartRepository.saveAll(equipmentSpotCheckPartList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void onInsertBean(MesSpotCheckOrder 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 = baseRDao.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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void onUpdateBean(MesSpotCheckOrder bean) {
|
|
|
|
|
|
|
|
|
|
// 数据校验
|
|
|
|
|
ValidatorBean.checkNotNull(bean.getSpotCheckId(), "点检方案不能为空");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|