diff --git a/common/common-decrypt/src/main/java/cn/fateverse/common/decrypt/aspect/EncryptAspect.java b/common/common-decrypt/src/main/java/cn/fateverse/common/decrypt/aspect/EncryptAspect.java index c48d920..e72f998 100644 --- a/common/common-decrypt/src/main/java/cn/fateverse/common/decrypt/aspect/EncryptAspect.java +++ b/common/common-decrypt/src/main/java/cn/fateverse/common/decrypt/aspect/EncryptAspect.java @@ -59,11 +59,7 @@ public class EncryptAspect { } else if (arg instanceof List) { try { List list = (List) arg; - for (int j = 0; j < list.size(); j++) { - String ciphertext = list.get(j); - String decrypt = encryptService.decrypt(ciphertext); - list.set(j, decrypt); - } + list.replaceAll(encryptService::decrypt); args[i] = list; } catch (Exception e) { throw new CustomException("接受参数类型错误,请使用String类型的泛型参数"); @@ -117,7 +113,9 @@ public class EncryptAspect { String decrypt = encryptService.encrypt((String) value); ReflectionUtils.setField(field, data, decrypt); } else if (field.getType().getName().startsWith(BASE_PACKAGE)) { - encrypt(value); + if (!value.getClass().isEnum()){ + encrypt(value); + } } else if (value instanceof Collection) { Collection collection = (Collection) value; for (Object item : collection) { @@ -148,7 +146,9 @@ public class EncryptAspect { String decrypt = encryptService.decrypt((String) value); ReflectionUtils.setField(field, arg, decrypt); } else if (field.getType().getName().startsWith(BASE_PACKAGE)) { - decrypt(value); + if (!value.getClass().isEnum()){ + decrypt(value); + } } } } diff --git a/common/common-decrypt/src/main/java/cn/fateverse/common/decrypt/entity/EncryptOption.java b/common/common-decrypt/src/main/java/cn/fateverse/common/decrypt/entity/EncryptOption.java new file mode 100644 index 0000000..eb62525 --- /dev/null +++ b/common/common-decrypt/src/main/java/cn/fateverse/common/decrypt/entity/EncryptOption.java @@ -0,0 +1,29 @@ +package cn.fateverse.common.decrypt.entity; + +import cn.fateverse.common.decrypt.annotation.EncryptField; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * @author Clay + * @date 2024/4/15 12:23 + */ +@Data +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class EncryptOption { + + /** + * 节点ID + */ + @EncryptField + private String value; + + /** + * 节点名称 + */ + private String label; +} diff --git a/common/common-decrypt/src/main/java/cn/fateverse/common/decrypt/entity/EncryptOptionTree.java b/common/common-decrypt/src/main/java/cn/fateverse/common/decrypt/entity/EncryptOptionTree.java new file mode 100644 index 0000000..91fcf85 --- /dev/null +++ b/common/common-decrypt/src/main/java/cn/fateverse/common/decrypt/entity/EncryptOptionTree.java @@ -0,0 +1,38 @@ +package cn.fateverse.common.decrypt.entity; + +import cn.fateverse.common.core.entity.OptionTree; +import cn.fateverse.common.decrypt.annotation.EncryptField; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * @author Clay + * @date 2024/4/15 12:23 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class EncryptOptionTree { + /** + * 节点ID + */ + @EncryptField + private String value; + + /** + * 节点名称 + */ + private Object label; + + /** + * 子节点 + */ + @JsonInclude(JsonInclude.Include.NON_EMPTY) + private List children; +} diff --git a/custom-query/custom-query-api/pom.xml b/custom-query/custom-query-api/pom.xml new file mode 100644 index 0000000..ba95ad8 --- /dev/null +++ b/custom-query/custom-query-api/pom.xml @@ -0,0 +1,41 @@ + + + + custom-query + cn.fateverse + 1.0.0 + + 4.0.0 + + custom-query-api + + + 11 + 11 + + + + + cn.fateverse + common-dubbo + + + org.apache.dubbo.extensions + dubbo-cluster-specify-address-dubbo3 + 1.0.0 + + + org.apache.dubbo + dubbo + + + + + cn.fateverse + common-dubbo + + + + \ No newline at end of file diff --git a/custom-query/custom-query-biz/pom.xml b/custom-query/custom-query-biz/pom.xml index 9fa810b..f037425 100644 --- a/custom-query/custom-query-biz/pom.xml +++ b/custom-query/custom-query-biz/pom.xml @@ -49,9 +49,14 @@ cn.fateverse admin-api + + + + cn.fateverse - common-seata + custom-query-api + 1.0.0 org.mariadb.jdbc diff --git a/custom-query/custom-query-biz/src/main/java/cn/fateverse/query/config/HandlerMethodConfiguration.java b/custom-query/custom-query-biz/src/main/java/cn/fateverse/query/config/HandlerMethodConfiguration.java new file mode 100644 index 0000000..7866153 --- /dev/null +++ b/custom-query/custom-query-biz/src/main/java/cn/fateverse/query/config/HandlerMethodConfiguration.java @@ -0,0 +1,93 @@ +package cn.fateverse.query.config; + +import cn.fateverse.common.core.exception.CustomException; +import cn.fateverse.query.controller.TestController; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.ObjectUtils; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.method.HandlerMethod; +import org.springframework.web.servlet.mvc.method.RequestMappingInfo; +import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; + +import java.lang.reflect.Method; +import java.util.Map; + +/** + * @author Clay + * @date 2024/4/12 16:56 + */ +@Slf4j +@Configuration +public class HandlerMethodConfiguration implements ApplicationContextAware { + + + public static final String CUSTOM_INTERFACE = "customInterface:"; + private RequestMappingHandlerMapping mapping; + private Method mappingMethod; + + + public HandlerMethodConfiguration() { + Class testControllerClass = TestController.class; + Method[] declaredMethods = testControllerClass.getDeclaredMethods(); + for (Method declaredMethod : declaredMethods) { + if ("mapping".equals(declaredMethod.getName())) { + mappingMethod = declaredMethod; + } + } + if (mappingMethod == null) { + log.error("mappingMethod is null"); + } + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + mapping = (RequestMappingHandlerMapping) applicationContext.getBean("requestMappingHandlerMapping"); + } + + /** + * 注册映射接口 + * + * @param path 接口路径 + * @param requestMethod 请求方法 + */ + public void registerMapping(String path, RequestMethod requestMethod) { + String[] empty = {}; + RequestMappingInfo.Builder builder = RequestMappingInfo + .paths(path) + .methods(requestMethod) + .params(empty) + .headers(empty) + .consumes(empty) + .produces(empty) + .mappingName(CUSTOM_INTERFACE + path); + RequestMappingInfo requestMappingInfo = builder.options(mapping.getBuilderConfiguration()).build(); + Map handlerMethods = mapping.getHandlerMethods(); + if (handlerMethods.containsKey(requestMappingInfo)) { + throw new CustomException("path is exist"); + } + mapping.registerMapping(requestMappingInfo, "testController", mappingMethod); + } + + /** + * 卸载映射接口 + * + * @param path 接口路径 + * @param requestMethod 请求类型 + */ + public void unregisterMapping(String path, RequestMethod requestMethod) { + Map handlerMethods = mapping.getHandlerMethods(); + for (RequestMappingInfo mappingInfo : handlerMethods.keySet()) { + if (!ObjectUtils.isEmpty(mappingInfo.getName()) + && (CUSTOM_INTERFACE + path).equals(mappingInfo.getName()) + && mappingInfo.getMethodsCondition().getMethods().contains(requestMethod)) { + mapping.unregisterMapping(mappingInfo); + } + } + } + + +} diff --git a/custom-query/custom-query-biz/src/main/java/cn/fateverse/query/controller/DataAdapterController.java b/custom-query/custom-query-biz/src/main/java/cn/fateverse/query/controller/DataAdapterController.java index d3422a0..3d344bf 100644 --- a/custom-query/custom-query-biz/src/main/java/cn/fateverse/query/controller/DataAdapterController.java +++ b/custom-query/custom-query-biz/src/main/java/cn/fateverse/query/controller/DataAdapterController.java @@ -1,6 +1,9 @@ package cn.fateverse.query.controller; import cn.fateverse.common.core.exception.CustomException; +import cn.fateverse.common.decrypt.annotation.Encrypt; +import cn.fateverse.common.decrypt.annotation.EncryptField; +import cn.fateverse.common.decrypt.entity.EncryptOption; import cn.fateverse.common.excel.utils.ExcelUtil; import cn.fateverse.query.entity.dto.DataAdapterDto; import cn.fateverse.query.entity.query.DataAdapterQuery; @@ -39,6 +42,7 @@ public class DataAdapterController { @ApiOperation("获取数据源适配器列表") + @Encrypt @GetMapping @PreAuthorize("@ss.hasPermission('query:adapter:list')") public Result> list(DataAdapterQuery query) { @@ -47,9 +51,10 @@ public class DataAdapterController { } @ApiOperation("获取校验规则option") + @Encrypt @GetMapping("/option") - public Result> option() { - List