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

    <select id="getId" parameterType="com.zfire.jiasm.syncdata.parameter.InstalDetailCode" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderInstallDetailCode">
        select a.id,a.path,a.gree_image_id,a.tmguid,a.order_base_id,a.order_detail_id
        from order_install_detail_code 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}
    </select>

    <select id="getJyCode" parameterType="com.zfire.jiasm.syncdata.parameter.InstalDetailCode" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxJyktTmmxUpload">
        select order_base_id as worker_order_no,out_id as fa_order_install_detail_code_id,tmguid, 'guangfo' as created_by,
               create_time as created_date,'guangfo' as last_modified_by,update_time as last_modified_date,pgwcmxid,
               code as xjqtm,type as tmlx,gree_image_id as scwj,gree_image_id as scid,password as kjmm,create_time as cjsj,
               password2 as kjmm2, gree_image_id as imgpath
        from order_install_detail_code
            where order_base_id = #{request.orderNo} and id = #{request.id}
    </select>

    <select id="getSyCode" parameterType="com.zfire.jiasm.syncdata.parameter.InstalDetailCode" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxSyktTmmxLsUpload">
        select order_base_id as worker_order_no,out_id as fa_order_install_detail_code_id,tmguid,'guangfo' as created_by,
               create_time as created_date,'guangfo' as last_modified_by,update_time as last_modified_date,pgwcmxid,
               code as jqtm,
               case when type = '1' then 2 else 1 end as tmlx,
               gree_image_id as scwj,gree_image_id as scid,password as kjmm,create_time	as cjsj,
               password2 as kjmm2,gree_image_id as imgpath
        from order_install_detail_code
        where order_base_id = #{request.orderNo} and id = #{request.id}
    </select>

    <select id="getOtherCode" parameterType="com.zfire.jiasm.syncdata.parameter.InstalDetailCode" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxQitaTmmxUpload">
        select order_base_id as worker_order_no,out_id as fa_order_install_detail_code_id,tmguid,'guangfo' as created_by,
               create_time as created_date,'guangfo' as last_modified_by,update_time as last_modified_date,
               pgwcmxid as pgwcmxid,code as jqtm,type as tmlx,gree_image_id as scwj,gree_image_id as scid,password as kjmm,
               create_time as cjsj,password2 as kjmm2,gree_image_id
        from order_install_detail_code
        where order_base_id = #{request.orderNo} and id = #{request.id}
    </select>

    <select id="getIdCj" parameterType="com.zfire.jiasm.syncdata.parameter.InstalDetailCode" resultType="com.zfire.jiasm.syncdata.plus.entity.OrderInstallDetailCode">
        select a.id,a.path,a.gree_image_id,a.tmguid,a.order_base_id,a.order_detail_id,a.status
        from order_install_detail_code 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')
    </select>

    <select id="getSyCodeCj" parameterType="com.zfire.jiasm.syncdata.parameter.InstalDetailCode" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzWgmxSyktTmmxLsUpload">
        select a.order_base_id as worker_order_no,a.out_id as fa_order_install_detail_code_id,a.tmguid,'guangfo' as created_by,
               a.create_time as created_date,'guangfo' as last_modified_by,a.update_time as last_modified_date,b.pgwcmxid,
               a.code as jqtm,case when a.type = '1' then 2 else 1 end as tmlx,
               a.gree_image_id as scwj,a.gree_image_id as scid,a.password as kjmm,a.create_time	as cjsj,
               a.password2 as kjmm2,a.gree_image_id as imgpath
        from order_install_detail_code a left join order_install_detail b on a.order_base_id=b.order_base_id and a.order_detail_id=b.id
        where a.order_base_id = #{request.orderNo} and a.id = #{request.id}
    </select>



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

    <update id="updateCodeOutId" parameterType="com.zfire.jiasm.syncdata.parameter.InstalDetailCode">
        update order_install_detail_code a,order_install_detail b set a.out_id=b.out_id
        where a.order_base_id=b.order_base_id
            and a.order_detail_id=b.id
            and a.order_base_id =  #{request.orderNo}
    </update>

    <update id="updateCodeIncodePath" parameterType="com.zfire.jiasm.syncdata.parameter.InstalDetailCode">
        update order_install_detail_code a,order_detail_file b
               set a.path=b.file_path,a.gree_image_id=b.brand_file_path
        where a.order_base_id=b.order_base_id
          and a.order_detail_id=b.order_detail_id
          and a.type=b.file_type
          and a.type=1
          and a.status=1
          and a.order_base_id  #{request.orderNo}
    </update>

    <update id="updateCodeOutcodePath" parameterType="com.zfire.jiasm.syncdata.parameter.InstalDetailCode">
        update order_install_detail_code a,order_detail_file b set a.path=b.file_path,a.gree_image_id=b.brand_file_path
        where a.order_base_id=b.order_base_id
          and a.order_detail_id=b.order_detail_id
          and a.type=b.file_type-1
          and a.type=2
          and a.status=1
          and a.order_base_id =  #{request.orderNo}
    </update>



</mapper>