<?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.ruoyi.system.mapper.SiteInfoMapper">

    <resultMap type="com.ruoyi.system.domain.SiteInfo" id="SiteInfoMap">
        <result property="siteId" column="site_id" jdbcType="INTEGER"/>
        <result property="id" column="id" jdbcType="VARCHAR"/>
        <result property="siteName" column="site_name" jdbcType="VARCHAR"/>
        <result property="siteType" column="site_type" jdbcType="INTEGER"/>
        <result property="lon" column="lon" jdbcType="VARCHAR"/>
        <result property="lat" column="lat" jdbcType="VARCHAR"/>
        <result property="siteTime" column="site_time" jdbcType="VARCHAR"/>
        <result property="adminRegion" column="admin_region" jdbcType="VARCHAR"/>
        <result property="manageUnit" column="manage_unit" jdbcType="VARCHAR"/>
        <result property="affiliatedUnit" column="affiliated_unit" jdbcType="VARCHAR"/>
        <result property="contactName" column="contact_name" jdbcType="VARCHAR"/>
        <result property="contactPhone" column="contact_phone" jdbcType="VARCHAR"/>
        <result property="creatTime" column="creat_time" jdbcType="TIMESTAMP"/>
        <result property="isDel" column="is_del" jdbcType="INTEGER"/>
        <result property="deviceId" column="device_id" jdbcType="VARCHAR"/>
        <result property="videoUrl" column="video_url" jdbcType="VARCHAR"/>
        <result property="videoUser" column="video_user" jdbcType="VARCHAR"/>
        <result property="videoPwd" column="video_pwd" jdbcType="VARCHAR"/>
        <result property="videoPort" column="video_port" jdbcType="VARCHAR"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="SiteInfoMap">
        select
            site_id, id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port
        from site_info
        where site_id = #{siteId}
    </select>

    <!--查询单个-->
    <select id="queryBySiteCode" resultMap="SiteInfoMap">
        select
            site_id, id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port
        from site_info
        where id = #{siteCode} and is_del = 0
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="SiteInfoMap">
        select
            site_id, id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port
        from site_info
        <where>
            <if test="siteInfoQuery.siteId != null">
                and site_id = #{siteInfoQuery.siteId}
            </if>
            <if test="siteInfoQuery.id != null and siteInfoQuery.id != ''">
                and id = #{siteInfoQuery.id}
            </if>
            <if test="siteInfoQuery.siteName != null and siteInfoQuery.siteName != ''">
                and site_name LIKE concat('%',#{siteInfoQuery.siteName},'%')
            </if>
            <if test="siteInfoQuery.siteType != null">
                and site_type = #{siteInfoQuery.siteType}
            </if>
            <if test="siteInfoQuery.siteTime != null and siteInfoQuery.siteTime != ''">
                and site_time = #{siteInfoQuery.siteTime}
            </if>
            and is_del = 0
        </where>
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from site_info
        <where>
            <if test="siteId != null">
                and site_id = #{siteId}
            </if>
            <if test="id != null and id != ''">
                and id = #{id}
            </if>
            <if test="siteName != null and siteName != ''">
                and site_name = #{siteName}
            </if>
            <if test="siteType != null">
                and site_type = #{siteType}
            </if>
            <if test="lon != null and lon != ''">
                and lon = #{lon}
            </if>
            <if test="lat != null and lat != ''">
                and lat = #{lat}
            </if>
            <if test="siteTime != null and siteTime != ''">
                and site_time = #{siteTime}
            </if>
            <if test="adminRegion != null and adminRegion != ''">
                and admin_region = #{adminRegion}
            </if>
            <if test="manageUnit != null and manageUnit != ''">
                and manage_unit = #{manageUnit}
            </if>
            <if test="affiliatedUnit != null and affiliatedUnit != ''">
                and affiliated_unit = #{affiliatedUnit}
            </if>
            <if test="contactName != null and contactName != ''">
                and contact_name = #{contactName}
            </if>
            <if test="contactPhone != null and contactPhone != ''">
                and contact_phone = #{contactPhone}
            </if>
            <if test="creatTime != null">
                and creat_time = #{creatTime}
            </if>
            <if test="isDel != null">
                and is_del = #{isDel}
            </if>
            <if test="deviceId != null and deviceId != ''">
                and device_id = #{deviceId}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="siteId" useGeneratedKeys="true">
        insert into site_info(id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port)
        values (#{id}, #{siteName}, #{siteType}, #{lon}, #{lat}, #{siteTime}, #{adminRegion}, #{manageUnit}, #{affiliatedUnit}, #{contactName}, #{contactPhone}, #{creatTime}, #{isDel}, #{deviceId}, #{videoUrl}, #{videoUser}, #{videoPwd}, #{videoPort})
    </insert>

    <insert id="insertBatch" keyProperty="siteId" useGeneratedKeys="true">
        insert into site_info(id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.id}, #{entity.siteName}, #{entity.siteType}, #{entity.lon}, #{entity.lat}, #{entity.siteTime}, #{entity.adminRegion}, #{entity.manageUnit}, #{entity.affiliatedUnit}, #{entity.contactName}, #{entity.contactPhone}, #{entity.creatTime}, #{entity.isDel}, #{entity.deviceId}, #{entity.videoUrl}, #{entity.videoUser}, #{entity.videoPwd}, #{entity.videoPort})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="siteId" useGeneratedKeys="true">
        insert into site_info(id, site_name, site_type, lon, lat, site_time, admin_region, manage_unit, affiliated_unit, contact_name, contact_phone, creat_time, is_del, device_id, video_url, video_user, video_pwd, video_port)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.id}, #{entity.siteName}, #{entity.siteType}, #{entity.lon}, #{entity.lat}, #{entity.siteTime}, #{entity.adminRegion}, #{entity.manageUnit}, #{entity.affiliatedUnit}, #{entity.contactName}, #{entity.contactPhone}, #{entity.creatTime}, #{entity.isDel}, #{entity.deviceId}, #{entity.videoUrl}, #{entity.videoUser}, #{entity.videoPwd}, #{entity.videoPort})
        </foreach>
        on duplicate key update
id = values(id),
site_name = values(site_name),
site_type = values(site_type),
lon = values(lon),
lat = values(lat),
site_time = values(site_time),
admin_region = values(admin_region),
manage_unit = values(manage_unit),
affiliated_unit = values(affiliated_unit),
contact_name = values(contact_name),
contact_phone = values(contact_phone),
creat_time = values(creat_time),
is_del = values(is_del),
device_id = values(device_id),
video_url = values(video_url),
video_user = values(video_user),
video_pwd = values(video_pwd),
video_port = values(video_port)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update site_info
        <set>
            <if test="id != null and id != ''">
                id = #{id},
            </if>
            <if test="siteName != null and siteName != ''">
                site_name = #{siteName},
            </if>
            <if test="siteType != null">
                site_type = #{siteType},
            </if>
            <if test="lon != null and lon != ''">
                lon = #{lon},
            </if>
            <if test="lat != null and lat != ''">
                lat = #{lat},
            </if>
            <if test="siteTime != null and siteTime != ''">
                site_time = #{siteTime},
            </if>
            <if test="adminRegion != null and adminRegion != ''">
                admin_region = #{adminRegion},
            </if>
            <if test="manageUnit != null and manageUnit != ''">
                manage_unit = #{manageUnit},
            </if>
            <if test="affiliatedUnit != null and affiliatedUnit != ''">
                affiliated_unit = #{affiliatedUnit},
            </if>
            <if test="contactName != null and contactName != ''">
                contact_name = #{contactName},
            </if>
            <if test="contactPhone != null and contactPhone != ''">
                contact_phone = #{contactPhone},
            </if>
            <if test="creatTime != null">
                creat_time = #{creatTime},
            </if>
            <if test="isDel != null">
                is_del = #{isDel},
            </if>
            <if test="deviceId != null and deviceId != ''">
                device_id = #{deviceId},
            </if>
            <if test="videoUrl != null and videoUrl != ''">
                video_url = #{videoUrl},
            </if>
            <if test="videoUser != null and videoUser != ''">
                video_user = #{videoUser},
            </if>
            <if test="videoPwd != null and videoPwd != ''">
                video_pwd = #{videoPwd},
            </if>
            <if test="videoPort != null and videoPort != ''">
                video_port = #{videoPort},
            </if>
        </set>
        where site_id = #{siteId}
    </update>

    <!--通过主键删除-->
    <update id="deleteById">
        update site_info set is_del = 1 where site_id = #{siteId}
    </update>

</mapper>

