package com.palmnest.service.notice.impl;

import com.palmnest.application.bean.Page;
import com.palmnest.dao.notice.EmailConfigDao;
import com.palmnest.model.notice.EmailConfigModel;
import com.palmnest.service.impl.GenericManagerImpl;
import com.palmnest.service.notice.EmailConfigManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("emailConfigManager")
public class EmailConfigManagerImpl extends GenericManagerImpl<EmailConfigModel, Integer> implements EmailConfigManager {

	private EmailConfigDao emailConfigDao;

	@Autowired
	public void setRoomInfoDao(EmailConfigDao emailConfigDao) {
		this.emailConfigDao = emailConfigDao;
		this.dao = emailConfigDao;
	}

	/**
	 * longmeizhen
	 */
	@Override
	public Page getEmailConfigList(String orgIds, String email, int pageNo, int pageSize)
			throws Exception {
		return emailConfigDao.getEmailConfigList(orgIds, email, pageNo, pageSize);
	}

	/**
	 * longmeizhen
	 */
	@Override
	public String saveOrUpdate(EmailConfigModel emailConfigModel) {
		String isSuccess = "fail";
		if (emailConfigModel.getId() == null) {
			EmailConfigModel model = emailConfigDao.save(emailConfigModel);
			if (model != null) {
				isSuccess = "success";
			}
		} else {
			try {
				emailConfigDao.updateObj(emailConfigModel);
				isSuccess = "success";
			} catch (Exception e) {

				isSuccess = "fail";
			}
		}
		return isSuccess;
	}

	@Override
	public EmailConfigModel getEmailByOrg(String orgId) {
		return emailConfigDao.getEmailByOrg(orgId);
	}
}
