Browse Source

广告-v0.09

MOKASZ\lw12420 1 year ago
parent
commit
228fdc1b3d

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

@@ -493,14 +493,16 @@ public class PlanNewCommonOutController {
         } else if (2 == request.getTypePlan()) {
         } else if (2 == request.getTypePlan()) {
             // 听书裂变
             // 听书裂变
             planNew = this.getListeningPlan(request);
             planNew = this.getListeningPlan(request);
-        } else if (3 == request.getTypePlan() ||6 == request.getTypePlan() ||7 == request.getTypePlan()) {
+        } else if (3 == request.getTypePlan() ||6 == request.getTypePlan()) {
             // 交友裂变
             // 交友裂变
-            planNew = this.getFriendPlan(request,exchange);
-        } else if (4 == request.getTypePlan()) {
+            planNew = this.getFriendPlan(request);
+        } else if (7 == request.getTypePlan()) {
+            planNew = this.getAlbum(request,exchange);
+        }else if (4 == request.getTypePlan()) {
             planNew = this.getTakeaway(request);
             planNew = this.getTakeaway(request);
         }else{
         }else{
             // 交友裂变
             // 交友裂变
-            planNew = this.getFriendPlan(request,exchange);
+            planNew = this.getFriendPlan(request);
         }
         }
         Mono<Boolean> rateReturn = blacklistService.getRateReturn(exchange);
         Mono<Boolean> rateReturn = blacklistService.getRateReturn(exchange);
         return rateReturn.flatMap(bl->{
         return rateReturn.flatMap(bl->{
@@ -624,7 +626,7 @@ public class PlanNewCommonOutController {
     /**
     /**
      * 交友裂变
      * 交友裂变
      */
      */
-    private Mono<RStatus<DomainSelectRes>> getFriendPlan(OutDomainRequest request, ServerWebExchange exchange) {
+    private Mono<RStatus<DomainSelectRes>> getFriendPlan(OutDomainRequest request) {
         Mono<String> stringMono;
         Mono<String> stringMono;
         if (StrUtil.isBlank(request.getLandingPageDomain()) || request.getLandingPageDomain().trim().isEmpty()) {
         if (StrUtil.isBlank(request.getLandingPageDomain()) || request.getLandingPageDomain().trim().isEmpty()) {
             stringMono = Mono.just(" ");
             stringMono = Mono.just(" ");
@@ -691,30 +693,109 @@ public class PlanNewCommonOutController {
             domainSelectRes.setTransferPageDomain(tuple3.getT2());
             domainSelectRes.setTransferPageDomain(tuple3.getT2());
             domainSelectRes.setBackgroupDomain(tuple3.getT3());
             domainSelectRes.setBackgroupDomain(tuple3.getT3());
             domainSelectRes.setPath("");
             domainSelectRes.setPath("");
-            String s = setUnique(exchange);
-            domainSelectRes.setUnique(s+tuple3.getT1());
+            domainSelectRes.setUnique(IdUtil.fastSimpleUUID());
             return Mono.just(domainSelectRes);
             return Mono.just(domainSelectRes);
         });
         });
         return RStatus.success(res);
         return RStatus.success(res);
     }
     }
-    public  String sanitizeKey(String key) {
-        // 去除空格、换行、不可见字符、特殊符号等
-        return key.replaceAll("[\\s\\n\\r\\t]", "")  // 去除空白字符、换行符、制表符等
-                .replaceAll("[{}\"]", "_");           // 替换大括号和引号为下划线
+    private Mono<RStatus<DomainSelectRes>> getAlbum(OutDomainRequest request, ServerWebExchange exchange) {
+        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)
+                    .switchIfEmpty(Mono.error(new BaseException("查询domain 返回结果为空")))
+                    .onErrorResume(throwable -> Mono.error(new BaseException("查询domain 返回结果为空")))
+                    .collectList().flatMap(fm -> {
+                        int i = RandomUtil.randomInt(0, fm.size());
+                        String domain = fm.get(i).domain();
+                        String string = RandomStr.getRandomStr(request.getCode());
+                        return Mono.just(string + "." + domain);
+                    });
+        }
+        Mono<String> transferPageDomain;
+        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)
+                    .switchIfEmpty(Mono.error(new BaseException("transferPageDomain 域名查詢為空 group_type_id:::" + request.getTransferPageDomain())))
+                    .onErrorResume(throwable -> Mono.error(new BaseException(throwable.getMessage()))).collectList().flatMap(fff -> {
+                        if (!fff.isEmpty()) {
+                            DomainSelect domainSelect = fff.get(RandomUtil.randomInt(0, fff.size()));
+                            String string = RandomStr.getRandomStr(request.getCode());
+                            String domain1 = domainSelect.domain();
+                            return Mono.just(string + "." + domain1);
+                        } else {
+                            return Mono.error(new BaseException("transferPageDomain 中轉域名查詢為空 group_type_id:::" + request.getTransferPageDomain()));
+                        }
+                    });
+        } else {
+            transferPageDomain = Mono.just(" ");
+        }
+        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)
+                    .switchIfEmpty(Mono.error(new BaseException("backgroupDomain 域名查询为空 group_type_id" + request.getBackgroupDomain())))
+                    .onErrorResume(throwable -> Mono.error(new BaseException(throwable.getMessage()))).collectList().flatMap(fff -> {
+                        if (!fff.isEmpty()) {
+                            DomainSelect domainSelect = fff.get(RandomUtil.randomInt(0, fff.size()));
+                            String string = RandomStr.getRandomStr(request.getCode());
+                            String domain1 = domainSelect.domain();
+                            return Mono.just(string + "." + domain1);
+                        } else {
+                            return Mono.error(new BaseException("backgroupDomain 背景域名查詢為空 group_type_id" + request.getBackgroupDomain()));
+                        }
+                    });
+        } else {
+            backgroupDomain = Mono.just(" ");
+        }
+        Mono<DomainSelectRes> res = Mono.zip(stringMono, transferPageDomain, backgroupDomain).flatMap(tuple3 -> {
+            DomainSelectRes domainSelectRes = new DomainSelectRes();
+            domainSelectRes.setDomain(tuple3.getT1());
+            domainSelectRes.setTransferPageDomain(tuple3.getT2());
+            domainSelectRes.setBackgroupDomain(tuple3.getT3());
+            domainSelectRes.setPath("");
+            String s = setUnique(exchange);
+            String t1 = tuple3.getT1();
+            if (!"".equals(t1.trim())) {
+                String[] split = t1.split("\\.");
+                if (split.length > 1) {
+                    StringBuilder stringBuilder = new StringBuilder();
+                    for (int i = 0; i < split.length; i++) {
+                        if(i!=0){
+                            stringBuilder.append(split[i]);
+                        }
+                    }
+                    t1=stringBuilder.toString();
+                }
+            }
+            domainSelectRes.setUnique(s+t1);
+            return Mono.just(domainSelectRes);
+        });
+        return RStatus.success(res);
     }
     }
