package com.ym.mec.biz.service.impl;

import com.ym.mec.biz.dal.dao.MarketActivityDao;
import com.ym.mec.biz.dal.dao.VipGroupDefaultClassesUnitPriceDao;
import com.ym.mec.biz.dal.entity.ActivityDetailDto;
import com.ym.mec.biz.dal.entity.MarketActivity;
import com.ym.mec.biz.dal.entity.VipGroupDefaultClassesUnitPrice;
import com.ym.mec.biz.service.MarketActivityService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.exception.BizException;
import com.ym.mec.common.service.impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;

@Service
public class MarketActivityServiceImpl extends BaseServiceImpl<Integer, MarketActivity>  implements MarketActivityService {
	
	@Autowired
	private MarketActivityDao marketActivityDao;
	@Autowired
	private VipGroupDefaultClassesUnitPriceDao vipGroupDefaultClassesUnitPriceDao;

	@Override
	public BaseDAO<Integer, MarketActivity> getDAO() {
		return marketActivityDao;
	}

    @Override
    public List<ActivityDetailDto> queryActivity(Integer marketPriceId,Integer organId) {
		List<ActivityDetailDto> activityDetailDtos = marketActivityDao.queryActivity(marketPriceId,organId);
		activityDetailDtos.removeAll(Collections.singleton(null));
		for (ActivityDetailDto activityDetailDto : activityDetailDtos) {
			VipGroupDefaultClassesUnitPrice category = vipGroupDefaultClassesUnitPriceDao.getByVipGroupCategory(activityDetailDto.getCategoryId(), organId);
			if(category == null){
				throw new BizException("请设置分部收费标准");
			}
			activityDetailDto.setOriginalPrice(activityDetailDto.getCourseNum().multiply(category.getOnlineClassesUnitPrice()).setScale(0, BigDecimal.ROUND_CEILING));
		}
		return activityDetailDtos;
    }
}