Browse Source

全链路:::::ip+黑白名单+访问限制-v0.02

MOKASZ\lw12420 1 year ago
parent
commit
08eebd79df

+ 0 - 3
launch-admin/src/main/java/com/webflux/launchadmin/mysql/controller/listening/req/ListeningDataLists.java

@@ -29,8 +29,5 @@ public class ListeningDataLists {
      */
     List<H5ImageAndTextListening> images;
 
-    private String wxUrl;
-
-
 
 }

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

@@ -114,8 +114,7 @@ public class PlanNewOutController {
      * @return {@link Mono}<{@link RStatus}<{@link DomainSelectRes}>>
      */
     @GetMapping("domain/select")
-
-    public Mono<RStatus<DomainSelectRes>> domainSelect(@RequestParam("code") String code,@RequestParam("type") String type ,@RequestParam("typePlan") Integer typePlan ){
+    public Mono<RStatus<DomainSelectRes>> domainSelect(@RequestParam("code") String code,@RequestParam("type") String type ,@RequestParam("typePlan") Integer typePlan , ServerWebExchange exchange ){
         if (1 == typePlan) {
             Mono<PlanNew> code1 = template
                     .selectOne(Query.query(Criteria.where("code").is(code)), PlanNew.class)
@@ -192,33 +191,54 @@ public class PlanNewOutController {
                     return Mono.just(domainSelectRes);
                 });
             });
-            return RStatus.success(domainSelectResMono1);
+            Mono<Boolean> rateReturn = blacklistService.getRateReturn(exchange);
+            return rateReturn.flatMap(bl->{
+                if(bl){
+                    return  RStatus.successList(domainSelectResMono1) ;
+                }else {
+                    DomainSelectRes dataLists = new DomainSelectRes();
+                    dataLists.setWxUrl(BlacklistService.wxUrl.get());
+                    return RStatus.fail("1","",Mono.just(dataLists));
+                }
+            });
+          //  return RStatus.success(domainSelectResMono1);
         }else  if(2==typePlan){
-            Long start = System.currentTimeMillis();
-            Object planCache = stringRedisTemplate.opsForHash().get(RedisKey.PLAN_LISTEN_INFO,code);
-            if (planCache == null){
-                throw new BaseException("未获取到计划信息");
-            }
-            ListeningPlanNew planInfo = com.alibaba.fastjson.JSONObject.parseObject(planCache.toString(),ListeningPlanNew.class);
-            String idKey = RedisKey.DOMAIN_RAND_ID + planInfo.groupId().toString() + ":" + type.toString();
-            String domainId = stringRedisTemplate.opsForSet().randomMember(idKey);
-            if (domainId.isEmpty()){
-                throw new BaseException("缓存"+ idKey + "不存在");
-            }
-            Object domainInfoCache = stringRedisTemplate.opsForHash().get(RedisKey.DOMAIN_INFO,domainId);
-            if (domainInfoCache == null){
-                throw new BaseException("缓存" + RedisKey.DOMAIN_INFO + "指定域名信息不存在");
-            }
-            DomainSelect domainInfo = com.alibaba.fastjson.JSONObject.parseObject(domainInfoCache.toString(),DomainSelect.class);
-            DomainSelectRes domainSelectRes = new DomainSelectRes();
-            String domain = domainInfo.domain();
-            String string = RandomStr.getRandomStr(code);
-            domainSelectRes.setDomain(string+"."+domain);
-            domainSelectRes.setPath("");
-            domainSelectRes.setUnique(IdUtil.fastSimpleUUID());
-            Long end = System.currentTimeMillis();
-            log.info("volta-time:{}-{}-{}",start,end,start-end);
-            return RStatus.success(Mono.just(domainSelectRes));
+
+            Mono<Boolean> rateReturn = blacklistService.getRateReturn(exchange);
+            return rateReturn.flatMap(bl->{
+                if(bl){
+                    Long start = System.currentTimeMillis();
+                    Object planCache = stringRedisTemplate.opsForHash().get(RedisKey.PLAN_LISTEN_INFO,code);
+                    if (planCache == null){
+                        throw new BaseException("未获取到计划信息");
+                    }
+                    ListeningPlanNew planInfo = com.alibaba.fastjson.JSONObject.parseObject(planCache.toString(),ListeningPlanNew.class);
+                    String idKey = RedisKey.DOMAIN_RAND_ID + planInfo.groupId().toString() + ":" + type.toString();
+                    String domainId = stringRedisTemplate.opsForSet().randomMember(idKey);
+                    if (domainId.isEmpty()){
+                        throw new BaseException("缓存"+ idKey + "不存在");
+                    }
+                    Object domainInfoCache = stringRedisTemplate.opsForHash().get(RedisKey.DOMAIN_INFO,domainId);
+                    if (domainInfoCache == null){
+                        throw new BaseException("缓存" + RedisKey.DOMAIN_INFO + "指定域名信息不存在");
+                    }
+                    DomainSelect domainInfo = com.alibaba.fastjson.JSONObject.parseObject(domainInfoCache.toString(),DomainSelect.class);
+                    DomainSelectRes domainSelectRes = new DomainSelectRes();
+                    String domain = domainInfo.domain();
+                    String string = RandomStr.getRandomStr(code);
+                    domainSelectRes.setDomain(string+"."+domain);
+                    domainSelectRes.setPath("");
+                    domainSelectRes.setUnique(IdUtil.fastSimpleUUID());
+                    Long end = System.currentTimeMillis();
+                    log.info("volta-time:{}-{}-{}",start,end,start-end);
+                    return  RStatus.successList(Mono.just(domainSelectRes)) ;
+                }else {
+                    DomainSelectRes dataLists = new DomainSelectRes();
+                    dataLists.setWxUrl(BlacklistService.wxUrl.get());
+                    return RStatus.fail("1","",Mono.just(dataLists));
+                }
+            });
+           // return RStatus.success(Mono.just(domainSelectRes));
         }
         throw new BaseException("typePlan 类型错误");
 
