CRM项目后端将用户的权限提交到前端实现对应权限进行对应操作------CRM项目

java">package ***.alatus.service.impl;

import ***.alatus.constant.Constants;
import ***.alatus.manager.RedisManager;
import ***.alatus.manager.UserManager;
import ***.alatus.mapper.TUserMapper;
import ***.alatus.model.TUser;
import ***.alatus.query.BaseQuery;
import ***.alatus.query.UserQuery;
import ***.alatus.service.UserService;
import ***.alatus.util.CacheUtils;
import ***.alatus.util.JWTUtils;
import ***.github.pagehelper.PageHelper;
import ***.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private TUserMapper tUserMapper;
    @Resource
    private RedisManager redisManager;
    @Resource
    private UserManager userManager;

//    注入一个密码加密器
    @Resource
    private PasswordEncoder passwordEncoder;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        TUser tUser = tUserMapper.selectByLoginAct(username);
        if(tUser == null){
            throw new UsernameNotFoundException("登陆账号不存在");
        }
//        设置用户的角色
        tUser.setRoleList(userManager.loadRoleListByUser(tUser));
        tUser.setMenuPermissionList(userManager.getMenuPermissionList(tUser));
        return tUser;
    }

    @Override
    public PageInfo<TUser> getUserByPage(Integer current) {
//        设置PageHelper和分页情况
        PageHelper.startPage(current, Constants.PAGE_SIZE);
//        查询
        ArrayList<TUser> list = tUserMapper.selectUserByPage(BaseQuery.builder().build());
//        封装分页到PageInfo中
        PageInfo<TUser> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public TUser getUserById(Integer id) {
        return tUserMapper.selectDetailByPrimaryKey(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int saveUser(UserQuery userQuery) {
        TUser tUser = new TUser();
//        把query对象的数据复制到user对象里面
//        这个工具类的复制要求是两个对象的属性名要相同,属性要相同
        BeanUtils.copyProperties(userQuery,tUser);
        tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));
//        创建时间
        tUser.setCreateTime(new Date());
//        通过token解析出的用户获取ID作为创建者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();
        tUser.setCreateBy(loginId);
        return tUserMapper.insertSelective(tUser);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateUser(UserQuery userQuery) {
        TUser tUser = new TUser();
//        把query对象的数据复制到user对象里面
//        这个工具类的复制要求是两个对象的属性名要相同,属性要相同
        BeanUtils.copyProperties(userQuery,tUser);
        if(StringUtils.hasText(userQuery.getLoginPwd())){
            tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));
        }
//        编辑时间
        tUser.setEditTime(new Date());
//        通过token解析出的用户获取ID作为编辑者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();
        tUser.setEditBy(loginId);
        return tUserMapper.updateByPrimaryKeySelective(tUser);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delUserById(Integer id) {
        return tUserMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delUsersByIds(List<String> idList) {
//        遍历删除法
//        int result = 0;
//        for (int i = 0; i < idList.size(); i++) {
//            result += tUserMapper.deleteByPrimaryKey(Integer.parseInt(idList.get(i)));
//        }
//        return result;
        return tUserMapper.deleteByIds(idList);
    }

    @Override
    public List<TUser> getOwnerList() {
//        先从redis获取
//        redis没有就走mysql
        return CacheUtils.getCacheData(() -> {
//            从redis查数据
            return (List<TUser>)redisManager.getValue(Constants.OWNER_KEY);
        }
        ,() -> {
//            生产,从mysql查询数据
            return (List<TUser>)tUserMapper.selectByOwner();
        }
        ,(t) -> {
//            消费,把数据放入缓存redis
            redisManager.setValue(Constants.OWNER_KEY,t);
        });
    }
}
package ***.alatus.service.impl;

import ***.alatus.constant.Constants;
import ***.alatus.manager.RedisManager;
import ***.alatus.manager.UserManager;
import ***.alatus.mapper.TUserMapper;
import ***.alatus.model.TUser;
import ***.alatus.query.BaseQuery;
import ***.alatus.query.UserQuery;
import ***.alatus.service.UserService;
import ***.alatus.util.CacheUtils;
import ***.alatus.util.JWTUtils;
import ***.github.pagehelper.PageHelper;
import ***.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Resource
    private TUserMapper tUserMapper;
    @Resource
    private RedisManager redisManager;
    @Resource
    private UserManager userManager;

//    注入一个密码加密器
    @Resource
    private PasswordEncoder passwordEncoder;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        TUser tUser = tUserMapper.selectByLoginAct(username);
        if(tUser == null){
            throw new UsernameNotFoundException("登陆账号不存在");
        }
//        设置用户的角色
        tUser.setRoleList(userManager.loadRoleListByUser(tUser));
        tUser.setMenuPermissionList(userManager.getMenuPermissionList(tUser));
        return tUser;
    }

    @Override
    public PageInfo<TUser> getUserByPage(Integer current) {
//        设置PageHelper和分页情况
        PageHelper.startPage(current, Constants.PAGE_SIZE);
//        查询
        ArrayList<TUser> list = tUserMapper.selectUserByPage(BaseQuery.builder().build());
//        封装分页到PageInfo中
        PageInfo<TUser> info = new PageInfo<>(list);
        return info;
    }

    @Override
    public TUser getUserById(Integer id) {
        return tUserMapper.selectDetailByPrimaryKey(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int saveUser(UserQuery userQuery) {
        TUser tUser = new TUser();
//        把query对象的数据复制到user对象里面
//        这个工具类的复制要求是两个对象的属性名要相同,属性要相同
        BeanUtils.copyProperties(userQuery,tUser);
        tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));
//        创建时间
        tUser.setCreateTime(new Date());
//        通过token解析出的用户获取ID作为创建者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();
        tUser.setCreateBy(loginId);
        return tUserMapper.insertSelective(tUser);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateUser(UserQuery userQuery) {
        TUser tUser = new TUser();
//        把query对象的数据复制到user对象里面
//        这个工具类的复制要求是两个对象的属性名要相同,属性要相同
        BeanUtils.copyProperties(userQuery,tUser);
        if(StringUtils.hasText(userQuery.getLoginPwd())){
            tUser.setLoginPwd(passwordEncoder.encode(userQuery.getLoginPwd()));
        }
//        编辑时间
        tUser.setEditTime(new Date());
//        通过token解析出的用户获取ID作为编辑者的ID
        Integer loginId = JWTUtils.parseUserFromJWT(userQuery.getToken()).getId();
        tUser.setEditBy(loginId);
        return tUserMapper.updateByPrimaryKeySelective(tUser);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delUserById(Integer id) {
        return tUserMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delUsersByIds(List<String> idList) {
//        遍历删除法
//        int result = 0;
//        for (int i = 0; i < idList.size(); i++) {
//            result += tUserMapper.deleteByPrimaryKey(Integer.parseInt(idList.get(i)));
//        }
//        return result;
        return tUserMapper.deleteByIds(idList);
    }

    @Override
    public List<TUser> getOwnerList() {
//        先从redis获取
//        redis没有就走mysql
        return CacheUtils.getCacheData(() -> {
//            从redis查数据
            return (List<TUser>)redisManager.getValue(Constants.OWNER_KEY);
        }
        ,() -> {
//            生产,从mysql查询数据
            return (List<TUser>)tUserMapper.selectByOwner();
        }
        ,(t) -> {
//            消费,把数据放入缓存redis
            redisManager.setValue(Constants.OWNER_KEY,t);
        });
    }
}

package ***.alatus.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import ***.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * 用户表
 * t_user
 */
@Data
public class TUser implements UserDetails,Serializable {
    /**
     * 主键,自动增长,用户ID
     */
    private Integer id;

    /**
     * 登录账号
     */
    private String loginAct;

    /**
     * 登录密码
     */
    private String loginPwd;

    /**
     * 用户姓名
     */
    private String name;

    /**
     * 用户手机
     */
    private String phone;

    /**
     * 用户邮箱
     */
    private String email;

    /**
     * 账户是否没有过期,0已过期 1正常
     */
    private Integer a***ountNoExpired;

    /**
     * 密码是否没有过期,0已过期 1正常
     */
    private Integer credentialsNoExpired;

    /**
     * 账号是否没有锁定,0已锁定 1正常
     */
    private Integer a***ountNoLocked;

    /**
     * 账号是否启用,0禁用 1启用
     */
    private Integer a***ountEnabled;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 创建人
     */
    private Integer createBy;

    /**
     * 编辑时间
     */
    private Date editTime;

    /**
     * 编辑人
     */
    private Integer editBy;

    /**
     * 最近登录时间
     */
    private Date lastLoginTime;

    /**
     * 一对一关联:创建人
     */
    private TUser createByPO;

    /**
     * 一对一关联:编辑人
     */
    private TUser editByPO;

    private static final long serialVersionUID = 1L;

//    权限标识符的List
    private List<String> roleList;
//    菜单的list
    private List<TPermission> menuPermissionList;
//    权限标识符List
    private List<String> permissionList;
//    让以下的都JSON忽略,不然会报异常,而且也用不着他们
    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> list = new ArrayList<>();
//        角色列表遍历,做非空判断避免空指针
        if(this.getRoleList() != null){
            this.getRoleList().forEach(role -> {
                list.add(new SimpleGrantedAuthority(role));
            });
        }
//        权限标识符
        if(this.getPermissionList() != null){
            this.getPermissionList().forEach(permission -> {
                list.add(new SimpleGrantedAuthority(permission));
            });
        }
        return list;
    }
    @JsonIgnore
    @Override
    public String getPassword() {
        return this.getLoginPwd();
    }
    @JsonIgnore
    @Override
    public String getUsername() {
        return this.getLoginAct();
    }
//    以下的设计都是为1可用,为0不可用
    @JsonIgnore
    @Override
    public boolean isA***ountNonExpired() {
        return this.getA***ountNoExpired() == 1;
    }
    @JsonIgnore
    @Override
    public boolean isA***ountNonLocked() {
        return this.getA***ountNoLocked() == 1;
    }
    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return this.getCredentialsNoExpired() == 1;
    }
    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return this.getA***ountEnabled() == 1;
    }
}
package ***.alatus.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;

