From 25b374a2864261095a5122f1583bd0102855fe8d Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Wed, 6 Dec 2023 15:09:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3=EF=BC=8C=E5=8E=BB=E6=8E=89?= =?UTF-8?q?=E6=97=A0=E7=94=A8=E7=9A=84=E8=A1=A8=E5=AD=97=E6=AE=B5=EF=BC=8C?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=96=87=E4=BB=B6=E8=BD=AC=E5=AD=98=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/system/domain/UserExtend.java | 8 - .../system/domain/UserExtendExample.java | 140 ------------------ .../system/mapper/UserExtendMapper.xml | 60 ++------ .../3.0.0/ddl/V3.0.0_11__system_setting.sql | 8 +- .../FunctionalCaseAttachmentController.java | 4 +- .../filemanagement/FileAssociationDTO.java | 39 +++++ .../service/FileAssociationService.java | 22 +-- .../project/service/FileMetadataService.java | 3 +- .../FileManagementControllerTests.java | 18 ++- .../controller/PersonalCenterController.java | 6 +- .../request/user/PersonalUpdateRequest.java | 3 + .../system/dto/user/PersonalDTO.java | 23 +++ .../metersphere/system/dto/user/UserDTO.java | 6 - .../mapper/ExtUserRoleRelationMapper.xml | 8 +- .../service/UserRoleRelationService.java | 44 ++++-- .../system/service/UserService.java | 33 ++++- .../main/resources/systemGeneratorConfig.xml | 66 ++++----- .../user/PersonalControllerTests.java | 25 ++++ .../controller/user/UserControllerTests.java | 10 ++ .../resources/dml/init_user_org_project.sql | 9 ++ 20 files changed, 252 insertions(+), 283 deletions(-) create mode 100644 backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/FileAssociationDTO.java create mode 100644 backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/PersonalDTO.java diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtend.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtend.java index d0135984f2..41153ba6f3 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtend.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtend.java @@ -15,12 +15,6 @@ public class UserExtend implements Serializable { @Size(min = 1, max = 50, message = "{user_extend.id.length_range}", groups = {Created.class, Updated.class}) private String id; - @Schema(description = "UI本地调试地址") - private String seleniumServer; - - @Schema(description = "api本地调试地址") - private String apiServer; - @Schema(description = "头像") private String avatar; @@ -31,8 +25,6 @@ public class UserExtend implements Serializable { public enum Column { id("id", "id", "VARCHAR", false), - seleniumServer("selenium_server", "seleniumServer", "VARCHAR", false), - apiServer("api_server", "apiServer", "VARCHAR", false), avatar("avatar", "avatar", "VARCHAR", false), platformInfo("platform_info", "platformInfo", "LONGVARBINARY", false); diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtendExample.java b/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtendExample.java index 6a140d8389..4dc338b69d 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtendExample.java +++ b/backend/framework/domain/src/main/java/io/metersphere/system/domain/UserExtendExample.java @@ -174,146 +174,6 @@ public class UserExtendExample { return (Criteria) this; } - public Criteria andSeleniumServerIsNull() { - addCriterion("selenium_server is null"); - return (Criteria) this; - } - - public Criteria andSeleniumServerIsNotNull() { - addCriterion("selenium_server is not null"); - return (Criteria) this; - } - - public Criteria andSeleniumServerEqualTo(String value) { - addCriterion("selenium_server =", value, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerNotEqualTo(String value) { - addCriterion("selenium_server <>", value, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerGreaterThan(String value) { - addCriterion("selenium_server >", value, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerGreaterThanOrEqualTo(String value) { - addCriterion("selenium_server >=", value, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerLessThan(String value) { - addCriterion("selenium_server <", value, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerLessThanOrEqualTo(String value) { - addCriterion("selenium_server <=", value, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerLike(String value) { - addCriterion("selenium_server like", value, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerNotLike(String value) { - addCriterion("selenium_server not like", value, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerIn(List values) { - addCriterion("selenium_server in", values, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerNotIn(List values) { - addCriterion("selenium_server not in", values, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerBetween(String value1, String value2) { - addCriterion("selenium_server between", value1, value2, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andSeleniumServerNotBetween(String value1, String value2) { - addCriterion("selenium_server not between", value1, value2, "seleniumServer"); - return (Criteria) this; - } - - public Criteria andApiServerIsNull() { - addCriterion("api_server is null"); - return (Criteria) this; - } - - public Criteria andApiServerIsNotNull() { - addCriterion("api_server is not null"); - return (Criteria) this; - } - - public Criteria andApiServerEqualTo(String value) { - addCriterion("api_server =", value, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerNotEqualTo(String value) { - addCriterion("api_server <>", value, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerGreaterThan(String value) { - addCriterion("api_server >", value, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerGreaterThanOrEqualTo(String value) { - addCriterion("api_server >=", value, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerLessThan(String value) { - addCriterion("api_server <", value, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerLessThanOrEqualTo(String value) { - addCriterion("api_server <=", value, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerLike(String value) { - addCriterion("api_server like", value, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerNotLike(String value) { - addCriterion("api_server not like", value, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerIn(List values) { - addCriterion("api_server in", values, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerNotIn(List values) { - addCriterion("api_server not in", values, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerBetween(String value1, String value2) { - addCriterion("api_server between", value1, value2, "apiServer"); - return (Criteria) this; - } - - public Criteria andApiServerNotBetween(String value1, String value2) { - addCriterion("api_server not between", value1, value2, "apiServer"); - return (Criteria) this; - } - public Criteria andAvatarIsNull() { addCriterion("avatar is null"); return (Criteria) this; diff --git a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/UserExtendMapper.xml b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/UserExtendMapper.xml index 979c191a0b..8aa80ecf88 100644 --- a/backend/framework/domain/src/main/java/io/metersphere/system/mapper/UserExtendMapper.xml +++ b/backend/framework/domain/src/main/java/io/metersphere/system/mapper/UserExtendMapper.xml @@ -3,8 +3,6 @@ - - @@ -69,7 +67,7 @@ - id, selenium_server, api_server, avatar + id, avatar platform_info @@ -123,10 +121,10 @@ - insert into user_extend (id, selenium_server, api_server, - avatar, platform_info) - values (#{id,jdbcType=VARCHAR}, #{seleniumServer,jdbcType=VARCHAR}, #{apiServer,jdbcType=VARCHAR}, - #{avatar,jdbcType=VARCHAR}, #{platformInfo,jdbcType=LONGVARBINARY}) + insert into user_extend (id, avatar, platform_info + ) + values (#{id,jdbcType=VARCHAR}, #{avatar,jdbcType=VARCHAR}, #{platformInfo,jdbcType=LONGVARBINARY} + ) insert into user_extend @@ -134,12 +132,6 @@ id, - - selenium_server, - - - api_server, - avatar, @@ -151,12 +143,6 @@ #{id,jdbcType=VARCHAR}, - - #{seleniumServer,jdbcType=VARCHAR}, - - - #{apiServer,jdbcType=VARCHAR}, - #{avatar,jdbcType=VARCHAR}, @@ -177,12 +163,6 @@ id = #{record.id,jdbcType=VARCHAR}, - - selenium_server = #{record.seleniumServer,jdbcType=VARCHAR}, - - - api_server = #{record.apiServer,jdbcType=VARCHAR}, - avatar = #{record.avatar,jdbcType=VARCHAR}, @@ -197,8 +177,6 @@ update user_extend set id = #{record.id,jdbcType=VARCHAR}, - selenium_server = #{record.seleniumServer,jdbcType=VARCHAR}, - api_server = #{record.apiServer,jdbcType=VARCHAR}, avatar = #{record.avatar,jdbcType=VARCHAR}, platform_info = #{record.platformInfo,jdbcType=LONGVARBINARY} @@ -208,8 +186,6 @@ update user_extend set id = #{record.id,jdbcType=VARCHAR}, - selenium_server = #{record.seleniumServer,jdbcType=VARCHAR}, - api_server = #{record.apiServer,jdbcType=VARCHAR}, avatar = #{record.avatar,jdbcType=VARCHAR} @@ -218,12 +194,6 @@ update user_extend - - selenium_server = #{seleniumServer,jdbcType=VARCHAR}, - - - api_server = #{apiServer,jdbcType=VARCHAR}, - avatar = #{avatar,jdbcType=VARCHAR}, @@ -235,26 +205,22 @@ update user_extend - set selenium_server = #{seleniumServer,jdbcType=VARCHAR}, - api_server = #{apiServer,jdbcType=VARCHAR}, - avatar = #{avatar,jdbcType=VARCHAR}, + set avatar = #{avatar,jdbcType=VARCHAR}, platform_info = #{platformInfo,jdbcType=LONGVARBINARY} where id = #{id,jdbcType=VARCHAR} update user_extend - set selenium_server = #{seleniumServer,jdbcType=VARCHAR}, - api_server = #{apiServer,jdbcType=VARCHAR}, - avatar = #{avatar,jdbcType=VARCHAR} + set avatar = #{avatar,jdbcType=VARCHAR} where id = #{id,jdbcType=VARCHAR} insert into user_extend - (id, selenium_server, api_server, avatar, platform_info) + (id, avatar, platform_info) values - (#{item.id,jdbcType=VARCHAR}, #{item.seleniumServer,jdbcType=VARCHAR}, #{item.apiServer,jdbcType=VARCHAR}, - #{item.avatar,jdbcType=VARCHAR}, #{item.platformInfo,jdbcType=LONGVARBINARY}) + (#{item.id,jdbcType=VARCHAR}, #{item.avatar,jdbcType=VARCHAR}, #{item.platformInfo,jdbcType=LONGVARBINARY} + ) @@ -270,12 +236,6 @@ #{item.id,jdbcType=VARCHAR} - - #{item.seleniumServer,jdbcType=VARCHAR} - - - #{item.apiServer,jdbcType=VARCHAR} - #{item.avatar,jdbcType=VARCHAR} diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql index e542f7208a..89d405eb16 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/ddl/V3.0.0_11__system_setting.sql @@ -321,11 +321,9 @@ CREATE INDEX idx_update_user ON organization(`update_user`); DROP TABLE IF EXISTS user_extend; CREATE TABLE user_extend ( - `id` VARCHAR(50) NOT NULL COMMENT '用户ID', - `platform_info` BLOB COMMENT '其他平台对接信息', - `selenium_server` VARCHAR(255) COMMENT 'UI本地调试地址', - `api_server` VARCHAR(255) COMMENT 'api本地调试地址', - `avatar` VARCHAR(255) COMMENT '头像', + `id` VARCHAR(50) NOT NULL COMMENT '用户ID', + `platform_info` BLOB COMMENT '其他平台对接信息', + `avatar` VARCHAR(255) COMMENT '头像', PRIMARY KEY (id) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseAttachmentController.java b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseAttachmentController.java index 64607c24c9..dc14bb9551 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseAttachmentController.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/controller/FunctionalCaseAttachmentController.java @@ -5,6 +5,7 @@ import io.metersphere.functional.request.FunctionalCaseAssociationFileRequest; import io.metersphere.functional.request.FunctionalCaseDeleteFileRequest; import io.metersphere.functional.request.FunctionalCaseFileRequest; import io.metersphere.functional.service.FunctionalCaseAttachmentService; +import io.metersphere.project.dto.filemanagement.FileAssociationDTO; import io.metersphere.project.dto.filemanagement.FileLogRecord; import io.metersphere.project.dto.filemanagement.request.FileMetadataTableRequest; import io.metersphere.project.dto.filemanagement.response.FileInformationResponse; @@ -118,7 +119,8 @@ public class FunctionalCaseAttachmentController { String fileId = null; try { - fileId = fileAssociationService.transferAndAssociation(attachment.getFileName(), fileByte, attachment.getCaseId(), FileAssociationSourceUtil.SOURCE_TYPE_FUNCTIONAL_CASE, fileLogRecord); + FileAssociationDTO fileAssociationDTO = new FileAssociationDTO(attachment.getFileName(), fileByte, attachment.getCaseId(), FileAssociationSourceUtil.SOURCE_TYPE_FUNCTIONAL_CASE, fileLogRecord); + fileId = fileAssociationService.transferAndAssociation(fileAssociationDTO); functionalCaseAttachmentService.deleteCaseAttachment(Arrays.asList(request.getFileId()), request.getCaseId(), request.getProjectId()); } catch (Exception e) { throw new MSException(Translator.get("file.transfer.error")); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/FileAssociationDTO.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/FileAssociationDTO.java new file mode 100644 index 0000000000..f8906ab0d7 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/filemanagement/FileAssociationDTO.java @@ -0,0 +1,39 @@ +package io.metersphere.project.dto.filemanagement; + +import io.metersphere.sdk.constants.ModuleConstants; +import jakarta.validation.constraints.NotBlank; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 文件转存 + */ +@Data +@NoArgsConstructor +@AllArgsConstructor +public class FileAssociationDTO { + @NotBlank + private String fileName; + + @NotBlank + private String sourceId; + + @NotBlank + private String sourceType; + + @NotBlank + private String moduleId = ModuleConstants.NODE_TYPE_DEFAULT; + + private byte[] fileBytes; + + private FileLogRecord fileLogRecord; + + public FileAssociationDTO(String fileName, byte[] fileBytes, String sourceId, String sourceType, FileLogRecord fileLogRecord) { + this.fileName = fileName; + this.sourceId = sourceId; + this.sourceType = sourceType; + this.fileBytes = fileBytes; + this.fileLogRecord = fileLogRecord; + } +} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileAssociationService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileAssociationService.java index 15149a71d6..4e6010154f 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileAssociationService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileAssociationService.java @@ -3,6 +3,7 @@ package io.metersphere.project.service; import io.metersphere.project.domain.FileAssociation; import io.metersphere.project.domain.FileAssociationExample; import io.metersphere.project.domain.FileMetadata; +import io.metersphere.project.dto.filemanagement.FileAssociationDTO; import io.metersphere.project.dto.filemanagement.FileAssociationSource; import io.metersphere.project.dto.filemanagement.FileInfo; import io.metersphere.project.dto.filemanagement.FileLogRecord; @@ -307,22 +308,22 @@ public class FileAssociationService { /** * 转存并关联文件 - * @param fileName 文件名称(含后缀) - * @param fileBytes 文件字节流 - * @param sourceId 要关联的资源ID - * @param sourceType 要关联的资源名称 - * @param fileLogRecord 日志记录相关 * @return * @throws Exception */ - public String transferAndAssociation(String fileName,byte[] fileBytes,String sourceId,String sourceType, @Validated FileLogRecord fileLogRecord) throws Exception { - FileAssociationSource source = extFileAssociationMapper.selectNameBySourceTableAndId(FileAssociationSourceUtil.getQuerySql(sourceType),sourceId); + public String transferAndAssociation(@Validated FileAssociationDTO fileAssociationDTO) throws Exception { + FileAssociationSource source = extFileAssociationMapper.selectNameBySourceTableAndId(FileAssociationSourceUtil.getQuerySql(fileAssociationDTO.getSourceType()), fileAssociationDTO.getSourceId()); this.validateSourceName(source); - String fileId = fileMetadataService.transferFile(fileName, fileLogRecord.getProjectId(), fileLogRecord.getOperator(),fileBytes); + String fileId = fileMetadataService.transferFile( + fileAssociationDTO.getFileName(), + fileAssociationDTO.getFileLogRecord().getProjectId(), + fileAssociationDTO.getModuleId(), + fileAssociationDTO.getFileLogRecord().getOperator(), + fileAssociationDTO.getFileBytes()); List accociationList = new ArrayList<>(); accociationList.add(fileId); - this.association(sourceId, sourceType, accociationList, fileLogRecord); - fileAssociationLogService.saveTransferAssociationLog(sourceId,fileName,source.getSourceName(),fileLogRecord); + this.association(fileAssociationDTO.getSourceId(), fileAssociationDTO.getSourceType(), accociationList, fileAssociationDTO.getFileLogRecord()); + fileAssociationLogService.saveTransferAssociationLog(fileAssociationDTO.getSourceId(), fileAssociationDTO.getFileName(), source.getSourceName(), fileAssociationDTO.getFileLogRecord()); return fileId; } @@ -332,7 +333,6 @@ public class FileAssociationService { } } - /** * 获取文件列表接口 * diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java index 3611bf9b81..85197aa2d8 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/FileMetadataService.java @@ -214,12 +214,11 @@ public class FileMetadataService { * @return * @throws Exception */ - public String transferFile(String fileName, String projectId, String operator, byte[] fileBytes) throws Exception { + public String transferFile(String fileName, String projectId, String moduleId, String operator, byte[] fileBytes) throws Exception { if (StringUtils.isBlank(fileName)) { throw new MSException(Translator.get("file.name.cannot.be.empty")); } fileName = this.genTransferFileName(StringUtils.trim(fileName), projectId); - String moduleId = ModuleConstants.NODE_TYPE_DEFAULT; FileMetadata fileMetadata = this.genFileMetadata(fileName, StorageType.MINIO.name(), fileBytes.length, false, projectId, moduleId, operator); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java index e85119147b..c13d771c19 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/filemanagement/FileManagementControllerTests.java @@ -1,6 +1,7 @@ package io.metersphere.project.controller.filemanagement; import io.metersphere.project.domain.*; +import io.metersphere.project.dto.filemanagement.FileAssociationDTO; import io.metersphere.project.dto.filemanagement.FileLogRecord; import io.metersphere.project.dto.filemanagement.request.*; import io.metersphere.project.dto.filemanagement.response.FileAssociationResponse; @@ -15,7 +16,10 @@ import io.metersphere.project.service.FileService; import io.metersphere.project.utils.FileManagementBaseUtils; import io.metersphere.project.utils.FileManagementRequestUtils; import io.metersphere.project.utils.FileMetadataUtils; -import io.metersphere.sdk.constants.*; +import io.metersphere.sdk.constants.ModuleConstants; +import io.metersphere.sdk.constants.PermissionConstants; +import io.metersphere.sdk.constants.SessionConstants; +import io.metersphere.sdk.constants.StorageType; import io.metersphere.sdk.util.FileAssociationSourceUtil; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.TempFileUtils; @@ -1591,31 +1595,31 @@ public class FileManagementControllerTests extends BaseTest { .build(); //关联正常文件 String filePath = Objects.requireNonNull(this.getClass().getClassLoader().getResource("file/file_upload.JPG")).getPath(); - String fileID = fileAssociationService.transferAndAssociation("testTransferFile.jpg", TempFileUtils.getFile(filePath), "sty-file-association-bug-id-4", FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord); + String fileID = fileAssociationService.transferAndAssociation(new FileAssociationDTO("testTransferFile.jpg", TempFileUtils.getFile(filePath), "sty-file-association-bug-id-4", FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord)); FileMetadataExample example = new FileMetadataExample(); example.createCriteria().andIdEqualTo(fileID).andNameEqualTo("testTransferFile").andTypeEqualTo("JPG"); Assertions.assertEquals(fileMetadataMapper.countByExample(example), 1); //重复转存检查文件名是否加1 - fileID = fileAssociationService.transferAndAssociation("testTransferFile.jpg", TempFileUtils.getFile(filePath), "sty-file-association-bug-id-4", FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord); + fileID = fileAssociationService.transferAndAssociation(new FileAssociationDTO("testTransferFile.jpg", TempFileUtils.getFile(filePath), "sty-file-association-bug-id-4", FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord)); example.clear(); example.createCriteria().andIdEqualTo(fileID).andNameEqualTo("testTransferFile(1)").andTypeEqualTo("JPG"); Assertions.assertEquals(fileMetadataMapper.countByExample(example), 1); //重复转存检查文件名是否加1 - fileID = fileAssociationService.transferAndAssociation("testTransferFile.jpg", TempFileUtils.getFile(filePath), "sty-file-association-bug-id-4", FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord); + fileID = fileAssociationService.transferAndAssociation(new FileAssociationDTO("testTransferFile.jpg", TempFileUtils.getFile(filePath), "sty-file-association-bug-id-4", FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord)); example.clear(); example.createCriteria().andIdEqualTo(fileID).andNameEqualTo("testTransferFile(2)").andTypeEqualTo("JPG"); Assertions.assertEquals(fileMetadataMapper.countByExample(example), 1); //测试没有后缀的文件名 - fileID = fileAssociationService.transferAndAssociation("testTransfer", TempFileUtils.getFile(filePath), "sty-file-association-bug-id-4", FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord); + fileID = fileAssociationService.transferAndAssociation(new FileAssociationDTO("testTransfer", TempFileUtils.getFile(filePath), "sty-file-association-bug-id-4", FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord)); example.clear(); example.createCriteria().andIdEqualTo(fileID).andNameEqualTo("testTransfer"); Assertions.assertEquals(fileMetadataMapper.countByExample(example), 1); //资源不存在 boolean error = false; try { - fileAssociationService.transferAndAssociation("testTransferFile.jpg", TempFileUtils.getFile(filePath), IDGenerator.nextStr(), FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord); + fileAssociationService.transferAndAssociation(new FileAssociationDTO("testTransferFile.jpg", TempFileUtils.getFile(filePath), IDGenerator.nextStr(), FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord)); } catch (Exception e) { error = true; } @@ -1623,7 +1627,7 @@ public class FileManagementControllerTests extends BaseTest { //文件名称不合法 error = false; try { - fileAssociationService.transferAndAssociation("testTransfer/File.jpg", TempFileUtils.getFile(filePath), IDGenerator.nextStr(), FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord); + fileAssociationService.transferAndAssociation(new FileAssociationDTO("testTransfer/File.jpg", TempFileUtils.getFile(filePath), IDGenerator.nextStr(), FileAssociationSourceUtil.SOURCE_TYPE_BUG, fileLogRecord)); } catch (Exception e) { error = true; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/PersonalCenterController.java b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/PersonalCenterController.java index 89eecde11b..c1002b53a0 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/controller/PersonalCenterController.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/controller/PersonalCenterController.java @@ -4,7 +4,7 @@ import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.exception.MSException; import io.metersphere.system.dto.request.user.PersonalUpdatePasswordRequest; import io.metersphere.system.dto.request.user.PersonalUpdateRequest; -import io.metersphere.system.dto.user.UserDTO; +import io.metersphere.system.dto.user.PersonalDTO; import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.service.UserLogService; @@ -29,9 +29,9 @@ public class PersonalCenterController { @GetMapping("/get/{id}") @Operation(summary = "个人中心-获取信息") @RequiresPermissions(PermissionConstants.SYSTEM_PERSONAL_READ) - public UserDTO getInformation(@PathVariable String id) { + public PersonalDTO getInformation(@PathVariable String id) { this.checkPermission(id); - return userService.getUserDTOByKeyword(id); + return userService.getPersonalById(id); } @PostMapping("/update-info") diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdateRequest.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdateRequest.java index 04c6a18293..124b1e514d 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdateRequest.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/request/user/PersonalUpdateRequest.java @@ -13,6 +13,9 @@ public class PersonalUpdateRequest { @NotBlank(message = "{user.id.not_blank}") private String id; + @Schema(description = "头像", requiredMode = Schema.RequiredMode.REQUIRED) + private String avatar; + @Schema(description = "用户名", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{user.id.not_blank}") private String username; diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/PersonalDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/PersonalDTO.java new file mode 100644 index 0000000000..da14d11b3b --- /dev/null +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/PersonalDTO.java @@ -0,0 +1,23 @@ +package io.metersphere.system.dto.user; + +import io.metersphere.project.domain.Project; +import io.metersphere.system.domain.Organization; +import io.metersphere.system.domain.User; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +@Data +@EqualsAndHashCode(callSuper = false) +public class PersonalDTO extends User { + + @Schema(description = "头像") + private String avatar; + + @Schema(description = "用户所属组织和项目") + private Map> organizationProjectMap = new LinkedHashMap<>(); +} diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/UserDTO.java b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/UserDTO.java index cc1f84613f..06aaa39c1b 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/UserDTO.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/dto/user/UserDTO.java @@ -21,12 +21,6 @@ public class UserDTO extends User { @Schema(description = "其他平台对接信息", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private byte[] platformInfo; - @Schema(description = "UI本地调试地址") - private String seleniumServer; - - @Schema(description = "API本地调试地址") - private String apiServer; - @Schema(description = "头像") private String avatar; } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.xml b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.xml index 9c35ad2784..0a282a3bed 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.xml +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/mapper/ExtUserRoleRelationMapper.xml @@ -6,9 +6,13 @@ SELECT * FROM user_role_relation WHERE - - user_id = #{userId} + user_id IN + + #{item} + + + AND role_id IN ( SELECT id FROM user_role WHERE scope_id = 'global' ) diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java index 1e3c90fb0d..fe1adf3b58 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserRoleRelationService.java @@ -1,20 +1,22 @@ package io.metersphere.system.service; +import io.metersphere.project.domain.Project; +import io.metersphere.project.mapper.ProjectMapper; import io.metersphere.sdk.constants.OperationLogConstants; import io.metersphere.sdk.constants.UserRoleEnum; import io.metersphere.sdk.constants.UserRoleScope; -import io.metersphere.system.log.dto.LogDTO; -import io.metersphere.system.log.constants.OperationLogModule; -import io.metersphere.system.log.constants.OperationLogType; -import io.metersphere.system.log.service.OperationLogService; -import io.metersphere.system.uid.IDGenerator; import io.metersphere.sdk.util.JSON; import io.metersphere.system.domain.*; +import io.metersphere.system.dto.response.UserTableResponse; +import io.metersphere.system.log.constants.OperationLogModule; +import io.metersphere.system.log.constants.OperationLogType; +import io.metersphere.system.log.dto.LogDTO; +import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.mapper.ExtUserRoleRelationMapper; import io.metersphere.system.mapper.OrganizationMapper; import io.metersphere.system.mapper.UserRoleMapper; import io.metersphere.system.mapper.UserRoleRelationMapper; -import io.metersphere.system.dto.response.UserTableResponse; +import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import jakarta.validation.Valid; import jakarta.validation.constraints.NotEmpty; @@ -27,10 +29,7 @@ import org.mybatis.spring.SqlSessionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Service @@ -48,6 +47,8 @@ public class UserRoleRelationService { private OrganizationMapper organizationMapper; @Resource private OperationLogService operationLogService; + @Resource + private ProjectMapper projectMapper; //批量添加用户记录日志 public List getBatchLogs(@Valid @NotEmpty List userRoleId, @@ -129,6 +130,29 @@ public class UserRoleRelationService { userRoleRelationMapper.batchInsert(userRoleRelationSaveList); } + public Map> selectOrganizationProjectByUserId(String userId) { + Map> returnMap = new LinkedHashMap<>(); + UserRoleRelationExample example = new UserRoleRelationExample(); + example.createCriteria().andUserIdEqualTo(userId); + List userRoleRelationList = userRoleRelationMapper.selectByExample(example); + for (UserRoleRelation userRoleRelation : userRoleRelationList) { + Organization organization = organizationMapper.selectByPrimaryKey(userRoleRelation.getOrganizationId()); + if (organization != null) { + Project project = projectMapper.selectByPrimaryKey(userRoleRelation.getSourceId()); + if (project != null) { + if (returnMap.containsKey(organization)) { + if (!returnMap.get(organization).contains(project)) { + returnMap.get(organization).add(project); + } + } else { + returnMap.put(organization, new ArrayList<>(Arrays.asList(project))); + } + } + } + } + return returnMap; + } + public Map selectGlobalUserRoleAndOrganization(@Valid @NotEmpty List userIdList) { List userRoleRelationList = extUserRoleRelationMapper.selectGlobalRoleByUserIdList(userIdList); List userRoleIdList = userRoleRelationList.stream().map(UserRoleRelation::getRoleId).distinct().collect(Collectors.toList()); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java index 61551c7e86..fca2d70da2 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/UserService.java @@ -24,13 +24,11 @@ import io.metersphere.system.dto.sdk.ExcelParseDTO; import io.metersphere.system.dto.sdk.SessionUser; import io.metersphere.system.dto.table.TableBatchProcessDTO; import io.metersphere.system.dto.table.TableBatchProcessResponse; +import io.metersphere.system.dto.user.PersonalDTO; import io.metersphere.system.dto.user.UserDTO; import io.metersphere.system.dto.user.UserExtendDTO; import io.metersphere.system.log.service.OperationLogService; -import io.metersphere.system.mapper.BaseUserMapper; -import io.metersphere.system.mapper.ExtUserMapper; -import io.metersphere.system.mapper.SystemParameterMapper; -import io.metersphere.system.mapper.UserMapper; +import io.metersphere.system.mapper.*; import io.metersphere.system.notice.sender.impl.MailNoticeSender; import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.utils.UserImportEventListener; @@ -67,6 +65,8 @@ public class UserService { @Resource private UserMapper userMapper; @Resource + private UserExtendMapper userExtendMapper; + @Resource private ExtUserMapper extUserMapper; @Resource private UserInviteService userInviteService; @@ -140,7 +140,6 @@ public class UserService { return userCreateDTO; } - public UserDTO getUserDTOByKeyword(String email) { UserDTO userDTO = baseUserMapper.selectDTOByKeyword(email); if (userDTO != null) { @@ -154,6 +153,16 @@ public class UserService { return userDTO; } + public PersonalDTO getPersonalById(String id) { + UserDTO userDTO = baseUserMapper.selectDTOByKeyword(id); + PersonalDTO personalDTO = new PersonalDTO(); + if (userDTO != null) { + BeanUtils.copyBean(personalDTO, userDTO); + personalDTO.setOrganizationProjectMap(userRoleRelationService.selectOrganizationProjectByUserId(userDTO.getId())); + } + return personalDTO; + } + public List list(BasePageRequest request) { List returnList = new ArrayList<>(); List userList = baseUserMapper.selectByKeyword(request.getKeyword(), false); @@ -524,6 +533,20 @@ public class UserService { editUser.setEmail(request.getEmail()); editUser.setUpdateUser(operator); editUser.setUpdateTime(System.currentTimeMillis()); + + if (StringUtils.isNotEmpty(request.getAvatar())) { + UserExtend userExtend = userExtendMapper.selectByPrimaryKey(request.getId()); + if (userExtend == null) { + userExtend = new UserExtend(); + userExtend.setId(request.getId()); + userExtend.setAvatar(request.getAvatar()); + userExtendMapper.insert(userExtend); + } else { + userExtend.setAvatar(request.getAvatar()); + userExtendMapper.updateByPrimaryKey(userExtend); + } + } + return userMapper.updateByPrimaryKeySelective(editUser) > 0; } diff --git a/backend/services/system-setting/src/main/resources/systemGeneratorConfig.xml b/backend/services/system-setting/src/main/resources/systemGeneratorConfig.xml index 9b84580616..e9e0b06876 100644 --- a/backend/services/system-setting/src/main/resources/systemGeneratorConfig.xml +++ b/backend/services/system-setting/src/main/resources/systemGeneratorConfig.xml @@ -69,40 +69,40 @@ - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ + + + + + + + + + + + + + + + + + + + + + + + -
-
-
-
-
-
-
-
-
+ + + + + + + + +