<?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.yd.csf.service.dao.CommissionExpectedMapper">

    <resultMap id="BaseResultMap" type="com.yd.csf.service.model.CommissionExpected">
            <id property="id" column="id" />
            <result property="commissionExpectedBizId" column="commission_expected_biz_id" />
            <result property="policyNo" column="policy_no" />
            <result property="reconciliationCompany" column="reconciliation_company" />
            <result property="reconciliationCompanyBizId" column="reconciliation_company_biz_id" />
            <result property="commissionPeriod" column="commission_period" />
            <result property="totalPeriod" column="total_period" />
            <result property="commissionName" column="commission_name" />
            <result property="commissionType" column="commission_type" />
            <result property="commissionRatio" column="commission_ratio" />
            <result property="currency" column="currency" />
            <result property="commissionDate" column="commission_date" />
            <result property="status" column="status" />
            <result property="defaultExchangeRate" column="default_exchange_rate" />
            <result property="expectedAmount" column="expected_amount" />
            <result property="paidAmount" column="paid_amount" />
            <result property="remark" column="remark" />
            <result property="isDeleted" column="is_deleted" />
            <result property="creatorId" column="creator_id" />
            <result property="updaterId" column="updater_id" />
            <result property="createTime" column="create_time" />
            <result property="updateTime" column="update_time" />
    </resultMap>

    <sql id="Base_Column_List">
        id,commission_expected_biz_id,policy_no,reconciliation_company,reconciliation_company_biz_id,commission_period,
        total_period,commission_name,commission_type,commission_ratio,currency,default_exchange_rate,expected_amount,
        commission_date,status,paid_amount,remark,is_deleted,creator_id,
        updater_id,create_time,update_time
    </sql>

    <select id="getExpectedStatistics" resultType="com.yd.csf.service.vo.CommissionExpectedStatisticsVO">
        SELECT
            IFNULL(SUM(expected_amount),0) AS totalAmount,
            IFNULL(SUM(paid_amount),0) AS totalPaidAmount,
            COUNT(DISTINCT policy_no) AS totalPolicyCount
        FROM
            commission_expected
        WHERE
            id IN
            <foreach collection="expectedIds" item="item" open="(" close=")" separator=",">
                #{item}
            </foreach>
    </select>
</mapper>