import ***.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * 用户表
 * t_user
 */
@Data
public class TUser implements UserDetails,Serializable {
    /**
     * 主键,自动增长,用户ID
     */
    private Integer id;

    /**
     * 登录账号
     */
    private String loginAct;

    /**
     * 登录密码
     */
    private String loginPwd;

    /**
     * 用户姓名
     */
    private String name;

    /**
     * 用户手机
     */
    private String phone;

    /**
     * 用户邮箱
     */
    private String email;

    /**
     * 账户是否没有过期,0已过期 1正常
     */
    private Integer a***ountNoExpired;

    /**
     * 密码是否没有过期,0已过期 1正常
     */
    private Integer credentialsNoExpired;

    /**
     * 账号是否没有锁定,0已锁定 1正常
     */
    private Integer a***ountNoLocked;

    /**
     * 账号是否启用,0禁用 1启用
     */
    private Integer a***ountEnabled;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 创建人
     */
    private Integer createBy;

    /**
     * 编辑时间
     */
    private Date editTime;

    /**
     * 编辑人
     */
    private Integer editBy;

    /**
     * 最近登录时间
     */
    private Date lastLoginTime;

    /**
     * 一对一关联:创建人
     */
    private TUser createByPO;

    /**
     * 一对一关联:编辑人
     */
    private TUser editByPO;

