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
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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
<?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.org.dao.OrgUserDao">
 
    <!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="com.landtool.lanbase.modules.org.entity.OrgUser" id="userMap">
        <result property="userid" column="USERID"/>
        <result property="loginname" column="LOGINNAME"/>
        <result property="password" column="PASSWORD"/>
        <result property="chinesename" column="CHINESENAME"/>
        <result property="spellfirst" column="SPELLFIRST"/>
        <result property="userstatus" column="USERSTATUS"/>
        <result property="mobileno" column="MOBILENO"/>
        <result property="isreceivemsg" column="ISRECEIVEMSG"/>
        <result property="officetel" column="OFFICETEL"/>
        <result property="email" column="EMAIL"/>
        <result property="address" column="ADDRESS"/>
        <result property="idcard" column="IDCARD"/>
        <result property="nativeplace" column="NATIVEPLACE"/>
        <result property="sex" column="SEX"/>
        <result property="photourl" column="PHOTOURL"/>
        <result property="education" column="EDUCATION"/>
        <result property="speciality" column="SPECIALITY"/>
        <result property="jobtitle" column="JOBTITLE"/>
        <result property="joblevel" column="JOBLEVEL"/>
        <result property="rcreateuser" column="RCREATEUSER"/>
        <result property="rcreatedate" column="RCREATEDATE"/>
        <result property="rlasteditdate" column="RLASTEDITDATE"/>
        <result property="remark" column="REMARK"/>
        <!-- <result property="salt" column="SALT"/> -->
        <result property="systemName" column="SYSTEMNAME"/>
        <result property="certificateurl" column="CERTIFICATEURL"/>
    </resultMap>
 
    <resultMap type="com.landtool.lanbase.modules.org.entity.OrgUserJoinUnit" id="UserJoinUnit">
        <id property="userid" column="USERID"/>
        <result property="loginname" column="LOGINNAME"/>
        <result property="password" column="PASSWORD"/>
        <result property="chinesename" column="CHINESENAME"/>
        <result property="spellfirst" column="SPELLFIRST"/>
        <result property="userstatus" column="USERSTATUS"/>
        <result property="mobileno" column="MOBILENO"/>
        <result property="isreceivemsg" column="ISRECEIVEMSG"/>
        <result property="officetel" column="OFFICETEL"/>
        <result property="email" column="EMAIL"/>
        <result property="address" column="ADDRESS"/>
        <result property="idcard" column="IDCARD"/>
        <result property="nativeplace" column="NATIVEPLACE"/>
        <result property="sex" column="SEX"/>
        <result property="photourl" column="PHOTOURL"/>
        <result property="education" column="EDUCATION"/>
        <result property="speciality" column="SPECIALITY"/>
        <result property="jobtitle" column="JOBTITLE"/>
        <result property="joblevel" column="JOBLEVEL"/>
        <result property="rcreateuser" column="RCREATEUSER"/>
        <result property="rcreatedate" column="RCREATEDATE"/>
        <result property="rlasteditdate" column="RLASTEDITDATE"/>
        <result property="remark" column="REMARK"/>
        <!-- <result property="salt" column="SALT"/>  -->
        <result property="certificateurl" column="CERTIFICATEURL"/>
        <collection property="orguserunits" ofType="com.landtool.lanbase.modules.org.entity.OrgUserunit" resultMap="com.landtool.lanbase.modules.org.dao.OrgUserunitDao.userunitMap"/>
        <collection property="orgusergroup" ofType="com.landtool.lanbase.modules.org.entity.OrgUserGroup" resultMap="com.landtool.lanbase.modules.org.dao.OrgUserGroupDao.usergroupMap"/>
 
    </resultMap >
 
    <resultMap type="com.landtool.lanbase.modules.org.entity.OrgUserWithUnitCell" id="userUnitCell">
        <result property="userid" column="USERID"/>
        <result property="loginname" column="LOGINNAME"/>
        <result property="chinesename" column="CHINESENAME"/>
        <result property="userstatus" column="USERSTATUS"/>
        <result property="mobileno" column="MOBILENO"/>
        <result property="isreceivemsg" column="ISRECEIVEMSG"/>
        <result property="rcreateuser" column="RCREATEUSER"/>
        <result property="rcreatedate" column="RCREATEDATE"/>
        <result property="unitnames" column="UNITNAMES"/>
        <result property="joblevel" column="JOBLEVEL"/>
    </resultMap>
 
    <sql id="userColumns">
        ou.USERID,ou.LOGINNAME,ou.PASSWORD,ou.CHINESENAME,ou.SPELLFIRST,ou.USERSTATUS,ou.MOBILENO,ou.ISRECEIVEMSG,
        ou.OFFICETEL,ou.EMAIL,ou.ADDRESS,ou.IDCARD,ou.NATIVEPLACE,ou.SEX,ou.PHOTOURL,ou.certificateurl,
        ou.EDUCATION,ou.SPECIALITY,ou.JOBTITLE,ou.JOBLEVEL,ou.RCREATEUSER,ou.RCREATEDATE,ou.RLASTEDITDATE,ou.REMARK
        <!-- ou.SALT -->
    </sql>
 
    <sql id="userUnitColumns">
        ou2.unitid,ou2.posname,ou2.workseasdate,ou2.worktype,ou2.workstartdate,ou2.workenddate
    </sql>
 
    <sql id="userGroupColumns">
        ou3.userId,ou3.groupId,ou3.createUnitId,ou3.rCreateDate,ou3.rCreateUser
    </sql>
 
    <select id="queryObject" resultType="com.landtool.lanbase.modules.org.entity.OrgUser">
        select * from ORG_USER where USERID = #{value}
    </select>
 
    <select id="queryList" resultType="com.landtool.lanbase.modules.org.entity.OrgUser">
        SELECT *
        FROM(
            SELECT ROW_NUMBER() OVER(ORDER BY B.userid) AS rownumber,B.*
            FROM (
                    select * from ORG_USER us
                    <where>
                        <if test="loginname != null and loginname != ''">
                            AND us.LOGINNAME LIKE ('%' || #{loginname} || '%')
                        </if>
                        <if test="userstatus != null and userstatus != ''">
                            AND cast(us.USERSTATUS as varchar) = #{userstatus}
                        </if>
                        <if test="chinesename != null and chinesename != ''">
                            AND us.CHINESENAME LIKE ('%' || #{chinesename} || '%')
                        </if>
                        <if test="unitname != null and unitname != ''">
                            AND exists(select ut.userid from ORG_USERUNIT ut JOIN ORG_UNIT un on un.unitid = ut.unitid where us.userid = ut.userid and (un.UNITNAME LIKE ('%' || #{unitname} || '%') or LOWER(un.spellfirst) LIKE ('%' || LOWER(#{unitname}) || '%'))
                        </if>
                    </where>
                ) B
            ) A
        WHERE rownumber > #{lowerOffset} AND  <![CDATA[ rownumber <= ${upperOffset} ]]>
    </select>
 
     <select id="queryTotal" resultType="int">
        SELECT
            COUNT(*)
        FROM ORG_USER us
        LEFT JOIN (
            SELECT
                ouu.USERID,
                max(ou.UNITNAME) AS UNITNAMES,
                max(ouu.RCREATEDATE) AS RCREATEDATE
            FROM ORG_USERUNIT ouu
            LEFT JOIN ORG_UNIT ou ON ouu.unitid=ou.unitid
            GROUP BY ouu.USERID
        )b  ON  us.USERID = b.USERID
        <where>
            <if test="loginname != null and loginname != ''">
                AND us.LOGINNAME LIKE ('%' || #{loginname} || '%')
            </if>
            <if test="userstatus != null and userstatus != ''">
                AND cast(us.USERSTATUS as varchar) = #{userstatus}
            </if>
            <if test="chinesename != null and chinesename != ''">
                AND (us.CHINESENAME LIKE ('%' || #{chinesename} || '%') or us.LOGINNAME LIKE ('%' || #{chinesename} || '%')  or LOWER(us.spellfirst) LIKE ('%' || LOWER(#{chinesename}) || '%'))
            </if>
            <if test="unitname != null and unitname != ''">
                AND exists(select ut.userid from ORG_USERUNIT ut JOIN ORG_UNIT un on un.unitid = ut.unitid where us.userid = ut.userid and (un.UNITNAME LIKE ('%' || #{unitname} || '%') or LOWER(un.spellfirst) LIKE ('%' || LOWER(#{unitname}) || '%')))
            </if>
        </where>
    </select>
 
    <insert id="save" parameterType="com.landtool.lanbase.modules.org.entity.OrgUser">
        insert into ORG_USER
        (
            LOGINNAME,
            PASSWORD,
            CHINESENAME,
            SPELLFIRST,
            USERSTATUS,
            MOBILENO,
            ISRECEIVEMSG,
            OFFICETEL,
            EMAIL,
            ADDRESS,
            IDCARD,
            NATIVEPLACE,
            SEX,
            PHOTOURL,
            EDUCATION,
            SPECIALITY,
            JOBTITLE,
            JOBLEVEL,
            RCREATEUSER,
            RCREATEDATE,
            RLASTEDITDATE,
            REMARK,
            certificateurl,
            isfirstlogin
             <if test="fromsys != null and fromsys !=''" >
               ,FROMSYS
            </if>
 
            <!-- SALT  -->
        )
        values
        (
            #{loginname},
            #{password},
            #{chinesename},
            #{spellfirst},
            #{userstatus},
            #{mobileno,jdbcType=VARCHAR},
            #{isreceivemsg},
            #{officetel,jdbcType=VARCHAR},
            #{email,jdbcType=VARCHAR},
            #{address,jdbcType=VARCHAR},
            #{idcard,jdbcType=VARCHAR},
            #{nativeplace,jdbcType=VARCHAR},
            #{sex,jdbcType=NUMERIC},
            #{photourl,jdbcType=VARCHAR},
            #{education,jdbcType=VARCHAR},
            #{speciality,jdbcType=VARCHAR},
            #{jobtitle,jdbcType=BIGINT},
            #{joblevel,jdbcType=VARCHAR},
            #{rcreateuser},
            #{rcreatedate},
            #{rlasteditdate},
            #{remark,jdbcType=VARCHAR},
            #{certificateurl,jdbcType=VARCHAR},
            #{isfirstlogin,jdbcType=BIGINT}
             <if test="fromsys != null and fromsys !=''" >
            ,#{fromsys,jdbcType=VARCHAR}
             </if>
            <!-- #{salt,jdbcType=VARCHAR}  -->
        )
    </insert>
 
         <insert id="saveBatch" parameterType="java.util.List">
        insert into ORG_USER
        (
            USERID,
            LOGINNAME,
            PASSWORD,
            CHINESENAME,
            SPELLFIRST,
            USERSTATUS,
            MOBILENO,
            ISRECEIVEMSG,
            OFFICETEL,
            EMAIL,
            ADDRESS,
            IDCARD,
            NATIVEPLACE,
            SEX,
            PHOTOURL,
            EDUCATION,
            SPECIALITY,
            JOBTITLE,
            JOBLEVEL,
            RCREATEUSER,
            RCREATEDATE,
            RLASTEDITDATE,
            REMARK,
            certificateurl
            <if test="fromsys != null and fromsys !=''" >
               ,FROMSYS
            </if>
            <!-- SALT  -->
        )
        SELECT nextval('ORG_USER_SEQ') as USERID, a.* from(
        <foreach item="item" collection="list" index="index" separator="union all" >
         select
            #{item.loginname},
            #{item.password},
            #{item.chinesename},
            #{item.spellfirst},
            #{item.userstatus},
            #{item.mobileno,jdbcType=VARCHAR},
            #{item.isreceivemsg},
            #{item.officetel,jdbcType=VARCHAR},
            #{item.email,jdbcType=VARCHAR},
            #{item.address,jdbcType=VARCHAR},
            #{item.idcard,jdbcType=VARCHAR},
            #{item.nativeplace,jdbcType=VARCHAR},
            #{item.sex,jdbcType=VARCHAR},
            #{item.photourl,jdbcType=VARCHAR},
            #{item.education,jdbcType=VARCHAR},
            #{item.speciality,jdbcType=VARCHAR},
            #{item.jobtitle,jdbcType=VARCHAR},
            #{item.joblevel,jdbcType=VARCHAR},
            #{item.rcreateuser},
            #{item.rcreatedate},
            #{item.rlasteditdate},
            #{item.remark,jdbcType=VARCHAR},
            #{item.certificateurl,jdbcType=VARCHAR}
              <if test="fromsys != null and fromsys !=''" >
               ,#{item.fromsys,jdbcType=VARCHAR}
            </if>
         from dual
        </foreach>)a
    </insert>
 
    <update id="update" parameterType="com.landtool.lanbase.modules.org.entity.OrgUser">
        update ORG_USER
        <set>
            <if test="loginname != null">LOGINNAME = #{loginname}, </if>
            <if test="password != null">PASSWORD = #{password}, </if>
            <if test="chinesename != null">CHINESENAME = #{chinesename}, </if>
            <if test="spellfirst != null">SPELLFIRST = #{spellfirst}, </if>
            <if test="userstatus != null">USERSTATUS = #{userstatus}, </if>
            <if test="mobileno != null">MOBILENO = #{mobileno}, </if>
            <if test="isreceivemsg != null">ISRECEIVEMSG = #{isreceivemsg}, </if>
            <if test="officetel != null">OFFICETEL = #{officetel}, </if>
            <if test="email != null">EMAIL = #{email}, </if>
            <if test="address != null">ADDRESS = #{address}, </if>
            <if test="idcard != null">IDCARD = #{idcard}, </if>
            <if test="nativeplace != null">NATIVEPLACE = #{nativeplace}, </if>
            <if test="sex != null">SEX = #{sex}, </if>
            <if test="photourl != null">PHOTOURL = #{photourl}, </if>
            <if test="education != null">EDUCATION = #{education}, </if>
            <if test="speciality != null">SPECIALITY = #{speciality}, </if>
            <if test="jobtitle != null">JOBTITLE = #{jobtitle}, </if>
            <if test="joblevel != null">JOBLEVEL = #{joblevel}, </if>
            <if test="rcreateuser != null">RCREATEUSER = #{rcreateuser}, </if>
            <if test="rcreatedate != null">RCREATEDATE = #{rcreatedate}, </if>
            <if test="rlasteditdate != null">RLASTEDITDATE = #{rlasteditdate}, </if>
            <if test="remark != null">REMARK = #{remark}, </if>
            <if test="certificateurl != null">CERTIFICATEURL = #{certificateurl}</if>
            <!-- <if test="salt != null">SALT = #{salt}</if>  -->
        </set>
        where USERID = #{userid}
    </update>
 
    <update id="updateStatus" parameterType="com.landtool.lanbase.modules.org.entity.OrgUser">
        update ORG_USER
        <set>
            <if test="loginname != null">LOGINNAME = #{loginname}, </if>
            <if test="password != null">PASSWORD = #{password}, </if>
            <if test="chinesename != null">CHINESENAME = #{chinesename}, </if>
            <if test="spellfirst != null">SPELLFIRST = #{spellfirst}, </if>
            <if test="userstatus != null">USERSTATUS = #{userstatus}, </if>
            <if test="mobileno != null">MOBILENO = #{mobileno}, </if>
            <if test="isreceivemsg != null">ISRECEIVEMSG = #{isreceivemsg}, </if>
            <if test="officetel != null">OFFICETEL = #{officetel}, </if>
            <if test="email != null">EMAIL = #{email}, </if>
            <if test="address != null">ADDRESS = #{address}, </if>
            <if test="idcard != null">IDCARD = #{idcard}, </if>
            <if test="nativeplace != null">NATIVEPLACE = #{nativeplace}, </if>
            <if test="sex != null">SEX = #{sex}, </if>
            <if test="photourl != null">PHOTOURL = #{photourl}, </if>
            <if test="education != null">EDUCATION = #{education}, </if>
            <if test="speciality != null">SPECIALITY = #{speciality}, </if>
            <if test="jobtitle != null">JOBTITLE = #{jobtitle}, </if>
            <if test="joblevel != null">JOBLEVEL = #{joblevel}, </if>
            <if test="rcreateuser != null">RCREATEUSER = #{rcreateuser}, </if>
            <if test="rcreatedate != null">RCREATEDATE = #{rcreatedate}, </if>
            <if test="rlasteditdate != null">RLASTEDITDATE = #{rlasteditdate}, </if>
            <if test="remark != null">REMARK = #{remark}, </if>
            <if test="certificateurl != null">CERTIFICATEURL = #{certificateurl}</if>
            <!-- <if test="salt != null">SALT = #{salt}</if>  -->
        </set>
        where USERID = #{userid}
    </update>
 
 
 
    <delete id="delete">
        delete from ORG_USER where USERID = #{value}
    </delete>
 
    <delete id="deleteBatch">
        delete from ORG_USER where USERID in
        <foreach item="userid" collection="array" open="(" separator="," close=")">
            #{userid}
        </foreach>
    </delete>
 
    <select id="queryListForBareAPIwithUnit" resultType="com.landtool.lanbase.modules.org.entity.OrgUser">
        SELECT
            <include refid="userColumns"/>
        FROM ORG_USER ou
        LEFT JOIN ORG_USERUNIT ou2 ON ou.USERID = ou2.USERID
        LEFT JOIN ORG_UNIT ou3 ON ou3.UNITID=ou2.UNITID
        <if test="xzqhId != null">
        LEFT JOIN ORG_UNITREGION ou4 ON ou3.UNITID = ou4.UNITID
        LEFT JOIN ORG_REGION ox ON ou4.regionid = ox.regionid
        </if>
        WHERE 1=1
        <if test="xzqhId != null"> AND ou4.regionid = #{xzqhId} </if>
        <if test="unitId != null"> AND ou3.UNITID = #{unitId} </if>
    </select>
 
    <select id="queryListForBareAPIwithRole" resultType="com.landtool.lanbase.modules.org.entity.OrgUser">
        SELECT
            <include refid="userColumns"/>
        FROM ORG_USER ou
        LEFT JOIN ORG_USERGROUP oug ON  ou.userid = oug.userid
        LEFT JOIN ORG_GROUP og ON og.groupid = oug.groupid
        LEFT JOIN SYS_ROLEGROUP srr ON srr.groupid = og.groupid
        LEFT JOIN SYS_ROLE sr ON sr.ROLEID = srr.ROLEID
        LEFT JOIN SYS_SYSTEMINFO ss ON ss.APPID = sr.APPID
        WHERE 1=1
        <if test="appId != null"> AND ss.APPID = #{appId} </if>
    </select>
 
    <select id="queryListByTime" resultType="com.landtool.lanbase.modules.org.entity.OrgUser">
        SELECT
            <include refid="userColumns"/>
        FROM ORG_USER ou
        WHERE ou.RLASTEDITDATE >  #{time}
    </select>
 
    <select id="queryObjectJoinUnit" resultMap="UserJoinUnit">
        SELECT
            <include refid="userColumns"/>,
            <include refid="userUnitColumns"/>,
            <include refid="userGroupColumns"/>
        FROM ORG_USER ou
        LEFT JOIN ORG_USERUNIT ou2 ON ou2.USERID=ou.USERID
        LEFT JOIN ORG_USERGROUP ou3 ON ou3.USERID=ou.USERID
        WHERE ou.USERID = #{userId}
    </select>
 
    <select id="queryObjectJoinUnitByLoginname" resultMap="UserJoinUnit">
        SELECT
            <include refid="userColumns"/>,
            <include refid="userUnitColumns"/>,
            <include refid="userGroupColumns"/>
        FROM ORG_USER ou
        LEFT JOIN ORG_USERUNIT ou2 ON ou2.USERID=ou.USERID
        LEFT JOIN ORG_USERGROUP ou3 ON ou3.USERID=ou.USERID
        WHERE ou.loginname = #{loginname} limit 1
    </select>
 
    <select id="queryListWithUnitNames" resultMap="userUnitCell">
    with RECURSIVE tab(unitid,RCREATEUSER) as ( select unitid,RCREATEUSER from ORG_UNIT where unitid = #{unitid} union all select b.unitid,b.RCREATEUSER from tab a, ORG_UNIT b where b.parentid = a.unitid )
        select * from (
        SELECT  *
        FROM(
            SELECT ROW_NUMBER() OVER(ORDER BY rcreatedate DESC) AS rownumber,C.*
            FROM (
 
                SELECT
                      us.USERID,
                      us.LOGINNAME,
                      us.CHINESENAME,
                      us.USERSTATUS,
                      us.MOBILENO,
                      us.ISRECEIVEMSG,
                      us.RCREATEUSER,
                      us.RCREATEDATE,
                      b.UNITNAMES,
                      us.JOBLEVEL,
                      b.deptname
                FROM ORG_USER us
                LEFT JOIN (
                    SELECT
                        ouu.USERID,
                        max(ou.UNITNAME) AS UNITNAMES,
                        max(ou1.UNITNAME) as deptname,
                        max(ouu.RCREATEDATE) AS RCREATEDATE
                    FROM ORG_USERUNIT ouu
                    LEFT JOIN ORG_UNIT ou ON ouu.unitid=ou.unitid
                    LEFT JOIN ORG_UNIT ou1 ON ou1.unitid = ouu.deptid
                    where ouu.worktype = '1'
                    GROUP BY ouu.USERID
                )b  ON  us.USERID = b.USERID
                where 1 = 1
                <if test="isadmin != 1">
                AND (us.USERID =#{userid} or us.rcreateuser = #{userid} or exists(select ut.userid from ORG_USERUNIT ut
                         where us.userid = ut.userid
                         and ut.unitid in (select unitid from tab)))
                </if>
                    <if test="loginname != null and loginname != ''">
                        AND us.LOGINNAME LIKE ('%' || #{loginname} || '%')
                    </if>
                    <if test="userstatus != null and userstatus != ''">
                        AND cast(us.USERSTATUS as varchar) = #{userstatus}
                    </if>
                    <if test="chinesename != null and chinesename != ''">
                        AND (us.CHINESENAME LIKE ('%' || #{chinesename} || '%') or us.LOGINNAME LIKE ('%' || #{chinesename} || '%') or LOWER(us.spellfirst) LIKE ('%' || LOWER(#{chinesename}) || '%'))
                    </if>
                    <if test="unitname != null and unitname != ''">
                        AND exists(select ut.userid from ORG_USERUNIT ut JOIN ORG_UNIT un on un.unitid = ut.unitid where us.userid = ut.userid and (un.UNITNAME LIKE ('%' || #{unitname} || '%') or LOWER(un.spellfirst) LIKE ('%' || LOWER(#{unitname}) || '%')  )  )
                    </if>
 
                ) C
        ) A
        WHERE rownumber > #{lowerOffset} AND  <![CDATA[ rownumber <= ${upperOffset} ]]>
        )a order by
        <choose>
            <when test="sidx != null and sidx != ''">
                ${sidx} ${order}
            </when>
            <otherwise>
                rcreatedate DESC
            </otherwise>
        </choose>
    </select>
 
    <select id="queryTotalWithUnitNames" resultType="int">
    with RECURSIVE tab(unitid,RCREATEUSER) as ( select unitid,RCREATEUSER from ORG_UNIT where unitid = #{unitid} union all select b.unitid,b.RCREATEUSER from tab a, ORG_UNIT b where b.parentid = a.unitid )
        SELECT count(*)
        FROM(
            SELECT ROW_NUMBER() OVER(ORDER BY C.userid) AS rownumber,C.*
            FROM (
 
                SELECT
                      us.USERID,
                      us.LOGINNAME,
                      us.CHINESENAME,
                      us.USERSTATUS,
                      us.MOBILENO,
                      us.ISRECEIVEMSG,
                      us.RCREATEUSER,
                      us.RCREATEDATE,
                      b.UNITNAMES,
                      us.JOBLEVEL
                FROM ORG_USER us
                LEFT JOIN (
                    SELECT
                        ouu.USERID,
                        max(ou.UNITNAME) AS UNITNAMES,
                        max(ouu.RCREATEDATE) AS RCREATEDATE
                    FROM ORG_USERUNIT ouu
                    LEFT JOIN ORG_UNIT ou ON ouu.unitid=ou.unitid
                    GROUP BY ouu.USERID
                )b  ON  us.USERID = b.USERID
                where 1 = 1
                <if test="isadmin != 1">
                 AND (us.USERID =#{userid} or us.rcreateuser = #{userid} or exists(select ut.userid from ORG_USERUNIT ut
                         where us.userid = ut.userid
                         and ut.unitid in (select unitid from tab)))
                </if>
                    <if test="loginname != null and loginname != ''">
                        AND us.LOGINNAME LIKE ('%' || #{loginname} || '%')
                    </if>
                    <if test="userstatus != null and userstatus != ''">
                        AND cast(us.USERSTATUS as varchar) = #{userstatus}
                    </if>
                    <if test="chinesename != null and chinesename != ''">
                        AND (us.CHINESENAME LIKE ('%' || #{chinesename} || '%') or us.LOGINNAME LIKE ('%' || #{chinesename} || '%') or LOWER(us.spellfirst) LIKE ('%' || LOWER(#{chinesename}) || '%'))
                    </if>
                    <if test="unitname != null and unitname != ''">
                        AND exists(select ut.userid from ORG_USERUNIT ut JOIN ORG_UNIT un on un.unitid = ut.unitid where us.userid = ut.userid and (un.UNITNAME LIKE ('%' || #{unitname} || '%') or LOWER(un.spellfirst) LIKE ('%' || LOWER(#{unitname}) || '%')))
                    </if>
 
                ) C
        ) A
    </select>
 
    <select id="queryByUserName" resultType="com.landtool.lanbase.modules.org.entity.OrgUser" >
        select * from ORG_USER where LOGINNAME = #{value}
    </select>
 
    <select id="queryObjectJoinUnitByChineseName" resultMap="UserJoinUnit">
        select * from ORG_USER where  chinesename= #{value}
    </select>
 
    <select id="queryUserWithSEQ" resultType="int">
        SELECT currval('ORG_USER_SEQ') FROM DUAL
    </select>
 
    <select id="findUserByWord" resultType="com.landtool.lanbase.modules.org.entity.OrgUser">
        select userid,chinesename from ORG_USER
        <where>
        <if test="keyWord != null and keyWord != ''">
            LOGINNAME LIKE ('%' || #{keyWord} || '%')
            or CHINESENAME LIKE ('%' || #{keyWord} || '%')
            or LOWER(SPELLFIRST) LIKE ('%' || LOWER(#{keyWord}) || '%')
        </if>
        </where>
    </select>
 
    <update id="updateStatusByUserId" parameterType="com.landtool.lanbase.modules.org.entity.OrgUser">
        update ORG_USER
        <set>
            <if test="userStatus != null">USERSTATUS = #{userStatus},RLASTEDITDATE=now()</if>
        </set>
        where USERID = #{userId}
    </update>
 
    <update id="updatePassword" parameterType="com.landtool.lanbase.modules.org.entity.OrgUser">
        UPDATE ORG_USER SET password = #{newPassword}
        WHERE USERID = #{userId} AND PASSWORD = #{password}
    </update>
 
    <!-- 查询用户的所有菜单ID -->
    <select id="queryAllMenuId" resultType="long">
        select distinct rm.menu_id from SYS_USER_ROLE ur
            LEFT JOIN SYS_ROLE_MENU rm on ur.role_id = rm.role_id
        where ur.user_id = #{userId}
    </select>
 
    <select id="querySpellFirst" parameterType="java.lang.Integer" resultType="java.lang.String">
        <!-- alert 数据库中存在大小写的拼音,导致首字母重复 -->
        select UPPER(spellfirst) as spellfirst from
        (
        select UPPER(SUBSTR(spellfirst,1,1)) as spellfirst from ORG_USER
        where userid not in(#{userid}) and userstatus = 0 and userstatus is not null group by UPPER(SUBSTR(spellfirst,1,1))
        )a order by a.spellfirst
 
        <!--select UPPER(spellfirst) as spellfirst from
        (
            select SUBSTR(spellfirst,1,1) as spellfirst from ORG_USER
            where userid not in(#{userid}) and userstatus = 0 and userstatus is not null group by SUBSTR(spellfirst,1,1)
        )a order by a.spellfirst -->
    </select>
 
    <select id="queryListOrderByType" resultType="com.landtool.lanbase.modules.org.entity.OrgUser" >
        select * from ORG_USER a
        <if test="unitspellfirst != null and unitspellfirst != ''">
            left join ORG_USERUNIT b on a.userid = b.userid
            left join ORG_UNIT c on b.unitid = c.unitid
        </if>
        <if test="rolename != null and rolename != ''">
            left join ORG_USERGROUP b on a.userid = b.userid
            left join SYS_ROLEGROUP c on b.groupid = c.groupid
            left join SYS_ROLE d on c.roleid = d.roleid
        </if>
        where 1 = 1 and a.userid not in(#{userid}) and a.userstatus = 0
        <if test="spellfirst != null and spellfirst != ''">
            AND a.spellfirst LIKE ('' || #{spellfirst} || '%')
        </if>
        <choose>
            <when test="unitspellfirst != null and unitspellfirst == '-1'">
                AND c.unitid is null order by a.spellfirst
            </when>
            <when test="unitspellfirst != null and unitspellfirst != ''">
                AND c.unitid = #{unitspellfirst}
            </when>
        </choose>
        <choose>
            <when test="rolename != null and rolename == '-1'">
                AND d.rolename is null order by a.spellfirst
            </when>
            <when test="rolename != null and rolename != ''">
                AND d.rolename is not null AND d.rolename = #{rolename}
            </when>
        </choose>
    </select>
 
    <select id="queryUserUnitSpellFirst" parameterType="java.lang.Integer" resultType="java.lang.String">
        select d.unitname from(
            select distinct SUBSTR(c.spellfirst,1,1) as spellfirst,
            to_char(c.unitid)||'_'||c.unitname as unitname
            from ORG_USER a
            left join ORG_USERUNIT b on a.userid = b.userid
            left join ORG_UNIT c on b.unitid = c.unitid
            where a.userid not in(#{userid}) and a.userstatus = 0 and c.unitid is not null
        ) d order by d.spellfirst
    </select>
 
    <select id="queryUserRoleName" parameterType="java.lang.Integer" resultType="java.lang.String">
        select rolename from ORG_USER a
            left join ORG_USERGROUP b on a.userid = b.userid
            left join SYS_ROLEGROUP c on b.groupid = c.groupid
            left join SYS_ROLE d on c.roleid = d.roleid
        where a.userid not in(#{userid}) and a.userstatus = 0 group by d.rolename order by d.rolename
    </select>
 
    <select id="queryAllList" resultType="com.landtool.lanbase.modules.org.entity.OrgUser">
        select userid,chinesename from ORG_USER where userstatus = 0
    </select>
 
    <select id="queryByLoginname" resultType="java.lang.Integer" parameterType="java.lang.String">
        SELECT COUNT(*) from ORG_USER where loginname = #{loginname}
    </select>
 
    <select id="queryUserResCatalog" resultType="java.lang.Integer" parameterType="java.lang.String">
        SELECT * FROM  ROLE_CATALOGID_REL c WHERE ROLEID IN
        (
          SELECT  b.ROLEID FROM ORG_USERGROUP a LEFT JOIN SYS_ROLEGROUP b ON a.GROUPID=b.GROUPID
          WHERE a.USERID=4
        )  AND c.STATUS=1
    </select>
 
</mapper>