<?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.TConfinedSpaceMapper">

    <resultMap type="com.zehong.system.domain.TConfinedSpace" id="TConfinedSpaceResult">
        <result property="id"    column="id"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterprise_name"    />
        <result property="socialCreditCode"    column="social_credit_code"    />
        <result property="venueFacility"    column="venue_facility"    />
        <result property="venueType"    column="venue_type"    />
        <result property="specificLocation"    column="specific_location"    />
        <result property="area"    column="area"    />
        <result property="riskFactors"    column="risk_factors"    />
        <result property="workFrequency"    column="work_frequency"    />
        <result property="warningSign"    column="warning_sign"    />
        <result property="emergencyEquipment"    column="emergency_equipment"    />
        <result property="siteSupervisor"    column="site_supervisor"    />
        <result property="supervisorPhone"    column="supervisor_phone"    />
        <result property="lastDate"    column="last_date"    />
        <result property="createTime"    column="create_time"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
    </resultMap>

    <sql id="selectTConfinedSpaceVo">
        select id, enterprise_id, enterprise_name, social_credit_code, venue_facility, venue_type, specific_location, area, risk_factors, work_frequency, warning_sign, emergency_equipment, site_supervisor, supervisor_phone, last_date, create_time, longitude, latitude from t_confined_space
    </sql>

    <select id="selectTConfinedSpaceList" parameterType="com.zehong.system.domain.TConfinedSpace" resultMap="TConfinedSpaceResult">
        <include refid="selectTConfinedSpaceVo"/>
        <where>
            <if test="enterpriseId != null  and enterpriseId != ''"> and enterprise_id = #{enterpriseId}</if>
            <if test="enterpriseName != null  and enterpriseName != ''"> and enterprise_name like concat('%', #{enterpriseName}, '%')</if>
            <if test="socialCreditCode != null  and socialCreditCode != ''"> and social_credit_code = #{socialCreditCode}</if>
            <if test="venueFacility != null  and venueFacility != ''"> and venue_facility = #{venueFacility}</if>
            <if test="venueType != null  and venueType != ''"> and venue_type = #{venueType}</if>
            <if test="warningSign != null  and warningSign != ''"> and warning_sign = #{warningSign}</if>
            <if test="lastDate != null "> and last_date = #{lastDate}</if>
        </where>
    </select>

    <select id="selectTConfinedSpaceById" parameterType="Long" resultMap="TConfinedSpaceResult">
        <include refid="selectTConfinedSpaceVo"/>
        where id = #{id}
    </select>

    <insert id="insertTConfinedSpace" parameterType="com.zehong.system.domain.TConfinedSpace" useGeneratedKeys="true" keyProperty="id">
        insert into t_confined_space
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="enterpriseId != null">enterprise_id,</if>
            <if test="enterpriseName != null">enterprise_name,</if>
            <if test="socialCreditCode != null">social_credit_code,</if>
            <if test="venueFacility != null">venue_facility,</if>
            <if test="venueType != null">venue_type,</if>
            <if test="specificLocation != null">specific_location,</if>
            <if test="area != null">area,</if>
            <if test="riskFactors != null">risk_factors,</if>
            <if test="workFrequency != null">work_frequency,</if>
            <if test="warningSign != null">warning_sign,</if>
            <if test="emergencyEquipment != null">emergency_equipment,</if>
            <if test="siteSupervisor != null">site_supervisor,</if>
            <if test="supervisorPhone != null">supervisor_phone,</if>
            <if test="lastDate != null">last_date,</if>
            <if test="createTime != null">create_time,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="enterpriseId != null">#{enterpriseId},</if>
            <if test="enterpriseName != null">#{enterpriseName},</if>
            <if test="socialCreditCode != null">#{socialCreditCode},</if>
            <if test="venueFacility != null">#{venueFacility},</if>
            <if test="venueType != null">#{venueType},</if>
            <if test="specificLocation != null">#{specificLocation},</if>
            <if test="area != null">#{area},</if>
            <if test="riskFactors != null">#{riskFactors},</if>
            <if test="workFrequency != null">#{workFrequency},</if>
            <if test="warningSign != null">#{warningSign},</if>
            <if test="emergencyEquipment != null">#{emergencyEquipment},</if>
            <if test="siteSupervisor != null">#{siteSupervisor},</if>
            <if test="supervisorPhone != null">#{supervisorPhone},</if>
            <if test="lastDate != null">#{lastDate},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
        </trim>
    </insert>

    <update id="updateTConfinedSpace" parameterType="com.zehong.system.domain.TConfinedSpace">
        update t_confined_space
        <trim prefix="SET" suffixOverrides=",">
            <if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
            <if test="enterpriseName != null">enterprise_name = #{enterpriseName},</if>
            <if test="socialCreditCode != null">social_credit_code = #{socialCreditCode},</if>
            <if test="venueFacility != null">venue_facility = #{venueFacility},</if>
            <if test="venueType != null">venue_type = #{venueType},</if>
            <if test="specificLocation != null">specific_location = #{specificLocation},</if>
            <if test="area != null">area = #{area},</if>
            <if test="riskFactors != null">risk_factors = #{riskFactors},</if>
            <if test="workFrequency != null">work_frequency = #{workFrequency},</if>
            <if test="warningSign != null">warning_sign = #{warningSign},</if>
            <if test="emergencyEquipment != null">emergency_equipment = #{emergencyEquipment},</if>
            <if test="siteSupervisor != null">site_supervisor = #{siteSupervisor},</if>
            <if test="supervisorPhone != null">supervisor_phone = #{supervisorPhone},</if>
            <if test="lastDate != null">last_date = #{lastDate},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTConfinedSpaceById" parameterType="Long">
        delete from t_confined_space where id = #{id}
    </delete>

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

    <!--将关联设备信息与密闭空间进行绑定-->
    <update id="updatetRelationDeviceDetailInfo" parameterType="java.util.List">
        update t_relation_device_detail_info set relation_device_id = #{id} ,relation_device_type =#{relationDevicetype}
        where
        relation_device_detail_id in
        <foreach collection="gettDeviceInfoS" item="items" index="key" open="(" separator="," close=")">
           #{items.relationDeviceDetailId}
        </foreach>
    </update>
</mapper>