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

    <select id="getId" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderDetailFile">
        select a.id,a.file_path,a.brand_file_index,a.order_detail_id,a.order_base_id,a.brand_file_path,a.fjguid
        from order_detail_file a, order_install_detail b
        where a.order_base_id = #{request.orderNo} and b.order_base_id = #{request.orderNo}
          and a.order_detail_id = b.id
          and b.id = #{request.id}
          and a.file_name != '销售-购机凭证'
          order by a.id
    </select>

    <select id="getIdRe" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderDetailFile">
        select id
        from order_detail_file
        where order_base_id = #{request.orderNo} and
            (file_path is null or file_path = '' or brand_file_path is null or brand_file_path = '')
    </select>

    <select id="getIdReT" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderDetailFile">
        select id,order_detail_id
        from order_detail_file
        where order_base_id = #{request.orderNo} and file_type = #{request.type}  and
            (file_path is null or file_path = '' or brand_file_path is null or brand_file_path = '') limit 1
    </select>

    <select id="getFileUpload" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxJyktFjUpload">
        select a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_append_id,b.pgguid,a.fjguid,
               'guangfo' as created_by,a.create_time as created_date,
               'guangfo' as last_modified_by,a.update_time as last_modified_date,
               a.out_id as fjindex,a.file_name as fjname,a.file_path as fjphonepath,a.file_remark as fjremark,
            a.out_id as fjsequence,a.brand_file_path as fjserverpath,
            a.pgwcmxid,a.create_time as reatetime,a.file_type as type
        from order_detail_file 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}
    </select>

    <select id="getFileUploadCJ" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxJyktFjUpload">
        select 44 as syn_status, a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_append_id,b.pgguid,a.fjguid,
               'guangfo' as created_by,a.create_time as created_date,
               'guangfo' as last_modified_by,a.update_time as last_modified_date,
            a.out_id as fjindex,a.file_name as fjname,a.file_path as fjphonepath,a.file_remark as fjremark,
            a.out_id as fjsequence,a.brand_file_path as fjserverpath,
            a.pgwcmxid,a.create_time as reatetime,a.file_type as type
        from order_detail_file 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}
    </select>

    <select id="getSyFileUpload" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxSyktFjUpload">
        select a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_append_id,b.pgguid,a.pgwcmxid,a.fjguid,
               'guangfo' as created_by,a.create_time as created_date,
               'guangfo' as last_modified_by,a.update_time as last_modified_date,
               a.out_id as fjindex,a.file_name as fjname,a.file_path as fjphonepath,a.file_remark as fjremark,
               a.out_id as fjsequence,a.brand_file_path as fjserverpath,
               a.create_time as reatetime,a.file_type as type
        from order_detail_file 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}
    </select>

    <select id="getOtherFileUpload" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxQitaFjUpload">
        select a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_append_id,b.pgguid,a.pgwcmxid,a.fjguid,
               'guangfo' as created_by,a.create_time as created_date,
               'guangfo' as last_modified_by,a.update_time as last_modified_date,
               a.out_id as fjindex,a.file_name as fjname,a.file_path as fjphonepath,a.file_remark as fjremark,
            a.out_id as fjsequence,a.brand_file_path as fjserverpath,
               a.create_time as reatetime,a.file_type as type
        from order_detail_file 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}
    </select>

    <select id="getItfTblWxjsFjJyktUpload" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblWxjsFjJyktUpload">
        select a.order_base_id as worker_order_no,a.out_id as fa_order_repair_annex_id,
               a.fjguid,'guangfo' as created_by,a.create_time as created_date,
               'guangfo' as last_modified_by,a.update_time as last_modified_date,
               b.brand_wxjsguid as wxjsguid,a.brand_file_path as wjlj,a.create_time as cjsj,
               a.file_name as tpms,a.file_path as wjnm,a.pgwcmxid as wxmxguid,
               b.wxjsmxguid as wxjsmxguid,a.repair_item_id as repairitemno,a.number as repairtroubleno
        from order_detail_file a
                 left join order_repair_detail b on a.order_base_id = b.order_base_id and b.id=a.order_detail_id
        where a.order_base_id =  #{request.orderNo} and a.id =  #{request.id}
    </select>


    <select id="getIdCj" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderDetailFile">
        select a.id,a.file_path,a.brand_file_index,a.order_detail_id,a.order_base_id,a.brand_file_path,a.fjguid
        from order_detail_file a, order_install_detail b
        where a.order_base_id = #{request.orderNo} and b.order_base_id = #{request.orderNo}
          and a.order_detail_id = b.id
          and b.id = #{request.id}
          and b.status in('1','2')
          and a.file_name != '销售-购机凭证'
        order by a.id
    </select>

    <select id="getFileUploadCj" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxJyktFjUpload">
        select 44 as syn_status,a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_append_id,b.pgguid,a.fjguid,
               'guangfo' as created_by,a.create_time as created_date,
               'guangfo' as last_modified_by,a.update_time as last_modified_date,
               a.out_id as fjindex,a.file_name as fjname,a.file_path as fjphonepath,a.file_remark as fjremark,
            a.out_id as fjsequence,a.brand_file_path as fjserverpath,
            a.pgwcmxid,a.create_time as reatetime,
            a.file_type as type
        from order_detail_file 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}
    </select>

    <select id="getSyFileUploadCj" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxSyktFjUpload">
        select 44 as syn_status,a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_append_id,b.pgguid,a.pgwcmxid,a.fjguid,
               'guangfo' as created_by,a.create_time as created_date,
               'guangfo' as last_modified_by,a.update_time as last_modified_date,
               a.out_id as fjindex,a.file_name as fjname,a.file_path as fjphonepath,a.file_remark as fjremark,
            a.out_id as fjsequence,a.brand_file_path as fjserverpath,
            a.create_time as reatetime,a.file_type as type
        from order_detail_file 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}
    </select>

    <select id="getOtherFileUploadCj" parameterType="com.zfire.jiasm.syncdata.parameter.InstallCJDetailFile" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxQitaFjUpload">
        select 44 as syn_status,a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_append_id,b.pgguid,a.pgwcmxid,a.fjguid,
               'guangfo' as created_by,a.create_time as created_date,
               'guangfo' as last_modified_by,a.update_time as last_modified_date,
               a.out_id as fjindex,a.file_name as fjname,a.file_path as fjphonepath,a.file_remark as fjremark,
            a.out_id as fjsequence,a.brand_file_path as fjserverpath,
            a.create_time as reatetime,a.file_type as type
        from order_detail_file 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}
    </select>



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



</mapper>