<?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.hys.app.mapper.erp.WarehouseOutItemMapper">

    <!-- 查询出库单统计分页列表数据 -->
    <select id="queryList" resultType="com.hys.app.model.erp.vo.WarehouseOutItemV1" useCache="false">
        select
            item.id,
            o.sn as sn,h.name as warehouse_name,
            g.sn as goods_sn,g.name as goods_name,
            g.goods_style as goods_style,
            p.num as qty,
            c.name as goods_category
        from erp_warehouse_out_item as item
        left join erp_warehouse_out as o on item.warehouse_out_id=o.id
        left join erp_warehouse as h on o.warehouse_id=h.id
        left join erp_goods as g on g.id=item.goods_id
        left join es_category as c on c.category_id=g.category_id
        left join erp_product_stock as p  on p.goods_id=g.id and p.warehouse_id=h.id
        <where>
            <if test="request.startTime != null and request.startTime>0">
                and o.create_time <![CDATA[ >= ]]> #{request.startTime}
            </if>
            <if test="request.endTime != null and request.endTime>0">
                and o.create_time<![CDATA[ <= ]]> #{request.endTime}
            </if>

            <if test="request.warehouseId != null and request.warehouseId>0">
                and o.warehouse_id =#{request.warehouseId}
            </if>

        </where>
        order by item.id desc
        limit ${(request.pageNo- 1) * request.pageSize} , #{request.pageSize}
    </select>


    <select id="selectCount" resultType="Long" useCache="false">
        select
        count(item.id)
        from erp_warehouse_out_item as item
        left join erp_warehouse_out as o on item.warehouse_out_id=o.id
        left join erp_warehouse as h on o.warehouse_id=h.id
        left join erp_goods as g on g.id=item.goods_id
        left join es_category as c on c.category_id=g.category_id
        left join erp_product_stock as p  on p.goods_id=g.id and p.warehouse_id=h.id
        <where>
            <if test="request.startTime != null and request.startTime>0">
                and o.create_time <![CDATA[ >= ]]> #{request.startTime}
            </if>
            <if test="request.endTime != null and request.endTime>0">
                and o.create_time<![CDATA[ <= ]]> #{request.endTime}
            </if>

            <if test="request.warehouseId != null and request.warehouseId>0">
                and o.warehouse_id =#{request.warehouseId}
            </if>
        </where>
    </select>

</mapper>