<?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.THiddenTroubleMapper">
    
    <resultMap type="THiddenTrouble" id="THiddenTroubleResult">
        <result property="troubleId"    column="trouble_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="deviceType"    column="device_type"    />
        <result property="orderId"    column="order_id"    />
        <result property="address"    column="address"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="coordinates"    column="coordinates"    />
        <result property="dealStatus"    column="deal_status"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTHiddenTroubleVo">
        select trouble_id, device_id, device_type, order_id, address, longitude, latitude, coordinates, deal_status, update_time, create_time, remarks from t_hidden_trouble
    </sql>

    <select id="selectTHiddenTroubleList" parameterType="THiddenTrouble" resultMap="THiddenTroubleResult">
        <include refid="selectTHiddenTroubleVo"/>
        <where>  
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="deviceType != null "> and device_type = #{deviceType}</if>
            <if test="orderId != null  and orderId != ''"> and order_id = #{orderId}</if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
            <if test="coordinates != null "> and coordinates = #{coordinates}</if>
            <if test="dealStatus != null  and dealStatus != ''"> and deal_status = #{dealStatus}</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
        </where>
    </select>
    
    <select id="selectTHiddenTroubleById" parameterType="int" resultMap="THiddenTroubleResult">
        <include refid="selectTHiddenTroubleVo"/>
        where trouble_id = #{troubleId}
    </select>
        
    <insert id="insertTHiddenTrouble" parameterType="THiddenTrouble" useGeneratedKeys="true" keyProperty="troubleId">
        insert into t_hidden_trouble
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="orderId != null">order_id,</if>
            <if test="address != null">address,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="coordinates != null">coordinates,</if>
            <if test="dealStatus != null">deal_status,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="remarks != null">remarks,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="address != null">#{address},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="coordinates != null">#{coordinates},</if>
            <if test="dealStatus != null">#{dealStatus},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTHiddenTrouble" parameterType="THiddenTrouble">
        update t_hidden_trouble
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceType != null">device_id = #{deviceType},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="address != null">address = #{address},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="coordinates != null">coordinates = #{coordinates},</if>
            <if test="dealStatus != null">deal_status = #{dealStatus},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where trouble_id = #{troubleId}
    </update>

    <delete id="deleteTHiddenTroubleById" parameterType="Long">
        delete from t_hidden_trouble where trouble_id = #{troubleId}
    </delete>

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