package com.ruoyi.mall.service.impl;

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

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mall.mapper.MallCombineGoodsMapper;
import com.ruoyi.mall.domain.MallCombineGoods;
import com.ruoyi.mall.service.IMallCombineGoodsService;

import javax.annotation.Resource;

/**
 * 拼团商品Service业务层处理
 *
 * @author ruoyi
 * @date 2024-03-21
 */
@Service
public class MallCombineGoodsServiceImpl implements IMallCombineGoodsService
{
    @Resource
    private MallCombineGoodsMapper mallCombineGoodsMapper;

    /**
     * 查询拼团商品
     *
     * @param combineId 拼团商品主键
     * @return 拼团商品
     */
    @Override
    public MallCombineGoods selectMallCombineGoodsByCombineId(Long combineId)
    {
        return mallCombineGoodsMapper.selectMallCombineGoodsByCombineId(combineId);
    }

    /**
     * 查询拼团商品列表
     *
     * @param mallCombineGoods 拼团商品
     * @return 拼团商品
     */
    @Override
    public List<MallCombineGoods> selectMallCombineGoodsList(MallCombineGoods mallCombineGoods)
    {
        return mallCombineGoodsMapper.selectMallCombineGoodsList(mallCombineGoods);
    }

    /**
     * 新增拼团商品
     *
     * @param mallCombineGoods 拼团商品
     * @return 结果
     */
    @Override
    public AjaxResult insertMallCombineGoods(MallCombineGoods mallCombineGoods)
    {
        //是否已添加过此商品
        if (mallCombineGoodsMapper.selectMallCombineGoodsByGoodsId(mallCombineGoods.getGoodsId()) > 0){
            return AjaxResult.error("此商品已添加");
        }
        mallCombineGoods.setCreateAt(DateUtils.getTime());
        mallCombineGoods.setDelFlag(0);
        return AjaxResult.toAjax(mallCombineGoodsMapper.insertMallCombineGoods(mallCombineGoods));
    }

    /**
     * 修改拼团商品
     *
     * @param mallCombineGoods 拼团商品
     * @return 结果
     */
    @Override
    public int updateMallCombineGoods(MallCombineGoods mallCombineGoods)
    {
        mallCombineGoods.setUpdateAt(DateUtils.getTime());
        return mallCombineGoodsMapper.updateMallCombineGoods(mallCombineGoods);
    }

    /**
     * 批量删除拼团商品
     *
     * @param combineIds 需要删除的拼团商品主键
     * @return 结果
     */
    @Override
    public int deleteMallCombineGoodsByCombineIds(Long[] combineIds)
    {
        return mallCombineGoodsMapper.deleteMallCombineGoodsByCombineIds(combineIds);
    }

    /**
     * 删除拼团商品信息
     *
     * @param combineId 拼团商品主键
     * @return 结果
     */
    @Override
    public int deleteMallCombineGoodsByCombineId(Long combineId)
    {
        return mallCombineGoodsMapper.deleteMallCombineGoodsByCombineId(combineId);
    }

    /**
     * 拼团商品可选商品列表
     *
     * @return 拼团商品
     */
    @Override
    public List<Map<String, Object>> enableCombineGoodsList() {
        return mallCombineGoodsMapper.enableCombineGoodsList();
    }

    /**
     * 拼团商品列表
     *
     * @return 拼团商品
     */
    @Override
    public List<Map<String, Object>> getCombineGoodsList(Map<String, Object> params) {
        return mallCombineGoodsMapper.getCombineGoodsList(params);
    }
}
