package com.mvc.controller.dic;


import com.mvc.model.CorrectMap;
import com.mvc.model.ErrorMap;
import com.mvc.model.DicConfigAuthModel;
import com.mvc.service.dic.DicConfigAuthService;
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("/DicConfigAuthAction")
@Controller
public class DicConfigAuthAction {

    @Autowired
    private DicConfigAuthService dicConfigAuthService;

    @ApiOperation("分页查询配置权限字典")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findAllDicConfigAuth(@RequestBody DicConfigAuthModel model){
        try {
            Map<String,Object> res= dicConfigAuthService.findAllDicConfigAuth(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 = "/saveDicConfigAuth",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveDicConfigAuth(@RequestBody DicConfigAuthModel model){
        try {
            DicConfigAuthModel resModel= dicConfigAuthService.saveDicConfigAuth(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 = "/updateDicConfigAuth",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateDeviceAcc(@RequestBody DicConfigAuthModel model){
        try {
            DicConfigAuthModel resModel= dicConfigAuthService.updateDicConfigAuth(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 = "/deleteDicConfigAuth/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteDicConfigAuth(@PathVariable("id") int id){
        try {
            int  res= dicConfigAuthService.deleteDicConfigAuth(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;
        }
    }
}
