47023 PCN: NC报废流程相关优化设计文档[DM202505140012]

dev_temp_xw_202505230000_47023
xiangwei.zhang 2 months ago
parent 641a8d5fbd
commit a19b5b43b2

@ -37,4 +37,6 @@ public interface IMesNcProcessingService {
List<String> queryPartInspectionCreateUser(String organizeCode);
void syncQmsScrap(String organizeCode);
}

@ -0,0 +1,30 @@
package cn.estsh.i3plus.ext.mes.pcn.api.busi;
import cn.estsh.i3plus.pojo.mes.bean.MesQmsScrap;
import cn.estsh.i3plus.pojo.mes.bean.nc.MesPartInspection;
import cn.estsh.i3plus.pojo.mes.bean.nc.MesPartInspectionPerson;
import java.util.List;
/**
* @Description :MES_QMS
* @Reference :
* @Author : gsz
* @CreateDate 2024/7/3 10:28
* @Modify:
**/
public interface IMesQmsScrapService {
/**
* QMS
* @param mesPartInspectionList
* @param organizeCode
*/
void doQmsScrapByPartInspectionNew(List<MesPartInspection> mesPartInspectionList, List<MesPartInspectionPerson> mesPartInspectionPersonList, String organizeCode);
/**
* QMS
* @param mesPartInspectionList
* @param organizeCode
*/
void doQmsScrapByPartInspection(List<MesPartInspection> mesPartInspectionList, String organizeCode);
}

