<?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.dms.mapper.DmsBaseMaintStationMapper">

    <resultMap type="DmsBaseMaintStation" id="DmsBaseMaintStationResult">
        <result property="maintStationId"    column="maint_station_id"    />
        <result property="deviceTypeId"    column="device_type_id"    />
        <result property="maintStationCode"    column="maint_station_code"    />
        <result property="protocolCode"    column="protocol_code"    />
        <result property="isFlag"    column="is_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="selectDmsBaseMaintStationVo">
        select maint_station_id, device_type_id, maint_station_code, protocol_code, is_flag, remark, create_by, create_time, update_by, update_time from dms_base_maint_station
    </sql>

    <select id="selectDmsBaseMaintStationList" parameterType="DmsBaseMaintStation" resultMap="DmsBaseMaintStationResult">
        select a.maint_station_id, a.device_type_id, a.maint_station_code, a.protocol_code, a.is_flag, a.remark, a.create_by, a.create_time, a.update_by, a.update_time
        from dms_base_maint_station a
        left join dms_base_device_type b on a.device_type_id = b.device_type_id
        <where>
            <if test="deviceTypeId != null "> and a.device_type_id = #{deviceTypeId}</if>
            <if test="maintStationCode != null  and maintStationCode != ''"> and a.maint_station_code = #{maintStationCode}</if>
            <if test="protocolCode != null  and protocolCode != ''"> and a.protocol_code = #{protocolCode}</if>
            <if test="isFlag != null "> and a.is_flag = #{isFlag}</if>
            <if test="TypeName != null "> and b.type_name like concat('%', #{TypeName},'%')</if>
        </where>
    </select>

    <select id="selectDmsBaseMaintStationByMaintStationId" parameterType="Long" resultMap="DmsBaseMaintStationResult">
        <include refid="selectDmsBaseMaintStationVo"/>
        where maint_station_id = #{maintStationId}
    </select>

    <insert id="insertDmsBaseMaintStation" parameterType="DmsBaseMaintStation" useGeneratedKeys="true" keyProperty="maintStationId">
        insert into dms_base_maint_station
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceTypeId != null">device_type_id,</if>
            <if test="maintStationCode != null">maint_station_code,</if>
            <if test="protocolCode != null">protocol_code,</if>
            <if test="isFlag != null">is_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="deviceTypeId != null">#{deviceTypeId},</if>
            <if test="maintStationCode != null">#{maintStationCode},</if>
            <if test="protocolCode != null">#{protocolCode},</if>
            <if test="isFlag != null">#{isFlag},</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="updateDmsBaseMaintStation" parameterType="DmsBaseMaintStation">
        update dms_base_maint_station
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceTypeId != null">device_type_id = #{deviceTypeId},</if>
            <if test="maintStationCode != null">maint_station_code = #{maintStationCode},</if>
            <if test="protocolCode != null">protocol_code = #{protocolCode},</if>
            <if test="isFlag != null">is_flag = #{isFlag},</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 maint_station_id = #{maintStationId}
    </update>

    <delete id="deleteDmsBaseMaintStationByMaintStationId" parameterType="Long">
        delete from dms_base_maint_station where maint_station_id = #{maintStationId}
    </delete>

    <delete id="deleteDmsBaseMaintStationByMaintStationIds" parameterType="String">
        delete from dms_base_maint_station where maint_station_id in
        <foreach item="maintStationId" collection="array" open="(" separator="," close=")">
            #{maintStationId}
        </foreach>
    </delete>
</mapper>
