package com.palmnest.webapp.quartz;

import com.palmnest.service.estateserve.AppUserManager;
import com.palmnest.service.estateserve.ContractIinformationOrderManager;
import com.palmnest.service.estateserve.ScWxuserManager;
import com.palmnest.service.estateserve.ServiceProjectAllocationManager;
import com.palmnest.service.wechat.RechargeManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 初始化数据的控制器
 * 临时
 *
 * @author yubing
 * @since 2017-04-10
 */
@Controller
@RequestMapping("/tempInitBaseDataTask/*")
public class TempInitBaseDataTask {

	@Autowired
	private AppUserManager                   appUserManager;
	@Autowired
	private ContractIinformationOrderManager contractIinformationOrderManager;
	@Autowired
	private ScWxuserManager                  scWxuserManager;
	@Autowired
	private ServiceProjectAllocationManager  serviceProjectAllocationManager;
	@Autowired
	private RechargeManager                  rechargeManager;

	/**
	 * 同步注册用户信息—一键服务系统
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/initAppUserToOneKeyService", method = {RequestMethod.GET, RequestMethod.POST})
	public @ResponseBody
	String userinformationSync(HttpServletRequest request) {
		appUserManager.initAppUserToOneKeyService();
		return "success";
	}

	/**
	 * 初始化企业的签约状态
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/initVirtualArchContractStatus", method = {RequestMethod.GET, RequestMethod.POST})
	public @ResponseBody
	String initVirtualArchContractStatus(HttpServletRequest request) {
		contractIinformationOrderManager.updateVirtualContractStatus();
		return "success";
	}

	/**
	 * 初始化微信资料信息
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/initUpWxUserMsg", method = {RequestMethod.GET, RequestMethod.POST})
	public @ResponseBody
	String initWxUserMsg(HttpServletRequest request) {
		System.out.println("initUpWxUserMsg");
		scWxuserManager.updateAllWxUserInfo();
		return "success";
	}

	/**
	 * 所有项目批量
	 * 上架/下架服务包
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/batchOnOffService", method = {RequestMethod.GET, RequestMethod.POST})
	public @ResponseBody
	String batchOnOffService(HttpServletRequest request) {


		System.out.println("batchOnOffService");

		//状态（0-下线，1-上线）
		String status        = request.getParameter("status");
		String serviceTypeId = request.getParameter("serviceTypeId"); //服务ID
		String orderNo       = request.getParameter("orderNo");                //orderNo

		serviceProjectAllocationManager.assignBatchOnOffService(status, serviceTypeId, orderNo);

		return "success";
	}


	/**
	 * 所有项目批量
	 * 上架/下架服务包
	 *
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "/assginRecoveryRecharge", method = {RequestMethod.GET, RequestMethod.POST})
	public @ResponseBody
	String assginRecoveryRecharge(HttpServletRequest request) {
		System.out.println("assginRecoveryRecharge");
		String month = request.getParameter("month");
		rechargeManager.assignRecoveryRecharge(month);
		return "success";
	}

}
