feat(系统设置): 超级管理员的项目列表进行排序处理

This commit is contained in:
song-tianyang 2024-03-04 14:01:56 +08:00 committed by 建国
parent b8ca3b5e96
commit 06c03d5982
2 changed files with 15 additions and 8 deletions

View File

@ -10,11 +10,11 @@ import io.metersphere.dto.ProjectDTO;
import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.request.ProjectRequest; import io.metersphere.request.ProjectRequest;
import io.metersphere.service.BaseProjectService; import io.metersphere.service.BaseProjectService;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import jakarta.annotation.Resource;
import java.util.List; import java.util.List;
@RestController @RestController
@ -33,7 +33,7 @@ public class BaseProjectController {
public List<Project> getUserProject(@RequestBody ProjectRequest request) { public List<Project> getUserProject(@RequestBody ProjectRequest request) {
// 仅支持查询当前用户的项目 // 仅支持查询当前用户的项目
request.setUserId(SessionUtils.getUserId()); request.setUserId(SessionUtils.getUserId());
return baseProjectService.getUserProject(request); return baseProjectService.getUserProject(request, SessionUtils.getCurrentProjectId());
} }
@PostMapping(value = "upload/files/{projectId}", consumes = {"multipart/form-data"}) @PostMapping(value = "upload/files/{projectId}", consumes = {"multipart/form-data"})

View File

@ -99,7 +99,7 @@ public class BaseProjectService {
return baseProjectMapper.getProjectWithWorkspace(request); return baseProjectMapper.getProjectWithWorkspace(request);
} }
public List<Project> getUserProject(ProjectRequest request) { public List<Project> getUserProject(ProjectRequest request, String sessionProjectId) {
boolean isSuper = baseUserMapper.isSuperUser(SessionUtils.getUserId()); boolean isSuper = baseUserMapper.isSuperUser(SessionUtils.getUserId());
if (isSuper) { if (isSuper) {
ProjectExample example = new ProjectExample(); ProjectExample example = new ProjectExample();
@ -110,22 +110,29 @@ public class BaseProjectService {
if (StringUtils.isNotBlank(request.getWorkspaceId())) { if (StringUtils.isNotBlank(request.getWorkspaceId())) {
criteria.andWorkspaceIdEqualTo(request.getWorkspaceId()); criteria.andWorkspaceIdEqualTo(request.getWorkspaceId());
} }
return projectMapper.selectByExample(example); example.setOrderByClause(" CONVERT(name USING gbk) COLLATE gbk_chinese_ci ASC ");
List<Project> returnProject = projectMapper.selectByExample(example);
this.swapProject(returnProject, sessionProjectId);
return returnProject;
} }
if (StringUtils.isNotBlank(request.getName())) { if (StringUtils.isNotBlank(request.getName())) {
request.setName(StringUtils.wrapIfMissing(request.getName(), "%")); request.setName(StringUtils.wrapIfMissing(request.getName(), "%"));
} }
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
List<Project> returnList = baseProjectMapper.getUserProject(request); List<Project> returnList = baseProjectMapper.getUserProject(request);
this.swapProject(returnList, sessionProjectId);
return returnList;
}
private void swapProject(List<Project> projectList, String sessionProjectId) {
int ownerProjectIndex = 0; int ownerProjectIndex = 0;
for (int i = 0; i < returnList.size(); i++) { for (int i = 0; i < projectList.size(); i++) {
if (StringUtils.equals(returnList.get(i).getId(), SessionUtils.getCurrentProjectId())) { if (StringUtils.equals(projectList.get(i).getId(), sessionProjectId)) {
ownerProjectIndex = i; ownerProjectIndex = i;
break; break;
} }
} }
Collections.swap(returnList, 0, ownerProjectIndex); Collections.swap(projectList, 0, ownerProjectIndex);
return returnList;
} }
public List<Project> getProjectByIds(List<String> ids) { public List<Project> getProjectByIds(List<String> ids) {