| | |
| | | package org.jeecg.modules.mdc.service.impl; |
| | | |
| | | import com.alipay.api.domain.NewsfeedMediaGiftInfo; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.jeecg.common.constant.CommonConstant; |
| | | import org.jeecg.common.exception.JeecgBootException; |
| | | import org.jeecg.modules.mdc.dto.*; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 对比分析 |
| | | */ |
| | | @Override |
| | | public ComparativeAnalysisDto comparativeAnalysis(String userId, ComparativeAnalysisQueryVo vo) { |
| | | ComparativeAnalysisDto result = new ComparativeAnalysisDto(); |
| | | List<String> equipmentIds = new ArrayList<>(); |
| | | if (StringUtils.isNotEmpty(vo.getParentId()) && StringUtils.isEmpty(vo.getEquipmentId())) { |
| | | if ("2".equals(vo.getTypeTree())) { |
| | | // 部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, vo.getParentId()); |
| | | } else { |
| | | // 产线层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, vo.getParentId()); |
| | | } |
| | | } else if (StringUtils.isNotEmpty(vo.getEquipmentId())) { |
| | | // 单台设备信息 |
| | | vo.setEquipmentIdList(Collections.singletonList(vo.getEquipmentId())); |
| | | } else { |
| | | // 查询用户拥有的所有设备信息 |
| | | if ("2".equals(vo.getTypeTree())) { |
| | | // 部门层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsByDepart(userId, null); |
| | | } else { |
| | | // 产线层级 |
| | | equipmentIds = mdcEquipmentService.getEquipmentIdsProduction(userId, null); |
| | | } |
| | | } |
| | | if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) { |
| | | vo.setEquipmentIdList(equipmentIds); |
| | | } |
| | | if (vo.getEquipmentIdList() == null || vo.getEquipmentIdList().isEmpty()) { |
| | | return result; |
| | | } |
| | | |
| | | // 查询原始数据 |
| | | List<MdcComAnaDto> resultDtos = mdcEfficiencyReportMapper.comparativeAnalysis(vo); |
| | | if (resultDtos != null && !resultDtos.isEmpty()) { |
| | | // 组装图形和仪表数据 |
| | | List<GraphicsDto> graphicsDtos = new ArrayList<>(); |
| | | // 获取天数 |
| | | long days = ChronoUnit.DAYS.between(LocalDate.parse(vo.getStartTime(), DateTimeFormatter.ofPattern("yyyyMMdd")), LocalDate.parse(vo.getEndTime(), DateTimeFormatter.ofPattern("yyyyMMdd"))) + 1; |
| | | BigDecimal time = new BigDecimal("24").multiply(new BigDecimal(days)); |
| | | for (MdcComAnaDto mdcComAnaDto : resultDtos) { |
| | | GraphicsDto graphicsDto = new GraphicsDto(); |
| | | graphicsDto.setEquipmentId(mdcComAnaDto.getEquipmentId()); |
| | | graphicsDto.setCloseLong(mdcComAnaDto.getCloseLong()); |
| | | graphicsDto.setOpenLong(mdcComAnaDto.getOpenLong()); |
| | | // 24小时利用率 = 加工时间/24 |
| | | graphicsDto.setUtilizationRate(mdcComAnaDto.getProcessLong().divide(time, 6, BigDecimal.ROUND_HALF_UP)); |
| | | // 开机率 = 开机时间 / 24 |
| | | graphicsDto.setOpenRate(mdcComAnaDto.getOpenLong().divide(time, 6, BigDecimal.ROUND_HALF_UP)); |
| | | graphicsDtos.add(graphicsDto); |
| | | } |
| | | result.setGraphics(graphicsDtos); |
| | | |
| | | List<UtilizationRateDto> tops = new ArrayList<>(); |
| | | List<UtilizationRateDto> lasts = new ArrayList<>(); |
| | | graphicsDtos.stream().sorted(Comparator.comparing(GraphicsDto::getUtilizationRate)).limit(5).forEach(graphicsDto -> { |
| | | UtilizationRateDto utilizationRateDto = new UtilizationRateDto(); |
| | | utilizationRateDto.setEquipmentId(graphicsDto.getEquipmentId()); |
| | | utilizationRateDto.setUtilizationRate(graphicsDto.getUtilizationRate()); |
| | | lasts.add(utilizationRateDto); |
| | | }); |
| | | graphicsDtos.stream().sorted(Comparator.comparing(GraphicsDto::getUtilizationRate).reversed()).limit(5).forEach(graphicsDto -> { |
| | | UtilizationRateDto utilizationRateDto = new UtilizationRateDto(); |
| | | utilizationRateDto.setEquipmentId(graphicsDto.getEquipmentId()); |
| | | utilizationRateDto.setUtilizationRate(graphicsDto.getUtilizationRate()); |
| | | tops.add(utilizationRateDto); |
| | | }); |
| | | MeterDto meterDto = new MeterDto(); |
| | | meterDto.setTops(tops); |
| | | meterDto.setLasts(lasts); |
| | | result.setMeters(meterDto); |
| | | // 组装饼图数据 |
| | | PieChartDto pieChartDto = new PieChartDto(); |
| | | BigDecimal openLong = new BigDecimal("0"); |
| | | BigDecimal closeLong = new BigDecimal("0"); |
| | | BigDecimal waitLong = new BigDecimal("0"); |
| | | BigDecimal processLong = new BigDecimal("0"); |
| | | for (MdcComAnaDto resultDto : resultDtos) { |
| | | openLong = openLong.add(resultDto.getOpenLong()); |
| | | closeLong = closeLong.add(resultDto.getCloseLong()); |
| | | waitLong = waitLong.add(resultDto.getWaitLong()); |
| | | processLong = processLong.add(resultDto.getProcessLong()); |
| | | } |
| | | // 开机率 = 开机时长 / (24 × 天数 × 个数) |
| | | pieChartDto.setOpenRate(openLong.divide(time.multiply(new BigDecimal(resultDtos.size())), 6, BigDecimal.ROUND_HALF_UP)); |
| | | // 关机率 = 1 - 开机率 |
| | | pieChartDto.setCloseRate(new BigDecimal("1").subtract(pieChartDto.getOpenRate())); |
| | | // 加工率 = 加工时间 / (24 × 天数 × 个数) |
| | | pieChartDto.setProcessRate(processLong.divide(time.multiply(new BigDecimal(resultDtos.size())), 6, BigDecimal.ROUND_HALF_UP)); |
| | | // 待机率 = 开机率 - 加工率 |
| | | pieChartDto.setWaitRate(pieChartDto.getOpenRate().subtract(pieChartDto.getProcessRate())); |
| | | result.setPieCharts(pieChartDto); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |
| | | private StatisticalAnalysisVo efficiencyStatisticalRate(List<MdcEfficiencyDto> efficiencyList) { |
| | | StatisticalAnalysisVo vo = new StatisticalAnalysisVo(); |
| | | for (MdcEfficiencyDto mdcEfficiencyDto : efficiencyList) { |