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;