<?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.dayou.mapper.BusinessCommissionRateMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.BusinessCommissionRate">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="business_type" property="businessType" />
        <result column="user_type" property="userType" />
        <result column="business_cate_id" property="businessCateId" />
        <result column="min_ratio" property="minRatio" />
        <result column="max_ratio" property="maxRatio" />
        <result column="low_limit_amount" property="lowLimitAmount" />
        <result column="top_limit_amount" property="topLimitAmount" />
        <result column="quarter_ratio" property="quarterRatio" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        created,
        modified,
        business_type, user_type, business_cate_id, min_ratio, max_ratio, low_limit_amount, top_limit_amount, quarter_ratio
    </sql>

    <select id="page" parameterType="com.dayou.entity.BusinessCommissionRate" resultType="com.dayou.entity.BusinessCommissionRate">
        SELECT
            bcr.id,
            bcr.business_type, bcr.user_type, bcr.business_cate_id, bcr.min_ratio, bcr.max_ratio, bcr.low_limit_amount, bcr.top_limit_amount, bcr.quarter_ratio
            ,dd.name as businessCateName FROM `business_commission_rate` bcr left join dict_data dd on bcr.business_cate_id = dd.id
        where bcr.deleted = 0 and dd.deleted = 0 and bcr.business_type = #{rate.businessType} and bcr.user_type = #{rate.userType}
        <if test="rate.businessCateId!=null">
            and bcr.business_cate_id = #{rate.businessCateId}
        </if>
        order by bcr.created DESC
    </select>

    <select id="getBusinessCate" resultType="com.dayou.common.PullDownModel">
        SELECT
            bcr.id,
            dd.name
        FROM
            business_commission_rate bcr
                LEFT JOIN dict_data dd ON dd.id = bcr.business_cate_id
        WHERE
            bcr.deleted = 0
          AND dd.deleted = 0
          AND bcr.business_type = #{businessType}
          AND bcr.user_type = #{userType}
        ORDER BY
            bcr.id DESC
    </select>

</mapper>
