Commit 2d2d6363 by 周海峰

no message

parent dce43812
......@@ -5,6 +5,7 @@ import com.metro.auth.platform.domain.auth.PlatformApplications;
import com.metro.auth.platform.domain.auth.PlatformApplicationsGroup;
import com.metro.auth.platform.service.PlatformApplicationsGroupService;
import com.metro.auth.platform.service.PlatformApplicationsService;
import com.metro.auth.platform.service.PlatformRoleApplicationAppService;
import org.springframework.stereotype.Controller;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
......@@ -27,7 +28,7 @@ public class WechatApiController {
@Resource
private PlatformApplicationsGroupService platformApplicationsGroupService;
@Resource
private PlatformApplicationsService platformApplicationsService;
private PlatformRoleApplicationAppService platformRoleApplicationAppService;
@GetMapping("/appGroupPageList")
public ResultJson appGroupPageList(@RequestParam String userId, String appName) {
......@@ -36,22 +37,18 @@ public class WechatApiController {
platformApplicationsGroupService.selectList(new PlatformApplicationsGroup());
// 应用
List<PlatformApplications> platformApplicationsList =
platformApplicationsService.getPlatformApplicationsListByUserid(userId);
platformRoleApplicationAppService.getPlatformApplicationsAppListByUserid(userId);
if (!CollectionUtils.isEmpty(platformApplicationsList)) {
//过滤
if (!StringUtils.isEmpty(appName)) {
platformApplicationsList = platformApplicationsList.stream().filter(app -> app.getTitle().contains(appName)).collect(Collectors.toList());
}
for (PlatformApplicationsGroup applicationsGroup : platformApplicationsGroups) {
String groupCode = applicationsGroup.getGroupCode();
List<PlatformApplications> groupOf = platformApplicationsList.stream().filter(item -> groupCode.equals(item.getGroupCode())).collect(Collectors.toList());
applicationsGroup.setApplicationsList(groupOf);
}
}
// 只要有应用的分组
platformApplicationsGroups = platformApplicationsGroups.stream()
.filter(group -> !CollectionUtils.isEmpty(group.getApplicationsList()))
......
......@@ -113,5 +113,5 @@ public interface PlatformApplicationsMapper {
int insertRoleApplication(PlatformRoleApplication platformRoleApplication);
List<PlatformApplications> getPlatformApplicationsListByRoleAppList(List<String> roleid);
}
......@@ -336,6 +336,7 @@
select distinct T.* from platform_applications T left join platform_role_application_app R on T.id=R.applicationid
where T.qyflag='1' and R.roleid = #{roleid,jdbcType=VARCHAR} order by T.num + 0
</select>
<select id="getPlatformApplicationsListByRoleList" resultMap="BaseResultMap">
select distinct T.* from platform_applications T left join platform_role_application R on T.id=R.applicationid
where T.qyflag='1' and R.roleid in
......@@ -343,13 +344,17 @@
#{name}
</foreach>
</select>
<select id="getPlatformApplicationsListByRoleAppList" resultMap="BaseResultMap">
select distinct T.* from platform_applications T left join platform_role_application_app R on T.id=R.applicationid
where T.qyflag='1' and R.roleid in
<foreach collection="list" item="name" index="index" open="(" close=")" separator=",">
#{name}
</foreach>
</select>
<delete id="deleteByRoleid" parameterType="java.lang.String">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
-->
delete from platform_role_application where roleid = #{roleid,jdbcType=VARCHAR}
</delete>
<insert id="insertRoleApplication" parameterType="com.metro.auth.platform.domain.auth.PlatformRoleApplication">
......
......@@ -14,4 +14,6 @@ public interface PlatformRoleApplicationAppService {
int deleteByRoleid(String roleid);
int insertRoleApplicationApp(PlatformRoleApplicationApp platformRoleApplicationApp);
List<PlatformApplications> getPlatformApplicationsAppListByUserid(String userid);
}
......@@ -3,12 +3,15 @@ package com.metro.auth.platform.service;
import com.metro.auth.platform.domain.auth.PlatformApplications;
import com.metro.auth.platform.domain.auth.PlatformApplicationsExample;
import com.metro.auth.platform.domain.auth.PlatformRoleApplicationApp;
import com.metro.auth.platform.domain.auth.PlatformSysRole;
import com.metro.auth.platform.mapper.PlatformApplicationsMapper;
import com.metro.auth.platform.mapper.PlatformRoleApplicationAppMapper;
import com.metro.auth.platform.mapper.PlatformSysRoleMapper;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
@Service
......@@ -16,9 +19,10 @@ public class PlatformRoleApplicationAppServiceImpl implements PlatformRoleApplic
@Resource
PlatformApplicationsMapper platformApplicationsMapper;
@Resource
PlatformRoleApplicationAppMapper platformRoleApplicationAppMapper;
@Resource
PlatformSysRoleMapper platformSysRoleMapper;
@Override
public List<PlatformApplications> getPlatformApplicationsListApp() {
......@@ -61,4 +65,46 @@ public class PlatformRoleApplicationAppServiceImpl implements PlatformRoleApplic
public int insertRoleApplicationApp(PlatformRoleApplicationApp platformRoleApplicationApp) {
return platformRoleApplicationAppMapper.insertRoleApplicationApp(platformRoleApplicationApp);
}
@Override
public List<PlatformApplications> getPlatformApplicationsAppListByUserid(String userid) {
// 1. 查询所有启用的应用
PlatformApplicationsExample example = new PlatformApplicationsExample();
example.createCriteria().andQyflagEqualTo("1");
List<PlatformApplications> allApplications = platformApplicationsMapper.selectByExample(example);
// 3. 安全地解析userid并查询用户角色
Set<String> roleIds = new HashSet<>();
int userIdInt = Integer.parseInt(userid);
// 直接查询出角色ID列表,避免在Java代码中循环提取
roleIds = platformSysRoleMapper.selectByUserId(userIdInt)
.stream().map(PlatformSysRole::getId)
.collect(Collectors.toSet());
// 4. 根据角色ID列表查询可见应用
List<PlatformApplications> visibleApplications;
if (roleIds.isEmpty()) {
visibleApplications = Collections.emptyList(); // 如果没有角色,则可见应用列表为空
} else {
visibleApplications = platformApplicationsMapper.getPlatformApplicationsListByRoleAppList(new ArrayList<>(roleIds));
}
// 提取可见应用的ID集合,用于快速判断
Set<Integer> visibleAppIds = visibleApplications.stream()
.map(PlatformApplications::getId)
.collect(Collectors.toSet());
// 遍历所有应用,根据其ID是否在可见应用ID集合中来更新状态
allApplications.forEach(app -> {
if (visibleAppIds.contains(app.getId())) {
app.setRoleUseStatue(app.getId()); // 可见
} else {
app.setRoleUseStatue(0); // 不可见
}
});
return allApplications.stream()
.sorted(Comparator.comparing(app -> StringUtils.isEmpty(app.getNum()) ? 0 : Integer.parseInt(app.getNum())))
.collect(Collectors.toList());
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论