package com.lightinit.hsdatashow.controller.ms;

import com.lightinit.hsdatashow.entity.*;
import com.lightinit.hsdatashow.model.ResultState;
import com.lightinit.hsdatashow.service.ms.IMSEnergyService;
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;

/**
 * @Author: sunxiang
 * @Date: 2018/8/29 14:06
 * @Description:
 **/
@Controller
@RequestMapping(value="ms/energy")
public class MSEnergyController {

    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("能源消耗总量分析","EnergyConsumption");
        map.put("能源消耗占比分析","EnergyProportion");
        map.put("污染、清洁能源比重分析","CleanPolluteProportion");
        map.put("新能源基础设施","NewenergyInfrastructure");
        map.put("原煤消耗分析","CoalConsume");
        map.put("电力消耗对比分析","ElectricConsume");
        return map;
    }
    @Autowired
    private IMSEnergyService msEnergyService;
    @RequestMapping(value="index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/energy/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

    @RequestMapping(value="list.action")
    public ModelAndView list(String tableType,int pageNo){
        ModelAndView modelAndView=new ModelAndView("ms/energy/"+tableType+"_list");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List list=msEnergyService.list(tableType,pager);
        long total=msEnergyService.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/energy/"+tableType+"_add");
        Object obj=null;
        if(id !=null){
             obj=msEnergyService.findById(tableType,id);
        }
        modelAndView.addObject("outputModel",obj);
        return modelAndView;
    }

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

    @RequestMapping(value="addEnergyConsumption.action")
    @ResponseBody
    public ResultState addEnergyConsumption(EnergyConsumption energyConsumption){
        boolean isEdit=energyConsumption.getId()==null?false:true;
        ResultState resultState=msEnergyService.add(energyConsumption,isEdit);
        return resultState;
    }

    @RequestMapping(value="addCleanPolluteProportion.action")
    @ResponseBody
    public ResultState addEnergyProportion(CleanPolluteProportion cleanPolluteProportion){
        boolean isEdit=cleanPolluteProportion.getId()==null?false:true;
        ResultState resultState=msEnergyService.add(cleanPolluteProportion,isEdit);
        return resultState;
    }

    @RequestMapping(value="addEnergyProportion.action")
    @ResponseBody
    public ResultState addEnergyProportion(EnergyProportion energyProportion){
        boolean isEdit=energyProportion.getId()==null?false:true;
        ResultState resultState=msEnergyService.add(energyProportion,isEdit);
        return resultState;
    }
     @RequestMapping(value="addNewenergyInfrastructure.action")
     @ResponseBody
     public ResultState addNewenergyInfrastructure(NewenergyInfrastructure newenergyInfrastructure){
        boolean isEdit=newenergyInfrastructure.getId()==null?false:true;
        ResultState resultState=msEnergyService.add(newenergyInfrastructure,isEdit);
        return resultState;
     }

     @RequestMapping(value="addCoalConsume.action")
     @ResponseBody
     public ResultState addCoalConsume(CoalConsume coalConsume){
        boolean isEdit=coalConsume.getId()==null?false:true;
        ResultState resultState=msEnergyService.add(coalConsume,isEdit);
        return resultState;
     }

     @RequestMapping(value="addElectricConsume.action")
     @ResponseBody
     public ResultState addCoalConsume(ElectricConsume electricConsume){
        boolean isEdit=electricConsume.getId()==null?false:true;
        ResultState resultState=msEnergyService.add(electricConsume,isEdit);
        return resultState;
     }


}
