WorkUserRoleMapper.xml 1.54 KB
Newer Older
cq990612's avatar
cq990612 committed
1 2 3
<?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="cn.wisenergy.mapper.WorkUserRoleMapper">
cq990612's avatar
cq990612 committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
    <insert id="insertBatch">
        INSERT INTO work_user_role
        (user_id,role_id)
        VALUES
        <foreach collection ="roleIds" item="roleId" separator =",">
            ( #{userId}, #{roleId})
        </foreach >


    </insert>
    <delete id="deleteByUserId">
        DELETE
        FROM work_user_role
        WHERE user_id = #{userId}
    </delete>
cq990612's avatar
cq990612 committed
19 20 21 22 23 24 25


    <select id="getRole" resultType="java.lang.Integer">
        SELECT role_id
        FROM work_user_role
        WHERE user_id = #{userId}
    </select>
26

cq990612's avatar
cq990612 committed
27 28 29 30 31 32 33 34
    <select id="getRoleUserLevel" resultType="cn.wisenergy.model.dto.UserRoleLevelDto">
select ur.user_id as 'user_id',r.id as 'role_id',l.name as 'level_name',l.rank as 'rank'
from work_user_role ur join work_role r on ur.role_id = r.id
join work_role_level rl on rl.role_id = r.id JOIN work_level l on l.id = rl.level_id
WHERE ur.user_id = #{userId}
ORDER BY rank desc


cq990612's avatar
cq990612 committed
35 36 37 38 39
    </select>
    <select id="getUserRoleDeptDtoByRoleId" resultType="cn.wisenergy.model.app.WorkUser">
        select u.id,u.name,u.dept_id
        from work_user_role r left JOIN work_user u on r.user_id = u.id
        <where>
cq990612's avatar
cq990612 committed
40
            u.status = 1
cq990612's avatar
cq990612 committed
41
            <if test="null != roleId">
cq990612's avatar
cq990612 committed
42
            AND  r.role_id = #{roleId}
cq990612's avatar
cq990612 committed
43 44 45
            </if>
            group by r.user_id
        </where>
cq990612's avatar
cq990612 committed
46
        ORDER BY CONVERT( u.name USING GBK ) ASC
cq990612's avatar
cq990612 committed
47
    </select>
cq990612's avatar
cq990612 committed
48
</mapper>