jinlin
2023-12-28 63447fec93e8e562833db30bc848884001b808c4
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
<?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.zt.modules.sys.dao.SysUserDao">
 
    <select id="getList" resultType="com.zt.core.sys.model.SysUser">
        select a.*
        ,(select t2.name from sys_dept t2 where t2.id = a.dept_id) deptName
        from sys_user a
        where a.is_delete = 0
        <if test="username != null and username.trim() != ''">
            and (a.username like #{username} or a.nick_name like #{username})
        </if>
        <if test="deptId != null and deptId != 0">
            and a.dept_id = #{deptId}
        </if>
        <!--        <if test="status != null and status != ''">
                    and a.status = #{status}
                </if>
                <if test="companyId != null">
                    and a.company_id = #{companyId}
                </if>
                <if test="deptIds != null">
                    and a.dept_id in
                    <foreach item="id" collection="deptIds" open="(" separator="," close=")">
                        #{id}
                    </foreach>
                </if>-->
    </select>
 
    <select id="getById" resultType="com.zt.core.sys.model.SysUser">
        select a.id
             , a.dept_id
             , a.company_id
             , '1271368584383188993' as                                            TENANT_ID
             , a.username
             , a.real_name
             , a.mobile
             , (select t2.name from sys_dept t2 where t2.id = a.dept_id) deptName
        from sys_user a
        where a.is_delete = 0
          and a.id = #{value}
        limit 1
    </select>
 
    <select id="getByUsername" resultType="com.zt.core.sys.model.SysUser">
        select a.id
             , a.dept_id
             , a.company_id
             , '1271368584383188993' as TENANT_ID
             , a.username
             , a.real_name
             , a.mobile
             , (select t2.name from sys_dept t2 where t2.id = a.dept_id) deptName
             , a.password
        from sys_user a
        where a.is_delete = 0
          and username = #{value}
        limit 1
    </select>
    <select id="checkUserArea" resultType="com.zt.core.sys.model.SysUser">
        select a.*
        from sys_user a,
             sys_role_user b,
             sys_role c
        where b.is_delete = 0
          and c.is_delete = 0
          and a.id = #{userId}
          and b.user_id = a.id
          and c.id = b.role_id
          and ((#{localServer} = 'jd' and c.code in ('cjbm','ztsxlbm'))
              or (#{localServer} = 'cj'
                      and c.code in ('zlbm','tybm','ywzbm','tzbm','czbm','bzbm','dbsbm')
                )
            )
    </select>
    <select id="isGetByUsernameList" resultType="com.zt.core.sys.model.SysUser">
        select
        a.id
        ,a.dept_id
        ,a.company_id
        ,'1271368584383188993' as TENANT_ID
        ,a.username
        ,a.real_name
        ,a.mobile
        ,a.password
        from
        sys_user a
        where is_delete = 0
        and user_name = #{username}
        <if test="unitid != null and unitid != ''">
            and dept_id = #{unitid}
        </if>
        <if test="code != null and code != ''">
            or dept_id in (select id from sys_dept where code=#{code}))
        </if>
        <if test="password != null and password != ''">
            and password = #{password}
        </if>
    </select>
 
    <select id="isDomainName" resultType="com.zt.core.sys.model.SysUser">
        select a.id
             , a.dept_id
             , a.company_id
             , '1271368584383188993' as                                            TENANT_ID
             , a.username
             , a.real_name
             , a.mobile
             , (select t2.name from sys_dept t2 where t2.id = a.dept_id) deptName
        from sys_user a
        where a.is_delete = 0
#         and a.code = #{code}
    </select>
 
    <select id="userRoleInfo" resultType="com.zt.core.context.User">
        SELECT
        a.real_Name,
        c.name as roleName,
        (select name from sys_dept d where a.dept_id = d.ID AND d.is_delete=0 limit 1 ) as deptName
        FROM
        sys_user a,
        sys_role_user b,
        sys_role c,
        sys_role_menu e,
        sys_menu f
        WHERE 1=1
        <if test="userId != null and userId != ''">
            and a.id = #{userId}
        </if>
        <if test="username != null and username != ''">
            and a.username = #{username}
        </if>
        and a.id = b.user_id
        AND b.role_id = c.id
        and c.id = e.role_id
        and e.menu_id = f.id
        AND b.is_delete=0
        AND c.is_delete=0
        AND e.is_delete=0
        AND f.is_delete=0
        <if test="systemId != null and systemId != ''">
            and f.pid = #{systemId}
        </if>
        limit 1
    </select>
 
    <select id="getRoles" resultType="java.lang.String">
        SELECT group_concat(b.role_id) AS role_id
        FROM sys_role_user b
        WHERE b.is_delete = 0
          AND b.user_id = #{userId}
    </select>
 
    <select id="getRoleNames" resultType="java.lang.String">
        SELECT group_concat(a.name) AS name
        FROM sys_role a,
             sys_role_user b
        WHERE b.is_delete = 0
          AND b.user_id = #{userId}
          and a.is_delete = 0
        and a.id =b.role_id
    </select>
 
    <update id="updateLogin">
        update
        sys_user
        <trim prefix="set" suffixOverrides=",">
            <if test="loginErrorCount!=null">login_error_count=#{loginErrorCount},</if>
            <if test="isLocked!=null">is_locked=#{isLocked},</if>
            <if test="lastLoginErrorTime!=null">last_login_error_time=#{lastLoginErrorTime}</if>
        </trim>
        WHERE id=#{id}
    </update>
    <select id="getByDeptIds" resultType="com.zt.core.sys.model.SysUser">
        SELECT
        b.id
        ,b.dept_id
        ,b.company_id
        ,'1271368584383188993' as TENANT_ID
        ,b.username
        ,b.real_name
        ,b.mobile
        FROM
        sys_user b
        WHERE
        b.is_delete = 0
        and dept_id in
        <foreach collection="deptIds" index="index" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>
    <select id="getEntity" resultType="com.zt.core.sys.model.SysUser">
        SELECT b.id
             , b.dept_id
             , b.company_id
             , '1271368584383188993' as TENANT_ID
             , b.username
             , b.real_name
             , b.mobile
        FROM sys_user b
        WHERE b.is_delete = 0
          and b.id = #{id}
        limit 1
    </select>
    <select id="getNewConnectUser" resultType="com.zt.core.sys.model.SysUser">
        select *
        from sys_user
        where dept_id = #{newShipTeam}
          and id in (select user_id
                          from sys_role_user a,
                               sys_role b
                          where a.role_id = b.id
                            and b.code = 'tybm')
    </select>
    <select id="checkTestHome" resultType="java.lang.Integer">
        SELECT
            count( 1 )
        FROM
            sys_user
        WHERE
            is_delete = 0
          AND id = #{userId}
          AND (
                user_name IN ( 'admin', 'yszl' )
                OR id IN (
                SELECT
                    user_id
                FROM
                    sys_role_user b,
                    sys_role c
                WHERE
                    b.is_delete = 0
                  AND c.is_delete = 0
                  AND c.id = b.role_id
                  AND c.`code` IN ( 'xtglybm', 'ztsxlbm', 'dbsbm', 'zlbm', 'bzbm', 'czbm' )
            )
            )
    </select>
    <select id="getUsersList" resultType="com.zt.core.sys.model.SysUser">
        select real_name as name,id as id from sys_user
    </select>
    <select id="getUsersName" resultType="java.lang.String">
        select real_name from sys_user WHERE id=#{id}
    </select>
    <update id="updatePassword">
        update
        sys_user
        set password = #{password}
        WHERE id=#{id}
    </update>
</mapper>