From 23855599412c4d61b38d78f0f3abd3430a48b5b1 Mon Sep 17 00:00:00 2001 From: zhangherong <571457620@qq.com> Date: 星期三, 25 六月 2025 11:51:38 +0800 Subject: [PATCH] Merge branch 'mdc_hyjs_master' --- lxzn-module-mdc/src/main/java/org/jeecg/modules/board/service/impl/DtBoardServiceImpl.java | 382 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 382 insertions(+), 0 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/board/service/impl/DtBoardServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/board/service/impl/DtBoardServiceImpl.java new file mode 100644 index 0000000..38d74e0 --- /dev/null +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/board/service/impl/DtBoardServiceImpl.java @@ -0,0 +1,382 @@ +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 椹卞姩瀵瑰簲鐨勫睍绀哄弬鏁� 骞舵牴鎹甼ey 鎷艰浠� 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璁惧涓昏酱杞�熷瓧娈祍pindlespeed + 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; + } + +} -- Gitblit v1.9.3