2026-04-14 13:47:38 +08:00
|
|
|
|
package com.label.controller;
|
2026-04-09 16:18:39 +08:00
|
|
|
|
|
|
|
|
|
|
import com.label.common.result.Result;
|
|
|
|
|
|
import com.label.common.shiro.TokenPrincipal;
|
2026-04-14 13:39:24 +08:00
|
|
|
|
import com.label.entity.SysConfig;
|
2026-04-14 13:45:15 +08:00
|
|
|
|
import com.label.service.SysConfigService;
|
2026-04-12 00:15:59 +08:00
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
2026-04-09 16:18:39 +08:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-14 13:31:50 +08:00
|
|
|
|
* 系统配置接口(2 个端点,均需 ADMIN 权限)。
|
|
|
|
|
|
*
|
|
|
|
|
|
* GET /api/config — 查询当前公司所有可见配置(公司专属 + 全局默认合并)
|
|
|
|
|
|
* PUT /api/config/{key} — 更新/创建公司专属配置(UPSERT)
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Tag(name = "系统配置", description = "全局和公司级系统配置管理")
|
2026-04-09 16:18:39 +08:00
|
|
|
|
@RestController
|
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
|
public class SysConfigController {
|
|
|
|
|
|
|
|
|
|
|
|
private final SysConfigService sysConfigService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-14 13:31:50 +08:00
|
|
|
|
* GET /api/config — 查询合并后的配置列表。
|
|
|
|
|
|
*
|
|
|
|
|
|
* 响应中每条配置含 scope 字段:
|
|
|
|
|
|
* - "COMPANY":当前公司专属配置(优先生效)
|
|
|
|
|
|
* - "GLOBAL":全局默认配置(公司未覆盖时生效)
|
2026-04-09 16:18:39 +08:00
|
|
|
|
*/
|
2026-04-14 13:31:50 +08:00
|
|
|
|
@Operation(summary = "查询合并后的系统配置")
|
2026-04-09 16:18:39 +08:00
|
|
|
|
@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()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2026-04-14 13:31:50 +08:00
|
|
|
|
* PUT /api/config/{key} — UPSERT 公司专属配置。
|
|
|
|
|
|
*
|
2026-04-09 16:18:39 +08:00
|
|
|
|
* Body: { "value": "...", "description": "..." }
|
|
|
|
|
|
*/
|
2026-04-14 13:31:50 +08:00
|
|
|
|
@Operation(summary = "更新或创建公司专属配置")
|
2026-04-09 16:18:39 +08:00
|
|
|
|
@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__");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|