重构用户角色类

This commit is contained in:
liuchengqian 2023-02-03 17:48:48 +08:00
parent 80cf256e56
commit acd127babd
10 changed files with 33 additions and 43 deletions

View File

@ -1,7 +1,7 @@
package com.xkrs.common.account;
import com.xkrs.model.entity.SysAuthorityEntity;
import com.xkrs.service.SysAuthorityService;
import com.xkrs.straw.model.entity.SysAuthorityEntity;
import com.xkrs.straw.model.entity.SysUserEntity;
import com.xkrs.straw.service.SysRoleService;
import com.xkrs.straw.service.SysUserService;

View File

@ -1,6 +1,6 @@
package com.xkrs.service;
import com.xkrs.model.entity.SysAuthorityEntity;
import com.xkrs.straw.model.entity.SysAuthorityEntity;
import java.util.List;

View File

@ -1,9 +1,9 @@
package com.xkrs.service.impl;
import com.xkrs.dao.RelRoleAuthorityDao;
import com.xkrs.dao.SysAuthorityDao;
import com.xkrs.model.entity.SysAuthorityEntity;
import com.xkrs.service.SysAuthorityService;
import com.xkrs.straw.dao.RelRoleAuthorityDao;
import com.xkrs.straw.dao.SysAuthorityDao;
import com.xkrs.straw.model.entity.SysAuthorityEntity;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

View File

@ -1,6 +1,6 @@
package com.xkrs.dao;
package com.xkrs.straw.dao;
import com.xkrs.model.entity.RelRoleAuthorityEntity;
import com.xkrs.straw.model.entity.RelRoleAuthorityEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

View File

@ -1,6 +1,6 @@
package com.xkrs.dao;
package com.xkrs.straw.dao;
import com.xkrs.model.entity.RelUserRoleEntity;
import com.xkrs.straw.model.entity.RelUserRoleEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;

View File

