Cui Zhi Feng
2024-08-26 e65a268807c32ef2d066a6ee8375f927e95101fa
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
<?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.mzl.flower.mapper.system.UserMapper">
    <select id="loginUser" resultType="com.mzl.flower.entity.system.User">
        SELECT *
        FROM t_user t
        WHERE t.deleted = 0 AND t.status = 'A'
        and t.type = 'customer'
        and (t.login_name = #{username} or t.tel = #{username})
    </select>
 
    <select id="getActiveUser" resultType="com.mzl.flower.entity.system.User">
        SELECT *
        FROM t_user t
        WHERE (t.login_name = #{username} or t.tel = #{username})
        AND t.status = 'A'
        AND t.deleted = 0
        AND (t.`type` IN
            <foreach collection="userTypes" item="type" open="(" separator="," close=")">
                #{type}
            </foreach>
        )
    </select>
 
    <select id="searchUser" resultType="com.mzl.flower.dto.response.system.UserListDTO">
        SELECT
        u.ID AS id,
        u.LOGIN_NAME AS loginName,
        u.TEL AS tel,
        u.NICK_NAME AS nickName,
        u.STATUS AS STATUS,
        uu.NICK_NAME AS createdName,
        u.create_time AS createdDate,
        u.IS_SYS AS isSys,
        (SELECT GROUP_CONCAT(DISTINCT(role.ID)) FROM t_role role INNER JOIN t_user_role ur ON ur.ROLE_ID = role.ID
            WHERE
            ur.USER_ID = u.ID
            ORDER BY ROLE_NAME
        ) AS roleIds,
        (SELECT GROUP_CONCAT(DISTINCT(ROLE_NAME)) FROM t_role role INNER JOIN t_user_role ur ON ur.ROLE_ID = role.ID
            WHERE
            ur.USER_ID = u.ID
            ORDER BY ROLE_NAME
        ) AS roleDesc,
        e.birthday,
        e.gender,
        e.id_card,
        e.post_name,
        e.work_content,
        e.in_date,
        e.salary
        FROM t_user u
        LEFT JOIN t_user uu ON u.create_by = uu.id
        left join t_employee e on e.user_id = u.id
        where u.deleted = 0
        <if test="condition.loginName != null and condition.loginName != ''">
            AND (u.LOGIN_NAME LIKE concat('%', #{condition.loginName},'%')
                or u.NICK_NAME LIKE concat('%', #{condition.loginName},'%')
                or u.tel LIKE concat('%', #{condition.loginName},'%')
            )
        </if>
        <if test="condition.status != null and condition.status != ''">
            AND u.STATUS = #{condition.status}
        </if>
        AND (u.`type` in
            <foreach collection="condition.userTypes" item="type" open="(" separator="," close=")">
                #{type}
            </foreach>
        )
        order by u.create_time desc
    </select>
 
    <select id="selectUserRoleDesc" resultType="string">
        SELECT GROUP_CONCAT(DISTINCT(ROLE_NAME))
        FROM t_role role
        INNER JOIN t_user_role ur ON ur.ROLE_ID = role.ID
        WHERE ur.USER_ID = #{userId}
        ORDER BY ROLE_NAME
    </select>
    <select id="getByOpenID" resultType="com.mzl.flower.entity.system.User">
        SELECT
            t.*
        FROM
            t_user_wechat w
                LEFT JOIN t_user t ON t.id = w.user_id WHERE w.open_id = #{openId}
        AND t.`type` IN
        <foreach collection="userTypes" item="type" open="(" separator="," close=")">
            #{type}
        </foreach>
 
    </select>
</mapper>