<?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.ho.business.mapper.StationRemoteControlMapper">


    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.ho.business.entity.StationRemoteControl"
            useGeneratedKeys="true">
        insert into station_remote_control
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="entity.id != null">id,</if>
            <if test="entity.stationId != null">station_id,</if>
            <if test="entity.ip != null">ip,</if>
            <if test="entity.port != null">port,</if>
            <if test="entity.userName != null">user_name,</if>
            <if test="entity.password != null">password,</if>
            <if test="entity.intranetIp != null">intranet_ip,</if>
            <if test="entity.type != null">type,</if>
            <if test="entity.createTime != null">create_time,</if>
            <if test="entity.updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="entity.id != null">#{entity.id,jdbcType=INTEGER},</if>
            <if test="entity.stationId != null">#{entity.stationId,jdbcType=INTEGER},</if>
            <if test="entity.ip != null">#{entity.ip,jdbcType=VARCHAR},</if>
            <if test="entity.port != null">#{entity.port,jdbcType=VARCHAR},</if>
            <if test="entity.userName != null">#{entity.userName,jdbcType=VARCHAR},</if>
            <if test="entity.password != null">#{entity.password,jdbcType=VARCHAR},</if>
            <if test="entity.intranetIp != null">#{entity.intranetIp,jdbcType=VARCHAR},</if>
            <if test="entity.type != null">#{entity.type,jdbcType=VARCHAR},</if>
            <if test="entity.createTime != null">#{entity.createTime,jdbcType=TIMESTAMP},</if>
            <if test="entity.updateTime != null">#{entity.updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="update" parameterType="com.ho.business.entity.StationRemoteControl">
        update station_remote_control
        <set>
            <if test="entity.ip != null">
                ip = #{entity.ip,jdbcType=VARCHAR},
            </if>
            <if test="entity.port != null">
                port = #{entity.port,jdbcType=VARCHAR},
            </if>
            <if test="entity.userName != null">
                user_name = #{entity.userName,jdbcType=VARCHAR},
            </if>
            <if test="entity.password != null">
                password = #{entity.password,jdbcType=VARCHAR},
            </if>
            <if test="entity.intranetIp != null">
                intranet_ip = #{entity.intranetIp,jdbcType=VARCHAR},
            </if>
            <if test="entity.type != null">
                type = #{entity.type,jdbcType=VARCHAR},
            </if>
            <if test="entity.updateTime != null">
                update_time = #{entity.updateTime,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{entity.id,jdbcType=INTEGER}
    </update>
    <delete id="delete">
        delete from  station_remote_control where id = #{id,jdbcType=INTEGER}
    </delete>

    <select id="search" resultType="com.ho.business.entity.StationRemoteControl">
        select s.*,t.name stationName from station_remote_control s
        left join station t on s.station_id = t.id
       <where>
           <if test="stationId != null and stationId !=''">
               and s.station_id = #{stationId}
           </if>
       </where>
    </select>

    <select id="selectList" resultType="com.ho.business.entity.StationRemoteControl">
        select s.*,t.name stationName from station_remote_control s
        left join station t on s.station_id = t.id
       <where>
           <if test="vo.stationId != null and vo.stationId !=''">
               and s.station_id = #{vo.stationId}
           </if>
           <if test="vo.stationName != null and vo.stationName !=''">
               and t.name like concat('%',#{vo.stationName},'%')
           </if>
           <if test="vo.intranetIp != null and vo.intranetIp !=''">
               and s.intranet_ip like concat('%',#{vo.intranetIp},'%')
           </if>
           <if test="vo.ip != null and vo.ip !=''">
               and s.ip  like concat('%',#{vo.ip},'%')
           </if>
           <if test="vo.type != null and vo.type !=''">
               and s.type = #{vo.type}
           </if>
       </where>
        order by s.create_time desc
    </select>
</mapper>
