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
<?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.xiaopeng.account.mapper.XpOperationsUserMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, nick_name, unique_number, avatar, password, phone_number, remarks, status, id_card_front, id_card_back, driver_license, certificate_of_no_criminal_record, training_graduation_certificate, is_deleted, create_time, update_time, create_by, update_by
    </sql>
    <select id="selectUserPageByConditions"
            resultType="com.xiaopeng.api.vo.account.XpOperationsUserWithRoleVO">
        SELECT
        u.*,
        r.id AS roleId,
        GROUP_CONCAT(r.role_name) AS roleName
        FROM xp_operations_user u
        LEFT JOIN xp_operations_role ur ON u.id = ur.operations_user_id
        LEFT JOIN sys_role r ON ur.role_id = r.id AND r.is_deleted = 0
     <where>
        u.is_deleted = 0
        <if test="query.nickName != null and query.nickName != ''">
            AND u.nick_name LIKE CONCAT('%', #{query.nickName}, '%')
        </if>
        <if test="query.phoneNumber != null and query.phoneNumber != ''">
            AND u.phone_number LIKE CONCAT('%', #{query.phoneNumber}, '%')
        </if>
        <if test="query.roleId != null">
            AND r.id = #{query.roleId}
        </if>
        <if test="query.ids != null and query.ids.size() > 0">
            AND u.id IN
            <foreach collection="query.ids" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
 
     </where>
        GROUP BY u.id
        ORDER BY u.create_time DESC
    </select>
    <select id="pageList" resultType="com.xiaopeng.api.vo.account.XpOperationsUserVO">
        SELECT xou.id, xou.nick_name, xou.unique_number, xou.avatar,xou.sex, xou.password, xou.phone_number, xou.remarks, xou.status,
        xou.id_card_front, xou.id_card_back, xou.driver_license, xou.certificate_of_no_criminal_record,
        xou.training_graduation_certificate, xou.is_deleted, xou.create_time, xou.update_time, xou.create_by
            from xp_operations_user xou
        where xou.is_deleted = 0
            <if test="query.nickName != null and query.nickName != ''">
                and xou.nick_name like concat('%',#{query.nickName},'%')
            </if>
            <if test="query.phoneNumber != null and query.phoneNumber != ''">
                and xou.phone_number like concat('%',#{query.phoneNumber},'%')
            </if>
            <if test="query.roleId != null">
                AND EXISTS (SELECT 1 FROM xp_operations_role xore
                    WHERE xore.operations_user_id = xou.id
                    AND xore.role_id = #{query.roleId})
            </if>
            <if test="query.status != null">
                and xou.status = #{query.status}
            </if>
        order by xou.create_time desc
    </select>
 
 
    <select id="exportOperationsUser" resultType="com.xiaopeng.api.vo.account.ExportOperationsUserVo">
        SELECT
        xou.id,
        xou.nick_name,
        xou.unique_number,
        xou.avatar,
        xou.PASSWORD,
        xou.phone_number,
        xou.remarks,
        xou.STATUS,
        xou.id_card_front,
        xou.id_card_back,
        xou.driver_license,
        xou.certificate_of_no_criminal_record,
        xou.training_graduation_certificate,
        xou.is_deleted,
        xou.create_time,
        xou.update_time,
        xou.create_by,
        bb.roleName
        FROM
        xp_operations_user xou
        left join (
        select a.operations_user_id, GROUP_CONCAT(b.role_name SEPARATOR ';') as roleName from xp_operations_role a
        left join sys_role b on (a.role_id = b.id)
        group by a.operations_user_id
        ) bb on (xou.id = bb.operations_user_id)
        WHERE xou.is_deleted = 0
        <if test="query.nickName != null and query.nickName != ''">
            and xou.nick_name like concat('%',#{query.nickName},'%')
        </if>
        <if test="query.phoneNumber != null and query.phoneNumber != ''">
            and xou.phone_number like concat('%',#{query.phoneNumber},'%')
        </if>
        <if test="query.roleId != null">
            AND EXISTS (SELECT 1 FROM xp_operations_role xore
            WHERE xore.operations_user_id = xou.id
            AND xore.role_id = #{query.roleId})
        </if>
        <if test="query.status != null">
            and xou.status = #{query.status}
        </if>
        order by xou.create_time desc
    </select>
 
 
    <select id="findList" resultType="com.xiaopeng.api.vo.account.XpOperationsUserVO">
    </select>
 
    <select id="pageListByIds" resultType="com.xiaopeng.api.vo.account.XpOperationsUserWithRoleVO">
        SELECT
        u.*,
        r.id AS roleId,
        GROUP_CONCAT(r.role_name) AS roleName
        FROM xp_operations_user u
        LEFT JOIN xp_operations_role ur ON u.id = ur.operations_user_id
        LEFT JOIN sys_role r ON ur.role_id = r.id AND r.is_deleted = 0
        <where>
            u.is_deleted = 0
            <if test="query.nickName != null and query.nickName != ''">
                AND u.nick_name LIKE CONCAT('%', #{query.nickName}, '%')
            </if>
            <if test="query.roleId != null">
                AND r.role_name LIKE CONCAT('%', #{query.role}, '%')
            </if>
            <if test="query.ids != null and query.ids.size() > 0">
                AND u.id IN
                <foreach collection="query.ids" item="id" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
 
        </where>
        GROUP BY u.id
        ORDER BY u.create_time DESC
    </select>
 
</mapper>