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

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ym.mec.biz.dal.dao.OrganizationCourseUnitPriceSettingsDao;
import com.ym.mec.biz.dal.entity.CourseSchedule.CourseScheduleType;
import com.ym.mec.biz.dal.entity.OrganizationCourseUnitPriceSettings;
import com.ym.mec.biz.service.OrganizationCourseUnitPriceSettingsService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;

@Service
public class OrganizationCourseUnitPriceSettingsServiceImpl extends BaseServiceImpl<Integer, OrganizationCourseUnitPriceSettings>  implements OrganizationCourseUnitPriceSettingsService {
	
	@Autowired
	private OrganizationCourseUnitPriceSettingsDao organizationCourseUnitPriceSettingsDao;

	@Override
	public BaseDAO<Integer, OrganizationCourseUnitPriceSettings> getDAO() {
		return organizationCourseUnitPriceSettingsDao;
	}

	@Override
	public boolean batchInsert(List<OrganizationCourseUnitPriceSettings> organizationCourseUnitPriceSettingsList) {
		organizationCourseUnitPriceSettingsDao.batchInsert(organizationCourseUnitPriceSettingsList);
		return true;
	}

	@Override
	public OrganizationCourseUnitPriceSettings queryByOrganIdAndCourseTypeAndChargeType(Integer organId, CourseScheduleType courseType, Integer chargeTypeId) {
		return organizationCourseUnitPriceSettingsDao.queryByOrganIdAndCourseTypeAndChargeType(organId, courseType, chargeTypeId);
	}

	@Override
	public List<OrganizationCourseUnitPriceSettings> querySingle(Integer organId, String courseType, Integer tenantId) {
		return organizationCourseUnitPriceSettingsDao.querySingle(organId, courseType, tenantId);
	}

	@Override
	@Transactional(rollbackFor = Exception.class)
	public int save(List<OrganizationCourseUnitPriceSettings> organizationCourseUnitPriceSettingsList) {
		int successCount = 0;
		for (OrganizationCourseUnitPriceSettings ocup : organizationCourseUnitPriceSettingsList) {
			if (ocup.getId() != null) {
				successCount += organizationCourseUnitPriceSettingsDao.update(ocup);
			} else {
				successCount += organizationCourseUnitPriceSettingsDao.insert(ocup);
			}
		}
		return successCount;
	}
}