From 63d50da13d256f7df075f37054a239740bf172ac Mon Sep 17 00:00:00 2001 From: qushaowei <qushaowei@163.com> Date: 星期四, 14 三月 2024 16:01:05 +0800 Subject: [PATCH] Merge branch 'master' of http://117.34.109.166:18448/r/mdc_430 into develop --- lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/IMdcHomeServiceImpl.java | 231 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 231 insertions(+), 0 deletions(-) diff --git a/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/IMdcHomeServiceImpl.java b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/IMdcHomeServiceImpl.java new file mode 100644 index 0000000..df3abeb --- /dev/null +++ b/lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/IMdcHomeServiceImpl.java @@ -0,0 +1,231 @@ +package org.jeecg.modules.mdc.service.impl; + +import com.baomidou.mybatisplus.core.toolkit.StringUtils; +import org.jeecg.modules.mdc.entity.EquipmentLog; +import org.jeecg.modules.mdc.mapper.MdcHomeMapper; +import org.jeecg.modules.mdc.service.IEquipmentLogService; +import org.jeecg.modules.mdc.service.IMdcEquipmentService; +import org.jeecg.modules.mdc.service.IMdcHomeService; +import org.jeecg.modules.mdc.util.DateUtils; +import org.jeecg.modules.mdc.vo.MdcCommonVo; +import org.jeecg.modules.mdc.vo.MdcEquipmentStatusVo; +import org.jeecg.modules.system.entity.MdcProduction; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.util.*; + +/** + * @author Lius + * @date 2024/3/14 9:52 + */ +@Service +public class IMdcHomeServiceImpl implements IMdcHomeService { + + @Resource + private IMdcEquipmentService mdcEquipmentService; + + @Resource + private IEquipmentLogService equipmentLogService; + + @Resource + private MdcHomeMapper mdcHomeMapper; + + /** + * 璁惧杩愯鐘舵�佺粺璁� + */ + @Override + public List<MdcCommonVo> getEquipmentStatusStatistics(String userId, String key) { + List<MdcCommonVo> result = new ArrayList<>(); + MdcCommonVo mdcCommonVo1 = new MdcCommonVo(); + mdcCommonVo1.setName("鍏虫満"); + mdcCommonVo1.setValue("0"); + result.add(mdcCommonVo1); + MdcCommonVo mdcCommonVo2 = new MdcCommonVo(); + mdcCommonVo2.setName("鎶ヨ"); + mdcCommonVo2.setValue("0"); + result.add(mdcCommonVo2); + MdcCommonVo mdcCommonVo3 = new MdcCommonVo(); + mdcCommonVo3.setName("寰呮満"); + mdcCommonVo3.setValue("0"); + result.add(mdcCommonVo3); + MdcCommonVo mdcCommonVo4 = new MdcCommonVo(); + mdcCommonVo4.setName("杩愯"); + mdcCommonVo4.setValue("0"); + result.add(mdcCommonVo4); + MdcEquipmentStatusVo mdcEquipmentStatusVo = new MdcEquipmentStatusVo(); + if (StringUtils.isBlank(key)) { + return result; + } + List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key); + if (equipmentIdList == null || equipmentIdList.isEmpty()) { + return result; + } + List<EquipmentLog> logList = equipmentLogService.getEquipmentStatusList(equipmentIdList); + if (logList != null && !logList.isEmpty()) { + for (EquipmentLog equipmentLog : logList) { + if (equipmentLog.getOporation() != null) { + switch (equipmentLog.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.clear(); + MdcCommonVo mdcCommonVo5 = new MdcCommonVo(); + mdcCommonVo5.setName("鍏虫満"); + mdcCommonVo5.setValue(mdcEquipmentStatusVo.getCloseCount().toString()); + result.add(mdcCommonVo5); + MdcCommonVo mdcCommonVo6 = new MdcCommonVo(); + mdcCommonVo6.setName("鎶ヨ"); + mdcCommonVo6.setValue(mdcEquipmentStatusVo.getAlarmCount().toString()); + result.add(mdcCommonVo6); + MdcCommonVo mdcCommonVo7 = new MdcCommonVo(); + mdcCommonVo7.setName("寰呮満"); + mdcCommonVo7.setValue(mdcEquipmentStatusVo.getWaitCount().toString()); + result.add(mdcCommonVo7); + MdcCommonVo mdcCommonVo8 = new MdcCommonVo(); + mdcCommonVo8.setName("杩愯"); + mdcCommonVo8.setValue(mdcEquipmentStatusVo.getRunCount().toString()); + result.add(mdcCommonVo8); + return result; + } + + /** + * 璁惧鍒╃敤鐜囩粺璁� + */ + @Override + public List<MdcCommonVo> getEquipmentUtilizationStatistics(String userId, String key) { + List<MdcCommonVo> result = new ArrayList<>(); + //鑾峰彇鍏徃鎴栧巶鍖轰簩绾т俊鎭� + List<MdcProduction> mdcProductionList = mdcHomeMapper.getProductionByPid(userId, key); + if (mdcProductionList != null && !mdcProductionList.isEmpty()) { + for (MdcProduction mdcProduction : mdcProductionList) { + MdcCommonVo mdcCommonVo = new MdcCommonVo(); + mdcCommonVo.setName(mdcProduction.getProductionName()); + mdcCommonVo.setProductionCode(mdcProduction.getProductionCode()); + //鑾峰彇姝ゅ眰绾т笅璁惧 + List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProduction.getId()); + if (equipmentIdList == null || equipmentIdList.isEmpty()) { + mdcCommonVo.setValue("0"); + } else { + String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE), DateUtils.STRDATE); + BigDecimal processCount = mdcHomeMapper.getProcessCount(equipmentIdList, date); + if (processCount == null || processCount.compareTo(BigDecimal.ZERO) == 0) { + mdcCommonVo.setValue("0"); + } else { + mdcCommonVo.setValue(processCount.divide(new BigDecimal(86400).multiply(new BigDecimal(equipmentIdList.size())), 4, RoundingMode.HALF_UP).toString()); + } + } + result.add(mdcCommonVo); + } + } + return result; + } + + /** + * 璁惧OEE缁熻 + */ + @Override + public List<MdcCommonVo> getEquipmentOeeStatistics(String userId, String key) { + List<MdcCommonVo> result = new ArrayList<>(); + //鑾峰彇鍏徃鎴栧巶鍖轰簩绾т俊鎭� + List<MdcProduction> mdcProductionList = mdcHomeMapper.getProductionByPid(userId, key); + if (mdcProductionList != null && !mdcProductionList.isEmpty()) { + for (MdcProduction mdcProduction : mdcProductionList) { + MdcCommonVo mdcCommonVo = new MdcCommonVo(); + mdcCommonVo.setName(mdcProduction.getProductionName()); + mdcCommonVo.setProductionCode(mdcProduction.getProductionCode()); + //鑾峰彇姝ゅ眰绾т笅璁惧 + List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProduction.getId()); + if (equipmentIdList == null || equipmentIdList.isEmpty()) { + mdcCommonVo.setValue("0"); + } else { + String date = DateUtils.format(DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE), DateUtils.STR_YEAR_MONTH); + BigDecimal oee = mdcHomeMapper.getOeeByDate(equipmentIdList, date); + if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) { + mdcCommonVo.setValue("0"); + } else { + mdcCommonVo.setValue(oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).toString()); + } + } + result.add(mdcCommonVo); + } + } + return result; + } + + /** + * 璁惧OEE鍜屽埄鐢ㄧ巼缁熻鏌辩姸鍥� + */ + @Override + public Map<String, Object> getEquipmentMonthStatistics(String userId, String key) { + List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key); + Map<String, Object> result = new HashMap<>(); + Date end = DateUtils.toDate(LocalDate.now().plusMonths(-1).toString(), DateUtils.STR_DATE); + Date start = DateUtils.toDate(LocalDate.now().plusMonths(-12).toString(), DateUtils.STR_DATE); + List<String> monthBetween = DateUtils.getMonthBetween(start, end); + List<String> dateList = new ArrayList<>(); + List<MdcCommonVo> utilizationList = new ArrayList<>(); + List<MdcCommonVo> oeeList = new ArrayList<>(); + for (String month : monthBetween) { + //鏃ユ湡闆嗗悎 + String name = month.substring(month.lastIndexOf("-") + 1).replaceFirst("^0*", "") + "鏈�"; + dateList.add(name); + //鍒╃敤鐜囧拰oee + MdcCommonVo mdcCommonUtilizationVo = new MdcCommonVo(); + mdcCommonUtilizationVo.setName(name); + MdcCommonVo mdcCommonOeeVo = new MdcCommonVo(); + mdcCommonOeeVo.setName(name); + if (equipmentIdList == null || equipmentIdList.isEmpty()) { + mdcCommonUtilizationVo.setValue("0"); + mdcCommonOeeVo.setValue("0"); + } else { + //鍒╃敤鐜� + Map<String, Object> resultMap = mdcHomeMapper.getUtilizationByMonth(equipmentIdList, month.replace("-", "")); + if (resultMap != null && resultMap.get("processLong") != null) { + BigDecimal processLong = BigDecimal.valueOf((Double) resultMap.get("processLong")); + BigDecimal processDay = new BigDecimal((Integer) resultMap.get("processDay")); + if (processLong.compareTo(BigDecimal.ZERO) == 0) { + mdcCommonUtilizationVo.setValue("0"); + } else { + mdcCommonUtilizationVo.setValue(processLong.divide(processDay, 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).toString()); + } + } else { + mdcCommonUtilizationVo.setValue("0"); + } + + //OEE + BigDecimal oee = mdcHomeMapper.getOeeByDate(equipmentIdList, month); + if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) { + mdcCommonOeeVo.setValue("0"); + } else { + mdcCommonOeeVo.setValue(oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).toString()); + } + } + utilizationList.add(mdcCommonUtilizationVo); + oeeList.add(mdcCommonOeeVo); + } + result.put("dateList", dateList); + result.put("utilizationList", utilizationList); + result.put("oeeList", oeeList); + return result; + } +} -- Gitblit v1.9.3