package org.jeecg.modules.mdc.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.sun.org.apache.bcel.internal.generic.NEW; import org.jeecg.common.api.CommonAPI; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.util.TranslateDictTextUtils; import org.jeecg.modules.eam.constant.EquipmentMaintenanceStatus; import org.jeecg.modules.eam.constant.EquipmentOperationTagEnum; import org.jeecg.modules.eam.constant.EquipmentRepairStatus; import org.jeecg.modules.eam.constant.MaintenanceCategoryEnum; import org.jeecg.modules.mdc.constant.MdcConstant; import org.jeecg.modules.mdc.dto.EamEquipmentExtendDto; import org.jeecg.modules.mdc.entity.*; import org.jeecg.modules.mdc.mapper.MdcBoardMapper; import org.jeecg.modules.mdc.service.*; import org.jeecg.modules.mdc.util.DateUtils; import org.jeecg.modules.mdc.vo.MdcBoardEquRealTImeVo; import org.jeecg.modules.mdc.vo.MdcBoardRateVo; import org.jeecg.modules.mdc.vo.MdcEquipmentStatusVo; import org.jeecg.modules.mdcJc.service.IMdcJcRcJobreportService; import org.jeecg.modules.system.entity.MdcProduction; import org.jeecg.modules.system.service.IMdcProductionService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.util.*; import java.util.stream.Collectors; /** * @Author: Lius * @CreateTime: 2025-05-06 * @Description: 看板接口 */ @Service public class MdcBoardServiceImpl implements IMdcBoardService { @Resource private IMdcProductionService mdcProductionService; @Resource private IEquipmentService equipmentService; @Resource private IMdcEquipmentService mdcEquipmentService; @Resource private IMdcEquipmentStatisticalInfoService mdcEquipmentStatisticalInfoService; @Resource private IMdcOeeInfoService mdcOeeInfoService; @Resource private IMdcJcRcJobreportService mdcJcRcJobreportService; @Resource private CommonAPI commonAPI; @Resource private IEquipmentLogService equipmentLogService; @Resource private IEquipmentWorkLineService equipmentWorkLineService; @Resource private MdcBoardMapper mdcBoardMapper; /** * 设备状态 */ @Override public Map equipmentStatusStatistics(String productionId) { Map result = new HashMap<>(); if (StringUtils.isBlank(productionId)) { MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper().eq(MdcProduction::getParentId, "")); productionId = mdcProduction.getId(); } List proIds = mdcProductionService.findChildByProId(productionId); if (proIds == null || proIds.isEmpty()) { return result; } List equipmentList = equipmentService.listByProds(proIds); if (equipmentList == null || equipmentList.isEmpty()) { return result; } MdcEquipmentStatusVo mdcEquipmentStatusVo = new MdcEquipmentStatusVo(); for (Equipment equipment : equipmentList) { if (equipment.getOporation() != null) { switch (equipment.getOporation()) { case 1: case 2: mdcEquipmentStatusVo.setWaitCount(mdcEquipmentStatusVo.getWaitCount() + 1); break; case 3: mdcEquipmentStatusVo.setRunCount(mdcEquipmentStatusVo.getRunCount() + 1); break; case 22: mdcEquipmentStatusVo.setAlarmCount(mdcEquipmentStatusVo.getAlarmCount() + 1); break; default: mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1); break; } } else { mdcEquipmentStatusVo.setCloseCount(mdcEquipmentStatusVo.getCloseCount() + 1); } } result.put("equipmentStatus", mdcEquipmentStatusVo); return result; } /** * 获取产线列表 */ @Override public List proList(String productionId) { if (StringUtils.isBlank(productionId)) { MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper().eq(MdcProduction::getParentId, "")); productionId = mdcProduction.getId(); } return mdcProductionService.list(new LambdaQueryWrapper().eq(MdcProduction::getParentId, productionId).eq(MdcProduction::getMdcFlag, "1").eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0).orderByAsc(MdcProduction::getProductionOrder)); } /** * 率分析走势 */ @Override public Map rateAnalysisTrend(String productionId) { Map result = new HashMap<>(); if (StringUtils.isBlank(productionId)) { MdcProduction mdcProduction = mdcProductionService.getOne(new LambdaQueryWrapper().eq(MdcProduction::getParentId, "")); productionId = mdcProduction.getId(); } List proIds = mdcProductionService.findChildByProId(productionId); if (proIds == null || proIds.isEmpty()) { return result; } List equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds); if (equipmentIdList == null || equipmentIdList.isEmpty()) { return result; } LocalDate now = LocalDate.now(); Date startDate = DateUtils.toDate(now.plusDays(-15).toString(), DateUtils.STR_DATE); Date endDate = DateUtils.toDate(now.plusDays(-1).toString(), DateUtils.STR_DATE); String start = DateUtils.format(startDate, DateUtils.STR_DATE); String end = DateUtils.format(endDate, DateUtils.STR_DATE); List dateList = DateUtils.getDatesStringList(startDate, endDate); List dates = dateList.stream().map(date -> date.substring(5, 10)).collect(Collectors.toList()); result.put("dateList", dates); Map statisticsMap = new LinkedHashMap<>(); dateList.forEach(date -> { statisticsMap.put(date, new MdcBoardRateVo(date.substring(5, 10))); }); // TEEP 开机率 开动率 List mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquipmentAndDate(equipmentIdList, start.replaceAll("-", ""), end.replaceAll("-", "")); if (mdcEquipmentStatisticalInfo != null && !mdcEquipmentStatisticalInfo.isEmpty()) { mdcEquipmentStatisticalInfo.forEach(equipmentStatisticalInfo -> { String date = DateUtils.format(DateUtils.toDate(equipmentStatisticalInfo.getTheDate(), DateUtils.STRDATE), DateUtils.STR_DATE); if (statisticsMap.containsKey(date)) { MdcBoardRateVo mdcBoardRateVo = statisticsMap.get(date); if (equipmentStatisticalInfo.getProcessLong().compareTo(BigDecimal.ZERO) > 0) { mdcBoardRateVo.setUtilizationRate(equipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP)); } if (equipmentStatisticalInfo.getOpenLong().compareTo(BigDecimal.ZERO) > 0) { mdcBoardRateVo.setOpenRate(equipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP)); } if (equipmentStatisticalInfo.getOpenLong().compareTo(BigDecimal.ZERO) > 0) { mdcBoardRateVo.setStartRate(equipmentStatisticalInfo.getProcessLong().multiply(new BigDecimal("100").divide(equipmentStatisticalInfo.getOpenLong(), 2, RoundingMode.HALF_UP))); } statisticsMap.put(date, mdcBoardRateVo); } }); } // OEE List oeeInfo = mdcOeeInfoService.findByEquIdsAndDate(equipmentIdList, start, end); if (oeeInfo != null && !oeeInfo.isEmpty()) { oeeInfo.forEach(mdcOeeInfo -> { if (statisticsMap.containsKey(mdcOeeInfo.getTheDate())) { MdcBoardRateVo mdcBoardRateVo = statisticsMap.get(mdcOeeInfo.getTheDate()); if (mdcOeeInfo.getOee().compareTo(BigDecimal.ZERO) > 0) { mdcBoardRateVo.setOee(mdcOeeInfo.getOee().setScale(2, RoundingMode.HALF_UP)); } statisticsMap.put(mdcOeeInfo.getTheDate(), mdcBoardRateVo); } }); } List dataList = new ArrayList<>(statisticsMap.values()); result.put("dataList", dataList); return result; } /** * 设备列表 */ @Override public List equipmentList(String productionId) { List proIds = mdcProductionService.findChildByProId(productionId); if (proIds == null || proIds.isEmpty()) { return null; } return mdcEquipmentService.findByProIds(proIds); } /** * 设备日利用率分析 */ @Override public Map rateAnalysisTrendDay(String equipmentId) { Map result = new HashMap<>(); LocalDate now = LocalDate.now(); Date startDate = DateUtils.toDate(now.plusDays(-7).toString(), DateUtils.STR_DATE); Date endDate = DateUtils.toDate(now.plusDays(-1).toString(), DateUtils.STR_DATE); String start = DateUtils.format(startDate, DateUtils.STR_DATE); String end = DateUtils.format(endDate, DateUtils.STR_DATE); List dayBetween = DateUtils.getDatesStringList(startDate, endDate); List dateList = dayBetween.stream().map(date -> date.substring(5, 10)).collect(Collectors.toList()); result.put("dateList", dateList); Map statisticsMap = new LinkedHashMap<>(); dayBetween.forEach(date -> { statisticsMap.put(date, new MdcBoardRateVo(date.substring(5, 10))); }); // TEEP List mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquIdAndDate(equipmentId, start.replaceAll("-", ""), end.replaceAll("-", "")); if (mdcEquipmentStatisticalInfo != null && !mdcEquipmentStatisticalInfo.isEmpty()) { mdcEquipmentStatisticalInfo.forEach(equipmentStatisticalInfo -> { String date = DateUtils.format(DateUtils.toDate(equipmentStatisticalInfo.getTheDate(), DateUtils.STRDATE), DateUtils.STR_DATE); if (statisticsMap.containsKey(date)) { MdcBoardRateVo mdcBoardRateVo = statisticsMap.get(date); if (equipmentStatisticalInfo.getProcessLong().compareTo(BigDecimal.ZERO) > 0) { mdcBoardRateVo.setUtilizationRate(equipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP)); } statisticsMap.put(date, mdcBoardRateVo); } }); } // OEE List oeeInfo = mdcOeeInfoService.findByEquIdAndDate(equipmentId, start, end); if (oeeInfo != null && !oeeInfo.isEmpty()) { oeeInfo.forEach(mdcOeeInfo -> { if (statisticsMap.containsKey(mdcOeeInfo.getTheDate())) { MdcBoardRateVo mdcBoardRateVo = statisticsMap.get(mdcOeeInfo.getTheDate()); if (mdcOeeInfo.getOee().compareTo(BigDecimal.ZERO) > 0) { mdcBoardRateVo.setOee(mdcOeeInfo.getOee().setScale(2, RoundingMode.HALF_UP)); } statisticsMap.put(mdcOeeInfo.getTheDate(), mdcBoardRateVo); } }); } List dataList = new ArrayList<>(statisticsMap.values()); result.put("dataList", dataList); return result; } /** * 设备月率分析 */ @Override public Map rateAnalysisTrendMonth(String equipmentId) { Map result = new HashMap<>(); LocalDate now = LocalDate.now(); Date start = DateUtils.toDate(now.plusMonths(-6).toString(), DateUtils.STR_DATE); Date end = DateUtils.toDate(now.plusMonths(-1).toString(), DateUtils.STR_DATE); List monthBetween = DateUtils.getMonthBetween(start, end); List dateList = new ArrayList<>(); List dataList = new ArrayList<>(); for (String month : monthBetween) { String name = month.substring(month.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "月"; dateList.add(name); MdcBoardRateVo mdcBoardRateVo = new MdcBoardRateVo(); mdcBoardRateVo.setDate(name); // TEEP MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquIdAndMonth(equipmentId, month.replaceAll("-", "")); if (mdcEquipmentStatisticalInfo != null) { mdcBoardRateVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP)); } // OEE BigDecimal oee = mdcOeeInfoService.findByEquIdAndMonth(equipmentId, month); if (oee != null) { mdcBoardRateVo.setOee(oee.setScale(2, RoundingMode.HALF_UP)); } // 合格率 BigDecimal passRate = mdcJcRcJobreportService.findRateByMonth(equipmentId, month); if (passRate != null) { mdcBoardRateVo.setPassRate(passRate); } dataList.add(mdcBoardRateVo); } result.put("dateList", dateList); result.put("dataList", dataList); return result; } /** * 设备实时信息 */ @Override public MdcBoardEquRealTImeVo equipmentRealTimeDetail(String equipmentId) { MdcBoardEquRealTImeVo mdcBoardEquRealTImeVo = mdcEquipmentService.getByEquipmentId(equipmentId); if (mdcBoardEquRealTImeVo == null) { return new MdcBoardEquRealTImeVo(); } //设备管理员翻译 String realName = commonAPI.translateDictFromTable("sys_user", "realname", "username", mdcBoardEquRealTImeVo.getEquipmentManager()); mdcBoardEquRealTImeVo.setEquipmentManager(realName); mdcBoardEquRealTImeVo.setAlarm("无"); if (mdcBoardEquRealTImeVo.getOporation() != null) { switch (mdcBoardEquRealTImeVo.getOporation()) { case 1: case 2: mdcBoardEquRealTImeVo.setOporationDict("待机"); break; case 3: mdcBoardEquRealTImeVo.setOporationDict("运行"); break; case 22: mdcBoardEquRealTImeVo.setOporationDict("报警"); // 查询报警号 EquipmentLog equipmentLog = equipmentLogService.findAlarmByEquId(equipmentId); if (equipmentLog != null && StringUtils.isNotBlank(equipmentLog.getAlarm())) { mdcBoardEquRealTImeVo.setAlarm(equipmentLog.getAlarm()); } break; default: mdcBoardEquRealTImeVo.setOporationDict("关机"); break; } } else { mdcBoardEquRealTImeVo.setOporationDict("关机"); mdcBoardEquRealTImeVo.setOporation(0); } //设备运行数据 Map mapData = equipmentWorkLineService.getDataList(mdcBoardEquRealTImeVo.getSaveTableName()); if (mapData != null) { if (mapData.containsKey("Sequencenumber")) { Object object = mapData.get("Sequencenumber"); mdcBoardEquRealTImeVo.setSequenceNumber(object == null ? "" : object.toString()); } if (mapData.containsKey("spindlespeed")) { Object object = mapData.get("spindlespeed"); mdcBoardEquRealTImeVo.setSpindleSpeed(object == null ? "" : object.toString()); } if (mapData.containsKey("spindleload")) { Object object = mapData.get("spindleload"); mdcBoardEquRealTImeVo.setSpindleLoad(object == null ? "" : object.toString()); } if (mapData.containsKey("spindlebeilv")) { Object object = mapData.get("spindlebeilv"); mdcBoardEquRealTImeVo.setSpindlebeilv(object == null ? "" : object.toString()); } if (mapData.containsKey("feedbeilv")) { Object object = mapData.get("feedbeilv"); mdcBoardEquRealTImeVo.setFeedbeilv(object == null ? "" : object.toString()); } } // 维保状态 EamEquipmentExtendDto eamEquipmentExtendDto = mdcBoardMapper.findEquExtend(equipmentId); mdcBoardEquRealTImeVo.setMaintenanceStatus("正常"); mdcBoardEquRealTImeVo.setReportRepairStatus("无"); if (eamEquipmentExtendDto != null) { if (!EquipmentRepairStatus.NORMAL.name().equals(eamEquipmentExtendDto.getRepairStatus())) { mdcBoardEquRealTImeVo.setMaintenanceStatus("维修"); } else { if (EquipmentMaintenanceStatus.UNDER_INSPECTION.name().equals(eamEquipmentExtendDto.getMaintenanceStatus()) || EquipmentMaintenanceStatus.INSPECTION_CONFIRM.name().equals(eamEquipmentExtendDto.getMaintenanceStatus())) { mdcBoardEquRealTImeVo.setMaintenanceStatus("点检"); } else if (EquipmentMaintenanceStatus.UNDER_MAINTENANCE.name().equals(eamEquipmentExtendDto.getMaintenanceStatus()) || EquipmentMaintenanceStatus.WAIT_CONFIRM.name().equals(eamEquipmentExtendDto.getMaintenanceStatus())) { mdcBoardEquRealTImeVo.setMaintenanceStatus("周报"); } } } // 报修情况 String repairStatus = mdcBoardMapper.findReportRepairStatus(equipmentId); if (repairStatus != null) { String reportRepair = commonAPI.translateDict("report_repair_status", repairStatus); mdcBoardEquRealTImeVo.setReportRepairStatus(reportRepair); } else { mdcBoardEquRealTImeVo.setReportRepairStatus("无"); } // 下次点检下次保养 Date nextInspection = mdcBoardMapper.findInsOrMain(equipmentId, MaintenanceCategoryEnum.POINT_INSPECTION.name()); if (nextInspection != null) { mdcBoardEquRealTImeVo.setNextInspection(nextInspection); } Date nextMaintenance = mdcBoardMapper.findInsOrMain(equipmentId, MaintenanceCategoryEnum.WEEK_MAINTENANCE.name()); if (nextMaintenance != null) { mdcBoardEquRealTImeVo.setNextMaintenance(nextMaintenance); } return mdcBoardEquRealTImeVo; } }