<?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.fjhx.victoriatourist.mapper.abnormal.AbnormalInfoMapper">
    <select id="getPage" resultType="com.fjhx.victoriatourist.entity.abnormal.vo.AbnormalInfoVo">
        select
            ai.id,
            ai.type,
            ai.link_id,
            ai.link_code,
            ai.title,
            ai.status,
            ai.handle_user,
            ai.handle_time,
            ai.remark,
            ai.create_user,
            ai.create_time,
            ai.update_user,
            ai.update_time,
            ai.purchase_id,
            li.code as logisticsCode
            <if test="businessType eq 10 or businessType eq 50">
                ,p.create_user purchaseUserId
            </if>
        from abnormal_info ai
                <!-- 到货质检 待入库 来源 -->
                <if test="businessType eq 10 or businessType eq 50">
                        left JOIN bytesailing_purchase.purchase p ON ai.purchase_id = p.id
                        LEFT JOIN bytesailing_purchase.purchase_detail pd ON pd.purchase_id = p.id
                        LEFT JOIN bytesailing_item.product_info pi ON pd.bussiness_id = pi.id
                </if>
                <!-- 京东订单出库 调仓来源 -->
                <if test="businessType eq 20 or businessType eq 30">
                        left JOIN stock_transfer st ON ai.link_id = st.id
                        left JOIN stock_transfer_details std ON std.stock_transfer_id = st.id
                        LEFT JOIN bytesailing_item.product_info pi ON std.product_id = pi.id
                </if>
                <!-- 到货异常来源 -->
                <if test="businessType eq 40">
                        left JOIN bytesailing_purchase.arrival arr ON ai.link_id = arr.id and arr.del_flag = 0
                        left JOIN bytesailing_purchase.arrival_detail arrd ON arrd.arrival_id = arr.id and arr.del_flag = 0
                        LEFT JOIN bytesailing_item.product_info pi ON arrd.bussiness_id = pi.id
                </if>
                LEFT JOIN bytesailing_base.sys_dept de ON CAST(json_unquote(pi.victoriatourist_json -> '$.deptId') AS UNSIGNED) = de.dept_id
                left join logistics_infos li on ai.logistics_infos_id = li.id
            ${ew.customSqlSegment}
    </select>

</mapper>
