cloudroam
2025-03-28 5a1450c6f418a653d0e2cd6cd950b98093db73b3
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
<?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>
 
    <select id="searchUserInfo" resultType="com.mzl.flower.dto.response.system.UserListInfoDTO">
        SELECT
            user_id,
            id,
            name AS loginName,
            contact_tel tel,
            type
        FROM (
                 SELECT user_id, id, name, contact_tel, 'supplier' AS type
                 FROM t_supplier_info
                 WHERE user_id IN (SELECT id FROM t_user WHERE type = 'supplier')
 
                 UNION ALL
 
                 SELECT user_id, id, name, contact_tel, 'partner' AS type
                 FROM t_partner_info
                 WHERE user_id IN (SELECT id FROM t_user WHERE type = 'partner')
 
                 UNION ALL
 
                 SELECT c.user_id, c.id, c.name, u.tel AS contact_tel, 'customer' AS type
                 FROM t_customer_info c
                          JOIN t_user u ON c.user_id = u.id
                 WHERE c.user_id IN (SELECT id FROM t_user WHERE type = 'customer')
             ) AS combined_table
        <where>
        <if test="condition.userType != null and condition.userType != ''">
            AND type = #{condition.userType}
        </if>
        <if test="condition.id != null and condition.id != ''">
            AND id = #{condition.id}
        </if>
        <if test="condition.loginName != null and condition.loginName != ''">
            AND name like concat('%', #{condition.loginName},'%')
        </if>
        <if test="condition.tel != null and condition.tel != ''">
            AND contact_tel like concat('%', #{condition.tel},'%')
        </if>
        </where>
        ORDER BY user_id, id
    </select>
 
    <select id="getSelectList" resultType="com.mzl.flower.dto.response.sms.SmsSelectVO">
        SELECT
        user_id,
        id,
        name AS loginName,
        contact_tel tel,
        type
        FROM (
        SELECT user_id, id, name, contact_tel, 'supplier' AS type
        FROM t_supplier_info
        WHERE user_id IN (SELECT id FROM t_user WHERE type = 'supplier')
 
        UNION ALL
 
        SELECT user_id, id, name, contact_tel, 'partner' AS type
        FROM t_partner_info
        WHERE user_id IN (SELECT id FROM t_user WHERE type = 'partner')
 
        UNION ALL
 
        SELECT c.user_id, c.id, c.name, u.tel AS contact_tel, 'customer' AS type
        FROM t_customer_info c
        JOIN t_user u ON c.user_id = u.id
        WHERE c.user_id IN (SELECT id FROM t_user WHERE type = 'customer')
        ) AS combined_table
        <where>
            1=1
            <if test="idList != null and idList.size() > 0">
                AND user_id IN
                <foreach collection="idList" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>
</mapper>