package com.mvc.controller.dic;

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

    @Autowired
    private FacUserRoleService facUserRoleService;

    @ApiOperation("查询所有内部用户角色")
    @RequestMapping(value = "/list",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> findAllFacUserRole(@RequestBody FacUserRoleModel model){
        try {
            List<FacUserRoleModel> resList = facUserRoleService.findAllFacUserRole(model);
            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 = "/saveFacUserRole",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> saveFacUserRole(@RequestBody FacUserRoleModel model){
        try {
            FacUserRoleModel resModel= facUserRoleService.saveFacUserRole(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 = "/updateFacUserRole",method = RequestMethod.POST)
    @ResponseBody
    public Map<String,Object> updateFacUserRole(@RequestBody FacUserRoleModel model){
        try {
            FacUserRoleModel resModel= facUserRoleService.updateFacUserRole(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 = "/deleteFacUserRole/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> deleteFacUserRole(@PathVariable("id") int id){
        try {
            int  res= facUserRoleService.deleteFacUserRole(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;
        }
    }
}