+
     //用户ID的生成逻辑调整,改为ip+ua+落地一级域名的形式生成用户ID(效果:用户在不同的落地页里都需要解锁同一相册)
     //用户ID的生成逻辑调整,改为ip+ua+落地一级域名的形式生成用户ID(效果:用户在不同的落地页里都需要解锁同一相册)
     public String setUnique(ServerWebExchange exchange){
     public String setUnique(ServerWebExchange exchange){
         ServerHttpRequest httpRequest = exchange.getRequest();
         ServerHttpRequest httpRequest = exchange.getRequest();
         InetSocketAddress remoteAddress = httpRequest.getRemoteAddress();
         InetSocketAddress remoteAddress = httpRequest.getRemoteAddress();
         // 从请求头中获取 User-Agent
         // 从请求头中获取 User-Agent
-        String ipAddress;
+        StringBuilder stringBuilder = new StringBuilder();
         if (remoteAddress != null) {
         if (remoteAddress != null) {
-            ipAddress = remoteAddress.getAddress().getHostAddress();
-        } else {
-            ipAddress = null;
+            stringBuilder.append(remoteAddress.getAddress().getHostAddress());
         }
         }
-        String first = httpRequest.getHeaders().getFirst("User-Agent");
-        return sanitizeKey(ipAddress+first);
+        stringBuilder.append(httpRequest.getHeaders().getFirst("User-Agent"));
+        return stringBuilder.toString().replaceAll("[\\s{}\"'\\\\]", "_");
     }
     }
 
 
     private Mono<RStatus<DomainSelectRes>> getTakeaway(OutDomainRequest request) {
     private Mono<RStatus<DomainSelectRes>> getTakeaway(OutDomainRequest request) {