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.model.ms.GarbageRegionModel;
import com.lightinit.hsdatashow.service.ms.IMSAtmosphereService;
import com.lightinit.hsdatashow.service.ms.IMSWaterQualityService;
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/waterQuality")
public class MSWaterQualityController extends BaseController {
    private static LinkedHashMap<String,String> getChartTable(){
        LinkedHashMap<String, String> map = new LinkedHashMap<>();
        map.put("水质达标率","WaterqualityHandle");
        map.put("地表水按水域功能类型占比","WaterqualitySurface");
        map.put("城市污水处理率","WaterqualityCityHandle");
        map.put("重点污染源工业废水排放","WaterqualityIndustry");
       // map.put("集中式饮用水水源地水质情况","WaterqualityFocus");
        return map;
    }
    @Autowired
    private IMSWaterQualityService imsEcologicalCivilizationService;
    @RequestMapping(value="index.htm")
    public ModelAndView index(){
        ModelAndView modelAndView = new ModelAndView("ms/waterQuality/index");
        modelAndView.addObject("chartTable",getChartTable());
        return modelAndView;
    }

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

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

    @RequestMapping(value="addWaterqualityHandle.action")
    @ResponseBody
    public ResultState addWaterqualityHandle(WaterqualityHandle waterqualityHandle){
        boolean isEdit=waterqualityHandle.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.add(waterqualityHandle,isEdit);
        return resultState;
    }

    @RequestMapping(value="addWaterqualityCityHandle.action")
    @ResponseBody
    public ResultState addWaterqualityCityHandle(WaterqualityCityHandle waterqualityCityHandle){
        boolean isEdit=waterqualityCityHandle.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.add(waterqualityCityHandle,isEdit);
        return resultState;
    }

    @RequestMapping(value="addWaterqualityIndustry.action")
    @ResponseBody
    public ResultState addWaterqualityIndustry(WaterqualityIndustry waterqualityIndustry){
        boolean isEdit=waterqualityIndustry.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.add(waterqualityIndustry,isEdit);
        return resultState;
    }

    @RequestMapping(value="addWaterqualitySurface.action")
    @ResponseBody
    public ResultState addWaterqualitySurface(WaterqualitySurface waterqualitySurface){
        boolean isEdit=waterqualitySurface.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.add(waterqualitySurface,isEdit);
        return resultState;
    }

//    @RequestMapping(value="addWaterqualityFocus.action")
//    @ResponseBody
//    public ResultState addWaterqualityFocus(WaterqualityFocus waterqualityFocus){
//        boolean isEdit=waterqualityFocus.getId()==null?false:true;
//        ResultState resultState=imsEcologicalCivilizationService.add(waterqualityFocus,isEdit);
//        return resultState;
//    }

    @RequestMapping(value="reginIndex.htm")
    public ModelAndView reginIndex(){
        ModelAndView modelAndView = new ModelAndView("ms/waterQuality/reginIndex");
        return modelAndView;
    }


    @RequestMapping(value="regionList.action")
    public ModelAndView reginList(String tableType,int pageNo){
        ModelAndView modelAndView=new ModelAndView("ms/waterQuality/regionList");
        BaseExample.Page pager = new BaseExample.Page();
        pager.setPageNo(pageNo);
        List<GarbageRegionModel> list=imsEcologicalCivilizationService.regionList(pager);
        long total=imsEcologicalCivilizationService.regionCount(pager);
        pager.setTotal(total);
        modelAndView.addObject("list",list);
        modelAndView.addObject("pager",pager);
        return modelAndView;
    }

    @RequestMapping(value="regionAdd.htm")
    public ModelAndView reginAdd( Long id){
        ModelAndView modelAndView=new ModelAndView("ms/waterQuality/regionAdd");
        GarbageRegionModel garbageRegionModel =imsEcologicalCivilizationService.findByRegionId(id);
        modelAndView.addObject("outputModel",garbageRegionModel);
        return modelAndView;
    }


    @RequestMapping(value="add.action")
    @ResponseBody
    public ResultState add(GarbageRegionModel garbageRegionModel){
        boolean isEdit=garbageRegionModel.getId()==null?false:true;
        ResultState resultState=imsEcologicalCivilizationService.doAdd(garbageRegionModel,isEdit);
        return resultState;
    }

    @RequestMapping(value="del.action")
    @ResponseBody
    public ResultState del(Long id,Long regionId) {
        ResultState resultState =imsEcologicalCivilizationService.del(id,regionId);
        return resultState;
    }

}