@@ -579,17 +599,8 @@ public class PlanNewOutController {
             });
             return dataListsMono;
         });
-        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.fail("1","",Mono.just(dataLists));
-            }
-        });
-       // return RStatus.successList(dataListsMono1);
+
+        return RStatus.successList(dataListsMono1);
     }
 
 

+ 0 - 2
launch-admin/src/main/java/com/webflux/launchadmin/mysql/controller/planNew/res/DataLists.java

@@ -59,7 +59,5 @@ public class DataLists {
     private String backgroupDomain;//背景组域名
 
     private String  listButton;
-    private String wxUrl;
-
 
 }

+ 2 - 0
launch-admin/src/main/java/com/webflux/launchadmin/mysql/controller/planNew/res/DomainSelectRes.java

@@ -22,4 +22,6 @@ public class DomainSelectRes {
      * 背景组域名
      */
     private String backgroupDomain;
+
+    private String wxUrl;
 }

+ 1 - 1
launch-admin/src/main/java/com/webflux/launchadmin/mysql/service/ip/BlacklistService.java

@@ -64,7 +64,7 @@ public class BlacklistService {
             try {
                 return getIpRateNum(ipAddress);
             }catch (Exception e){
-                log.error("ip黑名单验证Error:::"+e.getMessage());
+                log.error("ip黑名单验证:" +ipAddress+"::Error:::"+e.getMessage());
                 return Mono.just(false);
             }
         }

+ 1 - 11
launch-admin/src/main/java/com/webflux/launchadmin/mysql/service/listening/ListeningPlanServiceImpl.java

@@ -459,17 +459,7 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
                 return Mono.just(listeningDataLists);
             });
         });
-        Mono<Boolean> rateReturn = blacklistService.getRateReturn(exchange);
-        return rateReturn.flatMap(bl->{
-            if(bl){
-                return  RStatus.success(idx_num1) ;
-            }else {
-                ListeningDataLists dataLists = new ListeningDataLists();
-                dataLists.setWxUrl(BlacklistService.wxUrl.get());
-                return RStatus.fail("1","",Mono.just(dataLists));
-            }
-        });
-       // return RStatus.success(idx_num1);
+        return RStatus.success(idx_num1);
     }
     private static final ConcurrentHashMap<String,Integer> map = new ConcurrentHashMap<>();
     //清空用户Map数据