<?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.zehong.system.mapper.TSiteStationInfoMapper">

    <resultMap type="TSiteStationInfo" id="TSiteStationInfoResult">
        <result property="siteStationId"    column="site_station_id"    />
        <result property="siteStationType"    column="site_station_type"    />
        <result property="siteStationName"    column="site_station_name"    />
        <result property="buildDate"    column="build_date"    />
        <result property="buildUnit"    column="build_unit"    />
        <result property="beyondEnterpriseId"    column="beyond_enterprise_id"    />
        <result property="beyondEnterpriseName"    column="beyond_enterprise_name"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="address"    column="address"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDel"    column="is_del"    />
        <result property="remarks"    column="remarks"    />
        <result property="pictureAddress"    column="picture_address"    />
    </resultMap>

    <sql id="selectTSiteStationInfoVo">
        select site_station_id,picture_address,(CASE site_station_type WHEN '1' THEN '加气站' WHEN '2' THEN '门站'WHEN '3' THEN '调压站' WHEN '4' THEN '储备站'WHEN '5' THEN '气化站'end ) as   site_station_type,
         site_station_name, build_date, build_unit, beyond_enterprise_id, beyond_enterprise_name, longitude, latitude,address,
          create_by, create_time, update_by, update_time, is_del, remarks from t_site_station_info
    </sql>

    <select id="selectTSiteStationInfoList" parameterType="TSiteStationInfo" resultMap="TSiteStationInfoResult">
        <include refid="selectTSiteStationInfoVo"/>
        <where>
             is_del='0'
            <if test="beyondEnterpriseId != null  and beyondEnterpriseId != -2">
             and beyond_enterprise_id = #{beyondEnterpriseId}
             </if>
            <if test="siteStationName != null  and siteStationName != ''"> and site_station_name like concat('%', #{siteStationName}, '%')</if>
            <if test="beyondEnterpriseName != null  and beyondEnterpriseName != ''"> and beyond_enterprise_name like concat('%', #{beyondEnterpriseName}, '%')</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
        order by site_station_id desc
    </select>

    <select id="selectTSiteStationInfoById" parameterType="Long" resultMap="TSiteStationInfoResult">
      select site_station_id,picture_address,site_station_type,address,
         site_station_name, build_date, build_unit, beyond_enterprise_id, beyond_enterprise_name, longitude, latitude,
          create_by, create_time, update_by, update_time, is_del, remarks from t_site_station_info
        where site_station_id = #{siteStationId} and is_del='0'
    </select>

    <select id="getSiteStationAlarmList" resultType="Map">
        select a2.site_station_id as siteStationId
        from t_relation_device_detail_info a1
        left join t_detector_info a2 on a1.iot_no = a2.detector_code
        right join t_site_station_info a3 on a1.relation_device_id = a3.site_station_id
        where a1.is_del = '0' and a2.is_del = '0' and a3.is_del = '0' and a2.detector_status = '2'
    </select>

    <insert id="insertTSiteStationInfo" parameterType="TSiteStationInfo" useGeneratedKeys="true" keyProperty="siteStationId">
        insert into t_site_station_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="siteStationType != null">site_station_type,</if>
            <if test="siteStationName != null">site_station_name,</if>
            <if test="buildDate != null">build_date,</if>
            <if test="buildUnit != null">build_unit,</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id,</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</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>
            <if test="isDel != null">is_del,</if>
            <if test="remarks != null">remarks,</if>
            <if test="pictureAddress != null">picture_address,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="siteStationType != null">#{siteStationType},</if>
            <if test="siteStationName != null">#{siteStationName},</if>
            <if test="buildDate != null">#{buildDate},</if>
            <if test="buildUnit != null">#{buildUnit},</if>
            <if test="beyondEnterpriseId != null">#{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">#{beyondEnterpriseName},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</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>
            <if test="isDel != null">#{isDel},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="pictureAddress != null">#{pictureAddress},</if>
         </trim>
    </insert>

    <update id="updateTSiteStationInfo" parameterType="TSiteStationInfo">
        update t_site_station_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="siteStationType != null">site_station_type = #{siteStationType},</if>
            <if test="siteStationName != null">site_station_name = #{siteStationName},</if>
            <if test="buildDate != null">build_date = #{buildDate},</if>
            <if test="buildUnit != null">build_unit = #{buildUnit},</if>
            <if test="beyondEnterpriseId != null">beyond_enterprise_id = #{beyondEnterpriseId},</if>
            <if test="beyondEnterpriseName != null">beyond_enterprise_name = #{beyondEnterpriseName},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</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>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="pictureAddress != null">picture_address = #{pictureAddress},</if>
        </trim>
        where site_station_id = #{siteStationId}
    </update>

    <update id="deleteTSiteStationInfoById" parameterType="Long">
        update t_site_station_info set is_del='1' where site_station_id = #{siteStationId}
    </update>

    <update id="deleteTSiteStationInfoByIds" parameterType="String">
        update   t_site_station_info set is_del='1' where site_station_id in
        <foreach item="siteStationId" collection="array" open="(" separator="," close=")">
            #{siteStationId}
        </foreach>
    </update>
</mapper>
