package com.mvc.controller;

import com.mvc.model.TRgeAuthModel;
import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.service.TRgeAuthService;
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.Map;

@Api(tags = "用户注册授权表控制类")
@RequestMapping("/TRgeAuthAction")
@Controller
public class TRgeAuthAction {

    @Autowired
    private TRgeAuthService tRgeAuthService;
    
    @ApiOperation("分页查询用户注册授权表")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findAllTRgeAuth(@RequestBody TRgeAuthModel model){
        try {
            Map<String,Object> res= tRgeAuthService.findAllTRgeAuth(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 = "/saveTRgeAuth",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveTRgeAuth(@RequestBody TRgeAuthModel model){
        try {
            TRgeAuthModel resModel= tRgeAuthService.saveTRgeAuth(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 = "/updateTRgeAuth",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody TRgeAuthModel model){
        try {
            TRgeAuthModel resModel= tRgeAuthService.updateTRgeAuth(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 = "/deleteTRgeAuth/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteTRgeAuth(@PathVariable("id") int id){
        try {
            int  res= tRgeAuthService.deleteTRgeAuth(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;
        }
    }
}
