package com.mvc.controller.forwarding;

import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.forwarding.DicForwarderModel;
import com.mvc.service.forwarding.DicForwarderService;
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("/DicForwarderAction")
@Controller
public class DicForwarderAction {

    @Resource
    private DicForwarderService dicForwarderService;
    
    @ApiOperation("查询数据转发字典表")
    @RequestMapping(value = "/findAllDicForwarder",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findAllDicForwarder(){
        try {
            List<DicForwarderModel> res= dicForwarderService.findAllDicForwarder();
            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 = "/saveDicForwarder",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveDicForwarder(@RequestBody DicForwarderModel model){
        try {
            DicForwarderModel resModel= dicForwarderService.saveDicForwarder(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 = "/updateDicForwarder",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody DicForwarderModel model){
        try {
            DicForwarderModel resModel= dicForwarderService.updateDicForwarder(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 = "/deleteDicForwarder/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteDicForwarder(@PathVariable("id") int id){
        try {
            int  res= dicForwarderService.deleteDicForwarder(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;
        }
    }
}
