feat(credit): 支持指定工作表索引导入信用用户数据
- 添加 ExcelImportSupport.findSheetIndex 方法查找特定工作表 - 修改 tryImport 方法支持传入工作表索引参数 - 更新导入配置循环使用指定工作表索引 - 修改 readNameHyperlinks 方法使用正确的工作表索引读取超链接 - 设置 ImportParams 的起始工作表索引为动态获取的索引值
This commit is contained in:
@@ -154,13 +154,14 @@ public class CreditUserController extends BaseController {
|
||||
int successCount = 0;
|
||||
|
||||
try {
|
||||
int sheetIndex = ExcelImportSupport.findSheetIndex(file, "招投标", 0);
|
||||
List<CreditUserImportParam> list = null;
|
||||
int usedTitleRows = 0;
|
||||
int usedHeadRows = 0;
|
||||
int[][] tryConfigs = new int[][]{{1, 1}, {0, 1}, {0, 2}, {0, 3}};
|
||||
|
||||
for (int[] config : tryConfigs) {
|
||||
list = filterEmptyRows(tryImport(file, config[0], config[1]));
|
||||
list = filterEmptyRows(tryImport(file, config[0], config[1], sheetIndex));
|
||||
if (!CollectionUtils.isEmpty(list)) {
|
||||
usedTitleRows = config[0];
|
||||
usedHeadRows = config[1];
|
||||
@@ -174,7 +175,7 @@ public class CreditUserController extends BaseController {
|
||||
User loginUser = getLoginUser();
|
||||
Integer currentUserId = loginUser != null ? loginUser.getUserId() : null;
|
||||
Integer currentTenantId = loginUser != null ? loginUser.getTenantId() : null;
|
||||
Map<Integer, String> urlMap = readNameHyperlinks(file, 0, usedTitleRows, usedHeadRows);
|
||||
Map<Integer, String> urlMap = readNameHyperlinks(file, sheetIndex, usedTitleRows, usedHeadRows);
|
||||
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
CreditUserImportParam param = list.get(i);
|
||||
@@ -275,11 +276,11 @@ public class CreditUserController extends BaseController {
|
||||
workbook.close();
|
||||
}
|
||||
|
||||
private List<CreditUserImportParam> tryImport(MultipartFile file, int titleRows, int headRows) throws Exception {
|
||||
private List<CreditUserImportParam> tryImport(MultipartFile file, int titleRows, int headRows, int sheetIndex) throws Exception {
|
||||
ImportParams importParams = new ImportParams();
|
||||
importParams.setTitleRows(titleRows);
|
||||
importParams.setHeadRows(headRows);
|
||||
importParams.setStartSheetIndex(0);
|
||||
importParams.setStartSheetIndex(sheetIndex);
|
||||
importParams.setSheetNum(1);
|
||||
return ExcelImportUtil.importExcel(file.getInputStream(), CreditUserImportParam.class, importParams);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user