<?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.inspect.taskftp.mapper.PatrolTaskFtpMapper">

    <resultMap type="PatrolTaskFtp" id="PatrolTaskFtpResult">
        <result property="lineId" column="line_id"/>
        <result property="ftpIp" column="ftp_ip"/>
        <result property="ftpPort" column="ftp_port"/>
        <result property="ftpUserName" column="ftp_user_name"/>
        <result property="ftpPwd" column="ftp_pwd"/>
        <result property="ftpPath" column="ftp_path"/>
        <result property="ftpType" column="ftp_type"/>
    </resultMap>

    <sql id="selectPatrolTaskFtpVo">
        select line_id, ftp_ip, ftp_port, ftp_user_name, ftp_pwd, ftp_path, ftp_type
        from patrol_task_ftp
    </sql>

    <select id="selectPatrolTaskFtpList" parameterType="PatrolTaskFtp" resultMap="PatrolTaskFtpResult">
        <include refid="selectPatrolTaskFtpVo"/>
        <where>
            <if test="ftpIp != null  and ftpIp != ''">and ftp_ip = #{ftpIp}</if>
            <if test="ftpPort != null  and ftpPort != ''">and ftp_port = #{ftpPort}</if>
            <if test="ftpUserName != null  and ftpUserName != ''">and ftp_user_name like concat('%', #{ftpUserName},
                '%')
            </if>
            <if test="ftpPwd != null  and ftpPwd != ''">and ftp_pwd = #{ftpPwd}</if>
            <if test="ftpPath != null  and ftpPath != ''">and ftp_path = #{ftpPath}</if>
            <if test="ftpType != null  and ftpType != ''">and ftp_type = #{ftpType}</if>
        </where>
    </select>

    <select id="selectPatrolTaskFtpByLineId" parameterType="Long" resultMap="PatrolTaskFtpResult">
        <include refid="selectPatrolTaskFtpVo"/>
        where line_id = #{lineId}
    </select>

    <insert id="insertPatrolTaskFtp" parameterType="PatrolTaskFtp" useGeneratedKeys="true" keyProperty="lineId">
        insert into patrol_task_ftp
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="ftpIp != null">ftp_ip,</if>
            <if test="ftpPort != null">ftp_port,</if>
            <if test="ftpUserName != null">ftp_user_name,</if>
            <if test="ftpPwd != null">ftp_pwd,</if>
            <if test="ftpPath != null">ftp_path,</if>
            <if test="ftpType != null">ftp_type,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="ftpIp != null">#{ftpIp},</if>
            <if test="ftpPort != null">#{ftpPort},</if>
            <if test="ftpUserName != null">#{ftpUserName},</if>
            <if test="ftpPwd != null">#{ftpPwd},</if>
            <if test="ftpPath != null">#{ftpPath},</if>
            <if test="ftpType != null">#{ftpType},</if>
        </trim>
    </insert>

    <update id="updatePatrolTaskFtp" parameterType="PatrolTaskFtp">
        update patrol_task_ftp
        <trim prefix="SET" suffixOverrides=",">
            <if test="ftpIp != null">ftp_ip = #{ftpIp},</if>
            <if test="ftpPort != null">ftp_port = #{ftpPort},</if>
            <if test="ftpUserName != null">ftp_user_name = #{ftpUserName},</if>
            <if test="ftpPwd != null">ftp_pwd = #{ftpPwd},</if>
            <if test="ftpPath != null">ftp_path = #{ftpPath},</if>
            <if test="ftpType != null">ftp_type = #{ftpType},</if>
        </trim>
        where line_id = #{lineId}
    </update>

    <delete id="deletePatrolTaskFtpByLineId" parameterType="Long">
        delete
        from patrol_task_ftp
        where line_id = #{lineId}
    </delete>

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