package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.model.admin.StatisiticSearchModel;
import com.lightinit.hsdataplatform.model.admin.StatisticModel;
import com.lightinit.hsdataplatform.service.admin.IResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.*;

/**
 * @Author: sunxiang
 * @Date: 2018/7/16 14:51
 * @Description:
 **/
@Controller
@RequestMapping("/admin/resource_numsta")
public class ResourceNumStatisitcController {

    @Autowired
    private IResourceService resourceService;
    @RequestMapping(value = "themeindex.htm")
    public ModelAndView themeindex(){
        ModelAndView modelAndView = new ModelAndView("admin/resource_num_statisitic/themeindex");
        return modelAndView;
    }

    @RequestMapping(value = "themelist.action")
    public ModelAndView themelist(StatisiticSearchModel inputModel){
        ModelAndView modelAndView = new ModelAndView("admin/resource_num_statisitic/themelist");
        List<String> list=resourceService.getCatelogTypeIsTheme(inputModel);
        List<Map<String, Object>> listMap=resourceService.getEveryThemeTotal(inputModel);
        HashMap<String,Long> map = new HashMap<>();
        for (Map<String, Object> stringIntegerMap : listMap) {
           map.put((String)stringIntegerMap.get("title"),(Long)stringIntegerMap.get("total"));
        }
        modelAndView.addObject("list",list);
        modelAndView.addObject("map",map);
        return modelAndView;
    }

    @RequestMapping(value = "sectorindex.htm")
    public ModelAndView sectorindex(){
        ModelAndView modelAndView = new ModelAndView("admin/resource_num_statisitic/sectorindex");
        return modelAndView;
    }

    @RequestMapping(value = "sectorlist.action")
    public ModelAndView sectorlist(StatisiticSearchModel inputModel){
        ModelAndView modelAndView = new ModelAndView("admin/resource_num_statisitic/sectorlist");
        List<String> list=resourceService.getSectorList();
        List<Map<String, Object>> listMap=resourceService.getEverySectorTotal(inputModel);
        HashMap<String,Long> map = new HashMap<>();
        for (Map<String, Object> stringIntegerMap : listMap) {
            map.put((String)stringIntegerMap.get("title"),(Long)stringIntegerMap.get("total"));
        }
        modelAndView.addObject("list",list);
        modelAndView.addObject("map",map);
        return modelAndView;
    }


    /////////////////////////////////////////////排名////////////////////////
    @RequestMapping(value = "themeSortIndex.htm")
    public ModelAndView themeSortIndex(){
        ModelAndView modelAndView = new ModelAndView("admin/resource_num_statisitic/themeSortIndex");
        return modelAndView;
    }

    @RequestMapping(value = "themeSortList.action")
    public ModelAndView themeSortList(StatisiticSearchModel inputModel){
        ModelAndView modelAndView = new ModelAndView("admin/resource_num_statisitic/themeSortList");
        List<String> list=resourceService.getCatelogTypeIsTheme(inputModel);
        List<StatisticModel> statisticModelList=resourceService.getThemeSortTotal(inputModel);
        for (StatisticModel statisticModel : statisticModelList) {
            list.remove(statisticModel.getName());
        }
        for (String name : list) {
            StatisticModel model = new StatisticModel();
            model.setName(name);
            statisticModelList.add(model);
        }
        modelAndView.addObject("list",statisticModelList);
        return modelAndView;
    }


    @RequestMapping(value = "sectorSortIndex.htm")
    public ModelAndView sectorSortIndex(){
        ModelAndView modelAndView = new ModelAndView("admin/resource_num_statisitic/sectorSortIndex");
        return modelAndView;
    }

    @RequestMapping(value = "sectorSortList.action")
    public ModelAndView sectorSortList(StatisiticSearchModel inputModel){
        ModelAndView modelAndView = new ModelAndView("admin/resource_num_statisitic/sectorSortList");
        List<String> list=resourceService.getSectorList();
        List<StatisticModel> statisticModelList=resourceService.getSectorSortList(inputModel);
        for (StatisticModel statisticModel : statisticModelList) {
            list.remove(statisticModel.getName());
        }
        for (String name : list) {
            StatisticModel model = new StatisticModel();
            model.setName(name);
            statisticModelList.add(model);
        }
        modelAndView.addObject("list",statisticModelList);
        return modelAndView;
    }

}
