<?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.hw.mes.mapper.MesBaseStationInfoMapper">

    <resultMap type="MesBaseStationInfo" id="MesBaseStationInfoResult">
        <result property="stationId" column="station_id"/>
        <result property="stationCode" column="station_code"/>
        <result property="stationName" column="station_name"/>
        <result property="processId" column="process_id"/>
        <result property="processName" column="process_name"/>
        <result property="floor" column="floor"/>
        <result property="productionTime" column="production_time"/>
        <result property="activeFlag" column="active_flag"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectMesBaseStationInfoVo">
        select mbsi.station_id,
               mbsi.station_code,
               mbsi.station_name,
               mbsi.process_id,
               mbpi.process_name,
               mbsi.floor,
               mbsi.production_time,
               mbsi.active_flag,
               mbsi.remark,
               mbsi.create_by,
               mbsi.create_time,
               mbsi.update_by,
               mbsi.update_time
        from mes_base_station_info mbsi
                 left join mes_base_process_info mbpi on mbpi.process_id = mbsi.process_id
    </sql>

    <select id="selectMesBaseStationInfoList" parameterType="MesBaseStationInfo" resultMap="MesBaseStationInfoResult">
        <include refid="selectMesBaseStationInfoVo"/>
        <where>
            <if test="stationCode != null  and stationCode != ''">and station_code = #{stationCode}</if>
            <if test="stationName != null  and stationName != ''">and station_name like concat('%', #{stationName},
                '%')
            </if>
            <if test="processId != null ">and process_id = #{processId}</if>
            <if test="floor != null ">and floor = #{floor}</if>
            <if test="productionTime != null ">and production_time = #{productionTime}</if>
            <if test="activeFlag != null  and activeFlag != ''">and active_flag = #{activeFlag}</if>
            <if test="remark != null  and remark != ''">and remark = #{remark}</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>

    <select id="selectMesBaseStationInfoByStationId" parameterType="Long" resultMap="MesBaseStationInfoResult">
        <include refid="selectMesBaseStationInfoVo"/>
        where station_id = #{stationId}
    </select>

    <insert id="insertMesBaseStationInfo" parameterType="MesBaseStationInfo" useGeneratedKeys="true"
            keyProperty="stationId">
        insert into mes_base_station_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="stationCode != null">station_code,</if>
            <if test="stationName != null and stationName != ''">station_name,</if>
            <if test="processId != null">process_id,</if>
            <if test="floor != null">floor,</if>
            <if test="productionTime != null">production_time,</if>
            <if test="activeFlag != null and activeFlag != ''">active_flag,</if>
            <if test="remark != null">remark,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="stationCode != null">#{stationCode},</if>
            <if test="stationName != null and stationName != ''">#{stationName},</if>
            <if test="processId != null">#{processId},</if>
            <if test="floor != null">#{floor},</if>
            <if test="productionTime != null">#{productionTime},</if>
            <if test="activeFlag != null and activeFlag != ''">#{activeFlag},</if>
            <if test="remark != null">#{remark},</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>
        </trim>
    </insert>

    <update id="updateMesBaseStationInfo" parameterType="MesBaseStationInfo">
        update mes_base_station_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="stationCode != null">station_code = #{stationCode},</if>
            <if test="stationName != null and stationName != ''">station_name = #{stationName},</if>
            <if test="processId != null">process_id = #{processId},</if>
            <if test="floor != null">floor = #{floor},</if>
            <if test="productionTime != null">production_time = #{productionTime},</if>
            <if test="activeFlag != null and activeFlag != ''">active_flag = #{activeFlag},</if>
            <if test="remark != null">remark = #{remark},</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>
        </trim>
        where station_id = #{stationId}
    </update>

    <delete id="deleteMesBaseStationInfoByStationId" parameterType="Long">
        delete
        from mes_base_station_info
        where station_id = #{stationId}
    </delete>

    <delete id="deleteMesBaseStationInfoByStationIds" parameterType="String">
        delete from mes_base_station_info where station_id in
        <foreach item="stationId" collection="array" open="(" separator="," close=")">
            #{stationId}
        </foreach>
    </delete>
</mapper>