| | |
| | | // 查询原始数据(不依赖数据库聚合) |
| | | List<Map<String, Object>> rawData = apsGasPipingRouteStatMapper.selectRawStatData(queryParams); |
| | | |
| | | // 如果没有查询到原始数据,但需要返回所有工序/车间的数据 |
| | | if (rawData.isEmpty()) { |
| | | // 创建没有时间限制的基础查询参数 |
| | | Map<String, Object> baseParams = new HashMap<>(queryParams); |
| | | baseParams.remove("yearStart"); |
| | | baseParams.remove("monthStart"); |
| | | baseParams.remove("yearEnd"); |
| | | baseParams.remove("monthEnd"); |
| | | |
| | | // 直接从aps_gas_piping_route_stat表查询所有可能的工序和车间 |
| | | List<Map<String, Object>> baseData = apsGasPipingRouteStatMapper.selectBaseStatData(baseParams); |
| | | |
| | | // 为每个工序/车间创建基于时间的空数据 |
| | | for (Map<String, Object> data : baseData) { |
| | | String rowGroupValue = getStringValue(data, rowGroupBy); |
| | | if (rowGroupValue == null || rowGroupValue.trim().isEmpty()) continue; |
| | | |
| | | Map<String, Object> rowEntry = new HashMap<>(); |
| | | Map<String, Object> rowDetail = new HashMap<>(); |
| | | |
| | | // 添加基本信息 |
| | | String plant = getStringValue(data, "plant"); |
| | | String major = getStringValue(data, "major"); |
| | | String workshop = getStringValue(data, "workshop"); |
| | | |
| | | if (groupByPlant) rowDetail.put("plant", plant); |
| | | if (groupByMajor) rowDetail.put("major", major); |
| | | if (groupByWorkshop) rowDetail.put("workshop", workshop); |
| | | |
| | | // 处理工序名称 - 如果rowGroupBy为workshop,需要添加processName字段 |
| | | if ("workshop".equals(rowGroupBy)) { |
| | | String processName = getStringValue(data, "processName"); |
| | | rowDetail.put("processName", processName != null ? 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(rowGroupValue, rowDetail); |
| | | plantTable.add(rowEntry); |
| | | } |
| | | |
| | | result.put("plantTable", plantTable); |
| | | result.put("timePoints", timePoints); |
| | | result.put("rowGroupBy", rowGroupBy); |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | result.put("timePoints", timePoints); |
| | | result.put("rowGroupBy", rowGroupBy); |
| | | |
| | | // 根据文档注意点3,添加排序逻辑 |
| | | if (!plantTable.isEmpty()) { |
| | | // 对聚合结果进行排序 |
| | | 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); |
| | | }); |
| | | } |
| | | |
| | | return result; |
| | | } |
| | | |