<?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.younike.system.mapper.TaskLogMapper">
    
    <resultMap type="TaskLog" id="TaskLogResult">
        <result property="id"    column="id"    />
        <result property="taskName"    column="task_name"    />
        <result property="taskParam"    column="task_param"    />
        <result property="taskInfo"    column="task_info"    />
        <result property="taskResult"    column="task_result"    />
        <result property="errorLog"    column="error_log"    />
        <result property="executionTime"    column="execution_time"    />
        <result property="column1"    column="column1"    />
        <result property="column2"    column="column2"    />
        <result property="column3"    column="column3"    />
    </resultMap>

    <sql id="selectTaskLogVo">
        select id, task_name, task_param, task_info, task_result, error_log, execution_time, column1, column2, column3 from task_log
    </sql>

    <select id="selectTaskLogList" parameterType="TaskLog" resultMap="TaskLogResult">
        <include refid="selectTaskLogVo"/>
        <where>  
            <if test="taskName != null  and taskName != ''"> and task_name like concat('%', #{taskName}, '%')</if>
            <if test="taskParam != null  and taskParam != ''"> and task_param = #{taskParam}</if>
            <if test="taskInfo != null  and taskInfo != ''"> and task_info = #{taskInfo}</if>
            <if test="taskResult != null "> and task_result = #{taskResult}</if>
            <if test="errorLog != null  and errorLog != ''"> and error_log = #{errorLog}</if>
            <if test="executionTime != null "> and execution_time = #{executionTime}</if>
            <if test="column1 != null  and column1 != ''"> and column1 = #{column1}</if>
            <if test="column2 != null  and column2 != ''"> and column2 = #{column2}</if>
            <if test="column3 != null  and column3 != ''"> and column3 = #{column3}</if>
        </where>
    </select>
    
    <select id="selectTaskLogById" parameterType="Long" resultMap="TaskLogResult">
        <include refid="selectTaskLogVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTaskLog" parameterType="TaskLog" useGeneratedKeys="true" keyProperty="id">
        insert into task_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="taskName != null">task_name,</if>
            <if test="taskParam != null">task_param,</if>
            <if test="taskInfo != null">task_info,</if>
            <if test="taskResult != null">task_result,</if>
            <if test="errorLog != null">error_log,</if>
            <if test="executionTime != null">execution_time,</if>
            <if test="column1 != null">column1,</if>
            <if test="column2 != null">column2,</if>
            <if test="column3 != null">column3,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="taskName != null">#{taskName},</if>
            <if test="taskParam != null">#{taskParam},</if>
            <if test="taskInfo != null">#{taskInfo},</if>
            <if test="taskResult != null">#{taskResult},</if>
            <if test="errorLog != null">#{errorLog},</if>
            <if test="executionTime != null">#{executionTime},</if>
            <if test="column1 != null">#{column1},</if>
            <if test="column2 != null">#{column2},</if>
            <if test="column3 != null">#{column3},</if>
         </trim>
    </insert>

    <update id="updateTaskLog" parameterType="TaskLog">
        update task_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="taskName != null">task_name = #{taskName},</if>
            <if test="taskParam != null">task_param = #{taskParam},</if>
            <if test="taskInfo != null">task_info = #{taskInfo},</if>
            <if test="taskResult != null">task_result = #{taskResult},</if>
            <if test="errorLog != null">error_log = #{errorLog},</if>
            <if test="executionTime != null">execution_time = #{executionTime},</if>
            <if test="column1 != null">column1 = #{column1},</if>
            <if test="column2 != null">column2 = #{column2},</if>
            <if test="column3 != null">column3 = #{column3},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTaskLogById" parameterType="Long">
        delete from task_log where id = #{id}
    </delete>

    <delete id="deleteTaskLogByIds" parameterType="String">
        delete from task_log where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>