<?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.stock.StockJournalMapper">

    <select id="getPage" resultType="com.fjhx.entity.stock.StockJournal">
        SELECT
            t1.id,
            t1.type,
            t1.details_type,
            t1.goods_id,
            t1.warehouse_id,
            t1.change_quantity,
            t1.actual_quantity,
            t1.is_in_stock,
            t1.remarks,
            t1.create_user,
            t1.create_time,
            t2.`type` goodsType,
            t2.`name` goodsName,
            t2.`unit` goodsUnit,
            t3.logistics_info_code,
            t4.`name` warehouseName
        FROM
            stock_journal t1
            LEFT JOIN product_info t2 ON t1.goods_id = t2.id
            LEFT JOIN logistics_details t3 ON t1.business_id = t3.id
            LEFT JOIN warehouse t4 on t1.warehouse_id = t4.id
        ${ew.customSqlSegment}
    </select>

    <select id="getManualOutPage" resultType="java.util.Map">
        select sj.id,
               sj.change_quantity,
               sj.create_user,
               sj.create_time,
               pi.name,
               pi.code,
               pi.unit,
               pi.specs
        from stock_journal sj
                 left join product_info pi on sj.goods_id = pi.id
                 left join warehouse w on sj.warehouse_id = w.id
            ${ew.customSqlSegment}
    </select>

    <!-- 手动入库列表 -->
    <select id="getManualInStockPage" resultType="com.fjhx.entity.stock.StockJournal">
        SELECT
            t1.id,
            t1.`code`,
            t1.change_quantity,
            t1.create_user,
            t1.create_time,
            t1.goods_id,
            t2.`code` goods_code,
            t2.`name` goods_name,
            t2.type goods_type,
            t2.specs goods_specs,
            t2.unit goods_unit,
            t1.warehouse_id,
            t3.`name` warehouse_name
        FROM
            stock_journal t1
            LEFT JOIN product_info t2 ON t1.goods_id = t2.id
            LEFT JOIN warehouse t3 ON t1.warehouse_id = t3.id
        ${ew.customSqlSegment}
    </select>

    <!-- 到货质检列表 -->
<!--    <select id="getArrivalQualityPage" resultType="com.fjhx.entity.stock.StockJournal">-->
<!--        SELECT t3.code-->
<!--        FROM stock_journal t1-->
<!--                 INNER JOIN logistics_details t2 ON t1.business_id = t2.id-->
<!--                 LEFT JOIN purchase t3 ON t2.purchase_id = t3.id-->
<!--                 LEFT JOIN supplier t4 ON t3.supplier_id = t4.id-->
<!--                 LEFT JOIN warehouse t5 ON t1.warehouse_id = t5.id-->
<!--            ${ew.customSqlSegment}-->
<!--    </select>-->

    <select id="inOutDocument" resultType="java.util.Map">
        select sj.code,
               w.name         warehouseName,
               sum(sj.amount) amount,
               sj.create_time,
               sj.create_user
        from stock_journal sj
                 left join warehouse w on sj.warehouse_id = w.id
            ${ew.customSqlSegment}
    </select>

</mapper>
