MES_QMS报废品汇总+MES可疑品汇总JOB

tags/yfai-mes-ext-v1.0
gsz 11 months ago
parent fceafc19ee
commit d15d620e92

@ -13,7 +13,7 @@ import java.util.List;
* @Modify:
**/
public interface IMesCcscTaskService extends IBaseMesService<MesCcscTask> {
MesCcscTask insert(MesWorkOrder mesWorkOrder,String orderNo,Integer frequency,Integer rule,Integer qtyRule);
MesCcscTask insert(MesWorkOrder mesWorkOrder,String testType,String orderNo,Integer frequency,Integer rule,Integer qtyRule);
void doCcscTaskByMesWorkOrder(String organizeCode,List<MesWorkOrder> mesWorkOrderList);
}

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

@ -0,0 +1,22 @@
package cn.estsh.i3plus.ext.mes.api.base;
import cn.estsh.i3plus.pojo.mes.bean.MesQmsSuspicious;
import cn.estsh.i3plus.pojo.mes.bean.nc.MesPartInspection;
import java.util.List;
/**
* @Description :MES
* @Reference :
* @Author : gsz
* @CreateDate 2024/7/3 10:28
* @Modify:
**/
public interface IMesQmsSuspiciousService extends IBaseMesService<MesQmsSuspicious> {
/**
* QMS
* @param mesPartInspectionList
* @param organizeCode
*/
void doQmsSuspiciousByPartInspection(List<MesPartInspection> mesPartInspectionList, String organizeCode);
}

@ -61,7 +61,7 @@ class sapToMesCcscTaskResult {
insertSqlList.add("update mes_ccsc_task set task_result = '"+taskResult+ "' " +
" where organize_code= '"+organizeCode+"' and task_no= '"+taskNo+"'; ");
LOGGER.info("-------- filterData Start QMS同步MES_CCSC任务检测结果 60----------")
LOGGER.info("-------- filterData Start QMS同步MES_CCSC任务检测结果 60-{}-------",taskResult)
if (resultMap.size() > 0) {
sqlParams.put("work_order_no", resultMap.get(0).get("work_order_no"));

@ -1,19 +1,22 @@
package cn.estsh.i3plus.ext.mes.apiservice.controller.busi;
import cn.estsh.i3plus.ext.mes.api.base.IMesCcscTaskService;
import cn.estsh.i3plus.ext.mes.api.base.IMesConfigService;
import cn.estsh.i3plus.ext.mes.api.base.IMesWorkOrderService;
import cn.estsh.i3plus.ext.mes.api.base.*;
import cn.estsh.i3plus.ext.mes.api.busi.IMaximoService;
import cn.estsh.i3plus.ext.mes.pojo.model.MaximoParamModel;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
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.MesProductionRecord;
import cn.estsh.i3plus.pojo.mes.bean.MesShift;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrder;
import cn.estsh.i3plus.pojo.mes.bean.nc.MesPartInspection;
import cn.estsh.i3plus.pojo.mes.repository.MesPartInspectionRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesProductionRecordRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesShiftRepository;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import cn.estsh.impp.framework.base.controller.MesBaseController;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
@ -25,7 +28,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -54,6 +59,13 @@ public class MesWhiteListController extends MesBaseController {
@Autowired
private IMesConfigService configService;
@Autowired
private MesPartInspectionRepository partInspectionRepository;
@Autowired
private IMesQmsScrapService qmsScrapService;
@Autowired
private IMesQmsSuspiciousService qmsSuspiciousService;
@PostMapping(value = "/meter/main-data")
@ApiOperation(value = "Maximo仪表主数据", notes = "Maximo仪表主数据")
public Map doMeterMainData(@RequestBody MaximoParamModel paramModel) {
@ -144,4 +156,45 @@ public class MesWhiteListController extends MesBaseController {
}
return ResultBean.success();
}
@GetMapping(value = "/qmsScrap")
@ApiOperation(value = "qmsScrap", notes = " ")
public ResultBean doQmsScrapTest(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);
DdlPreparedPack.getNumEqualPack(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), "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)) {
qmsScrapService.doQmsScrapByPartInspection(mesPartInspectionList,organizeCode);
for (MesPartInspection mesPartInspection : mesPartInspectionList) {
mesPartInspection.setSystemSyncStatus(1);
mesPartInspection.setSystemSyncDatetime(TimeTool.getNowTime(true));
}
partInspectionRepository.saveAll(mesPartInspectionList);
}
return ResultBean.success().setSuccess(true);
}
@GetMapping(value = "/qmsSuspicious")
@ApiOperation(value = "qmsSuspicious", notes = " ")
public ResultBean doQmsSuspiciousTest(String organizeCode) {
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
// DdlPreparedPack.getNumEqualPack(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), "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)) {
qmsSuspiciousService.doQmsSuspiciousByPartInspection(mesPartInspectionList,organizeCode);
}
return ResultBean.success().setSuccess(true);
}
}

