package cn.com.countrygarden.bi.main.controller.v2;

import cn.com.countrygarden.bi.main.core.Response;
import cn.com.countrygarden.bi.main.model.AccessToken;
import cn.com.countrygarden.bi.main.service.twerp.hm.TbDesktopResourceService;
import cn.com.countrygarden.bi.main.service.twerp.hm.TbSysUserService;
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 java.util.*;

@Controller("takeOverDataControllerV2")
@RequestMapping("/api/biapp/data/v2/takeOver")
public class TakeOverDataController {

    @Autowired
    private TbSysUserService userService;
    @Autowired
    private TbDesktopResourceService resourceService;


    /**
     * 查询接管面积
     * @param commID
     * @param organCode
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/organ", produces = "application/json;charset=utf-8", method = RequestMethod.GET)
    public Object takeOverByOrgan(@RequestParam(value = "CommID", defaultValue = "") String commID,
                                  @RequestParam(value = "OrganCode", defaultValue = "") String organCode) {

        AccessToken accessToken = userService.getCurrentAccessToken();

        List<Map<String, String>> resources = resourceService.sumByOrganByUserCodeFromCache(
                accessToken.getUserCode(),
                organCode,
                commID
        );


        return Response.response(resources);
    }
}
