<?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.ga.core.mapper.commission.ReconciliationVarianceMapper">

    <resultMap id="VOMap" type="com.ga.core.vo.commission.ReconciliationVarianceVO"/>

    <!--
        차이 상세 일괄 등록.
        MyBatis foreach — Service에서 List<ReconciliationVarianceVO> 전달.
    -->
    <insert id="insertBatch">
        INSERT INTO reconciliation_variance
            (recon_id, policy_no, expected_amount, reported_amount,
             variance_reason, created_by, created_at)
        VALUES
        <foreach collection="list" item="v" separator=",">
            (#{v.reconId}, #{v.policyNo}, #{v.expectedAmount}, #{v.reportedAmount},
             #{v.varianceReason}, #{v.createdBy}, NOW())
        </foreach>
    </insert>

    <!-- 대사 입수 ID 기준 차이 상세 목록 조회 -->
    <select id="selectByRecon" resultMap="VOMap">
        SELECT variance_id, recon_id, policy_no,
               expected_amount, reported_amount, variance_reason,
               created_at, created_by
          FROM reconciliation_variance
         WHERE recon_id = #{reconId}
         ORDER BY variance_id ASC
    </select>

</mapper>
