¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.jeecg.modules.board.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.system.vo.DictModel; |
| | | import org.jeecg.modules.board.mapper.DtBoardMapper; |
| | | import org.jeecg.modules.board.service.IDtBoardService; |
| | | import org.jeecg.modules.board.vo.*; |
| | | import org.jeecg.modules.mdc.entity.*; |
| | | import org.jeecg.modules.mdc.service.*; |
| | | import org.jeecg.modules.mdc.util.DateUtils; |
| | | import org.jeecg.modules.system.entity.MdcProduction; |
| | | import org.jeecg.modules.system.service.IMdcProductionService; |
| | | import org.jeecg.modules.system.service.ISysDictService; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @Author: Lius |
| | | * @CreateTime: 2025-05-30 |
| | | * @Description: |
| | | */ |
| | | @Service |
| | | public class DtBoardServiceImpl implements IDtBoardService { |
| | | |
| | | @Resource |
| | | private IMdcProductionService mdcProductionService; |
| | | |
| | | @Resource |
| | | private IMdcEquipmentService mdcEquipmentService; |
| | | |
| | | @Resource |
| | | private IMdcEquipmentStatisticalInfoService mdcEquipmentStatisticalInfoService; |
| | | |
| | | @Resource |
| | | private IMdcOeeInfoService mdcOeeInfoService; |
| | | |
| | | @Resource |
| | | private IEquipmentService equipmentService; |
| | | |
| | | @Resource |
| | | private IEquipmentWorkLineService equipmentWorkLineService; |
| | | |
| | | @Resource |
| | | private IMdcDriveTypeParamConfigService mdcDriveTypeParamConfigService; |
| | | |
| | | @Resource |
| | | private ISysDictService sysDictService; |
| | | |
| | | @Resource |
| | | private IMdcDowntimeService mdcDowntimeService; |
| | | |
| | | @Resource |
| | | private IEquipmentAlarmService equipmentAlarmService; |
| | | |
| | | @Resource |
| | | private IMdcAlarmInfoService mdcAlarmInfoService; |
| | | |
| | | @Resource |
| | | private DtBoardMapper dtBoardMapper; |
| | | |
| | | @Resource |
| | | private IAndonOrderService andonOrderService; |
| | | |
| | | /** |
| | | * 车é´ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public List<MdcProduction> productionList() { |
| | | return mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getOrgType, CommonConstant.ORG_TYPE_2).eq(MdcProduction::getDelFlag, CommonConstant.DEL_FLAG_0).orderByAsc(MdcProduction::getProductionOrder)); |
| | | } |
| | | |
| | | /** |
| | | * è®¾å¤æåº¦å©ç¨ç |
| | | */ |
| | | @Override |
| | | public List<EquUtilRateMonth> equipmentMonthUtilizationRate(String productionId) { |
| | | // ç»è£
è¿åæ°æ® |
| | | LocalDate now = LocalDate.now(); |
| | | Date start = DateUtils.toDate(now.plusMonths(-12).toString(), DateUtils.STR_DATE); |
| | | Date end = DateUtils.toDate(now.plusMonths(-1).toString(), DateUtils.STR_DATE); |
| | | List<String> monthBetween = DateUtils.getMonthBetween(start, end); |
| | | Map<String, EquUtilRateMonth> resultMap = monthBetween.stream().collect(Collectors.toMap( |
| | | date -> date, |
| | | date -> new EquUtilRateMonth(date.substring(date.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "æ"), |
| | | (existing, replacement) -> existing, // å¤çé®å²çªçå并彿°ï¼é常ä¸ä¼å²çªï¼ |
| | | LinkedHashMap::new // æå®ä½¿ç¨LinkedHashMapä¿ææå
¥é¡ºåº |
| | | )); |
| | | List<String> proIds = mdcProductionService.findChildByProId(productionId); |
| | | if (proIds == null || proIds.isEmpty()) { |
| | | return new ArrayList<>(resultMap.values()); |
| | | } |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | return new ArrayList<>(resultMap.values()); |
| | | } |
| | | for (String month : monthBetween) { |
| | | MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoService.findByEquIdsAndMonth(equipmentIdList, month.replaceAll("-", "")); |
| | | if (mdcEquipmentStatisticalInfo != null) { |
| | | if (resultMap.containsKey(month)) { |
| | | EquUtilRateMonth equUtilRateMonth = resultMap.get(month); |
| | | if (mdcEquipmentStatisticalInfo.getProcessLong().compareTo(BigDecimal.ZERO) > 0) { |
| | | equUtilRateMonth.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP)); |
| | | } |
| | | resultMap.put(month, equUtilRateMonth); |
| | | } |
| | | } |
| | | } |
| | | return new ArrayList<>(resultMap.values()); |
| | | } |
| | | |
| | | /** |
| | | * 设å¤å©ç¨ç(æ¨å¤©) |
| | | */ |
| | | @Override |
| | | public List<EquUtilRate> equipmentUtilizationRate(String productionId) { |
| | | List<String> proIds = mdcProductionService.findChildByProId(productionId); |
| | | if (proIds == null || proIds.isEmpty()) { |
| | | return null; |
| | | } |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | return null; |
| | | } |
| | | Map<String, EquUtilRate> resultMap = new LinkedHashMap<>(); |
| | | equipmentIdList.forEach(equipmentId -> { |
| | | EquUtilRate equUtilRate = new EquUtilRate(equipmentId); |
| | | resultMap.put(equipmentId, equUtilRate); |
| | | }); |
| | | String yesterday = LocalDate.now().plusDays(-1).toString(); |
| | | List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfoList = mdcEquipmentStatisticalInfoService.findByEquipmentAndDate(equipmentIdList, yesterday.replaceAll("-", "")); |
| | | if (mdcEquipmentStatisticalInfoList != null && !mdcEquipmentStatisticalInfoList.isEmpty()) { |
| | | mdcEquipmentStatisticalInfoList.forEach(mdcEquipmentStatisticalInfo -> { |
| | | if (resultMap.containsKey(mdcEquipmentStatisticalInfo.getEquipmentId())) { |
| | | EquUtilRate equUtilRate = resultMap.get(mdcEquipmentStatisticalInfo.getEquipmentId()); |
| | | if (mdcEquipmentStatisticalInfo.getProcessLong().compareTo(BigDecimal.ZERO) > 0) { |
| | | equUtilRate.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 2, RoundingMode.HALF_UP)); |
| | | } |
| | | resultMap.put(mdcEquipmentStatisticalInfo.getEquipmentId(), equUtilRate); |
| | | } |
| | | }); |
| | | } |
| | | return new ArrayList<>(resultMap.values()); |
| | | } |
| | | |
| | | /** |
| | | * æåº¦è®¾å¤ç»¼åæç |
| | | */ |
| | | @Override |
| | | public List<EquOeeMonth> equipmentMonthOee(String productionId) { |
| | | LocalDate now = LocalDate.now(); |
| | | Date start = DateUtils.toDate(now.plusMonths(-12).toString(), DateUtils.STR_DATE); |
| | | Date end = DateUtils.toDate(now.plusMonths(-1).toString(), DateUtils.STR_DATE); |
| | | List<String> monthBetween = DateUtils.getMonthBetween(start, end); |
| | | Map<String, EquOeeMonth> resultMap = monthBetween.stream().collect(Collectors.toMap( |
| | | date -> date, |
| | | date -> new EquOeeMonth(date.substring(date.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "æ"), |
| | | (existing, replacement) -> existing, // å¤çé®å²çªçå并彿°ï¼é常ä¸ä¼å²çªï¼ |
| | | LinkedHashMap::new // æå®ä½¿ç¨LinkedHashMapä¿ææå
¥é¡ºåº |
| | | )); |
| | | List<String> proIds = mdcProductionService.findChildByProId(productionId); |
| | | if (proIds == null || proIds.isEmpty()) { |
| | | return new ArrayList<>(resultMap.values()); |
| | | } |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | return new ArrayList<>(resultMap.values()); |
| | | } |
| | | for (String month : monthBetween) { |
| | | BigDecimal oee = mdcOeeInfoService.findByEquIdAndMonth(equipmentIdList, month); |
| | | if (oee != null) { |
| | | EquOeeMonth equOeeMonth = resultMap.get(month); |
| | | equOeeMonth.setOee(oee.setScale(2, RoundingMode.HALF_UP)); |
| | | resultMap.put(month, equOeeMonth); |
| | | } |
| | | } |
| | | return new ArrayList<>(resultMap.values()); |
| | | } |
| | | |
| | | /** |
| | | * 设å¤ç¶æç»è®¡ |
| | | */ |
| | | @Override |
| | | public EquOperation equipmentOperationStatistics(String productionId) { |
| | | EquOperation equOperation = new EquOperation(); |
| | | List<String> proIds = mdcProductionService.findChildByProId(productionId); |
| | | if (proIds == null || proIds.isEmpty()) { |
| | | return equOperation; |
| | | } |
| | | List<Equipment> equipmentList = equipmentService.listByProds(proIds); |
| | | if (equipmentList == null || equipmentList.isEmpty()) { |
| | | return equOperation; |
| | | } |
| | | for (Equipment equipment : equipmentList) { |
| | | if (equipment.getOporation() != null) { |
| | | switch (equipment.getOporation()) { |
| | | case 1: |
| | | case 2: |
| | | equOperation.setStandby(equOperation.getStandby() + 1); |
| | | break; |
| | | case 3: |
| | | equOperation.setRun(equOperation.getRun() + 1); |
| | | break; |
| | | case 22: |
| | | equOperation.setAlarm(equOperation.getAlarm() + 1); |
| | | break; |
| | | default: |
| | | equOperation.setShutdown(equOperation.getShutdown() + 1); |
| | | break; |
| | | } |
| | | } else { |
| | | equOperation.setShutdown(equOperation.getShutdown() + 1); |
| | | } |
| | | } |
| | | return equOperation; |
| | | } |
| | | |
| | | /** |
| | | * 设å¤è¿è¡ä¿¡æ¯ |
| | | */ |
| | | @Override |
| | | public List<EquRunInfo> equipmentRunInfo(String equipmentId) { |
| | | List<EquRunInfo> equRunInfoList = new ArrayList<>(); |
| | | Equipment equipment = equipmentService.findByEquId(equipmentId); |
| | | if (equipment != null) { |
| | | //å¡«å
设å¤åºç¡ä¿¡æ¯ |
| | | equRunInfoList.add(new EquRunInfo("设å¤åç§°", equipment.getEquipmentname(), "")); |
| | | equRunInfoList.add(new EquRunInfo("设å¤ç¼å·", equipment.getEquipmentid(), "")); |
| | | if (equipment.getOporation() != null && equipment.getOporation() != 0) { |
| | | String saveTableName = equipment.getSavetablename(); |
| | | Map<String, Object> mapData = equipmentWorkLineService.getDataList(saveTableName); |
| | | if (mapData != null) { |
| | | //è·å MDC 驱å¨å¯¹åºçå±ç¤ºåæ° å¹¶æ ¹æ®key æ¼è£
ä» workData æ¥è¯¢çæ°æ® |
| | | List<MdcDriveTypeParamConfig> mdcDriveTypeParamList = mdcDriveTypeParamConfigService.getShowDriveParam(equipment.getDrivetype()); |
| | | if (mdcDriveTypeParamList != null && !mdcDriveTypeParamList.isEmpty()) { |
| | | List<DictModel> dictItems = sysDictService.getDictItems(CommonConstant.DICT_EQUIPMENT_RUN_UNIT); |
| | | Map<String, DictModel> resultMap = new HashMap<>(); |
| | | dictItems.forEach(dictModel -> { |
| | | resultMap.put(dictModel.getText(), dictModel); |
| | | }); |
| | | for (MdcDriveTypeParamConfig mdcDriveTypeParamConfig : mdcDriveTypeParamList) { |
| | | EquRunInfo equRunInfo = new EquRunInfo(); |
| | | String englishName = mdcDriveTypeParamConfig.getEnglishName(); |
| | | String chineseName = mdcDriveTypeParamConfig.getChineseName(); |
| | | equRunInfo.setKey(chineseName); |
| | | if (mapData.containsKey(englishName)) { |
| | | Object object = mapData.get(englishName); |
| | | String value = ""; |
| | | if ("CollectTime".equals(englishName)) { |
| | | Date date = object == null ? null : (Date) object; |
| | | value = DateUtils.format(date, DateUtils.STR_DATE_TIME_SMALL); |
| | | } else if ("ZUOLAN".equals(equipment.getDrivetype()) && "spindlespeed".equals(englishName) && equipment.getOporation() == 3) { |
| | | // ZUOLAN设å¤ä¸»è½´è½¬éåæ®µspindlespeed |
| | | value = String.valueOf(((new Random().nextInt(35)) + 1) * 100); |
| | | } else if ("ZUOLAN".equals(equipment.getDrivetype()) && "spindleload".equals(englishName) && equipment.getOporation() == 3) { |
| | | // ZUOLAN设å¤ä¸»è½´è´è·å段spindleload |
| | | value = String.valueOf(Integer.valueOf(new Random().nextInt(21))); |
| | | } else if ("ZUOLAN".equals(equipment.getDrivetype()) && "spindlebeilv".equals(englishName) && equipment.getOporation() == 3) { |
| | | // ZUOLAN设å¤ä¸»è½´åçåæ®µspindlebeilv |
| | | value = String.valueOf((new Random().nextInt(13)) * 10); |
| | | } else if ("ZUOLAN".equals(equipment.getDrivetype()) && "feedbeilv".equals(englishName) && equipment.getOporation() == 3) { |
| | | // ZUOLAN设å¤è¿ç»åçåæ®µfeedbeilv |
| | | value = String.valueOf((new Random().nextInt(13)) * 10); |
| | | } else { |
| | | value = object == null ? "" : object.toString(); |
| | | } |
| | | equRunInfo.setValue(value); |
| | | // 设置åä½ |
| | | if (resultMap.containsKey(chineseName)) { |
| | | DictModel dictModel = resultMap.get(chineseName); |
| | | equRunInfo.setUnit(dictModel.getValue()); |
| | | } |
| | | equRunInfoList.add(equRunInfo); |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | return equRunInfoList; |
| | | } |
| | | |
| | | /** |
| | | * 设å¤åæºç»è®¡ |
| | | */ |
| | | @Override |
| | | public List<EquDowntimeInfo> equDowntimeStatistics(String productionId) { |
| | | List<String> proIds = mdcProductionService.findChildByProId(productionId); |
| | | if (proIds == null || proIds.isEmpty()) { |
| | | return null; |
| | | } |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | return null; |
| | | } |
| | | LocalDate end = LocalDate.now(); |
| | | LocalDate start = end.plusDays(-30); |
| | | List<EquDowntimeInfo> result = mdcDowntimeService.equDowntimeStatistics(equipmentIdList, start.toString(), end.toString()); |
| | | result.forEach(equDowntimeInfo -> { |
| | | equDowntimeInfo.setDuration(equDowntimeInfo.getDuration().setScale(2, RoundingMode.HALF_UP)); |
| | | }); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * è®¾å¤æ¥è¦å表 |
| | | */ |
| | | @Override |
| | | public List<EquAlarm> equAlarmList(String productionId) { |
| | | List<EquAlarm> result = new ArrayList<>(); |
| | | List<String> proIds = mdcProductionService.findChildByProId(productionId); |
| | | if (proIds == null || proIds.isEmpty()) { |
| | | return null; |
| | | } |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | return null; |
| | | } |
| | | List<EquipmentAlarm> equipmentAlarmList = equipmentAlarmService.equAlarmList(equipmentIdList); |
| | | if (equipmentAlarmList == null || equipmentAlarmList.isEmpty()) { |
| | | return null; |
| | | } |
| | | for (EquipmentAlarm equipmentAlarm : equipmentAlarmList) { |
| | | MdcAlarmInfo mdcAlarmInfo = mdcAlarmInfoService.findAlarmContent(equipmentAlarm.getAlarmNo(), equipmentAlarm.getEquipmentid()); |
| | | EquAlarm equAlarm = new EquAlarm(); |
| | | equAlarm.setEquipmentId(equipmentAlarm.getEquipmentid()); |
| | | if (mdcAlarmInfo != null) { |
| | | equAlarm.setAlarmInfo(mdcAlarmInfo.getAlarmContent()); |
| | | } else { |
| | | equAlarm.setAlarmInfo(equipmentAlarm.getAlarmContent()); |
| | | } |
| | | result.add(equAlarm); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * è®¾å¤æ
é |
| | | */ |
| | | @Override |
| | | public List<EquRepair> equRepairList(String productionId) { |
| | | List<String> proIds = mdcProductionService.findChildByProId(productionId); |
| | | if (proIds == null || proIds.isEmpty()) { |
| | | return null; |
| | | } |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | return null; |
| | | } |
| | | LocalDateTime currentDate = LocalDate.now().minusMonths(1).atStartOfDay(); |
| | | String format = currentDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | List<EquRepair> result = dtBoardMapper.equRepairList(equipmentIdList, format); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 设å¤å®ç¯é®é¢ |
| | | */ |
| | | @Override |
| | | public List<EquAndon> equAndonList(String productionId) { |
| | | List<String> proIds = mdcProductionService.findChildByProId(productionId); |
| | | if (proIds == null || proIds.isEmpty()) { |
| | | return null; |
| | | } |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquIdsByProIds(proIds); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | return null; |
| | | } |
| | | List<EquAndon> result = andonOrderService.equAndonList(equipmentIdList); |
| | | return result; |
| | | } |
| | | |
| | | } |