@ -0,0 +1,98 @@
package cn.estsh.i3plus.ext.mes.apiservice.schedulejob;
import cn.estsh.i3plus.ext.mes.api.base.IMesQmsScrapService;
import cn.estsh.i3plus.mes.apiservice.schedulejob.BaseMesScheduleJob;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
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.nc.MesPartInspection;
import cn.estsh.i3plus.pojo.mes.repository.MesPartInspectionRepository;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import cn.estsh.impp.framework.boot.init.ApplicationProperties;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* @Description : MES_QMS
* @Reference :
* @Author : gsz
* @CreateDate 2024/7/3 8:58
* @Modify:
**/
@DisallowConcurrentExecution
@ApiOperation("MES_QMS报废品汇总Job")
public class MesQmsScrapJob extends BaseMesScheduleJob {
public static final Logger LOGGER = LoggerFactory.getLogger(MesQmsScrapJob.class);
private static final long serialVersionUID = 5078389675215031222L;
@Autowired
private MesPartInspectionRepository partInspectionRepository;
@Autowired
private IMesQmsScrapService qmsScrapService;
@Value("${server.port}")
private String serverPort;
@Value("${impp.server.ip}")
private String ip;
public MesQmsScrapJob() {
super(MesQmsScrapJob.class, "MES_QMS报废品汇总");
this.setMultiInstance(true);
}
@Override
public void executeMesJob(JobExecutionContext context, ApplicationProperties applicationProperties) {
try {
String jobParam = this.getJobParam();
if (StringUtils.isBlank(jobParam)) {
throw new IllegalArgumentException("MES_QMS报废品汇总job参数为空请检查参数");
}
String[] organizeCodeList = jobParam.split(",");
LOGGER.info("MES_QMS报废品汇总 -----start");
for (String organizeCode : organizeCodeList) {
//获取前一天的所有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);
//查同步标识为2的数据如果接口映射同步则更新为1
DdlPreparedPack.getNumEqualPack(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), "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)) {
qmsScrapService.doQmsScrapByPartInspection(mesPartInspectionList,organizeCode);
for (MesPartInspection mesPartInspection : mesPartInspectionList) {
mesPartInspection.setSystemSyncStatus(1);
mesPartInspection.setSystemSyncDatetime(TimeTool.getNowTime(true));
}
partInspectionRepository.saveAll(mesPartInspectionList);
}
}
LOGGER.info("MES_QMS报废品汇总 ----- end");
} catch (Exception e) {
LOGGER.error("MES_QMS报废品汇总 e:{}", e.toString());
}
}
}

@ -0,0 +1,94 @@
package cn.estsh.i3plus.ext.mes.apiservice.schedulejob;
import cn.estsh.i3plus.ext.mes.api.base.IMesQmsSuspiciousService;
import cn.estsh.i3plus.mes.apiservice.schedulejob.BaseMesScheduleJob;
import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.nc.MesPartInspection;
import cn.estsh.i3plus.pojo.mes.repository.MesPartInspectionRepository;
import cn.estsh.impp.framework.boot.init.ApplicationProperties;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* @Description : MES
* @Reference :
* @Author : gsz
* @CreateDate 2024/7/3 15:58
* @Modify:
**/
@DisallowConcurrentExecution
@ApiOperation("MES可疑品汇总")
public class MesQmsSuspiciousJob extends BaseMesScheduleJob {
public static final Logger LOGGER = LoggerFactory.getLogger(MesQmsSuspiciousJob.class);
private static final long serialVersionUID = 5078389675215031222L;
@Autowired
private MesPartInspectionRepository partInspectionRepository;
@Autowired
private IMesQmsSuspiciousService qmsSuspiciousService;
@Value("${server.port}")
private String serverPort;
@Value("${impp.server.ip}")
private String ip;
public MesQmsSuspiciousJob() {
super(MesQmsSuspiciousJob.class, "MES可疑品汇总");
this.setMultiInstance(true);
}
@Override
public void executeMesJob(JobExecutionContext context, ApplicationProperties applicationProperties) {
try {
String jobParam = this.getJobParam();
if (StringUtils.isBlank(jobParam)) {
throw new IllegalArgumentException("MES可疑品汇总job参数为空请检查参数");
}
String[] organizeCodeList = jobParam.split(",");
LOGGER.info("MES可疑品汇总 -----start");
for (String organizeCode : organizeCodeList) {
//获取前一天的所有ncStatus=40报废状态下可疑品缺陷
DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
//按天执行前一天的所有可疑记录
// DdlPreparedPack.getNumEqualPack(CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue(), "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)) {
qmsSuspiciousService.doQmsSuspiciousByPartInspection(mesPartInspectionList,organizeCode);
for (MesPartInspection mesPartInspection : mesPartInspectionList) {
mesPartInspection.setSystemSyncStatus(1);
mesPartInspection.setSystemSyncDatetime(TimeTool.getNowTime(true));
}
partInspectionRepository.saveAll(mesPartInspectionList);
}
}
LOGGER.info("MES可疑品汇总 ----- end");
} catch (Exception e) {
LOGGER.error("MES可疑品汇总 e:{}", e.toString());
}
}
}

