| | |
| | | // 解析日期 |
| | | LocalDate startLocalDate = LocalDate.parse(startDate); |
| | | LocalDate endLocalDate = LocalDate.parse(endDate); |
| | | Date start = Date.from(startLocalDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); |
| | | Date end = Date.from(endLocalDate.plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant()); |
| | | |
| | | // 查询所有工序 |
| | | List<ProductProcess> processList = productProcessMapper.selectList(null); |
| | |
| | | while (!currentDate.isAfter(endLocalDate)) { |
| | | dateSet.add(currentDate); |
| | | currentDate = currentDate.plusDays(1); |
| | | } |
| | | |
| | | // 一次性查询所有日期范围内的质量检验记录 |
| | | List<QualityInspect> allQualityInspects = qualityInspectMapper.selectList( |
| | | new LambdaQueryWrapper<QualityInspect>() |
| | | .ge(QualityInspect::getCheckTime, start) |
| | | .lt(QualityInspect::getCheckTime, end) |
| | | ); |
| | | |
| | | // 按日期和工序分组处理数据 |
| | | Map<LocalDate, Map<String, BigDecimal[]>> dateProcessMap = new HashMap<>(); |
| | | |
| | | for (QualityInspect inspect : allQualityInspects) { |
| | | if (inspect.getCheckTime() != null && inspect.getProcess() != null) { |
| | | // 转换检查时间为LocalDate |
| | | LocalDate inspectDate = inspect.getCheckTime().toInstant() |
| | | .atZone(ZoneId.systemDefault()).toLocalDate(); |
| | | |
| | | // 确保日期在查询范围内 |
| | | if (dateSet.contains(inspectDate)) { |
| | | String processName = inspect.getProcess(); |
| | | |
| | | // 初始化日期和工序数据 |
| | | dateProcessMap.computeIfAbsent(inspectDate, k -> new HashMap<>()); |
| | | BigDecimal[] quantities = dateProcessMap.get(inspectDate) |
| | | .computeIfAbsent(processName, k -> new BigDecimal[]{BigDecimal.ZERO, BigDecimal.ZERO}); |
| | | |
| | | // 累加数量 |
| | | if (inspect.getQuantity() != null) { |
| | | quantities[0] = quantities[0].add(inspect.getQuantity()); |
| | | } |
| | | if (inspect.getDefectiveQuantity() != null) { |
| | | quantities[1] = quantities[1].add(inspect.getDefectiveQuantity()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 构建结果数据 |
| | |
| | | // 初始化工序数据列表 |
| | | List<Map<String, Object>> processesList = new ArrayList<>(); |
| | | |
| | | // 获取该日期的工序数据 |
| | | Map<String, BigDecimal[]> processData = dateProcessMap.getOrDefault(date, new HashMap<>()); |
| | | |
| | | for (ProductProcess process : processList) { |
| | | if (process.getName() != null) { |
| | | // 查询该工序在指定日期的质量检验记录 |
| | | List<QualityInspect> qualityInspects = qualityInspectMapper.selectList( |
| | | new LambdaQueryWrapper<QualityInspect>() |
| | | .eq(QualityInspect::getProcess, process.getName()) |
| | | .ge(QualityInspect::getCheckTime, Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant())) |
| | | .lt(QualityInspect::getCheckTime, Date.from(date.plusDays(1).atStartOfDay(ZoneId.systemDefault()).toInstant())) |
| | | ); |
| | | String processName = process.getName(); |
| | | BigDecimal[] quantities = processData.getOrDefault(processName, new BigDecimal[]{BigDecimal.ZERO, BigDecimal.ZERO}); |
| | | |
| | | // 计算该工序的总检验数量和不良数量 |
| | | BigDecimal processTotalQuantity = BigDecimal.ZERO; |
| | | BigDecimal processDefectiveQuantity = BigDecimal.ZERO; |
| | | BigDecimal processTotalQuantity = quantities[0]; |
| | | BigDecimal processDefectiveQuantity = quantities[1]; |
| | | |
| | | for (QualityInspect inspect : qualityInspects) { |
| | | if (inspect.getQuantity() != null) { |
| | | processTotalQuantity = processTotalQuantity.add(inspect.getQuantity()); |
| | | dailyTotalQuantity = dailyTotalQuantity.add(inspect.getQuantity()); |
| | | } |
| | | if (inspect.getDefectiveQuantity() != null) { |
| | | processDefectiveQuantity = processDefectiveQuantity.add(inspect.getDefectiveQuantity()); |
| | | dailyDefectiveQuantity = dailyDefectiveQuantity.add(inspect.getDefectiveQuantity()); |
| | | } |
| | | } |
| | | // 累加每日总数量 |
| | | dailyTotalQuantity = dailyTotalQuantity.add(processTotalQuantity); |
| | | dailyDefectiveQuantity = dailyDefectiveQuantity.add(processDefectiveQuantity); |
| | | |
| | | // 计算该工序的不良率 |
| | | double processDefectRate = 0.0; |