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

import com.ym.mec.biz.dal.dao.OrganizationCloudTeacherFeeDao;
import com.ym.mec.biz.dal.entity.OrganizationCloudTeacherFee;
import com.ym.mec.biz.service.OrganizationCloudTeacherFeeService;
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;

@Service
public class OrganizationCloudTeacherFeeServiceImpl extends BaseServiceImpl<Integer, OrganizationCloudTeacherFee> implements OrganizationCloudTeacherFeeService {

    @Autowired
    private OrganizationCloudTeacherFeeDao organizationCloudTeacherFeeDao;

    @Override
    public BaseDAO<Integer, OrganizationCloudTeacherFee> getDAO() {
        return organizationCloudTeacherFeeDao;
    }

    @Override
    public OrganizationCloudTeacherFee add(OrganizationCloudTeacherFee organizationCloudTeacherFee) {
        OrganizationCloudTeacherFee old = organizationCloudTeacherFeeDao.getByOrganId(organizationCloudTeacherFee.getOrganId());
        if (old != null) {
            throw new BizException("分部配置已存在，不能重复添加");
        }
        organizationCloudTeacherFeeDao.insert(organizationCloudTeacherFee);
        return organizationCloudTeacherFee;
    }

    @Override
    public OrganizationCloudTeacherFee updateFee(OrganizationCloudTeacherFee organizationCloudTeacherFee) {
        OrganizationCloudTeacherFee old = organizationCloudTeacherFeeDao.get(organizationCloudTeacherFee.getId());
        if (old == null || !old.getOrganId().equals(organizationCloudTeacherFee.getOrganId())) {
            throw new BizException("分部不能修改，请核查");
        }
        organizationCloudTeacherFeeDao.update(organizationCloudTeacherFee);
        return organizationCloudTeacherFee;
    }
}
