Skip to content

Commit

Permalink
sort workspace index
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanzhou11 committed Dec 20, 2024
1 parent f4daa64 commit 9f0c342
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
</sql>

<select id="getWorkspaces" resultMap="dss_workspace">
SELECT * from dss_workspace where id in (select distinct workspace_id from dss_workspace_user_role WHERE username = #{username}) order by create_time desc
select dw.* from dss_workspace dw inner join (select workspace_id,min(create_time) create_time from dss_workspace_user_role WHERE username = #{username} group by workspace_id) dwur on dw.id = dwur.workspace_id order by dwur.create_time desc
</select>

<select id="getMenuId" resultType="java.lang.Integer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ public boolean checkUserIfSettingAdmin(String username){
@Override
public List<DSSWorkspace> getWorkspaces(String userName) {
List<DSSWorkspace> workspaces = dssWorkspaceMapper.getWorkspaces(userName);
workspaces = sortDssWorkspacesIndex(workspaces);
//用于展示demo的工作空间是不应该返回的,除非用户是管理员
if (dssWorkspaceUserMapper.isAdmin(userName) == 1) {
return workspaces;
Expand All @@ -223,7 +224,7 @@ public List<DSSWorkspace> getWorkspaces(String userName) {
@Override
public DSSWorkspaceHomePageVO getWorkspaceHomePage(String userName, String moduleName) throws DSSErrorException {
List<DSSWorkspace> dssWorkspaces = dssWorkspaceMapper.getWorkspaces(userName);
List<Integer> workspaceIds = sortDssWorkspacesIndex(dssWorkspaces);
List<Integer> workspaceIds = sortDssWorkspacesIndex(dssWorkspaces).stream().map(DSSWorkspace::getId).collect(Collectors.toList());
DSSWorkspaceHomePageVO dssWorkspaceHomePageVO = new DSSWorkspaceHomePageVO();
if (workspaceIds.size() == 0) {
Long userId = dssWorkspaceUserMapper.getUserID(userName);
Expand Down Expand Up @@ -290,21 +291,23 @@ public DSSWorkspaceHomePageVO getWorkspaceHomePage(String userName, String modul
return dssWorkspaceHomePageVO;
}

private List<Integer> sortDssWorkspacesIndex(List<DSSWorkspace> dssWorkspaces) {
List<Integer> workspaceIds = dssWorkspaces.stream().filter(l -> !DEFAULT_DEMO_WORKSPACE_NAME.getValue().equals(l.getName())
private List<DSSWorkspace> sortDssWorkspacesIndex(List<DSSWorkspace> dssWorkspaces) {
if(dssWorkspaces.size()>1){
List<DSSWorkspace> dssWorkspaceReq = dssWorkspaces.stream().filter(l -> !DEFAULT_DEMO_WORKSPACE_NAME.getValue().equals(l.getName())
&&!DSSWorkspaceConstant.DEFAULT_WORKSPACE_NAME.getValue().equals(l.getName())
&&!DSSWorkspaceConstant.DEFAULT_0XWORKSPACE_NAME.getValue().equals(l.getName()))
.map(DSSWorkspace::getId).collect(Collectors.toList());
if(workspaceIds.size()>1){
Map<String, Integer> workspaceMap = dssWorkspaces.stream().collect(Collectors.toMap(DSSWorkspace::getName, DSSWorkspace::getId));
.collect(Collectors.toList());

Map<String, DSSWorkspace> workspaceMap = dssWorkspaces.stream().collect(Collectors.toMap(DSSWorkspace::getName, w->w));
if(workspaceMap.keySet().contains(DSSWorkspaceConstant.DEFAULT_WORKSPACE_NAME.getValue())){
workspaceIds.add(workspaceMap.get(DSSWorkspaceConstant.DEFAULT_WORKSPACE_NAME.getValue()));
dssWorkspaceReq.add(workspaceMap.get(DSSWorkspaceConstant.DEFAULT_WORKSPACE_NAME.getValue()));
}
if(workspaceMap.keySet().contains(DSSWorkspaceConstant.DEFAULT_0XWORKSPACE_NAME.getValue())){
workspaceIds.add(workspaceMap.get(DSSWorkspaceConstant.DEFAULT_0XWORKSPACE_NAME.getValue()));
dssWorkspaceReq.add(workspaceMap.get(DSSWorkspaceConstant.DEFAULT_0XWORKSPACE_NAME.getValue()));
}
return dssWorkspaceReq;
}
return workspaceIds;
return dssWorkspaces;
}

@Override
Expand Down

0 comments on commit 9f0c342

Please sign in to comment.