CRM项目使用AOP切面实现在用户登录封装权限并根据权限查询对应数据获取对应的用户信息------CRM项目

package com.alatus.aspect;

import com.alatus.commons.DataScope;
import com.alatus.constant.Constants;
import com.alatus.model.TUser;
import com.alatus.query.BaseQuery;
import com.alatus.util.JWTUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.List;

@Component
@Aspect
public class DataScopeAspect {
    @Pointcut(value = "@annotation(com.alatus.commons.DataScope)")
    private void pointCut(){

    }

    @Around(value = "pointCut()")
    public Object process(ProceedingJoinPoint joinPoint) throws Throwable {
//        通过连接点获得签名对象
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
//        转为签名方法对象获得方法(源方法)在原方法上获取指定注解
        DataScope dataScope = methodSignature.getMethod().getDeclaredAnnotation(DataScope.class);
        String tableAlias = dataScope.tableAlias();
        String tableField = dataScope.tableField();
//        在web容器获取当前请求的request对象
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//        从请求头中获取我们的token
        String token = request.getHeader(Constants.TOKEN_NAME);
//        解析token
        TUser tUser = JWTUtils.parseUserFromJWT(token);
//        已经获取了用户的角色
        List<String> roleList = tUser.getRoleList();
//        不包含管理员角色,查自己的数据,拼装SQL
        if (!roleList.contains("admin")) {
//            获取这个方法的形参的第一个参数
            Object params = joinPoint.getArgs()[0];
            if(params instanceof BaseQuery){
                BaseQuery query = (BaseQuery)params;
                query.setFilterSQL(" and "+tableAlias+"."+tableField+"="+tUser.getId());
            }
        }
//        joinPoint.proceed()前是方法执行前
//        如果还有业务代码可以提取出来,写到后面去
        return joinPoint.proceed();
    }
}
package com.alatus.aspect;

import com.alatus.commons.DataScope;
import com.alatus.constant.Constants;
import com.alatus.model.TUser;
import com.alatus.query.BaseQuery;
import com.alatus.util.JWTUtils;
import jakarta.servlet.http.HttpServletRequest;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.List;

@Component
@Aspect
public class DataScopeAspect {
    @Pointcut(value = "@annotation(com.alatus.commons.DataScope)")
    private void pointCut(){

    }

