<?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.zbf.system.mapper.SafetyStockMapper">

    <resultMap type="com.zbf.system.domain.SafetyStockVO" id="SafetyStockVO">
        <result property="storageId" column="storage_id"/>
        <result property="storageName" column="storage_name"/>
        <result property="goodsId" column="goods_id"/>
        <result property="goodsName" column="goods_name"/>
        <result property="shelvesNum" column="shelves_num"/>
        <result property="warnUp" column="warn_up"/>
        <result property="warnDown" column="warn_down"/>
    </resultMap>


    <select id="selectList" parameterType="com.zbf.system.domain.SafetyStockVO" resultMap="SafetyStockVO">
        SELECT
        t_mi_stock.storage_id,
        t_mi_stock.goods_id,
        sum( t_mi_stock.shelves_num ) shelves_num,
        max( t_base_goods.goods_name ) goods_name,
        max( t_base_goods.warn_up ) warn_up,
        max( t_base_goods.warn_down ) warn_down,
        max( t_base_storage.storage_name ) storage_name
        FROM
        t_mi_stock left join
        t_base_goods
        on
        t_mi_stock.goods_id = t_base_goods.goods_id
        left join
        t_base_storage
        on t_mi_stock.storage_id=t_base_storage.storage_id
        <where>
            <if test="storageId != null  and storageId != ''">and t_mi_stock.storage_id = #{storageId}</if>
            <if test="storageName != null  and storageName != ''">and t_base_storage.storage_name like concat('%',
                #{storageName},'%')
            </if>
            <if test="goodsId != null  and goodsId != ''">and t_mi_stock.goods_id = #{goodsId}</if>
            <if test="goodsName != null  and goodsName != ''">and t_base_goods.goods_name like concat('%',
                #{goodsName},'%')
            </if>
        </where>
        GROUP BY
        t_mi_stock.storage_id,
        t_mi_stock.goods_id
    </select>
</mapper>
