jiangping
2023-08-17 6365ab0a976afdd247742c9b3dca15deb3a7a7a1
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?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="doumeemes.dao.system.SystemRoleMapper">
 
  <!-- 查询角色列表 -->
  <resultMap id="SystemRoleListVO" type="doumeemes.dao.system.vo.SystemRoleListVO" autoMapping="true">
    <id column="ID" property="id"/>
    <association property="createUserInfo" javaType="doumeemes.dao.system.model.SystemUser">
      <id column="CREATE_USER_ID" property="id"/>
      <result column="CREATE_USER_NAME" property="username"/>
    </association>
    <association property="updateUserInfo" javaType="doumeemes.dao.system.model.SystemUser">
      <id column="UPDATE_USER_ID" property="id"/>
      <result column="UPDATE_USER_NAME" property="username"/>
    </association>
  </resultMap>
  <insert id="insertRoleUserBatch"  useGeneratedKeys="true" keyProperty="id">
    insert into `system_user_role` (
    `USER_ID`,
    `ROLE_ID`,
    `CREATE_USER`,
    `CREATE_TIME`,
    `UPDATE_USER`,
    `UPDATE_TIME` ,
    `DELETED` ,
    `STATUS`,
    `REMARK` ,
    `VALID_TIME` ,
    `INVALID_TIME`
    )
    values
    <foreach collection="list" separator="," item="item">
      (
      #{item.userId},
      #{item.roleId},
      #{item.createUser},
      #{item.createTime},
      #{item.updateUser},
      #{item.updateTime},
      #{item.deleted},
      #{item.status},
      #{item.remark},
      #{item.validTime},
      #{item.invalidTime}
      )
    </foreach>
  </insert>
  <insert id="insertRoleMenuBatch"  useGeneratedKeys="true" keyProperty="id">
    insert into `system_role_menu` (
    `ROLE_ID`,
    `MENU_ID`,
    `CREATE_USER`,
    `CREATE_TIME`,
    `UPDATE_USER`,
    `UPDATE_TIME` ,
    `DELETED` ,
    `STATUS` ,
    `REMARK`
    )
    values
    <foreach collection="list" separator="," item="item">
      (
      #{item.roleId},
      #{item.menuId},
      #{item.createUser},
      #{item.createTime},
      #{item.updateUser},
      #{item.updateTime},
      #{item.deleted},
      #{item.status},
      #{item.remark}
      )
    </foreach>
  </insert>
  <insert id="insertRolePermissionBatch"  useGeneratedKeys="true" keyProperty="id">
    insert into `system_role_permission` (
    `ROLE_ID`,
    `PERMISSION_ID`,
    `CREATE_USER`,
    `CREATE_TIME`,
    `UPDATE_USER`,
    `UPDATE_TIME` ,
    `DELETED` ,
    `STATUS`,
    `REMARK`
    )
    values
    <foreach collection="list" separator="," item="item">
      (
      #{item.roleId},
      #{item.permissionId},
      #{item.createUser},
      #{item.createTime},
      #{item.updateUser},
      #{item.updateTime},
      #{item.deleted},
      #{item.status},
      #{item.remark}
      )
    </foreach>
  </insert>
  <insert id="insertDataPermissionBatch"  useGeneratedKeys="true" keyProperty="id">
    insert into `system_data_permission` (
    `BUSINESS_CODE`,
    `ROLE_ID`,
    `TYPE`,
    `CUSTOM_DATA`,
    `DISABLED`,
    `REMARK` ,
    `CREATE_USER` ,
    `CREATE_TIME`,
    `UPDATE_USER` ,
    `UPDATE_TIME`,
    `DELETED`
    )
    values
    <foreach collection="list" separator="," item="item">
      (
      #{item.businessCode},
      #{item.roleId},
      #{item.type},
      #{item.customData},
      #{item.disabled},
      #{item.remark},
      #{item.createUser},
      #{item.createTime},
      #{item.updateUser},
      #{item.updateTime},
      #{item.deleted}
      )
    </foreach>
  </insert>
  <select id="selectManageList" parameterType="doumeemes.dao.system.dto.QuerySystemUserDTO" resultMap="SystemRoleListVO">
    SELECT
     role.`COMPANY_ID`,role.`TYPE`, role.ID, role.`CODE`, role.`NAME`, role.`REMARK`, role.`FIXED`, role.`CREATE_TIME`, role.`UPDATE_TIME`,
      create_user.ID CREATE_USER_ID, create_user.`USERNAME` CREATE_USER_NAME,
      update_user.ID UPDETE_USER_ID, update_user.`USERNAME` UPDATE_USER_NAME
    FROM SYSTEM_ROLE role
    LEFT JOIN `SYSTEM_USER` create_user ON create_user.ID = role.CREATE_USER
    LEFT JOIN `SYSTEM_USER` update_user ON update_user.ID = role.UPDATE_USER
    <where>
      role.DELETED = 0
      <if test="dto.code != null and dto.code != ''">
        AND role.`CODE` LIKE CONCAT('%', #{dto.code}, '%')
      </if>
      <if test="dto.name != null and dto.name != ''">
        AND role.`NAME` LIKE CONCAT('%', #{dto.name}, '%')
      </if>
      <if test="dto.type != null">
        AND role.`TYPE` = #{dto.type}
      </if>
      <if test="dto.companyId != null">
        AND role.`COMPANY_ID` = #{dto.companyId}
      </if>
    </where>
    ${orderByClause}
  </select>
 
  <!-- 查询用户角色列表 -->
  <select id="selectByUserId" parameterType="java.lang.Integer" resultType="doumeemes.dao.system.model.SystemRole">
    SELECT
    role.`COMPANY_ID`,role.`TYPE`,  role.ID, role.`CODE`, role.`NAME`, role.`REMARK`, role.`CREATE_TIME`, role.`UPDATE_TIME`
    FROM SYSTEM_ROLE role
    INNER JOIN SYSTEM_USER_ROLE user_role ON user_role.ROLE_ID = role.ID AND user_role.DELETED = 0
    <where>
      role.DELETED = 0
      AND user_role.USER_ID = #{userId}
    </where>
  </select>
  <!-- 查询用户角色列表 -->
  <select id="selectByUserModel"  resultType="doumeemes.dao.system.model.SystemRole">
    SELECT
    role.`COMPANY_ID`,role.`TYPE`,  role.ID, role.`CODE`, role.`NAME`, role.`REMARK`, role.`CREATE_TIME`, role.`UPDATE_TIME`
    FROM SYSTEM_ROLE role
    INNER JOIN SYSTEM_USER_ROLE user_role ON user_role.ROLE_ID = role.ID AND user_role.DELETED = 0
    <where>
      role.DELETED = 0
      AND user_role.USER_ID = #{userId}
      <if test="dto.companyId != null" >
        and role.COMPANY_ID = #{dto.companyId}
      </if>
      <if test="dto.type != null" >
        and role.TYPE = #{dto.type}
      </if>
    </where>
  </select>
 
</mapper>