|
|
|
@ -10,10 +10,12 @@ 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.MesPartInspectionRepository;
|
|
|
|
|
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.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
@ -40,6 +42,9 @@ public class MesQmsSuspiciousService extends BaseMesService<MesQmsSuspicious> im
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesReworkTaskRepository mesReworkTaskRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private MesPartInspectionRepository partInspectionRepository;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void setPackQueryBean(MesQmsSuspicious bean, DdlPackBean packBean) {
|
|
|
|
|
DdlPreparedPack.getStringLikerPack(bean.getPartNo(), "partNo", packBean);
|
|
|
|
@ -58,78 +63,103 @@ public class MesQmsSuspiciousService extends BaseMesService<MesQmsSuspicious> im
|
|
|
|
|
//根据物料对可疑品分组
|
|
|
|
|
for (Map.Entry<String, List<MesPartInspection>> stringListEntry : workOrderPartMap.entrySet()) {
|
|
|
|
|
String key = stringListEntry.getKey();
|
|
|
|
|
List<MesPartInspection> mesPartInspections = stringListEntry.getValue();
|
|
|
|
|
MesPartInspection next = mesPartInspections.iterator().next();
|
|
|
|
|
List<MesPartInspection> mesPartInspectionsList = stringListEntry.getValue();
|
|
|
|
|
//修改时间的集合
|
|
|
|
|
List<MesPartInspection> mesPartInspectionsListTime = new ArrayList<>();
|
|
|
|
|
for (MesPartInspection partInspection : mesPartInspectionsList) {
|
|
|
|
|
MesPartInspection partInspectionNew = new MesPartInspection();
|
|
|
|
|
BeanUtils.copyProperties(partInspection, partInspectionNew);
|
|
|
|
|
//去创建日期换算整点2024-07-25 10:00:00
|
|
|
|
|
DdlPackBean packBeanNew = DdlPackBean.getDdlPackBean(organizeCode);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(partInspection.getPartNo(), "partNo", packBeanNew);
|
|
|
|
|
DdlPreparedPack.getStringEqualPack(partInspection.getSn(), "sn", packBeanNew);
|
|
|
|
|
packBeanNew.setOrderByStr(" order by createDatetime ");
|
|
|
|
|
MesPartInspection partInspectionDao = partInspectionRepository.getByProperty(packBeanNew);
|
|
|
|
|
String qmsTime = partInspection.getCreateDatetime().substring(0, 13) + ":00:00";
|
|
|
|
|
if (!StringUtil.isEmpty(partInspectionDao)) {
|
|
|
|
|
qmsTime = partInspectionDao.getCreateDatetime().substring(0, 13) + ":00:00";
|
|
|
|
|
}
|
|
|
|
|
partInspectionNew.setInspectionDate(qmsTime);
|
|
|
|
|
mesPartInspectionsListTime.add(partInspectionNew);
|
|
|
|
|
}
|
|
|
|
|
//根据时间分组发送
|
|
|
|
|
Map<String, List<MesPartInspection>> mesPartInspectionsMap = mesPartInspectionsListTime.stream().collect(Collectors.groupingBy(MesPartInspection::getInspectionDate));
|
|
|
|
|
for (Map.Entry<String, List<MesPartInspection>> partInspection : mesPartInspectionsMap.entrySet()) {
|
|
|
|
|
List<MesPartInspection> mesPartInspections = partInspection.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);
|
|
|
|
|
//新增一条数据到报废表中
|
|
|
|
|
MesQmsSuspicious mesQmsSuspicious = new MesQmsSuspicious();
|
|
|
|
|
mesQmsSuspicious.setOrganizeCode(organizeCode);
|
|
|
|
|
mesQmsSuspicious.setInspectionDate(next.getInspectionDate());
|
|
|
|
|
|
|
|
|
|
//返工合格数 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();
|
|
|
|
|
//检验数量是全部数量汇总
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
reworkPending += mesPartInspection.getQty();
|
|
|
|
|
reworkQty += 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);
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|