    @Around(value = "pointCut()")
    public Object process(ProceedingJoinPoint joinPoint) throws Throwable {
//        通过连接点获得签名对象
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
//        转为签名方法对象获得方法(源方法)在原方法上获取指定注解
        DataScope dataScope = methodSignature.getMethod().getDeclaredAnnotation(DataScope.class);
        String tableAlias = dataScope.tableAlias();
        String tableField = dataScope.tableField();
//        在web容器获取当前请求的request对象
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//        从请求头中获取我们的token
        String token = request.getHeader(Constants.TOKEN_NAME);
//        解析token
        TUser tUser = JWTUtils.parseUserFromJWT(token);
//        已经获取了用户的角色
        List<String> roleList = tUser.getRoleList();
//        不包含管理员角色,查自己的数据,拼装SQL
        if (!roleList.contains("admin")) {
//            获取这个方法的形参的第一个参数
            Object params = joinPoint.getArgs()[0];
            if(params instanceof BaseQuery){
                BaseQuery query = (BaseQuery)params;
                query.setFilterSQL(" and "+tableAlias+"."+tableField+"="+tUser.getId());
            }
        }
//        joinPoint.proceed()前是方法执行前
//        如果还有业务代码可以提取出来,写到后面去
        return joinPoint.proceed();
    }
}
<?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="com.alatus.mapper.TRoleMapper">
  <resultMap id="BaseResultMap" type="com.alatus.model.TRole">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="role" jdbcType="VARCHAR" property="role" />
    <result column="role_name" jdbcType="VARCHAR" property="roleName" />
  </resultMap>
  <sql id="Base_Column_List">
    id, `role`, role_name
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_role
    where id = #{id,jdbcType=INTEGER}
  </select>

  <select id="selectByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
      tr.*
    from t_role tr left join t_user_role tur on tr.id = tur.role_id
    where tur.user_id = #{userId, jdbcType=INTEGER}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_role
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TRole" useGeneratedKeys="true">
    insert into t_role (`role`, role_name)
    values (#{role,jdbcType=VARCHAR}, #{roleName,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TRole" useGeneratedKeys="true">
    insert into t_role
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="role != null">
        `role`,
      </if>
      <if test="roleName != null">
        role_name,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="role != null">
        #{role,jdbcType=VARCHAR},
      </if>
      <if test="roleName != null">
        #{roleName,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.alatus.model.TRole">
    update t_role
    <set>
      <if test="role != null">
        `role` = #{role,jdbcType=VARCHAR},
      </if>
      <if test="roleName != null">
        role_name = #{roleName,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.alatus.model.TRole">
    update t_role
    set `role` = #{role,jdbcType=VARCHAR},
      role_name = #{roleName,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="com.alatus.mapper.TRoleMapper">
  <resultMap id="BaseResultMap" type="com.alatus.model.TRole">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="role" jdbcType="VARCHAR" property="role" />
    <result column="role_name" jdbcType="VARCHAR" property="roleName" />
  </resultMap>
  <sql id="Base_Column_List">
    id, `role`, role_name
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_role
    where id = #{id,jdbcType=INTEGER}
  </select>

  <select id="selectByUserId" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select
      tr.*
    from t_role tr left join t_user_role tur on tr.id = tur.role_id
    where tur.user_id = #{userId, jdbcType=INTEGER}
  </select>

  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_role
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TRole" useGeneratedKeys="true">
    insert into t_role (`role`, role_name)
    values (#{role,jdbcType=VARCHAR}, #{roleName,jdbcType=VARCHAR})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TRole" useGeneratedKeys="true">
    insert into t_role
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="role != null">
        `role`,
      </if>
      <if test="roleName != null">
        role_name,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="role != null">
        #{role,jdbcType=VARCHAR},
      </if>
      <if test="roleName != null">
        #{roleName,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.alatus.model.TRole">
    update t_role
    <set>
      <if test="role != null">
        `role` = #{role,jdbcType=VARCHAR},
      </if>
      <if test="roleName != null">
        role_name = #{roleName,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.alatus.model.TRole">
    update t_role
    set `role` = #{role,jdbcType=VARCHAR},
      role_name = #{roleName,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
package com.alatus.mapper;

import com.alatus.model.TRole;

import java.util.List;

public interface TRoleMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TRole record);

    int insertSelective(TRole record);

    TRole selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TRole record);

    int updateByPrimaryKey(TRole record);

    List<TRole> selectByUserId(Integer userId);
}
package com.alatus.mapper;

import com.alatus.model.TRole;

import java.util.List;

