✨ 添加演示模式.
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
package com.orion.visor.framework.common.constant;
|
||||
|
||||
/**
|
||||
* bean 排序常量
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/29 16:09
|
||||
*/
|
||||
public interface BeanOrderConst {
|
||||
|
||||
/**
|
||||
* 公共返回值包装处理器
|
||||
*/
|
||||
int RESPONSE_ADVICE_WRAPPER = Integer.MIN_VALUE + 1000;
|
||||
|
||||
/**
|
||||
* 演示模式切面
|
||||
*/
|
||||
int DEMO_DISABLE_API_ASPECT = 20;
|
||||
|
||||
/**
|
||||
* 操作日志切面
|
||||
*/
|
||||
int OPERATOR_LOG_ASPECT = 30;
|
||||
|
||||
}
|
||||
@@ -86,7 +86,7 @@ public enum ErrorCode implements CodeInfo {
|
||||
|
||||
UNSUPPOETED(915, "不支持此操作"),
|
||||
|
||||
PREVIEW_DISABLE_API(916, "预览模式不支持此功能"),
|
||||
DEMO_DISABLE_API(916, "演示模式不支持此功能"),
|
||||
|
||||
;
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package com.orion.visor.framework.common.constant;
|
||||
|
||||
/**
|
||||
* 结果增强器 排序常量
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/29 16:09
|
||||
*/
|
||||
public interface ResponseAdviceOrderConst {
|
||||
|
||||
int WRAPPER = Integer.MIN_VALUE + 1000;
|
||||
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import com.orion.visor.framework.biz.operator.log.core.model.OperatorType;
|
||||
import com.orion.visor.framework.biz.operator.log.core.service.OperatorLogFrameworkService;
|
||||
import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogFiller;
|
||||
import com.orion.visor.framework.biz.operator.log.core.utils.OperatorLogs;
|
||||
import com.orion.visor.framework.common.constant.BeanOrderConst;
|
||||
import com.orion.visor.framework.common.security.LoginUser;
|
||||
import com.orion.visor.framework.common.security.SecurityHolder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -18,6 +19,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
@@ -41,6 +43,7 @@ import java.util.concurrent.ExecutorService;
|
||||
*/
|
||||
@Aspect
|
||||
@Slf4j
|
||||
@Order(BeanOrderConst.OPERATOR_LOG_ASPECT)
|
||||
public class OperatorLogAspect {
|
||||
|
||||
private static final ExecutorService LOG_SAVER = ExecutorBuilder.create()
|
||||
|
||||
@@ -27,7 +27,7 @@ public class ServerTemplate extends Template {
|
||||
table.bizPackage = bizPackage;
|
||||
table.enableUnitTest = true;
|
||||
table.enableOperatorLog = true;
|
||||
table.enablePreviewApi = true;
|
||||
table.enableDemoApi = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,12 +104,12 @@ public class ServerTemplate extends Template {
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否生成预览 api 注解
|
||||
* 是否生成演示模式 api 注解
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public ServerTemplate disablePreviewApi() {
|
||||
table.enablePreviewApi = false;
|
||||
public ServerTemplate disableDemoApi() {
|
||||
table.enableDemoApi = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,9 +59,9 @@ public class Table {
|
||||
protected boolean enableOperatorLog;
|
||||
|
||||
/**
|
||||
* 是否生成预览 api 注解
|
||||
* 是否生成演示模式 api 注解
|
||||
*/
|
||||
protected boolean enablePreviewApi;
|
||||
protected boolean enableDemoApi;
|
||||
|
||||
/**
|
||||
* 缓存的 key
|
||||
|
||||
@@ -6,8 +6,8 @@ import com.orion.visor.framework.biz.operator.log.core.annotation.OperatorLog;
|
||||
#end
|
||||
import com.orion.visor.framework.common.validator.group.Page;
|
||||
import com.orion.visor.framework.log.core.annotation.IgnoreLog;
|
||||
#if($meta.enablePreviewApi)
|
||||
import com.orion.visor.framework.web.core.annotation.PreviewDisableApi;
|
||||
#if($meta.enableDemoApi)
|
||||
import com.orion.visor.framework.web.core.annotation.DemoDisableApi;
|
||||
#end
|
||||
import com.orion.visor.framework.log.core.enums.IgnoreLogMode;
|
||||
import com.orion.visor.framework.web.core.annotation.RestWrapper;
|
||||
@@ -54,8 +54,8 @@ public class ${table.controllerName} {
|
||||
@Resource
|
||||
private ${type}Service ${typeLower}Service;
|
||||
|
||||
#if($meta.enablePreviewApi)
|
||||
@PreviewDisableApi
|
||||
#if($meta.enableDemoApi)
|
||||
@DemoDisableApi
|
||||
#end
|
||||
#if($meta.enableOperatorLog)
|
||||
@OperatorLog(${type}OperatorType.CREATE)
|
||||
@@ -67,8 +67,8 @@ public class ${table.controllerName} {
|
||||
return ${typeLower}Service.create${type}(request);
|
||||
}
|
||||
|
||||
#if($meta.enablePreviewApi)
|
||||
@PreviewDisableApi
|
||||
#if($meta.enableDemoApi)
|
||||
@DemoDisableApi
|
||||
#end
|
||||
#if($meta.enableOperatorLog)
|
||||
@OperatorLog(${type}OperatorType.UPDATE)
|
||||
@@ -114,8 +114,8 @@ public class ${table.controllerName} {
|
||||
return ${typeLower}Service.get${type}Page(request);
|
||||
}
|
||||
|
||||
#if($meta.enablePreviewApi)
|
||||
@PreviewDisableApi
|
||||
#if($meta.enableDemoApi)
|
||||
@DemoDisableApi
|
||||
#end
|
||||
#if($meta.enableOperatorLog)
|
||||
@OperatorLog(${type}OperatorType.DELETE)
|
||||
@@ -128,8 +128,8 @@ public class ${table.controllerName} {
|
||||
return ${typeLower}Service.delete${type}ById(id);
|
||||
}
|
||||
|
||||
#if($meta.enablePreviewApi)
|
||||
@PreviewDisableApi
|
||||
#if($meta.enableDemoApi)
|
||||
@DemoDisableApi
|
||||
#end
|
||||
#if($meta.enableOperatorLog)
|
||||
@OperatorLog(${type}OperatorType.DELETE)
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.orion.lang.utils.collect.Lists;
|
||||
import com.orion.visor.framework.common.constant.AutoConfigureOrderConst;
|
||||
import com.orion.visor.framework.common.constant.FilterOrderConst;
|
||||
import com.orion.visor.framework.common.web.filter.FilterCreator;
|
||||
import com.orion.visor.framework.web.core.aspect.PreviewDisableApiAspect;
|
||||
import com.orion.visor.framework.web.core.aspect.DemoDisableApiAspect;
|
||||
import com.orion.visor.framework.web.core.filter.TraceIdFilter;
|
||||
import com.orion.visor.framework.web.core.handler.GlobalExceptionHandler;
|
||||
import com.orion.visor.framework.web.core.handler.WrapperResultHandler;
|
||||
@@ -141,12 +141,12 @@ public class OrionWebAutoConfiguration implements WebMvcConfigurer {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 预览模式禁用 api 切面
|
||||
* @return 演示模式禁用 api 切面
|
||||
*/
|
||||
@Bean
|
||||
@ConditionalOnProperty(value = "orion.preview", havingValue = "true")
|
||||
public PreviewDisableApiAspect previewDisableApiAspect() {
|
||||
return new PreviewDisableApiAspect();
|
||||
@ConditionalOnProperty(value = "orion.demo", havingValue = "true")
|
||||
public DemoDisableApiAspect demoDisableApiAspect() {
|
||||
return new DemoDisableApiAspect();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.orion.visor.framework.web.core.annotation;
|
||||
import java.lang.annotation.*;
|
||||
|
||||
/**
|
||||
* 预览禁用 api
|
||||
* 演示模式禁用 api
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
@@ -12,5 +12,5 @@ import java.lang.annotation.*;
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface PreviewDisableApi {
|
||||
public @interface DemoDisableApi {
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.orion.visor.framework.web.core.aspect;
|
||||
|
||||
import com.orion.visor.framework.common.constant.BeanOrderConst;
|
||||
import com.orion.visor.framework.common.constant.ErrorCode;
|
||||
import com.orion.visor.framework.web.core.annotation.DemoDisableApi;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.core.annotation.Order;
|
||||
|
||||
/**
|
||||
* 演示模式禁用 api 切面
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/5/21 16:52
|
||||
*/
|
||||
@Aspect
|
||||
@Slf4j
|
||||
@Order(BeanOrderConst.DEMO_DISABLE_API_ASPECT)
|
||||
public class DemoDisableApiAspect {
|
||||
|
||||
public DemoDisableApiAspect() {
|
||||
}
|
||||
|
||||
@Pointcut("@annotation(e)")
|
||||
public void disableApi(DemoDisableApi e) {
|
||||
}
|
||||
|
||||
@Before(value = "disableApi(e)", argNames = "e")
|
||||
public void beforeDisableApi(DemoDisableApi e) {
|
||||
throw ErrorCode.DEMO_DISABLE_API.exception();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.orion.visor.framework.web.core.aspect;
|
||||
|
||||
import com.orion.visor.framework.common.constant.ErrorCode;
|
||||
import com.orion.visor.framework.web.core.annotation.PreviewDisableApi;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
|
||||
/**
|
||||
* 预览禁用 api 切面
|
||||
*
|
||||
* @author Jiahang Li
|
||||
* @version 1.0.0
|
||||
* @since 2024/5/21 16:52
|
||||
*/
|
||||
@Aspect
|
||||
@Slf4j
|
||||
public class PreviewDisableApiAspect {
|
||||
|
||||
public PreviewDisableApiAspect() {
|
||||
}
|
||||
|
||||
@Around("@annotation(o)")
|
||||
public Object around(ProceedingJoinPoint joinPoint, PreviewDisableApi o) {
|
||||
throw ErrorCode.PREVIEW_DISABLE_API.exception();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package com.orion.visor.framework.web.core.handler;
|
||||
import com.orion.lang.constant.StandardContentType;
|
||||
import com.orion.lang.define.wrapper.HttpWrapper;
|
||||
import com.orion.lang.define.wrapper.RpcWrapper;
|
||||
import com.orion.visor.framework.common.constant.ResponseAdviceOrderConst;
|
||||
import com.orion.visor.framework.common.constant.BeanOrderConst;
|
||||
import com.orion.visor.framework.web.core.annotation.IgnoreWrapper;
|
||||
import com.orion.visor.framework.web.core.annotation.RestWrapper;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -23,7 +23,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
|
||||
* @version 1.0.0
|
||||
* @since 2023/6/15 17:38
|
||||
*/
|
||||
@Order(ResponseAdviceOrderConst.WRAPPER)
|
||||
@Order(BeanOrderConst.RESPONSE_ADVICE_WRAPPER)
|
||||
@ControllerAdvice
|
||||
public class WrapperResultHandler implements ResponseBodyAdvice<Object> {
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
"description": "项目版本."
|
||||
},
|
||||
{
|
||||
"name": "orion.preview",
|
||||
"name": "orion.demo",
|
||||
"type": "java.lang.Boolean",
|
||||
"description": "是否为预览模式.",
|
||||
"description": "是否为演示模式.",
|
||||
"defaultValue": false
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user