package com.fs.oms.mapper;

import com.fs.oms.domain.OmsProduct;
import com.fs.oms.vo.OmsProductExportVO;
import com.fs.oms.vo.OmsProductListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 商品Mapper接口
 *
 * @author fs
 * @date 2023-06-07
 */
public interface OmsProductMapper
{
    /**
     * 查询商品
     *
     * @param productId 商品ID
     * @return 商品
     */
    public OmsProduct selectOmsProductById(Long productId);

    /**
     * 查询商品列表
     *
     * @param omsProduct 商品
     * @return 商品集合
     */
    public List<OmsProduct> selectOmsProductList(OmsProduct omsProduct);

    /**
     * 新增商品
     *
     * @param omsProduct 商品
     * @return 结果
     */
    public int insertOmsProduct(OmsProduct omsProduct);

    /**
     * 修改商品
     *
     * @param omsProduct 商品
     * @return 结果
     */
    public int updateOmsProduct(OmsProduct omsProduct);

    /**
     * 删除商品
     *
     * @param productId 商品ID
     * @return 结果
     */
    public int deleteOmsProductById(Long productId);

    /**
     * 批量删除商品
     *
     * @param productIds 需要删除的数据ID
     * @return 结果
     */
    public int deleteOmsProductByIds(Long[] productIds);

    @Select({"<script> " +
            "select p.*,pc.cate_name  from oms_product p left join oms_product_category pc on p.cate_id=pc.cate_id   " +
            "where 1=1 " +
            "<if test = 'maps.productName != null and  maps.productName !=\"\"    '> " +
            "and p.product_name like CONCAT('%',#{maps.productName},'%') " +
            "</if>" +
            "<if test = 'maps.cateId != null    '> " +
            "and (pc.cate_id =#{maps.cateId} or pc.pid=#{maps.cateId} )" +
            "</if>" +
            "<if test = 'maps.productType != null    '> " +
            "and p.product_type =#{maps.productType} " +
            "</if>" +
            "<if test = 'maps.isAudit != null    '> " +
            "and p.is_audit =#{maps.isAudit} " +
            "</if>" +
            " order by p.product_id desc "+
            "</script>"})
    List<OmsProductListVO> selectOmsProductListVO(@Param("maps") OmsProduct omsProduct);

    @Select({"<script> " +
            " select p.*,pc.cate_name from (SELECT ave.bar_code as bar_code,p.product_id, p.image, p.slider_image,p.product_name, p.product_info, p.cate_id, p.price,  " +
            " p.ot_price,p.cost,p.spec_type,p.unit_name,p.sort,p.product_type,p.create_time,p.update_time,p.is_audit " +
            " FROM oms_product p LEFT JOIN oms_product_attr_value ave on p.product_id=ave.product_id  WHERE ave.bar_code != '' and p.product_id is not null" +
            ") p left join oms_product_category pc on p.cate_id=pc.cate_id   " +
            " where 1=1 " +
            "<if test = 'maps.productName != null and  maps.productName !=\"\"  '> " +
            "and p.product_name like CONCAT('%',#{maps.productName},'%') " +
            "</if>" +
            "<if test = 'maps.barCode != null and  maps.barCode !=\"\"    '> " +
            "and p.bar_code like CONCAT('%',#{maps.barCode},'%') " +
            "</if>" +
            "<if test = 'maps.cateId != null    '> " +
            "and (pc.cate_id =#{maps.cateId} or pc.pid=#{maps.cateId} )" +
            "</if>" +
            "<if test = 'maps.productType != null    '> " +
            "and p.product_type =#{maps.productType} " +
            "</if>" +
            "<if test = 'maps.isAudit != null    '> " +
            "and p.is_audit =#{maps.isAudit} " +
            "</if>" +
            " order by p.product_id desc "+
            "</script>"})
    List<OmsProductListVO> selectFsStoreProductBarCodeListVO(@Param("maps")OmsProduct omsProduct);

    @Select ({"<script> " +
            "  SELECT p.product_id, p.image, p.slider_image,p.product_name, p.product_info, p.cate_id," +
            " p.ot_price,p.unit_name,p.sort,p.is_audit," +
            " p.create_time,p.update_time,p.is_del,p.cost,p.spec_type," +
            " p.product_type,ave.sku,ave.price,ave.bar_code FROM oms_product p " +
            "  LEFT JOIN oms_product_attr_value ave on p.product_id=ave.product_id WHERE  p.product_id is not null " +
            "</script>"})
    List<OmsProductExportVO> selectOmsProductExportList(@Param("maps")OmsProduct omsProduct);
}