Преглед изворни кода

Merge branch 'pro' of http://git.mokasz.com/liuwei/launch-webFlux-platform into pro

volta пре 2 година
родитељ
комит
26b60dcd28

+ 7 - 3
launch-admin/src/main/java/com/webflux/launchadmin/filter/TraceIdFilter.java

@@ -2,8 +2,10 @@ package com.webflux.launchadmin.filter;
 
 import com.plumelog.core.TraceId;
 import lombok.SneakyThrows;
+import org.jetbrains.annotations.NotNull;
 import org.springframework.http.server.reactive.ServerHttpRequest;
 import org.springframework.stereotype.Component;
+import org.springframework.util.MultiValueMap;
 import org.springframework.web.server.ServerWebExchange;
 import org.springframework.web.server.WebFilter;
 import org.springframework.web.server.WebFilterChain;
@@ -15,9 +17,10 @@ import reactor.core.publisher.Mono;
  */
 @Component
 public class TraceIdFilter implements WebFilter {
+    @NotNull
     @SneakyThrows
     @Override
-    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
+    public Mono<Void> filter(@NotNull ServerWebExchange exchange, @NotNull WebFilterChain chain) {
         try {
             ServerHttpRequest request = exchange.getRequest();
             String traceId = request.getQueryParams().getFirst("traceId");
@@ -26,8 +29,9 @@ public class TraceIdFilter implements WebFilter {
             } else {
                 TraceId.logTraceID.set(traceId);
             }
-        } finally {
-            return chain.filter(exchange);
+        } catch (Exception e) {
+            TraceId.set();
         }
+        return chain.filter(exchange);
     }
 }

+ 7 - 1
launch-admin/src/main/java/com/webflux/launchadmin/global/GlobalExceptionHandler.java

@@ -14,6 +14,7 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.bind.annotation.ResponseStatus;
 import org.springframework.web.bind.annotation.RestControllerAdvice;
 import org.springframework.web.multipart.MaxUploadSizeExceededException;
+import org.springframework.web.server.MissingRequestValueException;
 import org.springframework.web.server.ServerWebExchange;
 import reactor.core.publisher.Mono;
 
