puzhibing
2026-05-12 08cc6d5cf7e93b75cfabe7dcc2aeaa9afa1117eb
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
<?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.XpOperationsRoleMapper">
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        operations_user_id, role_id
    </sql>
 
    <!-- 根据用户ID列表查询用户及角色信息 -->
    <select id="selectUsersWithRoleByIds" resultType="com.xiaopeng.api.vo.account.XpOperationsUserWithRoleVO">
        SELECT
            u.*,
            r.id AS roleId,
            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.id IN
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </select>
 
    <!-- 根据条件查询用户及角色信息 -->
    <select id="selectUsersByConditions" 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="nickName != null and nickName != ''">
                AND u.nick_name LIKE CONCAT('%', #{nickName}, '%')
            </if>
            <if test="phoneNumberQueryValues != null and phoneNumberQueryValues.size() > 0">
                AND u.phone_number IN
                <foreach collection="phoneNumberQueryValues" item="phoneNumberValue" open="(" separator="," close=")">
                    #{phoneNumberValue}
                </foreach>
            </if>
            <if test="roleId != null">
                AND r.id = #{roleId}
            </if>
        </where>
        GROUP BY u.id
    </select>
    <select id="selectSysUserRoleByOperationUserId"
            resultType="com.xiaopeng.api.model.account.XpOperationsRole">
        SELECT
            ur.operations_user_id AS operationsUserId,
            ur.role_id AS roleId
        FROM xp_operations_role ur
        WHERE ur.operations_user_id = #{userId}
    </select>
    <select id="selectSysUserRoleByOperationUserId"
            resultType="com.xiaopeng.api.model.account.XpOperationsRole">
        SELECT
            ur.operations_user_id AS operationsUserId,
            ur.role_id AS roleId
        FROM xp_operations_role ur
        WHERE ur.operations_user_id = #{userId}
    </select>
 
</mapper>