@ -47,10 +47,12 @@ public class MesCcscTaskServiceImpl extends BaseMesService<MesCcscTask> implemen
}
@Override
public MesCcscTask insert(MesWorkOrder mesWorkOrder, String orderNo, Integer frequency, Integer rule, Integer qtyRule) {
public MesCcscTask insert(MesWorkOrder mesWorkOrder, String testType, String orderNo, Integer frequency, Integer rule, Integer qtyRule) {
MesCcscTask mesCcscTask = new MesCcscTask(mesWorkOrder);
mesCcscTask.setTaskNo(orderNo);
mesCcscTask.setFrequency(frequency);
mesCcscTask.setTestType(testType);
mesCcscTask.setAssemblyLine(mesWorkOrder.getWorkCenterCode());
mesCcscTask.setRule(rule);
mesCcscTask.setQty((double)qtyRule);
ConvertBean.serviceModelInitialize(mesCcscTask, mesWorkOrder.getModifyUser());
@ -85,6 +87,8 @@ public class MesCcscTaskServiceImpl extends BaseMesService<MesCcscTask> implemen
Integer frequency = ccscRule.getFrequency();
Integer rule = ccscRule.getRule();
Integer qtyRule = ccscRule.getQty();
String testType = ccscRule.getTestType();
Integer ccscRuleQty = 1;
LOGGER.info("-------- doCcscTaskByMesWorkOrder--83-{}",rule);
List<MesWorkOrder> mesWorkOrderToTask=new ArrayList<>();
//首件取第一个工单?还是全部工单都同步,取工单明细条码的首件条码?
@ -102,10 +106,12 @@ public class MesCcscTaskServiceImpl extends BaseMesService<MesCcscTask> implemen
if (!mesWorkOrderToTask.contains(next)) {
mesWorkOrderToTask.add(next);
}
ccscRuleQty=2;
break;
case 4://随机
int qty= mesWorkOrders.size()/qtyRule ;
mesWorkOrderToTask.addAll(mesWorkOrders.stream().sorted(Comparator.comparing(MesWorkOrder::getStartTime)).collect(Collectors.toList()).subList(0,qty));
case 4://随机 todo 规则应该是每生产qtyRule件此产品触发一次检测任务任务中待检测的数量为1
if(mesWorkOrders.size()/qtyRule>0){
mesWorkOrderToTask.add(mesWorkOrders.stream().sorted(Comparator.comparing(MesWorkOrder::getStartTime).reversed()).collect(Collectors.toList()).iterator().next());
}
break;
default:
break;
@ -117,6 +123,7 @@ public class MesCcscTaskServiceImpl extends BaseMesService<MesCcscTask> implemen
DdlPreparedPack.getStringEqualPack(mesWorkOrder.getWorkOrderNo(), "workOrderNo", ddlPackBean);
DdlPreparedPack.getStringEqualPack(mesWorkOrder.getPartNo(), "partNo", ddlPackBean);
List<MesCcscTask> mesCcscTaskList = baseRDao.findByHqlWhere(ddlPackBean);
LOGGER.info("-------- doCcscTaskByMesWorkOrder--120-mesCcscTaskList{}",mesCcscTaskList);
if (CollectionUtils.isEmpty(mesCcscTaskList)) {
//全部新增task表
for (MesWorkOrder workOrder : mesWorkOrderToTask) {
@ -133,16 +140,18 @@ public class MesCcscTaskServiceImpl extends BaseMesService<MesCcscTask> implemen
.build();
}
LOGGER.info("-------- doCcscTaskByMesWorkOrder--129-insert");
insert(workOrder, orderNo, frequency, rule,qtyRule);
insert(workOrder,testType, orderNo, frequency, rule,ccscRuleQty);
}
}
LOGGER.info("-------- doCcscTaskByMesWorkOrder--133-ccscRuleRDao.save");
//按照班次更新下次执行时间
ccscRule.setNextExeTime(CronUtil.getRecentTriggerTime(ccscRule.getCron()));
//设置末次执行时间
ccscRule.setLastExeTime(nowTime);
ConvertBean.serviceModelUpdate(ccscRule, mesWorkOrder.getModifyUser());
ccscRuleRDao.save(ccscRule);
if(!CollectionUtils.isEmpty(mesWorkOrderToTask)){
LOGGER.info("-------- doCcscTaskByMesWorkOrder--133-ccscRuleRDao.save");
//按照班次更新下次执行时间
ccscRule.setNextExeTime(CronUtil.getRecentTriggerTime(ccscRule.getCron()));
//设置末次执行时间
ccscRule.setLastExeTime(nowTime);
ConvertBean.serviceModelUpdate(ccscRule, mesWorkOrder.getModifyUser());
ccscRuleRDao.save(ccscRule);
}
}
}
}

