package com.palmnest.service.notice.impl;

import com.palmnest.application.bean.Page;
import com.palmnest.application.core.util.PropertiesKit;
import com.palmnest.application.dto.output.MobileConfigDto;
import com.palmnest.dao.notice.MobileConfigDao;
import com.palmnest.model.notice.MobileConfigModel;
import com.palmnest.service.impl.GenericManagerImpl;
import com.palmnest.service.notice.MobileConfigManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author HIAPAD
 * @Description TODO
 * @Date 2018/9/11 16:39
 **/
@Service("mobileConfigManager")
public class MobileConfigManagerImpl extends GenericManagerImpl<MobileConfigModel, Long> implements MobileConfigManager {

	public static String smsSunMei_server = PropertiesKit.readPropertiesValue("smsSunMei_server", "wechat.properties");

	private MobileConfigDao mobileConfigDao;

	@Autowired
	public void setRoomInfoDao(MobileConfigDao mobileConfigDao) {
		this.mobileConfigDao = mobileConfigDao;
		this.dao = mobileConfigDao;
	}

	@Override
	public String saveOrUpdate(MobileConfigModel mobileConfigModel) {
		String isSuccess = "fail";
		if (mobileConfigModel.getId() == null) {
			MobileConfigModel model = mobileConfigDao.save(mobileConfigModel);
			if (model != null) {
				isSuccess = "success";
			}
		} else {
			try {
				mobileConfigDao.updateObj(mobileConfigModel);
				isSuccess = "success";
			} catch (Exception e) {

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

	@Override
	public Page getMobileConfigList(String orgIds, int pageNo, int pageSize) throws Exception {
		return mobileConfigDao.getMobileConfigList(orgIds, pageNo, pageSize);
	}

	@Override
	public List<MobileConfigModel> getMobileConfigList(String orgIds) throws Exception {
		return mobileConfigDao.getMobileConfigList(orgIds);
	}

	@Override
	public MobileConfigDto convertToDto(MobileConfigModel emailConfigModel) {

		MobileConfigDto mobileConfigDto = new MobileConfigDto(emailConfigModel.getId(), emailConfigModel.getMobileNum(), emailConfigModel.getPassword());
		mobileConfigDto.setMsgUrl(smsSunMei_server);
		return mobileConfigDto;
	}
}
