Skip to content

Commit

Permalink
revert: 回退全局响应结果处理器
Browse files Browse the repository at this point in the history
1.影响 API 文档生成
2.其他已知及未知影响
  • Loading branch information
Charles7c committed Nov 28, 2023
1 parent 8c1c4b0 commit c7a4e32
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 134 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import top.charles7c.cnadmin.system.service.UserService;
import top.charles7c.continew.starter.cache.redisson.util.RedisUtils;
import top.charles7c.continew.starter.core.util.ExceptionUtils;
import top.charles7c.continew.starter.extension.crud.model.resp.R;
import top.charles7c.continew.starter.extension.crud.util.validate.ValidationUtils;

/**
Expand All @@ -69,7 +70,7 @@ public class AuthController {
@SaIgnore
@Operation(summary = "账号登录", description = "根据账号和密码进行登录认证")
@PostMapping("/account")
public LoginResp accountLogin(@Validated @RequestBody AccountLoginReq loginReq) {
public R<LoginResp> accountLogin(@Validated @RequestBody AccountLoginReq loginReq) {
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, loginReq.getUuid());
String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, "验证码已失效");
Expand All @@ -79,62 +80,64 @@ public LoginResp accountLogin(@Validated @RequestBody AccountLoginReq loginReq)
String rawPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(loginReq.getPassword()));
ValidationUtils.throwIfBlank(rawPassword, "密码解密失败");
String token = loginService.accountLogin(loginReq.getUsername(), rawPassword);
return LoginResp.builder().token(token).build();
return R.ok(LoginResp.builder().token(token).build());
}

@SaIgnore
@Operation(summary = "邮箱登录", description = "根据邮箱和验证码进行登录认证")
@PostMapping("/email")
public LoginResp emailLogin(@Validated @RequestBody EmailLoginReq loginReq) {
public R<LoginResp> emailLogin(@Validated @RequestBody EmailLoginReq loginReq) {
String email = loginReq.getEmail();
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, email);
String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, "验证码已失效");
ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, "验证码错误");
RedisUtils.delete(captchaKey);
String token = loginService.emailLogin(email);
return LoginResp.builder().token(token).build();
return R.ok(LoginResp.builder().token(token).build());
}

@SaIgnore
@Operation(summary = "手机号登录", description = "根据手机号和验证码进行登录认证")
@PostMapping("/phone")
public LoginResp phoneLogin(@Validated @RequestBody PhoneLoginReq loginReq) {
public R<LoginResp> phoneLogin(@Validated @RequestBody PhoneLoginReq loginReq) {
String phone = loginReq.getPhone();
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, phone);
String captcha = RedisUtils.get(captchaKey);
ValidationUtils.throwIfBlank(captcha, "验证码已失效");
ValidationUtils.throwIfNotEqualIgnoreCase(loginReq.getCaptcha(), captcha, "验证码错误");
RedisUtils.delete(captchaKey);
String token = loginService.phoneLogin(phone);
return LoginResp.builder().token(token).build();
return R.ok(LoginResp.builder().token(token).build());
}

@Operation(summary = "用户退出", description = "注销用户的当前登录")
@Parameter(name = "Authorization", description = "令牌", required = true, example = "Bearer xxxx-xxxx-xxxx-xxxx",
in = ParameterIn.HEADER)
@PostMapping("/logout")
public void logout() {
public R logout() {
StpUtil.logout();
return R.ok();
}

@Log(ignore = true)
@Operation(summary = "获取用户信息", description = "获取登录用户信息")
@GetMapping("/user/info")
public UserInfoResp getUserInfo() {
public R<UserInfoResp> getUserInfo() {
LoginUser loginUser = LoginHelper.getLoginUser();
UserDetailResp userDetailResp = userService.get(loginUser.getId());
UserInfoResp userInfoResp = BeanUtil.copyProperties(userDetailResp, UserInfoResp.class);
userInfoResp.setPermissions(loginUser.getPermissions());
userInfoResp.setRoles(loginUser.getRoleCodes());
return userInfoResp;
return R.ok(userInfoResp);
}

@Log(ignore = true)
@Operation(summary = "获取路由信息", description = "获取登录用户的路由信息")
@GetMapping("/route")
public List<RouteResp> listRoute() {
public R<List<RouteResp>> listRoute() {
Long userId = LoginHelper.getUserId();
return loginService.buildRouteTree(userId);
List<RouteResp> routeTree = loginService.buildRouteTree(userId);
return R.ok(routeTree);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public R authorize(@PathVariable String source) {
@Operation(summary = "三方账号登录", description = "三方账号登录")
@Parameter(name = "source", description = "来源", example = "gitee", in = ParameterIn.PATH)
@PostMapping("/{source}")
public LoginResp login(@PathVariable String source, @RequestBody AuthCallback callback) {
public R<LoginResp> login(@PathVariable String source, @RequestBody AuthCallback callback) {
if (StpUtil.isLogin()) {
StpUtil.logout();
}
Expand All @@ -80,7 +80,7 @@ public LoginResp login(@PathVariable String source, @RequestBody AuthCallback ca
ValidationUtils.throwIf(!response.ok(), response.getMsg());
AuthUser authUser = response.getData();
String token = loginService.socialLogin(authUser);
return LoginResp.builder().token(token).build();
return R.ok(LoginResp.builder().token(token).build());
}

private AuthRequest getAuthRequest(String source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public class CaptchaController {

@Operation(summary = "获取图片验证码", description = "获取图片验证码(Base64编码,带图片格式:data:image/gif;base64)")
@GetMapping("/img")
public CaptchaResp getImageCaptcha() {
public R<CaptchaResp> getImageCaptcha() {
Captcha captcha = graphicCaptchaProperties.getCaptcha();
String uuid = IdUtil.fastUUID();
String captchaKey = RedisUtils.formatKey(CacheConstants.CAPTCHA_KEY_PREFIX, uuid);
RedisUtils.set(captchaKey, captcha.text(), Duration.ofMinutes(captchaProperties.getExpirationInMinutes()));
return CaptchaResp.builder().uuid(uuid).img(captcha.toBase64()).build();
return R.ok(CaptchaResp.builder().uuid(uuid).img(captcha.toBase64()).build());
}

@Operation(summary = "获取邮箱验证码", description = "发送验证码到指定邮箱")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,39 +97,42 @@ public R<String> upload(@NotNull(message = "文件不能为空") MultipartFile f

@Operation(summary = "查询部门树", description = "查询树结构的部门列表")
@GetMapping("/tree/dept")
public List<Tree<Long>> listDeptTree(DeptQuery query, SortQuery sortQuery) {
return deptService.tree(query, sortQuery, true);
public R<List<Tree<Long>>> listDeptTree(DeptQuery query, SortQuery sortQuery) {
List<Tree<Long>> treeList = deptService.tree(query, sortQuery, true);
return R.ok(treeList);
}

@Operation(summary = "查询菜单树", description = "查询树结构的菜单列表")
@GetMapping("/tree/menu")
public List<Tree<Long>> listMenuTree(MenuQuery query, SortQuery sortQuery) {
return menuService.tree(query, sortQuery, true);
public R<List<Tree<Long>>> listMenuTree(MenuQuery query, SortQuery sortQuery) {
List<Tree<Long>> treeList = menuService.tree(query, sortQuery, true);
return R.ok(treeList);
}

@Operation(summary = "查询角色字典", description = "查询角色字典列表")
@GetMapping("/dict/role")
public List<LabelValueResp<Long>> listRoleDict(RoleQuery query, SortQuery sortQuery) {
public R<List<LabelValueResp<Long>>> listRoleDict(RoleQuery query, SortQuery sortQuery) {
List<RoleResp> list = roleService.list(query, sortQuery);
return roleService.buildDict(list);
List<LabelValueResp<Long>> labelValueList = roleService.buildDict(list);
return R.ok(labelValueList);
}

@Operation(summary = "查询字典", description = "查询字典列表")
@Parameter(name = "code", description = "字典编码", example = "announcement_type", in = ParameterIn.PATH)
@GetMapping("/dict/{code}")
@Cacheable(key = "#code", cacheNames = CacheConstants.DICT_KEY_PREFIX)
public List<LabelValueResp> listDict(@PathVariable String code) {
public R<List<LabelValueResp>> listDict(@PathVariable String code) {
Optional<Class<?>> enumClass = this.getEnumClassByName(code);
return enumClass.map(this::listEnumDict).orElseGet(() -> dictItemService.listByDictCode(code));
return R.ok(enumClass.map(this::listEnumDict).orElseGet(() -> dictItemService.listByDictCode(code)));
}

@SaIgnore
@Operation(summary = "查询参数", description = "查询参数")
@GetMapping("/option")
@Cacheable(cacheNames = CacheConstants.OPTION_KEY_PREFIX)
public List<LabelValueResp> listOption(@Validated OptionQuery query) {
return optionService.list(query).stream().map(option -> new LabelValueResp(option.getCode(),
StrUtil.nullToDefault(option.getValue(), option.getDefaultValue()))).collect(Collectors.toList());
public R<List<LabelValueResp>> listOption(@Validated OptionQuery query) {
return R.ok(optionService.list(query).stream().map(option -> new LabelValueResp(option.getCode(),
StrUtil.nullToDefault(option.getValue(), option.getDefaultValue()))).collect(Collectors.toList()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import top.charles7c.cnadmin.monitor.model.resp.DashboardTotalResp;
import top.charles7c.cnadmin.monitor.service.DashboardService;
import top.charles7c.cnadmin.system.model.resp.DashboardAnnouncementResp;
import top.charles7c.continew.starter.extension.crud.model.resp.R;
import top.charles7c.continew.starter.extension.crud.util.validate.ValidationUtils;

/**
Expand All @@ -58,33 +59,33 @@ public class DashboardController {

@Operation(summary = "查询总计信息", description = "查询总计信息")
@GetMapping("/total")
public DashboardTotalResp getTotal() {
return dashboardService.getTotal();
public R<DashboardTotalResp> getTotal() {
return R.ok(dashboardService.getTotal());
}

@Operation(summary = "查询访问趋势信息", description = "查询访问趋势信息")
@Parameter(name = "days", description = "日期数", example = "30", in = ParameterIn.PATH)
@GetMapping("/access/trend/{days}")
public List<DashboardAccessTrendResp> listAccessTrend(@PathVariable Integer days) {
public R<List<DashboardAccessTrendResp>> listAccessTrend(@PathVariable Integer days) {
ValidationUtils.throwIf(7 != days && 30 != days, "仅支持查询近 7/30 天访问趋势信息");
return dashboardService.listAccessTrend(days);
return R.ok(dashboardService.listAccessTrend(days));
}

@Operation(summary = "查询热门模块列表", description = "查询热门模块列表")
@GetMapping("/popular/module")
public List<DashboardPopularModuleResp> listPopularModule() {
return dashboardService.listPopularModule();
public R<List<DashboardPopularModuleResp>> listPopularModule() {
return R.ok(dashboardService.listPopularModule());
}

@Operation(summary = "查询访客地域分布信息", description = "查询访客地域分布信息")
@GetMapping("/geo/distribution")
public DashboardGeoDistributionResp getGeoDistribution() {
return dashboardService.getGeoDistribution();
public R<DashboardGeoDistributionResp> getGeoDistribution() {
return R.ok(dashboardService.getGeoDistribution());
}

@Operation(summary = "查询公告列表", description = "查询公告列表")
@GetMapping("/announcement")
public List<DashboardAnnouncementResp> listAnnouncement() {
return dashboardService.listAnnouncement();
public R<List<DashboardAnnouncementResp>> listAnnouncement() {
return R.ok(dashboardService.listAnnouncement());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import top.charles7c.cnadmin.monitor.service.LogService;
import top.charles7c.continew.starter.extension.crud.model.query.PageQuery;
import top.charles7c.continew.starter.extension.crud.model.resp.PageDataResp;
import top.charles7c.continew.starter.extension.crud.model.resp.R;

/**
* 日志管理 API
Expand All @@ -58,29 +59,33 @@ public class LogController {
@Log(module = "登录日志")
@Operation(summary = "分页查询登录日志列表", description = "分页查询登录日志列表")
@GetMapping("/login")
public PageDataResp<LoginLogResp> page(LoginLogQuery query, @Validated PageQuery pageQuery) {
return logService.page(query, pageQuery);
public R<PageDataResp<LoginLogResp>> page(LoginLogQuery query, @Validated PageQuery pageQuery) {
PageDataResp<LoginLogResp> pageData = logService.page(query, pageQuery);
return R.ok(pageData);
}

@Log(module = "操作日志")
@Operation(summary = "分页查询操作日志列表", description = "分页查询操作日志列表")
@GetMapping("/operation")
public PageDataResp<OperationLogResp> page(OperationLogQuery query, @Validated PageQuery pageQuery) {
return logService.page(query, pageQuery);
public R<PageDataResp<OperationLogResp>> page(OperationLogQuery query, @Validated PageQuery pageQuery) {
PageDataResp<OperationLogResp> pageData = logService.page(query, pageQuery);
return R.ok(pageData);
}

@Log(module = "系统日志")
@Operation(summary = "分页查询系统日志列表", description = "分页查询系统日志列表")
@GetMapping("/system")
public PageDataResp<SystemLogResp> page(SystemLogQuery query, @Validated PageQuery pageQuery) {
return logService.page(query, pageQuery);
public R<PageDataResp<SystemLogResp>> page(SystemLogQuery query, @Validated PageQuery pageQuery) {
PageDataResp<SystemLogResp> pageData = logService.page(query, pageQuery);
return R.ok(pageData);
}

@Log(module = "系统日志")
@Operation(summary = "查看系统日志详情", description = "查看系统日志详情")
@Parameter(name = "id", description = "ID", example = "1", in = ParameterIn.PATH)
@GetMapping("/system/{id}")
public SystemLogDetailResp get(@PathVariable Long id) {
return logService.get(id);
public R<SystemLogDetailResp> get(@PathVariable Long id) {
SystemLogDetailResp detail = logService.get(id);
return R.ok(detail);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public class OnlineUserController {
@Operation(summary = "分页查询列表", description = "分页查询列表")
@SaCheckPermission("monitor:online:user:list")
@GetMapping
public PageDataResp<OnlineUserResp> page(OnlineUserQuery query, @Validated PageQuery pageQuery) {
return onlineUserService.page(query, pageQuery);
public R<PageDataResp<OnlineUserResp>> page(OnlineUserQuery query, @Validated PageQuery pageQuery) {
PageDataResp<OnlineUserResp> pageData = onlineUserService.page(query, pageQuery);
return R.ok(pageData);
}

@Operation(summary = "强退在线用户", description = "强退在线用户")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import top.charles7c.cnadmin.system.service.DictService;
import top.charles7c.continew.starter.extension.crud.annotation.CrudRequestMapping;
import top.charles7c.continew.starter.extension.crud.base.BaseController;
import top.charles7c.continew.starter.extension.crud.enums.Api;

/**
* 字典管理 API
Expand Down
Loading

0 comments on commit c7a4e32

Please sign in to comment.