package com.lxzn.ucenter.controller;
|
|
import com.lxzn.api.ucenter.RoleControllerApi;
|
import com.lxzn.framework.domain.ucenter.*;
|
import com.lxzn.framework.domain.ucenter.request.RoleRequest;
|
import com.lxzn.framework.model.response.*;
|
import com.lxzn.ucenter.service.IRoleService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.Collections;
|
import java.util.List;
|
|
@RestController
|
@RequestMapping("/ucenter/role")
|
public class RoleController implements RoleControllerApi {
|
@Autowired
|
private IRoleService roleService;
|
|
@Override
|
@PostMapping("/add")
|
public ResponseResult addRole(@RequestBody Role role) {
|
boolean b = roleService.addRole(role);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@PutMapping("/edit/{id}")
|
public ResponseResult editRole(@PathVariable("id") String id, @RequestBody Role role) {
|
boolean b = roleService.editRole(id ,role);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@PostMapping("/assign/menu/{roleId}")
|
public ResponseResult assignMenus(@PathVariable("roleId") String roleId, @RequestBody String[] menuIds) {
|
boolean b = roleService.assignMenus(roleId, menuIds);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@PostMapping("/assign/button/{roleId}")
|
public ResponseResult assignSysButton(@PathVariable("roleId") String roleId, @RequestBody String[] buttonIds) {
|
boolean b = roleService.assignSysButton(roleId, buttonIds);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@PostMapping("/assign/menu/button/{roleId}")
|
public ResponseResult assignMenuButton(@PathVariable("roleId") String roleId, @RequestBody String[] menuButtonIds) {
|
boolean b = roleService.assignMenuButton(roleId, menuButtonIds);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@PostMapping("/assign/obj/button/{roleId}")
|
public ResponseResult assignObjectButton(@PathVariable("roleId") String roleId, @RequestBody String[] objectButtonIds) {
|
boolean b = roleService.assignObjectButton(roleId, objectButtonIds);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
|
@Override
|
@GetMapping("/perm/select/non/{userId}")
|
public QueryListResponseResult<Role> getUserNonPermRole(@PathVariable("userId") String userId) {
|
List<Role> list = roleService.getUserNonPermRole(userId);
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
|
}
|
|
@Override
|
@GetMapping("/perm/select/{userId}")
|
public QueryListResponseResult<Role> getUserPermRole(@PathVariable("userId") String userId) {
|
List<Role> list = roleService.getUserPermRole(userId);
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
|
}
|
|
@Override
|
@GetMapping("/find/page/{page}/{size}")
|
public QueryPageResponseResult<Role> findPageList(@PathVariable("page") int page, @PathVariable("size") int size, RoleRequest roleRequest) {
|
return roleService.findPageList(page, size, roleRequest);
|
}
|
|
@Override
|
@GetMapping("/get/menu/button/{roleId}")
|
public QueryListResponseResult<CommonJsonTree> getMenuButtonTree(@PathVariable("roleId") String roleId) {
|
List<CommonJsonTree> commonJsonTree = roleService.getMenuButtonTree(roleId);
|
if(commonJsonTree == null)
|
commonJsonTree = Collections.emptyList();
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, commonJsonTree);
|
}
|
|
@Override
|
@GetMapping("/get/object/button/{roleId}")
|
public QueryListResponseResult<CommonJsonTree> getObjectButtonTree(@PathVariable("roleId") String roleId) {
|
List<CommonJsonTree> commonJsonTree = roleService.getObjectButtonTree(roleId);
|
if(commonJsonTree == null)
|
commonJsonTree = Collections.emptyList();
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, commonJsonTree);
|
}
|
|
@Override
|
@GetMapping("/get/menu/{roleId}")
|
public QueryListResponseResult<CommonJsonTree> getMenuTree(@PathVariable("roleId") String roleId) {
|
List<CommonJsonTree> commonJsonTree = roleService.getMenuTree(roleId);
|
if(commonJsonTree == null)
|
commonJsonTree = Collections.emptyList();
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, commonJsonTree);
|
}
|
|
@Override
|
@GetMapping("/list/all")
|
public QueryListResponseResult<Role> getRoleList() {
|
List<Role> list = roleService.list();
|
if(list == null)
|
list = Collections.emptyList();
|
return new QueryListResponseResult<>(CommonCode.SUCCESS, list);
|
}
|
|
@Override
|
@DeleteMapping("/delete")
|
public ResponseResult deleteRole(@RequestParam("id") String id) {
|
boolean b = roleService.deleteRole(id);
|
if(b) {
|
return new ResponseResult(CommonCode.SUCCESS);
|
}
|
return new ResponseResult(CommonCode.FAIL);
|
}
|
}
|