package com.palmnest.service.estateserve.impl;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.directwebremoting.util.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.palmnest.application.ElementConstant;
import com.palmnest.application.core.util.HttpMesssageKit;
import com.palmnest.application.core.util.LogExceptionStackUtil;
import com.palmnest.dao.property.PropertyDao;
import com.palmnest.model.estateserve.ReserveRecord;
import com.palmnest.service.AsynchronousDataService;
import com.palmnest.service.Executable;
import com.palmnest.service.estateserve.ReserveManager;
import com.palmnest.service.estateserve.SmsAuthCodeManager;
import com.palmnest.service.impl.GenericManagerImpl;

@Service("aeserveManager")
public class ReserveManagerImpl extends GenericManagerImpl<Object, Integer> implements ReserveManager {

	private Logger LOG = Logger.getLogger(ReserveManagerImpl.class);

	private PropertyDao propertyDao;

	@Autowired
	public void setPropertyDao(PropertyDao propertyDao) {
		this.propertyDao = propertyDao;
		this.dao = propertyDao;
	}

	@Autowired
	private SmsAuthCodeManager smsAuthCodeManager;

	//线程异步处理数据Serveice
	@Autowired
	private AsynchronousDataService asynchronousWorkService;

	private String typeWater             = "water";
	private String typeHighServe         = "highServe";
	private String typeOfficialWeb       = "officialWeb";
	private String indexServe            = "indexServe";
	private String typeExpressServe      = "express";//快递服务
	private String typeCleaningServe     = "cleaning";//保洁服务
	private String typeCloudserviceServe = "cloudservice";//云服务
	private String typeSmsServe          = "sms";//短信服务
	private String typeInternetServe     = "internet";//宽带服务
	private String typePlantleasingServe = "printpaper";//绿植服务
	private String typePrintpaperServe   = "printpaper";//打印服务
	private String typeStationeryServe   = "stationery";//文具纸品服务
	private String typeBusinessServe     = "business";//文具纸品服务


	@Override
	public String saveReserveRecordWather(final String telePhone, final String userName, final String type) {
		String retFlag = "success";
		try {
			LOG.info("saveReserveRecordWather---");
			LOG.info("telePhone:" + telePhone);

			ReserveRecord record = new ReserveRecord();
			record.setTelePhone(telePhone);
			record.setType(type);
			record.setCreator(userName);
			record.setStatus("0");
			record.setCreateTime(new Date());
			record.setIsEnabled(ElementConstant.YESORNO_1);
			propertyDao.save(record);
			asynchronousWorkService.store(new Executable() {
				@Override
				public Void execute() {
					String userMobile = "15976871001,13928471704";   //陈文礼的电话
					String content = "";
					if (typeWater.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询水服务，请与他进行沟通 ，谢谢！";
					} else if (typeHighServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询商务定制，请与他进行沟通 ，谢谢！";
					} else if (indexServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询首页服务项服务，请与他进行沟通 ，谢谢！";
					} else if (typeOfficialWeb.equals(type)) {
						content = telePhone + "客户：" + userName + "，在前台官网留言了，请与他进行沟通 ，谢谢！";
					} else if (typeExpressServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询快递服务，请与他进行沟通 ，谢谢！";
					} else if (typePlantleasingServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询绿植服务，请与他进行沟通 ，谢谢！";
					} else if (typeCleaningServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询保洁服务，请与他进行沟通 ，谢谢！";
					} else if (typeCloudserviceServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询企业云服务，请与他进行沟通 ，谢谢！";
					} else if (typeSmsServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询短信服务，请与他进行沟通 ，谢谢！";
					} else if (typeInternetServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询宽带服务，请与他进行沟通 ，谢谢！";
					} else if (typePrintpaperServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询打印纸服务，请与他进行沟通 ，谢谢！";
					} else if (typeStationeryServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询文具纸品服务，请与他进行沟通 ，谢谢！";
					} else if (typeBusinessServe.equals(type)) {
						content = telePhone + "客户：" + userName + "，正在咨询企业内购服务，请与他进行沟通 ，谢谢！";
					}
					if (StringUtils.isNotBlank(content)) {
//						smsAuthCodeManager.sendSms(userMobile, content);
						smsAuthCodeManager.smsSend(userMobile, content);
					}
					return null;
				}
			});
		} catch (Exception e) {
			retFlag = "error";
			LOG.error("saveReserveRecordWather occur error." + LogExceptionStackUtil.LogExceptionStack(e));
		}
		LOG.info("retFlag:" + retFlag);
		return retFlag;
	}
}