    private static final long serialVersionUID = 1L;

//    权限标识符的List
    private List<String> roleList;
//    菜单的list
    private List<TPermission> menuPermissionList;
//    权限标识符List
    private List<String> permissionList;
//    让以下的都JSON忽略,不然会报异常,而且也用不着他们
    @JsonIgnore
    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> list = new ArrayList<>();
//        角色列表遍历,做非空判断避免空指针
        if(this.getRoleList() != null){
            this.getRoleList().forEach(role -> {
                list.add(new SimpleGrantedAuthority(role));
            });
        }
//        权限标识符
        if(this.getPermissionList() != null){
            this.getPermissionList().forEach(permission -> {
                list.add(new SimpleGrantedAuthority(permission));
            });
        }
        return list;
    }
    @JsonIgnore
    @Override
    public String getPassword() {
        return this.getLoginPwd();
    }
    @JsonIgnore
    @Override
    public String getUsername() {
        return this.getLoginAct();
    }
//    以下的设计都是为1可用,为0不可用
    @JsonIgnore
    @Override
    public boolean isA***ountNonExpired() {
        return this.getA***ountNoExpired() == 1;
    }
    @JsonIgnore
    @Override
    public boolean isA***ountNonLocked() {
        return this.getA***ountNoLocked() == 1;
    }
    @JsonIgnore
    @Override
    public boolean isCredentialsNonExpired() {
        return this.getCredentialsNoExpired() == 1;
    }
    @JsonIgnore
    @Override
    public boolean isEnabled() {
        return this.getA***ountEnabled() == 1;
    }
}
package ***.alatus.mapper;

