<?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.mapper.apply.ApplyPurchaseMapper">

    <select id="getPage" resultType="com.fjhx.entity.apply.ApplyPurchase">
        SELECT
            t1.id,
            t1.`code`,
            t1.purchase_id,
            t1.purchase_code,
            t1.goods_id,
            t1.quantity,
            t1.unit_price,
            t1.plan_arrival_time,
            t1.receipt_warehouse_id,
            t1.`status`,
            t1.cause,
            t1.create_user,
            t1.create_time,
            t2.`type` goodsType,
            t2.`code` goodsCode,
            t2.`name` goodsName,
            t2.unit goodsUnit,
            t3.`name` warehouseName
        FROM
            apply_purchase t1
            LEFT JOIN product_info t2 ON t1.goods_id = t2.id
            LEFT JOIN warehouse t3 ON t1.receipt_warehouse_id = t3.id
        ${ew.customSqlSegment}
    </select>

    <select id="applyInPage" resultType="java.util.LinkedHashMap">
        select ap.id,
               ap.code,
               pi.code                             productCode,
               pi.name                             productName,
               pi.type                             productType,
               ap.quantity,
               ap.receipt_quantity,
               (ap.quantity - ap.receipt_quantity) not_receipt_quantity,
               w.name                              warehouse_name,
               receipt_time,
               ap.create_user,
               ap.status
        from apply_purchase ap
                 left join product_info pi on ap.goods_id = pi.id
                 LEFT JOIN warehouse w ON ap.receipt_warehouse_id = w.id
            ${ew.customSqlSegment}
    </select>

</mapper>
