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

import com.alibaba.fastjson.JSON;
import com.ym.mec.biz.dal.dao.VipGroupActivityDao;
import com.ym.mec.biz.dal.dto.VipGroupActivityAddDto;
import com.ym.mec.biz.dal.entity.VipGroupActivity;
import com.ym.mec.biz.service.VipGroupActivityService;
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.util.List;
import java.util.Objects;

@Service
public class VipGroupActivityServiceImpl extends BaseServiceImpl<Integer, VipGroupActivity>  implements VipGroupActivityService {
	
	@Autowired
	private VipGroupActivityDao vipGroupActivityDao;

	@Override
	public BaseDAO<Integer, VipGroupActivity> getDAO() {
		return vipGroupActivityDao;
	}

	@Override
	public void addVipGroupActivity(VipGroupActivityAddDto vipGroupActivityAddDto) {
		if(Objects.isNull(vipGroupActivityAddDto.getOrganId())){
			throw new BizException("请指定部门!");
		}

		vipGroupActivityAddDto.setSalarySettlementJson(JSON.toJSONString(vipGroupActivityAddDto.getVipGroupSalarySettlement()));
		super.insert(vipGroupActivityAddDto);
	}

	@Override
	public void updateVipGroupActivity(VipGroupActivityAddDto vipGroupActivityAddDto) {
		if(Objects.isNull(vipGroupActivityAddDto.getId())){
			throw new BizException("请指定活动编号!");
		}
		if(Objects.isNull(vipGroupActivityAddDto.getOrganId())){
			throw new BizException("请指定部门!");
		}
		vipGroupActivityAddDto.setSalarySettlementJson(JSON.toJSONString(vipGroupActivityAddDto.getVipGroupSalarySettlement()));
		super.update(vipGroupActivityAddDto);
	}

	@Override
	public List<VipGroupActivity> findByVipGroupCategory(Long categoryId) {
		if(Objects.isNull(categoryId)){
			throw new BizException("请选择课程形态!");
		}
		return vipGroupActivityDao.findByCategory(categoryId);
	}
}