From 06c03d5982a5b8c73a64ddc7bfe85dee62c75153 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Mon, 4 Mar 2024 14:01:56 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E8=B6=85=E7=BA=A7=E7=AE=A1=E7=90=86=E5=91=98=E7=9A=84=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=88=97=E8=A1=A8=E8=BF=9B=E8=A1=8C=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BaseProjectController.java | 4 ++-- .../service/BaseProjectService.java | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/controller/BaseProjectController.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/controller/BaseProjectController.java index 7d42e41742..326366e1e5 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/controller/BaseProjectController.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/controller/BaseProjectController.java @@ -10,11 +10,11 @@ import io.metersphere.dto.ProjectDTO; import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.request.ProjectRequest; import io.metersphere.service.BaseProjectService; +import jakarta.annotation.Resource; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; -import jakarta.annotation.Resource; import java.util.List; @RestController @@ -33,7 +33,7 @@ public class BaseProjectController { public List getUserProject(@RequestBody ProjectRequest request) { // 仅支持查询当前用户的项目 request.setUserId(SessionUtils.getUserId()); - return baseProjectService.getUserProject(request); + return baseProjectService.getUserProject(request, SessionUtils.getCurrentProjectId()); } @PostMapping(value = "upload/files/{projectId}", consumes = {"multipart/form-data"}) diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseProjectService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseProjectService.java index ac7a77fc4e..8ad5488425 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseProjectService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/BaseProjectService.java @@ -99,7 +99,7 @@ public class BaseProjectService { return baseProjectMapper.getProjectWithWorkspace(request); } - public List getUserProject(ProjectRequest request) { + public List getUserProject(ProjectRequest request, String sessionProjectId) { boolean isSuper = baseUserMapper.isSuperUser(SessionUtils.getUserId()); if (isSuper) { ProjectExample example = new ProjectExample(); @@ -110,22 +110,29 @@ public class BaseProjectService { if (StringUtils.isNotBlank(request.getWorkspaceId())) { criteria.andWorkspaceIdEqualTo(request.getWorkspaceId()); } - return projectMapper.selectByExample(example); + example.setOrderByClause(" CONVERT(name USING gbk) COLLATE gbk_chinese_ci ASC "); + List returnProject = projectMapper.selectByExample(example); + this.swapProject(returnProject, sessionProjectId); + return returnProject; } if (StringUtils.isNotBlank(request.getName())) { request.setName(StringUtils.wrapIfMissing(request.getName(), "%")); } request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); List returnList = baseProjectMapper.getUserProject(request); + this.swapProject(returnList, sessionProjectId); + return returnList; + } + + private void swapProject(List projectList, String sessionProjectId) { int ownerProjectIndex = 0; - for (int i = 0; i < returnList.size(); i++) { - if (StringUtils.equals(returnList.get(i).getId(), SessionUtils.getCurrentProjectId())) { + for (int i = 0; i < projectList.size(); i++) { + if (StringUtils.equals(projectList.get(i).getId(), sessionProjectId)) { ownerProjectIndex = i; break; } } - Collections.swap(returnList, 0, ownerProjectIndex); - return returnList; + Collections.swap(projectList, 0, ownerProjectIndex); } public List getProjectByIds(List ids) {