package com.mvc.controller.taizhang;


import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.StationGroupModel;
import com.mvc.othermodel.GroupAndStationTree;
import com.mvc.service.taizhang.StationGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "遥测站分组接口")
@RequestMapping("/StationGroupAction")
@Controller
public class StationGroupAction {

    @Autowired
    private StationGroupService stationGroupService;



    @ApiOperation("查询遥测站分组")
    @RequestMapping(value = "/fingStationGroup/{customerId}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> fingStationGroup(@PathVariable("customerId") String customerId){

        try {
            List<StationGroupModel> resList= stationGroupService.findStationGroup(customerId);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resList);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }


    @ApiOperation("查询遥测站分组和遥测站树")
    @RequestMapping(value = "/fingStationGroupAndStation/{customerId}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> fingStationGroupAndStation(@PathVariable("customerId") String customerId){

        try {
            List<GroupAndStationTree> resList= stationGroupService.fingStationGroupAndStation(customerId);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resList);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }


    @ApiOperation("新增遥测站分组")
    @RequestMapping(value = "/saveStationGroup",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveStationGroup(@RequestBody StationGroupModel model){
        try {
            StationGroupModel resModel= stationGroupService.saveStationGroup(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resModel);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("更新遥测站分组")
    @RequestMapping(value = "/updateStationGroup",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody StationGroupModel model){
        try {
            StationGroupModel resModel= stationGroupService.updateStationGroup(model);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",resModel);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }

    @ApiOperation("删除遥测站分组")
    @RequestMapping(value = "/deleteStationGroup/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteStationGroup(@PathVariable("id") int id){
        try {
            int  res= stationGroupService.deleteStationGroup(id);
            Map<String,Object> resMap=new CorrectMap();
            resMap.put("res",res);
            return resMap;
        } catch (Exception e) {
            e.printStackTrace();
            Map<String,Object> resMap=new ErrorMap();
            resMap.put("error",e.getMessage());
            return resMap;
        }
    }
}