public interface TRoleMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TRole record);

    int insertSelective(TRole record);

    TRole selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TRole record);

    int updateByPrimaryKey(TRole record);

    List<TRole> selectByUserId(Integer userId);
}
<?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="com.alatus.mapper.TUserMapper">
  <resultMap id="BaseResultMap" type="com.alatus.model.TUser">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="login_act" jdbcType="VARCHAR" property="loginAct" />
    <result column="login_pwd" jdbcType="VARCHAR" property="loginPwd" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="account_no_expired" jdbcType="INTEGER" property="accountNoExpired" />
    <result column="credentials_no_expired" jdbcType="INTEGER" property="credentialsNoExpired" />
    <result column="account_no_locked" jdbcType="INTEGER" property="accountNoLocked" />
    <result column="account_enabled" jdbcType="INTEGER" property="accountEnabled" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
  </resultMap>
  <resultMap id="UserDetailResultMap" type="com.alatus.model.TUser">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="login_act" jdbcType="VARCHAR" property="loginAct" />
    <result column="login_pwd" jdbcType="VARCHAR" property="loginPwd" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="account_no_expired" jdbcType="INTEGER" property="accountNoExpired" />
    <result column="credentials_no_expired" jdbcType="INTEGER" property="credentialsNoExpired" />
    <result column="account_no_locked" jdbcType="INTEGER" property="accountNoLocked" />
    <result column="account_enabled" jdbcType="INTEGER" property="accountEnabled" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
    <!--一对一关联-->
    <association property="createByPO" javaType="com.alatus.model.TUser">
      <id column="createById" jdbcType="INTEGER" property="id" />
      <result column="createByName" jdbcType="VARCHAR" property="name" />
    </association>
    <!--一对一关联-->
    <association property="editByPO" javaType="com.alatus.model.TUser">
      <id column="editById" jdbcType="INTEGER" property="id" />
      <result column="editName" jdbcType="VARCHAR" property="name" />
    </association>
  </resultMap>

  <sql id="Base_Column_List">
    id, login_act, login_pwd, `name`, phone, email, account_no_expired, credentials_no_expired, 
    account_no_locked, account_enabled, create_time, create_by, edit_time, edit_by, last_login_time
  </sql>
  <select id="selectByLoginAct" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user
    where login_act = #{username,jdbcType=VARCHAR}
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_user
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectDetailByPrimaryKey" parameterType="java.lang.Integer" resultMap="UserDetailResultMap">
    select
      tu.*,
      tu2.id createById, tu2.name createByName,
      tu3.id editById, tu3.name editName
    from t_user tu left join t_user tu2 on tu.create_by = tu2.id
                   left join t_user tu3 on tu.edit_by = tu3.id
    where tu.id = #{id, jdbcType=INTEGER}
  </select>
  <select id="selectUserByPage" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user as tu
    <where>
      ${filterSQL}
    </where>
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_user
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByIds" parameterType="java.util.List">
    delete from t_user
    where id in 
    <foreach collection="idList" item="id" open="(" close=")" separator=",">
        #{id,jdbcType=INTEGER}
    </foreach>
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TUser" useGeneratedKeys="true">
    insert into t_user (login_act, login_pwd, `name`, 
      phone, email, a
ccount_no_expired,
      credentials_no_expired, account_no_locked, 
      account_enabled, create_time, create_by, 
      edit_time, edit_by, last_login_time
      )
    values (#{loginAct,jdbcType=VARCHAR}, #{loginPwd,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
      #{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{accountNoExpired,jdbcType=INTEGER}, 
      #{credentialsNoExpired,jdbcType=INTEGER}, #{accountNoLocked,jdbcType=INTEGER}, 
      #{accountEnabled,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=INTEGER}, 
      #{editTime,jdbcType=TIMESTAMP}, #{editBy,jdbcType=INTEGER}, #{lastLoginTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TUser" useGeneratedKeys="true">
    insert into t_user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="loginAct != null">
        login_act,
      </if>
      <if test="loginPwd != null">
        login_pwd,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="email != null">
        email,
      </if>
      <if test="accountNoExpired != null">
        account_no_expired,
      </if>
      <if test="credentialsNoExpired != null">
        credentials_no_expired,
      </if>
      <if test="accountNoLocked != null">
        account_no_locked,
      </if>
      <if test="accountEnabled != null">
        account_enabled,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="editTime != null">
        edit_time,
      </if>
      <if test="editBy != null">
        edit_by,
      </if>
      <if test="lastLoginTime != null">
        last_login_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="loginAct != null">
        #{loginAct,jdbcType=VARCHAR},
      </if>
      <if test="loginPwd != null">
        #{loginPwd,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="accountNoExpired != null">
        #{accountNoExpired,jdbcType=INTEGER},
      </if>
      <if test="credentialsNoExpired != null">
        #{credentialsNoExpired,jdbcType=INTEGER},
      </if>
      <if test="accountNoLocked != null">
        #{accountNoLocked,jdbcType=INTEGER},
      </if>
      <if test="accountEnabled != null">
        #{accountEnabled,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        #{editBy,jdbcType=INTEGER},
      </if>
      <if test="lastLoginTime != null">
        #{lastLoginTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.alatus.model.TUser">
    update t_user
    <set>
      <if test="loginAct != null">
        login_act = #{loginAct,jdbcType=VARCHAR},
      </if>
      <if test="loginPwd != null and loginPwd != ''">
        login_pwd = #{loginPwd,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="accountNoExpired != null">
        account_no_expired = #{accountNoExpired,jdbcType=INTEGER},
      </if>
      <if test="credentialsNoExpired != null">
        credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},
      </if>
      <if test="accountNoLocked != null">
        account_no_locked = #{accountNoLocked,jdbcType=INTEGER},
      </if>
      <if test="accountEnabled != null">
        account_enabled = #{accountEnabled,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        edit_time = #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        edit_by = #{editBy,jdbcType=INTEGER},
      </if>
      <if test="lastLoginTime != null">
        last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.alatus.model.TUser">
    update t_user
    set login_act = #{loginAct,jdbcType=VARCHAR},
      login_pwd = #{loginPwd,jdbcType=VARCHAR},
      `name` = #{name,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      account_no_expired = #{accountNoExpired,jdbcType=INTEGER},
      credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},
      account_no_locked = #{accountNoLocked,jdbcType=INTEGER},
      account_enabled = #{accountEnabled,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_by = #{createBy,jdbcType=INTEGER},
      edit_time = #{editTime,jdbcType=TIMESTAMP},
      edit_by = #{editBy,jdbcType=INTEGER},
      last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP}
    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="com.alatus.mapper.TUserMapper">
  <resultMap id="BaseResultMap" type="com.alatus.model.TUser">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="login_act" jdbcType="VARCHAR" property="loginAct" />
    <result column="login_pwd" jdbcType="VARCHAR" property="loginPwd" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="account_no_expired" jdbcType="INTEGER" property="accountNoExpired" />
    <result column="credentials_no_expired" jdbcType="INTEGER" property="credentialsNoExpired" />
    <result column="account_no_locked" jdbcType="INTEGER" property="accountNoLocked" />
    <result column="account_enabled" jdbcType="INTEGER" property="accountEnabled" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
  </resultMap>
  <resultMap id="UserDetailResultMap" type="com.alatus.model.TUser">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="login_act" jdbcType="VARCHAR" property="loginAct" />
    <result column="login_pwd" jdbcType="VARCHAR" property="loginPwd" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="phone" jdbcType="VARCHAR" property="phone" />
    <result column="email" jdbcType="VARCHAR" property="email" />
    <result column="account_no_expired" jdbcType="INTEGER" property="accountNoExpired" />
    <result column="credentials_no_expired" jdbcType="INTEGER" property="credentialsNoExpired" />
    <result column="account_no_locked" jdbcType="INTEGER" property="accountNoLocked" />
    <result column="account_enabled" jdbcType="INTEGER" property="accountEnabled" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="last_login_time" jdbcType="TIMESTAMP" property="lastLoginTime" />
    <!--一对一关联-->
    <association property="createByPO" javaType="com.alatus.model.TUser">
      <id column="createById" jdbcType="INTEGER" property="id" />
      <result column="createByName" jdbcType="VARCHAR" property="name" />
    </association>
    <!--一对一关联-->
    <association property="editByPO" javaType="com.alatus.model.TUser">
      <id column="editById" jdbcType="INTEGER" property="id" />
      <result column="editName" jdbcType="VARCHAR" property="name" />
    </association>
  </resultMap>

  <sql id="Base_Column_List">
    id, login_act, login_pwd, `name`, phone, email, account_no_expired, credentials_no_expired, 
    account_no_locked, account_enabled, create_time, create_by, edit_time, edit_by, last_login_time
  </sql>
  <select id="selectByLoginAct" parameterType="java.lang.String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user
    where login_act = #{username,jdbcType=VARCHAR}
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_user
    where id = #{id,jdbcType=INTEGER}
  </select>
  <select id="selectDetailByPrimaryKey" parameterType="java.lang.Integer" resultMap="UserDetailResultMap">
    select
      tu.*,
      tu2.id createById, tu2.name createByName,
      tu3.id editById, tu3.name editName
    from t_user tu left join t_user tu2 on tu.create_by = tu2.id
                   left join t_user tu3 on tu.edit_by = tu3.id
    where tu.id = #{id, jdbcType=INTEGER}
  </select>
  <select id="selectUserByPage" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from t_user as tu
    <where>
      ${filterSQL}
    </where>
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_user
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByIds" parameterType="java.util.List">
    delete from t_user
    where id in 
    <foreach collection="idList" item="id" open="(" close=")" separator=",">
        #{id,jdbcType=INTEGER}
    </foreach>
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TUser" useGeneratedKeys="true">
    insert into t_user (login_act, login_pwd, `name`, 
      phone, email, a
ccount_no_expired,
      credentials_no_expired, account_no_locked, 
      account_enabled, create_time, create_by, 
      edit_time, edit_by, last_login_time
      )
    values (#{loginAct,jdbcType=VARCHAR}, #{loginPwd,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, 
      #{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{accountNoExpired,jdbcType=INTEGER}, 
      #{credentialsNoExpired,jdbcType=INTEGER}, #{accountNoLocked,jdbcType=INTEGER}, 
      #{accountEnabled,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, #{createBy,jdbcType=INTEGER}, 
      #{editTime,jdbcType=TIMESTAMP}, #{editBy,jdbcType=INTEGER}, #{lastLoginTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TUser" useGeneratedKeys="true">
    insert into t_user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="loginAct != null">
        login_act,
      </if>
      <if test="loginPwd != null">
        login_pwd,
      </if>
      <if test="name != null">
        `name`,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="email != null">
        email,
      </if>
      <if test="accountNoExpired != null">
        account_no_expired,
      </if>
      <if test="credentialsNoExpired != null">
        credentials_no_expired,
      </if>
      <if test="accountNoLocked != null">
        account_no_locked,
      </if>
      <if test="accountEnabled != null">
        account_enabled,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="editTime != null">
        edit_time,
      </if>
      <if test="editBy != null">
        edit_by,
      </if>
      <if test="lastLoginTime != null">
        last_login_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="loginAct != null">
        #{loginAct,jdbcType=VARCHAR},
      </if>
      <if test="loginPwd != null">
        #{loginPwd,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        #{name,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        #{email,jdbcType=VARCHAR},
      </if>
      <if test="accountNoExpired != null">
        #{accountNoExpired,jdbcType=INTEGER},
      </if>
      <if test="credentialsNoExpired != null">
        #{credentialsNoExpired,jdbcType=INTEGER},
      </if>
      <if test="accountNoLocked != null">
        #{accountNoLocked,jdbcType=INTEGER},
      </if>
      <if test="accountEnabled != null">
        #{accountEnabled,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        #{editBy,jdbcType=INTEGER},
      </if>
      <if test="lastLoginTime != null">
        #{lastLoginTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.alatus.model.TUser">
    update t_user
    <set>
      <if test="loginAct != null">
        login_act = #{loginAct,jdbcType=VARCHAR},
      </if>
      <if test="loginPwd != null and loginPwd != ''">
        login_pwd = #{loginPwd,jdbcType=VARCHAR},
      </if>
      <if test="name != null">
        `name` = #{name,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=VARCHAR},
      </if>
      <if test="email != null">
        email = #{email,jdbcType=VARCHAR},
      </if>
      <if test="accountNoExpired != null">
        account_no_expired = #{accountNoExpired,jdbcType=INTEGER},
      </if>
      <if test="credentialsNoExpired != null">
        credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},
      </if>
      <if test="accountNoLocked != null">
        account_no_locked = #{accountNoLocked,jdbcType=INTEGER},
      </if>
      <if test="accountEnabled != null">
        account_enabled = #{accountEnabled,jdbcType=INTEGER},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        edit_time = #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        edit_by = #{editBy,jdbcType=INTEGER},
      </if>
      <if test="lastLoginTime != null">
        last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.alatus.model.TUser">
    update t_user
    set login_act = #{loginAct,jdbcType=VARCHAR},
      login_pwd = #{loginPwd,jdbcType=VARCHAR},
      `name` = #{name,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=VARCHAR},
      email = #{email,jdbcType=VARCHAR},
      account_no_expired = #{accountNoExpired,jdbcType=INTEGER},
      credentials_no_expired = #{credentialsNoExpired,jdbcType=INTEGER},
      account_no_locked = #{accountNoLocked,jdbcType=INTEGER},
      account_enabled = #{accountEnabled,jdbcType=INTEGER},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_by = #{createBy,jdbcType=INTEGER},
      edit_time = #{editTime,jdbcType=TIMESTAMP},
      edit_by = #{editBy,jdbcType=INTEGER},
      last_login_time = #{lastLoginTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
