<?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.zfire.jiasm.syncdata.dao.mapper.RepairLogMapper">

    <select id="getFkid" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderRepairOperatingLog">
        select 1 as fkid
        from order_repair_operating_log
        where create_time > UNIX_TIMESTAMP(DATE_ADD(now() , INTERVAL -2 DAY) ) and fkid = #{request.pgid}
    </select>

    <select id="getUpdatetime" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderRepairOperatingLog">
        select min(update_time) as update_time
        from order_repair_operating_log
        where order_base_id = #{request.orderNo} and type = '创建工单'
    </select>

    <select id="getUpdatetimeT" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderRepairOperatingLog">
        select min(update_time) as update_time
        from order_repair_operating_log
        where order_base_id = #{request.orderNo} and type = '自动派工'
    </select>


    <select id="getItfTblAssignFkmxUpload" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAssignFkmxUpload">
        select out_id as fa_order_repair_operating_log_id,fkid,'guangfo' as created_by,
               create_time as created_date,'guangfo' as last_modified_by,update_time as last_modified_date,pgid,
               type as fklb,feedback as fkjg,content as fknr,operator as fkren,operator_number as fkrenmc,
               create_time as fksj,brand_file_id as scid,websit_id as fkwdno,
               brand_file_name as scwj,req_source_num as qqlyxh,fkmxguid,wjid
        from order_repair_operating_log
        where order_base_id = #{request.orderNo} and id = #{request.id}
    </select>

    <select id="getItfTblAssignAppointmentUpload" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAssignAppointmentUpload">
        select a.order_base_id as worker_order_no,a.out_id as fa_order_repair_operating_log_id,
               a.fkid as id,'guangfo' as created_by,a.create_time as created_date,'guangfo' as last_modified_by,
               a.update_time as last_modified_date,b.appointment_time as kssj,b.appointment_time as jssj,
               a.operator as czren,a.pgid,a.create_time as czsj,a.type as leix,a.type as reason,a.content as beiz
        from order_repair_operating_log a
                 left join order_base b on b.id = a.order_base_id
        where a.order_base_id = #{request.orderNo} and a.id = #{request.id}
          and (type in ('用户预约', '反馈改约', '服务人员申请改约', '延后改约', '延误' ) or feedback in( '用户预约', '用户改约', '延误'))
    </select>

    <update id="upRepairLogPgid" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar">
        update order_repair_operating_log set pgid = #{request.pgid}
        where order_base_id = #{request.orderNo} and (pgid is null or pgid = 0)
    </update>

    <update id="upRepairLogFkid" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar">
        update order_repair_operating_log set fkid = #{request.fkid}
        where order_base_id = #{request.orderNo} and id = #{request.id}
    </update>


</mapper>
