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

    <!-- 查询商品换货单商品统计分页列表数据 -->
    <select id="selectFormPage" resultType="com.hys.app.model.erp.vo.ChangeFormStatistics" useCache="false">
        select cf.sn,cf.change_time,cfp.* from es_change_form_product cfp left join es_change_form cf on cfp.change_id = cf.id
        <where>
            cfp.id is not null
            <if test="param.sn != null and param.sn != ''">
                and cf.sn like concat('%',#{param.sn},'%')
            </if>
            <if test="param.deptId != null and param.deptId != 0">
                and cf.dept_id = #{param.deptId}
            </if>
            <if test="param.warehouseId != null and param.warehouseId != 0">
                and cf.warehouse_id = #{param.warehouseId}
            </if>
            <if test="param.categoryId != null and param.categoryId != 0">
                and cfp.category_id = #{param.categoryId}
            </if>
            <if test="param.productName != null and param.productName != ''">
                and cfp.product_name like concat('%',#{param.productName},'%')
            </if>
            <if test="param.type != null">
                and cfp.`type` = #{param.type}
            </if>
            <if test="param.startTime != null and param.startTime != 0">
                and cf.change_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != 0">
                and cf.change_time &lt;= #{param.endTime}
            </if>
        </where>
        order by cf.create_time desc
    </select>

    <!-- 查询换货单商品统计信息集合 -->
    <select id="selectFormList" resultType="com.hys.app.model.erp.vo.ChangeFormStatistics" useCache="false">
        select cf.sn,cf.change_time,cfp.* from es_change_form_product cfp left join es_change_form cf on cfp.change_id = cf.id
        <where>
            cfp.id is not null
            <if test="param.sn != null and param.sn != ''">
                and cf.sn like concat('%',#{param.sn},'%')
            </if>
            <if test="param.deptId != null and param.deptId != 0">
                and cf.dept_id = #{param.deptId}
            </if>
            <if test="param.warehouseId != null and param.warehouseId != 0">
                and cf.warehouse_id = #{param.warehouseId}
            </if>
            <if test="param.categoryId != null and param.categoryId != 0">
                and cfp.category_id = #{param.categoryId}
            </if>
            <if test="param.productName != null and param.productName != ''">
                and cfp.product_name like concat('%',#{param.productName},'%')
            </if>
            <if test="param.type != null">
                and cfp.`type` = #{param.type}
            </if>
            <if test="param.startTime != null and param.startTime != 0">
                and cf.change_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != 0">
                and cf.change_time &lt;= #{param.endTime}
            </if>
        </where>
        order by cf.create_time desc
    </select>
</mapper>