@ -155,4 +155,19 @@ public class MesNcProcessingController {
}
}
@GetMapping("/sync-qms-scrap")
@ApiOperation(value = "同步到qms中间表")
public ResultBean syncQmsScrap(String organizeCode) {
try {
ValidatorBean.checkNotNull(organizeCode, "工厂不能为空");
ncProcessingService.syncQmsScrap(organizeCode);
return ResultBean.success("同步成功");
} catch (ImppBusiException imppException) {
return ResultBean.fail(imppException);
} catch (Exception e) {
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
}

@ -1137,8 +1137,14 @@ public class MesReworkTaskServiceImpl implements IMesReworkTaskService {
}
private void doCreateScrap(MesProductionAssemblyModel assemblyModel,String userName,String responsibleParty,String organizeCode) {
MesProduceSn oldProduceSn = getMesProduceSn(organizeCode,assemblyModel.getAssemblySn());
//新增一条数据到报废表中
MesQmsScrap mesQmsScrap = new MesQmsScrap();
mesQmsScrap.setWorkCenterCode(oldProduceSn.getWorkCenterCode());
mesQmsScrap.setWorkCellCode(oldProduceSn.getWorkCellCode());
mesQmsScrap.setShiftGroup(oldProduceSn.getShiftGroup());
mesQmsScrap.setOrganizeCode(organizeCode);
mesQmsScrap.setAsnNo("");
mesQmsScrap.setSource("MES");

@ -33,6 +33,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
@ -125,6 +126,11 @@ public class MesNcProcessingService implements IMesNcProcessingService {
@Autowired
private MesPartInspectionPersonRepository mesPartInspectionPersonRepository;
@Autowired
private MesPartInspectionPersonRepository partInspectionPersonRepository;
@Autowired
private IMesQmsScrapService mesQmsScrapService;
@Override
public ListPager<MesPartInspection> queryPartInspectionByPager(MesPartInspection partInspection, Pager pager) {
@ -1062,4 +1068,97 @@ public class MesNcProcessingService implements IMesNcProcessingService {
move.setWorkCenter(prodOrgExtService.getErpWorkCenterCode(org, workCenterCode));
return move;
}
@Override
public void syncQmsScrap(String organizeCode) {
boolean isNew = false;
MesConfig mesConfig = configService.getCfgValueByCode(organizeCode, "MES_SCAP_IS_NEW_TYPE");
if (mesConfig != null && Objects.equals(mesConfig.getCfgValue(), "1")) {
isNew = true;
}
if (isNew) {
sendToQmsNew(organizeCode);
} else {
sendToQms(organizeCode);
}
}
private void sendToQmsNew(String organizeCode) {
List<MesPartInspection> mesPartInspectionAllList = new ArrayList<>();
//获取前一天的所有ncStatus=40报废状态下可疑品缺陷
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
//DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.PART_INSPECTION_STATUS.FAIL.getValue(), "inspectionStatus", packBean);
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.PART_INSPECTION_NC_STATUS.SCRAP.getValue(), "ncStatus", packBean);
//查同步标识为3的数据如果接口映射同步则更新为1
DdlPreparedPack.getNumNOEqualPack(1, "systemSyncStatus", packBean);
List<MesPartInspectionPerson> mesPartInspectionPersonList = partInspectionPersonRepository.findByHqlWhere(packBean);
if (!CollectionUtils.isEmpty(mesPartInspectionPersonList)) {
List<Long> inspectionIds = mesPartInspectionPersonList.stream().map(MesPartInspectionPerson::getPid).collect(Collectors.toList());
//获取前一天的所有ncStatus=40报废状态下可疑品缺陷
DdlPackBean inspectionBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getInPackList(inspectionIds, "id", inspectionBean);
//DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.PART_INSPECTION_STATUS.FAIL.getValue(), "inspectionStatus", packBean);
List<MesPartInspection> mesPartInspectionList = partInspectionRepository.findByHqlWhere(inspectionBean);
log.info("一共需要汇总的批次加导入{}条报废数据2", mesPartInspectionList.size());
mesPartInspectionAllList.addAll(mesPartInspectionList);
}
//获取前一天的所有ncStatus=40报废状态下可疑品缺陷
DdlPackBean singlePackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.PART_INSPECTION_STATUS.FAIL.getValue(), "inspectionStatus", packBean);
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.PART_INSPECTION_NC_STATUS.SCRAP.getValue(), "ncStatus", packBean);
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.PART_INSPECTION_SOURCE_TYPE.SINGLE.getValue(), "sourceType", packBean);
//查同步标识为3的数据如果接口映射同步则更新为1
DdlPreparedPack.getNumNOEqualPack(1, "systemSyncStatus", packBean);
List<MesPartInspection> mesPartInspectionSingleList = partInspectionRepository.findByHqlWhere(packBean);
if (!CollectionUtils.isEmpty(mesPartInspectionSingleList)) {
log.info("一共需要汇总的单件{}条报废数据2", mesPartInspectionSingleList.size());
mesPartInspectionAllList.addAll(mesPartInspectionSingleList);
}
log.info("一共需要汇总{}条报废数据2", mesPartInspectionAllList.size());
mesQmsScrapService.doQmsScrapByPartInspectionNew(mesPartInspectionAllList,mesPartInspectionPersonList, organizeCode);
for (MesPartInspection mesPartInspection : mesPartInspectionAllList) {
mesPartInspection.setSystemSyncStatus(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
// ConvertBean.serviceModelUpdate(mesPartInspection, MesExtConstWords.JOB);
}
for (MesPartInspectionPerson mesPartInspectionPerson : mesPartInspectionPersonList) {
mesPartInspectionPerson.setSystemSyncStatus(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
}
partInspectionRepository.saveAll(mesPartInspectionAllList);
partInspectionPersonRepository.saveAll(mesPartInspectionPersonList);
}
private void sendToQms(String organizeCode){
//获取前一天的所有ncStatus=40报废状态下可疑品缺陷
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.PART_INSPECTION_STATUS.FAIL.getValue(), "inspectionStatus", packBean);
DdlPreparedPack.getNumEqualPack(MesExtEnumUtil.PART_INSPECTION_NC_STATUS.SCRAP.getValue(), "ncStatus", packBean);
//查同步标识为3的数据如果接口映射同步则更新为1
DdlPreparedPack.getNumNOEqualPack(1, "systemSyncStatus", packBean);
DdlPreparedPack.timeBuilder(
new SimpleDateFormat("yyyy-MM-dd").format(TimeTool.getDateBefore(new Date(), 1)) + " 00:00:00",
TimeTool.getToday() + " 00:00:00", "createDatetime", packBean, true);
List<MesPartInspection> mesPartInspectionList = partInspectionRepository.findByHqlWhere(packBean);
if (!CollectionUtils.isEmpty(mesPartInspectionList)) {
log.info("一共需要汇总{}条报废数据2", mesPartInspectionList.size());
mesQmsScrapService.doQmsScrapByPartInspection(mesPartInspectionList, organizeCode);
for (MesPartInspection mesPartInspection : mesPartInspectionList) {
mesPartInspection.setSystemSyncStatus(CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue());
// ConvertBean.serviceModelUpdate(mesPartInspection, MesExtConstWords.JOB);
}
partInspectionRepository.saveAll(mesPartInspectionList);
}
}
}

