package cn.com.countrygarden.bi.main.controller.performance.monthly;

import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.core.ResultCode;
import cn.com.countrygarden.bi.main.model.AccessToken;
import cn.com.countrygarden.bi.main.service.AccessTokenService;
import cn.com.countrygarden.bi.main.service.performance.PerformanceCompanyService;
import cn.com.countrygarden.bi.main.service.performance.PerformanceEnvService;
import cn.com.countrygarden.bi.main.service.performance.PerformanceMonthlyService;
import cn.com.countrygarden.bi.main.service.performance.common.PerformanceAreaService;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 月度--我的考核
 */
@Controller("MyPerformanceMonthController")
@RequestMapping("/MyMonthlyPerformance")
public class MyPerformanceMonthController {

    @Autowired
    private AccessTokenService accessTokenService;

    @Autowired
    private PerformanceAreaService performanceAreaService;


    /**
     * 区域--我的月度考核
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/OrganScoreDetail",method = {RequestMethod.POST,RequestMethod.GET})
    public Object organScoreDetail(@RequestParam("organList")String[] organList,
                                   @RequestParam("year") Integer year,HttpServletRequest request){

        //身份验证
        String accessToken = request.getParameter("AccessToken");
        AccessToken token = accessTokenService.findByToken(accessToken);
        if (token == null || token.getUserCode() == null) {
            return Response.response(ResultCode.UNAUTHORIZED);
        }

        return Response.response(this.performanceAreaService.selectMonthlyEnvScoreInfo(organList,year,token.getUserCode()));
    }

    /**
     * 城市公司--我的月度考核
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/CompanyScoreDetail",method = {RequestMethod.POST,RequestMethod.GET})
    public Object companyScoreDetail(@RequestParam("organList") String[] comList,
                                     @RequestParam("year") Integer year,HttpServletRequest request){
        //身份验证
        String accessToken = request.getParameter("AccessToken");
        AccessToken token = accessTokenService.findByToken(accessToken);
        if (token == null || token.getUserCode() == null) {
            return Response.response(ResultCode.UNAUTHORIZED);
        }
        return Response.response(this.performanceAreaService.selectMonthlyCompanyScoreInfo(comList,year,token.getUserCode()));
    }
}
