package com.platform.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.platform.dao.ApiGoodsMapper;
import com.platform.entity.GoodsVo;
import org.apache.commons.lang.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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


@Service
public class ApiGoodsService {
    @Autowired
    private ApiGoodsMapper goodsDao;


    public GoodsVo queryObject(Integer id) {
        return goodsDao.queryObject(id);
    }

    public GoodsVo queryObjectForUpdate(Integer id) {
        return goodsDao.queryObjectForUpdate(id);
    }

    public GoodsVo queryGoodsByName(String name) {
        return goodsDao.getGoodsByName(name);
    }




    public List<GoodsVo> queryList(Map<String, Object> map) {
        return goodsDao.queryList(map);
    }


    public int countGoodsOfBrand(Integer brandId , Integer isOnSale , Integer isDelete){
        if(null == brandId){
            return 0;
        }
        return goodsDao.countGoodsOfBrand(brandId , isDelete ,isOnSale);
    }

    public int queryTotal(Map<String, Object> map) {
        return goodsDao.queryTotal(map);
    }


    public void save(GoodsVo goods) {
        goodsDao.save(goods);
    }


    public void update(GoodsVo goods) {
        goodsDao.update(goods);
    }


    public void delete(Integer id) {
        goodsDao.delete(id);
    }


    public void deleteBatch(Integer[] ids) {
        goodsDao.deleteBatch(ids);
    }

    public List<GoodsVo> queryHotGoodsList(Map<String, Object> map) {
        return goodsDao.queryHotGoodsList(map);
    }

    public List<GoodsVo> queryCatalogProductList(Map<String, Object> map) {
        return goodsDao.queryCatalogProductList(map);
    }

    public  List<Map<String,Object>> getGoodsCategory(Integer brandId){
        if(null == brandId){
            return null;
        }
        QueryWrapper<GoodsVo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("goods.brand_id"  , brandId);
        queryWrapper.eq("goods.is_on_sale"  , 1);
        queryWrapper.eq("goods.is_delete"  , 0);
        return goodsDao.getGoodsCategory(queryWrapper);
    }


}
