package com.ruoyi.quality.service.impl;
|
|
import com.ruoyi.common.utils.StringUtils;
|
import com.ruoyi.quality.dto.*;
|
import com.ruoyi.quality.mapper.QualityInspectMapper;
|
import com.ruoyi.quality.pojo.QualityInspect;
|
import com.ruoyi.quality.service.QualityReportService;
|
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.math.BigDecimal;
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
|
@Service
|
public class QualityReportServiceImpl implements QualityReportService {
|
|
@Autowired
|
private QualityInspectMapper qualityInspectMapper;
|
|
@Override
|
public List<QualityInspectStatDto> getInspectStatistics() {
|
return qualityInspectMapper.getInspectStatistics();
|
}
|
|
@Override
|
public List<QualityPassRateDto> getPassRateStatistics() {
|
List<QualityInspect> rawList = qualityInspectMapper.getRawPassRateStatistics();
|
|
Map<Integer, QualityPassRateDto> map = new HashMap<>();
|
for (int i = 0; i <= 2; i++) {
|
QualityPassRateDto dto = new QualityPassRateDto();
|
dto.setModelType(i);
|
dto.setTotalCount(BigDecimal.ZERO);
|
dto.setCompletedCount(BigDecimal.ZERO);
|
dto.setQualifiedCount(BigDecimal.ZERO);
|
dto.setUnqualifiedCount(BigDecimal.ZERO);
|
map.put(i, dto);
|
}
|
|
for (QualityInspect qi : rawList) {
|
Integer type = qi.getInspectType();
|
if (type == null || !map.containsKey(type) || qi.getQuantity() == null) continue;
|
|
QualityPassRateDto dto = map.get(type);
|
|
BigDecimal qty = qi.getQuantity();
|
dto.setTotalCount(dto.getTotalCount().add(qty));
|
|
if (qi.getInspectState() != null && qi.getInspectState() == 1) {
|
dto.setCompletedCount(dto.getCompletedCount().add(qty));
|
|
BigDecimal qualified;
|
BigDecimal unqualified;
|
|
String result = qi.getCheckResult();
|
|
if (qi.getQualifiedQuantity() != null) {
|
qualified = qi.getQualifiedQuantity();
|
} else if ("合格".equals(result)) {
|
qualified = qty;
|
} else {
|
qualified = BigDecimal.ZERO;
|
}
|
|
if (qi.getUnqualifiedQuantity() != null) {
|
unqualified = qi.getUnqualifiedQuantity();
|
} else if ("不合格".equals(result) || "部分合格".equals(result)) {
|
unqualified = qty;
|
} else {
|
unqualified = BigDecimal.ZERO;
|
}
|
|
dto.setQualifiedCount(dto.getQualifiedCount().add(qualified));
|
dto.setUnqualifiedCount(dto.getUnqualifiedCount().add(unqualified));
|
}
|
}
|
|
List<QualityPassRateDto> resultList = new ArrayList<>();
|
for (int i = 0; i <= 2; i++) {
|
QualityPassRateDto dto = map.get(i);
|
|
if (dto.getTotalCount().compareTo(BigDecimal.ZERO) == 0) {
|
dto.setCompletionRate(BigDecimal.ZERO);
|
} else {
|
dto.setCompletionRate(dto.getCompletedCount().divide(dto.getTotalCount(), 4, java.math.RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, java.math.RoundingMode.HALF_UP));
|
}
|
|
if (dto.getCompletedCount().compareTo(BigDecimal.ZERO) == 0) {
|
dto.setPassRate(BigDecimal.ZERO);
|
} else {
|
dto.setPassRate(dto.getQualifiedCount().divide(dto.getCompletedCount(), 4, java.math.RoundingMode.HALF_UP).multiply(new BigDecimal("100")).setScale(2, java.math.RoundingMode.HALF_UP));
|
}
|
resultList.add(dto);
|
}
|
|
return resultList;
|
}
|
|
@Override
|
public List<QualityMonthlyPassRateWrapperDto> getMonthlyPassRateStatistics(String year) {
|
if (StringUtils.isEmpty(year)) {
|
return new ArrayList<>();
|
}
|
List<QualityMonthlyPassRateDto> flatData = qualityInspectMapper.getMonthlyPassRateStatistics(year);
|
|
// 按月份分组,并保持顺序
|
Map<String, List<QualityMonthlyPassRateDto>> groupedByMonth = flatData.stream()
|
.collect(Collectors.groupingBy(QualityMonthlyPassRateDto::getMonth, LinkedHashMap::new, Collectors.toList()));
|
|
List<QualityMonthlyPassRateWrapperDto> result = new ArrayList<>();
|
|
groupedByMonth.forEach((month, dtos) -> {
|
QualityMonthlyPassRateWrapperDto wrapper = new QualityMonthlyPassRateWrapperDto();
|
wrapper.setMonth(month);
|
|
for (QualityMonthlyPassRateDto dto : dtos) {
|
QualityPassRateDto passRateDto = new QualityPassRateDto();
|
BeanUtils.copyProperties(dto, passRateDto);
|
|
if (dto.getModelType() == 0) {
|
wrapper.setRawMaterial(passRateDto);
|
} else if (dto.getModelType() == 1) {
|
wrapper.setProcess(passRateDto);
|
} else if (dto.getModelType() == 2) {
|
wrapper.setOutgoing(passRateDto);
|
}
|
}
|
result.add(wrapper);
|
});
|
|
return result;
|
}
|
|
@Override
|
public List<QualityPassRateDto> getYearlyPassRateStatistics(String year) {
|
if (StringUtils.isEmpty(year)) {
|
return new ArrayList<>();
|
}
|
return qualityInspectMapper.getYearlyPassRateStatistics(year);
|
}
|
|
@Override
|
public List<QualityMonthlyDetailDto> getMonthlyCompletionDetails(String year) {
|
if (StringUtils.isEmpty(year)) {
|
return new ArrayList<>();
|
}
|
return qualityInspectMapper.getMonthlyCompletionDetails(year);
|
}
|
|
@Override
|
public QualityTopParameterDto getTopParameters(Integer modelType) {
|
if (modelType == null) {
|
return new QualityTopParameterDto();
|
}
|
List<QualityParameterStatDto> list = qualityInspectMapper.getTopParameters(modelType);
|
|
BigDecimal total = list.stream()
|
.map(QualityParameterStatDto::getCount)
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
QualityTopParameterDto result = new QualityTopParameterDto();
|
result.setTotalCount(total);
|
result.setList(list);
|
|
return result;
|
}
|
}
|