@ -0,0 +1,210 @@
package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.busi;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesQmsScrapService;
import cn.estsh.i3plus.ext.mes.pcn.apiservice.util.MesPcnException;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesPartInspectionModel;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
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.MesProduceSn;
import cn.estsh.i3plus.pojo.mes.bean.MesQmsScrap;
import cn.estsh.i3plus.pojo.mes.bean.nc.MesPartInspection;
import cn.estsh.i3plus.pojo.mes.bean.nc.MesPartInspectionDetail;
import cn.estsh.i3plus.pojo.mes.bean.nc.MesPartInspectionPerson;
import cn.estsh.i3plus.pojo.mes.repository.MesPartInspectionDetailRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesProduceSnRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesQmsScrapRepository;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
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 java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @Description :MES_QMS
* @Reference :
* @Author : gsz
* @CreateDate 2024/7/3 10:28
* @Modify:
**/
@Service
@Slf4j
public class MesQmsScrapService implements IMesQmsScrapService {
@Autowired
private MesPartInspectionDetailRepository partInspectionDetailRDao;
@Autowired
private MesProduceSnRepository mesProduceSnRepository;
@Autowired
private MesQmsScrapRepository mesQmsScrapRepository;
@Override
public void doQmsScrapByPartInspectionNew(List<MesPartInspection> mesPartInspectionLists, List<MesPartInspectionPerson> mesPartInspectionPersonList, String organizeCode) {
Map<String, List<MesPartInspection>> map = mesPartInspectionLists.stream().collect(Collectors.groupingBy(MesPartInspection::getInspectionDate));
map.forEach((k,v) -> {
String inspectionDate = k;
List<MesPartInspection> mesPartInspectionList = v;
List<Long> idList = mesPartInspectionList.stream().map(MesPartInspection::getId).collect(Collectors.toList());
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getInPackList(idList, "pid", packBean);
List<MesPartInspectionDetail> partInspectionDetails = partInspectionDetailRDao.findByHqlWhere(packBean);
Map<Long, List<MesPartInspectionDetail>> idDetailListMap = partInspectionDetails.stream().collect(Collectors.groupingBy(MesPartInspectionDetail::getPid));
List<MesPartInspectionModel> partInspectionModels = new ArrayList<>();
for (MesPartInspection mesPartInspection : mesPartInspectionList) {
MesPartInspectionModel mesPartInspectionModel = new MesPartInspectionModel();
BeanUtils.copyProperties(mesPartInspection, mesPartInspectionModel);
if (Objects.equals(mesPartInspection.getSourceType(), MesExtEnumUtil.PART_INSPECTION_SOURCE_TYPE.SINGLE.getValue())) {
// 根据条码查询条码信息
DdlPackBean ddlPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(mesPartInspection.getSn(),"productSn", ddlPackBean);
DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{"createDatetime"}, ddlPackBean);
MesProduceSn mesProduceSn = mesProduceSnRepository.getByProperty(ddlPackBean);
if (mesProduceSn == null) {
DdlPackBean custPackBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getStringEqualPack(mesPartInspection.getSn(),"custSn", custPackBean);
DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.DESC.getValue()}, new String[]{"createDatetime"}, custPackBean);
mesProduceSn = mesProduceSnRepository.getByProperty(custPackBean);
if (mesProduceSn == null) {
MesPcnException.throwBusiException(String.format("条码:【%s】不存在", mesPartInspection.getSn()));
}
}
mesPartInspectionModel.setWorkCenterCode(mesProduceSn.getWorkCenterCode());
mesPartInspectionModel.setWorkCellCode(mesProduceSn.getWorkCellCode());
mesPartInspectionModel.setShiftGroup(mesProduceSn.getShiftGroup());
partInspectionModels.add(mesPartInspectionModel);
} else {
mesPartInspectionModel.setWorkCenterCode(mesPartInspection.getWorkCenterCode());
partInspectionModels.add(mesPartInspectionModel);
}
}
//43326 电子化检验发送给QMS的数据按照零件号+责任人类型分组发送
//Map<String, List<MesPartInspection>> workOrderPartMap = mesPartInspectionList.stream().collect(Collectors.groupingBy(p -> p.getPartNo() +"="+p.getResponsibleParty()));
Map<MesPartInspectionModel, List<MesPartInspectionModel>> workOrderPartMap = partInspectionModels.stream().collect(Collectors.groupingBy(p -> {
MesPartInspectionModel mesPartInspectionModel = new MesPartInspectionModel();
mesPartInspectionModel.setWorkCenterCode(p.getWorkCenterCode());
mesPartInspectionModel.setWorkCellCode(p.getWorkCellCode());
mesPartInspectionModel.setShiftGroup(p.getShiftGroup());
mesPartInspectionModel.setPartNo(p.getPartNo());
mesPartInspectionModel.setResponsibleParty(p.getResponsibleParty());
return mesPartInspectionModel;
}));
//根据物料对可疑品分组
List<MesQmsScrap> qmsScrapList = new ArrayList<>();
log.info("一共需要汇总{}条报废数据2", workOrderPartMap.size());
Map<Long, List<MesPartInspectionPerson>> personMap = mesPartInspectionPersonList.stream().collect(Collectors.groupingBy(MesPartInspectionPerson::getPid));
for (Map.Entry<MesPartInspectionModel, List<MesPartInspectionModel>> stringListEntry : workOrderPartMap.entrySet()) {
MesPartInspectionModel mesPartInspectionModel = stringListEntry.getKey();
String keyPartNo = mesPartInspectionModel.getPartNo();
List<MesPartInspectionModel> mesPartInspections = stringListEntry.getValue();
MesPartInspectionModel next = mesPartInspections.iterator().next();
List<MesPartInspectionDetail> mesPartInspectionDetails = new ArrayList<>();
for (MesPartInspectionModel mesPartInspection : mesPartInspections) {
mesPartInspectionDetails.addAll(idDetailListMap.get(mesPartInspection.getId()));
}
//新增一条数据到报废表中
MesQmsScrap mesQmsScrap = new MesQmsScrap();
mesQmsScrap.setWorkCenterCode(mesPartInspectionModel.getWorkCenterCode());
mesQmsScrap.setWorkCellCode(mesPartInspectionModel.getWorkCellCode());
mesQmsScrap.setShiftGroup(mesPartInspectionModel.getShiftGroup());
mesQmsScrap.setOrganizeCode(organizeCode);
mesQmsScrap.setAsnNo("");
mesQmsScrap.setSource("MES");
double sum = 0.0;
for (MesPartInspection mesPartInspection : mesPartInspections) {
if (Objects.equals(mesPartInspection.getSourceType(), MesExtEnumUtil.PART_INSPECTION_SOURCE_TYPE.SINGLE.getValue())) {
sum += mesPartInspection.getRejectQty();
} else {
List<MesPartInspectionPerson> personList = personMap.get(mesPartInspection.getId());
if (!CollectionUtils.isEmpty(personList)) {
double rejectQty = personList.stream().map(MesPartInspectionPerson::getQty).reduce((a, b) -> a + b).get();
sum += rejectQty;
}
}
}
mesQmsScrap.setRejectQty(sum);
mesQmsScrap.setPartNo(keyPartNo);
mesQmsScrap.setPartName(next.getPartName());
String defectTypeName = mesPartInspectionDetails.stream().map(MesPartInspectionDetail::getDefectTypeName).collect(Collectors.joining(";"));
mesQmsScrap.setDefectTypeName(defectTypeName);
mesQmsScrap.setReponsibilityId(next.getResponsibleParty());
mesQmsScrap.setNcJudger(next.getModifyUser());
ConvertBean.serviceModelInitialize(mesQmsScrap, "MesScrapJob");
qmsScrapList.add(mesQmsScrap);
}
log.info("一共需要汇总{}条报废数据3", qmsScrapList.size());
mesQmsScrapRepository.saveAll(qmsScrapList);
});
}
@Override
public void doQmsScrapByPartInspection(List<MesPartInspection> mesPartInspectionLists, String organizeCode){
Map<String, List<MesPartInspection>> map = mesPartInspectionLists.stream().collect(Collectors.groupingBy(MesPartInspection::getInspectionDate));
map.forEach((k,v) -> {
String inspectionDate = k;
List<MesPartInspection> mesPartInspectionList = v;
List<Long> idList = mesPartInspectionList.stream().map(MesPartInspection::getId).collect(Collectors.toList());
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
DdlPreparedPack.getInPackList(idList, "pid", packBean);
List<MesPartInspectionDetail> partInspectionDetails = partInspectionDetailRDao.findByHqlWhere(packBean);
Map<Long, List<MesPartInspectionDetail>> idDetailListMap = partInspectionDetails.stream().collect(Collectors.groupingBy(MesPartInspectionDetail::getPid));
//43326 电子化检验发送给QMS的数据按照零件号+责任人类型分组发送
Map<String, List<MesPartInspection>> workOrderPartMap = mesPartInspectionList.stream().collect(Collectors.groupingBy(p -> p.getPartNo() + "=" + p.getResponsibleParty()));
//根据物料对可疑品分组
List<MesQmsScrap> qmsScrapList = new ArrayList<>();
log.info("一共需要汇总{}条报废数据2", workOrderPartMap.size());
for (Map.Entry<String, List<MesPartInspection>> stringListEntry : workOrderPartMap.entrySet()) {
String keyPartNo = stringListEntry.getKey().split("=")[0];
List<MesPartInspection> mesPartInspections = stringListEntry.getValue();
MesPartInspection next = mesPartInspections.iterator().next();
List<MesPartInspectionDetail> mesPartInspectionDetails = new ArrayList<>();
for (MesPartInspection mesPartInspection : mesPartInspections) {
mesPartInspectionDetails.addAll(idDetailListMap.get(mesPartInspection.getId()));
}
//新增一条数据到报废表中
MesQmsScrap mesQmsScrap = new MesQmsScrap();
mesQmsScrap.setOrganizeCode(organizeCode);
mesQmsScrap.setAsnNo("");
mesQmsScrap.setSource("MES");
double sum = mesPartInspections.stream().mapToDouble(MesPartInspection::getRejectQty).sum();
mesQmsScrap.setRejectQty(sum);
mesQmsScrap.setPartNo(keyPartNo);
mesQmsScrap.setPartName(next.getPartName());
String defectTypeName = mesPartInspectionDetails.stream().map(MesPartInspectionDetail::getDefectTypeName).collect(Collectors.joining(";"));
mesQmsScrap.setDefectTypeName(defectTypeName);
mesQmsScrap.setReponsibilityId(next.getResponsibleParty());
mesQmsScrap.setNcJudger(next.getModifyUser());
ConvertBean.serviceModelInitialize(mesQmsScrap, "MesScrapJob");
qmsScrapList.add(mesQmsScrap);
}
log.info("一共需要汇总{}条报废数据3", qmsScrapList.size());
mesQmsScrapRepository.saveAll(qmsScrapList);
});
}
}

@ -0,0 +1,15 @@
package cn.estsh.i3plus.ext.mes.pcn.pojo.model;
import cn.estsh.i3plus.pojo.mes.bean.nc.MesPartInspection;
import lombok.Data;
@Data
public class MesPartInspectionModel extends MesPartInspection {
// 产线
private String workCenterCode;
// 工位
private String workCellCode;
// 班组
private String shiftGroup;
}
Loading…
Cancel
Save