liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<?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>