<?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="cn.edu.whu.boot.collection.mapper.TaskSelectIdMapper">

    <resultMap id="taskSelectIdResultMap" type="cn.edu.whu.boot.collection.domain.TaskSelectId">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="src_task_id" property="srcTaskId" jdbcType="INTEGER"/>
        <result column="src_table_name" property="srcTableName" jdbcType="VARCHAR"/>
        <result column="select_order" property="selectOrder" jdbcType="SMALLINT"/>
        <result column="select_id" property="selectId" jdbcType="VARCHAR"/>
        <result column="dest_task_id" property="destTaskId" jdbcType="INTEGER"/>
        <result column="dest_table_name" property="destTableName" jdbcType="VARCHAR"/>
    </resultMap>

    <insert id="insert" parameterType="cn.edu.whu.boot.collection.domain.TaskSelectId">
        INSERT INTO task_select_id(src_task_id,src_table_name,dest_task_id,dest_table_name,select_order,select_id)
        VALUES (#{srcTaskId},#{srcTableName},#{destTaskId},#{destTableName},#{selectOrder},#{selectId})
    </insert>

    <delete id="delete" parameterType="java.lang.Integer">
        DELETE FROM task_select_id WHERE src_task_id = #{taskId} or dest_task_id = #{taskId}
    </delete>

    <select id="getTaskSelectIdByTaskIdAndTableName" resultMap="taskSelectIdResultMap">
        SELECT * FROM task_select_id
        WHERE src_task_id = #{srcTaskId} and src_table_name = #{srcTableName}
        and dest_task_id = #{destTaskId} and dest_table_name = #{destTableName}
    </select>

    <select id="getMaxSelectOrder" resultType="java.lang.Integer">
        SELECT MAX(select_order) FROM task_select_id
        WHERE src_task_id = #{srcTaskId} and src_table_name = #{srcTableName}
        and dest_task_id = #{destTaskId} and dest_table_name = #{destTableName}
    </select>

</mapper>