<?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.pdaaphm.biz.mapper.AlgorithmIoFieldMapper">

    <resultMap type="AlgorithmIoField" id="AlgorithmIoFieldResult">
        <result property="id"    column="id"    />
        <result property="algorithmSubId"    column="algorithm_sub_id"    />
        <result property="type"    column="type"    />
        <result property="name"    column="name"    />
        <result property="index"    column="index"    />
        <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"    />
        <result property="algoSubName" column="sub_name"    />
    </resultMap>

    <sql id="selectAlgorithmIoFieldVo">
        select io.id, io.algorithm_sub_id, io.`type`, io.`name`, io.`index`, io.create_by, io.create_time, io.update_by, io.update_time, io.remark, sub.name as sub_name from t_algorithm_io_field as io left join t_algorithm_sub_type as sub on io.algorithm_sub_id = sub.id
    </sql>

    <select id="selectAlgorithmIoFieldList" parameterType="AlgorithmIoField" resultMap="AlgorithmIoFieldResult">
        <include refid="selectAlgorithmIoFieldVo"/>
        <where>
            <if test="algorithmSubId != null "> and algorithm_sub_id = #{algorithmSubId}</if>
            <if test="type != null  and type != ''"> and `type` = #{type}</if>
            <if test="name != null  and name != ''"> and `name` like concat('%', #{name}, '%')</if>
            <if test="index != null "> and `index` = #{index}</if>
        </where>
    </select>

    <select id="selectAlgorithmIoFieldById" parameterType="Long" resultMap="AlgorithmIoFieldResult">
        <include refid="selectAlgorithmIoFieldVo"/>
        where io.id = #{id}
    </select>

    <insert id="insertAlgorithmIoField" parameterType="AlgorithmIoField" useGeneratedKeys="true" keyProperty="id">
        insert into t_algorithm_io_field
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="algorithmSubId != null">algorithm_sub_id,</if>
            <if test="type != null">`type`,</if>
            <if test="name != null">`name`,</if>
            <if test="index != null">`index`,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="algorithmSubId != null">#{algorithmSubId},</if>
            <if test="type != null">#{type},</if>
            <if test="name != null">#{name},</if>
            <if test="index != null">#{index},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateAlgorithmIoField" parameterType="AlgorithmIoField">
        update t_algorithm_io_field
        <trim prefix="SET" suffixOverrides=",">
            <if test="algorithmSubId != null">algorithm_sub_id = #{algorithmSubId},</if>
            <if test="type != null">`type` = #{type},</if>
            <if test="name != null">`name` = #{name},</if>
            <if test="index != null">`index` = #{index},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAlgorithmIoFieldById" parameterType="Long">
        delete from t_algorithm_io_field where id = #{id}
    </delete>

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

    <select id="getIoSubList" resultType="Map">
        select id, `type`, `name` from t_algorithm_io_field where algorithm_sub_id = #{id}
    </select>
</mapper>
