package com.mvc.controller.ysfx;

import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.ysfx.TStationStructureModel;
import com.mvc.service.ysfx.TStationStructureService;
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("/TStationStructureAction")
@Controller
public class TStationStructureAction {

    @Autowired
    private TStationStructureService tStationStructureService;

    @ApiOperation("查询所有站点结构")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findAllTStationStructure(){

        try {
            List<TStationStructureModel> resList = tStationStructureService.findAllTStationStructure();
            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 = "/saveTStationStructure",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveTStationStructure(@RequestBody TStationStructureModel model){
        try {
            TStationStructureModel resModel= tStationStructureService.saveTStationStructure(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 = "/updateTStationStructure",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody TStationStructureModel model){
        try {
            TStationStructureModel resModel= tStationStructureService.updateTStationStructure(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 = "/deleteTStationStructure/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteTStationStructure(@PathVariable("id") int id){
        try {
            int  res= tStationStructureService.deleteTStationStructure(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;
        }
    }

    @ApiOperation("根据代码码查询站点结构")
    @RequestMapping(value = "/findStationStruViewModelsByUnitCode/{unitCode}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> findStationStruViewModelsByUnitCode(@PathVariable("unitCode") String unitCode){
        try {
            var res= tStationStructureService.findStationStruViewModelsByUnitCode(unitCode);
            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;
        }
    }

    @ApiOperation("根据站代码获取树形结构数据(节水项目)")
    @RequestMapping(value = "/getStructuresTreeDataByUnitCode/{unitCode}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> getStructuresTreeDataByUnitCode(@PathVariable("unitCode") String unitCode){
        try {
            var res= tStationStructureService.getStructuresTreeDataByUnitCode(unitCode);
            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;
        }
    }
}