import ***.alatus.model.TPermission;

import java.util.List;

public interface TPermissionMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TPermission record);

    int insertSelective(TPermission record);

    TPermission selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TPermission record);

    int updateByPrimaryKey(TPermission record);

    List<TPermission> selectMenuPermissionByUserId(Integer id);
}
package ***.alatus.mapper;

import ***.alatus.model.TPermission;

import java.util.List;

public interface TPermissionMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TPermission record);

    int insertSelective(TPermission record);

    TPermission selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TPermission record);

    int updateByPrimaryKey(TPermission record);

    List<TPermission> selectMenuPermissionByUserId(Integer id);
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="***.alatus.mapper.TPermissionMapper">
  <resultMap id="BaseResultMap" type="***.alatus.model.TPermission">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="parent_id" jdbcType="INTEGER" property="parentId" />
    <result column="order_no" jdbcType="INTEGER" property="orderNo" />
    <result column="icon" jdbcType="VARCHAR" property="icon" />
  </resultMap>
  <resultMap id="PermissionRoleMap" type="***.alatus.model.TPermission">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="parent_id" jdbcType="INTEGER" property="parentId" />
    <result column="order_no" jdbcType="INTEGER" property="orderNo" />
    <result column="icon" jdbcType="VARCHAR" property="icon" />