@@ -50,7 +51,12 @@ public class GlobalExceptionHandler {
         log.warn("接口异常 uri = {} e = {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
         return RW.fail(HttpStatus.FORBIDDEN.toString(), "没有权限,请联系管理员授权", Mono.just(e.getMessage()));
     }
-
+    //@ResponseStatus(HttpStatus.BAD_REQUEST)
+    @ExceptionHandler(MissingRequestValueException.class)
+    public Mono<RW<Object>> handleMissingRequestValueException(ServerWebExchange exchange, AccessDeniedException e) {
+        log.warn("接口异常 uri = {} e = {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));
+        return RW.fail(HttpStatus.FORBIDDEN.toString(), "请求参数异常", Mono.just(e.getMessage()));
+    }
     @ExceptionHandler(AccountExpiredException.class)
     public Mono<RW<Object>> handleAccountExpiredException(ServerWebExchange exchange, AccountExpiredException e) {
         log.warn("接口异常 uri = {} e = {}", exchange.getRequest().getPath().value(), LogExceptionStackTrace.erroStackTrace(e));

+ 24 - 23
launch-admin/src/main/java/com/webflux/launchadmin/mysql/controller/planNew/PlanNewCommonOutController.java

@@ -271,10 +271,10 @@ public class PlanNewCommonOutController {
         } else if (2 == request.getTypePlan()) {
             // 听书裂变
             return this.getListeningPlan(request);
-        } else if(3==request.getTypePlan()){
+        } else if (3 == request.getTypePlan()) {
             // 交友裂变
             return this.getFriendPlan(request);
-        }else if(4==request.getTypePlan()){
+        } else if (4 == request.getTypePlan()) {
             return this.getTakeaway(request);
         }
         throw new BaseException("typePlan 类型错误");
@@ -409,12 +409,12 @@ public class PlanNewCommonOutController {
                     });
         }
         Mono<String> transferPageDomain;
-        if ( Objects.nonNull(request.getTransferPageDomain()) && StringUtils.isNotEmpty(request.getTransferPageDomain())) {
+        if (Objects.nonNull(request.getTransferPageDomain()) && StringUtils.isNotEmpty(request.getTransferPageDomain())) {
             transferPageDomain = template.select(Query.query(Criteria
-                    .where("group_type_id").is(request.getTransferPageDomain())
-                    .and("status").is(1)
-                    .and("type").is(5)
-                    .and("deleted_at").isNull()), DomainSelect.class)
+                            .where("group_type_id").is(request.getTransferPageDomain())
+                            .and("status").is(1)
+                            .and("type").is(5)
+                            .and("deleted_at").isNull()), DomainSelect.class)
                     .switchIfEmpty(Mono.error(new BaseException("transferPageDomain 域名查詢為空 group_type_id:::" + request.getTransferPageDomain())))
                     .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage()))).collectList().flatMap(fff -> {
                         if (!fff.isEmpty()) {
@@ -423,7 +423,7 @@ public class PlanNewCommonOutController {
                             String domain1 = domainSelect.domain();
                             return Mono.just(string + "." + domain1);
                         } else {
-                            throw new BaseException("transferPageDomain 中轉域名查詢為空 group_type_id:::" +  request.getTransferPageDomain());
+                            throw new BaseException("transferPageDomain 中轉域名查詢為空 group_type_id:::" + request.getTransferPageDomain());
                         }
                     });
         } else {
@@ -432,10 +432,10 @@ public class PlanNewCommonOutController {
         Mono<String> backgroupDomain;
         if (Objects.nonNull(request.getBackgroupDomain()) && StringUtils.isNotEmpty(request.getBackgroupDomain())) {
             backgroupDomain = template.select(Query.query(Criteria
-                    .where("group_type_id").is(request.getBackgroupDomain())
-                    .and("status").is(1)
-                    .and("type").is(4)
-                    .and("deleted_at").isNull()), DomainSelect.class)
+                            .where("group_type_id").is(request.getBackgroupDomain())
+                            .and("status").is(1)
+                            .and("type").is(4)
+                            .and("deleted_at").isNull()), DomainSelect.class)
                     .switchIfEmpty(Mono.error(new BaseException("backgroupDomain 域名查询为空 group_type_id" + request.getBackgroupDomain())))
                     .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage()))).collectList().flatMap(fff -> {
                         if (!fff.isEmpty()) {
@@ -450,7 +450,7 @@ public class PlanNewCommonOutController {
         } else {
             backgroupDomain = Mono.just(" ");
         }
-        Mono<DomainSelectRes> res = Mono.zip(stringMono,transferPageDomain,backgroupDomain).flatMap(tuple3 -> {
+        Mono<DomainSelectRes> res = Mono.zip(stringMono, transferPageDomain, backgroupDomain).flatMap(tuple3 -> {
             DomainSelectRes domainSelectRes = new DomainSelectRes();
             domainSelectRes.setDomain(tuple3.getT1());
             domainSelectRes.setTransferPageDomain(tuple3.getT2());
@@ -461,16 +461,17 @@ public class PlanNewCommonOutController {
         });
         return RStatus.success(res);
     }
+
     private Mono<RStatus<DomainSelectRes>> getTakeaway(OutDomainRequest request) {
         Mono<String> stringMono;
         if (StrUtil.isBlank(request.getLandingPageDomain()) || request.getLandingPageDomain().trim().isEmpty()) {
             stringMono = Mono.just(" ");
         } else {
             stringMono = template.select(Query.query(Criteria
-                    .where("group_type_id").is(request.getLandingPageDomain())
-                    .and("status").is(1)
-                    .and("deleted_at").isNull()
-                    .and("type").is(request.getType())), DomainSelect.class)
+                            .where("group_type_id").is(request.getLandingPageDomain())
+                            .and("status").is(1)
+                            .and("deleted_at").isNull()
+                            .and("type").is(request.getType())), DomainSelect.class)
                     .switchIfEmpty(Mono.error(new BaseException("查询domain 返回结果为空")))
                     .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())))
                     .collectList().flatMap(fm -> {
@@ -526,15 +527,15 @@ public class PlanNewCommonOutController {
                         .switchIfEmpty(Mono.just(List.of()))
                         .onErrorResume(throwable -> Mono.error(new Exception(LogExceptionStackTrace.erroStackTrace(throwable).toString())));
             }
-            Mono<TakeawayH5Data> takeaway ;
+            Mono<TakeawayH5Data> takeaway;
             if (Objects.nonNull(request.getTakeawayId()) && request.getTakeawayId() > 0) {
                 takeaway = takeawayServicesInterface.getTakeaway(request.getTakeawayId())
                         .switchIfEmpty(Mono.just(new TakeawayH5Data()))
-                        .onErrorResume(e->Mono.error(new BaseException("查询外卖模版数据异常:::"+LogExceptionStackTrace.erroStackTrace(e).toString())));
-            }else {
-                takeaway=Mono.just(new TakeawayH5Data());
+                        .onErrorResume(e -> Mono.error(new BaseException("查询外卖模版数据异常:::" + LogExceptionStackTrace.erroStackTrace(e).toString())));
+            } else {
+                takeaway = Mono.just(new TakeawayH5Data());
             }
-            return Mono.zip(groupAudio, retAudio, returnLoop, backgroupImageItemMono,takeaway).flatMap(f -> {
+            return Mono.zip(groupAudio, retAudio, returnLoop, backgroupImageItemMono, takeaway).flatMap(f -> {
                 PlanNewCommonMaterialRes materialRes = new PlanNewCommonMaterialRes();
                 materialRes.setGroupAudio(f.getT1());
                 materialRes.setRetAudio(f.getT2());
@@ -615,7 +616,7 @@ public class PlanNewCommonOutController {
             if (Objects.nonNull(request.getRedirectType()) && request.getRedirectType() == 2) {
                 stringBuilderMono = goGenerateService.byPlanNewIdGetUrlCommon(request.getRedirectPlanId(), isQs, request.getGroupIdQs());
             } else {
-                stringBuilderMono = Mono.just(new StringBuilder(request.getLink()));
+                stringBuilderMono = Mono.just(new StringBuilder(request.getLink() == null ? "" : request.getLink()));
             }
             Mono<PlanNewCommon> code = Mono.just(plan);
             return Mono.zip(code, getPosterTemplate(code), getPoster(code), getPlanNewBackgroupPoster(code), getEwm(code), stringBuilderMono).flatMap(f -> {

+ 3 - 0
launch-admin/src/main/java/com/webflux/launchadmin/mysql/controller/planNew/PlanNewOutController.java

@@ -317,6 +317,9 @@ public class PlanNewOutController {
      */
     @PostMapping("hfoInfo")
     public Mono<RStatus<DataLists>> hfoInfo(@RequestBody HfoRequest request, ServerWebExchange exchange){
+        if (Objects.isNull(request.getCode()) || "".equals(request.getCode().trim())) {
+          throw  new BaseException("code异常");
+        }
         ServerHttpRequest httpRequest = exchange.getRequest();
         InetSocketAddress remoteAddress = httpRequest.getRemoteAddress();
         String ipAddress;