mirror of
				https://github.com/continew-org/continew-admin.git
				synced 2025-10-31 22:57:17 +08:00 
			
		
		
		
	refactor: CommonController 迁移至 system 模块、OnlineUserController 迁移至 system/auth 模块
This commit is contained in:
		| @@ -14,7 +14,7 @@ | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package top.continew.admin.controller.common; | ||||
| package top.continew.admin.controller; | ||||
| 
 | ||||
| import cn.dev33.satoken.annotation.SaIgnore; | ||||
| import cn.hutool.core.date.LocalDateTimeUtil; | ||||
| @@ -14,7 +14,7 @@ | ||||
|  * limitations under the License. | ||||
|  */ | ||||
| 
 | ||||
| package top.continew.admin.controller.common; | ||||
| package top.continew.admin.controller; | ||||
| 
 | ||||
| import com.alicp.jetcache.anno.CachePenetrationProtect; | ||||
| import com.alicp.jetcache.anno.CacheRefresh; | ||||
| @@ -1,129 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
|  | ||||
| package top.continew.admin.controller.common; | ||||
|  | ||||
| import cn.dev33.satoken.annotation.SaIgnore; | ||||
| import cn.hutool.core.lang.tree.Tree; | ||||
| import cn.hutool.core.util.StrUtil; | ||||
| import com.alicp.jetcache.anno.Cached; | ||||
| import io.swagger.v3.oas.annotations.Operation; | ||||
| import io.swagger.v3.oas.annotations.Parameter; | ||||
| import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||||
| import jakarta.validation.constraints.NotNull; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import org.dromara.x.file.storage.core.FileInfo; | ||||
| import org.springframework.validation.annotation.Validated; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
| import org.springframework.web.multipart.MultipartFile; | ||||
| import top.continew.admin.common.constant.CacheConstants; | ||||
| import top.continew.admin.system.enums.OptionCategoryEnum; | ||||
| import top.continew.admin.system.model.query.*; | ||||
| import top.continew.admin.system.model.resp.file.FileUploadResp; | ||||
| import top.continew.admin.system.service.*; | ||||
| import top.continew.starter.core.util.validation.ValidationUtils; | ||||
| import top.continew.starter.extension.crud.model.query.SortQuery; | ||||
| import top.continew.starter.extension.crud.model.resp.LabelValueResp; | ||||
| import top.continew.starter.extension.tenant.annotation.TenantIgnore; | ||||
| import top.continew.starter.log.annotation.Log; | ||||
|  | ||||
| import java.io.IOException; | ||||
| import java.util.List; | ||||
|  | ||||
| /** | ||||
|  * 公共 API | ||||
|  * | ||||
|  * @author Charles7c | ||||
|  * @since 2023/1/22 21:48 | ||||
|  */ | ||||
| @Tag(name = "公共 API") | ||||
| @Log(ignore = true) | ||||
| @Validated | ||||
| @RestController | ||||
| @RequiredArgsConstructor | ||||
| @RequestMapping("/common") | ||||
| public class CommonController { | ||||
|  | ||||
|     private final FileService fileService; | ||||
|     private final DeptService deptService; | ||||
|     private final MenuService menuService; | ||||
|     private final UserService userService; | ||||
|     private final RoleService roleService; | ||||
|     private final DictItemService dictItemService; | ||||
|     private final OptionService optionService; | ||||
|  | ||||
|     @Operation(summary = "上传文件", description = "上传文件") | ||||
|     @Parameter(name = "parentPath", description = "上级目录", example = "/", in = ParameterIn.QUERY) | ||||
|     @PostMapping("/file") | ||||
|     public FileUploadResp upload(@RequestPart @NotNull(message = "文件不能为空") MultipartFile file, | ||||
|                                  @RequestParam(required = false) String parentPath) throws IOException { | ||||
|         ValidationUtils.throwIf(file::isEmpty, "文件不能为空"); | ||||
|         FileInfo fileInfo = fileService.upload(file, parentPath); | ||||
|         return FileUploadResp.builder() | ||||
|             .id(fileInfo.getId()) | ||||
|             .url(fileInfo.getUrl()) | ||||
|             .thUrl(fileInfo.getThUrl()) | ||||
|             .metadata(fileInfo.getMetadata()) | ||||
|             .build(); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询部门树", description = "查询树结构的部门列表") | ||||
|     @GetMapping("/tree/dept") | ||||
|     public List<Tree<Long>> listDeptTree(DeptQuery query, SortQuery sortQuery) { | ||||
|         return deptService.tree(query, sortQuery, true); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询菜单树", description = "查询树结构的菜单列表") | ||||
|     @GetMapping("/tree/menu") | ||||
|     public List<Tree<Long>> listMenuTree(MenuQuery query, SortQuery sortQuery) { | ||||
|         return menuService.tree(query, sortQuery, true); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询用户字典", description = "查询用户字典列表") | ||||
|     @GetMapping("/dict/user") | ||||
|     public List<LabelValueResp> listUserDict(UserQuery query, SortQuery sortQuery) { | ||||
|         return userService.listDict(query, sortQuery); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询角色字典", description = "查询角色字典列表") | ||||
|     @GetMapping("/dict/role") | ||||
|     public List<LabelValueResp> listRoleDict(RoleQuery query, SortQuery sortQuery) { | ||||
|         return roleService.listDict(query, sortQuery); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "查询字典", description = "查询字典列表") | ||||
|     @Parameter(name = "code", description = "字典编码", example = "notice_type", in = ParameterIn.PATH) | ||||
|     @GetMapping("/dict/{code}") | ||||
|     public List<LabelValueResp> listDict(@PathVariable String code) { | ||||
|         return dictItemService.listByDictCode(code); | ||||
|     } | ||||
|  | ||||
|     @TenantIgnore | ||||
|     @SaIgnore | ||||
|     @Operation(summary = "查询系统配置参数", description = "查询系统配置参数") | ||||
|     @GetMapping("/dict/option/site") | ||||
|     @Cached(key = "'SITE'", name = CacheConstants.OPTION_KEY_PREFIX) | ||||
|     public List<LabelValueResp<String>> listSiteOptionDict() { | ||||
|         OptionQuery optionQuery = new OptionQuery(); | ||||
|         optionQuery.setCategory(OptionCategoryEnum.SITE.name()); | ||||
|         return optionService.list(optionQuery) | ||||
|             .stream() | ||||
|             .map(option -> new LabelValueResp<>(option.getCode(), StrUtil.nullToDefault(option.getValue(), option | ||||
|                 .getDefaultValue()))) | ||||
|             .toList(); | ||||
|     } | ||||
| } | ||||
| @@ -1,65 +0,0 @@ | ||||
| /* | ||||
|  * Copyright (c) 2022-present Charles7c Authors. All Rights Reserved. | ||||
|  * | ||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||
|  * you may not use this file except in compliance with the License. | ||||
|  * You may obtain a copy of the License at | ||||
|  * | ||||
|  *     http://www.apache.org/licenses/LICENSE-2.0 | ||||
|  * | ||||
|  * Unless required by applicable law or agreed to in writing, software | ||||
|  * distributed under the License is distributed on an "AS IS" BASIS, | ||||
|  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||
|  * See the License for the specific language governing permissions and | ||||
|  * limitations under the License. | ||||
|  */ | ||||
|  | ||||
| package top.continew.admin.controller.monitor; | ||||
|  | ||||
| import cn.dev33.satoken.annotation.SaCheckPermission; | ||||
| import cn.dev33.satoken.stp.StpUtil; | ||||
| import io.swagger.v3.oas.annotations.Operation; | ||||
| import io.swagger.v3.oas.annotations.Parameter; | ||||
| import io.swagger.v3.oas.annotations.enums.ParameterIn; | ||||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||||
| import jakarta.validation.Valid; | ||||
| import lombok.RequiredArgsConstructor; | ||||
| import org.springframework.web.bind.annotation.*; | ||||
| import top.continew.admin.auth.model.query.OnlineUserQuery; | ||||
| import top.continew.admin.auth.model.resp.OnlineUserResp; | ||||
| import top.continew.admin.auth.service.OnlineUserService; | ||||
| import top.continew.starter.core.util.validation.CheckUtils; | ||||
| import top.continew.starter.extension.crud.model.query.PageQuery; | ||||
| import top.continew.starter.extension.crud.model.resp.PageResp; | ||||
|  | ||||
| /** | ||||
|  * 在线用户 API | ||||
|  * | ||||
|  * @author Charles7c | ||||
|  * @since 2023/1/20 21:51 | ||||
|  */ | ||||
| @Tag(name = "在线用户 API") | ||||
| @RestController | ||||
| @RequiredArgsConstructor | ||||
| @RequestMapping("/monitor/online") | ||||
| public class OnlineUserController { | ||||
|  | ||||
|     private final OnlineUserService baseService; | ||||
|  | ||||
|     @Operation(summary = "分页查询列表", description = "分页查询列表") | ||||
|     @SaCheckPermission("monitor:online:list") | ||||
|     @GetMapping | ||||
|     public PageResp<OnlineUserResp> page(@Valid OnlineUserQuery query, @Valid PageQuery pageQuery) { | ||||
|         return baseService.page(query, pageQuery); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "强退在线用户", description = "强退在线用户") | ||||
|     @Parameter(name = "token", description = "令牌", example = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJsb2dpblR5cGUiOiJsb2dpbiIsImxvZ2luSWQiOjEsInJuU3RyIjoiTUd6djdyOVFoeHEwdVFqdFAzV3M5YjVJRzh4YjZPSEUifQ.7q7U3ouoN7WPhH2kUEM7vPe5KF3G_qavSG-vRgIxKvE", in = ParameterIn.PATH) | ||||
|     @SaCheckPermission("monitor:online:kickout") | ||||
|     @DeleteMapping("/{token}") | ||||
|     public void kickout(@PathVariable String token) { | ||||
|         String currentToken = StpUtil.getTokenValue(); | ||||
|         CheckUtils.throwIfEqual(token, currentToken, "不能强退自己"); | ||||
|         StpUtil.kickoutByTokenValue(token); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user