refactor: flatten controller packages
This commit is contained in:
66
src/main/java/com/label/controller/SysConfigController.java
Normal file
66
src/main/java/com/label/controller/SysConfigController.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.label.controller;
|
||||
|
||||
import com.label.common.result.Result;
|
||||
import com.label.common.shiro.TokenPrincipal;
|
||||
import com.label.entity.SysConfig;
|
||||
import com.label.service.SysConfigService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 系统配置接口(2 个端点,均需 ADMIN 权限)。
|
||||
*
|
||||
* GET /api/config — 查询当前公司所有可见配置(公司专属 + 全局默认合并)
|
||||
* PUT /api/config/{key} — 更新/创建公司专属配置(UPSERT)
|
||||
*/
|
||||
@Tag(name = "系统配置", description = "全局和公司级系统配置管理")
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
public class SysConfigController {
|
||||
|
||||
private final SysConfigService sysConfigService;
|
||||
|
||||
/**
|
||||
* GET /api/config — 查询合并后的配置列表。
|
||||
*
|
||||
* 响应中每条配置含 scope 字段:
|
||||
* - "COMPANY":当前公司专属配置(优先生效)
|
||||
* - "GLOBAL":全局默认配置(公司未覆盖时生效)
|
||||
*/
|
||||
@Operation(summary = "查询合并后的系统配置")
|
||||
@GetMapping("/api/config")
|
||||
@RequiresRoles("ADMIN")
|
||||
public Result<List<Map<String, Object>>> listConfig(HttpServletRequest request) {
|
||||
TokenPrincipal principal = principal(request);
|
||||
return Result.success(sysConfigService.list(principal.getCompanyId()));
|
||||
}
|
||||
|
||||
/**
|
||||
* PUT /api/config/{key} — UPSERT 公司专属配置。
|
||||
*
|
||||
* Body: { "value": "...", "description": "..." }
|
||||
*/
|
||||
@Operation(summary = "更新或创建公司专属配置")
|
||||
@PutMapping("/api/config/{key}")
|
||||
@RequiresRoles("ADMIN")
|
||||
public Result<SysConfig> updateConfig(@PathVariable String key,
|
||||
@RequestBody Map<String, String> body,
|
||||
HttpServletRequest request) {
|
||||
String value = body.get("value");
|
||||
String description = body.get("description");
|
||||
TokenPrincipal principal = principal(request);
|
||||
return Result.success(
|
||||
sysConfigService.update(key, value, description, principal.getCompanyId()));
|
||||
}
|
||||
|
||||
private TokenPrincipal principal(HttpServletRequest request) {
|
||||
return (TokenPrincipal) request.getAttribute("__token_principal__");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user