| | |
| | | Map<String, ScaleSplitTransport> cumMap = loadCumulativeMap(period); |
| | | ScaleSplitTransport province = getProvinceCumulative(period); |
| | | |
| | | // 当月(第二页):周转量拆分表 MONTH 行(含当月同比) |
| | | // 当月(第二页):③提供合计/规下,规上字段由 ① H203-2 统一覆盖 |
| | | Map<String, Map<Integer, ScaleSplitTransport>> monthData = loadMonthData(period); |
| | | Map<String, ScaleSplitTransport> monthTurnover = new HashMap<>(); |
| | | for (ScaleSplitTransport rec : scaleSplitMapper.selectList( |
| | | new LambdaQueryWrapper<ScaleSplitTransport>() |
| | | .eq(ScaleSplitTransport::getPeriodType, "MONTH") |
| | | .eq(ScaleSplitTransport::getReportPeriod, period))) { |
| | | String name = RegionUtil.normalizeCityName(rec.getRegionName()); |
| | | if (name != null) monthTurnover.put(name, rec); |
| | | for (String city : RegionUtil.cityList()) { |
| | | ScaleSplitTransport rec = getRecord(monthData, city, month); |
| | | if (rec != null) monthTurnover.put(city, rec); |
| | | } |
| | | ScaleSplitTransport provinceMonth = monthTurnover.remove("湖北省"); |
| | | ScaleSplitTransport provinceMonth = loadProvinceMonthMap(period).get(month); |
| | | |
| | | // 以 docs/货运/生成_周转量排名.xlsx 为底稿:保留表头/合并/列宽/样式,仅替换数据;Q/R 占比为模板缓存值,按新数据重算 |
| | | File template = resolveFreightTemplate("生成_周转量排名.xlsx"); |
| | |
| | | int month = parseMonth(record.getReportPeriod()); |
| | | result.computeIfAbsent(city, k -> new HashMap<>()).put(month, record); |
| | | } |
| | | applyH2032MonthlyTurnoverAbove(result, period); |
| | | return result; |
| | | } |
| | | |
| | |
| | | result.put(city, record); |
| | | } |
| | | } |
| | | applyH2032CumulativeTurnoverAbove(result, period); |
| | | return result; |
| | | } |
| | | |
| | |
| | | int month = parseMonth(record.getReportPeriod()); |
| | | result.put(month, record); |
| | | } |
| | | applyH2032ProvinceMonthTurnoverAbove(result, period); |
| | | return result; |
| | | } |
| | | |
| | |
| | | if (!"湖北省".equals(name)) continue; |
| | | if (best == null || record.getReportPeriod().compareTo(best.getReportPeriod()) > 0) best = record; |
| | | } |
| | | return best; |
| | | return applyH2032ProvinceCumulativeTurnoverAbove(best, period); |
| | | } |
| | | |
| | | /** H2032规上: city -> month -> 货运量(吨) */ |
| | |
| | | return result; |
| | | } |
| | | |
| | | /** H2032 规上周转量: city -> month -> 万吨公里(turnover_total 吨公里 ÷10000) */ |
| | | private Map<String, Map<Integer, Double>> loadH2032TurnoverByMonth(String period) { |
| | | Map<String, Map<Integer, Double>> result = new HashMap<>(); |
| | | String yearPrefix = period.length() >= 4 ? period.substring(0, 4) : null; |
| | | for (H2032EnterpriseMonthly record : h2032Mapper.selectList(null)) { |
| | | String rp = record.getReportPeriod(); |
| | | if (rp == null || rp.compareTo(period) > 0) continue; |
| | | if (yearPrefix != null && !rp.startsWith(yearPrefix)) continue; |
| | | if (record.getTurnoverTotal() == null) continue; |
| | | String city = RegionUtil.cityByCode(record.getRegionCode()); |
| | | if (city == null) continue; |
| | | int m = parseMonth(rp); |
| | | result.computeIfAbsent(city, k -> new HashMap<>()) |
| | | .merge(m, record.getTurnoverTotal() / 10000.0, Double::sum); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** H2032 规上周转量 1..period 月累计: city -> 万吨公里 */ |
| | | private Map<String, Double> loadH2032TurnoverCumulative(String period) { |
| | | Map<String, Map<Integer, Double>> byMonth = loadH2032TurnoverByMonth(period); |
| | | int target = parseMonth(period); |
| | | Map<String, Double> result = new HashMap<>(); |
| | | for (Map.Entry<String, Map<Integer, Double>> e : byMonth.entrySet()) { |
| | | double sum = 0.0; |
| | | boolean any = false; |
| | | for (int m = 1; m <= target; m++) { |
| | | Double v = e.getValue().get(m); |
| | | if (v != null) { sum += v; any = true; } |
| | | } |
| | | if (any) result.put(e.getKey(), sum); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /** 规上字段只认 ① H203-2;③记录只保留合计,并据此重算规下。 */ |
| | | private void applyH2032MonthlyTurnoverAbove(Map<String, Map<Integer, ScaleSplitTransport>> data, |
| | | String period) { |
| | | int lastMonth = parseMonth(period); |
| | | Map<String, Map<Integer, Double>> current = loadH2032TurnoverByMonth(period); |
| | | Map<String, Map<Integer, Double>> prior = loadH2032TurnoverByMonth(previousYearPeriod(period)); |
| | | for (String city : RegionUtil.cityList()) { |
| | | Map<Integer, ScaleSplitTransport> cityData = data.get(city); |
| | | for (int m = 1; m <= lastMonth; m++) { |
| | | ScaleSplitTransport rec = cityData == null ? null : cityData.get(m); |
| | | Double above = monthValueOf(current, city, m); |
| | | if (rec == null && above == null) continue; |
| | | if (cityData == null) { |
| | | cityData = new HashMap<>(); |
| | | data.put(city, cityData); |
| | | } |
| | | if (rec == null) { |
| | | rec = new ScaleSplitTransport(); |
| | | rec.setRegionName(city); |
| | | cityData.put(m, rec); |
| | | } |
| | | applyH2032TurnoverAbove(rec, above, growthYoy(above, monthValueOf(prior, city, m))); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private void applyH2032CumulativeTurnoverAbove(Map<String, ScaleSplitTransport> data, String period) { |
| | | Map<String, Double> current = loadH2032TurnoverCumulative(period); |
| | | Map<String, Double> prior = loadH2032TurnoverCumulative(previousYearPeriod(period)); |
| | | for (String city : RegionUtil.cityList()) { |
| | | Double above = current.get(city); |
| | | ScaleSplitTransport rec = data.get(city); |
| | | if (rec == null && above == null) continue; |
| | | if (rec == null) { |
| | | rec = new ScaleSplitTransport(); |
| | | rec.setRegionName(city); |
| | | data.put(city, rec); |
| | | } |
| | | applyH2032TurnoverAbove(rec, above, growthYoy(above, prior.get(city))); |
| | | } |
| | | } |
| | | |
| | | private void applyH2032ProvinceMonthTurnoverAbove(Map<Integer, ScaleSplitTransport> data, String period) { |
| | | int lastMonth = parseMonth(period); |
| | | Map<String, Map<Integer, Double>> current = loadH2032TurnoverByMonth(period); |
| | | Map<String, Map<Integer, Double>> prior = loadH2032TurnoverByMonth(previousYearPeriod(period)); |
| | | for (int m = 1; m <= lastMonth; m++) { |
| | | Double above = sumCitiesOfMonth(current, m); |
| | | ScaleSplitTransport rec = data.get(m); |
| | | if (rec == null && above == null) continue; |
| | | if (rec == null) { |
| | | rec = new ScaleSplitTransport(); |
| | | rec.setRegionName("湖北省"); |
| | | data.put(m, rec); |
| | | } |
| | | applyH2032TurnoverAbove(rec, above, growthYoy(above, sumCitiesOfMonth(prior, m))); |
| | | } |
| | | } |
| | | |
| | | private ScaleSplitTransport applyH2032ProvinceCumulativeTurnoverAbove(ScaleSplitTransport province, |
| | | String period) { |
| | | Map<String, Double> current = loadH2032TurnoverCumulative(period); |
| | | Map<String, Double> prior = loadH2032TurnoverCumulative(previousYearPeriod(period)); |
| | | Double above = sumCitiesOf(current); |
| | | if (province == null && above == null) return null; |
| | | if (province == null) { |
| | | province = new ScaleSplitTransport(); |
| | | province.setRegionName("湖北省"); |
| | | } |
| | | applyH2032TurnoverAbove(province, above, growthYoy(above, sumCitiesOf(prior))); |
| | | return province; |
| | | } |
| | | |
| | | private void applyH2032TurnoverAbove(ScaleSplitTransport rec, Double above, Double yoy) { |
| | | rec.setAboveScaleTurnover(above); |
| | | rec.setAboveScaleYoy(yoy); |
| | | Double total = rec.getTotalTurnover(); |
| | | rec.setBelowScaleTurnover(total == null || above == null ? null : total - above); |
| | | } |
| | | |
| | | private String previousYearPeriod(String period) { |
| | | return (Integer.parseInt(period.substring(0, 4)) - 1) + period.substring(4); |
| | | } |
| | | |
| | | private Double sumCitiesOf(Map<String, Double> values) { |
| | | Double sum = null; |
| | | for (String city : RegionUtil.cityList()) { |
| | | Double v = values.get(city); |
| | | if (v != null) sum = sum == null ? v : sum + v; |
| | | } |
| | | return sum; |
| | | } |
| | | |
| | | private Double sumCitiesOfMonth(Map<String, Map<Integer, Double>> values, int month) { |
| | | Double sum = null; |
| | | for (String city : RegionUtil.cityList()) { |
| | | Double v = monthValueOf(values, city, month); |
| | | if (v != null) sum = sum == null ? v : sum + v; |
| | | } |
| | | return sum; |
| | | } |
| | | |
| | | private Double monthValueOf(Map<String, Map<Integer, Double>> byMonth, String city, int month) { |
| | | Map<Integer, Double> buckets = byMonth.get(city); |
| | | return buckets == null ? null : buckets.get(month); |
| | | } |
| | | |
| | | /** H2032规上同比(需去年同期的H2032数据,暂无则为空) */ |
| | | private Map<String, Double> computeH2032Yoy(String period) { |
| | | Map<String, Double> result = new HashMap<>(); |