<?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.dsk.cscec.mapper.CbSummaryActualMapper">

    <resultMap type="com.dsk.cscec.domain.CbSummaryActual" id="CbSummaryActualMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="cbSummaryId" column="cb_summary_id" jdbcType="INTEGER"/>
        <result property="taxInclusiveExpense" column="tax_inclusive_expense" jdbcType="NUMERIC"/>
        <result property="taxExclusiveExpense" column="tax_exclusive_expense" jdbcType="NUMERIC"/>
        <result property="expenseDate" column="expense_date" jdbcType="VARCHAR"/>
<!--        <result property="lockStatus" column="lock_status" jdbcType="INTEGER"/>-->
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="delFlag" column="del_flag" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="baseColumn">
        id, cb_summary_id, tax_inclusive_expense, tax_exclusive_expense, expense_date, create_time, del_flag
    </sql>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into cb_summary_actual(id,cb_summary_id, tax_inclusive_expense, tax_exclusive_expense,expense_date)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}, #{entity.cbSummaryId}, #{entity.taxInclusiveExpense}, #{entity.taxExclusiveExpense}, #{entity.expenseDate})
        </foreach>
        on duplicate key update
        cb_summary_id = values(cb_summary_id) , tax_inclusive_expense = values(tax_inclusive_expense) ,
        tax_exclusive_expense = values(tax_exclusive_expense) , expense_date = values(expense_date)
    </insert>

    <select id="getTotal" resultType="map">
        select ifnull(sum(csa.tax_inclusive_expense),0) taxInclusiveExpenseTotal,
            ifnull(sum(csa.tax_exclusive_expense),0) taxExclusiveExpenseTotal
        from cb_summary_actual csa
        <where>
            csa.cb_summary_id = #{cbSummaryId}
            and csa.expense_date &lt;= #{expenseDate}
            and csa.del_flag = 0
        </where>
    </select>
</mapper>

