liuxiaolong
2019-05-06 f99bc8c6a1d10610373738edd7d0aa0181c81d99
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
<?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.cloud.user.dao.UserRoleDao">
 
    <delete id="deleteUserRole">
        delete from sys_role_user WHERE 1=1 and userId = #{id}
        <if test="orgId != null and orgId != ''">
            and orgId = #{orgId}
        </if>
    </delete>
 
    <delete id="deleteUserRoleByParams" >
        delete from sys_role_user WHERE 1=1
        <if test="id != null">
            and roleId = #{id}
        </if>
        <if test="orgId != null">
            and orgId = #{orgId}
        </if>
    </delete>
 
    <select id="findRolesByUserId" resultType="com.cloud.model.sys.SysRole">
        select r.* from sys_role_user ru inner join sys_role r on r.id = ru.roleId where ru.userId = #{userId}
        <if test="orgId != null and orgId != ''">
            and ru.orgId= #{orgId}
        </if>
    </select>
 
    <select id="findRolesIdsByUserId" resultType="Integer">
        select r.id from sys_role_user ru inner join sys_role r on r.id = ru.roleId where ru.userId = #{id}
        <!--<if test="orgId != null and orgId != ''">
            and r.orgId= #{orgId}
        </if>-->
    </select>
 
    <select id="findRolesIds" resultType="Integer">
        select roleId from sys_role_user  where userId = #{id}
    </select>
 
    <insert id="saveUserRoles">
        INSERT INTO sys_role_user
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">
                userId,
            </if>
            <if test="roleId != null">
                roleId,
            </if>
            <if test="orgId != null">
                orgId,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="userId != null">
                #{userId,jdbcType=INTEGER},
            </if>
            <if test="roleId != null">
                #{roleId,jdbcType=INTEGER},
            </if>
            <if test="orgId != null">
                #{orgId,jdbcType=INTEGER},
            </if>
        </trim>
    </insert>
 
    <select id="findUserRoleCount" resultType="int">
        SELECT count(roleId) from sys_role_user where roleId = #{id}
        <if test="orgId != null">
            and orgId = #{orgId}
        </if>
    </select>
</mapper>