<?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.DetailOrderRepairMapper">

    <select id="getItfTblWxjsJyktUpload" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblWxjsJyktUpload">
        select a.order_base_id as worker_order_no,a.out_id as fa_order_repair_detail_id,a.brand_wxjsguid as wxjsguid,
               'guangfo' as created_by,a.create_time as created_date,'guangfo' as last_modified_by,a.update_time as last_modified_date,
               d.pgid as pgid,a.settle_websit_id as jswdno,a.repair_type_three as wxlx3,
               if(c.ref_dict_code in(104,106),1,case a.type when 'INSIDE' then 2 when 'OUT' then 1 else 3 end) as nwji,
               if(c.ref_dict_code in(104,106) and (a.out_code is null or a.out_code = ''), a.inside_code, a.out_code)	as jqtm,
               case when length(a.out_number)>10 then left(a.in_number,10) else a.out_number end as wjxin,a.out_style as wjms,if(c.ref_dict_code in(104,106), '', a.inside_code) as njtm,'' as njtm2,
               case when length(a.in_number) >5  then left(a.in_number,5) else a.in_number end as njxin,
               a.in_style as njmc,a.invoice_no as fpbh,a.install_time as azrq,
               if(d.update_time is null,max(e.update_time), d.update_time)	as xfrq,a.brand_wxgid as wxgid,a.worker_name as wxgmc,
               a.worker_mobile as wxgdh,a.repair_fees as wxfy,a.traffic_expense as jtfy,a.other_fees as qtfy,a.total_fees as zjfy,
               a.settle_bill as jsdh,a.clearing as jszt,a.trouble as gzxx,
               a.trouble_analysis as gzfx,a.repaire_item as wxnr,a.remark as beiz,a.create_time as ldrq,a.worker_name as czrmc,
               if(length(a.gps_address)>110,left(a.gps_address,110),a.gps_address) as gpsdzxx,
               d.user_mobile as yddh,0 as zsfy,0 as dzfy,h.ref_dict_code as spid,
               c.ref_dict_name as spmc,a.settle_time as zjssj,a.create_time as cjdt,i.pgmxid,j.zbby,
               case when length(a.lng) >12  then left(a.lng,12) else a.lng end as sjcjjd,
               case when length(a.lat) >12  then left(a.lat,12) else a.lat end as sjcjwd,
               if(j.zbby = '1' and c.ref_dict_code = 101 , 8, 1 ) as wxlx,a.over_time as bwgsj
        from order_repair_detail a
             left join sys_dict_ref c on c.dict_code=a.main_id and c.brand_id = #{request.brandId} and c.dict_type='MAIN_TYPE'
             left join order_base d on d.id=a.order_base_id
             left join order_repair_operating_log e on e.order_base_id=a.order_base_id
             left join sys_dict_ref h on h.dict_code=a.main_id and h.brand_id = #{request.brandId} and h.dict_type='MAIN_TYPE'
             left join order_product i on i.order_base_id = a.order_base_id and i.id = a.repair_product_id
             left join order_repair j on j.order_base_id = a.order_base_id
        where a.order_base_id = #{request.orderNo} and a.id =  #{request.id}
    </select>



    <update id="updatePgid" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar">
        update order_repair_detail set brand_pgid = #{request.pgid}
        where order_base_id = #{request.orderNo} and brand_pgid is null
    </update>





</mapper>