@ -0,0 +1,75 @@
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base;
import cn.estsh.i3plus.ext.mes.api.base.IMesQmsScrapService;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
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.repository.MesPartInspectionDetailRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Description :MES_QMS
* @Reference :
* @Author : gsz
* @CreateDate 2024/7/3 10:28
* @Modify:
**/
@Service
@Slf4j
public class MesQmsScrapService extends BaseMesService<MesQmsScrap> implements IMesQmsScrapService {
@Autowired
private MesPartInspectionDetailRepository partInspectionDetailRDao;
@Override
protected void setPackQueryBean(MesQmsScrap bean, DdlPackBean packBean) {
DdlPreparedPack.getStringLikerPack(bean.getPartNo(), "partNo", packBean);
}
@Override
public void doQmsScrapByPartInspection(List<MesPartInspection> mesPartInspectionList, String organizeCode) {
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));
Map<String, List<MesPartInspection>> workOrderPartMap = mesPartInspectionList.stream().collect(Collectors.groupingBy(MesPartInspection::getPartNo));
//根据物料对可疑品分组
for (Map.Entry<String, List<MesPartInspection>> stringListEntry : workOrderPartMap.entrySet()) {
String key = stringListEntry.getKey();
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((int) sum);
mesQmsScrap.setPartNo(key);
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");
baseRDao.insert(mesQmsScrap);
}
}
}

