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.constant.CommonConstant; import org.jeecg.modules.mdc.constant.MdcConstant; import org.jeecg.modules.mdc.entity.Equipment; import org.jeecg.modules.mdc.entity.MdcEquipment; import org.jeecg.modules.mdc.entity.MdcEquipmentStatisticalInfo; import org.jeecg.modules.mdc.entity.MdcOeeInfo; import org.jeecg.modules.mdc.service.*; import org.jeecg.modules.mdc.util.DateUtils; 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; /** * 设备状态 */ @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; } }