package com.fs.his.mapper;

import com.fs.his.domain.FsIntegralGoods;
import com.fs.his.param.FsIntegralGoodsListUParam;
import com.fs.his.vo.FsGoodsVO;
import com.fs.his.vo.FsIntegralGoodsChooseVO;
import com.fs.his.vo.FsIntegralGoodsListUVO;
import com.fs.his.vo.FsIntegralGoodsListVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

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

/**
 * 积分商品Mapper接口
 *
 * @author fs
 * @date 2023-11-02
 */
public interface FsIntegralGoodsMapper
{
    /**
     * 查询积分商品
     *
     * @param goodsId 积分商品主键
     * @return 积分商品
     */
    public FsIntegralGoods selectFsIntegralGoodsByGoodsId(Long goodsId);

    /**
     * 查询积分商品列表
     *
     * @param fsIntegralGoods 积分商品
     * @return 积分商品集合
     */
    public List<FsIntegralGoods> selectFsIntegralGoodsList(FsIntegralGoods fsIntegralGoods);

    /**
     * 新增积分商品
     *
     * @param fsIntegralGoods 积分商品
     * @return 结果
     */
    public int insertFsIntegralGoods(FsIntegralGoods fsIntegralGoods);

    /**
     * 修改积分商品
     *
     * @param fsIntegralGoods 积分商品
     * @return 结果
     */
    public int updateFsIntegralGoods(FsIntegralGoods fsIntegralGoods);

    /**
     * 删除积分商品
     *
     * @param goodsId 积分商品主键
     * @return 结果
     */
    public int deleteFsIntegralGoodsByGoodsId(Long goodsId);

    /**
     * 批量删除积分商品
     *
     * @param goodsIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteFsIntegralGoodsByGoodsIds(Long[] goodsIds);

    @Select({"<script> select goods_id,bar_code, img_url, images, goods_name, ot_price, goods_type, status, integral, cash, sort, stock, descs, create_time from fs_integral_goods" +
            "<where>  \n" +
            "            <if test=\"goodsName != null  and goodsName != ''\"> and goods_name like concat('%', #{goodsName}, '%')</if>\n" +
            "            <if test=\"goodsType != null \"> and goods_type = #{goodsType}</if>\n" +
            "            <if test=\"status != null \"> and status = #{status}</if>\n" +
            "            <if test=\"integral != null \"> and integral = #{integral}</if>\n" +
            "        </where> order by sort,goods_id desc"+
            "</script>"})
    List<FsIntegralGoodsListVO> selectFsIntegralGoodsListVO(FsIntegralGoods fsIntegralGoods);
    @Select({"<script> " +
            "select g.goods_id,g.img_url,g.images,g.goods_name,g.ot_price,g.goods_type,g.integral,g.cash,g.sort  from fs_integral_goods g  " +
            "where g.status=1  " +
            "<if test = 'maps.goodsType != null and maps.goodsType != 0     '> " +
            "and g.goods_type = #{maps.goodsType}  " +
            "</if>" +
            "<if test = 'maps.keyword != null and maps.keyword != \"\"'> " +
            "and g.goods_name like CONCAT('%',#{maps.keyword},'%') " +
            "</if>" +
            " order by g.goods_id desc "+
            "</script>"})
    List<FsIntegralGoodsListUVO> selectFsIntegralGoodsListUVO(@Param("maps")FsIntegralGoodsListUParam param);

    /**
     * 查询指定积分区间的商品
     * @param param 查询参数
     * @return 商品列表
     */
    List<FsIntegralGoods> selectFsIntegralGoodsByStage(FsIntegralGoodsListUParam param);

    @Update("update fs_integral_goods set stock = stock - #{num} where goods_id = #{goodsId} and stock >= #{num}")
    int subStock(@Param("goodsId") Long goodsId, @Param("num") int num);

    @Update("update fs_integral_goods set stock = stock + #{num} where goods_id = #{goodsId}")
    int addStock(@Param("goodsId") Long goodsId, @Param("num") int num);

    /**
     * 获取选择积分商品列表
     */
    List<FsIntegralGoodsChooseVO> getChooseIntegralGoodsListByMap(@Param("params") Map<String, Object> params);

    /**
     * 根据id集合查询积分商品列表
     */
    List<FsGoodsVO> getFsGoodsVOListByIds(@Param("goodsIds") List<Long> goodsIds);
}
