<?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.inspur.mapper.ElevatorWorkOrderMapper">
    
    <resultMap type="ElevatorWorkOrder" id="ElevatorWorkOrderResult">
        <result property="id"    column="id"    />
        <result property="trappedPersonTel"    column="trapped_person_tel"    />
        <result property="region"    column="region"    />
        <result property="community"    column="community"    />
        <result property="building"    column="building"    />
        <result property="elevatorName"    column="elevator_name"    />
        <result property="securityCode"    column="security_code"    />
        <result property="status"    column="status"    />
        <result property="createDate"    column="create_date"    />
        <result property="recordingDuration"    column="recording_duration"    />
        <result property="callRecording"    column="call_recording"    />
        <result property="maintCompany"    column="maint_company"    />
        <result property="maintFristPerson"    column="maint_frist_person"    />
        <result property="maintfristTel"    column="maintfrist_tel"    />
        <result property="maintSecondPerson"    column="maint_second_person"    />
        <result property="maintSecondTel"    column="maint_second_tel"    />
        <result property="tenementPerson"    column="tenement_person"    />
        <result property="tenementTel"    column="tenement_tel"    />
        <result property="handler"    column="handler"    />
        <result property="handleContactTel"    column="handle_contact_tel"    />
        <result property="handleDepart"    column="handle_depart"    />
        <result property="handleTime"    column="handle_time"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectElevatorWorkOrderVo">
        select id, trapped_person_tel, region, community, building, elevator_name, security_code, status, create_date, recording_duration, call_recording, maint_company, maint_frist_person, maintfrist_tel, maint_second_person, maint_second_tel, tenement_person, tenement_tel, handler, handle_contact_tel, handle_depart, handle_time, del_flag, create_time, update_time, remark from elevator_work_order
    </sql>

    <select id="selectElevatorWorkOrderList" parameterType="ElevatorWorkOrder" resultMap="ElevatorWorkOrderResult">
        <include refid="selectElevatorWorkOrderVo"/>
        <where>  
            <if test="elevatorName != null  and elevatorName != ''"> and (elevator_name like concat('%', #{elevatorName}, '%') or security_code like concat('%', #{elevatorName}, '%'))</if>
            <if test="securityCode != null  and securityCode != ''"> and security_code like concat('%', #{securityCode}, '%')</if>
            <if test="status != null "> and status = #{status}</if>
            <!--<if test="createDate != null "> and create_date = #{createDate}</if>-->
            <if test="createDateStart != null"><!-- 开始时间检索 -->
                AND date_format(create_time,'%Y%m%d') &gt;= date_format(#{createDateStart},'%Y%m%d')
            </if>
            <if test="createDateEnd != null"><!-- 结束时间检索 -->
                AND date_format(create_time,'%Y%m%d') &lt;= date_format(#{createDateEnd},'%Y%m%d')
            </if>
        </where>
    </select>
    
    <select id="selectElevatorWorkOrderById" parameterType="Long" resultMap="ElevatorWorkOrderResult">
        <include refid="selectElevatorWorkOrderVo"/>
        where id = #{id}
    </select>

    <insert id="insertElevatorWorkOrder" parameterType="ElevatorWorkOrder" useGeneratedKeys="true" keyProperty="id">
        insert into elevator_work_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="trappedPersonTel != null">trapped_person_tel,</if>
            <if test="region != null">region,</if>
            <if test="community != null">community,</if>
            <if test="building != null">building,</if>
            <if test="elevatorName != null">elevator_name,</if>
            <if test="securityCode != null">security_code,</if>
            <if test="status != null">status,</if>
            <if test="createDate != null">create_date,</if>
            <if test="recordingDuration != null">recording_duration,</if>
            <if test="callRecording != null">call_recording,</if>
            <if test="maintCompany != null">maint_company,</if>
            <if test="maintFristPerson != null">maint_frist_person,</if>
            <if test="maintfristTel != null">maintfrist_tel,</if>
            <if test="maintSecondPerson != null">maint_second_person,</if>
            <if test="maintSecondTel != null">maint_second_tel,</if>
            <if test="tenementPerson != null">tenement_person,</if>
            <if test="tenementTel != null">tenement_tel,</if>
            <if test="handler != null">handler,</if>
            <if test="handleContactTel != null">handle_contact_tel,</if>
            <if test="handleDepart != null">handle_depart,</if>
            <if test="handleTime != null">handle_time,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="trappedPersonTel != null">#{trappedPersonTel},</if>
            <if test="region != null">#{region},</if>
            <if test="community != null">#{community},</if>
            <if test="building != null">#{building},</if>
            <if test="elevatorName != null">#{elevatorName},</if>
            <if test="securityCode != null">#{securityCode},</if>
            <if test="status != null">#{status},</if>
            <if test="createDate != null">#{createDate},</if>
            <if test="recordingDuration != null">#{recordingDuration},</if>
            <if test="callRecording != null">#{callRecording},</if>
            <if test="maintCompany != null">#{maintCompany},</if>
            <if test="maintFristPerson != null">#{maintFristPerson},</if>
            <if test="maintfristTel != null">#{maintfristTel},</if>
            <if test="maintSecondPerson != null">#{maintSecondPerson},</if>
            <if test="maintSecondTel != null">#{maintSecondTel},</if>
            <if test="tenementPerson != null">#{tenementPerson},</if>
            <if test="tenementTel != null">#{tenementTel},</if>
            <if test="handler != null">#{handler},</if>
            <if test="handleContactTel != null">#{handleContactTel},</if>
            <if test="handleDepart != null">#{handleDepart},</if>
            <if test="handleTime != null">#{handleTime},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateElevatorWorkOrder" parameterType="ElevatorWorkOrder">
        update elevator_work_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="trappedPersonTel != null">trapped_person_tel = #{trappedPersonTel},</if>
            <if test="region != null">region = #{region},</if>
            <if test="community != null">community = #{community},</if>
            <if test="building != null">building = #{building},</if>
            <if test="elevatorName != null">elevator_name = #{elevatorName},</if>
            <if test="securityCode != null">security_code = #{securityCode},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createDate != null">create_date = #{createDate},</if>
            <if test="recordingDuration != null">recording_duration = #{recordingDuration},</if>
            <if test="callRecording != null">call_recording = #{callRecording},</if>
            <if test="maintCompany != null">maint_company = #{maintCompany},</if>
            <if test="maintFristPerson != null">maint_frist_person = #{maintFristPerson},</if>
            <if test="maintfristTel != null">maintfrist_tel = #{maintfristTel},</if>
            <if test="maintSecondPerson != null">maint_second_person = #{maintSecondPerson},</if>
            <if test="maintSecondTel != null">maint_second_tel = #{maintSecondTel},</if>
            <if test="tenementPerson != null">tenement_person = #{tenementPerson},</if>
            <if test="tenementTel != null">tenement_tel = #{tenementTel},</if>
            <if test="handler != null">handler = #{handler},</if>
            <if test="handleContactTel != null">handle_contact_tel = #{handleContactTel},</if>
            <if test="handleDepart != null">handle_depart = #{handleDepart},</if>
            <if test="handleTime != null">handle_time = #{handleTime},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteElevatorWorkOrderById" parameterType="Long">
        delete from elevator_work_order where id = #{id}
    </delete>

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