<?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.*,
        li.code as logisticsCode,
        p.create_user purchaseUserId
        FROM
        (
        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,
        ai.logistics_infos_id,
        IFNULL( sum( ad.refund_amount ), 0 ) AS refundAmount
        FROM
        abnormal_info ai
        LEFT JOIN abnormal_details ad ON ad.abnormal_info_id = ai.id
        GROUP BY
        ai.id
        )ai
        left join bytesailing_purchase.purchase p on ai.purchase_id = p.id
        LEFT JOIN bytesailing_base.sys_dept de ON p.team_id = de.dept_id
        left join logistics_infos li on ai.logistics_infos_id = li.id
            ${ew.customSqlSegment}
    </select>

</mapper>
