|
|
@@ -38,10 +38,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
|
+import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.data.relational.core.query.Criteria;
|
|
|
import org.springframework.data.relational.core.query.Query;
|
|
|
|
|
|
+import org.springframework.http.server.reactive.ServerHttpRequest;
|
|
|
+
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.server.ServerWebExchange;
|
|
|
import reactor.core.publisher.Flux;
|
|
|
@@ -50,6 +53,9 @@ import reactor.core.publisher.Mono;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
+import java.net.InetSocketAddress;
|
|
|
+import java.time.Duration;
|
|
|
+
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -76,6 +82,8 @@ public class PlanNewCommonOutController {
|
|
|
@Resource
|
|
|
private StringRedisTemplate stringRedisTemplate;
|
|
|
@Resource
|
|
|
+ private ReactiveRedisTemplate<String,String> reactiveRedisTemplate;
|
|
|
+ @Resource
|
|
|
private TakeawayServicesInterface takeawayServicesInterface;
|
|
|
@Resource
|
|
|
private IpAnalyzeServiceInterface ipAnalyzeServiceInterface;
|
|
|
@@ -500,12 +508,12 @@ public class PlanNewCommonOutController {
|
|
|
planNew = this.getListeningPlan(request);
|
|
|
} else if (3 == request.getTypePlan() ||6 == request.getTypePlan() ||7 == request.getTypePlan()) {
|
|
|
// 交友裂变
|
|
|
- planNew = this.getFriendPlan(request);
|
|
|
+ planNew = this.getFriendPlan(request,exchange);
|
|
|
} else if (4 == request.getTypePlan()) {
|
|
|
planNew = this.getTakeaway(request);
|
|
|
}else{
|
|
|
// 交友裂变
|
|
|
- planNew = this.getFriendPlan(request);
|
|
|
+ planNew = this.getFriendPlan(request,exchange);
|
|
|
}
|
|
|
Mono<Boolean> rateReturn = blacklistService.getRateReturn(exchange);
|
|
|
return rateReturn.flatMap(bl->{
|
|
|
@@ -629,7 +637,7 @@ public class PlanNewCommonOutController {
|
|
|
/**
|
|
|
* 交友裂变
|
|
|
*/
|
|
|
- private Mono<RStatus<DomainSelectRes>> getFriendPlan(OutDomainRequest request) {
|
|
|
+ private Mono<RStatus<DomainSelectRes>> getFriendPlan(OutDomainRequest request, ServerWebExchange exchange) {
|
|
|
Mono<String> stringMono;
|
|
|
if (StrUtil.isBlank(request.getLandingPageDomain()) || request.getLandingPageDomain().trim().isEmpty()) {
|
|
|
stringMono = Mono.just(" ");
|
|
|
@@ -696,11 +704,31 @@ public class PlanNewCommonOutController {
|
|
|
domainSelectRes.setTransferPageDomain(tuple3.getT2());
|
|
|
domainSelectRes.setBackgroupDomain(tuple3.getT3());
|
|
|
domainSelectRes.setPath("");
|
|
|
- domainSelectRes.setUnique(IdUtil.fastSimpleUUID());
|
|
|
+ String s = setUnique(exchange);
|
|
|
+ domainSelectRes.setUnique(s+tuple3.getT1());
|
|
|
return Mono.just(domainSelectRes);
|
|
|
});
|
|
|
return RStatus.success(res);
|
|
|
}
|
|
|
+ public String sanitizeKey(String key) {
|
|
|
+ // 去除空格、换行、不可见字符、特殊符号等
|
|
|
+ return key.replaceAll("[\\s\\n\\r\\t]", "") // 去除空白字符、换行符、制表符等
|
|
|
+ .replaceAll("[{}\"]", "_"); // 替换大括号和引号为下划线
|
|
|
+ }
|
|
|
+ //用户ID的生成逻辑调整,改为ip+ua+落地一级域名的形式生成用户ID(效果:用户在不同的落地页里都需要解锁同一相册)
|
|
|
+ public String setUnique(ServerWebExchange exchange){
|
|
|
+ ServerHttpRequest httpRequest = exchange.getRequest();
|
|
|
+ InetSocketAddress remoteAddress = httpRequest.getRemoteAddress();
|
|
|
+ // 从请求头中获取 User-Agent
|
|
|
+ String ipAddress;
|
|
|
+ if (remoteAddress != null) {
|
|
|
+ ipAddress = remoteAddress.getAddress().getHostAddress();
|
|
|
+ } else {
|
|
|
+ ipAddress = null;
|
|
|
+ }
|
|
|
+ String first = httpRequest.getHeaders().getFirst("User-Agent");
|
|
|
+ return sanitizeKey(ipAddress+first);
|
|
|
+ }
|
|
|
|
|
|
private Mono<RStatus<DomainSelectRes>> getTakeaway(OutDomainRequest request) {
|
|
|
Mono<String> stringMono;
|
|
|
@@ -878,22 +906,35 @@ public class PlanNewCommonOutController {
|
|
|
});
|
|
|
Mono<List<AlbumReq>> albumList = Mono.just(List.of());
|
|
|
if (Objects.nonNull(request.getAlbumNum()) && 0 != request.getAlbumNum()) {
|
|
|
- Mono<List<Long>> album_id = template.select(Query.query(Criteria.where("group_id").is(plan.groupId())).columns("album_id"), Album.class).flatMap(album -> Mono.just(album.albumId())).collectList();
|
|
|
- albumList = album_id.flatMap(lists -> {
|
|
|
- if (lists.isEmpty() || lists.size() < request.getAlbumNum()) {
|
|
|
- return Mono.error(new BaseException(StrUtil.format("相册素材数:{};计划要求素材数:{} 不匹配", lists.size(), request.getAlbumNum())));
|
|
|
- }
|
|
|
- List<Long> longs = new ArrayList<>();
|
|
|
- for (int i = 0; i < request.getAlbumNum(); i++) {
|
|
|
- List<Long> collect = lists.stream().filter(f -> !longs.contains(f)).collect(Collectors.toList());
|
|
|
- Long aLong = collect.get(RandomUtil.randomInt(0, collect.size()));
|
|
|
- longs.add(aLong);
|
|
|
+ Mono<String> stringMono = reactiveRedisTemplate.opsForValue().get(request.getUnique()+"_albumList").switchIfEmpty(Mono.just(""));
|
|
|
+ albumList = stringMono.flatMap(s -> {
|
|
|
+ if (!"".equals(s)) {
|
|
|
+ JSONArray jsonArray = JSONUtil.parseArray(s);
|
|
|
+ List<AlbumReq> collect = jsonArray.stream().map(o -> {
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(o);
|
|
|
+ return JSONUtil.toBean(jsonObject, AlbumReq.class);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return Mono.just(collect);
|
|
|
}
|
|
|
- Mono<List<AlbumReq>> listMono = Flux.fromIterable(longs).flatMap(id -> {
|
|
|
- return sourceMaterialInterface.infoAlbum(id);
|
|
|
- }).collectList();
|
|
|
- return listMono;
|
|
|
+ Mono<List<Long>> album_id = template.select(Query.query(Criteria.where("group_id").is(plan.groupId())).columns("album_id"), Album.class)
|
|
|
+ .flatMap(album -> Mono.just(album.albumId())).collectList();
|
|
|
+ return album_id.flatMap(lists -> {
|
|
|
+ if (lists.isEmpty() || lists.size() < request.getAlbumNum()) {
|
|
|
+ return Mono.error(new BaseException(StrUtil.format("相册素材数:{};计划要求素材数:{} 不匹配", lists.size(), request.getAlbumNum())));
|
|
|
+ }
|
|
|
+ List<Long> longs = new ArrayList<>();
|
|
|
+ for (int i = 0; i < request.getAlbumNum(); i++) {
|
|
|
+ List<Long> collect = lists.stream().filter(f -> !longs.contains(f)).collect(Collectors.toList());
|
|
|
+ Long aLong = collect.get(RandomUtil.randomInt(0, collect.size()));
|
|
|
+ longs.add(aLong);
|
|
|
+ }
|
|
|
+ Mono<List<AlbumReq>> listMono = Flux.fromIterable(longs).flatMap(id -> {
|
|
|
+ return sourceMaterialInterface.infoAlbum(id);
|
|
|
+ }).collectList();
|
|
|
+ return listMono;
|
|
|
+ });
|
|
|
});
|
|
|
+
|
|
|
}
|
|
|
Mono<PlanNewCommonMaterialRes> planNewCommonMaterialResMono = Mono.zip(groupAudio, retAudio, returnLoop, backgroupImageItemMono, takeaway, adTop1, adBottom2, imageMono).flatMap(f -> {
|
|
|
PlanNewCommonMaterialRes materialRes = new PlanNewCommonMaterialRes();
|
|
|
@@ -919,7 +960,6 @@ public class PlanNewCommonOutController {
|
|
|
}
|
|
|
return Mono.just(materialRes);
|
|
|
});
|
|
|
-
|
|
|
Mono<List<DuanjuMaterialRes>> duanju = Mono.just(List.of());
|
|
|
Mono<List<H5ImageAndText>> kefu = Mono.just(List.of());
|
|
|
if (plan.type() == 8 &&Objects.nonNull(request.getImageAndTxtNum())&& request.getImageAndTxtNum() > 0) {
|
|
|
@@ -997,6 +1037,8 @@ public class PlanNewCommonOutController {
|
|
|
List<AlbumReq> t2 = tuple.getT2();
|
|
|
PlanNewCommonMaterialRes t1 = tuple.getT1();
|
|
|
if(!t2.isEmpty()){
|
|
|
+ String s = JSONUtil.toJsonStr(t2);
|
|
|
+ reactiveRedisTemplate.opsForValue().set(request.getUnique()+"_albumList",s, Duration.ofHours(2L)).subscribe();
|
|
|
t1.setAlbumList(t2);
|
|
|
}
|
|
|
t1.setDJs(tuple.getT3());
|