Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
dm_project
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
姚本章
dm_project
Commits
03996381
Commit
03996381
authored
Feb 05, 2021
by
zhangc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
commit
parent
1334c03f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
189 additions
and
0 deletions
+189
-0
GatewayConfiguration.java
.../src/main/java/com/jz/dm/config/GatewayConfiguration.java
+115
-0
AuthController.java
...ay/src/main/java/com/jz/dm/controller/AuthController.java
+10
-0
AuthRenewUpdateReq.java
...in/java/com/jz/dm/models/req/auth/AuthRenewUpdateReq.java
+33
-0
AuthService.java
...igateway/src/main/java/com/jz/dm/service/AuthService.java
+7
-0
AuthServiceImpl.java
...src/main/java/com/jz/dm/service/impl/AuthServiceImpl.java
+24
-0
No files found.
jz-dm-apigateway/src/main/java/com/jz/dm/config/GatewayConfiguration.java
0 → 100644
View file @
03996381
package
com
.
jz
.
dm
.
config
;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.config
* @PROJECT_NAME: jz-dm-parent
* @NAME: GatewayConfiguration
* @DATE: 2021-2-5/10:58
* @DAY_NAME_SHORT: 周五
* @Description: 详情github地址:https://github.com/alibaba/Sentinel/blob/master/sentinel-demo/sentinel-demo-spring-cloud-gateway/src/main/java/com/alibaba/csp/sentinel/demo/spring/sc/gateway/GatewayConfiguration.java
**/
/*@Configuration
public class GatewayConfiguration {
private final List<ViewResolver> viewResolvers;
private final ServerCodecConfigurer serverCodecConfigurer;
public GatewayConfiguration(ObjectProvider<List<ViewResolver>> viewResolversProvider,
ServerCodecConfigurer serverCodecConfigurer) {
this.viewResolvers = viewResolversProvider.getIfAvailable(Collections::emptyList);
this.serverCodecConfigurer = serverCodecConfigurer;
}
@Bean
@Order(Ordered.HIGHEST_PRECEDENCE)
public SentinelGatewayBlockExceptionHandler sentinelGatewayBlockExceptionHandler() {
// Register the block exception handler for Spring Cloud Gateway.
return new SentinelGatewayBlockExceptionHandler(viewResolvers, serverCodecConfigurer);
}
@Bean
@Order(-1)
public GlobalFilter sentinelGatewayFilter() {
return new SentinelGatewayFilter();
}
@PostConstruct
public void doInit() {
initCustomizedApis();
initGatewayRules();
}
private void initCustomizedApis() {
Set<ApiDefinition> definitions = new HashSet<>();
ApiDefinition api1 = new ApiDefinition("some_customized_api")
.setPredicateItems(new HashSet<ApiPredicateItem>() {{
add(new ApiPathPredicateItem().setPattern("/ahas"));
add(new ApiPathPredicateItem().setPattern("/product/**")
.setMatchStrategy(SentinelGatewayConstants.URL_MATCH_STRATEGY_PREFIX));
}});
ApiDefinition api2 = new ApiDefinition("another_customized_api")
.setPredicateItems(new HashSet<ApiPredicateItem>() {{
add(new ApiPathPredicateItem().setPattern("/**")
.setMatchStrategy(SentinelGatewayConstants.URL_MATCH_STRATEGY_PREFIX));
}});
definitions.add(api1);
definitions.add(api2);
GatewayApiDefinitionManager.loadApiDefinitions(definitions);
}
private void initGatewayRules() {
Set<GatewayFlowRule> rules = new HashSet<>();
rules.add(new GatewayFlowRule("aliyun_route")
.setCount(10)
.setIntervalSec(1)
);
rules.add(new GatewayFlowRule("aliyun_route")
.setCount(2)
.setIntervalSec(2)
.setBurst(2)
.setParamItem(new GatewayParamFlowItem()
.setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_CLIENT_IP)
)
);
rules.add(new GatewayFlowRule("httpbin_route")
.setCount(10)
.setIntervalSec(1)
.setControlBehavior(RuleConstant.CONTROL_BEHAVIOR_RATE_LIMITER)
.setMaxQueueingTimeoutMs(600)
.setParamItem(new GatewayParamFlowItem()
.setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_HEADER)
.setFieldName("X-Sentinel-Flag")
)
);
rules.add(new GatewayFlowRule("httpbin_route")
.setCount(1)
.setIntervalSec(1)
.setParamItem(new GatewayParamFlowItem()
.setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_URL_PARAM)
.setFieldName("pa")
)
);
rules.add(new GatewayFlowRule("httpbin_route")
.setCount(2)
.setIntervalSec(30)
.setParamItem(new GatewayParamFlowItem()
.setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_URL_PARAM)
.setFieldName("type")
.setPattern("warn")
.setMatchStrategy(SentinelGatewayConstants.PARAM_MATCH_STRATEGY_CONTAINS)
)
);
rules.add(new GatewayFlowRule("some_customized_api")
.setResourceMode(SentinelGatewayConstants.RESOURCE_MODE_CUSTOM_API_NAME)
.setCount(5)
.setIntervalSec(1)
.setParamItem(new GatewayParamFlowItem()
.setParseStrategy(SentinelGatewayConstants.PARAM_PARSE_STRATEGY_URL_PARAM)
.setFieldName("pn")
)
);
GatewayRuleManager.loadRules(rules);
}
}*/
jz-dm-apigateway/src/main/java/com/jz/dm/controller/AuthController.java
View file @
03996381
...
...
@@ -116,4 +116,14 @@ public class AuthController {
public
Mono
<
Result
>
resetSalt
(
@RequestBody
@Validated
SaltResetReq
req
)
{
return
Mono
.
fromSupplier
(()
->
authService
.
updateSaltInfo
(
req
));
}
/**
* @Description: 商城授权续费
* @Author: Mr.zhang
* @Date: 2020-12-26
*/
@ApiOperation
(
"商城授权续费"
)
@PostMapping
(
value
=
"/auth-renew"
)
public
Mono
<
Result
>
authRenew
(
@RequestBody
@Validated
AuthRenewUpdateReq
req
)
{
return
Mono
.
fromSupplier
(()
->
authService
.
updateAuthDate
(
req
));
}
}
jz-dm-apigateway/src/main/java/com/jz/dm/models/req/auth/AuthRenewUpdateReq.java
0 → 100644
View file @
03996381
package
com
.
jz
.
dm
.
models
.
req
.
auth
;
import
com.fasterxml.jackson.annotation.JsonFormat
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
import
org.springframework.format.annotation.DateTimeFormat
;
import
javax.validation.constraints.NotNull
;
import
java.io.Serializable
;
/**
* @author ZC
* @PACKAGE_NAME: com.jz.dm.models.req.auth
* @PROJECT_NAME: jz-dm-parent
* @NAME: AuthRenewUpdateReq
* @DATE: 2021-2-5/16:54
* @DAY_NAME_SHORT: 周五
* @Description:
**/
@ApiModel
@Data
public
class
AuthRenewUpdateReq
implements
Serializable
{
@ApiModelProperty
(
value
=
"授权码"
,
required
=
true
)
@NotNull
(
message
=
"授权码不能为空"
)
private
String
authCode
;
@ApiModelProperty
(
value
=
"有效截止时间"
,
required
=
true
)
@NotNull
(
message
=
"有效截止时间不能空"
)
@DateTimeFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
)
@JsonFormat
(
pattern
=
"yyyy-MM-dd HH:mm:ss"
,
timezone
=
"GMT+8"
)
private
String
validEndTime
;
}
jz-dm-apigateway/src/main/java/com/jz/dm/service/AuthService.java
View file @
03996381
...
...
@@ -91,4 +91,11 @@ public interface AuthService {
* @return
*/
Result
getServiceAuthList
(
ServiceAuthReq
req
);
/**
* 更新授权时间
* @param req
* @return
*/
Result
updateAuthDate
(
AuthRenewUpdateReq
req
);
}
jz-dm-apigateway/src/main/java/com/jz/dm/service/impl/AuthServiceImpl.java
View file @
03996381
...
...
@@ -381,4 +381,28 @@ public class AuthServiceImpl implements AuthService {
}
return
null
;
}
/**
* 更新授权续费信息
* @param req
* @return
*/
@Override
public
Result
updateAuthDate
(
AuthRenewUpdateReq
req
)
{
QueryWrapper
<
ApiAuth
>
queryWra
=
new
QueryWrapper
<>();
queryWra
.
eq
(
"auth_code"
,
req
.
getAuthCode
());
queryWra
.
eq
(
"is_deleted"
,
0
);
queryWra
.
eq
(
"status"
,
GeneralStatusTypeEnum
.
VALID
.
name
());
ApiAuth
apiAuth
=
apiAuthMapper
.
selectOne
(
queryWra
);
if
(
null
==
apiAuth
){
return
Result
.
of_error
(
"授权信息不存在!"
);
}
UpdateWrapper
<
ApiAuth
>
updateWra
=
new
UpdateWrapper
<>();
updateWra
.
set
(
"valid_end_time"
,
req
.
getValidEndTime
());
updateWra
.
eq
(
"id"
,
apiAuth
.
getId
());
if
(
apiAuthMapper
.
update
(
null
,
updateWra
)
==
0
){
return
Result
.
of_error
(
ResultMsg
.
UPDATE_FAIL
);
}
return
Result
.
of_success
(
ResultMsg
.
UPDATE_SUCCESS
);
}
}
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