---
spring:
  data:
    redis:
      lettuce:
        pool:
          max-idle: 8
          min-idle: 0
          max-wait: -1ms
          max-active: 8
        cluster:
          refresh:
            adaptive: true
            period: 2000
      cluster:
        max-redirects: 3
        nodes: 192.168.189.128:6381,192.168.189.128:6382,192.168.189.130:6383,192.168.189.130:6384,192.168.189.129:6385,192.168.189.129:6386
      password: abc123
      timeout: 5000
---
server:
  port: 8089
  servlet:
    context-path: /
    session:
      persistent: false
---
spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/dlyk?useUnicode=true&characterEncoding=utf-8&useSSL=false
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: abc123
    hikari:
      maximum-pool-size: 30
      minimum-idle: 30
      connection-timeout: 5000
      idle-timeout: 0
      max-lifetime: 18000000
#  设置jackson返回json数据时的时区格式
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss
---
mybatis:
  mapper-locations: classpath:mapper/*.xml
  configuration:
#    控制台打印SQL语句
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
---
spring:
  data:
    redis:
      lettuce:
        pool:
          max-idle: 8
          min-idle: 0
          max-wait: -1ms
          max-active: 8
        cluster:
          refresh:
            adaptive: true
            period: 2000
      cluster:
        max-redirects: 3
        nodes: 192.168.189.128:6381,192.168.189.128:6382,192.168.189.130:6383,192.168.189.130:6384,192.168.189.129:6385,192.168.189.129:6386
      password: abc123
      timeout: 5000
---
server:
  port: 8089
  servlet:
    context-path: /
    session:
      persistent: false
---
spring:
  datasource:
    url: jdbc:mysql://127.0.0.1:3306/dlyk?useUnicode=true&characterEncoding=utf-8&useSSL=false
    driver-class-name: com.mysql.cj.jdbc.Driver
    username: root
    password: abc123
    hikari:
      maximum-pool-size: 30
      minimum-idle: 30
      connection-timeout: 5000
      idle-timeout: 0
      max-lifetime: 18000000
#  设置jackson返回json数据时的时区格式
  jackson:
    time-zone: GMT+8
    date-format: yyyy-MM-dd HH:mm:ss
---
mybatis:
  mapper-locations: classpath:mapper/*.xml
  configuration:
#    控制台打印SQL语句
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
package com.alatus.mapper;

import com.alatus.commons.DataScope;
import com.alatus.model.TUser;
import com.alatus.query.BaseQuery;

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

public interface TUserMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TUser record);

    int insertSelective(TUser record);

    TUser selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TUser record);

    int updateByPrimaryKey(TUser record);

    TUser selectByLoginAct(String username);
    @DataScope(tableAlias = "tu",tableField = "id")
    ArrayList<TUser> selectUserByPage(BaseQuery query);

    TUser selectDetailByPrimaryKey(Integer id);

    int deleteByIds(List<String> idList);
}
package com.alatus.mapper;

import com.alatus.commons.DataScope;
import com.alatus.model.TUser;
import com.alatus.query.BaseQuery;

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

public interface TUserMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(TUser record);

    int insertSelective(TUser record);

    TUser selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(TUser record);

    int updateByPrimaryKey(TUser record);

    TUser selectByLoginAct(String username);
    @DataScope(tableAlias = "tu",tableField = "id")
    ArrayList<TUser> selectUserByPage(BaseQuery query);

    TUser selectDetailByPrimaryKey(Integer id);

    int deleteByIds(List<String> idList);
}
  • 23
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

旧约Alatus

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值