添加权限管理功能
This commit is contained in:
@@ -9,18 +9,15 @@ import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.security.Principal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -59,9 +56,9 @@ public class UmsAdminController {
|
||||
if (token == null) {
|
||||
return new CommonResult().validateFailed("用户名或密码错误");
|
||||
}
|
||||
Map<String,String> tokenMap = new HashMap<>();
|
||||
tokenMap.put("token",token);
|
||||
tokenMap.put("tokenHead",tokenHead);
|
||||
Map<String, String> tokenMap = new HashMap<>();
|
||||
tokenMap.put("token", token);
|
||||
tokenMap.put("tokenHead", tokenHead);
|
||||
return new CommonResult().success(tokenMap);
|
||||
}
|
||||
|
||||
@@ -74,28 +71,69 @@ public class UmsAdminController {
|
||||
if (refreshToken == null) {
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
Map<String,String> tokenMap = new HashMap<>();
|
||||
tokenMap.put("token",token);
|
||||
tokenMap.put("tokenHead",tokenHead);
|
||||
Map<String, String> tokenMap = new HashMap<>();
|
||||
tokenMap.put("token", token);
|
||||
tokenMap.put("tokenHead", tokenHead);
|
||||
return new CommonResult().success(tokenMap);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取用户信息")
|
||||
@RequestMapping(value = "/info",method = RequestMethod.GET)
|
||||
@ApiOperation(value = "获取当前登录用户信息")
|
||||
@RequestMapping(value = "/info", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object getAdminInfo(Principal principal){
|
||||
public Object getAdminInfo(Principal principal) {
|
||||
String username = principal.getName();
|
||||
UmsAdmin umsAdmin = adminService.getAdminByUsername(username);
|
||||
Map<String,Object> data = new HashMap<>();
|
||||
data.put("username",umsAdmin.getUsername());
|
||||
data.put("roles",new String[]{"TEST"});
|
||||
data.put("icon",umsAdmin.getIcon());
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("username", umsAdmin.getUsername());
|
||||
data.put("roles", new String[]{"TEST"});
|
||||
data.put("icon", umsAdmin.getIcon());
|
||||
return new CommonResult().success(data);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "登出功能")
|
||||
@RequestMapping(value = "/logout",method = RequestMethod.POST)
|
||||
@RequestMapping(value = "/logout", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object logout(){
|
||||
public Object logout() {
|
||||
return new CommonResult().success(null);
|
||||
}
|
||||
|
||||
@ApiOperation("根据用户名或姓名分页获取用户列表")
|
||||
@RequestMapping(value = "/list",method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object list(@RequestParam("name") String name,
|
||||
@RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
|
||||
@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum){
|
||||
List<UmsAdmin> adminList = adminService.list(name,pageSize,pageNum);
|
||||
return new CommonResult().pageSuccess(adminList);
|
||||
}
|
||||
|
||||
@ApiOperation("获取指定用户信息")
|
||||
@RequestMapping(value = "/{id}",method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public Object getItem(@PathVariable Long id){
|
||||
UmsAdmin admin = adminService.getItem(id);
|
||||
return new CommonResult().success(admin);
|
||||
}
|
||||
|
||||
@ApiOperation("获取指定用户信息")
|
||||
@RequestMapping(value = "/update/{id}",method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object update(@PathVariable Long id,@RequestBody UmsAdmin admin){
|
||||
int count = adminService.update(id,admin);
|
||||
if(count>0){
|
||||
return new CommonResult().success(count);
|
||||
}
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
|
||||
@ApiOperation("删除指定用户信息")
|
||||
@RequestMapping(value = "/delete/{id}",method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public Object delete(@PathVariable Long id){
|
||||
int count = adminService.delete(id);
|
||||
if(count>0){
|
||||
return new CommonResult().success(count);
|
||||
}
|
||||
return new CommonResult().failed();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user