From c1d045b9b2186ccf23ed4c9b80b0ef4b52114363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Mon, 22 Dec 2025 17:33:00 +0800 Subject: [PATCH] =?UTF-8?q?feat(credit):=20=E5=AF=BC=E5=85=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E6=94=AF=E6=8C=81=E8=AF=BB=E5=8F=96=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=E8=B6=85=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 CreditUser 实体类中新增 url 字段用于存储项目网址 - 在导入逻辑中增加读取 Excel 超链接的功能 - 新增 readNameHyperlinks 方法解析“项目名称”列的超链接 - 将读取到的超链接地址设置到对应 CreditUser 实体的 url 属性中 - 引入 Apache POI 相关依赖以支持 Excel 文件操作 - 更新导入处理流程,确保超链接与数据行正确匹配 --- .../controller/CreditUserController.java | 53 +++++++++++++++++++ .../gxwebsoft/credit/entity/CreditUser.java | 4 ++ 2 files changed, 57 insertions(+) diff --git a/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java b/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java index 9dd458f..fb17240 100644 --- a/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java +++ b/src/main/java/com/gxwebsoft/credit/controller/CreditUserController.java @@ -17,7 +17,11 @@ import com.gxwebsoft.credit.param.CreditUserParam; import com.gxwebsoft.credit.service.CreditUserService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.ss.usermodel.WorkbookFactory; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; @@ -27,10 +31,13 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import java.io.IOException; +import java.io.InputStream; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * 招投标信息表控制器 @@ -166,12 +173,18 @@ public class CreditUserController extends BaseController { User loginUser = getLoginUser(); Integer currentUserId = loginUser != null ? loginUser.getUserId() : null; Integer currentTenantId = loginUser != null ? loginUser.getTenantId() : null; + Map urlMap = readNameHyperlinks(file, 0, usedTitleRows, usedHeadRows); for (int i = 0; i < list.size(); i++) { CreditUserImportParam param = list.get(i); try { CreditUser item = convertImportParamToEntity(param); + String link = urlMap.get(i); + if (link != null && !link.isEmpty()) { + item.setUrl(link); + } + // 设置默认值 if (item.getUserId() == null && currentUserId != null) { item.setUserId(currentUserId); @@ -267,6 +280,46 @@ public class CreditUserController extends BaseController { return ExcelImportUtil.importExcel(file.getInputStream(), CreditUserImportParam.class, importParams); } + /** + * 读取“项目名称”列的超链接,按数据行顺序返回。 + */ + private Map readNameHyperlinks(MultipartFile file, int sheetIndex, int titleRows, int headRows) throws Exception { + Map result = new HashMap<>(); + try (InputStream is = file.getInputStream(); Workbook workbook = WorkbookFactory.create(is)) { + Sheet sheet = workbook.getSheetAt(sheetIndex); + if (sheet == null) { + return result; + } + int headerRowNum = titleRows + headRows - 1; + Row headerRow = sheet.getRow(headerRowNum); + int nameColIndex = 0; + if (headerRow != null) { + for (int c = headerRow.getFirstCellNum(); c < headerRow.getLastCellNum(); c++) { + Cell cell = headerRow.getCell(c); + if (cell != null && "项目名称".equals(cell.getStringCellValue())) { + nameColIndex = c; + break; + } + } + } + int dataStartRow = titleRows + headRows; + for (int r = dataStartRow; r <= sheet.getLastRowNum(); r++) { + Row row = sheet.getRow(r); + if (row == null) { + continue; + } + Cell cell = row.getCell(nameColIndex); + if (cell != null && cell.getHyperlink() != null) { + String address = cell.getHyperlink().getAddress(); + if (address != null && !address.isEmpty()) { + result.put(r - dataStartRow, address); + } + } + } + } + return result; + } + /** * 过滤掉完全空白的导入行,避免空行导致导入失败 */ diff --git a/src/main/java/com/gxwebsoft/credit/entity/CreditUser.java b/src/main/java/com/gxwebsoft/credit/entity/CreditUser.java index a18d69b..a29db3a 100644 --- a/src/main/java/com/gxwebsoft/credit/entity/CreditUser.java +++ b/src/main/java/com/gxwebsoft/credit/entity/CreditUser.java @@ -1,6 +1,7 @@ package com.gxwebsoft.credit.entity; import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import java.time.LocalDateTime; import com.baomidou.mybatisplus.annotation.TableLogic; @@ -29,6 +30,9 @@ public class CreditUser implements Serializable { @Schema(description = "项目名称") private String name; + @Schema(description = "项目网址") + private String url; + @Schema(description = "唯一标识") private String code;