<?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.TInspectionPlanMapper">
    
    <resultMap type="TInspectionPlan" id="TInspectionPlanResult">
        <result property="planId"    column="plan_id"    />
        <result property="planName"    column="plan_name"    />
        <result property="orderId"    column="order_id"    />
        <result property="deviceIds"    column="device_ids"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
        <result property="address"    column="address"    />
        <result property="planStatus"    column="plan_status"    />
        <result property="isDel"    column="is_del"    />
        <result property="updateTime"    column="update_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="remarks"    column="remarks"    />
    </resultMap>

    <sql id="selectTInspectionPlanVo">
        select plan_id, plan_name, order_id, device_ids, start_time, end_time, address, plan_status, is_del, update_time, create_time, remarks from t_inspection_plan
    </sql>

    <select id="selectTInspectionPlanList" parameterType="InspectionPlanForm" resultMap="TInspectionPlanResult">
        <include refid="selectTInspectionPlanVo"/>
        <where>
            and is_del = '0'
            <if test="planName != null  and planName != ''"> and plan_name like concat('%', #{planName}, '%')</if>
            <if test="orderId != null  and orderId != ''"> and order_id like concat('%', #{orderId}, '%')</if>
            <if test="startTime1 != null "> and start_time &gt;= #{startTime1}</if>
            <if test="endTime1 != null "> and start_time &lt;= #{endTime1}</if>
            <if test="startTime2 != null "> and end_time &gt;= #{startTime2}</if>
            <if test="endTime2 != null "> and end_time &lt;= #{endTime2}</if>
            <if test="planStatus != null  and planStatus != ''"> and plan_status = #{planStatus}</if>
            <if test="remarks != null "> and remarks &lt;= #{remarks}</if>
        </where>
    </select>
    
    <select id="selectTInspectionPlanById" parameterType="int" resultMap="TInspectionPlanResult">
        <include refid="selectTInspectionPlanVo"/>
        where plan_id = #{planId}
    </select>
        
    <insert id="insertTInspectionPlan" parameterType="TInspectionPlan" useGeneratedKeys="true" keyProperty="planId">
        insert into t_inspection_plan
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="planName != null">plan_name,</if>
            <if test="orderId != null">order_id,</if>
            <if test="deviceIds != null">device_ids,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
            <if test="address != null">address,</if>
            <if test="planStatus != null">plan_status,</if>
            <if test="isDel != null">is_del,</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="planName != null">#{planName},</if>
            <if test="orderId != null">#{orderId},</if>
            <if test="deviceIds != null">#{deviceIds},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
            <if test="address != null">#{address},</if>
            <if test="planStatus != null">#{planStatus},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="remarks != null">#{remarks},</if>
         </trim>
    </insert>

    <update id="updateTInspectionPlan" parameterType="TInspectionPlan">
        update t_inspection_plan
        <trim prefix="SET" suffixOverrides=",">
            <if test="planName != null">plan_name = #{planName},</if>
            <if test="orderId != null">order_id = #{orderId},</if>
            <if test="deviceIds != null">device_ids = #{deviceIds},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
            <if test="address != null">address = #{address},</if>
            <if test="planStatus != null">plan_status = #{planStatus},</if>
            <if test="isDel != null">is_del = #{isDel},</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 plan_id = #{planId}
    </update>

    <delete id="deleteTInspectionPlanById" parameterType="Long">
        delete from t_inspection_plan where plan_id = #{planId}
    </delete>

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