From fbc1c1590e7e81a550beb50c7cf65c663c7c5b41 Mon Sep 17 00:00:00 2001
From: zhizhijie <zhizhijie@users.noreply.gitee.com>
Date: 星期二, 01 九月 2026 16:42:06 +0800
Subject: [PATCH] 数据导入与报表生成多项改进
---
traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataImportController.java | 315 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 315 insertions(+), 0 deletions(-)
diff --git a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataImportController.java b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataImportController.java
index abd2716..18e657b 100644
--- a/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataImportController.java
+++ b/traffic-audit-server/src/main/java/com/trafficaudit/dataimport/controller/DataImportController.java
@@ -2,8 +2,12 @@
import com.trafficaudit.common.Result;
import com.trafficaudit.dataimport.dto.ImportResult;
+import com.trafficaudit.dataimport.entity.ImportBatch;
+import com.trafficaudit.dataimport.mapper.ImportBatchMapper;
import com.trafficaudit.dataimport.service.DataImportService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -11,6 +15,9 @@
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
@Slf4j
@RestController
@@ -19,6 +26,8 @@
@Resource
private DataImportService importService;
+ @Resource
+ private ImportBatchMapper importBatchMapper;
/** H203-2琛� 閬撹矾璐х墿杩愯緭鏈堝害鐢熶骇鎯呭喌 */
@PostMapping("/h2032")
@@ -50,6 +59,253 @@
}
+
+ /** H204 閬撹矾璐ц繍杞﹁締鑳芥簮娑堣�楁儏鍐碉紙瀛e害鑳借�楁槑缁� + 杩愭斂杞﹁締淇℃伅锛� */
+ @PostMapping("/energyMonthly")
+ public Result<String> importEnergyMonthly(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period) {
+ try {
+ ImportResult result = importService.importEnergyMonthly(file, period);
+ String msg = "H204鑳借�楀鎶ュ鍏ュ畬鎴愶細鎴愬姛 " + result.getSuccess() + " 鏉★紝澶辫触 " + result.getFail() + " 鏉★紙鍚悓鎶ヨ〃鏈熻繍鏀胯溅杈嗕俊鎭級";
+ if (result.getFail() > 0) {
+ java.util.List<String> details = result.getFailDetails();
+ int shown = Math.min(details.size(), 100);
+ for (int i = 0; i < shown; i++) {
+ msg += "\n" + details.get(i);
+ }
+ if (details.size() > shown) {
+ msg += "\n鈥︹�﹀叡 " + details.size() + " 琛屽け璐�";
+ }
+ }
+ return Result.ok(msg);
+ } catch (Exception e) {
+ log.error("energyMonthly import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 鑳借�楄溅杈嗚繍鏀夸俊鎭紙鐙珛妯℃澘锛屼篃鍙殢 H204 瀛f姤绗簩涓� sheet 涓�骞跺鍏ワ級 */
+ @PostMapping("/energyAuth")
+ public Result<String> importEnergyAuth(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period) {
+ try {
+ ImportResult result = importService.importEnergyAuth(file, period);
+ String msg = "鑳借�楄溅杈嗚繍鏀夸俊鎭鍏ュ畬鎴愶細鎴愬姛 " + result.getSuccess() + " 鏉★紝澶辫触 " + result.getFail() + " 鏉�";
+ if (result.getFail() > 0) {
+ java.util.List<String> details = result.getFailDetails();
+ int shown = Math.min(details.size(), 100);
+ for (int i = 0; i < shown; i++) {
+ msg += "\n" + details.get(i);
+ }
+ if (details.size() > shown) {
+ msg += "\n鈥︹�﹀叡 " + details.size() + " 琛屽け璐�";
+ }
+ }
+ return Result.ok(msg);
+ } catch (Exception e) {
+ log.error("energyAuth import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** H203-1琛� 鍏矾鏃呭杩愯緭鏈堝害鐢熶骇鎯呭喌锛堝惈杩愭斂杞﹁締鏁皊heet锛� */
+ @PostMapping("/passengerMonthly")
+ public Result<String> importPassengerMonthly(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period) {
+ try {
+ ImportResult result = importService.importPassengerMonthly(file, period);
+ String msg = "H2031鏃呭鏈堟姤瀵煎叆瀹屾垚锛氭垚鍔� " + result.getSuccess() + " 鏉★紝澶辫触 " + result.getFail() + " 鏉★紙鍚悓鎶ヨ〃鏈熻繍鏀胯溅杈嗘暟鎹級";
+ if (result.getFail() > 0) {
+ java.util.List<String> details = result.getFailDetails();
+ int shown = Math.min(details.size(), 100);
+ for (int i = 0; i < shown; i++) {
+ msg += "\n" + details.get(i);
+ }
+ if (details.size() > shown) {
+ msg += "\n鈥︹�﹀叡 " + details.size() + " 琛屽け璐�";
+ }
+ }
+ return Result.ok(msg);
+ } catch (Exception e) {
+ log.error("passengerMonthly import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+
+ /** 鍏矾鏃呭涓綋瀹㈣繍閲�/鍛ㄨ浆閲忥紙浼佷笟绾夸笅姹囨姤锛屽鍏ュ悗渚涘垎甯傚窞琛ㄤ釜浣撹濉厖锛� */
+ @PostMapping("/passengerIndividual")
+ public Result<String> importPassengerIndividual(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period) {
+ try {
+ ImportResult result = importService.importPassengerIndividual(file, period);
+ String msg = "涓綋瀹㈣繍閲忓鍏ュ畬鎴愶細鎴愬姛 " + result.getSuccess() + " 鏉★紝澶辫触 " + result.getFail() + " 鏉�";
+ if (result.getFail() > 0) {
+ java.util.List<String> details = result.getFailDetails();
+ int shown = Math.min(details.size(), 100);
+ for (int i = 0; i < shown; i++) {
+ msg += "\n" + details.get(i);
+ }
+ if (details.size() > shown) {
+ msg += "\n鈥︹�﹀叡 " + details.size() + " 琛屽け璐�";
+ }
+ }
+ return Result.ok(msg);
+ } catch (Exception e) {
+ log.error("passengerIndividual import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 鍏矾鏃呭杩愭斂杞﹁締鏁帮紙鐙珛妯℃澘锛屼篃鍙殢 H203-1 鏈堟姤绗簩涓� sheet 涓�骞跺鍏ワ級 */
+ @PostMapping("/passengerAuth")
+ public Result<String> importPassengerAuth(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period) {
+ try {
+ ImportResult result = importService.importPassengerAuth(file, period);
+ String msg = "鏃呭杩愭斂杞﹁締鏁板鍏ュ畬鎴愶細鎴愬姛 " + result.getSuccess() + " 鏉★紝澶辫触 " + result.getFail() + " 鏉�";
+ if (result.getFail() > 0) {
+ java.util.List<String> details = result.getFailDetails();
+ int shown = Math.min(details.size(), 100);
+ for (int i = 0; i < shown; i++) {
+ msg += "\n" + details.get(i);
+ }
+ if (details.size() > shown) {
+ msg += "\n鈥︹�﹀叡 " + details.size() + " 琛屽け璐�";
+ }
+ }
+ return Result.ok(msg);
+ } catch (Exception e) {
+ log.error("passengerAuth import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 鍩庡競鍏氦鏈堟姤锛堝煄甯傚叕鍏变氦閫氭湀搴﹁繍钀ユ儏鍐碉紝浼佷笟绾ф槑缁嗭級 */
+ @PostMapping("/cityBus")
+ public Result<String> importCityBus(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period) {
+ try {
+ ImportResult result = importService.importCityBus(file, period);
+ String msg = "鍩庡競鍏氦鏈堟姤瀵煎叆瀹屾垚锛氭垚鍔� " + result.getSuccess() + " 鏉★紝澶辫触 " + result.getFail() + " 鏉�";
+ if (result.getFail() > 0) {
+ java.util.List<String> details = result.getFailDetails();
+ int shown = Math.min(details.size(), 100);
+ for (int i = 0; i < shown; i++) {
+ msg += "\n" + details.get(i);
+ }
+ if (details.size() > shown) {
+ msg += "\n鈥︹�﹀叡 " + details.size() + " 琛屽け璐�";
+ }
+ }
+ return Result.ok(msg);
+ } catch (Exception e) {
+ log.error("cityBus import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 宸℃父鍑虹姹借溅杩愯惀鏈嶅姟鎯呭喌鏈堟姤锛堝競宸炵骇锛� */
+ @PostMapping("/cityTaxi")
+ public Result<String> importCityTaxi(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period) {
+ try {
+ ImportResult result = importService.importCityTaxi(file, period);
+ String msg = "宸℃父鍑虹鏈堟姤瀵煎叆瀹屾垚锛氭垚鍔� " + result.getSuccess() + " 鏉★紝澶辫触 " + result.getFail() + " 鏉�";
+ if (result.getFail() > 0) {
+ java.util.List<String> details = result.getFailDetails();
+ int shown = Math.min(details.size(), 100);
+ for (int i = 0; i < shown; i++) {
+ msg += "\n" + details.get(i);
+ }
+ if (details.size() > shown) {
+ msg += "\n鈥︹�﹀叡 " + details.size() + " 琛屽け璐�";
+ }
+ }
+ return Result.ok(msg);
+ } catch (Exception e) {
+ log.error("cityTaxi import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 鍑虹杞﹁繍鏀胯溅杈嗕俊鎭紙杞﹁締绾ф槑缁嗭紝鐢ㄤ簬杩愯惀杞︽暟瀵规瘮锛� */
+ @PostMapping("/cityTaxiAuth")
+ public Result<String> importCityTaxiAuth(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period) {
+ try {
+ int count = importService.importCityTaxiAuth(file, period);
+ return Result.ok("鍑虹杞﹁繍鏀胯溅杈嗗鍏ユ垚鍔�, 鍏� " + count + " 鏉¤褰�");
+ } catch (Exception e) {
+ log.error("cityTaxiAuth import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 鎶曡祫鏈堟姤锛堝叏鐪佹眹鎬诲ぇ琛級锛歝ategory=瀹㈣繍绔欏満/鐗╂祦鍥尯 */
+ @PostMapping("/investment")
+ public Result<String> importInvestment(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period,
+ @RequestParam(value = "category", defaultValue = "瀹㈣繍绔欏満") String category) {
+ try {
+ ImportResult result = importService.importInvestment(file, period, category);
+ String msg = "鎶曡祫鏈堟姤瀵煎叆瀹屾垚锛�" + category + "锛夛細鎴愬姛 " + result.getSuccess() + " 鏉★紝澶辫触 " + result.getFail() + " 鏉�";
+ if (result.getFail() > 0) {
+ java.util.List<String> details = result.getFailDetails();
+ int shown = Math.min(details.size(), 100);
+ for (int i = 0; i < shown; i++) {
+ msg += "\n" + details.get(i);
+ }
+ if (details.size() > shown) {
+ msg += "\n鈥︹�﹀叡 " + details.size() + " 琛屽け璐�";
+ }
+ }
+ return Result.ok(msg);
+ } catch (Exception e) {
+ log.error("investment import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 澶氭枃浠舵壒閲忓鍏ワ細鍓嶇涓�娆¢�夋嫨澶氫釜 Excel 涓婁紶锛坱ype 涓烘暟鎹被鍨嬶紝鎶曡祫绫诲瀷鎸夊競宸炲崟琛ㄨВ鏋愶級 */
+ @PostMapping("/batch")
+ public Result<Object> importBatch(@RequestParam("type") String type,
+ @RequestParam("period") String period,
+ @RequestParam("files") List<MultipartFile> files) {
+ try {
+ Map<String, Object> result = importService.importBatchFiles(type, period, files);
+ return Result.ok(result);
+ } catch (Exception e) {
+ log.error("batch import error", e);
+ return Result.error("鎵归噺瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 鎶曡祫甯傚窞鍗曡〃鎵归噺瀵煎叆锛圡2锛夛細鎵弿 docs/鎶曡祫/杈撳叆/{绫诲埆}/{X鏈坿 鐩綍鍏ㄩ儴甯傚窞鎶ヨ〃锛宑ategory=瀹㈣繍绔欏満/鐗╂祦鍥尯 */
+ @PostMapping("/investCityBatch")
+ public Result<Object> importInvestCityBatch(@RequestParam("period") String period,
+ @RequestParam(value = "category", defaultValue = "瀹㈣繍绔欏満") String category) {
+ try {
+ Map<String, Object> result = importService.importInvestCityDir(period, category);
+ return Result.ok(result);
+ } catch (Exception e) {
+ log.error("investCityBatch import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 鎶曡祫绯荤粺瀵煎嚭锛堝鏍告瘮瀵瑰熀鍑嗭級 */
+ @PostMapping("/investmentSystem")
+ public Result<String> importInvestmentSystem(@RequestParam("file") MultipartFile file,
+ @RequestParam("period") String period) {
+ try {
+ int count = importService.importInvestmentSystem(file, period);
+ return Result.ok("鎶曡祫绯荤粺瀵煎嚭瀵煎叆鎴愬姛, 鍏� " + count + " 鏉¤褰�");
+ } catch (Exception e) {
+ log.error("investmentSystem import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
/** 杩愭斂杞﹁締 */
@PostMapping("/transportAuth")
public Result<String> importTransportAuth(@RequestParam("file") MultipartFile file,
@@ -101,4 +357,63 @@
return Result.error("瀵煎叆澶辫触: " + e.getMessage());
}
}
+ /** 鐩綍娴忚鍣細path 涓虹┖杩斿洖椤圭洰 docs 鏁版嵁鐩綍锛岃繑鍥炲瓙鐩綍涓庡綋鍓嶇洰褰� Excel 鏂囦欢 */
+ @GetMapping("/dirs")
+ public Result<Map<String, Object>> dirs(@RequestParam(value = "path", required = false) String path) {
+ try {
+ Map<String, Object> result = importService.listDirs(path);
+ return Result.ok(result);
+ } catch (Exception e) {
+ log.error("list dirs error", e);
+ return Result.error("鐩綍娴忚澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 鎸夎矾寰勫鍏ュ崟涓� Excel 鏂囦欢锛堝墠绔�愭枃浠跺鍏ユ樉绀鸿繘搴︼級锛涙姤琛ㄦ湡浼樺厛浠庢枃浠跺悕璇嗗埆 */
+ @PostMapping("/fromDirFile")
+ public Result<Map<String, Object>> importFromDirFile(@RequestParam("type") String type,
+ @RequestParam(value = "period", required = false) String period,
+ @RequestParam(value = "skipImported", defaultValue = "true") boolean skipImported,
+ @RequestParam("path") String path) {
+ try {
+ Map<String, Object> result = importService.importDirFileByPath(type, period, skipImported, path);
+ return Result.ok(result);
+ } catch (Exception e) {
+ log.error("fromDirFile import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 浠庢湇鍔$鏂囦欢澶规壒閲忓鍏ワ細鎵弿 dir 涓嬪叏閮� .xlsx/.xls锛屾寜 type 閫愪釜瀵煎叆锛涙姤琛ㄦ湡浼樺厛浠庢枃浠跺悕璇嗗埆 */
+ @PostMapping("/fromDir")
+ public Result<Object> importFromDir(@RequestParam("type") String type,
+ @RequestParam(value = "period", required = false) String period,
+ @RequestParam(value = "skipImported", defaultValue = "true") boolean skipImported,
+ @RequestParam("dir") String dir) {
+ try {
+ Map<String, Object> result = importService.importFromDir(type, period, skipImported, dir);
+ return Result.ok(result);
+ } catch (Exception e) {
+ log.error("fromDir import error", e);
+ return Result.error("瀵煎叆澶辫触: " + e.getMessage());
+ }
+ }
+
+ /** 瀵煎叆鎵规鍘嗗彶锛堟暟鎹鍏ラ〉灞曠ず鏈�杩戝鍏ョ粨鏋滐級 */
+ @GetMapping("/batches")
+ public Result<Map<String, Object>> batches(@RequestParam(value = "type", required = false) String type,
+ @RequestParam(value = "period", required = false) String period,
+ @RequestParam(value = "limit", defaultValue = "20") int limit) {
+ int safeLimit = Math.min(Math.max(limit, 1), 200);
+ LambdaQueryWrapper<ImportBatch> w = new LambdaQueryWrapper<ImportBatch>()
+ .eq(type != null && !type.trim().isEmpty(), ImportBatch::getImportType, type)
+ .eq(period != null && !period.trim().isEmpty(), ImportBatch::getReportPeriod, period)
+ .orderByDesc(ImportBatch::getId)
+ .last("limit " + safeLimit);
+ List<ImportBatch> list = importBatchMapper.selectList(w);
+ Map<String, Object> result = new LinkedHashMap<>();
+ result.put("records", list);
+ return Result.ok(result);
+ }
+
}
--
Gitblit v1.9.1