<?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.hzs.report.report.mapper.WaresSalesVolumeMapper">

    <select id="queryList" resultType="com.hzs.report.report.vo.WaresSalesVolume">

        select oi.PK_WARES pkWares,min(bw.wares_code) waresCode, min(bw.wares_name) waresName, min(ac.CLASSIFY_NAME) classifyName ,
               min(so.ORDER_TYPE) orderType,min(bw.wares_price) waresPrice ,
               min(bw.wares_achieve) waresAchieve ,sum(oi.quantity) quantity ,sum(oi.price) price
        from  sa_order_items  oi
                  left join sa_order so on so.pk_id = oi.PK_ORDER
                  left join bd_wares bw on bw.pk_id = oi.PK_WARES
                  left join bd_area_classify ac on ac.pk_id = bw.PK_AREA_CLASSIFY
        where  oi.del_flag = 0 and so.del_flag = 0  and oi.pk_wares > 0 and bw.del_flag = 0 and ac.del_flag = 0 and so.ORDER_TYPE != 8
        <if test="waresCode != null and waresCode != ''">
            and bw.wares_code = #{waresCode}
        </if>
        <if test="waresName != null and waresName != ''">
            and bw.wares_name = #{waresName}
        </if>
        <if test="startDate != null">
            and oi.CREATION_TIME &gt;= #{startDate}
        </if>
        <if test="endDate != null">
            and oi.CREATION_TIME &lt;= #{endDate}
        </if>
        group by  oi.PK_WARES , so.order_type  , oi.PRICE
        order by oi.pk_wares desc



    </select>

    <select id="queryProductList" resultType="com.hzs.report.report.vo.WaresSalesVolumeProduct">

         select bp.PRODUCT_NAME productName,wd.QUANTITY productQuantity,bu.name unitName     from  BD_WARES_DETAIL wd
         left join bd_product bp on bp.pk_id = wd.PK_PRODUCT
          left join bd_unit bu on bu.pk_id = bp.UNIT
          where bu.del_flag = 0 and wd.del_flag = 0 and bp.del_flag = 0 and wd.pk_wares = #{pkWares}

    </select>

</mapper>
