升级支持Spring Cloud 2023+Spring Boot 3.2+JDK 17
This commit is contained in:
@@ -1,20 +1,21 @@
|
||||
package com.macro.mall.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.macro.mall.common.api.CommonPage;
|
||||
import com.macro.mall.common.api.CommonResult;
|
||||
import com.macro.mall.common.domain.UserDto;
|
||||
import com.macro.mall.dto.UmsAdminLoginParam;
|
||||
import com.macro.mall.dto.UmsAdminParam;
|
||||
import com.macro.mall.dto.UpdateAdminPasswordParam;
|
||||
import com.macro.mall.model.UmsAdmin;
|
||||
import com.macro.mall.model.UmsPermission;
|
||||
import com.macro.mall.model.UmsRole;
|
||||
import com.macro.mall.service.UmsAdminService;
|
||||
import com.macro.mall.service.UmsRoleService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -29,15 +30,17 @@ import java.util.stream.Collectors;
|
||||
* Created by macro on 2018/4/26.
|
||||
*/
|
||||
@Controller
|
||||
@Api(tags = "UmsAdminController", description = "后台用户管理")
|
||||
@Tag(name = "UmsAdminController", description = "后台用户管理")
|
||||
@RequestMapping("/admin")
|
||||
public class UmsAdminController {
|
||||
@Autowired
|
||||
private UmsAdminService adminService;
|
||||
@Autowired
|
||||
private UmsRoleService roleService;
|
||||
@Value("${sa-token.token-prefix}")
|
||||
private String tokenHead;
|
||||
|
||||
@ApiOperation(value = "用户注册")
|
||||
@Operation(summary = "用户注册")
|
||||
@RequestMapping(value = "/register", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult<UmsAdmin> register(@Validated @RequestBody UmsAdminParam umsAdminParam) {
|
||||
@@ -48,14 +51,21 @@ public class UmsAdminController {
|
||||
return CommonResult.success(umsAdmin);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "登录以后返回token")
|
||||
@Operation(summary = "登录以后返回token")
|
||||
@RequestMapping(value = "/login", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult login(@Validated @RequestBody UmsAdminLoginParam umsAdminLoginParam) {
|
||||
return adminService.login(umsAdminLoginParam.getUsername(),umsAdminLoginParam.getPassword());
|
||||
SaTokenInfo saTokenInfo = adminService.login(umsAdminLoginParam.getUsername(), umsAdminLoginParam.getPassword());
|
||||
if (saTokenInfo == null) {
|
||||
return CommonResult.validateFailed("用户名或密码错误");
|
||||
}
|
||||
Map<String, String> tokenMap = new HashMap<>();
|
||||
tokenMap.put("token", saTokenInfo.getTokenValue() );
|
||||
tokenMap.put("tokenHead", tokenHead+" ");
|
||||
return CommonResult.success(tokenMap);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "获取当前登录用户信息")
|
||||
@Operation(summary = "获取当前登录用户信息")
|
||||
@RequestMapping(value = "/info", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult getAdminInfo() {
|
||||
@@ -72,14 +82,15 @@ public class UmsAdminController {
|
||||
return CommonResult.success(data);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "登出功能")
|
||||
@Operation(summary = "登出功能")
|
||||
@RequestMapping(value = "/logout", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult logout() {
|
||||
adminService.logout();
|
||||
return CommonResult.success(null);
|
||||
}
|
||||
|
||||
@ApiOperation("根据用户名或姓名分页获取用户列表")
|
||||
@Operation(summary = "根据用户名或姓名分页获取用户列表")
|
||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<CommonPage<UmsAdmin>> list(@RequestParam(value = "keyword", required = false) String keyword,
|
||||
@@ -89,7 +100,7 @@ public class UmsAdminController {
|
||||
return CommonResult.success(CommonPage.restPage(adminList));
|
||||
}
|
||||
|
||||
@ApiOperation("获取指定用户信息")
|
||||
@Operation(summary = "获取指定用户信息")
|
||||
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<UmsAdmin> getItem(@PathVariable Long id) {
|
||||
@@ -97,7 +108,7 @@ public class UmsAdminController {
|
||||
return CommonResult.success(admin);
|
||||
}
|
||||
|
||||
@ApiOperation("修改指定用户信息")
|
||||
@Operation(summary = "修改指定用户信息")
|
||||
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult update(@PathVariable Long id, @RequestBody UmsAdmin admin) {
|
||||
@@ -108,7 +119,7 @@ public class UmsAdminController {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
@ApiOperation("修改指定用户密码")
|
||||
@Operation(summary = "修改指定用户密码")
|
||||
@RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult updatePassword(@RequestBody UpdateAdminPasswordParam updatePasswordParam) {
|
||||
@@ -126,7 +137,7 @@ public class UmsAdminController {
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("删除指定用户信息")
|
||||
@Operation(summary = "删除指定用户信息")
|
||||
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult delete(@PathVariable Long id) {
|
||||
@@ -137,7 +148,7 @@ public class UmsAdminController {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
@ApiOperation("修改帐号状态")
|
||||
@Operation(summary = "修改帐号状态")
|
||||
@RequestMapping(value = "/updateStatus/{id}", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult updateStatus(@PathVariable Long id,@RequestParam(value = "status") Integer status) {
|
||||
@@ -150,7 +161,7 @@ public class UmsAdminController {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
@ApiOperation("给用户分配角色")
|
||||
@Operation(summary = "给用户分配角色")
|
||||
@RequestMapping(value = "/role/update", method = RequestMethod.POST)
|
||||
@ResponseBody
|
||||
public CommonResult updateRole(@RequestParam("adminId") Long adminId,
|
||||
@@ -162,19 +173,11 @@ public class UmsAdminController {
|
||||
return CommonResult.failed();
|
||||
}
|
||||
|
||||
@ApiOperation("获取指定用户的角色")
|
||||
@Operation(summary = "获取指定用户的角色")
|
||||
@RequestMapping(value = "/role/{adminId}", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public CommonResult<List<UmsRole>> getRoleList(@PathVariable Long adminId) {
|
||||
List<UmsRole> roleList = adminService.getRoleList(adminId);
|
||||
return CommonResult.success(roleList);
|
||||
}
|
||||
|
||||
@ApiOperation("根据用户名获取通用用户信息")
|
||||
@RequestMapping(value = "/loadByUsername", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public UserDto loadUserByUsername(@RequestParam String username) {
|
||||
UserDto userDTO = adminService.loadUserByUsername(username);
|
||||
return userDTO;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user