package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.controller.admin.BaseController;
import com.lightinit.hsdatashow.entity.*;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.service.ms.IMSEcologicalCivilizationService;
import com.lightinit.hsdatashow.service.ms.IMSPublicEvaluationService;
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.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.LinkedHashMap;
import java.util.List;

@Controller
@RequestMapping(value = "/ms/PublicEvaluation")
public class MSPublicEvaluationController extends BaseController {
    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("舆情","PublicSentiment");
        map.put("生活条件，执政能力","Comprehensive");
        return map;
    }
    @Autowired
    private IMSPublicEvaluationService imsPublicEvaluationService;
    @RequestMapping(value="index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/publicEvaluation/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

    @RequestMapping(value="list.action")
    public ModelAndView list(String tableType,int pageNo){
        ModelAndView modelAndView=new ModelAndView("ms/publicEvaluation/"+tableType+"_list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List list=imsPublicEvaluationService.list(tableType,pager);
        long total=imsPublicEvaluationService.queryCount(tableType);
        pager.setTotal(total);
        modelAndView.addObject("list",list);
        modelAndView.addObject("pager",pager);
        return modelAndView;
    }

    @RequestMapping(value="add.htm")
    public ModelAndView add(String tableType,Long id){
        ModelAndView modelAndView=new ModelAndView("ms/publicEvaluation/"+tableType+"_add");
        Object obj=null;
        if(id !=null){
            obj=imsPublicEvaluationService.findById(tableType,id);
        }
        modelAndView.addObject("outputModel",obj);
        return modelAndView;
    }

    @RequestMapping(value="delete.action")
    @ResponseBody
    public ResultState delete(String tableType, Long id) {
        ResultState resultState =imsPublicEvaluationService.delete(tableType,id);
        return resultState;
    }

    @RequestMapping(value="addPublicSentiment.action")
    @ResponseBody
    public ResultState addPublicSentiment(PublicSentiment publicSentiment){
        boolean isEdit=publicSentiment.getId()==null?false:true;
        ResultState resultState=imsPublicEvaluationService.add(publicSentiment,isEdit);
        return resultState;
    }

    @RequestMapping(value="addComprehensive.action")
    @ResponseBody
    public ResultState addComprehensive(Comprehensive comprehensive){
        boolean isEdit=comprehensive.getId()==null?false:true;
        ResultState resultState=imsPublicEvaluationService.add(comprehensive,isEdit);
        return resultState;
    }

}
