package com.uas.platform.b2b.mobile.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.uas.platform.b2b.mobile.service.MobileTaskService;
import com.uas.platform.b2b.model.OfficeTask;
import com.uas.platform.b2b.model.OfficeTaskReply;
import com.uas.platform.b2b.temporary.model.OfficeTaskInfo;

/**
 * 
 * @author hejq
 * @time 创建时间：2017年3月17日
 */
@Controller("mobile.MobileTaskController")
@RequestMapping("/mobile/mobiletask")
public class MobileTaskController {

	@Autowired
	private MobileTaskService mobileTaskService;

	/**
	 * 保存工作任务
	 * 
	 * @param formStore
	 * @return
	 */
	@RequestMapping(value = "/saveTask", method = RequestMethod.POST)
	@ResponseBody
	private ModelMap saveTask(String formStore) {
		OfficeTaskInfo task = JSON.parseObject(formStore, OfficeTaskInfo.class);
		return mobileTaskService.saveTask(task);
	}

	/**
	 * 得到所有任务数据
	 * 
	 * @param emuu
	 * @param enuu
	 * @param pageNumber
	 * @param pageSize
	 * @param status
	 * @return
	 */
	@RequestMapping(value = "/getAllTasks", method = RequestMethod.GET)
	@ResponseBody
	private ModelMap getAllTasks(Long emuu, Long enuu, Integer pageNumber, Integer pageSize, String status) {
		return mobileTaskService.getAllTasks(emuu, enuu, pageNumber, pageSize, status);
	}

	/**
	 * 得到我发出的任务
	 * 
	 * @param emuu
	 * @param enuu
	 * @param pageNumber
	 * @param pageSize
	 * @param status
	 * @return
	 */
	@RequestMapping(value = "/myTasks", method = RequestMethod.GET)
	@ResponseBody
	private ModelMap getMyTasks(Long emuu, Long enuu, Integer pageNumber, Integer pageSize) {
		return mobileTaskService.getMyTasks(emuu, enuu, pageNumber, pageSize);
	}

	/**
	 * 获取回复记录
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/getTaskReply", method = RequestMethod.GET)
	@ResponseBody
	private ModelMap getTaskReply(Long id) {
		return mobileTaskService.getTaskReply(id);
	}

	/**
	 * 变更任务状态
	 * 
	 * @param formStore
	 * @param gridStore
	 * @return
	 */
	@RequestMapping(value = "/changeTaskStaus", method = RequestMethod.POST)
	@ResponseBody
	private ModelMap changeTaskStaus(String formStore, String gridStore) {
		OfficeTask task = JSON.parseObject(formStore, OfficeTask.class);
		OfficeTaskReply taskreply = JSON.parseObject(gridStore, OfficeTaskReply.class);
		return mobileTaskService.changeTaskStaus(task, taskreply);
	}

	/**
	 * 统计任务条数
	 * 
	 * @param emcode
	 * @param enuu
	 * @return
	 */
	@RequestMapping(value = "/getTaskCounts", method = RequestMethod.GET)
	@ResponseBody
	private ModelMap getTaskCounts(Long emcode, Long enuu) {
		return mobileTaskService.getTaskCounts(emcode, enuu);
	}
}
