| | |
| | | package org.jeecg.modules.mdc.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; |
| | | import org.apache.commons.compress.utils.Lists; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.jeecg.common.system.vo.DictModel; |
| | | import org.jeecg.modules.mdc.constant.MdcConstant; |
| | | import org.jeecg.modules.mdc.dto.MdcEquipmentDto; |
| | |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * @author Lius |
| | |
| | | * 设备运行状态统计 |
| | | */ |
| | | @Override |
| | | public List<MdcCommonVo> getEquipmentStatusStatistics(String userId, String key) { |
| | | public List<MdcCommonVo> getEquipmentStatusStatistics(String productionId) { |
| | | List<MdcCommonVo> result = new ArrayList<>(); |
| | | MdcCommonVo mdcCommonVo1 = new MdcCommonVo(); |
| | | mdcCommonVo1.setName("关机"); |
| | |
| | | mdcCommonVo4.setValue("0"); |
| | | result.add(mdcCommonVo4); |
| | | MdcEquipmentStatusVo mdcEquipmentStatusVo = new MdcEquipmentStatusVo(); |
| | | if (StringUtils.isBlank(key)) { |
| | | return result; |
| | | |
| | | //获取所有设备 |
| | | List<Equipment> equipmentList = Lists.newArrayList(); |
| | | if (StringUtils.isNotBlank(productionId)) { |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(productionId); |
| | | equipmentList = CollectionUtils.isNotEmpty(equipmentIdList) ? equipmentService.listByIds(equipmentIdList) : new ArrayList<>(); |
| | | }else { |
| | | equipmentList = equipmentService.list(); |
| | | } |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | return result; |
| | | } |
| | | // List<EquipmentLog> logList = equipmentLogService.getEquipmentStatusList(equipmentIdList); |
| | | List<Equipment> equipmentList = equipmentService.list(new LambdaQueryWrapper<Equipment>().in(Equipment::getEquipmentid, equipmentIdList)); |
| | | |
| | | if (equipmentList != null && !equipmentList.isEmpty()) { |
| | | for (Equipment equipment : equipmentList) { |
| | | if (equipment.getOporation() != null) { |
| | |
| | | * 设备利用率统计 |
| | | */ |
| | | @Override |
| | | public List<MdcCommonVo> getEquipmentUtilizationStatistics(String userId, String key) { |
| | | public List<MdcCommonVo> getEquipmentUtilizationStatistics(String productionId) { |
| | | List<MdcCommonVo> result = new ArrayList<>(); |
| | | //获取公司或厂区二级信息 |
| | | List<MdcProduction> mdcProductionList = mdcHomeMapper.getProductionByPid(userId, key); |
| | | List<MdcProduction> mdcProductionList = mdcHomeMapper.getProductionByPid(null, productionId); |
| | | |
| | | //如果不传“productionId”参数,则查所有车间,否则查询该车间下的工段等 |
| | | if (StringUtils.isEmpty(productionId)) { |
| | | mdcProductionList = mdcProductionList.stream().filter(mdcProduction -> "2".equals(mdcProduction.getOrgType())).collect(Collectors.toList()); |
| | | } |
| | | if (mdcProductionList != null && !mdcProductionList.isEmpty()) { |
| | | for (MdcProduction mdcProduction : mdcProductionList) { |
| | | MdcCommonVo mdcCommonVo = new MdcCommonVo(); |
| | |
| | | mdcCommonVo.setProductionCode(mdcProduction.getProductionCode()); |
| | | mdcCommonVo.setProductionId(mdcProduction.getId()); |
| | | //获取此层级下设备 |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProduction.getId()); |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(mdcProduction.getId()); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | mdcCommonVo.setValue("0"); |
| | | } else { |
| | |
| | | * 设备OEE统计 |
| | | */ |
| | | @Override |
| | | public List<MdcCommonVo> getEquipmentOeeStatistics(String userId, String key) { |
| | | public List<MdcCommonVo> getEquipmentOeeStatistics(String productionId) { |
| | | List<MdcCommonVo> result = new ArrayList<>(); |
| | | //获取公司或厂区二级信息 |
| | | List<MdcProduction> mdcProductionList = mdcHomeMapper.getProductionByPid(userId, key); |
| | | List<MdcProduction> mdcProductionList = mdcHomeMapper.getProductionByPid(null, productionId); |
| | | //如果不传“productionId”参数,则查所有车间,否则查询该车间下的工段等 |
| | | if (StringUtils.isEmpty(productionId)) { |
| | | mdcProductionList = mdcProductionList.stream().filter(mdcProduction -> "2".equals(mdcProduction.getOrgType())).collect(Collectors.toList()); |
| | | } |
| | | if (mdcProductionList != null && !mdcProductionList.isEmpty()) { |
| | | for (MdcProduction mdcProduction : mdcProductionList) { |
| | | MdcCommonVo mdcCommonVo = new MdcCommonVo(); |
| | |
| | | mdcCommonVo.setProductionCode(mdcProduction.getProductionCode()); |
| | | mdcCommonVo.setProductionId(mdcProduction.getId()); |
| | | //获取此层级下设备 |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, mdcProduction.getId()); |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(mdcProduction.getId()); |
| | | if (equipmentIdList == null || equipmentIdList.isEmpty()) { |
| | | mdcCommonVo.setValue("0"); |
| | | } else { |
| | |
| | | if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) { |
| | | mdcCommonVo.setValue("0"); |
| | | } else { |
| | | mdcCommonVo.setValue(oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | mdcCommonVo.setValue(CollectionUtils.isNotEmpty(equipmentIdList) ? oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).toString() : "0"); |
| | | } |
| | | } |
| | | result.add(mdcCommonVo); |
| | |
| | | * 设备OEE和利用率统计柱状图 |
| | | */ |
| | | @Override |
| | | public Map<String, Object> getEquipmentMonthStatistics(String userId, String key) { |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key); |
| | | public Map<String, Object> getEquipmentMonthStatistics(String productionId) { |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(productionId); |
| | | 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); |
| | |
| | | if (oee == null || oee.compareTo(BigDecimal.ZERO) == 0) { |
| | | mdcCommonOeeVo.setValue("0"); |
| | | } else { |
| | | mdcCommonOeeVo.setValue(oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).toString()); |
| | | mdcCommonOeeVo.setValue(CollectionUtils.isNotEmpty(equipmentIdList) ? oee.divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP).toString() : "0"); |
| | | } |
| | | } |
| | | utilizationList.add(mdcCommonUtilizationVo); |
| | |
| | | * 工段级前七天利用率折线图 |
| | | */ |
| | | @Override |
| | | public Map<String, Object> getEquipmentDayUtilizationStatistics(String userId, String key) { |
| | | public Map<String, Object> getEquipmentDayUtilizationStatistics(String productionId) { |
| | | Map<String, Object> result = new HashMap<>(); |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(userId, key); |
| | | //获取前七天日期集合 |
| | | String start = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-7).toString(), DateUtils.STR_DATE), DateUtils.STRDATE); |
| | | String end = DateUtils.format(DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE), DateUtils.STRDATE); |
| | | if (equipmentIdList != null && !equipmentIdList.isEmpty()) { |
| | | List<MdcEquipment> mdcEquipmentList = mdcEquipmentService.list(new LambdaQueryWrapper<MdcEquipment>().in(MdcEquipment::getEquipmentId, equipmentIdList)); |
| | | result.put("mdcEquipmentList", mdcEquipmentList); |
| | | List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfoList = mdcHomeMapper.getEquipmentSevenUtilizationStatistics(equipmentIdList, start, end); |
| | | List<EquipmentDayUtilizationVo> dataList = new ArrayList<>(); |
| | | if (mdcEquipmentStatisticalInfoList != null && !mdcEquipmentStatisticalInfoList.isEmpty()) { |
| | | for (MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo : mdcEquipmentStatisticalInfoList) { |
| | | EquipmentDayUtilizationVo equipmentDayUtilizationVo = new EquipmentDayUtilizationVo(); |
| | | equipmentDayUtilizationVo.setEquipmentId(mdcEquipmentStatisticalInfo.getEquipmentId()); |
| | | equipmentDayUtilizationVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(mdcEquipmentStatisticalInfoList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP)); |
| | | if (BigDecimal.ZERO.compareTo(mdcEquipmentStatisticalInfo.getOpenLong()) == -1) { |
| | | equipmentDayUtilizationVo.setOpenRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); |
| | | equipmentDayUtilizationVo.setStartRate(mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(mdcEquipmentStatisticalInfoList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP)); |
| | | } |
| | | dataList.add(equipmentDayUtilizationVo); |
| | | } |
| | | } |
| | | result.put("dataList", dataList); |
| | | } |
| | | /*List<String> dayBetween = DateUtils.getDatesStringList2(start, end); |
| | | |
| | | List<String> equipmentIdList = mdcEquipmentService.getEquipmentIdsProduction(productionId); |
| | | Date startDate = DateUtils.toDate(LocalDate.now().plusDays(-15).toString(), DateUtils.STR_DATE); |
| | | String start = DateUtils.format(startDate, DateUtils.STRDATE); |
| | | Date endDate = DateUtils.toDate(LocalDate.now().plusDays(-1).toString(), DateUtils.STR_DATE); |
| | | String end = DateUtils.format(endDate, DateUtils.STRDATE); |
| | | List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfos = mdcHomeMapper.getEquipmentSevenUtilizationStatistics(equipmentIdList, start, end); |
| | | Map<String, MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfoMap = mdcEquipmentStatisticalInfos.stream().collect(Collectors.toMap(MdcEquipmentStatisticalInfo::getTheDate, mdcEquipmentStatisticalInfo -> mdcEquipmentStatisticalInfo, (v1, v2) -> v1)); |
| | | List<String> dayBetween = DateUtils.getDatesStringList2(startDate, endDate); |
| | | |
| | | List<String> dateList = new ArrayList<>(); |
| | | List<EquipmentDayUtilizationVo> dataList = new ArrayList<>(); |
| | | |
| | | for (String date : dayBetween) { |
| | | EquipmentDayUtilizationVo equipmentDayUtilizationVo = new EquipmentDayUtilizationVo(); |
| | | String item = date.substring(4); |
| | |
| | | item = item.substring(1); |
| | | String sub = item.substring(1); |
| | | if (sub.startsWith("0")) { |
| | | item = item.substring(0, 1) + "月" + sub.substring(1) + "日"; |
| | | item = item.substring(0, 1) + "-" + sub.substring(1); |
| | | } else { |
| | | item = item.substring(0, 1) + "月" + item.substring(1) + "日"; |
| | | item = item.substring(0, 1) + "-" + item.substring(1); |
| | | } |
| | | } else { |
| | | String sub = item.substring(2); |
| | | if (sub.startsWith("0")) { |
| | | item = item.substring(0, 2) + "月" + sub.substring(2) + "日"; |
| | | item = item.substring(0, 2) + "-" + sub.substring(2); |
| | | } else { |
| | | item = item.substring(0, 2) + "月" + item.substring(2) + "日"; |
| | | item = item.substring(0, 2) + "-" + item.substring(2); |
| | | } |
| | | } |
| | | dateList.add(item); |
| | | equipmentDayUtilizationVo.setDate(item); |
| | | if (equipmentIdList != null && !equipmentIdList.isEmpty()) { |
| | | //获取前七天利用率数据 |
| | | List<MdcEquipmentStatisticalInfo> mdcEquipmentStatisticalInfos = mdcHomeMapper.getEquipmentDayUtilizationStatistics(equipmentIdList, dayBetween); |
| | | if (mdcEquipmentStatisticalInfos != null && !mdcEquipmentStatisticalInfos.isEmpty()) { |
| | | for (MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo : mdcEquipmentStatisticalInfos) { |
| | | if (mdcEquipmentStatisticalInfo.getTheDate().equals(date)) { |
| | | equipmentDayUtilizationVo.setUtilizationRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP)); |
| | | if (BigDecimal.ZERO.compareTo(mdcEquipmentStatisticalInfo.getOpenLong()) == -1) { |
| | | equipmentDayUtilizationVo.setOpenRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); |
| | | equipmentDayUtilizationVo.setStartRate(mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP)); |
| | | } |
| | | } |
| | | } |
| | | } else { |
| | | dataList.add(equipmentDayUtilizationVo); |
| | | |
| | | if (null != mdcEquipmentStatisticalInfoMap && mdcEquipmentStatisticalInfoMap.containsKey(date)) { |
| | | //获取当前日期下的利用率数据 |
| | | MdcEquipmentStatisticalInfo mdcEquipmentStatisticalInfo = mdcEquipmentStatisticalInfoMap.get(date); |
| | | equipmentDayUtilizationVo.setUtilizationRate(CollectionUtils.isNotEmpty(equipmentIdList) ? mdcEquipmentStatisticalInfo.getProcessLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); |
| | | if (BigDecimal.ZERO.compareTo(mdcEquipmentStatisticalInfo.getOpenLong()) == -1) { |
| | | equipmentDayUtilizationVo.setOpenRate(mdcEquipmentStatisticalInfo.getProcessLong().divide(mdcEquipmentStatisticalInfo.getOpenLong(), 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, RoundingMode.HALF_UP)); |
| | | equipmentDayUtilizationVo.setStartRate(CollectionUtils.isNotEmpty(equipmentIdList) ? mdcEquipmentStatisticalInfo.getOpenLong().divide(new BigDecimal("864"), 4, RoundingMode.HALF_UP).divide(new BigDecimal(equipmentIdList.size()), 4, RoundingMode.HALF_UP).setScale(2, RoundingMode.HALF_UP) : BigDecimal.ZERO); |
| | | } |
| | | } else { |
| | | dataList.add(equipmentDayUtilizationVo); |
| | | } |
| | | dataList.add(equipmentDayUtilizationVo); |
| | | } |
| | | result.put("dateList", dateList); |
| | | result.put("dataList", dataList);*/ |
| | | result.put("dataList", dataList); |
| | | return result; |
| | | } |
| | | |
| | |
| | | public List<MdcFeedback> getFeedbackList(String key) { |
| | | return mdcFeedbackService.getFeedbackList(key); |
| | | } |
| | | |
| | | @Override |
| | | public List<MdcProduction> getAllWorkShop() { |
| | | List<MdcProduction> list = mdcProductionService.list(new LambdaQueryWrapper<MdcProduction>().eq(MdcProduction::getOrgType, "2")); |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | return null; |
| | | } |
| | | return list; |
| | | } |
| | | } |