traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataViewController.java
@@ -24,6 +24,8 @@
import com.trafficaudit.dataimport.entity.WycTotalMonthly;
import com.trafficaudit.common.util.RegionUtil;
import com.trafficaudit.reportexport.calc.WycSplitCalc;
import com.trafficaudit.dataimport.service.CityRollupService;
import javax.servlet.http.HttpServletResponse;
import com.trafficaudit.dataimport.mapper.FreightTurnoverImportMapper;
import com.trafficaudit.dataimport.mapper.H2032EnterpriseMonthlyMapper;
import com.trafficaudit.dataimport.mapper.PassengerAuthVehicleMapper;
@@ -100,6 +102,8 @@
    private WycTotalMonthlyMapper wycTotalMapper;
    @Resource
    private WycSplitCalc wycSplitCalc;
    @Resource
    private CityRollupService cityRollupService;
    @GetMapping("/list")
    public Result<Map<String, Object>> list(@RequestParam("type") String type,
@@ -451,6 +455,39 @@
        return rows;
    }
    /** 支持按市州汇总的数据类型 */
    @GetMapping("/rollupTypes")
    public Result<List<Map<String, Object>>> rollupTypes() {
        return Result.ok(cityRollupService.supportedTypes());
    }
    /** 按市州汇总(任意起止月) */
    @GetMapping("/summary")
    public Result<Map<String, Object>> summary(@RequestParam("type") String type,
                                               @RequestParam("from") String from,
                                               @RequestParam("to") String to,
                                               @RequestParam(value = "rankMode", defaultValue = "blank") String rankMode) {
        return Result.ok(cityRollupService.summary(type, from, to, "recompute".equalsIgnoreCase(rankMode)));
    }
    /** 按市州汇总导出 Excel(数值全精度,显示 2 位小数 / 百分比) */
    @GetMapping("/export")
    public void export(@RequestParam("type") String type,
                       @RequestParam("from") String from,
                       @RequestParam("to") String to,
                       @RequestParam(value = "rankMode", defaultValue = "blank") String rankMode,
                       HttpServletResponse response) throws Exception {
        byte[] bytes = cityRollupService.exportExcel(type, from, to, "recompute".equalsIgnoreCase(rankMode));
        String fileName = "按市州汇总_" + type + "_" + from + "_" + to + ".xlsx";
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("UTF-8");
        response.setHeader("Content-Disposition",
                "attachment; filename=\"" + java.net.URLEncoder.encode(fileName, "UTF-8") + "\"");
        response.setContentLength(bytes.length);
        response.getOutputStream().write(bytes);
        response.getOutputStream().flush();
    }
    private boolean notEmpty(String s) {
        return s != null && !s.trim().isEmpty();
    }