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
<?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.OrgUserAuthDao">
 
    <!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="com.landtool.lanbase.modules.org.entity.OrgUserAuth" id="userauthMap">
        <result property="authId" column="AUTHID"/>
        <result property="userId" column="USERID"/>
        <result property="authGrad" column="AUTHGRAD"/>
        <result property="authUserId" column="AUTHUSERID"/>
        <result property="rCreateUser" column="RCREATEUSER"/>
        <result property="rCreateDate" column="RCREATEDATE"/>
        <result property="rOrder" column="RORDER"/>
        <result property="authResult" column="AUTHRESULT"/>
    </resultMap>
    
    <resultMap type="com.landtool.lanbase.modules.org.entity.OrgUserJoinAuth" id="UserJoinAuthMap">
        <result property="userid" column="USERID"/>
        <result property="loginname" column="LOGINNAME"/>
        <result property="chinesename" column="CHINESENAME"/>
        <result property="userstatus" column="USERSTATUS"/>
        <result property="authId" column="AUTHID"></result>
        <result property="authGrad" column="AUTHGRAD"/>
        <result property="rCreateUser" column="RCREATEUSER"/>
        <result property="rCreateDate" column="RCREATEDATE"/>
        <result property="authResult" column="AUTHRESULT"/>
        <result property="rCreateUserName" column="RCREATEUSERNAME"/>
        <result property="rn" column="RN"/>
        <result property="unitname" column="unitname"/>
    </resultMap>
 
    <select id="queryObject" resultType="com.landtool.lanbase.modules.org.entity.OrgUserAuth">
        select * from ORG_USERAUTH where AUTHID = #{value}
    </select>
 
    <select id="queryList" resultType="com.landtool.lanbase.modules.org.entity.OrgUserAuth">
        SELECT *
        FROM(
            SELECT ROW_NUMBER() OVER(ORDER BY B.authId) AS rownumber,B.*
            FROM (
                    select * from ORG_USERAUTH
                ) B
        ) A
        WHERE rownumber > #{lowerOffset} AND  <![CDATA[ rownumber <= ${upperOffset} ]]>
    </select>
    
    <select id="queryOrgUserJoinAuthList" resultMap="UserJoinAuthMap">
        select * from (
        SELECT *
        FROM(
            SELECT ROW_NUMBER() OVER(ORDER BY B.userid) AS rownumber,B.*
            FROM (
                            select distinct(o.userid),loginname,chinesename,userstatus,a.authGrad,a.authId,a.rCreateUser
                            ,a.rCreateDate,a.authResult,a.rCreateUserName,o.spellfirst,d.unitname from ORG_USER o
                            left join (
                               select authId,userid,authGrad,rCreateUser,rCreateDate,authResult,chinesename rCreateUserName from
                               ( select o.*,u.chinesename, row_number() over(partition by o.userid  order by o.rCreateDate DESC) rn 
                                   from ORG_USERAUTH o left join ORG_USER u on o.rcreateuser = u.userid)tt where tt.rn=1
                               ) a  
                               on o.userid = a.userid 
                            left join (
                                        SELECT ouu.USERID,max(ou.UNITNAME) AS unitname,max(ou.spellfirst) AS spellfirst
                                        FROM ORG_USERUNIT ouu
                                        LEFT JOIN ORG_UNIT ou ON ouu.unitid=ou.unitid
                                        where ouu.worktype = '1'
                                        GROUP BY (ouu.USERID,ouu.rcreatedate)
                                        order by ouu.rcreatedate desc
                                    )d  ON  o.USERID = d.USERID
                         <where>
                            <if test="LoginName != null and LoginName!=''">
                                     AND loginname LIKE ('%' || #{LoginName} || '%')
                            </if>
                            <if test="U_STATUS != null and U_STATUS!=''">
                                     AND cast(userstatus as varchar) = #{U_STATUS}
                            </if>
                            <if test="U_CNAME != null and U_CNAME!=''">
                                     AND (chinesename LIKE ('%' || #{U_CNAME} || '%') or loginname LIKE ('%' || #{U_CNAME} || '%') or LOWER(o.spellfirst) LIKE ('%' || LOWER(#{U_CNAME}) || '%') )
                            </if>
                            <if test="systemName != null and systemName != ''">
                                AND (d.UNITNAME LIKE ('%' || #{systemName} || '%') or LOWER(d.spellfirst) LIKE ('%' || LOWER(#{systemName}) || '%'))
                            </if>
                        </where>
                           
                ) B
        ) A
        WHERE rownumber > #{lowerOffset} AND  <![CDATA[ rownumber <= ${upperOffset} ]]>
        )a order by  
        <choose>
            <when test="sidx != null and sidx != ''">
                ${sidx} ${order}
            </when>
            <otherwise>
                userid
            </otherwise>
        </choose>
    </select>
    
     <select id="queryTotal" resultType="int">
        select count(*) from ORG_USERAUTH
    </select>
    
    <select id="queryOrgUserJoinAuthTotal" resultType="int">
        select count(distinct(o.userid)) from ORG_USER o
        left join (
               select authId,userid,authGrad,rCreateUser,rCreateDate,authResult
               from( select o.*, row_number() over(partition by userid  order by rCreateDate DESC) rn from ORG_USERAUTH o)tt
               where tt.rn=1
        ) a  on o.userid = a.userid 
        left join (
        SELECT ouu.USERID,max(ou.UNITNAME) AS unitname,max(ou.spellfirst) AS spellfirst
        FROM ORG_USERUNIT ouu
        LEFT JOIN ORG_UNIT ou ON ouu.unitid=ou.unitid
        where ouu.worktype = '1'
        GROUP BY (ouu.USERID,ouu.rcreatedate)
        order by ouu.rcreatedate desc
        )d  ON  o.USERID = d.USERID
        <where>
            <if test="LoginName != null and LoginName!=''">
                 AND loginname LIKE ('%' || #{LoginName} || '%')
            </if>
            <if test="U_STATUS != null and U_STATUS!=''">
                   AND cast(userstatus as varchar) = #{U_STATUS}
            </if>
            <if test="U_CNAME != null and U_CNAME!=''">
                AND (chinesename LIKE ('%' || #{U_CNAME} || '%') or loginname LIKE ('%' || #{U_CNAME} || '%') or LOWER(o.spellfirst) LIKE ('%' || LOWER(#{U_CNAME}) || '%') )
            </if>
            <if test="systemName != null and systemName != ''">
                AND (d.UNITNAME LIKE ('%' || #{systemName} || '%') or LOWER(d.spellfirst) LIKE ('%' || LOWER(#{systemName}) || '%'))
            </if>
        </where>
    </select>
     
    <insert id="save" parameterType="com.landtool.lanbase.modules.org.entity.OrgUserAuth">
        insert into ORG_USERAUTH
        (
            USERID, 
            AUTHGRAD, 
            AUTHUSERID, 
            RCREATEUSER, 
            RCREATEDATE, 
            RORDER, 
            AUTHRESULT
        )
        values
        (
            #{userId,jdbcType=BIGINT},
            #{authGrad,jdbcType=BIGINT},
            #{authUserId,jdbcType=BIGINT},
            #{rCreateUser},
            #{rCreateDate},
            #{rOrder,jdbcType=VARCHAR},
            #{authResult,jdbcType=BIGINT}
        )
    </insert>
     
    <update id="update" parameterType="com.landtool.lanbase.modules.org.entity.OrgUserAuth">
        update ORG_USERAUTH
        <set>
            <if test="userId != null">USERID = #{userId}, </if>
            <if test="authGrad != null">AUTHGRAD = #{authGrad}, </if>
            <if test="authUserId != null">AUTHUSERID = #{authUserId}, </if>
            <if test="rCreateUser != null">RCREATEUSER = #{rCreateUser}, </if>
            <if test="rCreateDate != null">RCREATEDATE = #{rCreateDate}, </if>
            <if test="rOrder != null">RORDER = #{rOrder}, </if>
            <if test="authResult != null">AUTHRESULT = #{authResult}</if>
        </set>
        where AUTHID = #{authId}
    </update>
    
    <delete id="delete">
        delete from ORG_USERAUTH where AUTHID = #{value}
    </delete>
    
    <delete id="deleteBatch">
        delete from ORG_USERAUTH where AUTHID in
        <foreach item="authId" collection="array" open="(" separator="," close=")">
            #{authId}
        </foreach>
    </delete>
 
    <update id="updateAuthState" parameterType="com.landtool.lanbase.modules.org.entity.OrgUserAuth">
        update ORG_USERAUTH
        <set>
            AUTHRESULT = #{authResult}
        </set>
        where AUTHID = #{authId}
    </update>
</mapper>