<?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.ruoyi.info.collection.mapper.CcdiDebtsInfoMapper">

    <resultMap id="CcdiDebtsInfoResultMap" type="com.ruoyi.info.collection.domain.CcdiDebtsInfo">
        <id property="debtId" column="debt_id"/>
        <result property="personId" column="person_id"/>
        <result property="personName" column="person_name"/>
        <result property="queryDate" column="query_date"/>
        <result property="debtMainType" column="debt_main_type"/>
        <result property="debtSubType" column="debt_sub_type"/>
        <result property="creditorType" column="creditor_type"/>
        <result property="debtName" column="debt_name"/>
        <result property="principalBalance" column="principal_balance"/>
        <result property="debtTotalAmount" column="debt_total_amount"/>
        <result property="debtStatus" column="debt_status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <select id="selectByPersonId" resultMap="CcdiDebtsInfoResultMap">
        SELECT
            debt_id, person_id, person_name, query_date, debt_main_type, debt_sub_type, creditor_type,
            debt_name, principal_balance, debt_total_amount, debt_status, create_by, create_time, update_by, update_time
        FROM ccdi_debts_info
        WHERE person_id = #{personId}
        ORDER BY debt_id ASC
    </select>

    <delete id="deleteByPersonId">
        DELETE FROM ccdi_debts_info
        WHERE person_id = #{personId}
    </delete>

    <insert id="insertBatch">
        INSERT INTO ccdi_debts_info
        (person_id, person_name, query_date, debt_main_type, debt_sub_type, creditor_type,
         debt_name, principal_balance, debt_total_amount, debt_status, create_by, create_time, update_by, update_time)
        VALUES
        <foreach collection="list" item="item" separator=",">
            (#{item.personId}, #{item.personName}, #{item.queryDate}, #{item.debtMainType}, #{item.debtSubType}, #{item.creditorType},
             #{item.debtName}, #{item.principalBalance}, #{item.debtTotalAmount}, #{item.debtStatus}, #{item.createBy}, NOW(), #{item.updateBy}, NOW())
        </foreach>
    </insert>

</mapper>
