|
@@ -7,31 +7,38 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.webflux.launchadmin.global.BaseException;
|
|
import com.webflux.launchadmin.global.BaseException;
|
|
|
import com.webflux.launchadmin.mysql.controller.planNew.req.*;
|
|
import com.webflux.launchadmin.mysql.controller.planNew.req.*;
|
|
|
import com.webflux.launchadmin.mysql.controller.planNew.res.*;
|
|
import com.webflux.launchadmin.mysql.controller.planNew.res.*;
|
|
|
import com.webflux.launchadmin.mysql.entity.groupUsers.GroupUsers;
|
|
import com.webflux.launchadmin.mysql.entity.groupUsers.GroupUsers;
|
|
|
import com.webflux.launchadmin.mysql.entity.listening.ListeningPlanNew;
|
|
import com.webflux.launchadmin.mysql.entity.listening.ListeningPlanNew;
|
|
|
import com.webflux.launchadmin.mysql.entity.planNew.*;
|
|
import com.webflux.launchadmin.mysql.entity.planNew.*;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.redis.RedisKey;
|
|
|
import com.webflux.launchadmin.mysql.service.planNew.goGenerate.GoGenerateService;
|
|
import com.webflux.launchadmin.mysql.service.planNew.goGenerate.GoGenerateService;
|
|
|
import com.webflux.launchadmin.mysql.service.planNew.ipAnalyze.IpAnalyzeServiceInterface;
|
|
import com.webflux.launchadmin.mysql.service.planNew.ipAnalyze.IpAnalyzeServiceInterface;
|
|
|
import com.webflux.launchadmin.mysql.service.planNew.structure.GoRequest;
|
|
import com.webflux.launchadmin.mysql.service.planNew.structure.GoRequest;
|
|
|
import com.webflux.launchadmin.mysql.service.planNew.structure.Item;
|
|
import com.webflux.launchadmin.mysql.service.planNew.structure.Item;
|
|
|
import com.webflux.launchcommon.returnObj.RStatus;
|
|
import com.webflux.launchcommon.returnObj.RStatus;
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
+import jakarta.json.Json;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.domain.Sort;
|
|
import org.springframework.data.domain.Sort;
|
|
|
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
|
|
|
+import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
|
|
import org.springframework.data.relational.core.query.Criteria;
|
|
import org.springframework.data.relational.core.query.Criteria;
|
|
|
import org.springframework.data.relational.core.query.Query;
|
|
import org.springframework.data.relational.core.query.Query;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import reactor.core.publisher.Mono;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.IntStream;
|
|
import java.util.stream.IntStream;
|
|
|
|
|
+import java.util.zip.GZIPOutputStream;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 通用计划-H5
|
|
* 通用计划-H5
|
|
@@ -48,6 +55,8 @@ public class PlanNewCommonOutController {
|
|
|
@Resource
|
|
@Resource
|
|
|
private GoGenerateService goGenerateService;
|
|
private GoGenerateService goGenerateService;
|
|
|
@Resource
|
|
@Resource
|
|
|
|
|
+ private ReactiveRedisTemplate<String, Object> reactiveRedisTemplate;
|
|
|
|
|
+ @Resource
|
|
|
private IpAnalyzeServiceInterface ipAnalyzeServiceInterface;
|
|
private IpAnalyzeServiceInterface ipAnalyzeServiceInterface;
|
|
|
private static final ConcurrentHashMap<String, Integer> MAP = new ConcurrentHashMap<>();
|
|
private static final ConcurrentHashMap<String, Integer> MAP = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
@@ -65,7 +74,7 @@ public class PlanNewCommonOutController {
|
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommon}>>
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommon}>>
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("getPlanNewCommonH5")
|
|
@GetMapping("getPlanNewCommonH5")
|
|
|
- public Mono<RStatus<PlanNewCommonRes>> getPlanNewCommonH5(@RequestParam("code") String code) {
|
|
|
|
|
|
|
+ public Mono<RStatus<byte[]>> getPlanNewCommonH5(@RequestParam("code") String code) {
|
|
|
Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(code)), PlanNewCommon.class)
|
|
Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(code)), PlanNewCommon.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("计划code异常")))
|
|
.switchIfEmpty(Mono.error(new BaseException("计划code异常")))
|
|
|
.onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage() + "1")));
|
|
.onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage() + "1")));
|
|
@@ -126,7 +135,25 @@ public class PlanNewCommonOutController {
|
|
|
return Mono.just(res);
|
|
return Mono.just(res);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
- return RStatus.success(resMono);
|
|
|
|
|
|
|
+ // GZIP压缩
|
|
|
|
|
+ Mono<byte[]> res = resMono.flatMap(f -> Mono.just(Objects.requireNonNull(this.compressData(JSONUtil.toJsonStr(f)))));
|
|
|
|
|
+ return RStatus.success(res);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * GZIP 压缩数据
|
|
|
|
|
+ */
|
|
|
|
|
+ private byte[] compressData(String data) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
|
|
|
|
+ GZIPOutputStream gzipOS = new GZIPOutputStream(stream);
|
|
|
|
|
+ gzipOS.write(data.getBytes());
|
|
|
|
|
+ gzipOS.close();
|
|
|
|
|
+ return stream.toByteArray();
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return null;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -136,7 +163,7 @@ public class PlanNewCommonOutController {
|
|
|
* @return {@link Mono}<{@link RStatus}<{@link DataListsKefu}>>
|
|
* @return {@link Mono}<{@link RStatus}<{@link DataListsKefu}>>
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("kefuList")
|
|
@PostMapping("kefuList")
|
|
|
- public Mono<RStatus<DataListsKefu>> kefuList(@RequestBody KefuRequest request) {
|
|
|
|
|
|
|
+ public Mono<RStatus<byte[]>> kefuList(@RequestBody KefuRequest request) {
|
|
|
Mono<PlanNewCommon> code = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
Mono<PlanNewCommon> code = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("code查询返回结构为空")))
|
|
.switchIfEmpty(Mono.error(new BaseException("code查询返回结构为空")))
|
|
|
.onErrorResume(throwable -> Mono.error(new Exception("通过code查询计划异常::" + throwable.getMessage())));
|
|
.onErrorResume(throwable -> Mono.error(new Exception("通过code查询计划异常::" + throwable.getMessage())));
|
|
@@ -194,12 +221,8 @@ public class PlanNewCommonOutController {
|
|
|
.is(request.getBackgroundGroupId())), BackgroupImageItem.class).collectList())
|
|
.is(request.getBackgroundGroupId())), BackgroupImageItem.class).collectList())
|
|
|
.switchIfEmpty(Mono.just(List.of()));
|
|
.switchIfEmpty(Mono.just(List.of()));
|
|
|
}
|
|
}
|
|
|
- Mono<Audio> retAudioId = Mono.just(new Audio(null, null, null, null, null, null, null, null));
|
|
|
|
|
- if (Objects.nonNull(request.getRetAudioId()) && request.getRetAudioId() > 0) {
|
|
|
|
|
- retAudioId = template.selectOne(Query.query(Criteria.where("id").is(request.getRetAudioId())), Audio.class)
|
|
|
|
|
- .switchIfEmpty(Mono.error(new BaseException(StrUtil.format("通过计划retAudioId:{}查询音频为空", request.getRetAudioId()))))
|
|
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException(StrUtil.format("通过计划retAudioId:{}查询音频Error::", request.getRetAudioId(), throwable.getMessage()))));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ Mono<Audio> retAudioId = this.getAudio(request.getRetAudioId());
|
|
|
Mono<DataListsKefu> dataListsMono = Mono.zip(Mono.just(planNew), backgroupImageItem, retAudioId, arrayListMono).flatMap(f -> {
|
|
Mono<DataListsKefu> dataListsMono = Mono.zip(Mono.just(planNew), backgroupImageItem, retAudioId, arrayListMono).flatMap(f -> {
|
|
|
DataListsKefu dataLists = new DataListsKefu();
|
|
DataListsKefu dataLists = new DataListsKefu();
|
|
|
dataLists.setPlanNewCommon(f.getT1());
|
|
dataLists.setPlanNewCommon(f.getT1());
|
|
@@ -217,7 +240,9 @@ public class PlanNewCommonOutController {
|
|
|
});
|
|
});
|
|
|
return dataListsMono;
|
|
return dataListsMono;
|
|
|
});
|
|
});
|
|
|
- return RStatus.successList(dataListsKefuMono);
|
|
|
|
|
|
|
+ // GZIP压缩
|
|
|
|
|
+ Mono<byte[]> res = dataListsKefuMono.flatMap(f -> Mono.just(Objects.requireNonNull(this.compressData(JSONUtil.toJsonStr(f)))));
|
|
|
|
|
+ return RStatus.successList(res);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -383,11 +408,11 @@ public class PlanNewCommonOutController {
|
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommonMaterialRes}>>
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommonMaterialRes}>>
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("getCommonMaterial")
|
|
@PostMapping("getCommonMaterial")
|
|
|
- public Mono<RStatus<PlanNewCommonMaterialRes>> getCommonMaterial(@RequestBody PlanNewCommonMaterialReq request) {
|
|
|
|
|
|
|
+ public Mono<RStatus<byte[]>> getCommonMaterial(@RequestBody PlanNewCommonMaterialReq request) {
|
|
|
Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("计划code异常 返回结果为空")))
|
|
.switchIfEmpty(Mono.error(new BaseException("计划code异常 返回结果为空")))
|
|
|
.onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
|
|
.onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
|
|
|
- Mono<PlanNewCommonMaterialRes> res = planNewCommonMono.flatMap(plan -> {
|
|
|
|
|
|
|
+ Mono<PlanNewCommonMaterialRes> materialResMono = planNewCommonMono.flatMap(plan -> {
|
|
|
// 群音频
|
|
// 群音频
|
|
|
Mono<Audio> groupAudio = this.getAudio(request.getAudioId());
|
|
Mono<Audio> groupAudio = this.getAudio(request.getAudioId());
|
|
|
// 返回音频
|
|
// 返回音频
|
|
@@ -423,6 +448,8 @@ public class PlanNewCommonOutController {
|
|
|
return Mono.just(materialRes);
|
|
return Mono.just(materialRes);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
+ // GZIP压缩
|
|
|
|
|
+ Mono<byte[]> res = materialResMono.flatMap(f -> Mono.just(Objects.requireNonNull(this.compressData(JSONUtil.toJsonStr(f)))));
|
|
|
return RStatus.success(res);
|
|
return RStatus.success(res);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -432,11 +459,18 @@ public class PlanNewCommonOutController {
|
|
|
private Mono<Audio> getAudio(Long id) {
|
|
private Mono<Audio> getAudio(Long id) {
|
|
|
if (Objects.isNull(id)) {
|
|
if (Objects.isNull(id)) {
|
|
|
return Mono.just(getAudio());
|
|
return Mono.just(getAudio());
|
|
|
- } else {
|
|
|
|
|
- return template.selectOne(Query.query(Criteria.where("id").is(id).and("deleted_at").isNull()), Audio.class)
|
|
|
|
|
- .switchIfEmpty(Mono.just(getAudio()))
|
|
|
|
|
- .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage() + "1")));
|
|
|
|
|
}
|
|
}
|
|
|
|
|
+ // 优先读缓存
|
|
|
|
|
+ Mono<Object> obj = reactiveRedisTemplate.opsForValue().get(RedisKey.FISSION_AUDIO + id);
|
|
|
|
|
+ return obj.flatMap(val -> {
|
|
|
|
|
+ if (val != null) {
|
|
|
|
|
+ return Mono.just(JSON.parseObject(val.toString(), Audio.class));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return template.selectOne(Query.query(Criteria.where("id").is(id)), Audio.class)
|
|
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException(StrUtil.format("通过计划retAudioId:{}查询音频为空", id))))
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException(StrUtil.format("通过计划retAudioId:{}查询音频Error::", id, throwable.getMessage()))));
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private Audio getAudio() {
|
|
private Audio getAudio() {
|
|
@@ -454,7 +488,7 @@ public class PlanNewCommonOutController {
|
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommonShareRes}>>
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommonShareRes}>>
|
|
|
*/
|
|
*/
|
|
|
@PostMapping("planCommonShare")
|
|
@PostMapping("planCommonShare")
|
|
|
- public Mono<RStatus<PlanNewCommonShareRes>> planCommonShare(@RequestBody PlanNewCommonShareReq request) {
|
|
|
|
|
|
|
+ public Mono<RStatus<byte[]>> planCommonShare(@RequestBody PlanNewCommonShareReq request) {
|
|
|
if (MAP.containsKey(request.getUnique())) {
|
|
if (MAP.containsKey(request.getUnique())) {
|
|
|
Integer integer = MAP.get(request.getUnique());
|
|
Integer integer = MAP.get(request.getUnique());
|
|
|
MAP.put(request.getUnique(), integer + 1);
|
|
MAP.put(request.getUnique(), integer + 1);
|
|
@@ -545,7 +579,9 @@ public class PlanNewCommonOutController {
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
Mono<PlanNewCommonShareRes> resMono1 = this.setEndData(request, setFmV(setAudioV(request, resMono)));
|
|
Mono<PlanNewCommonShareRes> resMono1 = this.setEndData(request, setFmV(setAudioV(request, resMono)));
|
|
|
- return RStatus.successList(resMono1);
|
|
|
|
|
|
|
+ // GZIP压缩
|
|
|
|
|
+ Mono<byte[]> res = resMono1.flatMap(f -> Mono.just(Objects.requireNonNull(this.compressData(JSONUtil.toJsonStr(f)))));
|
|
|
|
|
+ return RStatus.successList(res);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|