Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cloud-backend
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
framework
cloud-backend
Commits
c689db66
Commit
c689db66
authored
Jan 21, 2022
by
袁伟铭
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.0.0
parent
44631495
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
98 additions
and
0 deletions
+98
-0
api-server/src/main/java/com/zq/api/constant/ApiMethod.java
+26
-0
api-server/src/main/java/com/zq/api/controller/ApiController.java
+2
-0
api-server/src/main/java/com/zq/api/controller/MethodController.java
+64
-0
xxx-common-utils/pom.xml
+6
-0
No files found.
api-server/src/main/java/com/zq/api/constant/ApiMethod.java
0 → 100644
View file @
c689db66
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
""
;
}
api-server/src/main/java/com/zq/api/controller/ApiController.java
View file @
c689db66
...
@@ -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
{
...
...
api-server/src/main/java/com/zq/api/controller/MethodController.java
0 → 100644
View file @
c689db66
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
));
}
}
xxx-common-utils/pom.xml
View file @
c689db66
...
@@ -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>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment