<?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="cn.com.basic.user.entity.SysUserRole">
|
|
<resultMap id="BaseResultMap" type="cn.com.basic.user.entity.SysUserRole" >
|
<id column="id" property="id" jdbcType="VARCHAR" />
|
<result column="user_id" property="userId" jdbcType="VARCHAR" />
|
<result column="role_id" property="roleId" jdbcType="VARCHAR" />
|
<result column="is_valid" property="isValid" jdbcType="TINYINT" />
|
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP" />
|
<result column="update_user_id" property="updateUserId" jdbcType="VARCHAR" />
|
</resultMap>
|
|
<resultMap id="SysUserRoleRangeType" type="cn.com.basic.user.entity.SysUserRoleRangeType" >
|
<result column="user_id" property="userId" jdbcType="VARCHAR" />
|
<result column="role_id" property="roleId" jdbcType="VARCHAR" />
|
<result column="data_range_type" property="dataRangeType" jdbcType="TINYINT" />
|
</resultMap>
|
|
<sql id="Base_Column_List" >
|
id, user_id, role_id, is_valid, update_time, update_user_id
|
</sql>
|
|
<sql id="Base_Where_Clause">
|
<where>
|
<trim prefixOverrides="and">
|
<if test="id != null"> and ID = #{id}</if>
|
<if test="userId != null" >
|
and user_id = #{userId,jdbcType=VARCHAR}
|
</if>
|
<if test="roleId != null" >
|
and role_id = #{roleId,jdbcType=VARCHAR}
|
</if>
|
<if test="isValid != null" >
|
and is_valid = #{isValid,jdbcType=TINYINT}
|
</if>
|
<if test="updateTime != null" >
|
and update_time = #{updateTime,jdbcType=TIMESTAMP}
|
</if>
|
<if test="updateUserId != null" >
|
and update_user_id = #{updateUserId,jdbcType=VARCHAR}
|
</if>
|
</trim>
|
</where>
|
<if test="sorting != null">order by ${sorting}</if>
|
<if test="offset != null and limit != null">
|
limit #{offset}, #{limit}
|
</if>
|
</sql>
|
|
<!-- 查询总数 -->
|
<select id="selectCount" resultType="java.lang.Long" parameterType="java.util.Map">
|
select count(ID)
|
from re_sys_user_role
|
<include refid="Base_Where_Clause" />
|
</select>
|
|
<!-- 查询 -->
|
<select id="select" resultMap="BaseResultMap" parameterType="java.util.Map">
|
select
|
<include refid="Base_Column_List" />
|
from re_sys_user_role
|
<include refid="Base_Where_Clause" />
|
</select>
|
<!-- 根据ID删除-->
|
<delete id="deleteById" parameterType="java.lang.String">
|
delete from
|
re_sys_user_role
|
where ID = #{id}
|
</delete>
|
|
<!-- 根据ID查询 -->
|
<select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.String">
|
select
|
<include refid="Base_Column_List" />
|
from re_sys_user_role
|
where ID = #{id}
|
</select>
|
<!-- 添加 -->
|
<insert id="insert" parameterType="cn.com.basic.user.entity.SysUserRole">
|
insert into re_sys_user_role (id, user_id, role_id,
|
is_valid, update_time, update_user_id
|
)
|
values (#{id,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{roleId,jdbcType=VARCHAR},
|
#{isValid,jdbcType=TINYINT}, #{updateTime,jdbcType=TIMESTAMP}, #{updateUserId,jdbcType=VARCHAR}
|
)
|
</insert>
|
|
<!-- 通过ID更新 -->
|
<update id="updateByIdSelective" parameterType="cn.com.basic.user.entity.SysUserRole" >
|
update re_sys_user_role
|
<set >
|
<if test="userId != null" >
|
user_id = #{userId,jdbcType=VARCHAR},
|
</if>
|
<if test="roleId != null" >
|
role_id = #{roleId,jdbcType=VARCHAR},
|
</if>
|
<if test="isValid != null" >
|
is_valid = #{isValid,jdbcType=TINYINT},
|
</if>
|
<if test="updateTime != null" >
|
update_time = #{updateTime,jdbcType=TIMESTAMP},
|
</if>
|
<if test="updateUserId != null" >
|
update_user_id = #{updateUserId,jdbcType=VARCHAR},
|
</if>
|
</set>
|
where id = #{id,jdbcType=VARCHAR}
|
</update>
|
|
<!-- 根据IDs删除 -->
|
<delete id="deleteByIds">
|
delete from
|
re_sys_user_role
|
where
|
<foreach collection="array" item="id" open="id in (" close=")" separator=",">
|
'${id}'
|
</foreach>
|
</delete>
|
<!-- 设置is_valid删除-->
|
<delete id="delete" parameterType="java.util.Map">
|
update re_sys_user_role
|
set is_valid=0
|
<include refid="Base_Where_Clause" />
|
</delete>
|
|
<!--根据userId获取role和role的datarangetype-->
|
<resultMap id="ViewResultMap" type="cn.com.basic.user.entity.ViewUserRole" >
|
<result column="data_range_type" property="dataRangeType" jdbcType="TINYINT" />
|
<result column="user_id" property="id" jdbcType="VARCHAR" />
|
<result column="role_id" property="roleId" jdbcType="VARCHAR" />
|
<result column="name" property="name" jdbcType="VARCHAR" />
|
<result column="role_org_id" property="roleOrgId" jdbcType="VARCHAR" />
|
<result column="status" property="status" jdbcType="TINYINT" />
|
<result column="user_org_id" property="userOrgId" jdbcType="VARCHAR" />
|
<result column="type" property="type" jdbcType="TINYINT" />
|
<result column="number" property="number" jdbcType="VARCHAR" />
|
<result column="is_allow_login" property="isAllowLogin" jdbcType="TINYINT" />
|
<result column="sex" property="sex" jdbcType="VARCHAR" />
|
<result column="login_name" property="loginName" jdbcType="VARCHAR" />
|
<result column="id_card" property="idCard" jdbcType="VARCHAR" />
|
<result column="real_name" property="realName" jdbcType="VARCHAR" />
|
<result column="password" property="password" jdbcType="VARCHAR" />
|
<result column="email" property="email" jdbcType="VARCHAR" />
|
<result column="mobile" property="mobile" jdbcType="VARCHAR" />
|
<result column="phone" property="phone" jdbcType="VARCHAR" />
|
<result column="birthday" property="birthday" jdbcType="DATE" />
|
<result column="logo_path" property="logoPath" jdbcType="VARCHAR" />
|
<result column="comment" property="comment" jdbcType="VARCHAR" />
|
</resultMap>
|
<select id="selectRoleAndRangeTypeByUserId" resultMap="SysUserRoleRangeType" parameterType="java.lang.String">
|
select
|
*
|
from v_sys_user_role
|
where user_id = #{user_id}
|
</select>
|
<select id="selectRoleUsers" resultMap="ViewResultMap" parameterType="java.lang.String">
|
select
|
*
|
from v_sys_user_role
|
where role_id = #{role_id}
|
</select>
|
</mapper>
|