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.IMSTourismCultureService;
import com.lightinit.hsdatashow.service.ms.IMSTrafficTravelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
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.LinkedHashMap;
import java.util.List;

@Controller
@RequestMapping("/ms/TourismCulture")
public class MSTourismCultureController extends BaseController {
    @Autowired
    private IMSTourismCultureService imsTourismCultureService;

    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("基础公共文化设施","CulturalFacilities");
        map.put("传播途径及范围","Spread");
        map.put("居民文旅消费","Consumption");
        map.put("文旅企业,人员，产值","Industry");
        map.put("文旅产值占比","OutputValueRatio");
        return map;
    }
    @RequestMapping(value="index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/tourismCulture/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

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

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

    @RequestMapping(value="addCulturalFacilities.action")
    @ResponseBody
    public ResultState addCulturalFacilities(CulturalFacilities culturalFacilities){
        boolean isEdit=culturalFacilities.getId()==null?false:true;
        ResultState resultState=imsTourismCultureService.add(culturalFacilities,isEdit);
        return resultState;
    }

    @RequestMapping(value="addSpread.action")
    @ResponseBody
    public ResultState addSpread(Spread spread){
        boolean isEdit=spread.getId()==null?false:true;
        ResultState resultState=imsTourismCultureService.add(spread,isEdit);
        return resultState;
    }

    @RequestMapping(value="addConsumption.action")
    @ResponseBody
    public ResultState addConsumption(Consumption consumption){
        boolean isEdit=consumption.getId()==null?false:true;
        ResultState resultState=imsTourismCultureService.add(consumption,isEdit);
        return resultState;
    }
    @RequestMapping(value="addIndustry.action")
    @ResponseBody
    public ResultState addIndustry(Industry industry){
        boolean isEdit=industry.getId()==null?false:true;
        ResultState resultState=imsTourismCultureService.add(industry,isEdit);
        return resultState;
    }

    @RequestMapping(value="addOutputValueRatio.action")
    @ResponseBody
    public ResultState addOutputValueRatio(OutputValueRatio outputValueRatio){
        boolean isEdit=outputValueRatio.getId()==null?false:true;
        ResultState resultState=imsTourismCultureService.add(outputValueRatio,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;
//    }


}
