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

import java.util.List;

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.JSONObject;
import com.uas.platform.b2b.mobile.model.OutAddress;
import com.uas.platform.b2b.mobile.model.OutPlan;
import com.uas.platform.b2b.mobile.model.OutPlanDetail;
import com.uas.platform.b2b.mobile.model.OutSet;
import com.uas.platform.b2b.mobile.model.OutSign;
import com.uas.platform.b2b.mobile.service.OutAddressService;
import com.uas.platform.b2b.mobile.service.OutPlanService;
import com.uas.platform.b2b.mobile.service.OutSetService;
import com.uas.platform.b2b.mobile.service.OutSignService;

/**
 * 外勤设置
 * 
 * @author hejq
 * @time 创建时间：2017年2月22日
 */
@Controller("mobile/outPlanController")
@RequestMapping("/mobile/outplan")
public class OutPlanController {

	@Autowired
	private OutPlanService outPlanService;

	@Autowired
	private OutAddressService outAddressService;

	@Autowired
	private OutSetService outSetService;

	@Autowired
	private OutSignService outSignService;

	/**
	 * 保存外勤地址
	 * 
	 * @param formStore
	 * @return
	 */
	@RequestMapping(value = "/saveOutAddress", method = RequestMethod.POST)
	@ResponseBody
	private ModelMap saveOutAddress(String formStore) {
		OutAddress outAddress = JSONObject.parseObject(formStore, OutAddress.class);
		return outAddressService.saveOutAddress(outAddress);
	}

	/**
	 * 获取外勤地址
	 * 
	 * @param enuu
	 * @param pageNumber
	 * @param pageSize
	 * @return
	 */
	@RequestMapping(value = "/getOutAddress", method = RequestMethod.GET)
	@ResponseBody
	private ModelMap getOutAddress(Long enuu, Integer pageNumber, Integer pageSize) {
		return outAddressService.getOutAddress(enuu, pageNumber, pageSize);
	}
	/**
	 * 保存自动外勤设置
	 * 
	 * @param formStore
	 * @return
	 */
	@RequestMapping(value = "/saveOutSet", method = RequestMethod.POST)
	@ResponseBody
	private ModelMap saveOutSet(String formStore) {
		OutSet outSet = JSONObject.parseObject(formStore, OutSet.class);
		return outSetService.saveOutSet(outSet);
	}

	/**
	 * 获取外勤设置
	 * 
	 * @param enuu
	 * @return
	 */
	@RequestMapping(value = "/getOutSet", method = RequestMethod.GET)
	@ResponseBody
	private OutSet getOutSet(Long enuu) {
		return outSetService.getOutSet(enuu);
	}

	/**
	 * 保存新增外勤计划
	 * 
	 * @param param
	 * @param formStore
	 * @return
	 */
	@RequestMapping(value = "/saveOutPlan", method = RequestMethod.POST)
	@ResponseBody
	private ModelMap saveOutPlan(String param, String formStore) {
		OutPlan outPlan = JSONObject.parseObject(formStore, OutPlan.class);
		List<OutPlanDetail> outPlanDetails = JSONObject.parseArray(param, OutPlanDetail.class);
		return outPlanService.saveOutPlan(outPlan, outPlanDetails);
	};

	/**
	 * 保存外勤打卡记录
	 * 
	 * @param formStore
	 * @return
	 */
	@RequestMapping(value = "/saveOutSign", method = RequestMethod.POST)
	@ResponseBody
	private ModelMap saveOutSign(String formStore) {
		OutSign outSign = JSONObject.parseObject(formStore, OutSign.class);
		return outSignService.saveOutSign(outSign);
	}

	/**
	 * 获取当前人员的外勤计划
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getOutPlan", method = RequestMethod.GET)
	@ResponseBody
	private ModelMap getOutPlan(Long emcode, Long enuu) {
		return outPlanService.getOutPlan(emcode, enuu);
	}

	/**
	 * 更新外勤状态
	 * 
	 * @param id
	 * @param statuscode
	 * @return
	 */
	@RequestMapping(value = "/updateStatus", method = RequestMethod.POST)
	@ResponseBody
	private ModelMap updateStatus(Long id, String statuscode) {
		return outPlanService.updateStatus(id, statuscode);
	}
}
