package com.mvc.controller.forwarding;

import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.forwarding.TForwarderStationModel;
import com.mvc.service.forwarding.TForwarderStationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Api(tags = "数据转发站点表控制类")
@RequestMapping("/TForwarderStationAction")
@Controller
public class TForwarderStationAction {

    @Resource
    private TForwarderStationService tForwarderStationService;

    @ApiOperation("查询数据转发站点表")
    @RequestMapping(value = "/findAllTForwarderStation", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> findAllTForwarderStation(@RequestBody TForwarderStationModel model) {
        try {
            List<TForwarderStationModel> res = tForwarderStationService.findAllTForwarderStation(model);
            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 = "/saveTForwarderStation", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> saveTForwarderStation(@RequestBody TForwarderStationModel model) {
        try {
            TForwarderStationModel resModel = tForwarderStationService.saveTForwarderStation(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 = "/updateTForwarderStation", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> updateDeviceAcc(@RequestBody TForwarderStationModel model) {
        try {
            TForwarderStationModel resModel = tForwarderStationService.updateTForwarderStation(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 = "/deleteTForwarderStation/{id}", method = RequestMethod.GET)
    @ResponseBody
    public Map<String, Object> deleteTForwarderStation(@PathVariable("id") int id) {
        try {
            int res = tForwarderStationService.deleteTForwarderStation(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;
        }
    }
}
