1
13693261870
2022-09-16 762f2fb45db004618ba099aa3c0bd89dba1eb843
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
<?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.landtool.lanbase.modules.sys.dao.SysRoleGroupDao">
 
    <!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="com.landtool.lanbase.modules.sys.entity.SysRoleGroup" id="rolegroupMap">
        <result property="roleId" column="roleid"/>
        <result property="groupId" column="groupid"/>
        <result property="createUnitId" column="createunitid"/>
        <result property="rCreateDate" column="rcreatedate"/>
        <result property="rCreateUser" column="rcreateuser"/>
    </resultMap>
 
    <select id="queryObject" resultType="com.landtool.lanbase.modules.sys.entity.SysRoleGroup">
        select * from SYS_ROLEGROUP where roleid = #{value}
    </select>
 
    <select id="queryList" resultType="com.landtool.lanbase.modules.sys.entity.SysRoleGroup">
 
        SELECT  *
        FROM(
            SELECT ROW_NUMBER() OVER(ORDER BY B.roleid) AS rownumber,B.*
            FROM (
 
                        select * from SYS_ROLEGROUP
 
            ) B
        ) A
        WHERE rownumber > #{lowerOffset} AND  <![CDATA[ rownumber <= ${upperOffset} ]]>
    </select>
    
     <select id="queryTotal" resultType="int">
        select count(*) from SYS_ROLEGROUP
    </select>
     
    <insert id="save" parameterType="com.landtool.lanbase.modules.sys.entity.SysRoleGroup">
        insert into SYS_ROLEGROUP
        (
            roleid,
            groupid,
            createunitid,
            rcreatedate,
            rcreateuser
        )
        values
        (
            #{roleId},
            #{groupId},
            #{createUnitId},
            #{rCreateDate},
            #{rCreateUser}
        )
    </insert>
     
    <update id="update" parameterType="com.landtool.lanbase.modules.sys.entity.SysRoleGroup">
        update SYS_ROLEGROUP
        <set>
            <if test="groupId != null">groupid = #{groupId}, </if>
            <if test="createUnitId != null">createunitid = #{createUnitId}, </if>
            <if test="rCreateDate != null">rcreatedate = #{rCreateDate}, </if>
            <if test="rCreateUser != null">rcreateuser = #{rCreateUser}</if>
        </set>
        where roleid = #{roleId}
    </update>
    
    <delete id="delete">
        delete from SYS_ROLEGROUP where roleid = #{value}
    </delete>
    
    <delete id="deleteBatch">
        delete from SYS_ROLEGROUP where roleid in
        <foreach item="roleId" collection="array" open="(" separator="," close=")">
            #{roleId}
        </foreach>
    </delete>
 
    <select id="findList" resultType="map">
        SELECT
        groupid  "groupId", groupname  "groupName", description  "description", ROLES AS "roles"
        FROM(
            SELECT ROW_NUMBER() OVER(ORDER BY B.groupid) AS rownumber,B.*
            FROM (
 
                SELECT
                  og.groupid AS groupId,
                  og.groupname AS groupName,
                  og.description,
                  b.ROLES AS roles
                FROM ORG_GROUP og
                  LEFT JOIN (
                              SELECT DISTINCT
                                A.groupid,
                                (SELECT  STRING_AGG(cast(B.rolename as varchar),',')
                                    FROM (SELECT  srg.groupid, sr.rolename FROM SYS_ROLEGROUP  srg
                                    INNER JOIN SYS_ROLE sr ON srg.roleid = sr.roleid ) B
                                    WHERE B.groupid = A.groupid group by A.groupid order by A.groupid) AS ROLES
                              FROM (
                                     SELECT
                                       srg.groupid,
                                       sr.rolename
                                     FROM SYS_ROLEGROUP  srg
                                       INNER JOIN SYS_ROLE sr ON srg.roleid = sr.roleid
                                   ) A
                            ) b ON b.groupid = og.groupid
                        WHERE    og.appid IN (SELECT 0 AS appid from SYS_ROLE
                                                UNION
                                                SELECT appid FROM SYS_ROLE WHERE roleid = #{roleId})
                          <if test="excludeGroupIds != null and excludeGroupIds.size() > 0">
                              AND og.groupid NOT IN
                              <foreach item="groupId" collection="excludeGroupIds" open="(" separator="," close=")">
                                  #{groupId}
                              </foreach>
                          </if>
                          <if test="includeGroupIds != null">
                              <choose>
                                  <when test="includeGroupIds.size() > 0">
                                      AND og.groupid IN
                                      <foreach item="groupId" collection="includeGroupIds" open="(" separator="," close=")">
                                          #{groupId}
                                      </foreach>
                                  </when>
                                  <otherwise>
                                      AND og.groupid IN ('')
                                  </otherwise>
                              </choose>
                          </if>
                            <if test="groupName != null and groupName != ''">
                                AND og.groupname LIKE ('%' || #{groupName} || '%')
                            </if>
                            <if test="groupNameWithSelected != null and groupNameWithSelected != ''">
                                AND og.groupname LIKE ('%' || #{groupNameWithSelected} || '%')
                            </if>
 
 
            ) B
        ) A
        WHERE rownumber > #{lowerOffset} AND  <![CDATA[ rownumber <= ${upperOffset} ]]>
 
    </select>
 
    <select id="findTotal" resultType="int">
            SELECT
                count(*)
            FROM ORG_GROUP og
              LEFT JOIN (
                          SELECT DISTINCT
                            A.groupid,
                            (SELECT  STRING_AGG(cast(B.rolename as varchar),',')
                            FROM (SELECT  srg.groupid, sr.rolename FROM SYS_ROLEGROUP  srg
                            INNER JOIN SYS_ROLE sr ON srg.roleid = sr.roleid ) B
                            WHERE B.groupid = A.groupid group by A.groupid order by A.groupid) AS ROLES
                          FROM (
                                 SELECT
                                   srg.groupid,
                                   sr.rolename
                                 FROM SYS_ROLEGROUP  srg
                                   INNER JOIN SYS_ROLE sr ON srg.roleid = sr.roleid
                               ) A
                        ) b ON b.groupid = og.groupid
                    WHERE    og.appid IN (SELECT 0 AS appid from SYS_ROLE
                                            UNION
                                            SELECT appid FROM SYS_ROLE WHERE roleid = #{roleId})
                      <if test="excludeGroupIds != null and excludeGroupIds.size() > 0">
                          AND og.groupid NOT IN
                          <foreach item="groupId" collection="excludeGroupIds" open="(" separator="," close=")">
                              #{groupId}
                          </foreach>
                      </if>
                      <if test="includeGroupIds != null">
                          <choose>
                              <when test="includeGroupIds.size() > 0">
                                  AND og.groupid IN
                                  <foreach item="groupId" collection="includeGroupIds" open="(" separator="," close=")">
                                      #{groupId}
                                  </foreach>
                              </when>
                              <otherwise>
                                  AND og.groupid IN ('')
                              </otherwise>
                          </choose>
                      </if>
                        <if test="groupName != null and groupName != ''">
                            AND og.groupname LIKE ('%' || #{groupName} || '%')
                        </if>
                        <if test="groupNameWithSelected != null and groupNameWithSelected != ''">
                            AND og.groupname LIKE ('%' || #{groupNameWithSelected} || '%')
                        </if>
 
    </select>
 
    <select id="getGroupIdsByRoleId" resultType="java.lang.Long">
        SELECT
             srg.groupid
        FROM SYS_ROLEGROUP srg
          LEFT JOIN SYS_ROLE sr ON srg.roleid = sr.roleid
        WHERE sr.roleid = #{roleId}
    </select>
    
    <select id="findRoleList" resultType="map">
        SELECT roleid AS "roleId",
        rolename AS "roleName"
        FROM(
            SELECT ROW_NUMBER() OVER(ORDER BY B.roleid) AS rownumber,B.*
            FROM (
 
                SELECT
                  og.roleid AS roleId,
                  og.rolename AS roleName
                  FROM SYS_ROLE og where 1=1
                  
                          <if test="excludeRoleIds != null and excludeRoleIds.size() > 0">
                              AND og.roleid NOT IN
                              <foreach item="roleId" collection="excludeRoleIds" open="(" separator="," close=")">
                                  #{roleId}
                              </foreach>
                          </if>
                          <if test="includeRoleIds != null">
                              <choose>
                                  <when test="includeRoleIds.size() > 0">
                                      AND og.roleid IN
                                      <foreach item="roleId" collection="includeRoleIds" open="(" separator="," close=")">
                                          #{roleId}
                                      </foreach>
                                  </when>
                                  <otherwise>
                                      AND og.roleid IN ('')
                                  </otherwise>
                              </choose>
                          </if>
                            <if test="roleName != null and roleName != ''">
                                AND og.rolename LIKE ('%' || #{roleName} || '%')
                            </if>
                            <if test="roleNameWithSelected != null and roleNameWithSelected != ''">
                                AND og.rolename LIKE ('%' || #{roleNameWithSelected} || '%')
                            </if>
 
 
            ) B
        ) A
        WHERE rownumber > #{lowerOffset} AND  <![CDATA[ rownumber <= ${upperOffset} ]]>
    </select>
    
    <select id="findRoleTotal" resultType="int">
                SELECT count(*) FROM SYS_ROLE og where 1=1
                  
                              <if test="excludeRoleIds != null and excludeRoleIds.size() > 0">
                                  AND og.roleid NOT IN
                                  <foreach item="roleId" collection="excludeRoleIds" open="(" separator="," close=")">
                                      #{roleId}
                                  </foreach>
                              </if>
                              <if test="includeRoleIds != null">
                                  <choose>
                                      <when test="includeRoleIds.size() > 0">
                                          AND og.roleid IN
                                          <foreach item="roleId" collection="includeRoleIds" open="(" separator="," close=")">
                                              #{roleId}
                                          </foreach>
                                      </when>
                                      <otherwise>
                                          AND og.roleid IN ('')
                                      </otherwise>
                                  </choose>
                              </if>
                                <if test="roleName != null and roleName != ''">
                                    AND og.rolename LIKE ('%' || #{roleName} || '%')
                                </if>
                                <if test="roleNameWithSelected != null and roleNameWithSelected != ''">
                                    AND og.rolename LIKE ('%' || #{roleNameWithSelected} || '%')
                                </if>
    </select>
    
   <select id="getRoleIdsByGroupId" resultType="java.lang.Long">
        SELECT srg.roleid
        FROM SYS_ROLEGROUP srg
        WHERE srg.groupid = #{groupId}
    </select>
    
    <delete id="deleteBatchByRoleIdAndGroupIds">
        DELETE FROM SYS_ROLEGROUP
        WHERE
        ROLEID = #{roleId}
        AND groupid IN
        <foreach item="groupId" collection="groupIds" open="(" separator="," close=")">
            #{groupId}
        </foreach>
    </delete>
 
    <delete id="deleteBatchByGroupId">
        DELETE FROM SYS_ROLEGROUP WHERE groupid IN
        <foreach item="groupId" collection="array" open="(" separator="," close=")">
            #{groupId}
        </foreach>
    </delete>
</mapper>