diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java index 9a77bcc31f..6730fd1ba5 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/util/FilterChainUtils.java @@ -70,7 +70,8 @@ public class FilterChainUtils { // 获取插件中的图片 filterChainDefinitionMap.put("/plugin/image/**", "anon"); - filterChainDefinitionMap.put("/templates/user_import.xlsx", "anon"); + filterChainDefinitionMap.put("/templates/user_import_en.xlsx", "anon"); + filterChainDefinitionMap.put("/templates/user_import_cn.xlsx", "anon"); return filterChainDefinitionMap; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/excel/UserExcel.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/excel/UserExcel.java index d9a903f9bd..79cbd1a567 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/excel/UserExcel.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/excel/UserExcel.java @@ -10,16 +10,16 @@ import lombok.Data; public class UserExcel { @NotBlank(message = "{user.name.not_blank}") @Size(min = 1, max = 255, message = "{user.name.length_range}") - @ExcelProperty("name*") + @ExcelProperty(index = 0) private String name; @NotBlank(message = "{cannot_be_null}") @Size(min = 1, max = 64, message = "{user.email.length_range}") @Email(message = "{user.email.invalid}") - @ExcelProperty("email*") + @ExcelProperty(index = 1) private String email; - @ExcelProperty("phone") + @ExcelProperty(index = 2) private String phone; @ExcelProperty("workspace") diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java index faa5e18220..751d33727c 100644 --- a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/user/UserControllerTests.java @@ -560,7 +560,24 @@ public class UserControllerTests extends BaseTest { errorDataIndex = new int[]{}; UserParamUtils.checkImportResponse(response, importSuccessData, errorDataIndex); + + //导入中文文件 + importSuccessData = 19; + filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/user_import_cn_success.xls")).getPath(); + file = new MockMultipartFile("file", "userImportCn.xls", MediaType.APPLICATION_OCTET_STREAM_VALUE, UserParamUtils.getFileBytes(filePath)); + userImportReportDTOByFile = userService.getUserExcelParseDTO(file); + response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(UserRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class); + UserParamUtils.checkImportResponse(response, importSuccessData, errorDataIndex);//检查返回值 + userDTOList = this.checkImportUserInDb(userImportReportDTOByFile);//检查数据已入库 + for (UserDTO item : userDTOList) { + LOG_CHECK_LIST.add( + new CheckLogModel(item.getId(), OperationLogType.ADD, UserRequestUtils.URL_USER_IMPORT) + ); + } + + //文件内没有一条合格数据 应当导入成功的数据为0 + importSuccessData = 0; filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/user_import_error_all.xlsx")).getPath(); file = new MockMultipartFile("file", "userImport.xlsx", MediaType.APPLICATION_OCTET_STREAM_VALUE, UserParamUtils.getFileBytes(filePath)); response = userRequestUtils.parseObjectFromMvcResult(userRequestUtils.responseFile(UserRequestUtils.URL_USER_IMPORT, file), UserImportResponse.class); diff --git a/backend/services/system-setting/src/test/resources/file/user_import_cn_success.xls b/backend/services/system-setting/src/test/resources/file/user_import_cn_success.xls new file mode 100644 index 0000000000..854e08db07 Binary files /dev/null and b/backend/services/system-setting/src/test/resources/file/user_import_cn_success.xls differ