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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
<?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="menuServiceDaoImpl">
 
    <!-- 保存路由信息至 instance表中 add by wuxw 2018-07-03 -->
    <insert id="saveMenuGroupInfo" parameterType="Map">
        insert into m_menu_group(g_id, name, icon, label, seq, description, group_type, store_type)
        values (#{gId}, #{name}, #{icon}, #{label}, #{seq}, #{description}, #{groupType}, #{storeType})
    </insert>
 
    <!-- 查询路由信息 add by wuxw 2018-07-03 -->
    <select id="getMenuGroupInfo" parameterType="Map" resultType="Map">
        select t.g_id,t.name,t.icon,t.label,t.seq,t.description,t.g_id gId,t.group_type groupType,t.store_type storeType
        from m_menu_group t
        where t.status_cd= '0'
        <if test="gId !=null and gId != ''">
            and t.g_id= #{gId}
        </if>
        <if test="name !=null and name != ''">
            and t.name like concat('%',#{name},'%')
        </if>
        <if test="icon !=null and icon != ''">
            and t.icon= #{icon}
        </if>
        <if test="label !=null and label != ''">
            and t.label= #{label}
        </if>
        <if test="groupType !=null and groupType != ''">
            and t.group_type= #{groupType}
        </if>
        <if test="storeType !=null and storeType != ''">
            and t.store_type= #{storeType}
        </if>
        <if test="seq !=null">
            and t.seq= #{seq}
        </if>
        <if test="description !=null and description != ''">
            and t.description= #{description}
        </if>
        order by t.seq
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <!-- 修改路由信息 add by wuxw 2018-07-03 -->
    <update id="updateMenuGroupInfo" parameterType="Map">
        update m_menu_group t
        <set>
            <if test="statusCd !=null and statusCd != ''">
                t.status_cd = #{statusCd},
            </if>
            <if test="name !=null and name != ''">
                t.name= #{name},
            </if>
            <if test="icon !=null and icon != ''">
                t.icon= #{icon},
            </if>
            <if test="groupType !=null and groupType != ''">
                t.group_type= #{groupType},
            </if>
            <if test="label !=null ">
                t.label= #{label},
            </if>
            <if test="seq !=null ">
                t.seq= #{seq},
            </if>
            <if test="storeType !=null and storeType != ''">
                t.store_type= #{storeType},
            </if>
            <if test="description !=null and description != ''">
                t.description= #{description}
            </if>
        </set>
        where t.g_id= #{gId}
    </update>
 
    <!-- 查询路由数量 add by wuxw 2018-07-03 -->
    <select id="queryMenuGroupsCount" parameterType="Map" resultType="Map">
        select count(1) count
        from m_menu_group t
        where t.status_cd= '0'
        <if test="gId !=null and gId != ''">
            and t.g_id= #{gId}
        </if>
        <if test="name !=null and name != ''">
            and t.name like concat('%',#{name},'%')
        </if>
        <if test="icon !=null and icon != ''">
            and t.icon= #{icon}
        </if>
        <if test="groupType !=null and groupType != ''">
            and t.group_type= #{groupType}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and t.status_cd= #{statusCd}
        </if>
        <if test="label !=null and label != ''">
            and t.label= #{label}
        </if>
        <if test="seq !=null">
            and t.seq= #{seq}
        </if>
        <if test="storeType !=null and storeType != ''">
            and t.store_type= #{storeType}
        </if>
        <if test="description !=null and description != ''">
            and t.description= #{description}
        </if>
    </select>
 
    <!-- 保存路由信息至 instance表中 add by wuxw 2018-07-03 -->
    <insert id="saveBasePrivilegeRelInfo" parameterType="Map">
        insert into p_privilege_rel(p_id, pg_id)
        values (#{pId}, #{pgId})
    </insert>
 
    <!-- 保存路由信息至 instance表中 add by wuxw 2018-07-03 -->
    <insert id="saveBasePrivilegeInfo" parameterType="Map">
        insert into p_privilege(p_id, name, resource, domain, description, m_id)
        values (#{pId}, #{name}, #{resource}, #{domain}, #{description}, #{mId})
    </insert>
 
    <!-- 查询路由信息 add by wuxw 2018-07-03 -->
    <select id="getBasePrivilegeInfo" parameterType="Map" resultType="Map">
        select t.p_id,t.name,t.domain,t.resource,t.description,t.p_id pId,t.create_time createTime,st.name stName
        from p_privilege t
        left join store_type st on t.domain=st.store_type_cd
        where t.status_cd= '0'
        <if test="pId !=null and pId != ''">
            and t.p_id= #{pId}
        </if>
        <if test="name !=null and name != ''">
            and t.name like concat('%',#{name},'%')
        </if>
        <if test="resource !=null and resource != ''">
            and t.resource = #{resource}
        </if>
        <if test="domain !=null and domain != ''">
            and t.domain= #{domain}
        </if>
        <if test="mId !=null and mId != ''">
            and t.m_id= #{mId}
        </if>
        order by t.create_time desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <!-- 修改路由信息 add by wuxw 2018-07-03 -->
    <update id="updateBasePrivilegeInfo" parameterType="Map">
        update p_privilege t
        <set>
            <if test="statusCd !=null and statusCd != ''">
                t.status_cd = #{statusCd},
            </if>
            <if test="name !=null and name != ''">
                t.name= #{name},
            </if>
            <if test="resource !=null and resource != ''">
                t.resource= #{resource},
            </if>
            <if test="domain !=null and domain != ''">
                t.domain= #{domain},
            </if>
            <if test="description !=null and description != ''">
                t.description= #{description}
            </if>
        </set>
        where t.p_id= #{pId}
    </update>
 
    <!-- 修改路由信息 add by wuxw 2018-07-03 -->
    <update id="updateBasePrivilegeRelInfo" parameterType="Map">
        update p_privilege_rel t
        <set>
            <if test="statusCd !=null and statusCd != ''">
                t.status_cd = #{statusCd},
            </if>
            <if test="pgId !=null and pgId != ''">
                t.pg_id= #{pgId},
            </if>
 
        </set>
        where t.p_id= #{pId}
    </update>
 
    <!-- 查询路由数量 add by wuxw 2018-07-03 -->
    <select id="queryBasePrivilegesCount" parameterType="Map" resultType="Map">
        select count(1) count
        from p_privilege t
        where 1 =1
        <if test="pId !=null and pId != ''">
            and t.p_id= #{pId}
        </if>
        <if test="name !=null and name != ''">
            and t.name like concat('%',#{name},'%')
        </if>
        <if test="resource !=null and resource != ''">
            and t.resource = #{resource}
        </if>
        <if test="domain !=null and domain != ''">
            and t.domain= #{domain}
        </if>
        <if test="mId !=null and mId != ''">
            and t.m_id= #{mId}
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and t.status_cd= #{statusCd}
        </if>
    </select>
 
    <!-- 保存路由信息至 instance表中 add by wuxw 2018-07-03 -->
    <insert id="saveMenuInfo" parameterType="Map">
        insert into m_menu(m_id, name, g_id, url, seq, p_id, description, is_show)
        values (#{mId}, #{name}, #{gId}, #{url}, #{seq}, '-1', #{description}, #{isShow})
    </insert>
 
    <!-- 查询路由信息 add by wuxw 2018-07-03 -->
    <select id="getMenuInfo" parameterType="Map" resultType="Map">
        select DISTINCT t.m_id mId,t.name,t.g_id gId,t.url,t.seq,t.p_id pId,t.description,t.is_show isShow,
        if(t.is_show='Y','显示','不显示') isShowName,
        t.m_id pId,t.name pName,mg.name gName,mg.store_type,st.name storeTypeName
        from m_menu t,p_privilege p,m_menu_group mg,store_type st
        where t.status_cd= '0'
        and p.status_cd= '0'
        and t.m_id = p.m_id
        and t.g_id = mg.g_id
        and mg.store_type = st.store_type_cd
        <if test="gId !=null and gId != ''">
            and t.g_id= #{gId}
        </if>
        <if test="gName !=null and gName != ''">
            and mg.name= #{gName}
        </if>
        <if test="name !=null and name != ''">
            and t.name like concat('%',#{name},'%')
        </if>
        <if test="mName !=null and mName != ''">
            and t.name like concat('%',#{mName},'%')
        </if>
        <if test="domain !=null and domain != ''">
            and p.domain= #{domain}
        </if>
        <if test="pName !=null and pName != ''">
            and p.name like concat('%',#{pName},'%')
        </if>
        <if test="mId !=null and mId != ''">
            and t.m_id= #{mId}
        </if>
        <if test="pId !=null and pId != ''">
            and p.p_id= #{pId}
        </if>
        <if test="isShow !=null and isShow != ''">
            and t.is_show= #{isShow}
        </if>
        <if test="url !=null and url != ''">
            and t.url like concat('%',#{url},'%')
        </if>
        <if test="seq !=null">
            and t.seq= #{seq}
        </if>
        <if test="description !=null and description != ''">
            and t.description= #{description}
        </if>
        <if test="uName != null and uName != ''">
            and exists(
            SELECT 1
            FROM p_privilege_user ppu,u_user u
            WHERE ppu.`p_id` = p.`p_id`
            AND ppu.`privilege_flag` = '0'
            and ppu.user_id = u.user_id
            AND u.`name` = #{uName}
            AND ppu.`status_cd` = '0'
            UNION
            SELECT 1
            FROM p_privilege_user ppu,
            p_privilege_group ppg,p_privilege_rel ppr,u_user u
            WHERE ppu.`p_id` = ppr.pg_id
            AND ppr.pg_id = ppg.pg_id
            AND ppr.p_id = p.`p_id`
            AND ppu.`privilege_flag` = '1'
            and ppu.user_id = u.user_id
            AND u.`name` = #{uName}
            AND ppu.`status_cd` = '0'
            AND ppg.status_cd = '0'
            AND ppr.status_cd = '0'
            )
        </if>
        order by t.seq
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>
    </select>
 
    <!-- 修改路由信息 add by wuxw 2018-07-03 -->
    <update id="updateMenuInfo" parameterType="Map">
        update m_menu t
        <set>
            <if test="statusCd !=null and statusCd != ''">
                t.status_cd = #{statusCd},
            </if>
            <if test="name !=null and name != ''">
                t.name= #{name},
            </if>
            <if test="gId !=null and gId != ''">
                t.g_id= #{gId},
            </if>
            <if test="url !=null and url != ''">
                t.url= #{url},
            </if>
            <if test="seq !=null ">
                t.seq= #{seq},
            </if>
            <if test="isShow !=null and isShow != ''">
                t.is_show= #{isShow},
            </if>
            <if test="description !=null and description != ''">
                t.description= #{description}
            </if>
        </set>
        where t.m_id= #{mId}
    </update>
 
    <!-- 查询路由数量 add by wuxw 2018-07-03 -->
    <select id="queryMenusCount" parameterType="Map" resultType="Map">
        select count(DISTINCT(t.m_id)) count
        from m_menu t,p_privilege p,m_menu_group mg,store_type st
        where t.status_cd= '0'
        and p.status_cd= '0'
        and t.m_id = p.m_id
        and t.g_id = mg.g_id
        and mg.store_type = st.store_type_cd
        <if test="gId !=null and gId != ''">
            and t.g_id= #{gId}
        </if>
        <if test="gName !=null and gName != ''">
            and mg.name= #{gName}
        </if>
        <if test="name !=null and name != ''">
            and t.name like concat('%',#{name},'%')
        </if>
        <if test="mName !=null and mName != ''">
            and t.name like concat('%',#{mName},'%')
        </if>
        <if test="pId !=null and pId != ''">
            and p.p_id= #{pId}
        </if>
        <if test="domain !=null and domain != ''">
            and p.domain= #{domain}
        </if>
        <if test="pName !=null and pName != ''">
            and p.name like concat('%',#{pName},'%')
        </if>
        <if test="mId !=null and mId != ''">
            and p.m_id= #{mId}
        </if>
        <if test="isShow !=null and isShow != ''">
            and t.is_show= #{isShow}
        </if>
        <if test="url !=null and url != ''">
            and t.url like concat('%',#{url},'%')
        </if>
        <if test="seq !=null">
            and t.seq= #{seq}
        </if>
        <if test="description !=null and description != ''">
            and t.description= #{description}
        </if>
        <if test="uName != null and uName != ''">
            and exists(
            SELECT 1
            FROM p_privilege_user ppu,u_user u
            WHERE ppu.`p_id` = p.`p_id`
            AND ppu.`privilege_flag` = '0'
            and ppu.user_id = u.user_id
            AND u.`name` = #{uName}
            AND ppu.`status_cd` = '0'
            UNION
            SELECT 1
            FROM p_privilege_user ppu,
            p_privilege_group ppg,p_privilege_rel ppr,u_user u
            WHERE ppu.`p_id` = ppr.pg_id
            AND ppr.pg_id = ppg.pg_id
            AND ppr.p_id = p.`p_id`
            AND ppu.`privilege_flag` = '1'
            and ppu.user_id = u.user_id
            AND u.`name` = #{uName}
            AND ppu.`status_cd` = '0'
            AND ppg.status_cd = '0'
            AND ppr.status_cd = '0'
            )
        </if>
    </select>
 
    <select id="checkUserHasResource" parameterType="Map" resultType="Map">
        SELECT pp.*,'-1' AS pg_id,'' AS pg_name,ppu.privilege_flag privilegeFlag
        FROM p_privilege_user ppu,p_privilege pp
        WHERE ppu.`p_id` = pp.`p_id`
        <if test="resource != null and resource != ''">
            AND pp.`resource` = #{resource}
        </if>
        <if test="userId != null and userId != ''">
            AND ppu.`user_id` = #{userId}
        </if>
        AND ppu.`privilege_flag` = '0'
        AND ppu.`status_cd` = '0'
        AND pp.`status_cd` = '0'
        UNION
        SELECT pp.*,ppg.pg_id,ppg.name pg_name,ppu.privilege_flag privilegeFlag FROM p_privilege_user
        ppu,p_privilege_group ppg,p_privilege
        pp,p_privilege_rel ppr
        WHERE ppu.`p_id` = ppr.pg_id
        AND ppr.pg_id = ppg.pg_id
        AND ppr.p_id = pp.`p_id`
        <if test="resource != null and resource != ''">
            AND pp.`resource` = #{resource}
        </if>
        <if test="userId != null and userId != ''">
            AND ppu.`user_id` = #{userId}
        </if>
        AND ppu.`privilege_flag` = '1'
        AND ppu.`status_cd` = '0'
        AND pp.`status_cd` = '0'
        AND ppg.status_cd = '0'
        AND ppr.status_cd = '0'
    </select>
 
    <select id="hasPrivilege" parameterType="Map" resultType="Map">
        SELECT DISTINCT tt.p_id        `pId`,
                        tt.name,
                        tt.pg_id       pgId,
                        tt.pg_name     pgName,
                        tt.description,
                        tt.create_time createTime
        FROM (
                 SELECT pp.*, '-1' AS pg_id, '' AS pg_name
                 FROM p_privilege_user ppu,
                      p_privilege pp
                 WHERE ppu.`p_id` = pp.`p_id`
                   AND pp.p_id = #{pId}
                   AND ppu.`privilege_flag` = '0'
                   AND ppu.`user_id` = #{userId}
                   AND ppu.`status_cd` = '0'
                   AND pp.`status_cd` = '0'
                 UNION
                 SELECT pp.*, ppg.pg_id, ppg.name pg_name
                 FROM p_privilege_user ppu,
                      p_privilege_group ppg,
                      p_privilege pp,
                      p_privilege_rel ppr
                 WHERE ppu.`p_id` = ppr.pg_id
                   AND ppr.pg_id = ppg.pg_id
                   AND ppr.p_id = pp.`p_id`
                   AND pp.p_id = #{pId}
                   AND ppu.`privilege_flag` = '1'
                   AND ppu.`user_id` = #{userId}
                   AND ppu.`status_cd` = '0'
                   AND pp.`status_cd` = '0'
                   AND ppg.status_cd = '0'
                   AND ppr.status_cd = '0'
             ) tt
    </select>
</mapper>