<?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.AZGDLcLsDownloadMapper">
    <select id="getOrderBase" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderBase">
        select pgid,pgguid,'INSTALL' as order_type,'INSTALL' as order_small_type,c.order_state as order_status,
               a.dqjdsj as order_status_time,d.order_state as last_order_status,e.order_state as dispatch_status,
               a.pgsj as dispatch_time,a.yhmc as user_name,a.lxren as link_name,a.yddh as user_mobile,a.yddh2 as user_mobile2,
               a.yhsx as user_attr,IFNULL(a.quhao, '') as area_code,IFNULL(a.dhhm,'') as tel_phone,a.extendfiled2 as vip,a.email,
               IFNULL(a.sfen,'') as province,IFNULL(a.cshi,'') as city,IFNULL(a.xian,'') as area,IFNULL(a.xzhen,'') as street,
               a.sfenid as province_id,a.cshiid as city_id,a.xianid as area_id,a.xzhenid as street_id,
               IFNULL(a.dizi,'') as address,a.xxlb as info_type,
               IFNULL(a.beiz,'') as remark,IFNULL(a.yxji,'1') as priority,a.gdhao as file_no,f.dict_code as main_id,f.dict_value as main_name,
               g.dict_code as service_category_id,g.dict_value as service_category_name,
               IFNULL(a.azwdno, '') as websit_id,IFNULL(a.azwdmc, '') as websit_name,
               a.jspgwdno as rece_websit_id,a.jspgwdmc as rece_websit_name,
               a.cjwdno as create_websit_id,a.cjrmc as create_websit_name,
               a.xsdwno as sale_websit_id, a.xswdmc as sale_websit_name,a.xsdwxtbh as sale_websit_sys_number,
               a.zjczwd as last_operator_websit,a.zjczwdxtbh as sys_websit_number,
               a.jspgwdsj as rece_time,a.jspgwdsj as worker_rece_time,
               a.zxha as seat_no,a.ssqy as region,a.qqlyno as external_sys,a.qqlymc as external_name2,
               a.qqlyxh as external_no,a.qqlyzj as external_pk,a.bjustat as bjy_check_status,
               a.yhqwkssj as expect_start_time,a.yhqwjssj as expect_end_time,IFNULL(a.gpsdzxx,'') as gps_address,
               a.cjwdno as create_sys,a.zjczwd as last_operator_websit,a.zjczwdxtbh as sys_websit_number,
               a.zjczren as last_operator_by,a.zjczsj as last_operator_time,a.xslx as sale_type,a.lcid as process_no,
               a.djlxno as  bill_type_no,ifnull(a.yyazsj,a.yhqwkssj) as appointment_time,
               ifnull(a.yyazsj,a.yhqwkssj) as appointment_end_time,
               case a.sfwcps when '未配送' then 'NO' when '配送中' then 'NO' when '否' then 'NO' else 'YES' end as is_delivery_over,
               a.azsl as total_num,a.wwsl as undone_num,a.xsdh as sale_no,
               a.fphm as invoice_no,a.gmsj as buy_time,a.kqbh as cross_no,
               a.xsorsh as data_push_attr,a.jindu as lng,a.weidu as lat,a.shsj as delivery_time,a.sfygllc as sfygllc,
               a.xslxid as sale_type_id,a.yhsxid as user_attr_id,a.xxlbid as info_type_id,
               a.wcsj as over_time,a.cjdt as create_time,a.cjren as create_by,a.cjrmc as create_name,a.last_modified_date as update_time,
               a.last_modified_by as update_by,a.azren as dispatch_flag,a.jspgwdsj as first_dispatch_websit_time,
               ifnull(a.xxqd,'') as info_channel,a.xxlyid as info_source_id,ifnull(a.xxly,'') as info_source,
               1 as upload_flag,
               case when a.spid=102 then '商用' when a.spid=109 then '商用' else '家用' end as service_flag,
               a.fjhm as gree_virtualnumber,
               case a.dqjd when 1100 then '1' when 1122 then '1' when 1130 then '1' else '0' end as is_reservation
        from itf_tbl_az_assign_lc_ls_download a
                 left join order_state_contrast c on a.dqjd=c.brand_order_state and c.state_type=10 and c.brand_id = #{request.brandId}
                 left join order_state_contrast d on a.syjd=d.brand_order_state and d.state_type=10 and d.brand_id = #{request.brandId}
                 left join order_state_contrast e on a.dqjd=e.brand_order_state and e.state_type=11 and e.brand_id = #{request.brandId}
                 left join sys_dict_ref f on a.spid= f.ref_dict_code and f.brand_id=1 and f.dict_type='MAIN_TYPE'
                 left join sys_dict g on g.dict_type='SERVICE_CATEGORY' and g.dict_value='家电售后'
        where a.syn_req_id = #{request.synReqId}
    </select>

    <select id="getOrderBaseUp" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderBase">
        select pgid,pgguid,'INSTALL' as order_type,'INSTALL' as order_small_type,a.yddh as user_mobile,
               a.yddh2 as user_mobile2,a.yhmc as user_name,a.lxren as link_name,IFNULL(a.quhao, '') as area_code,
               IFNULL(a.dhhm,'') as tel_phone,IFNULL(a.fjhm,'') as gree_virtualnumber,
               IFNULL(a.dizi,'') as address,IFNULL(a.sfen,'') as province,IFNULL(a.cshi as city,''),
               IFNULL(a.xian,'') as area,IFNULL(a.xzhen,'') as street,a.sfenid as province_id,a.cshiid as city_id,
               a.xianid as area_id,a.xzhenid as street_id,IFNULL(a.beiz,'') as remark,a.wwsl as undone_num,b.sfzen as worker_id,
               b.wxgmc as worker_name,b.yddh as worker_mobile,b.sfzen as worker_idcard,a.pgsj as dispatch_time,
               a.jspgwdsj as rece_time,a.jspgwdno as rece_websit_id,a.wcsj as over_time,a.xsdwno as sale_websit_id,
               a.kqbh as cross_no,a.yhsx as user_attr,a.yhsxid as user_attr_id,a.xslxid as sale_type_id,a.xxlbid as info_type_id,
               a.fphm as invoice_no,a.gmsj as buy_time,
               a.xxlb as info_type,a.yhqwkssj as expect_start_time,ifnull(a.yyazsj,a.yhqwkssj) as appointment_time,
               c.order_state as order_status,ifnull(a.xxqd,'') as info_channel,a.xxlyid as info_source_id,ifnull(a.xxly,'') as info_source,



               a.dqjdsj as order_status_time,d.order_state as last_order_status,e.order_state as dispatch_status,
               a.fjhm as gree_virtualnumber,a.extendfiled2 as vip,a.email,
               IFNULL(a.yxji,'1') as priority,a.gdhao as file_no,f.dict_code as main_id,f.dict_value as main_name,
               g.dict_code as service_category_id,g.dict_value as service_category_name,
               IFNULL(a.azwdno, '') as websit_id,
               a.cjwdno as create_websit_id,
               a.zxha as seat_no,a.ssqy as region,a.qqlyno as external_sys,a.qqlymc as external_name2,
               a.qqlyxh as external_no,a.qqlyzj as external_pk,a.bjustat as bjy_check_status,
               a.yhqwjssj as expect_end_time,IFNULL(a.gpsdzxx,'') as gps_address,
               a.cjwdno as create_sys,a.zjczwd as last_operator_websit,a.zjczwdxtbh as sys_websit_number,
               a.zjczren as last_operator_by,a.zjczsj as last_operator_time,a.xslx as sale_type,a.lcid as process_no,
               a.djlxno as  bill_type_no,
               case a.sfwcps when '0' then 'NO'
                             when '1' then 'YES' else 'NO' end as is_delivery_over,
               a.azsl as total_num,a.xsdh as sale_no,

               a.xsorsh as data_push_attr,a.jindu as lng,a.weidu as lat,a.shsj as delivery_time,a.sfygllc as sfygllc,

               a.cjdt as create_time,a.cjren as create_by,a.cjrmc as create_name,a.last_modified_date as update_time,
               a.last_modified_by as update_by,a.azren as dispatch_flag,a.jspgwdsj as first_dispatch_websit_time,
               1 as upload_flag,TL_createOrderSn('33', 20, 1, 9) as id,
               case when a.spid=102 then '商用' when a.spid=109 then '商用' else '家用' end as service_flag,

        from itf_tbl_az_assign_lc_ls_download a
                 left join itf_tbl_wangdian_wxg_download b on a.azrenid=b.wxgid and b.wdno=a.jspgwdno
                 left join order_state_contrast c on a.dqjd=c.brand_order_state and c.state_type=10 and c.brand_id = #{request.brandId}
                 left join order_state_contrast d on a.syjd=d.brand_order_state and d.state_type=10 and d.brand_id = #{request.brandId}
                 left join order_state_contrast e on a.dqjd=e.brand_order_state and e.state_type=11 and e.brand_id = #{request.brandId}
                 left join sys_dict_ref f on a.spid= f.ref_dict_code and f.brand_id=1 and f.dict_type='MAIN_TYPE'
                 left join sys_dict g on g.dict_type='SERVICE_CATEGORY' and g.dict_value='家电售后'
        where a.syn_req_id = #{request.synReqId}
    </select>


</mapper>
