<?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.CcdiBankTagTaskMapper">

    <resultMap id="CcdiBankTagTaskResultMap" type="com.ruoyi.ccdi.project.domain.entity.CcdiBankTagTask">
        <id property="id" column="id"/>
        <result property="projectId" column="project_id"/>
        <result property="triggerType" column="trigger_type"/>
        <result property="modelCode" column="model_code"/>
        <result property="status" column="status"/>
        <result property="needRerun" column="need_rerun"/>
        <result property="successRuleCount" column="success_rule_count"/>
        <result property="failedRuleCount" column="failed_rule_count"/>
        <result property="hitCount" column="hit_count"/>
        <result property="errorMessage" column="error_message"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <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>

    <insert id="insertTask" parameterType="com.ruoyi.ccdi.project.domain.entity.CcdiBankTagTask" useGeneratedKeys="true" keyProperty="id">
        insert into ccdi_bank_tag_task (
            project_id, trigger_type, model_code, status, need_rerun, success_rule_count,
            failed_rule_count, hit_count, error_message, start_time, end_time,
            create_by, create_time, update_by, update_time
        ) values (
            #{projectId}, #{triggerType}, #{modelCode}, #{status}, #{needRerun}, #{successRuleCount},
            #{failedRuleCount}, #{hitCount}, #{errorMessage}, #{startTime}, #{endTime},
            #{createBy}, #{createTime}, #{updateBy}, #{updateTime}
        )
    </insert>

    <update id="updateTask" parameterType="com.ruoyi.ccdi.project.domain.entity.CcdiBankTagTask">
        update ccdi_bank_tag_task
        <set>
            <if test="triggerType != null">trigger_type = #{triggerType},</if>
            <if test="modelCode != null">model_code = #{modelCode},</if>
            <if test="status != null">status = #{status},</if>
            <if test="needRerun != null">need_rerun = #{needRerun},</if>
            <if test="successRuleCount != null">success_rule_count = #{successRuleCount},</if>
            <if test="failedRuleCount != null">failed_rule_count = #{failedRuleCount},</if>
            <if test="hitCount != null">hit_count = #{hitCount},</if>
            <if test="errorMessage != null">error_message = #{errorMessage},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </set>
        where id = #{id}
    </update>

    <select id="selectRunningTaskByProjectId" resultMap="CcdiBankTagTaskResultMap">
        select id, project_id, trigger_type, model_code, status, need_rerun, success_rule_count,
               failed_rule_count, hit_count, error_message, start_time, end_time,
               create_by, create_time, update_by, update_time
        from ccdi_bank_tag_task
        where project_id = #{projectId}
          and status = 'RUNNING'
        order by id desc
        limit 1
    </select>

</mapper>
