<?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.fastbee.ggroup.mapper.GSiteMonitorInfoMapper">

    <resultMap type="GSiteMonitorInfo" id="GSiteInfoResult">
        <result property="id"    column="id"    />
        <result property="monitoringStation"    column="monitoring_station"    />
        <result property="pileNumber"    column="pile_number"    />
        <result property="projectName"    column="project_name"    />
        <result property="constructionYear"    column="construction_year"    />
        <result property="equipmentBrand"    column="equipment_brand"    />
        <result property="equipmentModel"    column="equipment_model"    />
        <result property="siteLocation"    column="site_location"    />
        <result property="siteCoordinates"    column="site_coordinates"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="protectionScope"    column="protection_scope"    />
        <result property="protectionScopeRemarks"    column="protection_scope_remarks"    />
        <result property="faultReport"    column="fault_report"    />
        <result property="manager"    column="manager"    />
        <result property="managerPhone"    column="manager_phone"    />
        <result property="pictures"    column="pictures"    />
        <result property="code"    column="code"    />
        <result property="remarks"    column="remarks"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="siteId"    column="site_id"    />
    </resultMap>

    <sql id="selectGSiteInfoVo">
        select id, monitoring_station, pile_number, project_name, construction_year, equipment_brand, equipment_model, site_location, site_coordinates, longitude, latitude, protection_scope, protection_scope_remarks, fault_report, manager, manager_phone, pictures, code, remarks, del_flag, create_time, create_by, update_time, update_by, site_id from g_site_monitor_info
    </sql>

    <select id="selectGSiteInfoList" parameterType="GSiteMonitorInfo" resultMap="GSiteInfoResult">
        <include refid="selectGSiteInfoVo"/>
        <where>
            <if test="monitoringStation != null  and monitoringStation != ''"> and monitoring_station = #{monitoringStation}</if>
            <if test="pileNumber != null  and pileNumber != ''"> and pile_number = #{pileNumber}</if>
            <if test="projectName != null  and projectName != ''"> and project_name like concat('%', #{projectName}, '%')</if>
            <if test="constructionYear != null  and constructionYear != ''"> and construction_year = #{constructionYear}</if>
            <if test="equipmentBrand != null  and equipmentBrand != ''"> and equipment_brand = #{equipmentBrand}</if>
            <if test="equipmentModel != null  and equipmentModel != ''"> and equipment_model = #{equipmentModel}</if>
            <if test="siteLocation != null  and siteLocation != ''"> and site_location = #{siteLocation}</if>
            <if test="siteCoordinates != null  and siteCoordinates != ''"> and site_coordinates = #{siteCoordinates}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
            <if test="protectionScope != null  and protectionScope != ''"> and protection_scope = #{protectionScope}</if>
            <if test="protectionScopeRemarks != null  and protectionScopeRemarks != ''"> and protection_scope_remarks = #{protectionScopeRemarks}</if>
            <if test="faultReport != null  and faultReport != ''"> and fault_report = #{faultReport}</if>
            <if test="manager != null  and manager != ''"> and manager = #{manager}</if>
            <if test="managerPhone != null  and managerPhone != ''"> and manager_phone = #{managerPhone}</if>
            <if test="pictures != null  and pictures != ''"> and pictures = #{pictures}</if>
            <if test="code != null  and code != ''"> and code = #{code}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="siteId != null "> and site_id = #{siteId}</if>
        </where>
    </select>

    <select id="selectGSiteInfoBySiteId" parameterType="Long" resultMap="GSiteInfoResult">
        <include refid="selectGSiteInfoVo"/>
        where site_id = #{siteId}
    </select>

    <insert id="insertGSiteInfo" parameterType="GSiteMonitorInfo" useGeneratedKeys="true" keyProperty="id">
        insert into g_site_monitor_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="monitoringStation != null and monitoringStation != ''">monitoring_station,</if>
            <if test="pileNumber != null">pile_number,</if>
            <if test="projectName != null">project_name,</if>
            <if test="constructionYear != null">construction_year,</if>
            <if test="equipmentBrand != null">equipment_brand,</if>
            <if test="equipmentModel != null">equipment_model,</if>
            <if test="siteLocation != null">site_location,</if>
            <if test="siteCoordinates != null">site_coordinates,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="protectionScope != null">protection_scope,</if>
            <if test="protectionScopeRemarks != null">protection_scope_remarks,</if>
            <if test="faultReport != null">fault_report,</if>
            <if test="manager != null">manager,</if>
            <if test="managerPhone != null">manager_phone,</if>
            <if test="pictures != null">pictures,</if>
            <if test="code != null">code,</if>
            <if test="remarks != null">remarks,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="siteId != null">site_id,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="monitoringStation != null and monitoringStation != ''">#{monitoringStation},</if>
            <if test="pileNumber != null">#{pileNumber},</if>
            <if test="projectName != null">#{projectName},</if>
            <if test="constructionYear != null">#{constructionYear},</if>
            <if test="equipmentBrand != null">#{equipmentBrand},</if>
            <if test="equipmentModel != null">#{equipmentModel},</if>
            <if test="siteLocation != null">#{siteLocation},</if>
            <if test="siteCoordinates != null">#{siteCoordinates},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="protectionScope != null">#{protectionScope},</if>
            <if test="protectionScopeRemarks != null">#{protectionScopeRemarks},</if>
            <if test="faultReport != null">#{faultReport},</if>
            <if test="manager != null">#{manager},</if>
            <if test="managerPhone != null">#{managerPhone},</if>
            <if test="pictures != null">#{pictures},</if>
            <if test="code != null">#{code},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="siteId != null">#{siteId},</if>
        </trim>
    </insert>

    <update id="updateGSiteInfo" parameterType="GSiteMonitorInfo">
        update g_site_monitor_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="monitoringStation != null and monitoringStation != ''">monitoring_station = #{monitoringStation},</if>
            <if test="pileNumber != null">pile_number = #{pileNumber},</if>
            <if test="projectName != null">project_name = #{projectName},</if>
            <if test="constructionYear != null">construction_year = #{constructionYear},</if>
            <if test="equipmentBrand != null">equipment_brand = #{equipmentBrand},</if>
            <if test="equipmentModel != null">equipment_model = #{equipmentModel},</if>
            <if test="siteLocation != null">site_location = #{siteLocation},</if>
            <if test="siteCoordinates != null">site_coordinates = #{siteCoordinates},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="protectionScope != null">protection_scope = #{protectionScope},</if>
            <if test="protectionScopeRemarks != null">protection_scope_remarks = #{protectionScopeRemarks},</if>
            <if test="faultReport != null">fault_report = #{faultReport},</if>
            <if test="manager != null">manager = #{manager},</if>
            <if test="managerPhone != null">manager_phone = #{managerPhone},</if>
            <if test="pictures != null">pictures = #{pictures},</if>
            <if test="code != null">code = #{code},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="siteId != null">site_id = #{siteId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGSiteInfoById" parameterType="Long">
        delete from g_site_monitor_info where id = #{id}
    </delete>

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