@ -1,30 +1,27 @@
package com.xkrs.dao;
package com.xkrs.straw.dao;
import com.xkrs.model.entity.SysAuthorityEntity;
import com.xkrs.straw.model.entity.SysAuthorityEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List;
/**
* SysAuthorityDao
* @author tajochen
*/
public interface SysAuthorityDao extends JpaRepository<SysAuthorityEntity,Integer> {
public interface SysAuthorityDao extends JpaRepository<SysAuthorityEntity, Integer>, JpaSpecificationExecutor<SysAuthorityEntity> {
/**
* 查询权限实体列表根据用户名 Object[]
*
* @param userName 用户名
* @return 用户实体
*/
@Query(value = "SELECT a.id, a.authority_name, a.authority_name_zh, a.authority_desc " +
"FROM sys_authority a,rel_role_authority ra,sys_role r WHERE r.id = ra.role_id AND ra.authority_id = a.id AND r.id " +
"IN (SELECT r.id FROM sys_user u,sys_role r,rel_user_role ur " +
" WHERE u.user_name = :userName AND u.id = ur.user_id AND ur.role_id = r.id)", nativeQuery = true)
@Query(value = "SELECT a.id, a.authority_name, a.authority_name_zh, a.authority_desc FROM sys_authority a,rel_role_authority ra,sys_role r WHERE r.id = ra.role_id AND ra.authority_id = a.id AND r.id IN (SELECT r.id FROM sys_user u,sys_role r,rel_user_role ur WHERE u.user_name = :userName AND u.id = ur.user_id AND ur.role_id = r.id)", nativeQuery = true)
List<SysAuthorityEntity> selectByUserName(@Param("userName") String userName);
/**
* 根据id批量查询权限信息
*
* @param id
* @return
*/

View File

@ -1,4 +1,4 @@
package com.xkrs.model.entity;
package com.xkrs.straw.model.entity;
import javax.persistence.*;
import java.io.Serializable;

View File

@ -1,14 +1,15 @@
package com.xkrs.model.entity;
package com.xkrs.straw.model.entity;
import javax.persistence.*;
import java.io.Serializable;
/**
* RelUserRole 表实体类
*
* @author tajochen
*/
@Entity
@Table(name="rel_user_role")
@Table(name = "rel_user_role")
public class RelUserRoleEntity implements Serializable {
/**
@ -16,7 +17,7 @@ public class RelUserRoleEntity implements Serializable {
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rel_user_role_seq_gen")
@SequenceGenerator(name = "rel_user_role_seq_gen", sequenceName = "rel_user_role_id_seq",allocationSize = 1)
@SequenceGenerator(name = "rel_user_role_seq_gen", sequenceName = "rel_user_role_id_seq", allocationSize = 1)
private Integer id;
@Column(nullable = false)
@ -51,10 +52,6 @@ public class RelUserRoleEntity implements Serializable {
@Override
public String toString() {
return "RelUserRoleEntity{" +
"id=" + id +
", userId=" + userId +
", roleId=" + roleId +
'}';
return "RelUserRoleEntity{" + "id=" + id + ", userId=" + userId + ", roleId=" + roleId + '}';
}
}

View File

@ -1,14 +1,15 @@
package com.xkrs.model.entity;
package com.xkrs.straw.model.entity;
import javax.persistence.*;
import java.io.Serializable;
/**
* SysAuthority 表实体类
*
* @author tajochen
*/
@Entity
@Table(name="sys_authority")
@Table(name = "sys_authority")
public class SysAuthorityEntity implements Serializable {
/**
@ -16,10 +17,10 @@ public class SysAuthorityEntity implements Serializable {
*/
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sys_authority_seq_gen")
@SequenceGenerator(name = "sys_authority_seq_gen", sequenceName = "sys_authority_id_seq",allocationSize = 1)
@SequenceGenerator(name = "sys_authority_seq_gen", sequenceName = "sys_authority_id_seq", allocationSize = 1)
private Integer id;
@Column(length = 64, nullable = false, unique = true,columnDefinition = "varchar(64)")
@Column(length = 64, nullable = false, unique = true, columnDefinition = "varchar(64)")
private String authorityName;
@Column(length = 64, columnDefinition = "varchar(64)")
@ -62,11 +63,6 @@ public class SysAuthorityEntity implements Serializable {
@Override
public String toString() {
return "SysAuthorityEntity{" +
"id=" + id +
", authorityName='" + authorityName + '\'' +
", authorityDesc='" + authorityDesc + '\'' +
", authorityNameZh='" + authorityNameZh + '\'' +
'}';
return "SysAuthorityEntity{" + "id=" + id + ", authorityName='" + authorityName + '\'' + ", authorityDesc='" + authorityDesc + '\'' + ", authorityNameZh='" + authorityNameZh + '\'' + '}';
}
}

View File

@ -1,17 +1,17 @@
package com.xkrs.straw.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.RelRoleAuthorityDao;
import com.xkrs.dao.RelUserRoleDao;
import com.xkrs.dao.StreetDao;
import com.xkrs.model.entity.RelRoleAuthorityEntity;
import com.xkrs.model.entity.RelUserRoleEntity;
import com.xkrs.model.entity.StreetEntity;
import com.xkrs.model.qo.SysUserQo;
import com.xkrs.model.vo.SysUserVo;
import com.xkrs.service.RedisService;
import com.xkrs.straw.dao.RelRoleAuthorityDao;
import com.xkrs.straw.dao.RelUserRoleDao;
import com.xkrs.straw.dao.SysRoleDao;
import com.xkrs.straw.dao.SysUserDao;
import com.xkrs.straw.model.entity.RelRoleAuthorityEntity;
import com.xkrs.straw.model.entity.RelUserRoleEntity;
import com.xkrs.straw.model.entity.SysRoleEntity;
import com.xkrs.straw.model.entity.SysUserEntity;
import com.xkrs.straw.service.SysUserService;