<?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.StockTransferMapper">

    <!-- 查询库存调拨统计分页列表数据 -->
    <select id="selectStockTransferPage" resultType="com.hys.app.model.erp.vo.StockTransferStatistics" useCache="false">
        select st.sn,st.transfer_time,st.out_warehouse_name,st.in_warehouse_name,stp.* from erp_stock_transfer_product stp
        left join erp_stock_transfer st on stp.stock_transfer_id = st.id
        <where>
            stp.id is not null
            <if test="param.sn != null and param.sn != ''">
                and st.sn like concat('%',#{param.sn},'%')
            </if>
            <if test="param.outDeptId != null and param.outDeptId != 0">
                and st.out_dept_id = #{param.outDeptId}
            </if>
            <if test="param.inDeptId != null and param.inDeptId != 0">
                and st.in_dept_id = #{param.inDeptId}
            </if>
            <if test="param.outWarehouseId != null and param.outWarehouseId != 0">
                and st.out_warehouse_id = #{param.outWarehouseId}
            </if>
            <if test="param.inWarehouseId != null and param.inWarehouseId != 0">
                and st.in_warehouse_id = #{param.inWarehouseId}
            </if>
            <if test="param.categoryId != null and param.categoryId != 0">
                and stp.category_id = #{param.categoryId}
            </if>
            <if test="param.productName != null and param.productName != ''">
                and stp.product_name like concat('%',#{param.productName},'%')
            </if>
            <if test="param.startTime != null and param.startTime != 0">
                and st.transfer_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != 0">
                and st.transfer_time &lt;= #{param.endTime}
            </if>
        </where>
        order by st.create_time desc
    </select>

    <!-- 导出库存调拨统计列表 -->
    <select id="selectStockTransferList" resultType="com.hys.app.model.erp.vo.StockTransferStatistics" useCache="false">
        select st.sn,st.transfer_time,st.out_warehouse_name,st.in_warehouse_name,stp.* from erp_stock_transfer_product stp
        left join erp_stock_transfer st on stp.stock_transfer_id = st.id
        <where>
            stp.id is not null
            <if test="param.sn != null and param.sn != ''">
                and st.sn like concat('%',#{param.sn},'%')
            </if>
            <if test="param.outDeptId != null and param.outDeptId != 0">
                and st.out_dept_id = #{param.outDeptId}
            </if>
            <if test="param.inDeptId != null and param.inDeptId != 0">
                and st.in_dept_id = #{param.inDeptId}
            </if>
            <if test="param.outWarehouseId != null and param.outWarehouseId != 0">
                and st.out_warehouse_id = #{param.outWarehouseId}
            </if>
            <if test="param.inWarehouseId != null and param.inWarehouseId != 0">
                and st.in_warehouse_id = #{param.inWarehouseId}
            </if>
            <if test="param.categoryId != null and param.categoryId != 0">
                and stp.category_id = #{param.categoryId}
            </if>
            <if test="param.productName != null and param.productName != ''">
                and stp.product_name like concat('%',#{param.productName},'%')
            </if>
            <if test="param.startTime != null and param.startTime != 0">
                and st.transfer_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != 0">
                and st.transfer_time &lt;= #{param.endTime}
            </if>
        </where>
        order by st.create_time desc
    </select>
</mapper>