| | |
| | | plantTable.add(rowEntry); |
| | | } |
| | | |
| | | // 更新结果但不直接返回,继续执行后续注意点4的处理 |
| | | result.put("plantTable", plantTable); |
| | | result.put("timePoints", timePoints); |
| | | result.put("rowGroupBy", rowGroupBy); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | } else { |
| | | // 在Service层完成聚合 |
| | | // 使用组合key来实现多维度分组(动态rowGroupBy字段 + 可选的工厂/专业/车间) |
| | | Map<String, Map<String, Object>> groupInfoMap = new HashMap<>(); |
| | |
| | | rowDetail.put("timeData", timeDataList); |
| | | rowEntry.put(rowGroupValue, rowDetail); |
| | | plantTable.add(rowEntry); |
| | | } |
| | | } |
| | | |
| | | // 在返回前查询设计产能数据并计算产能负荷 |
| | |
| | | }); |
| | | } |
| | | |
| | | // 实现注意点4:当时间颗粒度为"日"时,确保没有数据的工厂也返回完整结构 |
| | | if ("day".equalsIgnoreCase(timeGranularity) && params.containsKey("plant")) { |
| | | // 获取请求中的工厂列表 |
| | | List<String> requestedPlants = new ArrayList<>(); |
| | | Object plantParam = params.get("plant"); |
| | | if (plantParam instanceof List) { |
| | | requestedPlants.addAll((List<String>) plantParam); |
| | | } else if (plantParam instanceof String) { |
| | | String plantStr = (String) plantParam; |
| | | if (plantStr.contains(",")) { |
| | | requestedPlants.addAll(Arrays.asList(plantStr.split(","))); |
| | | } else { |
| | | requestedPlants.add(plantStr); |
| | | } |
| | | } |
| | | |
| | | if (!requestedPlants.isEmpty()) { |
| | | // 检查哪些工厂没有数据 |
| | | Set<String> plantsWithData = new HashSet<>(); |
| | | for (Map<String, Object> rowEntry : plantTable) { |
| | | for (String rowKey : rowEntry.keySet()) { |
| | | Map<String, Object> rowDetail = (Map<String, Object>) rowEntry.get(rowKey); |
| | | if (rowDetail.containsKey("plant")) { |
| | | plantsWithData.add((String) rowDetail.get("plant")); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 找出没有数据的工厂 |
| | | List<String> plantsWithoutData = requestedPlants.stream() |
| | | .filter(plant -> !plantsWithData.contains(plant)) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (!plantsWithoutData.isEmpty()) { |
| | | // 获取所有去重的processName或workshop |
| | | List<String> allUniqueValues; |
| | | if ("processName".equals(rowGroupBy)) { |
| | | allUniqueValues = apsGasPipingRouteStatMapper.selectDistinctProcessNames(); |
| | | } else if ("workshop".equals(rowGroupBy)) { |
| | | allUniqueValues = apsGasPipingRouteStatMapper.selectDistinctWorkshops(); |
| | | } else { |
| | | // 如果rowGroupBy不是processName或workshop,跳过处理 |
| | | return result; |
| | | } |
| | | |
| | | // 为每个没有数据的工厂创建空数据结构 |
| | | for (String plant : plantsWithoutData) { |
| | | for (String uniqueValue : allUniqueValues) { |
| | | if (uniqueValue == null || uniqueValue.trim().isEmpty()) { |
| | | continue; |
| | | } |
| | | |
| | | // 检查是否已经存在这个值 |
| | | boolean exists = false; |
| | | for (Map<String, Object> entry : plantTable) { |
| | | if (entry.containsKey(uniqueValue)) { |
| | | Map<String, Object> detail = (Map<String, Object>) entry.get(uniqueValue); |
| | | String existingPlant = detail.containsKey("plant") ? (String) detail.get("plant") : ""; |
| | | if (plant.equals(existingPlant)) { |
| | | exists = true; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 如果不存在,创建新的空数据结构 |
| | | if (!exists) { |
| | | Map<String, Object> rowEntry = new HashMap<>(); |
| | | Map<String, Object> rowDetail = new HashMap<>(); |
| | | |
| | | // 设置基本信息 |
| | | rowDetail.put("plant", plant); |
| | | if (groupByMajor) { |
| | | rowDetail.put("major", ""); |
| | | } |
| | | if (groupByWorkshop && !"workshop".equals(rowGroupBy)) { |
| | | rowDetail.put("workshop", ""); |
| | | } |
| | | |
| | | // 处理processName - 如果rowGroupBy为workshop,需要设置空的processName |
| | | if ("workshop".equals(rowGroupBy)) { |
| | | rowDetail.put("processName", ""); |
| | | } |
| | | |
| | | // 为每个时间点创建零值数据 |
| | | List<Map<String, Object>> timeDataList = new ArrayList<>(); |
| | | for (String timePoint : timePoints) { |
| | | Map<String, Object> pointData = new HashMap<>(); |
| | | pointData.put("planDay", timePoint); |
| | | pointData.put("requireTimes", BigDecimal.ZERO); |
| | | pointData.put("designTimes", BigDecimal.ZERO); |
| | | pointData.put("capacityLoad", BigDecimal.ZERO); |
| | | timeDataList.add(pointData); |
| | | } |
| | | |
| | | rowDetail.put("timeData", timeDataList); |
| | | rowEntry.put(uniqueValue, rowDetail); |
| | | plantTable.add(rowEntry); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 重新排序结果 |
| | | Collections.sort(plantTable, (map1, map2) -> { |
| | | String key1 = map1.keySet().iterator().next(); |
| | | String key2 = map2.keySet().iterator().next(); |
| | | |
| | | // 首先按rowGroupBy排序(processName或workshop) |
| | | int result1 = key1.compareTo(key2); |
| | | if (result1 != 0) { |
| | | return result1; |
| | | } |
| | | |
| | | // 如果rowGroupBy相同,再按plant排序 |
| | | Map<String, Object> detail1 = (Map<String, Object>) map1.get(key1); |
| | | Map<String, Object> detail2 = (Map<String, Object>) map2.get(key2); |
| | | |
| | | String plant1 = detail1.containsKey("plant") ? (String) detail1.get("plant") : ""; |
| | | String plant2 = detail2.containsKey("plant") ? (String) detail2.get("plant") : ""; |
| | | |
| | | return plant1.compareTo(plant2); |
| | | }); |
| | | |
| | | // 更新结果 |
| | | result.put("plantTable", plantTable); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |