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
<?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.role.entity.SysRoleFunctionitem">
 
  <resultMap id="BaseResultMap" type="cn.com.basic.role.entity.SysRoleFunctionitem" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="role_id" property="roleId" jdbcType="VARCHAR" />
    <result column="function_item_id" property="functionItemId" 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="SysFunctionItemTree" type="cn.com.basic.role.entity.SysRoleFunctionItemTree">
    <result column="function_item_id" property="functionItemId" jdbcType="VARCHAR" />
    <result column="role_id" property="roleId" jdbcType="VARCHAR" />
    <result column="name" property="name" jdbcType="VARCHAR" />
    <result column="pid" property="pid" jdbcType="VARCHAR" />
    <result column="src_url" property="srcUrl" jdbcType="VARCHAR" />
    <result column="target_url" property="targetUrl" jdbcType="VARCHAR" />
    <result column="url_param" property="urlParam" jdbcType="VARCHAR" />
    <result column="order_num" property="orderNum" jdbcType="BIGINT" />
    <result column="privilege" property="privilege" jdbcType="BIGINT" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, role_id, function_item_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="roleId != null" >
          and role_id = #{roleId,jdbcType=VARCHAR}
        </if>
        <if test="functionItemId != null" >
          and function_item_id = #{functionItemId,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_role_functionitem
    <include refid="Base_Where_Clause" />
  </select>
 
  <!-- 查询 -->
  <select id="select" resultMap="BaseResultMap" parameterType="java.util.Map">
    select
    <include refid="Base_Column_List" />
    from re_sys_role_functionitem
    <include refid="Base_Where_Clause" />
  </select>
  <!-- 根据ID删除-->
  <delete id="deleteById" parameterType="java.lang.String">
    delete from
    re_sys_role_functionitem
    where ID = #{id}
  </delete>
 
  <delete id="delete" parameterType="java.util.Map">
    update re_sys_role_functionitem
    set is_valid=0
    <include refid="Base_Where_Clause" />
  </delete>
 
  <!-- 根据ID查询 -->
  <select id="selectById" resultMap="BaseResultMap" parameterType="java.lang.String">
    select
    <include refid="Base_Column_List" />
    from re_sys_role_functionitem
    where ID = #{id}
  </select>
  <!-- 添加 -->
  <insert id="insert" parameterType="cn.com.basic.role.entity.SysRoleFunctionitem">
    insert into re_sys_role_functionitem (id, role_id, function_item_id,
      privilege, is_valid, update_time,
      update_user_id)
    values (#{id,jdbcType=VARCHAR}, #{roleId,jdbcType=VARCHAR}, #{functionItemId,jdbcType=VARCHAR},
      #{privilege,jdbcType=BIGINT}, #{isValid,jdbcType=TINYINT}, #{updateTime,jdbcType=TIMESTAMP},
      #{updateUserId,jdbcType=VARCHAR})
  </insert>
 
  <!-- 通过ID更新 -->
  <update id="updateByIdSelective" parameterType="cn.com.basic.role.entity.SysRoleFunctionitem">
    update re_sys_role_functionitem
    <set >
      <if test="roleId != null" >
        role_id = #{roleId,jdbcType=VARCHAR},
      </if>
      <if test="functionItemId != null" >
        function_item_id = #{functionItemId,jdbcType=VARCHAR},
      </if>
      <if test="privilege != null" >
        privilege = #{privilege,jdbcType=BIGINT},
      </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_role_functionitem
    where
    <foreach collection="array" item="id" open="id in (" close=")" separator=",">
      '${id}'
    </foreach>
  </delete>
 
  <!-- 查询当前角色的功能树列表 -->
  <select id="getSysFunctionItemTreeByRoleId" resultMap="SysFunctionItemTree" parameterType="java.lang.String">
    select *
    from v_sys_role_function_item_tree
    where role_id = #{roleId}
    order by order_num
  </select>
</mapper>