<?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.wms.mapper.stock.StockJournalMapper">
    <select id="getPage" resultType="com.fjhx.wms.entity.stock.vo.StockJournalVo">
        SELECT
            sj.id,
            sj.type,
            sj.op_type,
            sj.code,
            sj.warehouse_id,
            w.NAME warehouseName,
            sj.create_user,
            sj.create_time,
            sj.update_user,
            sj.update_time
        FROM
            stock_journal sj
                JOIN warehouse w ON sj.warehouse_id = w.id
            ${ew.customSqlSegment}
    </select>
    <resultMap id="detail" type="com.fjhx.wms.entity.stock.vo.StockJournalVo">
        <id property="id" column="id"/>
        <result property="warehouseId" column="warehouse_id"/>
        <result property="warehouseName" column="warehouseName"/>
        <result property="type" column="type"/>
        <collection property="list" javaType="java.util.ArrayList" ofType="com.fjhx.wms.entity.stock.vo.StockVo">
            <id property="id" column="stockJournalDetailsId"/>
            <result property="productId" column="product_id"/>
            <result property="quantity" column="quantity"/>
        </collection>
    </resultMap>
    <select id="detail" resultMap="detail">
        SELECT
            sj.id,
            sj.type,
            sj.warehouse_id,
            w.`name` warehouseName,
            sjd.id stockJournalDetailsId,
            sjd.product_id,
            sjd.quantity
        FROM
            stock_journal sj
                JOIN warehouse w ON sj.warehouse_id = w.id
                JOIN stock_journal_details sjd ON sjd.stock_journal_id = sj.id
            ${ew.customSqlSegment}
    </select>

</mapper>
