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

    <!-- 查询库存报损单商品统计分页列表数据 -->
    <select id="selectReportPage" resultType="com.hys.app.model.erp.vo.StockDamageReportStatistics" useCache="false">
        select sdr.sn,sdr.report_time,sdr.damage_type_key,sdrp.* from es_stock_damage_report_product sdrp left join es_stock_damage_report sdr on sdrp.report_id = sdr.id
        <where>
            sdrp.id is not null
            <if test="param.sn != null and param.sn != ''">
                and sdr.sn like concat('%',#{param.sn},'%')
            </if>
            <if test="param.deptId != null and param.deptId != 0">
                and sdr.dept_id = #{param.deptId}
            </if>
            <if test="param.warehouseId != null and param.warehouseId != 0">
                and sdr.warehouse_id = #{param.warehouseId}
            </if>
            <if test="param.categoryId != null and param.categoryId != 0">
                and sdrp.category_id = #{param.categoryId}
            </if>
            <if test="param.productName != null and param.productName != ''">
                and sdrp.product_name like concat('%',#{param.productName},'%')
            </if>
            <if test="param.damageType != null and param.damageType != ''">
                and sdr.damage_type = #{param.damageType}
            </if>
            <if test="param.startTime != null and param.startTime != 0">
                and sdr.report_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != 0">
                and sdr.report_time &lt;= #{param.endTime}
            </if>
            <if test="param.productSn != null and param.productSn != ''">
                and sdrp.product_sn = #{param.productSn}
            </if>
        </where>
        order by sdr.create_time desc
    </select>

    <!-- 查询库存报损单商品统计信息集合 -->
    <select id="selectReportList" resultType="com.hys.app.model.erp.vo.StockDamageReportStatistics" useCache="false">
        select sdr.sn,sdr.report_time,sdr.damage_type_key,sdrp.* from es_stock_damage_report_product sdrp left join es_stock_damage_report sdr on sdrp.report_id = sdr.id
        <where>
            sdrp.id is not null
            <if test="param.sn != null and param.sn != ''">
                and sdr.sn like concat('%',#{param.sn},'%')
            </if>
            <if test="param.deptId != null and param.deptId != 0">
                and sdr.dept_id = #{param.deptId}
            </if>
            <if test="param.warehouseId != null and param.warehouseId != 0">
                and sdr.warehouse_id = #{param.warehouseId}
            </if>
            <if test="param.categoryId != null and param.categoryId != 0">
                and sdrp.category_id = #{param.categoryId}
            </if>
            <if test="param.productName != null and param.productName != ''">
                and sdrp.product_name like concat('%',#{param.productName},'%')
            </if>
            <if test="param.damageType != null and param.damageType != ''">
                and sdr.damage_type = #{param.damageType}
            </if>
            <if test="param.startTime != null and param.startTime != 0">
                and sdr.report_time &gt;= #{param.startTime}
            </if>
            <if test="param.endTime != null and param.endTime != 0">
                and sdr.report_time &lt;= #{param.endTime}
            </if>
            <if test="param.productSn != null and param.productSn != ''">
                and sdrp.product_sn = #{param.productSn}
            </if>
        </where>
        order by sdr.create_time desc
    </select>
</mapper>