package com.lightinit.hsdataplatform.controller.admin;

import com.lightinit.hsdataplatform.dictionary.DicOrderState;
import com.lightinit.hsdataplatform.dictionary.DicOrderType;
import com.lightinit.hsdataplatform.dictionary.DicResourceRankCategory;
import com.lightinit.hsdataplatform.dictionary.DicResourceRankClassify;
import com.lightinit.hsdataplatform.entity.BaseExample;
import com.lightinit.hsdataplatform.model.ResultState;
import com.lightinit.hsdataplatform.model.admin.OrderSearchModel;
import com.lightinit.hsdataplatform.model.admin.RankSearchModel;
import com.lightinit.hsdataplatform.service.admin.IResourceRankService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @Author: sunxiang
 * @Date: 2018/8/17 11:19
 * @Description:
 **/
@Controller
@RequestMapping("/admin/resource_rank")
public class ResourceRankController {

    @Autowired
    private IResourceRankService resourceRankService;
    @RequestMapping("/index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("/admin/resource_rank/index");
        modelAndView.addObject("dicResourceRankCategory", DicResourceRankCategory.getInstance().getDicMap().clone());
        modelAndView.addObject("dicResourceRankClassify", DicResourceRankClassify.getInstance().getDicMap().clone());
        return modelAndView;
    }

    /*@RequestMapping("list.action")
    @ResponseBody
    public ResultState getList(RankSearchModel inputModel,Integer pageNo){
        BaseExample.Page page = new BaseExample.Page();
        page.setPageNo(pageNo);
        inputModel.setPage(page);
        ResultState resultState=resourceRankService.getList(inputModel);
        resourceRankService.queryCount(inputModel);
        resultState.setMsg(inputModel.getClassify()+"+"+inputModel.getCategory());
        return resultState;
    }*/

    @RequestMapping("list.action")
    public ModelAndView getList(RankSearchModel inputModel,Integer pageNo){
        ModelAndView modelAndView = new ModelAndView("admin/resource_rank/list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        inputModel.setPage(pager);
        Map<String,Object> resultState=resourceRankService.getList(inputModel);
        pager.setTotal((Long)resultState.get("pagerTotal"));
        modelAndView.addObject("resultState",resultState);
        modelAndView.addObject("msg",inputModel.getClassify()+"+"+inputModel.getCategory());
        modelAndView.addObject("pager",pager);
        return modelAndView;
    }
}
