重构用户角色类

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; package com.xkrs.common.account;
import com.xkrs.model.entity.SysAuthorityEntity;
import com.xkrs.service.SysAuthorityService; import com.xkrs.service.SysAuthorityService;
import com.xkrs.straw.model.entity.SysAuthorityEntity;
import com.xkrs.straw.model.entity.SysUserEntity; import com.xkrs.straw.model.entity.SysUserEntity;
import com.xkrs.straw.service.SysRoleService; import com.xkrs.straw.service.SysRoleService;
import com.xkrs.straw.service.SysUserService; import com.xkrs.straw.service.SysUserService;

View File

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

View File

@ -1,9 +1,9 @@
package com.xkrs.service.impl; 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.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 org.springframework.stereotype.Service;
import javax.annotation.Resource; 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.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; 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.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor; 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.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import java.util.List; import java.util.List;
/** public interface SysAuthorityDao extends JpaRepository<SysAuthorityEntity, Integer>, JpaSpecificationExecutor<SysAuthorityEntity> {
* SysAuthorityDao
* @author tajochen
*/
public interface SysAuthorityDao extends JpaRepository<SysAuthorityEntity,Integer> {
/** /**
* 查询权限实体列表根据用户名 Object[] * 查询权限实体列表根据用户名 Object[]
*
* @param userName 用户名 * @param userName 用户名
* @return 用户实体 * @return 用户实体
*/ */
@Query(value = "SELECT a.id, a.authority_name, a.authority_name_zh, a.authority_desc " + @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)
"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); List<SysAuthorityEntity> selectByUserName(@Param("userName") String userName);
/** /**
* 根据id批量查询权限信息 * 根据id批量查询权限信息
*
* @param id * @param id
* @return * @return
*/ */

View File

@ -1,4 +1,4 @@
package com.xkrs.model.entity; package com.xkrs.straw.model.entity;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; 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 javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
/** /**
* RelUserRole 表实体类 * RelUserRole 表实体类
*
* @author tajochen * @author tajochen
*/ */
@Entity @Entity
@Table(name="rel_user_role") @Table(name = "rel_user_role")
public class RelUserRoleEntity implements Serializable { public class RelUserRoleEntity implements Serializable {
/** /**
@ -16,7 +17,7 @@ public class RelUserRoleEntity implements Serializable {
*/ */
@Id @Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "rel_user_role_seq_gen") @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; private Integer id;
@Column(nullable = false) @Column(nullable = false)
@ -51,10 +52,6 @@ public class RelUserRoleEntity implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "RelUserRoleEntity{" + return "RelUserRoleEntity{" + "id=" + id + ", userId=" + userId + ", roleId=" + roleId + '}';
"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 javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
/** /**
* SysAuthority 表实体类 * SysAuthority 表实体类
*
* @author tajochen * @author tajochen
*/ */
@Entity @Entity
@Table(name="sys_authority") @Table(name = "sys_authority")
public class SysAuthorityEntity implements Serializable { public class SysAuthorityEntity implements Serializable {
/** /**
@ -16,10 +17,10 @@ public class SysAuthorityEntity implements Serializable {
*/ */
@Id @Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sys_authority_seq_gen") @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; 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; private String authorityName;
@Column(length = 64, columnDefinition = "varchar(64)") @Column(length = 64, columnDefinition = "varchar(64)")
@ -62,11 +63,6 @@ public class SysAuthorityEntity implements Serializable {
@Override @Override
public String toString() { public String toString() {
return "SysAuthorityEntity{" + return "SysAuthorityEntity{" + "id=" + id + ", authorityName='" + authorityName + '\'' + ", authorityDesc='" + authorityDesc + '\'' + ", authorityNameZh='" + authorityNameZh + '\'' + '}';
"id=" + id +
", authorityName='" + authorityName + '\'' +
", authorityDesc='" + authorityDesc + '\'' +
", authorityNameZh='" + authorityNameZh + '\'' +
'}';
} }
} }

View File

@ -1,17 +1,17 @@
package com.xkrs.straw.service.impl; package com.xkrs.straw.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum; import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.dao.RelRoleAuthorityDao;
import com.xkrs.dao.RelUserRoleDao;
import com.xkrs.dao.StreetDao; 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.entity.StreetEntity;
import com.xkrs.model.qo.SysUserQo; import com.xkrs.model.qo.SysUserQo;
import com.xkrs.model.vo.SysUserVo; import com.xkrs.model.vo.SysUserVo;
import com.xkrs.service.RedisService; 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.SysRoleDao;
import com.xkrs.straw.dao.SysUserDao; 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.SysRoleEntity;
import com.xkrs.straw.model.entity.SysUserEntity; import com.xkrs.straw.model.entity.SysUserEntity;
import com.xkrs.straw.service.SysUserService; import com.xkrs.straw.service.SysUserService;