<?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="cn.cecep.talroad.mapper.MAmVideoDevFiMapper">

    <resultMap type="cn.cecep.talroad.domain.MAmVideoDevFi" id="MAmVideoDevFiResult">
        <result property="id" column="id"/>
        <result property="devId" column="dev_id"/>
        <result property="devName" column="dev_name"/>
        <result property="devInsideCode" column="dev_inside_code"/>
        <result property="devCode" column="dev_code"/>
        <result property="model" column="model"/>
        <result property="modelRoad" column="model_road"/>
        <result property="location" column="location"/>
        <result property="lonMap" column="lon_map"/>
        <result property="latMap" column="lat_map"/>
        <result property="descrAny" column="descr_any"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="factoryId" column="factory_id"/>
        <result property="outletId" column="outlet_id"/>
        <result property="devType" column="dev_type"/>
        <result property="devSource" column="dev_source"/>
        <result property="channelId" column="channel_id"/>
    </resultMap>


    <sql id="selectMAmVideoDevFiVo">
        select id,
               dev_id,
               dev_name,
               dev_inside_code,
               dev_code,
               model,
               model_road,
               location,
               lon_map,
               lat_map,
               descr_any,
               create_time,
               update_time,
               factory_id,
               outlet_id,
               dev_type,
               dev_source,
               channel_id
        from m_am_video_dev_fi
    </sql>

    <select id="selectMAmVideoDevFiList" parameterType="cn.cecep.talroad.domain.MAmVideoDevFi"
            resultMap="MAmVideoDevFiResult">
        <include refid="selectMAmVideoDevFiVo"/>
        <where>
            <if test="devId != null  and devId != ''">and dev_id = #{devId}</if>
            <if test="devName != null  and devName != ''">and dev_name like concat('%', #{devName}, '%')</if>
            <if test="devInsideCode != null  and devInsideCode != ''">and dev_inside_code = #{devInsideCode}</if>
            <if test="devCode != null  and devCode != ''">and dev_code = #{devCode}</if>
            <if test="model != null  and model != ''">and model = #{model}</if>
            <if test="modelRoad != null  and modelRoad != ''">and model_road = #{modelRoad}</if>
            <if test="location != null  and location != ''">and location = #{location}</if>
            <if test="lonMap != null  and lonMap != ''">and lon_map = #{lonMap}</if>
            <if test="latMap != null  and latMap != ''">and lat_map = #{latMap}</if>
            <if test="descrAny != null  and descrAny != ''">and descr_any = #{descrAny}</if>
            <if test="factoryId != null  and factoryId != ''">and factory_id = #{factoryId}</if>
            <if test="outletId != null  and outletId != ''">and outlet_id = #{outletId}</if>
            <if test="devType != null  and devType != ''">and dev_type = #{devType}</if>
            <if test="devSource != null  and devSource != ''">and dev_source = #{devSource}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
        </where>
        ORDER BY id
    </select>

    <select id="selectListDel" resultMap="MAmVideoDevFiResult">
        SELECT channel_id as dev_id
        FROM m_am_video_dev_fi
        GROUP BY channel_id
        HAVING count(channel_id) > 1
    </select>

    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO m_am_video_dev_fi
        (
        id, dev_id, dev_name, dev_inside_code, dev_code, model, model_road, location, lon_map, lat_map,
        descr_any, create_time, update_time, factory_id, outlet_id, dev_type, dev_source, gbs_device_id,
        channel_id, status, station_building_mn, device_id
        )
        VALUES
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.id},
            <if test="item.devId != null and item.devId != ''">#{item.devId}</if>
            <if test="item.devId == null or item.devId == ''">null</if>,
            <if test="item.devName != null and item.devName != ''">#{item.devName}</if>
            <if test="item.devName == null or item.devName == ''">null</if>,
            <if test="item.devInsideCode != null and item.devInsideCode != ''">#{item.devInsideCode}</if>
            <if test="item.devInsideCode == null or item.devInsideCode == ''">null</if>,
            <if test="item.devCode != null and item.devCode != ''">#{item.devCode}</if>
            <if test="item.devCode == null or item.devCode == ''">null</if>,
            <if test="item.model != null and item.model != ''">#{item.model}</if>
            <if test="item.model == null or item.model == ''">null</if>,
            <if test="item.modelRoad != null and item.modelRoad != ''">#{item.modelRoad}</if>
            <if test="item.modelRoad == null or item.modelRoad == ''">null</if>,
            <if test="item.location != null and item.location != ''">#{item.location}</if>
            <if test="item.location == null or item.location == ''">null</if>,
            <if test="item.lonMap != null">#{item.lonMap}</if>
            <if test="item.lonMap == null">null</if>,
            <if test="item.latMap != null">#{item.latMap}</if>
            <if test="item.latMap == null">null</if>,
            <if test="item.descrAny != null and item.descrAny != ''">#{item.descrAny}</if>
            <if test="item.descrAny == null or item.descrAny == ''">null</if>,
            <if test="item.createTime != null">#{item.createTime}</if>
            <if test="item.createTime == null">null</if>,
            <if test="item.updateTime != null">#{item.updateTime}</if>
            <if test="item.updateTime == null">null</if>,
            <if test="item.factoryId != null and item.factoryId != ''">#{item.factoryId}</if>
            <if test="item.factoryId == null or item.factoryId == ''">null</if>,
            <if test="item.outletId != null and item.outletId != ''">#{item.outletId}</if>
            <if test="item.outletId == null or item.outletId == ''">null</if>,
            <if test="item.devType != null and item.devType != ''">#{item.devType}</if>
            <if test="item.devType == null or item.devType == ''">null</if>,
            <if test="item.devSource != null and item.devSource != ''">#{item.devSource}</if>
            <if test="item.devSource == null or item.devSource == ''">null</if>,
            <if test="item.gbsDeviceId != null and item.gbsDeviceId != ''">#{item.gbsDeviceId}</if>
            <if test="item.gbsDeviceId == null or item.gbsDeviceId == ''">null</if>,
            <if test="item.channelId != null and item.channelId != ''">#{item.channelId}</if>
            <if test="item.channelId == null or item.channelId == ''">null</if>,
            <if test="item.status != null and item.status != ''">#{item.status}</if>
            <if test="item.status == null or item.status == ''">null</if>,
            <if test="item.stationBuildingMn != null and item.stationBuildingMn != ''">#{item.stationBuildingMn}</if>
            <if test="item.stationBuildingMn == null or item.stationBuildingMn == ''">null</if>,
            <if test="item.deviceId != null and item.deviceId != ''">#{item.deviceId}</if>
            <if test="item.deviceId == null or item.deviceId == ''">null</if>
            )
        </foreach>
    </insert>


    <update id="updateBatchCoordinate" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" separator=";">
            UPDATE m_am_video_dev_fi
            <set>
                <if test="item.lonMap != null and item.lonMap != ''">lon_map=#{item.lonMap},</if>
                <if test="item.lonMap == null or item.lonMap == ''">lon_map = null,</if>
                <if test="item.latMap != null  and item.latMap != ''">lat_map=#{item.latMap},</if>
                <if test="item.latMap == null or item.latMap == ''">lat_map = null,</if>
            </set>
            WHERE id=#{item.id}
        </foreach>
    </update>

</mapper>
