|
|
@@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.plumelog.core.util.LogExceptionStackTrace;
|
|
|
import com.webflux.launchadmin.global.BaseException;
|
|
|
import com.webflux.launchadmin.mysql.controller.planNew.req.KefuRequest;
|
|
|
@@ -26,6 +27,7 @@ import com.webflux.launchadmin.mysql.service.planNew.structure.Item;
|
|
|
import com.webflux.launchadmin.mysql.service.takeaway.TakeawayServicesInterface;
|
|
|
import com.webflux.launchcommon.returnObj.RStatus;
|
|
|
import com.webflux.launchcommon.utils.StringUtils;
|
|
|
+import com.weblux.launchredis.utils.RedisKey;
|
|
|
import jakarta.annotation.Resource;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
@@ -83,70 +85,16 @@ public class PlanNewCommonOutController {
|
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommon}>>
|
|
|
*/
|
|
|
@GetMapping("getPlanNewCommonH5")
|
|
|
- public Mono<RStatus<byte[]>> getPlanNewCommonH5(@RequestParam("code") String code) {
|
|
|
- Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(code)), PlanNewCommon.class)
|
|
|
- .switchIfEmpty(Mono.error(new BaseException("计划code异")))
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException("计划code异")));
|
|
|
- Mono<PlanNewCommonRes> resMono = planNewCommonMono.flatMap(f -> {
|
|
|
- // 群成员
|
|
|
- Mono<List<GroupUserRes>> groupUserResMono = Mono.just(new ArrayList<>());
|
|
|
- // 群封面
|
|
|
- Mono<List<Image>> imageMono = template.select(Query.query(Criteria.where("type").is(1)
|
|
|
- .and("group_type_id").is(f.groupId())
|
|
|
- .and("deleted_at").isNull()), Image.class)
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException("获取群封面异常"))).collectList();
|
|
|
- // 群名称
|
|
|
- Mono<List<Material>> textMono = template.select(Query.query(Criteria.where("type").is(4)
|
|
|
- .and("deleted_at").isNull()
|
|
|
- .and("group_type_id").is(f.groupId())), Material.class)
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException("获取群名称异常"))).collectList();
|
|
|
- if (3 == f.type()) {
|
|
|
- // 交友裂变, 需要群成员
|
|
|
- Mono<List<GroupUsers>> groupUsersMono = template.select(Query.query(Criteria.where("group_users_type").is(f.groupId())).limit(14), GroupUsers.class)
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException("获取群成员异常"))).collectList();
|
|
|
- groupUserResMono = groupUsersMono.flatMap(groupUsers -> {
|
|
|
- List<GroupUserRes> groupUserResList = groupUsers.stream().map(groupUsers1 -> {
|
|
|
- GroupUserRes groupUserRes = new GroupUserRes();
|
|
|
- groupUserRes.setUserHead(groupUsers1.groupUsersHead());
|
|
|
- groupUserRes.setUserNickname(groupUsers1.groupUsersNickname());
|
|
|
- return groupUserRes;
|
|
|
- }).collect(Collectors.toList());
|
|
|
- return Mono.just(groupUserResList);
|
|
|
- });
|
|
|
- }
|
|
|
- return Mono.zip(Mono.just(f), groupUserResMono, imageMono, textMono).flatMap(tuple -> {
|
|
|
- PlanNewCommon plan = tuple.getT1();
|
|
|
- PlanNewCommonRes res = new PlanNewCommonRes();
|
|
|
- res.setCode(plan.code());
|
|
|
- res.setType(plan.type());
|
|
|
- res.setName(plan.name());
|
|
|
- res.setGroupId(plan.groupId());
|
|
|
- res.setPosterTemplateId(plan.posterTemplateId());
|
|
|
- res.setImportDomain(plan.importDomain());
|
|
|
- res.setConfigJson(plan.configJson());
|
|
|
- res.setGroupUserList(tuple.getT2());
|
|
|
- List<H5ImageAndText> h5ImageAndTextList = new ArrayList<>();
|
|
|
- H5ImageAndText h5ImageAndText = new H5ImageAndText();
|
|
|
- List<Image> imageList = tuple.getT3();
|
|
|
- if (!imageList.isEmpty()) {
|
|
|
- Image image = imageList.get(RandomUtil.randomInt(0, imageList.size()));
|
|
|
- h5ImageAndText.setImage(image.image());
|
|
|
- }
|
|
|
-
|
|
|
- List<Material> materialList = tuple.getT4();
|
|
|
- if (!materialList.isEmpty()) {
|
|
|
- Material material = materialList.get(RandomUtil.randomInt(0, materialList.size()));
|
|
|
- h5ImageAndText.setName(material.content());
|
|
|
- h5ImageAndText.setRemark(material.remark());
|
|
|
- }
|
|
|
- h5ImageAndTextList.add(h5ImageAndText);
|
|
|
- res.setGroupImageAndTextList(h5ImageAndTextList);
|
|
|
- return Mono.just(res);
|
|
|
- });
|
|
|
- });
|
|
|
- // GZIP压缩
|
|
|
- Mono<byte[]> res = resMono.flatMap(f -> Mono.just(Objects.requireNonNull(this.compressData(JSONUtil.toJsonStr(f)))));
|
|
|
- return RStatus.success(res);
|
|
|
+ public Mono<RStatus<PlanNewCommonRes>> getPlanNewCommonH5(@RequestParam("code") String code) {
|
|
|
+ Mono<PlanNewCommonRes> resMono;
|
|
|
+ Object obj = stringRedisTemplate.opsForHash().get(RedisKey.PLAN_COMMON_INFO_H5, code);
|
|
|
+ if (obj != null) {
|
|
|
+ PlanNewCommonRes res = JSON.parseObject(obj.toString(), PlanNewCommonRes.class);
|
|
|
+ resMono = Mono.just(res);
|
|
|
+ } else {
|
|
|
+ resMono = planServiceInterface.getPlanNewCommonH5(code);
|
|
|
+ }
|
|
|
+ return RStatus.success(resMono);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -175,7 +123,7 @@ public class PlanNewCommonOutController {
|
|
|
public Mono<RStatus<byte[]>> kefuList(@RequestBody KefuRequest request) {
|
|
|
Mono<PlanNewCommon> code = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("code查询返回结构为空")))
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException("code查询返回结构为空")));
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("code查询返回结果为空")));
|
|
|
Mono<DataListsKefu> dataListsKefuMono = code.flatMap(planNew -> {
|
|
|
Mono<List<Image>> image = template.select(Query.query(Criteria.where("type").is(5)
|
|
|
.and("deleted_at").isNull()
|
|
|
@@ -294,7 +242,7 @@ public class PlanNewCommonOutController {
|
|
|
.and("type").is(5)
|
|
|
.and("deleted_at").isNull()), DomainSelect.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("transferPageDomain 域名查詢為空 group_type_id:::" + f.transferPageDomain())))
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException("transferPageDomain 域名查詢為空 group_type_id:::" + f.transferPageDomain()))).collectList().flatMap(fff -> {
|
|
|
+ .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 = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
|
@@ -316,7 +264,7 @@ public class PlanNewCommonOutController {
|
|
|
.and("type").is(4)
|
|
|
.and("deleted_at").isNull()), DomainSelect.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("backgroupDomain 域名查询为空 group_type_id" + f.backgroupDomain())))
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException("backgroupDomain 域名查询为空 group_type_id" + f.backgroupDomain()))).collectList().flatMap(fff -> {
|
|
|
+ .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 = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
|
@@ -335,7 +283,7 @@ public class PlanNewCommonOutController {
|
|
|
.and("type").is(request.getType())
|
|
|
.and("deleted_at").isNull()), DomainSelect.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("查询domain 返回结果为空")))
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException("查询domain 返回结果为空"))).collectList().flatMap(fm -> {
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException(throwable.getMessage()))).collectList().flatMap(fm -> {
|
|
|
// DomainSelectRes domainSelectRes = new DomainSelectRes();
|
|
|
int i = RandomUtil.randomInt(0, fm.size());
|
|
|
String domain = fm.get(i).domain();
|
|
|
@@ -369,7 +317,7 @@ public class PlanNewCommonOutController {
|
|
|
.and("type").is(request.getType())
|
|
|
.and("deleted_at").isNull()), DomainSelect.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("查询domain 返回结果为空")))
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException("查询domain 返回结果为空"))).collectList()
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException(throwable.getMessage()))).collectList()
|
|
|
.flatMap(fm -> {
|
|
|
DomainSelectRes domainSelectRes = new DomainSelectRes();
|
|
|
int i = RandomUtil.randomInt(0, fm.size());
|
|
|
@@ -397,7 +345,7 @@ public class PlanNewCommonOutController {
|
|
|
.and("deleted_at").isNull()
|
|
|
.and("type").is(request.getType())), DomainSelect.class)
|
|
|
.switchIfEmpty(Mono.error(new BaseException("查询domain 返回结果为空")))
|
|
|
- .onErrorResume(throwable -> Mono.error(new BaseException("查询domain 返回结果为空")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException(throwable.getMessage())))
|
|
|
.collectList().flatMap(fm -> {
|
|
|
int i = RandomUtil.randomInt(0, fm.size());
|
|
|
String domain = fm.get(i).domain();
|
|
|
@@ -556,24 +504,21 @@ public class PlanNewCommonOutController {
|
|
|
if (Objects.isNull(id) || id <= 0) {
|
|
|
return Mono.just(getAudio());
|
|
|
}
|
|
|
- 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()))));
|
|
|
- // String value = redisTemplate.opsForValue().get(RedisKey.FISSION_AUDIO + id);
|
|
|
+ String value = stringRedisTemplate.opsForValue().get(RedisKey.FISSION_AUDIO + id);
|
|
|
+ if (null == value || StrUtil.isBlank(value)) {
|
|
|
+ value = " ";
|
|
|
+ }
|
|
|
// 优先读缓存
|
|
|
- // Mono<String> obj = reactiveRedisTemplate.opsForValue().get(RedisKey.FISSION_AUDIO + id)
|
|
|
- // .switchIfEmpty(Mono.just(" "))
|
|
|
- // .onErrorResume(throwable -> Mono.error(new BaseException(StrUtil.format("通过计划retAudioId:{}查询音频Error::", id, throwable.getMessage()))));
|
|
|
- // return obj.flatMap(val -> {
|
|
|
- // if (val != null && StrUtil.isNotBlank(val.toString())) {
|
|
|
- // Audio audio = JSON.parseObject(val.toString(), Audio.class);
|
|
|
- // return Mono.just(audio);
|
|
|
- // } 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()))));
|
|
|
- // }
|
|
|
- // });
|
|
|
+ return Mono.just(value).flatMap(val -> {
|
|
|
+ if (val != null && StrUtil.isNotBlank(val)) {
|
|
|
+ Audio audio = JSON.parseObject(val, Audio.class);
|
|
|
+ return Mono.just(audio);
|
|
|
+ } 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() {
|