package com.huiju.estateagents.property.controller;

import com.huiju.estateagents.base.BaseController;
import com.huiju.estateagents.base.ResponseBean;
import com.huiju.estateagents.center.taUser.entity.TaUser;
import com.huiju.estateagents.property.common.UserElement;
import com.huiju.estateagents.property.service.IndexCountServiceI;
import com.google.common.collect.Maps;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @author FXF
 * @date 2019-05-28
 */
@RestController
@RequestMapping("/")
public class IndexCountController extends BaseController {
	
	@Autowired
	private IndexCountServiceI indexCountService;
	
	@ApiOperation(value = "获取物业端首页所有统计数据", notes = "获取物业端首页所有统计数据")
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "header", dataTypeClass = String.class, name = "X-Auth-Token", value = "Token")
	})
	@RequestMapping(value = "/index/count", method = RequestMethod.GET)
	public ResponseBean getIndexCount(HttpServletRequest request){
		TaUser userElement = getTaUser(request);
		ResponseBean  responseBean = new ResponseBean();
		Map<String,Object> indexCountMap = Maps.newHashMap();
		try {
			indexCountMap = indexCountService.getIndexCount(userElement);
		}catch (Exception e){
			responseBean.addError(e.getMessage());
			return responseBean;
		}
		responseBean.addSuccess(indexCountMap);
		return responseBean;
	}
}
