<?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="vip.xiaonuo.biz.modular.bizinventory.mapper.BizInventoryMapper">

    <select id="getTotal" resultType="java.math.BigDecimal">
        select IFNULL(sum(inventory_weight),0) inventory_weight from biz_inventory
        ${ew.customSqlSegment}
    </select>

    <select id="getProductName" resultType="vip.xiaonuo.biz.modular.bizinventory.param.BizInventoryReport">
        SELECT
            a.product_name licensePlate,
            a.count carCount,
            ifnull( b.outWeight, 0 ) outWeight,
            ifnull( c.inWeight, 0 ) inWeight
        FROM
            ( SELECT product_name, count( 1 ) count FROM biz_inventory where delete_flag = 'NOT_DELETE'
            <if test="paramMap.beginTime!=null and paramMap.endTime!=null">
                and inventory_time between #{paramMap.beginTime} and #{paramMap.endTime}
            </if>
            GROUP BY product_name ) a
            LEFT JOIN ( SELECT product_name, ifnull( sum( inventory_weight ), 0 ) outWeight FROM biz_inventory WHERE inventory_type = '出库' and delete_flag = 'NOT_DELETE'
            <if test="paramMap.beginTime!=null and paramMap.endTime!=null">
                and inventory_time between #{paramMap.beginTime} and #{paramMap.endTime}
            </if>
            GROUP BY product_name ) b ON a.product_name = b.product_name
            LEFT JOIN ( SELECT product_name, ifnull( sum( inventory_weight ), 0 ) inWeight FROM biz_inventory WHERE inventory_type = '入库'  and delete_flag = 'NOT_DELETE'
            <if test="paramMap.beginTime!=null and paramMap.endTime!=null">
                and inventory_time between #{paramMap.beginTime} and #{paramMap.endTime}
            </if>
            GROUP BY product_name ) c ON a.product_name = c.product_name
    </select>

    <select id="getLicenseNumber" resultType="vip.xiaonuo.biz.modular.bizinventory.param.BizInventoryReport">
        SELECT
            a.license_number licensePlate,
            a.count carCount,
            ifnull( b.outWeight, 0 ) outWeight,
            ifnull( c.inWeight, 0 ) inWeight
        FROM
            ( SELECT license_number, count( 1 ) count FROM biz_inventory where delete_flag = 'NOT_DELETE'
            <if test="paramMap.beginTime!=null and paramMap.endTime!=null">
                and inventory_time between #{paramMap.beginTime} and #{paramMap.endTime}
            </if>
            GROUP BY license_number ) a
            LEFT JOIN ( SELECT license_number, ifnull( sum( inventory_weight ), 0 ) outWeight FROM biz_inventory WHERE inventory_type = '出库' and delete_flag = 'NOT_DELETE'
            <if test="paramMap.beginTime!=null and paramMap.endTime!=null">
                and inventory_time between #{paramMap.beginTime} and #{paramMap.endTime}
            </if>
            GROUP BY license_number ) b ON a.license_number = b.license_number
            LEFT JOIN ( SELECT license_number, ifnull( sum( inventory_weight ), 0 ) inWeight FROM biz_inventory WHERE inventory_type = '入库' and delete_flag = 'NOT_DELETE'
            <if test="paramMap.beginTime!=null and paramMap.endTime!=null">
                and inventory_time between #{paramMap.beginTime} and #{paramMap.endTime}
            </if>
            GROUP BY license_number ) c ON a.license_number = c.license_number
    </select>
</mapper>