@ -0,0 +1,135 @@
package cn.estsh.i3plus.ext.mes.apiservice.serviceimpl.base;
import cn.estsh.i3plus.ext.mes.api.base.IMesQmsSuspiciousService;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.base.util.StringUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesQmsSuspicious;
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.rework.MesReworkTask;
import cn.estsh.i3plus.pojo.mes.repository.MesPartInspectionDetailRepository;
import cn.estsh.i3plus.pojo.mes.repository.MesReworkTaskRepository;
import cn.estsh.i3plus.pojo.mes.util.MesExtEnumUtil;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @Description :MES
* @Reference :
* @Author : gsz
* @CreateDate 2024/7/3 10:28
* @Modify:
**/
@Service
@Slf4j
public class MesQmsSuspiciousService extends BaseMesService<MesQmsSuspicious> implements IMesQmsSuspiciousService {
@Autowired
private MesPartInspectionDetailRepository partInspectionDetailRDao;
@Autowired
private MesReworkTaskRepository mesReworkTaskRepository;
@Override
protected void setPackQueryBean(MesQmsSuspicious bean, DdlPackBean packBean) {
DdlPreparedPack.getStringLikerPack(bean.getPartNo(), "partNo", packBean);
}
@Override
public void doQmsSuspiciousByPartInspection(List<MesPartInspection> mesPartInspectionList, String organizeCode) {
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));
Map<String, List<MesPartInspection>> workOrderPartMap = mesPartInspectionList.stream().collect(Collectors.groupingBy(MesPartInspection::getPartNo));
//根据物料对可疑品分组
for (Map.Entry<String, List<MesPartInspection>> stringListEntry : workOrderPartMap.entrySet()) {
String key = stringListEntry.getKey();
List<MesPartInspection> mesPartInspections = stringListEntry.getValue();
MesPartInspection next = mesPartInspections.iterator().next();
//新增一条数据到报废表中
MesQmsSuspicious mesQmsSuspicious = new MesQmsSuspicious();
mesQmsSuspicious.setOrganizeCode(organizeCode);
mesQmsSuspicious.setInspectionDate(next.getInspectionDate());
//检验数量是全部数量汇总
double sumQty = mesPartInspections.stream().mapToDouble(MesPartInspection::getQty).sum();
mesQmsSuspicious.setInspectionQty((int) sumQty);
//一次合格数 nc_status=10 inspection_status=10
double qualifiedQty = mesPartInspections.stream().filter(m -> m.getNcStatus() == 10 && m.getInspectionStatus() == 10).mapToDouble(MesPartInspection::getQty).sum();
mesQmsSuspicious.setQualifiedQty((int) qualifiedQty);
//不合格数 nc_status=10 inspection_status=20
double unqualifiedQty = mesPartInspections.stream().filter(m -> m.getNcStatus() == 10 && m.getInspectionStatus() == 20).mapToDouble(MesPartInspection::getQty).sum();
mesQmsSuspicious.setUnqualifiedQty((int) unqualifiedQty);
//误判数量 nc_status=30 inspection_status=20
double misjudgmentQty = mesPartInspections.stream().filter(m -> m.getNcStatus() == 30).mapToDouble(MesPartInspection::getQty).sum();
mesQmsSuspicious.setMisjudgmentQty((int) misjudgmentQty);
//一次报废数 nc_status=40 inspection_status=20
double scrappedQty = mesPartInspections.stream().filter(m -> m.getNcStatus() == 40 && m.getInspectionStatus() == 20).mapToDouble(MesPartInspection::getQty).sum();
mesQmsSuspicious.setScrappedQty((int) scrappedQty);
//返工合格数 nc_status=50 返工单 status=20
Integer reworkQualified = 0;
//返工pending创建返工单未处理
Integer reworkPending = 0;
//返工数
Integer reworkQty = 0;
List<MesPartInspectionDetail> mesPartInspectionDetails = new ArrayList<>();
for (MesPartInspection mesPartInspection : mesPartInspections) {
if(!StringUtil.isEmpty(idDetailListMap.get(mesPartInspection.getId()))){
mesPartInspectionDetails.addAll(idDetailListMap.get(mesPartInspection.getId()));
}
//计算返工数量
if (mesPartInspection.getNcStatus() == MesExtEnumUtil.PART_INSPECTION_NC_STATUS.REWORK.getValue()) {
MesReworkTask reworkTask = mesReworkTaskRepository.getById(mesPartInspection.getReworkTaskId());
if (!StringUtil.isEmpty(reworkTask)) {
//返工是否完成
if (reworkTask.getStatus() == MesExtEnumUtil.REWORK_TASK_STATUS.FINISH.getValue()) {
reworkQualified += mesPartInspection.getQty();
} else {
reworkPending += mesPartInspection.getQty();
}
} else {
reworkPending += mesPartInspection.getQty();
}
reworkQty+= mesPartInspection.getQty();
}
}
mesQmsSuspicious.setReworkQty(reworkQty);
mesQmsSuspicious.setReworkQualified(reworkQualified);
mesQmsSuspicious.setReworkPending(reworkPending);
mesQmsSuspicious.setNcPending(0);
mesQmsSuspicious.setReworkScrapped(0);
mesQmsSuspicious.setPartNo(key);
mesQmsSuspicious.setPartName(next.getPartName());
//缺陷分类缺陷数量JOSN格式:
//[{"Defect_Name":"缺陷01","Defect_Qty":1},{"Defect_Name":"缺陷02","Defect_Qty":2}]
Map<String, List<MesPartInspectionDetail>> listDefectMap = mesPartInspectionDetails.stream().collect(Collectors.groupingBy(MesPartInspectionDetail::getDefectTypeName));
List<Map<String, Object>> defectsList = new ArrayList<>();
for (Map.Entry<String, List<MesPartInspectionDetail>> listEntry : listDefectMap.entrySet()) {
Map<String, Object> defectMap = new HashMap<>();
defectMap.put("Defect_Name",listEntry.getKey());
defectMap.put("Defect_Qty",listEntry.getValue().size());
defectsList.add(defectMap);
}
//缺陷分布json
mesQmsSuspicious.setDefects(JSON.toJSONString(defectsList));
ConvertBean.serviceModelInitialize(mesQmsSuspicious, "MesSuspiciousJob");
baseRDao.insert(mesQmsSuspicious);
}
}
}
Loading…
Cancel
Save