/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package org.springblade.modules.mall.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springblade.modules.mall.entity.GoodsInfo;
import org.springblade.modules.mall.vo.GoodsInfoVO;

import java.io.Serializable;
import java.util.List;

/**
 * 商品表 Mapper 接口
 *
 * @author BladeX
 * @since 2022-05-07
 */
public interface GoodsInfoMapper extends BaseMapper<GoodsInfo> {

	/**
	 * 自定义分页
	 *
	 * @param page
	 * @param goodsInfo
	 * @return
	 */
	List<GoodsInfoVO> selectGoodsInfoPage(IPage page, GoodsInfoVO goodsInfo);

	@Select("SELECT DISTINCT i.id FROM t_goods_info i LEFT JOIN t_goods_spec s on s.goods_id = i.id " +
		"WHERE i.promotion_rate != s.promotion_rate and i.is_delete = 0 and s.option_id is not null and i.promotion_rate >= #{start} and i.promotion_rate < #{end} GROUP BY i.id")
	List<Long> mySelect(@Param("start") Integer start, @Param("end") Integer end);

	List<GoodsInfo> activityGoods(IPage page, String activityDate);

	@Select("select * from t_goods_info where id = #{id}")
	GoodsInfo get(Serializable id);
}