<!--    一对多-->
    <collection property="subPermissionList" ofType="***.alatus.model.TPermission">
      <id column="cid" jdbcType="INTEGER" property="id" />
      <result column="***ame" jdbcType="VARCHAR" property="name" />
      <result column="curl" jdbcType="VARCHAR" property="url" />
      <result column="cicon" jdbcType="VARCHAR" property="icon" />
    </collection>
  </resultMap>
  
  <sql id="Base_Column_List">
    id, `name`, code, url, `type`, parent_id, order_no, icon
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_permission
    where id = #{id,jdbcType=INTEGER}
  </select>


  <select id="selectMenuPermissionByUserId" parameterType="java.lang.Integer" resultMap="PermissionRoleMap">
    SELECT
      tp.*,
      childTp.`id` cid,childTp.`name` ***ame,childTp.`url` curl,childTp.`icon` cicon
    FROM
      t_permission tp
        LEFT JOIN t_permission childTp
                  ON tp.`id` = childTp.`parent_id`
        LEFT JOIN t_role_permission trp
                  ON tp.`id` = trp.`permission_id`
        LEFT JOIN t_role tr
                  ON tr.`id` = trp.`role_id`
        LEFT JOIN t_user_role tur
                  ON tur.`role_id` = tr.`id`
    WHERE
      tp.type = 'menu' and childTp.`type` = 'menu'
      and tur.`user_id` = #{id,jdbcType=INTEGER}
  </select>


    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_permission
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="***.alatus.model.TPermission" useGeneratedKeys="true">
    insert into t_permission (`name`, code, url, 
      `type`, parent_id, order_no, 
      icon)
    values (#{name,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, 
      #{type,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER}, #{orderNo,jdbcType=INTEGER}, 
      #{icon,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="***.alatus.model.TPermission" useGeneratedKeys="true">
    insert into t_permission
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="name != null">
        `name`,
      </if>
      <if test="code != null">
        code,
      </if>
      <if test="url != null">
        url,
      </if>
      <if test="type != null">
        `type`,
      </if>
      <if test="parentId != null">
        parent_id,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="icon != null">
        icon,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        #{code,jdbcType=VARCHAR},
      </if>
      <if test="url != null">
        #{url,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=VARCHAR},
      </if>
      <if test="parentId != null">
        #{parentId,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=INTEGER},
      </if>
      <if test="icon != null">
        #{icon,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="***.alatus.model.TPermission">
    update t_permission
    <set>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        code = #{code,jdbcType=VARCHAR},
      </if>
      <if test="url != null">
        url = #{url,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        `type` = #{type,jdbcType=VARCHAR},
      </if>
      <if test="parentId != null">
        parent_id = #{parentId,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=INTEGER},
      </if>
      <if test="icon != null">
        icon = #{icon,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="***.alatus.model.TPermission">
    update t_permission
    set `name` = #{name,jdbcType=VARCHAR},
      code = #{code,jdbcType=VARCHAR},
      url = #{url,jdbcType=VARCHAR},
      `type` = #{type,jdbcType=VARCHAR},
      parent_id = #{parentId,jdbcType=INTEGER},
      order_no = #{orderNo,jdbcType=INTEGER},
      icon = #{icon,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="***.alatus.mapper.TPermissionMapper">
  <resultMap id="BaseResultMap" type="***.alatus.model.TPermission">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="parent_id" jdbcType="INTEGER" property="parentId" />
    <result column="order_no" jdbcType="INTEGER" property="orderNo" />
    <result column="icon" jdbcType="VARCHAR" property="icon" />
  </resultMap>
  <resultMap id="PermissionRoleMap" type="***.alatus.model.TPermission">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="url" jdbcType="VARCHAR" property="url" />
    <result column="type" jdbcType="VARCHAR" property="type" />
    <result column="parent_id" jdbcType="INTEGER" property="parentId" />
    <result column="order_no" jdbcType="INTEGER" property="orderNo" />
    <result column="icon" jdbcType="VARCHAR" property="icon" />
<!--    一对多-->
    <collection property="subPermissionList" ofType="***.alatus.model.TPermission">
      <id column="cid" jdbcType="INTEGER" property="id" />
      <result column="***ame" jdbcType="VARCHAR" property="name" />
      <result column="curl" jdbcType="VARCHAR" property="url" />
      <result column="cicon" jdbcType="VARCHAR" property="icon" />
    </collection>
  </resultMap>
  
  <sql id="Base_Column_List">
    id, `name`, code, url, `type`, parent_id, order_no, icon
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_permission
    where id = #{id,jdbcType=INTEGER}
  </select>


  <select id="selectMenuPermissionByUserId" parameterType="java.lang.Integer" resultMap="PermissionRoleMap">
    SELECT
      tp.*,
      childTp.`id` cid,childTp.`name` ***ame,childTp.`url` curl,childTp.`icon` cicon
    FROM
      t_permission tp
        LEFT JOIN t_permission childTp
                  ON tp.`id` = childTp.`parent_id`
        LEFT JOIN t_role_permission trp
                  ON tp.`id` = trp.`permission_id`
        LEFT JOIN t_role tr
                  ON tr.`id` = trp.`role_id`
        LEFT JOIN t_user_role tur
                  ON tur.`role_id` = tr.`id`
    WHERE
      tp.type = 'menu' and childTp.`type` = 'menu'
      and tur.`user_id` = #{id,jdbcType=INTEGER}
  </select>


    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_permission
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="***.alatus.model.TPermission" useGeneratedKeys="true">
    insert into t_permission (`name`, code, url, 
      `type`, parent_id, order_no, 
      icon)
    values (#{name,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, 
      #{type,jdbcType=VARCHAR}, #{parentId,jdbcType=INTEGER}, #{orderNo,jdbcType=INTEGER}, 
      #{icon,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="***.alatus.model.TPermission" useGeneratedKeys="true">
    insert into t_permission
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="name != null">
        `name`,
      </if>
      <if test="code != null">
        code,
      </if>
      <if test="url != null">
        url,
      </if>
      <if test="type != null">
        `type`,
      </if>
      <if test="parentId != null">
        parent_id,
      </if>
      <if test="orderNo != null">
        order_no,
      </if>
      <if test="icon != null">
        icon,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        #{code,jdbcType=VARCHAR},
      </if>
      <if test="url != null">
        #{url,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=VARCHAR},
      </if>
      <if test="parentId != null">
        #{parentId,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        #{orderNo,jdbcType=INTEGER},
      </if>
      <if test="icon != null">
        #{icon,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="***.alatus.model.TPermission">
    update t_permission
    <set>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="code != null">
        code = #{code,jdbcType=VARCHAR},
      </if>
      <if test="url != null">
        url = #{url,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        `type` = #{type,jdbcType=VARCHAR},
      </if>
      <if test="parentId != null">
        parent_id = #{parentId,jdbcType=INTEGER},
      </if>
      <if test="orderNo != null">
        order_no = #{orderNo,jdbcType=INTEGER},
      </if>
      <if test="icon != null">
        icon = #{icon,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="***.alatus.model.TPermission">
    update t_permission
    set `name` = #{name,jdbcType=VARCHAR},
      code = #{code,jdbcType=VARCHAR},
      url = #{url,jdbcType=VARCHAR},
      `type` = #{type,jdbcType=VARCHAR},
      parent_id = #{parentId,jdbcType=INTEGER},
      order_no = #{orderNo,jdbcType=INTEGER},
      icon = #{icon,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
package ***.alatus.model;

import java.io.Serializable;
import java.util.List;

import lombok.Data;

/**
 * 权限表
 * t_permission
 */
@Data
public class TPermission implements Serializable {
    private Integer id;

    private String name;

    private String code;

    private String url;

    private String type;

    private Integer parentId;

    private Integer orderNo;

    private String icon;

    private List<TPermission> subPermissionList;

    private static final long serialVersionUID = 1L;
}
package ***.alatus.model;

import java.io.Serializable;
import java.util.List;

import lombok.Data;

/**
 * 权限表
 * t_permission
 */
@Data
public class TPermission implements Serializable {
    private Integer id;

    private String name;

    private String code;

    private String url;

    private String type;

    private Integer parentId;

    private Integer orderNo;

    private String icon;

    private List<TPermission> subPermissionList;

    private static final long serialVersionUID = 1L;
}
package ***.alatus.manager;

import ***.alatus.mapper.TPermissionMapper;
import ***.alatus.mapper.TRoleMapper;
import ***.alatus.model.TPermission;
import ***.alatus.model.TRole;
import ***.alatus.model.TUser;
import jakarta.annotation.Resource;
import org.springframework.stereotype.***ponent;

import java.util.ArrayList;
import java.util.List;

@***ponent
public class UserManager {
    //    注入角色的Mapper
    @Resource
    private TRoleMapper tRoleMapper;
    @Resource
    private TPermissionMapper tPermissionMapper;

    public List<String> loadRoleListByUser(TUser tUser){
//        查询一下当前登录的角色
        List<TRole> tRoleList = tRoleMapper.selectByUserId(tUser.getId());
        List<String> roleList = new ArrayList<>();
        tRoleList.forEach(tRole -> {
            roleList.add(tRole.getRole());
        });
        return roleList;
    }
    public List<TPermission> getMenuPermissionList(TUser tUser){
        List<TPermission> menuPermissionList = tPermissionMapper.selectMenuPermissionByUserId(tUser.getId());
        return menuPermissionList;
    }
}
package ***.alatus.manager;

import ***.alatus.mapper.TPermissionMapper;
import ***.alatus.mapper.TRoleMapper;
import ***.alatus.model.TPermission;
import ***.alatus.model.TRole;
import ***.alatus.model.TUser;
import jakarta.annotation.Resource;
import org.springframework.stereotype.***ponent;

import java.util.ArrayList;
import java.util.List;

@***ponent
public class UserManager {
    //    注入角色的Mapper
    @Resource
    private TRoleMapper tRoleMapper;
    @Resource
    private TPermissionMapper tPermissionMapper;

    public List<String> loadRoleListByUser(TUser tUser){
//        查询一下当前登录的角色
        List<TRole> tRoleList = tRoleMapper.selectByUserId(tUser.getId());
        List<String> roleList = new ArrayList<>();
        tRoleList.forEach(tRole -> {
            roleList.add(tRole.getRole());
        });
        return roleList;
    }
    public List<TPermission> getMenuPermissionList(TUser tUser){
        List<TPermission> menuPermissionList = tPermissionMapper.selectMenuPermissionByUserId(tUser.getId());
        return menuPermissionList;
    }
}
package ***.alatus.manager;

import ***.alatus.mapper.TClueMapper;
import ***.alatus.mapper.TCustomerMapper;
import ***.alatus.model.TClue;
import ***.alatus.model.TCustomer;
import ***.alatus.query.CustomerQuery;
import ***.alatus.util.JWTUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.***ponent;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@***ponent
public class CustomerManager {
    @Resource
    private TCustomerMapper tCustomerMapper;
    @Resource
    private TClueMapper tClueMapper;

    @Transactional(rollbackFor = Exception.class)
    public Boolean transferCustomer(CustomerQuery customerQuery) {
        TClue tClue = tClueMapper.selectByPrimaryKey(customerQuery.getClueId());
        if(tClue.getState() == -1){
            throw new RuntimeException("该线索已被使用");
        }
        else{
            TCustomer tCustomer = new TCustomer();
            BeanUtils.copyProperties(customerQuery,tCustomer);
            tCustomer.setCreateTime(new Date());
            tCustomer.setCreateBy(JWTUtils.parseUserFromJWT(customerQuery.getToken()).getId());
            tCustomerMapper.insert(tCustomer);
            TClue clue = new TClue();
            clue.setId(customerQuery.getClueId());
            clue.setState(-1);
            tClueMapper.updateByPrimaryKeySelective(clue);
            return true;
        }
    }
}
package ***.alatus.manager;

import ***.alatus.mapper.TClueMapper;
import ***.alatus.mapper.TCustomerMapper;
import ***.alatus.model.TClue;
import ***.alatus.model.TCustomer;
import ***.alatus.query.CustomerQuery;
import ***.alatus.util.JWTUtils;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.***ponent;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@***ponent
public class CustomerManager {
    @Resource
    private TCustomerMapper tCustomerMapper;
    @Resource
    private TClueMapper tClueMapper;

    @Transactional(rollbackFor = Exception.class)
    public Boolean transferCustomer(CustomerQuery customerQuery) {
        TClue tClue = tClueMapper.selectByPrimaryKey(customerQuery.getClueId());
        if(tClue.getState() == -1){
            throw new RuntimeException("该线索已被使用");
        }
        else{
            TCustomer tCustomer = new TCustomer();
            BeanUtils.copyProperties(customerQuery,tCustomer);
            tCustomer.setCreateTime(new Date());
            tCustomer.setCreateBy(JWTUtils.parseUserFromJWT(customerQuery.getToken()).getId());
            tCustomerMapper.insert(tCustomer);
            TClue clue = new TClue();
            clue.setId(customerQuery.getClueId());
            clue.setState(-1);
            tClueMapper.updateByPrimaryKeySelective(clue);
            return true;
        }
    }
}
转载请说明出处内容投诉
CSS教程_站长资源网 » CRM项目后端将用户的权限提交到前端实现对应权限进行对应操作------CRM项目

发表评论

欢迎 访客 发表评论

一个令你着迷的主题!

查看演示 官网购买