zhizhijie
2026-09-11 09e612af50beb200027317d6d4ccf7ad7092838e
traffic-audit-server/src/main/java/com/trafficaudit/reportexport/calc/WycSplitCalc.java
@@ -3,7 +3,9 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.trafficaudit.common.util.RegionUtil;
import com.trafficaudit.dataimport.entity.CityTaxiMonthly;
import com.trafficaudit.dataimport.entity.WycOrderMonthly;
import com.trafficaudit.dataimport.mapper.CityTaxiMonthlyMapper;
import com.trafficaudit.dataimport.mapper.WycOrderMonthlyMapper;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataFormatter;
@@ -76,6 +78,8 @@
    @Resource
    private CityTaxiMonthlyMapper cityTaxiMapper;
    @Resource
    private WycOrderMonthlyMapper wycOrderMapper;
    @Value("${city-passenger.template-dir:docs/城市客运}")
    private String templateDir;
@@ -190,6 +194,8 @@
    /** 读取 docs/城市客运/《网约车订单及全省总量.xlsx》:按 period(yyyy-MM) 行取 pin(B-E) 与 17 市州订单(G-W) */
    private Map<String, Object> loadMonthlyInput(String period) throws Exception {
        Map<String, Object> db = loadMonthlyInputFromDb(period);
        if (db != null) return db;
        File f = findInput();
        try (InputStream in = new FileInputStream(f);
             Workbook wb = WorkbookFactory.create(in)) {
@@ -226,6 +232,38 @@
        }
    }
    /** 优先从库取数(wyc_order_monthly);库里无该期或订单全空时返回 null,回退读母版文件 */
    private Map<String, Object> loadMonthlyInputFromDb(String period) {
        WycOrderMonthly row = wycOrderMapper.selectOne(new LambdaQueryWrapper<WycOrderMonthly>()
                .eq(WycOrderMonthly::getReportPeriod, period).last("LIMIT 1"));
        if (row == null) return null;
        List<String> cities = RegionUtil.cityList();
        Double[] vals = {
                row.getOrderWuhan(), row.getOrderHuangshi(), row.getOrderShiyan(), row.getOrderYichang(),
                row.getOrderXiangyang(), row.getOrderEzhou(), row.getOrderJingmen(), row.getOrderXiaogan(),
                row.getOrderJingzhou(), row.getOrderHuanggang(), row.getOrderXianning(), row.getOrderSuizhou(),
                row.getOrderEnshi(), row.getOrderXiantao(), row.getOrderQianjiang(), row.getOrderTianmen(),
                row.getOrderShennong()
        };
        double[] orders = new double[cities.size()];
        double sum = 0.0;
        for (int i = 0; i < orders.length && i < vals.length; i++) {
            orders[i] = vals[i] == null ? 0.0 : vals[i];
            sum += orders[i];
        }
        if (sum <= 0) return null;
        double orderSum = sum;
        if (row.getOrderSum() != null && row.getOrderSum() > 0) orderSum = row.getOrderSum();
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("pinK", row.getPinK() == null ? 0.0 : row.getPinK());
        map.put("pinCK", row.getPinCK() == null ? 0.0 : row.getPinCK());
        map.put("pinZ", row.getPinZ() == null ? 0.0 : row.getPinZ());
        map.put("pinCZ", row.getPinCZ() == null ? 0.0 : row.getPinCZ());
        map.put("orders", orders);
        map.put("orderSum", orderSum);
        map.put("source", "db");
        return map;
    }
    private File findInput() throws Exception {
        String rel = templateDir;
        while (rel.startsWith("./")) rel = rel.substring(2);