package com.yiqi.activity.service.impl;

import java.util.List;

import com.yiqi.activity.domain.ActivityInfo;
import com.yiqi.activity.domain.vo.ActivityDiscountInfoQueryVO;
import com.yiqi.activity.service.IActivityApplyOrgService;
import com.yiqi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yiqi.activity.mapper.ActivityDiscountInfoMapper;
import com.yiqi.activity.domain.ActivityDiscountInfo;
import com.yiqi.activity.service.IActivityDiscountInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

/**
 * 全场折扣活动Service业务层处理
 *
 * @author xiaohei
 * @date 2023-09-11
 */
@Service
public class ActivityDiscountInfoServiceImpl extends ServiceImpl<ActivityDiscountInfoMapper,ActivityDiscountInfo> implements IActivityDiscountInfoService {

    @Autowired
    private IActivityApplyOrgService activityApplyOrgService;

    /**
     * 查询全场折扣活动
     *
     * @param id 全场折扣活动主键
     * @return 全场折扣活动
     */
    @Override
    public ActivityDiscountInfo selectActivityDiscountInfoById(Long id) {
        return baseMapper.selectActivityDiscountInfoById(id);
    }

    /**
     * 查询全场折扣活动列表
     *
     * @param activityInfo 全场折扣活动
     * @return 全场折扣活动
     */
    @Override
    public List<ActivityDiscountInfoQueryVO> selectActivityDiscountInfoList(ActivityInfo activityInfo) {
        List<ActivityDiscountInfoQueryVO> activityDiscountInfoQueryVOList =  baseMapper.selectActivityDiscountInfoList(activityInfo);
        for(ActivityDiscountInfoQueryVO activityDiscountInfoQueryVO : activityDiscountInfoQueryVOList){
            activityDiscountInfoQueryVO.setStoreNum(activityApplyOrgService.getActivityApplyOrgNumByActivityId(activityDiscountInfoQueryVO.getId()));
        }
        return activityDiscountInfoQueryVOList;
    }

    /**
     * 新增全场折扣活动
     *
     * @param activityDiscountInfo 全场折扣活动
     * @return 结果
     */
    @Override
    public int insertActivityDiscountInfo(ActivityDiscountInfo activityDiscountInfo) {
        activityDiscountInfo.setCreateTime(DateUtils.getNowDate());
        return baseMapper.insertActivityDiscountInfo(activityDiscountInfo);
    }

    /**
     * 修改全场折扣活动
     *
     * @param activityDiscountInfo 全场折扣活动
     * @return 结果
     */
    @Override
    public int updateActivityDiscountInfo(ActivityDiscountInfo activityDiscountInfo) {
        activityDiscountInfo.setUpdateTime(DateUtils.getNowDate());
        return baseMapper.updateActivityDiscountInfo(activityDiscountInfo);
    }

    /**
     * 批量删除全场折扣活动
     *
     * @param ids 需要删除的全场折扣活动主键
     * @return 结果
     */
    @Override
    public int deleteActivityDiscountInfoByIds(Long[] ids) {
        return baseMapper.deleteActivityDiscountInfoByIds(ids);
    }

    /**
     * 删除全场折扣活动信息
     *
     * @param id 全场折扣活动主键
     * @return 结果
     */
    @Override
    public int deleteActivityDiscountInfoById(Long id) {
        return baseMapper.deleteActivityDiscountInfoById(id);
    }

    @Override
    public List<ActivityDiscountInfoQueryVO> getDiscountListByStoreId(Long storeId) {
        return baseMapper.getDiscountListByStoreId(storeId);
    }


}
