<?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.railway.business.safetool.mapper.SecScheduledToolMapper">

    <resultMap id="BaseResultMap" type="com.railway.business.safetool.domain.SecScheduledTool">
                <result column="id" property="id"/>
                <result column="scheduled_id" property="scheduledId"/>
                <result column="tool_id" property="toolId"/>
                <result column="del_flag" property="delFlag"/>
                <result column="create_by" property="createBy"/>
                <result column="create_time" property="createTime"/>
                <result column="update_by" property="updateBy"/>
                <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="Base_Column_List">
                id,
                scheduled_id,
                tool_id,
                del_flag,
                create_by,
                create_time,
                update_by,
                update_time
    </sql>



    <insert id="insert" parameterType="com.railway.business.safetool.domain.SecScheduledTool">
        <selectKey keyProperty="id" order="AFTER" resultType="Long">
            select @@IDENTITY as id
        </selectKey>
        INSERT INTO sec_scheduled_tool
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test ='null != scheduledId'>
                    scheduled_id,
                    </if>
                    <if test ='null != toolId'>
                    tool_id,
                    </if>
                    <if test ='null != delFlag'>
                    del_flag,
                    </if>
                    <if test ='null != createBy'>
                    create_by,
                    </if>
                    <if test ='null != createTime'>
                    create_time,
                    </if>
                    <if test ='null != updateBy'>
                    update_by,
                    </if>
                    <if test ='null != updateTime'>
                    update_time
                    </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test ='null != scheduledId'>
                    #{scheduledId},
                    </if>
                    <if test ='null != toolId'>
                    #{toolId},
                    </if>
                    <if test ='null != delFlag'>
                    #{delFlag},
                    </if>
                    <if test ='null != createBy'>
                    #{createBy},
                    </if>
                    <if test ='null != createTime'>
                    #{createTime},
                    </if>
                    <if test ='null != updateBy'>
                    #{updateBy},
                    </if>
                    <if test ='null != updateTime'>
                    #{updateTime}
                    </if>
        </trim>
    </insert>

    <delete id="delete" parameterType="com.railway.business.safetool.domain.vo.SecScheduledToolsAddVo">
     delete from sec_scheduled_tool  where scheduled_id = #{scheduledId}  and tool_id = #{toolId}
    </delete>


    <select id="checkdel" parameterType="com.railway.business.safetool.domain.vo.SecScheduledToolsAddVo"
            resultType="int">
        select count(1) c from sec_scheduled_tool	where   scheduled_id = #{scheduledId}
    </select>
    <select id="check" parameterType="com.railway.business.safetool.domain.SecScheduledTool"
    resultType="int">
        select count(1) c from sec_scheduled_tool	where   tool_id = #{toolId}
    </select>
    <update id="update" parameterType="com.railway.business.safetool.domain.SecScheduledTool">
        UPDATE sec_scheduled_tool
        <set>
                    <if test ='null != scheduledId'>scheduled_id = #{scheduledId},</if>
                    <if test ='null != toolId'>tool_id = #{toolId},</if>
                    <if test ='null != delFlag'>del_flag = #{delFlag},</if>
                    <if test ='null != createBy'>create_by = #{createBy},</if>
                    <if test ='null != createTime'>create_time = #{createTime},</if>
                    <if test ='null != updateBy'>update_by = #{updateBy},</if>
                    <if test ='null != updateTime'>update_time = #{updateTime}</if>
        </set>
        WHERE id = #{id}
    </update>


    <select id="getInfo" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sec_scheduled_tool
        WHERE del_flag='0' and id = #{id}

    </select>

    <select id="getList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM sec_scheduled_tool
        <where>
            del_flag='0'
                <if test="scheduledId!=null and scheduledId!=''">
                    and scheduled_id=#{scheduledId}
                </if>
                <if test="toolId!=null and toolId!=''">
                    and tool_id=#{toolId}
                </if>
                <if test="delFlag!=null and delFlag!=''">
                    and del_flag=#{delFlag}
                </if>
                <if test="createBy!=null and createBy!=''">
                    and create_by=#{createBy}
                </if>
                <if test="createTime!=null">
                    and create_time=#{createTime}
                </if>
                <if test="updateBy!=null and updateBy!=''">
                    and update_by=#{updateBy}
                </if>
                <if test="updateTime!=null">
                    and update_time=#{updateTime}
                </if>
        </where>
    </select>

</mapper>