package com.bjtdba.order.service.impl;

import com.bjtdba.entity.order.StoreCart;
import com.bjtdba.order.dao.MerchantDao;
import com.bjtdba.order.dao.OrderMerchantDao;
import com.bjtdba.order.dao.StoreCartDao;
import com.bjtdba.order.service.StoreCartService;
import com.bjtdba.order.vo.MerchantVo;
import com.bjtdba.order.vo.StoreCartVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 购物车表(StoreCart)表服务实现类
 *
 * @author makejava
 * @since 2022-09-29 14:39:50
 */
@Service("storeCartService")
public class StoreCartServiceImpl implements StoreCartService {
    @Resource
    private StoreCartDao storeCartDao;
    @Autowired
    private OrderMerchantDao orderMerchantDao;
    @Autowired
    private MerchantDao merchantDao;

    /**
     * 通过ID查询单条数据
     *
     * @param cartId 主键
     * @return 实例对象
     */
    @Override
    public StoreCart queryById(Long cartId) {
        return this.storeCartDao.queryById(cartId);
    }

    /**
     * 分页查询
     *
     * @param storeCart 筛选条件
     * @return 查询结果
     */
    @Override
    public List<StoreCart> queryByPage(StoreCart storeCart) {

        return  this.storeCartDao.queryAllByLimit(storeCart);
    }

    /**
     * 新增数据
     *
     * @param storeCart 实例对象
     * @return 实例对象
     */
    @Override
    public StoreCart insert(StoreCart storeCart) {
        this.storeCartDao.insert(storeCart);
        return storeCart;
    }

    /**
     * 修改数据
     *
     * @param storeCart 实例对象
     * @return 实例对象
     */
    @Override
    public StoreCart update(StoreCart storeCart) {
        this.storeCartDao.update(storeCart);
        return this.queryById(storeCart.getCartId());
    }

    /**
     * 通过主键删除数据
     *
     * @param cartId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long cartId) {
        return this.storeCartDao.deleteById(cartId) > 0;
    }

    public boolean batchDelete(String [] cartIds,Long uid){
        return this.storeCartDao.batchDelete(cartIds,uid)>0;
    }


    //<!-- 查询 事业二部商户 id结合-->
    public  List<Integer> getMerIds(){
        return this.orderMerchantDao.getMerIds();
    }

    public  Integer[] getMerids(Long uid){
        return this.storeCartDao.getMerids(uid);
    }

    public List<MerchantVo> getMerchantVo(Integer[] merIds){
        return  this.merchantDao.getMerchantVo(merIds);
    }

    public List<StoreCartVo>  queryByuid(Long uid){
        return storeCartDao.queryByuid(uid);
    }

    public StoreCartVo  queryByUidCartId(Long uid,Long cartId){
        return storeCartDao.queryByUidCartId(uid,cartId);
    }

    public List<StoreCart> getStoreCartList(String[] cartIds){
        return storeCartDao.getStoreCartList(cartIds);
    }


}
