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

    <select id="getOrderInstallUpload" parameterType="com.zfire.jiasm.syncdata.parameter.InstallDetail" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxJyktUpload">
        select a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_id,a.pgwcmxid,'guangfo' as created_by,
               a.create_time as created_date,'guangfo' as last_modified_by,a.update_time as last_modified_date,b.pgmxid,a.pgguid,
               c.ref_dict_code as spid,c.ref_dict_name as spmc,d.ref_dict_code as xlid,d.ref_dict_name as xlmc,
               e.ref_dict_code as xiid,IFNULL(e.ref_dict_name, '') as ximc,a.inside_number as jxmc,a.out_number as jxno,
               IFNULL(substr(a.inside_code, 1, 13), '') as njtm,'' as njtm2,
               case when a.out_code is null then ''
                    when length(a.out_code)>13 then left(a.out_code,13) else a.out_code end as wjtm,
               '' as beiz,'' as installambient,
               case a.type when 'inside' 	then '更换内机'
                           when 'out' 	then '更换外机'
                           else '安装整机'	end as aznr,
               '' as zjia, 0 as jcguan, '' kqkg,'' as gkzy,'' as yccxqk,a.worker_mobile as shji,a.worker_name as czren,a.first_time as czsj,
               a.operator_websit_id as czwd,
               if(a.first_time is null,a.update_time,a.first_time) as dqjdsj,
               if(a.first_time is null,a.update_time,a.first_time) as zjczsj,
               if(a.first_time is null,a.update_time,a.first_time) as cjdt,
               a.worker_name as azren,
               case a.source when 'MOBILE' then 2 else 1 end as dnorsj,a.settle_websit_id as jsdwxtbh,
               if(a.first_time is null,a.update_time,a.first_time) as scazsj,
               a.settle_amount as azfy,a.settle_amount as jsfy,
               IFNULL(a.inside_password, '') as kjmm, if(a.inside_password != '', 1, 8) as kjmmbs,
               if(length(a.gps_address)>140,left(a.gps_address,140),a.gps_address) as sjcjgps,
               if(a.first_time=0,a.update_time,a.first_time) as sjcjsj,'' as kjmm2,
               g.bracket as zjia,g.pipe as jcguan,g.swith_flag as kqkg,g.high_altitude as gkzy,g.hole as yccxqk,
               a.websit_id as zjczwdxtbh,a.first_time as wcsj,
               a.lat as sjcjjd,a.lng as sjcjwd,CONCAT(a.lat,',',a.lng) as sjcjjwdu
        from order_install_detail a
                 left join order_product b on b.order_base_id = a.order_base_id and a.order_product_id=b.id
                 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 sys_dict_ref d on d.dict_code=a.small_id and d.brand_id = #{request.brandId} and d.dict_type='SMALL_TYPE'
                 left join sys_dict_ref e on e.dict_code=a.series_id and e.brand_id = #{request.brandId} and e.dict_type='SERIES'
                 left join order_install_detail_fee g on g.order_base_id = a.order_base_id and g.order_detail_id=a.id
        where a.order_base_id = #{request.orderNo} and a.status in( '1' , '2') and a.id = #{request.id}
    </select>

    <select id="getSyOrderInstallUpload" parameterType="com.zfire.jiasm.syncdata.parameter.InstallDetail" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxSyktUpload">
        select a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_id,a.pgwcmxid,'guangfo' as created_by,
               a.create_time as created_date,'guangfo' as last_modified_by,a.update_time as last_modified_date,b.pgmxid,a.pgguid,
               c.ref_dict_code as spid,c.ref_dict_name as spmc,d.ref_dict_code as xlid,d.ref_dict_name as xlmc,
               e.ref_dict_code as xiid,IFNULL(e.ref_dict_name, '') as ximc,a.inside_number as jxmc,a.out_number as jxno,
               IFNULL(substr(a.inside_code, 1, 13), '') as njtm,'' as njtm2,
               case when a.out_code is null then ''
                    when length(a.out_code)>13 then left(a.out_code,13) else a.out_code end as wjtm,
               '' as beiz,'' as installambient,
               case a.type when 'inside' 	then '更换内机'
                           when 'out' 	then '更换外机'
                           else '安装整机'	end as aznr,
               '' as zjia, 0 as jcguan, '' kqkg,'' as gkzy,'' as yccxqk,a.worker_mobile as shji,a.worker_name as czren,a.first_time as czsj,
               a.operator_websit_id as czwd,
               if(a.first_time is null,a.update_time,a.first_time) as dqjdsj,
               if(a.first_time is null,a.update_time,a.first_time) as zjczsj,
               if(a.first_time is null,a.update_time,a.first_time) as cjdt,
               a.worker_name as azren,
               case a.source when 'MOBILE' then 2 else 1 end as dnorsj,a.settle_websit_id as jsdwxtbh,
               if(a.first_time is null,a.update_time,a.first_time) as scazsj,
               a.settle_amount as azfy,a.settle_amount as jsfy,
               IFNULL(a.inside_password, '') as kjmm, if(a.inside_password != '', 1, 8) as kjmmbs,
               if(length(a.gps_address)>140,left(a.gps_address,140),a.gps_address) as sjcjgps,
               if(a.first_time=0,a.update_time,a.first_time) as sjcjsj,
               g.bracket as zjia,g.pipe as jcguan,g.swith_flag as kqkg,g.high_altitude as gkzy,g.hole as yccxqk,
               a.websit_id as zjczwdxtbh,a.first_time as wcsj,
               a.lat as sjcjjd,a.lng as sjcjwd,CONCAT(a.lat,',',a.lng) as sjcjjwdu
        from order_install_detail a
                 left join order_product b on b.order_base_id = a.order_base_id and a.order_product_id=b.id
                 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 sys_dict_ref d on d.dict_code=a.small_id and d.brand_id = #{request.brandId} and d.dict_type='SMALL_TYPE'
                 left join sys_dict_ref e on e.dict_code=a.series_id and e.brand_id = #{request.brandId} and e.dict_type='SERIES'
                 left join order_install_detail_fee g on g.order_base_id = a.order_base_id and g.order_detail_id=a.id
        where a.order_base_id = #{request.orderNo} and a.status in( '1' , '2') and a.id = #{request.id}
    </select>


    <select id="getOtherOrderInstallUpload" parameterType="com.zfire.jiasm.syncdata.parameter.InstallDetail" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxQitaUpload">
        select a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_id,a.pgwcmxid,'guangfo' as created_by,
               a.create_time as created_date,'guangfo' as last_modified_by,a.update_time as last_modified_date,b.pgmxid,a.pgguid,
               c.ref_dict_code as spid,c.ref_dict_name as spmc,d.ref_dict_code as xlid,d.ref_dict_name as xlmc,
               e.ref_dict_code as xiid,IFNULL(e.ref_dict_name, '') as ximc,a.inside_number as jxmc,a.out_number as jxno,
               IFNULL(substr(a.inside_code, 1, 13), '') as njtm,'' as njtm2,
               case when a.out_code is null then ''
                    when length(a.out_code)>13 then left(a.out_code,13) else a.out_code end as wjtm,
               '' as beiz,'' as installambient,
               case a.type when 'inside' 	then '更换内机'
                           when 'out' 	then '更换外机'
                           else '安装整机'	end as aznr,
               '' as zjia, 0 as jcguan, '' kqkg,'' as gkzy,'' as yccxqk,a.worker_mobile as shji,a.worker_name as czren,a.first_time as czsj,
               a.operator_websit_id as czwd,
               if(a.first_time is null,a.update_time,a.first_time) as dqjdsj,
               if(a.first_time is null,a.update_time,a.first_time) as zjczsj,
               if(a.first_time is null,a.update_time,a.first_time) as cjdt,
               a.worker_name as azren,
               case a.source when 'MOBILE' then 2 else 1 end as dnorsj,a.settle_websit_id as jsdwxtbh,
               if(a.first_time is null,a.update_time,a.first_time) as scazsj,
               a.settle_amount as azfy,a.settle_amount as jsfy,
               IFNULL(a.inside_password, '') as kjmm, if(a.inside_password != '', 1, 8) as kjmmbs,
               if(length(a.gps_address)>140,left(a.gps_address,140),a.gps_address) as sjcjgps,
               if(a.first_time=0,a.update_time,a.first_time) as sjcjsj,'' as kjmm2,
               g.bracket as zjia,g.pipe as jcguan,g.swith_flag as kqkg,g.high_altitude as gkzy,g.hole as yccxqk,
               a.websit_id as zjczwdxtbh,a.first_time as wcsj,
               a.lat as sjcjjd,a.lng as sjcjwd,CONCAT(a.lat,',',a.lng) as sjcjjwdu
        from order_install_detail a
                 left join order_product b on b.order_base_id = a.order_base_id and a.order_product_id=b.id
                 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 sys_dict_ref d on d.dict_code=a.small_id and d.brand_id = #{request.brandId} and d.dict_type='SMALL_TYPE'
                 left join sys_dict_ref e on e.dict_code=a.series_id and e.brand_id = #{request.brandId} and e.dict_type='SERIES'
                 left join order_install_detail_fee g on g.order_base_id = a.order_base_id and g.order_detail_id=a.id
        where a.order_base_id = #{request.orderNo} and a.status in( '1' , '2') and a.id = #{request.id}
    </select>

    <select id="getOrderInstallUploadCj" parameterType="com.zfire.jiasm.syncdata.parameter.InstallDetail" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxJyktUpload">
        select 44 as syn_status,a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_id,a.pgwcmxid,'guangfo' as created_by,
               a.create_time as created_date,'guangfo' as last_modified_by,a.update_time as last_modified_date,b.pgmxid,a.pgguid,
               c.ref_dict_code as spid,c.ref_dict_name as spmc,d.ref_dict_code as xlid,d.ref_dict_name as xlmc,
               e.ref_dict_code as xiid,IFNULL(e.ref_dict_name, '') as ximc,a.inside_number as jxmc,a.out_number as jxno,
               IFNULL(substr(a.inside_code, 1, 13), '') as njtm,'' as njtm2,
               case when a.out_code is null then ''
                    when length(a.out_code)>13 then left(a.out_code,13) else a.out_code end as wjtm,
               '' as beiz,'' as installambient,
               case a.type when 'inside' 	then '更换内机'
                           when 'out' 	then '更换外机'
                           else '安装整机'	end as aznr,
               '' as zjia, 0 as jcguan, '' kqkg,'' as gkzy,'' as yccxqk,a.worker_mobile as shji,a.worker_name as czren,a.first_time as czsj,
               a.operator_websit_id as czwd,
               if(a.first_time is null,a.update_time,a.first_time) as dqjdsj,
               if(a.first_time is null,a.update_time,a.first_time) as zjczsj,
               if(a.first_time is null,a.update_time,a.first_time) as cjdt,
               a.worker_name as azren,
               case a.source when 'MOBILE' then 2 else 1 end as dnorsj,a.settle_websit_id as jsdwxtbh,
               if(a.first_time is null,a.update_time,a.first_time) as scazsj,
               a.settle_amount as azfy,a.settle_amount as jsfy,
               IFNULL(a.inside_password, '') as kjmm, if(a.inside_password != '', 1, 8) as kjmmbs,
               if(length(a.gps_address)>140,left(a.gps_address,140),a.gps_address) as sjcjgps,
               if(a.first_time=0,a.update_time,a.first_time) as sjcjsj,'' as kjmm2,
               g.bracket as zjia,g.pipe as jcguan,g.swith_flag as kqkg,g.high_altitude as gkzy,g.hole as yccxqk,
               a.websit_id as zjczwdxtbh,a.first_time as wcsj,
               a.lat as sjcjjd,a.lng as sjcjwd,CONCAT(a.lat,',',a.lng) as sjcjjwdu
        from order_install_detail a
                 left join order_product b on b.order_base_id = a.order_base_id and a.order_product_id=b.id
                 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 sys_dict_ref d on d.dict_code=a.small_id and d.brand_id = #{request.brandId} and d.dict_type='SMALL_TYPE'
                 left join sys_dict_ref e on e.dict_code=a.series_id and e.brand_id = #{request.brandId} and e.dict_type='SERIES'
                 left join order_install_detail_fee g on g.order_base_id = a.order_base_id and g.order_detail_id=a.id
        where a.order_base_id = #{request.orderNo} and a.status in( '1' , '2') and a.id = #{request.id}
    </select>

    <select id="getSyOrderInstallUploadCj" parameterType="com.zfire.jiasm.syncdata.parameter.InstallDetail" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxSyktUpload">
        select 44 as syn_status,a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_id,a.pgwcmxid,'guangfo' as created_by,
               a.create_time as created_date,'guangfo' as last_modified_by,a.update_time as last_modified_date,b.pgmxid,a.pgguid,
               c.ref_dict_code as spid,c.ref_dict_name as spmc,d.ref_dict_code as xlid,d.ref_dict_name as xlmc,
               e.ref_dict_code as xiid,IFNULL(e.ref_dict_name, '') as ximc,a.inside_number as jxmc,a.out_number as jxno,
               IFNULL(substr(a.inside_code, 1, 13), '') as njtm,'' as njtm2,
               case when a.out_code is null then ''
                    when length(a.out_code)>13 then left(a.out_code,13) else a.out_code end as wjtm,
               '' as beiz,'' as installambient,
               case a.type when 'inside' 	then '更换内机'
                           when 'out' 	then '更换外机'
                           else '安装整机'	end as aznr,
               '' as zjia, 0 as jcguan, '' kqkg,'' as gkzy,'' as yccxqk,a.worker_mobile as shji,a.worker_name as czren,a.first_time as czsj,
               a.operator_websit_id as czwd,
               if(a.first_time is null,a.update_time,a.first_time) as dqjdsj,
               if(a.first_time is null,a.update_time,a.first_time) as zjczsj,
               if(a.first_time is null,a.update_time,a.first_time) as cjdt,
               a.worker_name as azren,
               case a.source when 'MOBILE' then 2 else 1 end as dnorsj,a.settle_websit_id as jsdwxtbh,
               if(a.first_time is null,a.update_time,a.first_time) as scazsj,
               a.settle_amount as azfy,a.settle_amount as jsfy,
               IFNULL(a.inside_password, '') as kjmm, if(a.inside_password != '', 1, 8) as kjmmbs,
               if(length(a.gps_address)>140,left(a.gps_address,140),a.gps_address) as sjcjgps,
               if(a.first_time=0,a.update_time,a.first_time) as sjcjsj,
               g.bracket as zjia,g.pipe as jcguan,g.swith_flag as kqkg,g.high_altitude as gkzy,g.hole as yccxqk,
               a.websit_id as zjczwdxtbh,a.first_time as wcsj,
               a.lat as sjcjjd,a.lng as sjcjwd,CONCAT(a.lat,',',a.lng) as sjcjjwdu
        from order_install_detail a
                 left join order_product b on b.order_base_id = a.order_base_id and a.order_product_id=b.id
                 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 sys_dict_ref d on d.dict_code=a.small_id and d.brand_id = #{request.brandId} and d.dict_type='SMALL_TYPE'
                 left join sys_dict_ref e on e.dict_code=a.series_id and e.brand_id = #{request.brandId} and e.dict_type='SERIES'
                 left join order_install_detail_fee g on g.order_base_id = a.order_base_id and g.order_detail_id=a.id
        where a.order_base_id = #{request.orderNo} and a.status in( '1' , '2') and a.id = #{request.id}
    </select>

    <select id="getOtherOrderInstallUploadCj" parameterType="com.zfire.jiasm.syncdata.parameter.InstallDetail" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxQitaUpload">
        select 44 as syn_status,a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_id,a.pgwcmxid,'guangfo' as created_by,
               a.create_time as created_date,'guangfo' as last_modified_by,a.update_time as last_modified_date,b.pgmxid,a.pgguid,
               c.ref_dict_code as spid,c.ref_dict_name as spmc,d.ref_dict_code as xlid,d.ref_dict_name as xlmc,
               e.ref_dict_code as xiid,IFNULL(e.ref_dict_name, '') as ximc,a.inside_number as jxmc,a.out_number as jxno,
               IFNULL(substr(a.inside_code, 1, 13), '') as njtm,'' as njtm2,
               case when a.out_code is null then ''
                    when length(a.out_code)>13 then left(a.out_code,13) else a.out_code end as wjtm,
               '' as beiz,'' as installambient,
               case a.type when 'inside' 	then '更换内机'
                           when 'out' 	then '更换外机'
                           else '安装整机'	end as aznr,
               '' as zjia, 0 as jcguan, '' kqkg,'' as gkzy,'' as yccxqk,a.worker_mobile as shji,a.worker_name as czren,a.first_time as czsj,
               a.operator_websit_id as czwd,
               if(a.first_time is null,a.update_time,a.first_time) as dqjdsj,
               if(a.first_time is null,a.update_time,a.first_time) as zjczsj,
               if(a.first_time is null,a.update_time,a.first_time) as cjdt,
               a.worker_name as azren,
               case a.source when 'MOBILE' then 2 else 1 end as dnorsj,a.settle_websit_id as jsdwxtbh,
               if(a.first_time is null,a.update_time,a.first_time) as scazsj,
               a.settle_amount as azfy,a.settle_amount as jsfy,
               IFNULL(a.inside_password, '') as kjmm, if(a.inside_password != '', 1, 8) as kjmmbs,
               if(length(a.gps_address)>140,left(a.gps_address,140),a.gps_address) as sjcjgps,
               if(a.first_time=0,a.update_time,a.first_time) as sjcjsj,'' as kjmm2,
               g.bracket as zjia,g.pipe as jcguan,g.swith_flag as kqkg,g.high_altitude as gkzy,g.hole as yccxqk,
               a.websit_id as zjczwdxtbh,a.first_time as wcsj,
               a.lat as sjcjjd,a.lng as sjcjwd,CONCAT(a.lat,',',a.lng) as sjcjjwdu
        from order_install_detail a
                 left join order_product b on b.order_base_id = a.order_base_id and a.order_product_id=b.id
                 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 sys_dict_ref d on d.dict_code=a.small_id and d.brand_id = #{request.brandId} and d.dict_type='SMALL_TYPE'
                 left join sys_dict_ref e on e.dict_code=a.series_id and e.brand_id = #{request.brandId} and e.dict_type='SERIES'
                 left join order_install_detail_fee g on g.order_base_id = a.order_base_id and g.order_detail_id=a.id
        where a.order_base_id = #{request.orderNo} and a.status in( '1' , '2') and a.id = #{request.id}
    </select>


    <update id="installUpdatePgguid" parameterType="com.zfire.jiasm.syncdata.parameter.InstallDetail">
        update order_install_detail set pgguid = #{request.pgguId}
        where order_base_id = #{request.orderNo}
          and (pgguid is null or pgguid = '' or pgguid = '0')
    </update>

</mapper>