|
|
@@ -1,7 +1,5 @@
|
|
|
package com.siwei.apply.controller.third;
|
|
|
|
|
|
-import com.siwei.apply.domain.LandOneCode;
|
|
|
-import com.siwei.apply.service.third.TakeDataService;
|
|
|
import com.siwei.common.core.domain.R;
|
|
|
import com.siwei.common.core.web.controller.BaseController;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
@@ -29,34 +27,6 @@ import java.util.*;
|
|
|
public class DealExcelController extends BaseController {
|
|
|
protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
- private final TakeDataService takeDataService;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 按ID查询
|
|
|
- */
|
|
|
- @GetMapping("{id}")
|
|
|
- public R<LandOneCode> getById(@PathVariable String id) {
|
|
|
- try {
|
|
|
- return R.ok();
|
|
|
- } catch (Exception e) {
|
|
|
- return R.fail(e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 更新(按ID)
|
|
|
- */
|
|
|
- @PutMapping("zzz")
|
|
|
- public R<Void> update(@RequestBody LandOneCode body) {
|
|
|
- try {
|
|
|
- return R.ok(null);
|
|
|
- } catch (Exception e) {
|
|
|
- return R.fail(e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 处理excel数据(按合并列头分组读取)
|
|
|
@@ -64,7 +34,7 @@ public class DealExcelController extends BaseController {
|
|
|
@GetMapping("excelDeal_v2")
|
|
|
public R<Map<String, List<Map<String,String>>>> excelDeal_v2() {
|
|
|
try {
|
|
|
- String uploadFile = "D:\\workspace\\one-code-manage\\node_modules\\excel_deom\\project_info_v2.xlsx";
|
|
|
+ String uploadFile = "D:\\workspace\\one-code-manage\\node_modules\\excel_deom\\project_info_v4.xlsx";
|
|
|
Path filePath = Paths.get(uploadFile);
|
|
|
File file = filePath.toFile();
|
|
|
Map<String, List<Map<String, String>>> dataMap = readExcelWithMergedHeaders(file);
|
|
|
@@ -82,63 +52,9 @@ public class DealExcelController extends BaseController {
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 处理excel数据
|
|
|
- */
|
|
|
- @GetMapping("excelDeal")
|
|
|
- public R<List<Map<String, Object>>> excelDeal() {
|
|
|
- try {
|
|
|
- // 获取地址:
|
|
|
- String uploadFile = "D:\\workspace\\one-code-manage\\node_modules\\excel_deom\\project_info_v2.xlsx";
|
|
|
- // 构建文件的完整路径
|
|
|
- Path filePath = Paths.get(uploadFile);
|
|
|
- File file = filePath.toFile();
|
|
|
- List<Map<String, Object>> dataList = readExcel(file);
|
|
|
- for (int i = 0; i < dataList.size(); i++) {
|
|
|
- logger.info("第{}行数据: {}", i + 1, dataList.get(i));
|
|
|
- }
|
|
|
- return R.ok(dataList);
|
|
|
- } catch (Exception e) {
|
|
|
- return R.fail(e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
- private List<Map<String, Object>> readExcel(File file) throws Exception {
|
|
|
- List<Map<String, Object>> result = new ArrayList<>();
|
|
|
- try (FileInputStream fis = new FileInputStream(file);
|
|
|
- Workbook workbook = new XSSFWorkbook(fis)) {
|
|
|
- Sheet sheet = workbook.getSheetAt(0);
|
|
|
- if (sheet == null) {
|
|
|
- return result;
|
|
|
- }
|
|
|
- Row headerRow = sheet.getRow(0);
|
|
|
- if (headerRow == null) {
|
|
|
- return result;
|
|
|
- }
|
|
|
- List<String> headers = new ArrayList<>();
|
|
|
- for (int i = 0; i < headerRow.getPhysicalNumberOfCells(); i++) {
|
|
|
- Cell cell = headerRow.getCell(i);
|
|
|
- headers.add(cell == null ? "" : getCellValueAsString(cell));
|
|
|
- }
|
|
|
- for (int i = 1; i <= sheet.getLastRowNum(); i++) {
|
|
|
- Row row = sheet.getRow(i);
|
|
|
- if (row == null) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- Map<String, Object> rowData = new LinkedHashMap<>();
|
|
|
- for (int j = 0; j < headers.size(); j++) {
|
|
|
- Cell cell = row.getCell(j);
|
|
|
- rowData.put(headers.get(j), cell == null ? "" : getCellValueAsString(cell));
|
|
|
- }
|
|
|
- result.add(rowData);
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 按合并列头分组读取Excel
|
|
|
* 第一行合并单元格作为分类key,第二行作为子列头,第三行起为数据
|