Commit c689db66 by 袁伟铭

1.0.0

parent 44631495
package com.zq.api.constant;
import org.springframework.core.annotation.AliasFor;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* @author wilmiam
* @since 2022/1/5 10:42
*/
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD})
public @interface ApiMethod {
@AliasFor("name")
String value() default "";
@AliasFor("value")
String name() default "";
String service() default "";
}
...@@ -91,6 +91,8 @@ public class ApiController { ...@@ -91,6 +91,8 @@ public class ApiController {
// 判断指定异常是否来自或者包含指定异常 // 判断指定异常是否来自或者包含指定异常
if (ExceptionUtil.isFromOrSuppressedThrowable(e, FeignException.Unauthorized.class)) { if (ExceptionUtil.isFromOrSuppressedThrowable(e, FeignException.Unauthorized.class)) {
resp = ApiUtils.toApiResp(form, ResultVo.fail(401, "Unauthorized")); resp = ApiUtils.toApiResp(form, ResultVo.fail(401, "Unauthorized"));
} else if (ExceptionUtil.isFromOrSuppressedThrowable(e, FeignException.NotFound.class)) {
resp = ApiUtils.toApiResp(form, ResultVo.fail(404, "NotFound"));
} else if (stackTrace.contains("Load balancer does not have available server for client")) { } else if (stackTrace.contains("Load balancer does not have available server for client")) {
resp = ApiUtils.getServiceNotAvailableError(form); resp = ApiUtils.getServiceNotAvailableError(form);
} else { } else {
......
package com.zq.api.controller;
import cn.hutool.core.util.StrUtil;
import com.zq.api.constant.ApiMethod;
import com.zq.api.form.ApiForm;
import com.zq.api.form.ApiResp;
import com.zq.api.service.IApiLogic;
import com.zq.api.utils.ApiUtils;
import com.zq.common.vo.ResultVo;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author wilmiam
* @since 2022/1/21 17:00
*/
@Api(tags = "方法接口")
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/api")
public class MethodController {
@RequestMapping("/method")
public ApiResp getAllMethod(@RequestParam(required = false) String service, @RequestParam(required = false) String name) {
List<Map<String, Object>> methodList = new ArrayList<>();
Method[] methods = IApiLogic.class.getMethods();
for (Method method : methods) {
Class<?>[] params = method.getParameterTypes();
if (params.length == 1 && (params[0] == ApiForm.class)) {
ApiMethod apiMethod = AnnotationUtils.getAnnotation(method, ApiMethod.class);
if (StrUtil.isNotBlank(service)) {
if (apiMethod == null || !apiMethod.service().equals(service)) {
continue;
}
}
if (StrUtil.isNotBlank(name)) {
if ((apiMethod == null || !apiMethod.value().contains(name)) && !method.getName().toLowerCase().contains(name.toLowerCase())) {
continue;
}
}
Map<String, Object> data = new HashMap<>();
data.put("value", method.getName());
data.put("name", apiMethod == null ? "" : apiMethod.value());
data.put("service", apiMethod == null ? "" : apiMethod.service());
methodList.add(data);
}
}
return ApiUtils.toApiResp(new ApiForm(), ResultVo.success(methodList));
}
}
...@@ -123,6 +123,12 @@ ...@@ -123,6 +123,12 @@
<groupId>com.jfinal</groupId> <groupId>com.jfinal</groupId>
<artifactId>jfinal-ext3</artifactId> <artifactId>jfinal-ext3</artifactId>
<version>4.0.3</version> <version>4.0.3</version>
<exclusions>
<exclusion>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
</dependencies> </dependencies>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment