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

    <!-- 查询订单退货统计分页列表数据 -->
    <select id="selectOrderReturnPage" resultType="com.hys.app.model.erp.vo.OrderReturnStatistics" useCache="false">
        select eor.dept_name,eor.warehouse_name,eor.distribution_name,eor.sn,eor.order_sn,eor.return_time,eori.* from erp_order_return_item eori
        left join erp_order_return eor on eori.order_return_id = eor.id
        <where>
            eori.id is not null
            <if test="param.sn != null and param.sn != ''">
                and eor.sn like concat('%',#{param.sn},'%')
            </if>
            <if test="param.deptId != null and param.deptId != 0">
                and eor.dept_id = #{param.deptId}
            </if>
            <if test="param.warehouseId != null and param.warehouseId != 0">
                and eor.warehouse_id = #{param.warehouseId}
            </if>
            <if test="param.categoryId != null and param.categoryId != 0">
                and eori.category_id = #{param.categoryId}
            </if>
            <if test="param.productName != null and param.productName != ''">
                and eori.product_name like concat('%',#{param.productName},'%')
            </if>
            <if test="param.distributionName != null and param.distributionName != ''">
                and eor.distribution_name like concat('%',#{param.distributionName},'%')
            </if>
            <if test="param.startTime != null and param.startTime != 0">
                and eor.return_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != 0">
                and eor.return_time &lt;= #{param.endTime}
            </if>
        </where>
        order by eor.create_time desc
    </select>

    <!-- 导出订单退货统计列表 -->
    <select id="selectOrderReturnList" resultType="com.hys.app.model.erp.vo.OrderReturnStatistics" useCache="false">
        select eor.dept_name,eor.warehouse_name,eor.distribution_name,eor.sn,eor.order_sn,eor.return_time,eori.* from erp_order_return_item eori
        left join erp_order_return eor on eori.order_return_id = eor.id
        <where>
            eori.id is not null
            <if test="param.sn != null and param.sn != ''">
                and eor.sn like concat('%',#{param.sn},'%')
            </if>
            <if test="param.deptId != null and param.deptId != 0">
                and eor.dept_id = #{param.deptId}
            </if>
            <if test="param.warehouseId != null and param.warehouseId != 0">
                and eor.warehouse_id = #{param.warehouseId}
            </if>
            <if test="param.categoryId != null and param.categoryId != 0">
                and eori.category_id = #{param.categoryId}
            </if>
            <if test="param.productName != null and param.productName != ''">
                and eori.product_name like concat('%',#{param.productName},'%')
            </if>
            <if test="param.distributionName != null and param.distributionName != ''">
                and eor.distribution_name like concat('%',#{param.distributionName},'%')
            </if>
            <if test="param.startTime != null and param.startTime != 0">
                and eor.return_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != 0">
                and eor.return_time &lt;= #{param.endTime}
            </if>
        </where>
        order by eor.create_time desc
    </select>
    <select id="getAllNotClosedReturn" resultType="com.hys.app.model.erp.dos.OrderReturnDO">
        SELECT * FROM erp_order_return WHERE status = 'SALE_AFTER_ING' AND ( create_time + 1296000 )  &lt;  UNIX_TIMESTAMP()
    </select>
</mapper>