package com.ruoyi.web.sales.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.web.sales.domain.SalesOrderGoods;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

public interface SalesOrderGoodsMapper extends BaseMapper<SalesOrderGoods> {

    @Select({
            "<script>",
            "select sog.*, so.line_num, so.market_num, so.customer_num, so.customer_name, bm.variety, bm.variety_name, bm.goods_level ",
            "from sales_order_goods sog, sales_order so, base_material bm ",
            "where sog.order_num = so.order_num ",
            "  and sog.goods_num = bm.goods_num ",
            "  and sog.del_flag = '0' ",
            "  and so.del_flag = '0' ",
            "  and bm.del_flag = '0' ",
            "  and so.org_id = #{orgId} ",
            "  and sog.org_id = #{orgId} ",
            "  and bm.org_id = #{orgId} ",
            "  and so.sale_date = #{saleDate} ",
            "  <if test='lineNum != null and lineNum != \"\"'> and so.line_num = #{lineNum} </if>",
            "  <if test='marketNum != null and marketNum != \"\"'> and so.market_num = #{marketNum} </if>",
            "  <if test='customerNum != null and customerNum != \"\"'> and so.customer_num = #{customerNum} </if>",
            "order by so.id desc, sog.id asc",
            "</script>"
    })
    List<Map<String, Object>> listGoodsDetailByConditions(@Param("orgId") String orgId,
                                                          @Param("saleDate") String saleDate,
                                                          @Param("lineNum") String lineNum,
                                                          @Param("marketNum") String marketNum,
                                                          @Param("customerNum") String customerNum);
}
