kongzy
2024-07-01 47a751cb301d05276ae5d75145d57b2d090fe4e1
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
<?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.nanometer.smartlab.dao.SysUserDao">
  <resultMap id="SysUser" type="com.nanometer.smartlab.entity.SysUser">
    <id property="id" column="id"/>
    <result property="arp" column="arp"></result>
    <result property="account" column="account"></result>
    <result property="password" column="password"></result>
    <result property="company" column="company"></result>
    <result property="department" column="department"></result>
    <result property="departmentName" column="department_name"></result>
    <result property="name" column="name"></result>
    <result property="phone" column="phone"></result>
    <result property="email" column="email"></result>
    <result property="point" column="point"></result>
    <result property="memo" column="memo"></result>
    <result property="idCard" column="id_card"></result>
    <result property="approverFlag" column="approver_flag" typeHandler="com.nanometer.smartlab.entity.handler.ApproverFlagHandler"></result>
    <result property="seeFlag" column="see_flag" typeHandler="com.nanometer.smartlab.entity.handler.SeeFlagHandler"></result>
    <result property="roleId" column="role_id"></result>
    <result property="validFlag" column="valid_flag" typeHandler="com.nanometer.smartlab.entity.handler.ValidFlagHandler"></result>
    <result property="createTime" column="create_time"></result>
    <result property="updateTime" column="update_time"></result>
    <result property="roleName" column="roleName"></result>
    <result property="containerCodeList" column="containerCodeList"></result>
    <result property="projectId" column="project_id"></result>
     <result property="projectName" column="project_name"></result>
    <result property="url" column="url"></result>
    <result property="score" column="score"></result>
    <result property="waster" column="waster" typeHandler="com.nanometer.smartlab.entity.handler.WasterHandler"></result>
  </resultMap>
 
    <resultMap id="SysUserDto" type="com.nanometer.smartlab.entity.dto.SysUserDto">
        <id property="id" column="id"/>
        <result property="arp" column="arp"/>
        <result property="account" column="account"/>
        <result property="department" column="department"/>
        <result property="name" column="name"/>
        <result property="point" column="point"/>
        <collection property="sysLaboratory" ofType="com.nanometer.smartlab.entity.dto.SysLaboratoryDto" fetchType="lazy">
            <id property="id" column="sl_id"/>
            <result property="name" column="sl_name"/>
            <collection property="sysLaboratoryContainer" ofType="com.nanometer.smartlab.entity.dto.SysLaboratoryContainerDto" fetchType="lazy">
                <id property="id" column="slc_id"/>
                <result property="name" column="slc_name"/>
            </collection>
        </collection>
    </resultMap>
 
  <sql id="queryWhereSql">
    <if test="arp != null and arp != ''">
      and su.arp like #{arp}
    </if>
    <if test="name != null and name != ''">
      and su.name like #{name}
    </if>
    <if test="account != null and account != ''">
      and su.account like #{account}
    </if>
    <if test="idCard != null and idCard != ''">
      and su.id_card like #{idCard}
    </if>
    <if test="department != null and department != ''">
      and su.department = #{department}
    </if>
    <if test="approverFlag != null">
      and su.approver_flag = #{approverFlag}
    </if>
    <if test="seeFlag != null">
      and su.see_flag = #{seeFlag}
    </if>
    <if test="editId != null and editId != ''">
      and su.id != #{editId}
    </if>
    <if test="waster != null">
        and su.waster = #{waster}
    </if>
    <if test="projectId != null and projectId != ''">
        and su.project_id =#{projectId}
    </if>
      <if test="projectName != null and projectName != ''">
          and sp.project_name like concat("%",#{projectName},"%")
      </if>
    <if test="company != null and company != ''">
         and bm1.meta_value like concat("%",#{company},"%")
    </if>
  </sql>
 
  <select id="getSysUser"  resultMap="SysUser" >
    select * from sys_user
    where id = #{id} and valid_flag = 1
  </select>
 
  <select id="getUser"  resultMap="SysUser">
    select
    sys_user.id,
    sys_user.`name`,
    sys_user.phone,
    sys_user.project_id,
    base_meta.meta_value as department_name
    from sys_user
    left join  base_meta on sys_user.department = base_meta.id
    where sys_user.id = #{id}
    and sys_user.valid_flag = 1
    and base_meta.valid_flag = 1
  </select>
 
  <insert id="insertUserFavor" parameterType="java.util.Map" useGeneratedKeys = "true" keyProperty = "id">
    insert  into favor(user_id,reagent_id,create_time) value (#{user},#{reagent},now());
  </insert>
 
  <select id="getSysUserForSuppllier"  resultMap="SysUser" >
    select * from sys_user
    where id = #{id}
  </select>
 
  <delete id="deleteUserFavor"  parameterType="java.util.Map">
DELETE  FROM  favor
WHERE   id =  #{id};
 </delete>
    <select id="selectUserFavor" parameterType="java.util.Map"  resultType="java.lang.Integer">
  select  count(1) from favor
  where user_id = #{user}
    and reagent_id = #{reagent}
 </select>
 
 
 
  <select id="getSysUserByIdCard"   resultMap="SysUser" >
    select * from sys_user
    where id_card = #{idCard}
    and valid_flag = 1
    limit 1
  </select>
 
  <select id="getSysUserList" parameterType="java.util.Map" resultMap="SysUser">
    select su.*, br.name as roleName,sp.project_name from sys_user as su
    left join base_role as br on su.role_id = br.id
      left join base_meta bm on su.department = bm.id
      left join base_meta bm1 on bm1.id = su.company
    left join sys_project sp on sp.id=su.project_id
    where su.valid_flag = 1
      <if test="departmentNameLike != null and departmentNameLike != ''">
          and bm.meta_value  like #{departmentNameLike}
      </if>
    <include refid="queryWhereSql"/>
    order by su.arp ASC
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
    <select id="getSysUserSimpleInfoList" parameterType="java.util.Map" resultMap="SysUser">
        select su.id,su.arp,su.account,su.name,su.phone,su.email,su.create_time,su.project_id,bm.meta_value as department,bm1.meta_value as company,sp.project_name  from sys_user as su
        left join base_meta bm on su.department = bm.id
        left join base_meta bm1 on bm1.id = su.company
        left join sys_project sp on sp.id=su.project_id
        where su.valid_flag = 1
        <include refid="queryWhereSql"/>
        order by su.arp ASC
        <if test="first != null and pageSize != null">
            limit #{first}, #{pageSize}
        </if>
    </select>
 
  <select id="getHasProjectSysUserList" parameterType="java.util.Map" resultMap="SysUser">
    select DISTINCT su.*, br.name as roleName from sys_user as su
    left join base_role as br on su.role_id = br.id
    inner join sys_project as sp on su.id=sp.sys_user_id
    where su.valid_flag = 1
      <if test="department != null and department != ''">
          and su.department = #{department}
      </if>
      <if test="approverFlag != null">
          and su.approver_flag = #{approverFlag}
      </if>
      <if test="projectId != null and projectId != ''">
          and su.project_id =#{projectId}
      </if>
    order by su.arp ASC
    <if test="first != null and pageSize != null">
      limit #{first}, #{pageSize}
    </if>
  </select>
 
  <select id="getSysUserInfoList" parameterType="java.util.Map" resultMap="SysUser">
    select u.name,u.see_flag,u.role_id,u.valid_flag,u.id_card,u.point,group_concat(container_code SEPARATOR ',') containerCodeList ,u.arp, bm1.meta_value department,bm2.meta_value company,u.project_id projectId,
    u.url,u.score
    from sys_user u
    left join sys_laboratory l on l.department = u.department and l.valid_flag = 1
    left join sys_laboratory_container c on c.laboratory_id = l.id and c.valid_flag = 1
    left join base_meta bm1 on bm1.id = u.department
    left join base_meta bm2 on bm2.id = u.company
    where u.update_time >= #{startTime} and #{endTime} > u.update_time
    group by u.id;
  </select>
 
  <select id="getSysUserTotalCount" parameterType="java.util.Map" resultType="int">
    select count(1) from sys_user as su
    left join base_meta bm on su.department = bm.id
    left join base_meta bm1 on bm1.id = su.company
      left join sys_project sp on sp.id=su.project_id
    where su.valid_flag = 1
      <if test="departmentNameLike != null and departmentNameLike != ''">
          and bm.meta_value  like #{departmentNameLike}
      </if>
    <include refid="queryWhereSql"/>
  </select>
 
  <insert id="insertSysUser" parameterType="com.nanometer.smartlab.entity.SysUser" useGeneratedKeys = "true" keyProperty = "id">
    insert into sys_user( arp, account, password, company, department, name, phone, email, memo, id_card, approver_flag, see_flag, role_id, valid_flag, create_time, update_time,project_id,waster,url,score)
    values ( #{arp}, #{account}, #{password}, #{company}, #{department}, #{name}, #{phone}, #{email}, #{memo}, #{idCard}, #{approverFlag}, #{seeFlag}, #{roleId}, 1, now(), now(),#{projectId},#{waster},#{url},#{score})
  </insert>
 
  <update id="updateSysUser" parameterType="com.nanometer.smartlab.entity.SysUser">
    update sys_user set arp=#{arp}, account=#{account}, password=#{password}, company=#{company}, department=#{department}, name=#{name}, phone=#{phone},
    email=#{email}, memo=#{memo}, id_card=#{idCard}, approver_flag=#{approverFlag}, see_flag=#{seeFlag}, role_id=#{roleId}, point=#{point},update_time=now(),project_id=#{projectId},waster=#{waster},
    url= #{url},
    score = #{score}
    where id=#{id}
  </update>
 
  <update id="deleteSysUsers" parameterType="java.util.List">
    update sys_user set valid_flag=0, update_time=now()
    where id in
    <foreach collection="list" item="item" index="index" open="(" separator="," close=")">
      #{item}
    </foreach>
  </update>
 
  <select id="getSysUserInfoByContainerCode" resultMap="SysUser">
      select u.name,u.see_flag,u.role_id,u.valid_flag,u.id_card,container_code from sys_user u
    left join sys_laboratory l on l.department = u.department and l.valid_flag = 1
    left join sys_laboratory_container c on c.laboratory_id = l.id and c.valid_flag = 1
    where u.id = #{0} and container_code = #{1}
  </select>
 
  <select id="getUserListByContainerCode" parameterType="java.util.Map" resultMap="SysUser">
    select u.name,u.see_flag,u.role_id,u.valid_flag,u.id_card,container_code,bm2.meta_value department,bm1.meta_value company,u.arp,u.point
    from sys_user u
    left join sys_laboratory l on l.department = u.department and l.valid_flag = 1
    left join sys_laboratory_container c on c.laboratory_id = l.id and c.valid_flag = 1
    left join base_meta bm1 on bm1.id = u.company
    left join base_meta bm2 on bm2.id = u.department
    where container_code = #{0}
    and u.update_time >= #{1} and #{2} > u.update_time
  </select>
 
 
  <select id="selectByAccount" parameterType="com.nanometer.smartlab.entity.SysUser" resultMap="SysUser">
    select * from sys_user where valid_flag=1 and account=#{account}
  </select>
    <select id="selectUserInfo" resultMap="SysUserDto">
    SELECT
    su.id,
    su.arp,
    su.account,
    su.`name`,
    su.point,
    bm1.meta_value department,
    sl.id sl_id,
    sl.`name` sl_name,
    slc.id slc_id,
    slc.`name` slc_name
    FROM sys_user su
    LEFT JOIN base_meta bm1 on bm1.id = su.department
    LEFT JOIN sys_laboratory sl on sl.department = su.department
    LEFT JOIN sys_laboratory_container slc on slc.laboratory_id = sl.id
    WHERE su.valid_flag = 1
    and sl.valid_flag = 1
    and slc.valid_flag = 1
    ORDER BY su.`name` asc
    </select>
 
    <select id="getUserListByProject" parameterType="java.util.Map" resultMap="SysUser">
    SELECT u.name,u.see_flag,u.role_id,u.valid_flag,u.id_card,bm2.meta_value department,bm1.meta_value company,u.arp,u.point,u.project_id
    from sys_user u
    left join base_meta bm1 on bm1.id = u.company
    left join base_meta bm2 on bm2.id = u.department
    where
    u.project_id = #{0}
    and u.valid_flag = 1
    and u.update_time >= #{1} and #{2} > u.update_time
    </select>
    <select id="getUserByAccount" resultType="com.nanometer.smartlab.entity.dto.HazardousWasteUser">
    SELECT
    su.id,
    su.account,
    su.id_card,
    su.`name`,
    su.`password`,
    su.waster as adminFlag,
    su.project_id,
    bm.meta_value as department,
    com.meta_value as company_name,
    com.id as company,
    sp.project_name
    FROM sys_user AS su
    LEFT JOIN base_meta bm ON su.department = bm.id
    LEFT JOIN base_meta com on com.id = su.company
    left join sys_project sp on sp.id=su.project_id
    <where>
        su.valid_flag = 1
        <if test="account != null and account !=''">
            AND su.account = #{account}
        </if>
        <if test="userId != null ">
            AND su.id = #{userId}
        </if>
    </where>
    </select>
    <select id="getUserByProject" resultType="com.nanometer.smartlab.entity.dto.LaboratoryVo$LaboratoryUser">
    SELECT
    `name` as username
    FROM sys_user
    WHERE
        valid_flag = '1'
    AND waster = '1'
    AND project_id = #{projectId};
    </select>
    <select id="getUserByArp" resultMap="SysUser">
        select * from sys_user
        where arp = #{0} and valid_flag = 1
    </select>
    <select id="getUserCountInProject" parameterType="java.util.Map"  resultType="java.lang.Integer">
        select count(1) from sys_user as su
        left join base_meta bm on su.department = bm.id
        left join base_meta bm1 on bm1.id = su.company
        left join sys_project sp on sp.id=su.project_id
        where su.valid_flag = 1
        <if test="departmentNameLike != null and departmentNameLike != ''">
            and bm.meta_value  like concat("%",#{departmentNameLike},"%")
        </if>
        <if test="arp != null and arp != ''">
            and su.arp like concat("%",#{arp},"%")
        </if>
        <if test="name != null and name != ''">
            and su.name like concat("%",#{name},"%")
        </if>
        <if test="company != null and company != ''">
            and bm1.meta_value like concat("%",#{company},"%")
        </if>
        <if test="projectId != null and projectId != ''">
            and su.project_id=#{projectId}
        </if>
        <if test="projectName != null and projectName != ''">
            and sp.projectName like concat("%",#{projectId},"%")
        </if>
    </select>
    <select id="getUserInProject" parameterType="java.util.Map" resultMap="SysUser">
        select su.*, br.name as roleName from sys_user as su
        left join base_role as br on su.role_id = br.id
        left join base_meta bm on su.department = bm.id
        left join base_meta bm1 on bm1.id = su.company
        left join sys_project sp on sp.id=su.project_id
        where su.valid_flag = 1
        <if test="departmentNameLike != null and departmentNameLike != ''">
            and bm.meta_value  like concat("%",#{departmentNameLike},"%")
        </if>
        <if test="arp != null and arp != ''">
            and su.arp like concat("%",#{arp},"%")
        </if>
        <if test="name != null and name != ''">
            and su.name like concat("%",#{name},"%")
        </if>
        <if test="company != null and company != ''">
            and bm1.meta_value like concat("%",#{company},"%")
        </if>
        <if test="projectId != null and projectId != ''">
            and su.project_id=#{projectId}
        </if>
        <if test="projectName != null and projectName != ''">
            and sp.project_name like concat("%",#{projectName},"%")
        </if>
        order by su.arp ASC
        <if test="first != null and pageSize != null">
            limit #{first}, #{pageSize}
        </if>
    </select>
    <select id="getExportUserList" resultType="Map">
        select
        bm.meta_value AS departmentName,
        bm1.meta_value AS companyName,
        su.project_id,
        sp.project_name projectName,
        su.arp,
        su.name,
        su.account,
        su.id_card as idCard,
        su.phone,
        su.email,
        su.memo,
        br.name AS roleName,
        CASE WHEN su.approver_flag=0 then '否' else '是' END AS approver,
        CASE WHEN su.see_flag=2 then '一般人员' WHEN su.see_flag=3 then '安全员' WHEN su.see_flag=11 then '系统管理员'WHEN su.see_flag=0 then '实验室管理员' END AS seeName,
        CASE WHEN su.waster=2 then '危废管理员' WHEN su.waster=1 then '危废处理人员' else '' END AS wasterName,
        su.update_time as updateTime
        from sys_user as su
        left join base_role as br on su.role_id = br.id
        left join base_meta bm on su.department = bm.id
        left join base_meta bm1 on bm1.id = su.company
        left join sys_project sp on sp.id=su.project_id
        <where>
            su.valid_flag = 1
            <if test="arp != null and arp != ''">
                and su.arp like #{arp}
            </if>
            <if test="name != null and name != ''">
                and su.name like concat("%",#{name},"%")
            </if>
            <if test="departmentName != null and departmentName != ''">
                and su.department like concat("%",#{departmentName},"%")
            </if>
            <if test="projectId != null and projectId != ''">
                and su.project_id =#{projectId}
            </if>
            <if test="company != null and company != ''">
                and bm1.meta_value like concat("%",#{company},"%")
            </if>
        </where>
        order by su.arp ASC
    </select>
    <select id="getLibrarianEmail" resultType="java.lang.String">
        select su.email
        from sys_user  as su
        left join base_role as br on br.id = su.role_id
        where
            su.valid_flag = 1
        and br.name = '库管员'
        and su.email is not null
        and su.email != ''
    </select>
    <select id="getUserByName" resultMap="SysUser">
    select * from sys_user
    where name = #{name} and valid_flag = 1
    </select>
    <update id="updateUserPointBySelective" parameterType="java.util.Map">
    update sys_user set point=#{point}
    <where>
        <if test="id != null">
            id = #{id}
        </if>
    </where>
    </update>
</mapper>