Parcourir la source

ip限制-v0.01

MOKASZ\lw12420 il y a 1 an
Parent
commit
52889cc562

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

@@ -109,6 +109,7 @@ public class PlanNewCommonOutController {
                 .switchIfEmpty(Mono.error(new BaseException("计划code异")))
                 .onErrorResume(throwable -> Mono.error(new BaseException("计划code异")));
         Mono<PlanNewCommonRes> resMono = planNewCommonMono.flatMap(f -> {
+
             if(Objects.nonNull(f.type()) && 5==f.type()){
                 PlanNewCommonRes res = new PlanNewCommonRes();
                 res.setCode(code);
@@ -141,7 +142,7 @@ public class PlanNewCommonOutController {
                     return Mono.just(groupUserResList);
                 });
             }
-            return Mono.zip(Mono.just(f), groupUserResMono, imageMono, textMono).flatMap(tuple -> {
+            Mono<PlanNewCommonRes> planNewCommonResMono = Mono.zip(Mono.just(f), groupUserResMono, imageMono, textMono).flatMap(tuple -> {
                 PlanNewCommon plan = tuple.getT1();
                 PlanNewCommonRes res = new PlanNewCommonRes();
                 res.setCode(plan.code());
@@ -163,8 +164,8 @@ public class PlanNewCommonOutController {
                 if (!materialList.isEmpty()) {
                     Material material = materialList.get(RandomUtil.randomInt(0, materialList.size()));
                     String content = material.content();
-                    String clientIP=null ;//exchange.getRequest().getHeaders().getFirst("X-Forwarded-For");
-                    if ( Objects.nonNull(exchange.getRequest().getRemoteAddress())) {
+                    String clientIP = null;//exchange.getRequest().getHeaders().getFirst("X-Forwarded-For");
+                    if (Objects.nonNull(exchange.getRequest().getRemoteAddress())) {
                         clientIP = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
                     }
                     if (StrUtil.isNotBlank(clientIP)) {
@@ -188,10 +189,24 @@ public class PlanNewCommonOutController {
                 res.setGroupImageAndTextList(h5ImageAndTextList);
                 return Mono.just(res);
             });
+            int type = f.type();
+            if (type == 3 || type == 6 || type == 7) {
+                Mono<Boolean> rateReturn = blacklistService.getRateReturn(exchange);
+                return rateReturn.flatMap(bl->{
+                    if(bl){
+                        return  planNewCommonResMono;
+                    }else {
+                        PlanNewCommonRes dataLists = new PlanNewCommonRes();
+                        //dataLists.setWxUrl(BlacklistService.wxUrl.get());
+                        return Mono.just(dataLists);
+                    }
+                });
+            }else {
+                return  planNewCommonResMono;
+            }
         });
         // GZIP压缩
        // Mono<byte[]> res = resMono.flatMap(f -> Mono.just(Objects.requireNonNull(this.compressData(JSONUtil.toJsonStr(f)))));
-
         return RStatus.success(resMono);
     }
 
@@ -1157,7 +1172,7 @@ public class PlanNewCommonOutController {
      * @return {@link Mono}<{@link RStatus}<{@link PlanNewCommonShareRes}>>
      */
     @PostMapping("planCommonShare")
-    public Mono<RStatus<PlanNewCommonShareRes>> planCommonShare(@RequestBody PlanNewCommonShareReq request) {
+    public Mono<RStatus<PlanNewCommonShareRes>> planCommonShare(@RequestBody PlanNewCommonShareReq request,ServerWebExchange exchange) {
         if (request.getCode() == null || request.getCode().isEmpty()) {
             throw new BaseException("code不能为空");
         }
@@ -1251,7 +1266,24 @@ public class PlanNewCommonOutController {
         Mono<PlanNewCommonShareRes> resMono1 = this.setEndData(request, setFmV(setAudioV(request, resMono)));
         // GZIP压缩
         // Mono<byte[]> res = resMono1.flatMap(f -> Mono.just(Objects.requireNonNull(this.compressData(JSONUtil.toJsonStr(f)))));
-        return RStatus.successList(resMono1);
+        Mono<PlanNewCommonShareRes> planNewCommonShareResMono = planNewCommonMono.flatMap(planNewCommon -> {
+            int type = planNewCommon.type();
+            if (type == 3 || type == 6 || type == 7) {
+                Mono<Boolean> rateReturn = blacklistService.getRateReturn(exchange);
+                return rateReturn.flatMap(bl -> {
+                    if (bl) {
+                        return resMono1;
+                    } else {
+                        PlanNewCommonShareRes dataLists = new PlanNewCommonShareRes();
+                        //dataLists.setWxUrl(BlacklistService.wxUrl.get());
+                        return Mono.just(dataLists);
+                    }
+                });
+            } else {
+                return resMono1;
+            }
+        });
+         return RStatus.successList(planNewCommonShareResMono);
     }
 
     /**

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

@@ -598,8 +598,17 @@ public class PlanNewOutController {
             });
             return dataListsMono;
         });
-
-        return RStatus.successList(dataListsMono1);
+        Mono<Boolean> rateReturn = blacklistService.getRateReturn(exchange);
+        return rateReturn.flatMap(bl->{
+            if(bl){
+                return  RStatus.successList(dataListsMono1) ;
+            }else {
+                DataLists dataLists = new DataLists();
+                //dataLists.setWxUrl(BlacklistService.wxUrl.get());
+                return RStatus.success(Mono.just(dataLists));
+            }
+        });
+        //return RStatus.successList(dataListsMono1);
     }
 
 
@@ -614,7 +623,7 @@ public class PlanNewOutController {
      * @return {@link Mono}<{@link RStatus}<{@link DataLists}>>
      */
     @PostMapping("hftInfo")
-    public Mono<RStatus<DataLists0>> hftInfo(@RequestBody HftRequest request){
+    public Mono<RStatus<DataLists0>> hftInfo(@RequestBody HftRequest request, ServerWebExchange exchange){
         if (request.getCode() == null || request.getCode().isEmpty()) {
             throw new BaseException("code不能为空");
         }
@@ -703,7 +712,17 @@ public class PlanNewOutController {
         });
 
         Mono<DataLists0> dataLists0Mono1 = setEndData(request, setFmV(request, setAudioV(request, dataLists0Mono)));
-        return RStatus.successList(dataLists0Mono1);
+        Mono<Boolean> rateReturn = blacklistService.getRateReturn(exchange);
+        return rateReturn.flatMap(bl->{
+            if(bl){
+                return  RStatus.successList(dataLists0Mono1) ;
+            }else {
+                DataLists0 dataLists = new DataLists0();
+                //dataLists.setWxUrl(BlacklistService.wxUrl.get());
+                return RStatus.success(Mono.just(dataLists));
+            }
+        });
+        //return RStatus.successList(dataLists0Mono1);
     }
 //设置二维码 生成图片
     private Mono<DataLists0> setEndData(HftRequest request, Mono<DataLists0> dataLists0Mono2) {