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

import com.ym.mec.common.exception.BizException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ym.mec.biz.dal.dao.VipGroupDefaultClassesUnitPriceDao;
import com.ym.mec.biz.dal.entity.VipGroupDefaultClassesUnitPrice;
import com.ym.mec.biz.service.VipGroupDefaultClassesUnitPriceService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;

import java.util.Objects;

@Service
public class VipGroupDefaultClassesUnitPriceServiceImpl extends BaseServiceImpl<Integer, VipGroupDefaultClassesUnitPrice>  implements VipGroupDefaultClassesUnitPriceService {
	
	@Autowired
	private VipGroupDefaultClassesUnitPriceDao vipGroupDefaultClassesUnitPriceDao;

	@Override
	public BaseDAO<Integer, VipGroupDefaultClassesUnitPrice> getDAO() {
		return vipGroupDefaultClassesUnitPriceDao;
	}

	@Override
	public long insert(VipGroupDefaultClassesUnitPrice bean) {
		if(Objects.isNull(bean.getOrganId())){
			throw new BizException("请选择分部");
		}
		VipGroupDefaultClassesUnitPrice byVipGroupCategory = vipGroupDefaultClassesUnitPriceDao.getByVipGroupCategory( bean.getVipGroupCategoryId(),bean.getOrganId());
		if(null!=byVipGroupCategory){
			return vipGroupDefaultClassesUnitPriceDao.updateByVipGroupCategory(bean);
		}else{
			return super.insert(bean);
		}
	}
}
