优化权限模块,采用left join连表查询

master
星期八 5 years ago
parent 5a3d8d2475
commit 08190f79ca
  1. 24
      src/main/java/com/lq/cms/service/impl/SysPermissionServiceImpl.java
  2. 15
      src/main/resources/mybatis/mapping/SysPermissionDao.xml

@ -39,30 +39,6 @@ public class SysPermissionServiceImpl implements SysPermissionService{
@Override
public List<SysPermissionVo> findListPage(SysPermissionVo vo) {
List<SysPermissionVo> sysPermissionVos = sysPermissionDao.findListPage(vo);
sysPermissionVos.forEach(sysPermissionVo1->{
Optional<Long> sysResourceIdOptional = Optional.of(sysPermissionVo1.getSysResourceId());
if (sysResourceIdOptional.isPresent()) {
SysResource sysResource = sysResourceDao.findOne(sysResourceIdOptional.get());
if (sysResource!=null) {
sysPermissionVo1.setSysResourceName(sysResource.getMenuName());
}
}
Optional<Long> createUserIdOptional = Optional.of(sysPermissionVo1.getCreateUserId());
if (createUserIdOptional.isPresent()) {
SysUser createUser = sysUserDao.findOne(createUserIdOptional.get());
if (createUser!=null) {
sysPermissionVo1.setCreateUserName(createUser.getLoginName());
}
}
Optional<Long> updateUserIdOptional = Optional.of(sysPermissionVo1.getUpdateUserId());
if (updateUserIdOptional.isPresent()) {
SysUser updateUser = sysUserDao.findOne(updateUserIdOptional.get());
if (updateUser!=null) {
sysPermissionVo1.setUpdateUserName(updateUser.getLoginName());
}
}
});
return sysPermissionVos;
}

@ -8,6 +8,10 @@
permission_type,permission_key,name,sys_resource_id,id,status,create_time,create_user_id,update_time,update_user_id
</sql>
<sql id="sp_column_list">
permission_type,permission_key,name,sys_resource_id,sp.id,sp.status,sp.create_time,sp.create_user_id,sp.update_time,sp.update_user_id
</sql>
<select id="findOne" resultType="com.lq.entity.SysPermission" parameterType="long">
SELECT <include refid="column_list"/>
FROM sys_permission
@ -21,10 +25,13 @@
</select>
<select id="findListPage" resultType="SysPermissionVo" parameterType="SysPermissionVo">
SELECT <include refid="column_list"/>
FROM sys_permission
WHERE status = 1
ORDER BY create_time DESC,update_time DESC
SELECT <include refid="sp_column_list"/> ,create_su.login_name createUserName,update_su.login_name updateUserName,sr.menu_name sysResourceName
FROM sys_permission sp
LEFT JOIN sys_resource sr ON sp.sys_resource_id = sr.id
LEFT JOIN sys_user create_su ON sp.create_user_id = create_su.id AND create_su.status = 1
LEFT JOIN sys_user update_su ON sp.update_user_id = update_su.id AND update_su.status = 1
WHERE sp.status = 1
ORDER BY sp.create_time DESC,sp.update_time DESC
</select>
<select id="count" resultType="int" parameterType="SysPermissionVo">

Loading…
Cancel
Save