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

    <!-- 查询供应商退货统计分页列表数据 -->
    <select id="selectSupplierReturnPage" resultType="com.hys.app.model.erp.vo.SupplierReturnStatistics" useCache="false">
        select esr.dept_name,esr.warehouse_name,esr.supplier_name,esr.sn,esr.return_time,esrp.* from erp_supplier_return esr
        left join erp_supplier_return_item esrp on esr.id = esrp.supplier_return_id
        <where>
            esr.id is not null
            <if test="param.sn != null and param.sn != ''">
                and esr.sn like concat('%',#{param.sn},'%')
            </if>
            <if test="param.deptId != null and param.deptId != 0">
                and esr.dept_id = #{param.deptId}
            </if>
            <if test="param.warehouseId != null and param.warehouseId != 0">
                and esr.warehouse_id = #{param.warehouseId}
            </if>
            <if test="param.supplierId != null and param.supplierId != 0">
                and esr.supplier_id = #{param.supplierId}
            </if>
            <if test="param.categoryId != null and param.categoryId != 0">
                and esrp.category_id = #{param.categoryId}
            </if>
            <if test="param.productName != null and param.productName != ''">
                and esrp.product_name like concat('%',#{param.productName},'%')
            </if>
            <if test="param.supplierName != null and param.supplierName != ''">
                and esr.supplier_name like concat('%',#{param.supplierName},'%')
            </if>
            <if test="param.startTime != null and param.startTime != 0">
                and esr.return_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != 0">
                and esr.return_time &lt;= #{param.endTime}
            </if>
        </where>
        order by esr.create_time desc
    </select>

    <!-- 查询导出出库单统计列表 -->
    <select id="selectSupplierReturnList" resultType="com.hys.app.model.erp.vo.SupplierReturnStatistics" useCache="false">
        select esr.dept_name,esr.warehouse_name,esr.supplier_name,esr.sn,esr.return_time,esrp.* from erp_supplier_return esr
        left join erp_supplier_return_item esrp on esr.id = esrp.supplier_return_id
        <where>
            esr.id is not null
            <if test="param.sn != null and param.sn != ''">
                and esr.sn like concat('%',#{param.sn},'%')
            </if>
            <if test="param.deptId != null and param.deptId != 0">
                and esr.dept_id = #{param.deptId}
            </if>
            <if test="param.warehouseId != null and param.warehouseId != 0">
                and esr.warehouse_id = #{param.warehouseId}
            </if>
            <if test="param.supplierId != null and param.supplierId != 0">
                and esr.supplier_id = #{param.supplierId}
            </if>
            <if test="param.categoryId != null and param.categoryId != 0">
                and esrp.category_id = #{param.categoryId}
            </if>
            <if test="param.productName != null and param.productName != ''">
                and esrp.product_name like concat('%',#{param.productName},'%')
            </if>
            <if test="param.supplierName != null and param.supplierName != ''">
                and esr.supplier_name like concat('%',#{param.supplierName},'%')
            </if>
            <if test="param.startTime != null and param.startTime != 0">
                and esr.return_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != 0">
                and esr.return_time &lt;= #{param.endTime}
            </if>
        </where>
        order by esr.create_time desc
    </select>
</mapper>