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

    <select id="getItfTblAssignMxUpload" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAssignMxUpload">
        select a.out_id as fa_order_repair_product_id,a.pgmxid,'guangfo' as created_by,
               a.create_time as created_date,'guangfo' as last_modified_by,a.update_time as last_modified_date,
               a.pgid,c.ref_dict_code as spid,c.ref_dict_name as spmc,d.ref_dict_code as xlid,d.ref_dict_name as xlmc,
               (case when e.ref_dict_code > 99999 then 0 else e.ref_dict_code end) as xiid,IFNULL(e.ref_dict_name, '') as ximc,
               f.product_id as jxid,IFNULL(f.name,'') as jxmc,IFNULL(f.jxid,'') as jxno,a.buy_time as gmsj,a.create_time as czsj,
               '' as gzwz,a.fault_reason as gzxx, a.create_by as czren,a.sale_websit as xsdw,
               a.sale_websit_mobile as xsdwdh,a.service_websit_mobile as fwdwdh,
               a.remark as beiz,'' as qqlyxh,'' as pinpai,a.price as fee,0 as xxfee,
               '' as hsqk,i.bug_obj_code as gzxxid,a.num as shul,0 as wxcount,0 as yblength
        from order_product 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 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 product f on f.jxid = a.product_id
                 left join repair_bug i on i.bug_id=a.fault_reason
        where a.id = #{request.id}
    </select>

    <select id="getItfTblAzAssignMxUpload" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar" resultType="com.zfire.jiasm.syncdata.plus.entity.ItfTblAzAssignMxUpload">
        select UNIX_TIMESTAMP(a.create_time) as fa_order_install_product_id,a.pgmxid,'guangfo' as created_by,a.pgguid,
               a.create_time as created_date,'guangfo' as last_modified_by,a.update_time as last_modified_date,
               c.ref_dict_code as spid,c.ref_dict_name as spmc,d.ref_dict_code as xlid,d.ref_dict_name as xlmc,
               (case when e.ref_dict_code > 99999 then 0 else e.ref_dict_code end) as xiid,IFNULL(e.ref_dict_name, '') as ximc,
               f.name as jxmc,f.jxid as jxno,a.create_time as czsj,a.price as jiage,
               a.num as shul,IFNULL(a.unit, '套') as danw,a.out_num as wjsl,a.inside_num as njsl,a.material_number as wldm
        from order_product 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 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 product f on f.jxid = a.product_id
        where a.id = #{request.id}
    </select>

    <update id="upPgguid" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar">
        update order_product
        set pgguid =  #{request.pgid}
        where order_base_id = #{request.orderNo} and (pgguid is null or pgguid = '' or pgguid = '0')
    </update>

    <update id="upPgmxid" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar">
        update order_product
        set pgmxid =  #{request.pgid}
        where order_base_id = #{request.orderNo} and id = #{request.id} and (pgmxid is null or pgmxid = '')
    </update>

    <update id="upPgid" parameterType="com.zfire.jiasm.syncdata.parameter.OrderPar">
        update order_product
        set pgid =  #{request.pgid}
        where order_base_id = #{request.orderNo} and (pgid is null or pgid = '')
    </update>

</mapper>
