| | |
| | | package com.ruoyi.quality.service.impl; |
| | | |
| | | import com.ruoyi.basic.service.IProductModelService; |
| | | import com.ruoyi.basic.service.IProductService; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.quality.dto.QualityPassRateDto; |
| | | import com.ruoyi.quality.dto.QualityInspectStatDto; |
| | | import com.ruoyi.quality.dto.QualityMonthlyPassRateDto; |
| | | import com.ruoyi.quality.dto.QualityMonthlyDetailDto; |
| | | import com.ruoyi.quality.dto.QualityParameterStatDto; |
| | | import com.ruoyi.quality.dto.QualityMonthlyPassRateWrapperDto; |
| | | import com.ruoyi.quality.dto.QualityTopParameterDto; |
| | | import com.ruoyi.production.service.ProductOrderService; |
| | | import com.ruoyi.quality.dto.*; |
| | | import com.ruoyi.quality.mapper.QualityInspectMapper; |
| | | import com.ruoyi.quality.service.QualityReportService; |
| | | import org.springframework.beans.BeanUtils; |
| | |
| | | QualityPassRateDto passRateDto = new QualityPassRateDto(); |
| | | BeanUtils.copyProperties(dto, passRateDto); |
| | | |
| | | if (dto.getInspectType() == 0) { |
| | | if (dto.getModelType() == 0) { |
| | | wrapper.setRawMaterial(passRateDto); |
| | | } else if (dto.getInspectType() == 1) { |
| | | } else if (dto.getModelType() == 1) { |
| | | wrapper.setProcess(passRateDto); |
| | | } else if (dto.getInspectType() == 2) { |
| | | } else if (dto.getModelType() == 2) { |
| | | wrapper.setOutgoing(passRateDto); |
| | | } |
| | | } |
| | |
| | | } |
| | | |
| | | @Override |
| | | public QualityTopParameterDto getTopParameters(Integer inspectType) { |
| | | if (inspectType == null) { |
| | | public QualityTopParameterDto getTopParameters(Integer modelType) { |
| | | if (modelType == null) { |
| | | return new QualityTopParameterDto(); |
| | | } |
| | | List<QualityParameterStatDto> list = qualityInspectMapper.getTopParameters(inspectType); |
| | | List<QualityParameterStatDto> list = qualityInspectMapper.getTopParameters(modelType); |
| | | |
| | | BigDecimal total = list.stream() |
| | | .map(QualityParameterStatDto::getCount) |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<QualityPassRateDto> getMonthlyPassRateWithComparison(String year, Integer month) { |
| | | if (StringUtils.isEmpty(year) || month == null || month < 1 || month > 12) { |
| | | return new ArrayList<>(); |
| | | } |
| | | |
| | | // 获取当前年月的合格率数据 |
| | | List<QualityMonthlyPassRateDto> currentMonthData = qualityInspectMapper.getMonthlyPassRateStatistics(year); |
| | | |
| | | // 计算上月 |
| | | int lastMonth = month - 1; |
| | | String lastMonthYear = year; |
| | | if (lastMonth == 0) { |
| | | lastMonth = 12; |
| | | lastMonthYear = String.valueOf(Integer.parseInt(year) - 1); |
| | | } |
| | | |
| | | // 计算去年同月 |
| | | String lastYear = String.valueOf(Integer.parseInt(year) - 1); |
| | | |
| | | // 获取上月数据 |
| | | List<QualityMonthlyPassRateDto> lastMonthData = qualityInspectMapper.getMonthlyPassRateStatistics(lastMonthYear); |
| | | |
| | | // 获取去年同月数据 |
| | | List<QualityMonthlyPassRateDto> lastYearData = qualityInspectMapper.getMonthlyPassRateStatistics(lastYear); |
| | | |
| | | // 月份名称映射 |
| | | String[] monthNames = {"一月", "二月", "三月", "四月", "五月", "六月", |
| | | "七月", "八月", "九月", "十月", "十一月", "十二月"}; |
| | | String currentMonthName = monthNames[month - 1]; |
| | | String lastMonthName = monthNames[lastMonth - 1]; |
| | | |
| | | // 构建结果 |
| | | List<QualityPassRateDto> result = new ArrayList<>(); |
| | | |
| | | for (int modelType = 0; modelType <= 2; modelType++) { |
| | | final int type = modelType; |
| | | |
| | | QualityPassRateDto dto = new QualityPassRateDto(); |
| | | dto.setModelType(modelType); |
| | | |
| | | // 当前月数据 |
| | | QualityMonthlyPassRateDto currentDto = currentMonthData.stream() |
| | | .filter(d -> d.getMonth().equals(currentMonthName) && d.getModelType() == type) |
| | | .findFirst() |
| | | .orElse(null); |
| | | |
| | | if (currentDto != null) { |
| | | dto.setTotalCount(currentDto.getTotalCount()); |
| | | dto.setCompletedCount(currentDto.getCompletedCount()); |
| | | dto.setQualifiedCount(currentDto.getQualifiedCount()); |
| | | dto.setUnqualifiedCount(currentDto.getUnqualifiedCount()); |
| | | dto.setCompletionRate(currentDto.getCompletionRate()); |
| | | dto.setPassRate(currentDto.getPassRate()); |
| | | } else { |
| | | dto.setTotalCount(BigDecimal.ZERO); |
| | | dto.setCompletedCount(BigDecimal.ZERO); |
| | | dto.setQualifiedCount(BigDecimal.ZERO); |
| | | dto.setUnqualifiedCount(BigDecimal.ZERO); |
| | | dto.setCompletionRate(BigDecimal.ZERO); |
| | | dto.setPassRate(BigDecimal.ZERO); |
| | | } |
| | | |
| | | // 上月数据 |
| | | QualityMonthlyPassRateDto lastMonthDto = lastMonthData.stream() |
| | | .filter(d -> d.getMonth().equals(lastMonthName) && d.getModelType() == type) |
| | | .findFirst() |
| | | .orElse(null); |
| | | |
| | | BigDecimal lastMonthPassRate = lastMonthDto != null ? lastMonthDto.getPassRate() : BigDecimal.ZERO; |
| | | dto.setLastMonthPassRate(lastMonthPassRate); |
| | | |
| | | // 去年同月数据 |
| | | QualityMonthlyPassRateDto lastYearDto = lastYearData.stream() |
| | | .filter(d -> d.getMonth().equals(currentMonthName) && d.getModelType() == type) |
| | | .findFirst() |
| | | .orElse(null); |
| | | |
| | | BigDecimal lastYearPassRate = lastYearDto != null ? lastYearDto.getPassRate() : BigDecimal.ZERO; |
| | | dto.setLastYearPassRate(lastYearPassRate); |
| | | |
| | | // 计算环比变化 |
| | | BigDecimal currentPassRate = dto.getPassRate() != null ? dto.getPassRate() : BigDecimal.ZERO; |
| | | if (lastMonthPassRate != null && lastMonthPassRate.compareTo(BigDecimal.ZERO) > 0) { |
| | | BigDecimal momChange = currentPassRate.subtract(lastMonthPassRate); |
| | | dto.setMomChange(momChange); |
| | | dto.setMomTrend(momChange.compareTo(BigDecimal.ZERO)); |
| | | } else { |
| | | dto.setMomChange(BigDecimal.ZERO); |
| | | dto.setMomTrend(0); |
| | | } |
| | | |
| | | // 计算同比变化 |
| | | if (lastYearPassRate != null && lastYearPassRate.compareTo(BigDecimal.ZERO) > 0) { |
| | | BigDecimal yoyChange = currentPassRate.subtract(lastYearPassRate); |
| | | dto.setYoyChange(yoyChange); |
| | | dto.setYoyTrend(yoyChange.compareTo(BigDecimal.ZERO)); |
| | | } else { |
| | | dto.setYoyChange(BigDecimal.ZERO); |
| | | dto.setYoyTrend(0); |
| | | } |
| | | |
| | | result.add(dto); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | } |