<?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.RepairDownloadMapper">
    <select id="getOrderBase" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderBase">
        select a.pgid,a.pgguid,'REPAIR' as order_type,c.order_state as order_status,d.order_state as last_order_status,
               a.dqjdsj as order_status_time,IFNULL(a.yxji,'1') as priority,a.xjwdsj as dispatch_time,
               a.xjwdsj as dispatch_websit_time,a.yhmc as user_name,a.yddh as user_mobile,
               a.yddh2 as user_mobile2,a.yhsx as user_attr,a.quhao as area_code,a.dhhm as tel_phone,
               a.fjhm as gree_virtualnumber,a.email,a.vip,
               a.sfen as province,a.cshi as city,a.xian as area,a.xzhen as street,
               a.sfenid as province_id,a.cshiid as city_id,a.xianid as area_id,a.xzhenid as street_id,
               a.dizi as address,IFNULL(a.gpsdzxx,'') as gps_address,
               a.xxlb as info_type,a.beiz as remark,a.gdhao as file_no,e.dict_code as main_id,e.dict_value as main_name,
               f.dict_code as service_category_id,f.dict_value as service_category_name,
               if((a.wxwdno='' or wxwdno is null),IFNULL(a.xjwdno,''),a.wxwdno) as websit_id,a.wxwdmc as websit_name,
               a.xjwdno as rece_websit_id,a.xjwdmc as rece_websit_name,
               a.cjwdno as create_websit_id,'' as create_websit_name,
               a.xswdno as sale_websit_id,a.xswdmc as sale_websit_name,
               a.zjczwd as last_operator_websit,a.zjczwdxtbh as sys_websit_number,
               a.xxqdid as info_channel_id,ifnull(a.xxqd,'') as info_channel,a.xxlyid as info_source_id,ifnull(a.xxly,'') as info_source,
               a.ssqy as region,a.zxhao as seat_no,a.xsdh as external_pk,
               a.bjustat as bjy_check_status,a.yhqwsmsj as expect_start_time,a.qwsmjssj as expect_end_time,a.cjwdno as create_sys,
               a.last_modified_by as last_operator_by,IFNULL(a.zjczsj,a.last_modified_date) as last_operator_time,
               a.yhqwsmsj as appointment_time,a.azsl as total_num,a.wwsl as undone_num,a.xsdh as sale_no,
               a.xsorsh as data_push_attr,
               a.jindu as lng,a.weidu as lat,a.wcsj as over_time,a.cjdt as create_time,a.cjren as create_by,a.cjrmc as create_name,
               IFNULL(a.last_modified_date,a.zjczsj) as update_time,a.last_modified_by as update_by,a.wxrenid as dispatch_flag,1 as upload_flag,
               a.xjwdsj as rece_time,a.xjwdsj as worker_rece_time,a.xxlbid as info_type_id,
               a.yhsxid as user_attr_id,a.qqlymc as external_name2,a.qqlyxh as external_no,a.wxcount as out_wxcount,
               case a.tsdengji when '一级投诉' then 'FIRST'
                               when '二级投诉' then 'SECOND'
                               when '三级投诉' then 'THIRD'
                               when '特级投诉' then 'SUPER' else 'NO' end as complaint,
               case when a.spid=102 then '商用' when a.spid=109 then '商用' else '家用' end as service_flag
        from itf_tbl_assign_download a
                 left join order_state_contrast c on c.brand_order_state=a.stat and c.state_type=60 and c.brand_id = #{request.brandId}
                 left join order_state_contrast d on d.brand_order_state=a.qystat and d.state_type=60 and d.brand_id = #{request.brandId}
                 left join sys_dict_ref e on e.ref_dict_code=a.spid and e.brand_id = #{request.brandId} and e.dict_type='MAIN_TYPE'
                 left join sys_dict f on f.dict_type='SERVICE_CATEGORY' and f.dict_value='家电售后'
        where a.syn_req_id = #{request.synReqId}
    </select>

    <select id="getUpOrderBase" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderBase">
        select a.yhmc as user_name,a.quhao as area_code,a.yddh as user_mobile,a.dhhm as tel_phone,
               a.email,a.yddh2 as user_mobile2,a.vip,a.xjwdsj as dispatch_time,
               a.sfen as province,a.cshi as city,a.xian as area,a.xzhen as street,
               a.sfenid as province_id,a.cshiid as city_id,a.xianid as area_id,a.xzhenid as street_id,
               a.dizi as address,a.beiz as remark,IFNULL(a.last_modified_date,a.zjczsj) as update_time,
               case when a.spid=102 then '商用' when a.spid=109 then '商用' else '家用' end as service_flag,
               a.last_modified_by as update_by,IFNULL(a.yxji,'1') as priority,a.gpsdzxx as gps_address,
               case a.tsdengji when '一级投诉' then 'FIRST'
                               when '二级投诉' then 'SECOND'
                               when '三级投诉' then 'THIRD'
                               when '特级投诉' then 'SUPER' else 'NO' end as complaint,
               a.xswdno as sale_websit_id,
               a.xxqdid as info_channel_id,ifnull(a.xxqd,'') as info_channel,a.xxlyid as info_source_id,ifnull(a.xxly,'') as info_source,
               a.wcsj as over_time,IFNULL(a.zjczsj,a.last_modified_date) as last_operator_time,
               IFNULL(a.last_modified_date,a.zjczsj) as update_time,a.yhsx as user_attr,a.yhsxid as user_attr_id,
               a.fjhm as gree_virtualnumber,
               a.gdhao as file_no,a.zxhao as seat_no,a.xjwdsj as rece_time,a.xjwdsj as worker_rece_time,
               a.yhqwsmsj as appointment_time,
               a.yhqwsmsj as expect_start_time,a.qwsmjssj as expect_end_time,
               a.wxcount as out_wxcount,a.ssqy as region,a.xsdh as external_pk
        from itf_tbl_assign_download a
        where a.syn_req_id = #{request.synReqId}
    </select>

    <select id="getOrderBaseStatus" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderBase">
        select c.order_state as order_status,d.order_state as last_order_status
        from itf_tbl_assign_download a
                 left join order_state_contrast c on c.brand_order_state=a.stat and c.state_type=60 and c.brand_id = #{request.brandId}
                 left join order_state_contrast d on d.brand_order_state=a.qystat and d.state_type=60 and d.brand_id = #{request.brandId}
        where a.syn_req_id = #{request.synReqId}
    </select>


</mapper>
