package org.fouram.controller;

import org.fouram.core.base.controller.BaseController;
import org.fouram.core.util.AppUtil;
import org.fouram.core.util.AppUtil.ResultConstant;
import org.fouram.core.util.LoggerUtil;
import org.fouram.service.SapReportService;
import org.fouram.service.SapUserService;
import org.fouram.service.TaskService;
import org.fouram.service.TestUserService;
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.ResponseBody;

@Controller
@RequestMapping(value = "/task")
public class TaskController extends BaseController {

	@Autowired
	private TaskService taskService;
	@Autowired
	private SapUserService sapUserService;
	@Autowired
	private TestUserService testUserService;
	@Autowired
	private SapReportService sapReportService;

	/**
	 * http://localhost:8080/sapcms/task/syncWeixinUser
	 * @return
	 */
	@RequestMapping(value = "/syncWeixinUser", produces = "application/json;charset=utf-8")
	@ResponseBody
	public Object syncWeixinUser() {
		try {
			taskService.syncWeixinUser();
			return AppUtil.success();
		} catch (Exception e) {
			LoggerUtil.error(e);
			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
		}
	}
	
	/**
	 * http://localhost:8080/sapcms/task/createOrUpdateWXUsers
	 * @return
	 */
	@RequestMapping(value = "/createOrUpdateWXUsers", produces = "application/json;charset=utf-8")
	@ResponseBody
	public Object createOrUpdateWXUsers() {
		try {
			testUserService.createOrUpdateWXUsers();
			return AppUtil.success();
		} catch (Exception e) {
			LoggerUtil.error(e);
			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
		}
	}
	
	/**
	 * http://localhost:8080/sapcms/task/saveSapAllReportData
	 * @return
	 */
	@RequestMapping(value = "/saveSapAllReportData", produces = "application/json;charset=utf-8")
	@ResponseBody
	public Object saveSapAllReportData() {
		try {
			sapReportService.saveSapAllReportData();
			return AppUtil.success();
		} catch (Exception e) {
			LoggerUtil.error(e);
			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
		}
	}
	
	/**
	 * http://localhost:8080/sapcms/task/updateUnableData
	 * @return
	 */
	@RequestMapping(value = "/updateUnableData", produces = "application/json;charset=utf-8")
	@ResponseBody
	public Object updateUnableData() {
		try {
			sapUserService.updateUnableData();
			return AppUtil.success();
		} catch (Exception e) {
			LoggerUtil.error(e);
			return AppUtil.error(ResultConstant.WEB_ERR_MSG);
		}
	}
}