mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-10 11:44:04 +08:00
新增系统配置api接口
This commit is contained in:
parent
c85467f62f
commit
aabd41ce01
@ -4,6 +4,7 @@ import xyz.playedu.api.domain.AdminUser;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PlayEduBackendThreadLocal {
|
||||
|
||||
@ -12,6 +13,7 @@ public class PlayEduBackendThreadLocal {
|
||||
public final static String KEY_ADMIN_USER_ID = "admin_id";
|
||||
public final static String KEY_ADMIN_USER = "admin_user";
|
||||
public final static String KEY_ADMIN_PER = "admin_per";
|
||||
public final static String KEY_CONFIG = "config";
|
||||
|
||||
public PlayEduBackendThreadLocal() {
|
||||
}
|
||||
@ -57,4 +59,12 @@ public class PlayEduBackendThreadLocal {
|
||||
THREAD_LOCAL.remove();
|
||||
}
|
||||
|
||||
public static void setConfig(Map<String, String> config) {
|
||||
put(KEY_CONFIG, config);
|
||||
}
|
||||
|
||||
public static Map<String, String> getConfig() {
|
||||
return (Map<String, String>) get(KEY_CONFIG);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,14 +6,14 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.CorsRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import xyz.playedu.api.middleware.AdminAuthMiddleware;
|
||||
import xyz.playedu.api.middleware.AdminMiddleware;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
@Resource
|
||||
private AdminAuthMiddleware adminAuthMiddleware;
|
||||
private AdminMiddleware adminAuthMiddleware;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
|
@ -4,13 +4,14 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import xyz.playedu.api.config.MinioConfig;
|
||||
import xyz.playedu.api.PlayEduBackendThreadLocal;
|
||||
import xyz.playedu.api.service.ImageCaptchaService;
|
||||
import xyz.playedu.api.types.ImageCaptchaResult;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/backend/v1/system")
|
||||
@ -19,9 +20,6 @@ public class SystemController {
|
||||
@Autowired
|
||||
private ImageCaptchaService imageCaptchaService;
|
||||
|
||||
@Autowired
|
||||
private MinioConfig minioConfig;
|
||||
|
||||
@GetMapping("/image-captcha")
|
||||
public JsonResponse imageCaptcha() throws IOException {
|
||||
ImageCaptchaResult imageCaptchaResult = imageCaptchaService.generate();
|
||||
@ -35,8 +33,7 @@ public class SystemController {
|
||||
|
||||
@GetMapping("/config")
|
||||
public JsonResponse config() {
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("minio_endpoint", minioConfig.getEndPoint());
|
||||
Map<String, String> data = PlayEduBackendThreadLocal.getConfig();
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,7 @@ import xyz.playedu.api.bus.BackendBus;
|
||||
import xyz.playedu.api.constant.SystemConstant;
|
||||
import xyz.playedu.api.domain.AdminUser;
|
||||
import xyz.playedu.api.service.AdminUserService;
|
||||
import xyz.playedu.api.service.AppConfigService;
|
||||
import xyz.playedu.api.service.JWTService;
|
||||
import xyz.playedu.api.types.JWTPayload;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
@ -19,10 +20,11 @@ import xyz.playedu.api.util.HelperUtil;
|
||||
import xyz.playedu.api.util.RequestUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class AdminAuthMiddleware implements HandlerInterceptor {
|
||||
public class AdminMiddleware implements HandlerInterceptor {
|
||||
|
||||
@Autowired
|
||||
private JWTService jwtService;
|
||||
@ -36,9 +38,20 @@ public class AdminAuthMiddleware implements HandlerInterceptor {
|
||||
@Autowired
|
||||
private BackendBus backendBus;
|
||||
|
||||
@Autowired
|
||||
private AppConfigService configService;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
if ("OPTIONS".equals(request.getMethod()) || BackendBus.inUnAuthWhitelist(request.getRequestURI())) {
|
||||
if ("OPTIONS".equals(request.getMethod())) {
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
}
|
||||
|
||||
// 读取全局配置
|
||||
Map<String, String> systemConfig = configService.keyValues();
|
||||
PlayEduBackendThreadLocal.setConfig(systemConfig);
|
||||
|
||||
if (BackendBus.inUnAuthWhitelist(request.getRequestURI())) {
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
}
|
||||
|
@ -20,4 +20,6 @@ public interface AppConfigService extends IService<AppConfig> {
|
||||
|
||||
void saveFromMap(HashMap<String, String> data);
|
||||
|
||||
Map<String, String> keyValues();
|
||||
|
||||
}
|
||||
|
@ -57,6 +57,11 @@ public class AppConfigServiceImpl extends ServiceImpl<AppConfigMapper, AppConfig
|
||||
updateBatchById(list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> keyValues() {
|
||||
return list(query().getWrapper().eq("is_hidden", 0)).stream().collect(Collectors.toMap(AppConfig::getKeyName, AppConfig::getKeyValue));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user