package com.jeeplus.modules.API.userinfo;


import java.util.HashSet;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.sys.service.SystemService;
import com.jeeplus.modules.utils.ErrorCode;
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 org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.web.BaseController;
import com.jeeplus.modules.sys.service.OfficeService;

/**
 * 当前企业Controller
 * @author zmy
 * @version 2017-04-17
 */
@Controller
@RequestMapping(value = "${frontPath}/userInfo/currentcompany")
public class CurrentCompanyController extends BaseController{

	@Autowired
	private SystemService systemService;
	
	/**
	 * 获取当前企业列表
	 */
	@ResponseBody
	@RequestMapping(value = "getUserInfoCompanyList", method=RequestMethod.GET)
	public AjaxJson findCompany (String id,HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes)
	{
		AjaxJson j=new AjaxJson();
		List<Map<String, Object>> companyList = systemService.getCurrentCompany(id);
		j.put("data",companyList);
		j.setErrorCode(ErrorCode.code_1004);
		j.setMsg("获取企业列表成功");
		return j;
	}
	/**
	 * 切换用户当前企业
	 */
	@ResponseBody
	@RequestMapping(value = "getUserInfoCurrentCompany", method=RequestMethod.GET)
	public AjaxJson getCurrentCompany (String id,String companyId,String officeId,HttpServletRequest request, HttpServletResponse response, RedirectAttributes redirectAttributes)
	{  	
					
		AjaxJson j=new AjaxJson();
		List<Map<String, Object>> companyList = systemService.saveCurrentCompanyById(id,companyId,officeId);
		j.put("data",companyList);
		j.setMsg("切换企业成功");
		j.setErrorCode(ErrorCode.code_1004);
		return j;
		}	
	}

