Commit 03996381 authored by zhangc's avatar zhangc

commit

parent 1334c03f
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);
}
}*/
...@@ -116,4 +116,14 @@ public class AuthController { ...@@ -116,4 +116,14 @@ public class AuthController {
public Mono<Result> resetSalt(@RequestBody @Validated SaltResetReq req) { public Mono<Result> resetSalt(@RequestBody @Validated SaltResetReq req) {
return Mono.fromSupplier(() -> authService.updateSaltInfo(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));
}
} }
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;
}
...@@ -91,4 +91,11 @@ public interface AuthService { ...@@ -91,4 +91,11 @@ public interface AuthService {
* @return * @return
*/ */
Result getServiceAuthList(ServiceAuthReq req); Result getServiceAuthList(ServiceAuthReq req);
/**
* 更新授权时间
* @param req
* @return
*/
Result updateAuthDate(AuthRenewUpdateReq req);
} }
...@@ -381,4 +381,28 @@ public class AuthServiceImpl implements AuthService { ...@@ -381,4 +381,28 @@ public class AuthServiceImpl implements AuthService {
} }
return null; 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);
}
} }
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