<?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.ccdi.project.mapper.CcdiBankTagResultMapper">

    <resultMap id="CcdiBankTagResultMap" type="com.ruoyi.ccdi.project.domain.entity.CcdiBankTagResult">
        <id property="id" column="id"/>
        <result property="projectId" column="project_id"/>
        <result property="modelCode" column="model_code"/>
        <result property="modelName" column="model_name"/>
        <result property="ruleCode" column="rule_code"/>
        <result property="ruleName" column="rule_name"/>
        <result property="indicatorCode" column="indicator_code"/>
        <result property="resultType" column="result_type"/>
        <result property="riskLevel" column="risk_level"/>
        <result property="bankStatementId" column="bank_statement_id"/>
        <result property="objectType" column="object_type"/>
        <result property="objectKey" column="object_key"/>
        <result property="groupId" column="group_id"/>
        <result property="logId" column="log_id"/>
        <result property="reasonDetail" column="reason_detail"/>
        <result property="businessCaliberSnapshot" column="business_caliber_snapshot"/>
        <result property="hitValueSnapshot" column="hit_value_snapshot"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <resultMap id="CcdiBankStatementHitTagVOResultMap" type="com.ruoyi.ccdi.project.domain.vo.CcdiBankStatementHitTagVO">
        <result property="ruleCode" column="rule_code"/>
        <result property="ruleName" column="rule_name"/>
        <result property="riskLevel" column="risk_level"/>
        <result property="reasonDetail" column="reason_detail"/>
        <result property="bankStatementId" column="bank_statement_id"/>
    </resultMap>

    <delete id="deleteByProjectAndModel">
        delete from ccdi_bank_statement_tag_result
        where project_id = #{projectId}
        <if test="modelCode != null and modelCode != ''">
            and model_code = #{modelCode}
        </if>
    </delete>

    <select id="selectStatementTagsByProjectAndStatementIds" resultMap="CcdiBankStatementHitTagVOResultMap">
        select
            rule_code,
            rule_name,
            risk_level,
            reason_detail,
            bank_statement_id
        from ccdi_bank_statement_tag_result
        where project_id = #{projectId}
          and bank_statement_id is not null
          and bank_statement_id IN
        <foreach collection="bankStatementIds" item="item" open="(" separator="," close=")">
            #{item}
        </foreach>
        order by bank_statement_id asc, id asc
    </select>

    <insert id="insertBatch" parameterType="java.util.List">
        insert into ccdi_bank_statement_tag_result (
            project_id, model_code, model_name, rule_code, rule_name, indicator_code,
            result_type, risk_level, bank_statement_id, object_type, object_key, group_id,
            log_id, reason_detail, business_caliber_snapshot, hit_value_snapshot,
            create_by, create_time, update_by, update_time, remark
        ) values
        <foreach collection="list" item="item" separator=",">
            (
                #{item.projectId}, #{item.modelCode}, #{item.modelName}, #{item.ruleCode}, #{item.ruleName}, #{item.indicatorCode},
                #{item.resultType}, #{item.riskLevel}, #{item.bankStatementId}, #{item.objectType}, #{item.objectKey}, #{item.groupId},
                #{item.logId}, #{item.reasonDetail}, #{item.businessCaliberSnapshot}, #{item.hitValueSnapshot},
                #{item.createBy}, #{item.createTime}, #{item.updateBy}, #{item.updateTime}, #{item.remark}
            )
        </foreach>
        on duplicate key update
            reason_detail = values(reason_detail),
            business_caliber_snapshot = values(business_caliber_snapshot),
            hit_value_snapshot = values(hit_value_snapshot),
            update_by = values(update_by),
            update_time = values(update_time),
            remark = values(remark)
    </insert>

</mapper>
