<?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.com.countrygarden.bi.main.dao.wcx.WcxRoleMapper">

    <select id="selectPageData" resultType="cn.com.countrygarden.bi.main.dto.wcx.WcxRoleDto">
        select
        role_id            roleId,
        role_name          roleName,
        create_date        createDate,
        status             status,
        weight_ratio       weightRatio,
        (
        CASE
        WHEN role_type = '1'
        THEN point_number
        ELSE 0
        END
        ) numberPoints,
        (
        CASE
        WHEN role_type = '2'
        THEN point_number
        ELSE 0
        END
        ) goldenHammer,
        role_type          roleType,
        role_code          roleCode
        from wcx_role
        <where>
            <if test="roleName != null and roleName != ''">
                role_name like concat('%', #{roleName}, '%')
            </if>
        </where>
        limit #{pageOffset}, #{pageSize}
    </select>

    <select id="selectPageCount" resultType="int">
        select
        count(*)
        from wcx_role
        <where>
            <if test="roleName != null and roleName != ''">
                role_name like concat('%', #{roleName}, '%')
            </if>
        </where>
    </select>

    <update id="updateWeightRatio">
        UPDATE wcx_role
        SET  weight_ratio = #{weightRatio}
        WHERE role_type = '2'
    </update>

    <select id="selectWeightRatio" resultType="int">
        SELECT weight_ratio
        from wcx_role
        WHERE role_type = '2'
        limit 1
    </select>

    <select id="getThumsRoleOfLeader" resultType="int">
        SELECT weight_ratio FROM wcx_role WHERE role_type = '2' limit 1
    </select>

    <update id="update">
        UPDATE wcx_role
        SET role_type = #{roleType},
        point_number = #{pointNumber},
        role_code = #{roleCode},
        weight_ratio = #{weightRatio},
        role_name = #{roleName}
        WHERE role_id = #{roleId}
    </update>

    <select id="haveUserUnderRole" resultType="string">
        SELECT user_id FROM wcx_user WHERE role_id = #{roleId} limit 1
    </select>
</mapper>
