角色管理

master
王皓雯 6 years ago
parent 7c80ded0b2
commit f3df99688a

@ -0,0 +1,86 @@
package com.macro.mall.controller;
import com.macro.mall.dto.CommonResult;
import com.macro.mall.model.UmsPermission;
import com.macro.mall.model.UmsRole;
import com.macro.mall.service.UmsRoleService;
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;
/**
*
*/
@Controller
@Api(tags = "UmsRoleController", description = "后台用户角色管理")
@RequestMapping("/role")
public class UmsRoleController {
@Autowired
private UmsRoleService roleService;//角色服务
@ApiOperation("添加角色")
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public Object create(@RequestBody UmsRole role) {
int count = roleService.create(role);
if(count>0){
return new CommonResult().success(count);
}
return new CommonResult().failed();
}
@ApiOperation("修改角色")
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
@ResponseBody
public Object update(@PathVariable Long id, @RequestBody UmsRole role) {
int count = roleService.update(id,role);
if(count>0){
return new CommonResult().success(count);
}
return new CommonResult().failed();
}
@ApiOperation("批量删除角色")
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
public Object delete(@RequestParam("ids") List<Long> ids) {//根据id删除角色
int count = roleService.delete(ids);
if(count>0){
return new CommonResult().success(count);
}
return new CommonResult().failed();
}
@ApiOperation("获取相应角色权限")
@RequestMapping(value = "/permission/{roleId}", method = RequestMethod.GET)//角色权限
@ResponseBody
public Object getPermissionList(@PathVariable Long roleId) {
List<UmsPermission> permissionList =roleService.getPermissionList(roleId);
return new CommonResult().success(permissionList);
}
@ApiOperation("修改角色权限")
@RequestMapping(value = "/permission/update", method = RequestMethod.POST)
@ResponseBody
public Object updatePermission(@RequestParam Long roleId,
@RequestParam("permissionIds") List<Long> permissionIds) {
int count = roleService.updatePermission(roleId,permissionIds);
if(count>0){
return new CommonResult().success(count);
}
return new CommonResult().failed();
}
@ApiOperation("获取所有角色")
@RequestMapping(value = "/list",method = RequestMethod.GET)
@ResponseBody
public Object list(){
List<UmsRole> roleList = roleService.list();
return new CommonResult().success(roleList);
}
}
Loading…
Cancel
Save