|
|
@@ -0,0 +1,625 @@
|
|
|
+package com.webflux.launchadmin.mysql.controller.planNew;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.webflux.launchadmin.global.BaseException;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.req.HftRequest;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.req.OutDomainRequest;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.req.PlanNewCommonMaterialReq;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.req.PlanNewCommonShareReq;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.res.*;
|
|
|
+import com.webflux.launchadmin.mysql.entity.groupUsers.GroupUsers;
|
|
|
+import com.webflux.launchadmin.mysql.entity.listening.ListeningPlanNew;
|
|
|
+import com.webflux.launchadmin.mysql.entity.planNew.*;
|
|
|
+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.structure.GoRequest;
|
|
|
+import com.webflux.launchadmin.mysql.service.planNew.structure.Item;
|
|
|
+import com.webflux.launchcommon.returnObj.RStatus;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
|
+import org.springframework.data.relational.core.query.Criteria;
|
|
|
+import org.springframework.data.relational.core.query.Query;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 通用计划-H5
|
|
|
+ *
|
|
|
+ * @author: wangcheng
|
|
|
+ * @date: 2024/7/10 14:13
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@RestController
|
|
|
+@RequestMapping("out/planNewCommon")
|
|
|
+public class PlanNewCommonOutController {
|
|
|
+ @Resource
|
|
|
+ private R2dbcEntityTemplate template;
|
|
|
+ @Resource
|
|
|
+ private GoGenerateService goGenerateService;
|
|
|
+ @Resource
|
|
|
+ private IpAnalyzeServiceInterface ipAnalyzeServiceInterface;
|
|
|
+ private static final ConcurrentHashMap<String, Integer> MAP = new ConcurrentHashMap<>();
|
|
|
+
|
|
|
+ @Scheduled(cron = "1 1 4 * * ?")
|
|
|
+ public void clearUserContextHashMap() {
|
|
|
+ log.info("清空计划-H5用户Map数据》》》》》》》》》》》》》》》》》》》》》》开始");
|
|
|
+ MAP.clear();
|
|
|
+ log.info("清空计划-H5用户Map数据》》》》》》》》》》》》》》》》》》》》》》 结束");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过 code 获取计划配置H5信息
|
|
|
+ *
|
|
|
+ * @param code
|
|
|
+ * @return {@link Mono}<{@link RStatus}<{@link PlanNewCommon}>>
|
|
|
+ */
|
|
|
+ @GetMapping("getPlanNewCommonH5")
|
|
|
+ public Mono<RStatus<PlanNewCommonRes>> 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 Exception(throwable.getMessage() + "1")));
|
|
|
+ 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 Exception(throwable.getMessage() + "2"))).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 Exception(throwable.getMessage() + "3"))).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 Exception(throwable.getMessage() + "4"))).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<Image> imageList = tuple.getT3();
|
|
|
+ Image image = imageList.get(RandomUtil.randomInt(0, imageList.size()));
|
|
|
+ List<Material> materialList = tuple.getT4();
|
|
|
+ Material material = materialList.get(RandomUtil.randomInt(0, materialList.size()));
|
|
|
+ List<H5ImageAndText> h5ImageAndTextList = new ArrayList<>();
|
|
|
+ H5ImageAndText h5ImageAndText = new H5ImageAndText();
|
|
|
+ h5ImageAndText.setImage(image.image());
|
|
|
+ h5ImageAndText.setName(material.content());
|
|
|
+ h5ImageAndText.setRemark(material.remark());
|
|
|
+ h5ImageAndTextList.add(h5ImageAndText);
|
|
|
+ res.setGroupImageAndTextList(h5ImageAndTextList);
|
|
|
+ return Mono.just(res);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return RStatus.success(resMono);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询domain
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @return {@link Mono}<{@link RStatus}<{@link DomainSelectRes}>>
|
|
|
+ */
|
|
|
+ @PostMapping("domainSelect")
|
|
|
+ public Mono<RStatus<DomainSelectRes>> domainSelect(@RequestBody OutDomainRequest request) {
|
|
|
+ if (1 == request.getTypePlan()) {
|
|
|
+ // 加群裂变
|
|
|
+ return this.getPlanNew(request);
|
|
|
+ } else if (2 == request.getTypePlan()) {
|
|
|
+ // 听书裂变
|
|
|
+ return this.getListeningPlan(request);
|
|
|
+ } else if (3 == request.getTypePlan()) {
|
|
|
+ // 交友裂变
|
|
|
+ return this.getFriendPlan(request);
|
|
|
+ }
|
|
|
+ throw new BaseException("typePlan 类型错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 加群裂变
|
|
|
+ */
|
|
|
+ private Mono<RStatus<DomainSelectRes>> getPlanNew(OutDomainRequest request) {
|
|
|
+ Mono<PlanNew> code1 = template
|
|
|
+ .selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNew.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("计划code异常 返回结果为空")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
|
|
|
+ Mono<DomainSelectRes> domainSelectResMono1 = code1.flatMap(f -> {
|
|
|
+ Mono<String> stringMono;
|
|
|
+ if (f.transferPageBl() == 1 && Objects.nonNull(f.transferPageDomain())) {
|
|
|
+ stringMono = template.select(Query.query(Criteria
|
|
|
+ .where("group_type_id").is(f.transferPageDomain())
|
|
|
+ .and("status").is(1)
|
|
|
+ .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 Exception(throwable.getMessage()))).collectList().flatMap(fff -> {
|
|
|
+ if (!fff.isEmpty()) {
|
|
|
+ DomainSelect domainSelect = fff.get(RandomUtil.randomInt(0, fff.size()));
|
|
|
+ String string = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
|
+ String domain1 = domainSelect.domain();
|
|
|
+ return Mono.just(string + "." + domain1);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ throw new BaseException("transferPageDomain 中轉域名查詢為空 group_type_id:::" + f.transferPageDomain());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ stringMono = Mono.just(" ");
|
|
|
+ }
|
|
|
+ Mono<String> stringMono1;
|
|
|
+ if (Objects.nonNull(f.backgroupDomain()) && !f.backgroupDomain().trim().isEmpty()) {
|
|
|
+ stringMono1 = template.select(Query.query(Criteria
|
|
|
+ .where("group_type_id").is(f.backgroupDomain())
|
|
|
+ .and("status").is(1)
|
|
|
+ .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 Exception(throwable.getMessage()))).collectList().flatMap(fff -> {
|
|
|
+ if (!fff.isEmpty()) {
|
|
|
+ DomainSelect domainSelect = fff.get(RandomUtil.randomInt(0, fff.size()));
|
|
|
+ String string = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
|
+ String domain1 = domainSelect.domain();
|
|
|
+ return Mono.just(string + "." + domain1);
|
|
|
+ } else {
|
|
|
+ throw new BaseException("backgroupDomain 背景域名查詢為空 group_type_id" + f.backgroupDomain());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ stringMono1 = Mono.just(" ");
|
|
|
+ }
|
|
|
+ Mono<String> stringMono2 = template.select(Query.query(Criteria
|
|
|
+ .where("group_type_id").is(f.landingPageDomain())
|
|
|
+ .and("status").is(1)
|
|
|
+ .and("type").is(request.getType())), DomainSelect.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("查询domain 返回结果为空")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage()))).collectList().flatMap(fm -> {
|
|
|
+ // DomainSelectRes domainSelectRes = new DomainSelectRes();
|
|
|
+ int i = RandomUtil.randomInt(0, fm.size());
|
|
|
+ String domain = fm.get(i).domain();
|
|
|
+ String string = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
|
+ return Mono.just(string + "." + domain);
|
|
|
+ });
|
|
|
+ return Mono.zip(stringMono2, stringMono1, stringMono).flatMap(fff -> {
|
|
|
+ DomainSelectRes domainSelectRes = new DomainSelectRes();
|
|
|
+ domainSelectRes.setDomain(fff.getT1());
|
|
|
+ domainSelectRes.setPath("");
|
|
|
+ domainSelectRes.setTransferPageBl(f.transferPageBl());
|
|
|
+ domainSelectRes.setBackgroupDomain(fff.getT2());
|
|
|
+ domainSelectRes.setTransferPageDomain(fff.getT3());
|
|
|
+ domainSelectRes.setUnique(IdUtil.fastSimpleUUID());
|
|
|
+ return Mono.just(domainSelectRes);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return RStatus.success(domainSelectResMono1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 听书裂变
|
|
|
+ */
|
|
|
+ private Mono<RStatus<DomainSelectRes>> getListeningPlan(OutDomainRequest request) {
|
|
|
+ Mono<ListeningPlanNew> code1 = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), ListeningPlanNew.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("计划code异常 返回结果为空")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
|
|
|
+ Mono<DomainSelectRes> domainSelectResMono1 = code1.flatMap(f -> template.select(Query.query(Criteria
|
|
|
+ .where("group_type_id").is(f.groupId())
|
|
|
+ .and("status").is(1)
|
|
|
+ .and("type").is(request.getType())), DomainSelect.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("查询domain 返回结果为空")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage()))).collectList()
|
|
|
+ .flatMap(fm -> {
|
|
|
+ DomainSelectRes domainSelectRes = new DomainSelectRes();
|
|
|
+ int i = RandomUtil.randomInt(0, fm.size());
|
|
|
+ String domain = fm.get(i).domain();
|
|
|
+ String string = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
|
+ domainSelectRes.setDomain(string + "." + domain);
|
|
|
+ domainSelectRes.setPath("");
|
|
|
+ domainSelectRes.setUnique(IdUtil.fastSimpleUUID());
|
|
|
+ return Mono.just(domainSelectRes);
|
|
|
+ }));
|
|
|
+ return RStatus.success(domainSelectResMono1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 交友裂变
|
|
|
+ */
|
|
|
+ private Mono<RStatus<DomainSelectRes>> getFriendPlan(OutDomainRequest request) {
|
|
|
+ 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 Exception(throwable.getMessage())))
|
|
|
+ .collectList().flatMap(fm -> {
|
|
|
+ int i = RandomUtil.randomInt(0, fm.size());
|
|
|
+ String domain = fm.get(i).domain();
|
|
|
+ String string = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
|
+ return Mono.just(string + "." + domain);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ Mono<DomainSelectRes> res = stringMono.flatMap(fff -> {
|
|
|
+ DomainSelectRes domainSelectRes = new DomainSelectRes();
|
|
|
+ domainSelectRes.setDomain(fff);
|
|
|
+ domainSelectRes.setPath("");
|
|
|
+ domainSelectRes.setUnique(IdUtil.fastSimpleUUID());
|
|
|
+ return Mono.just(domainSelectRes);
|
|
|
+ });
|
|
|
+ return RStatus.success(res);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询落地页素材
|
|
|
+ *
|
|
|
+ * @param request
|
|
|
+ * @return {@link Mono}<{@link RStatus}<{@link PlanNewCommonMaterialRes}>>
|
|
|
+ */
|
|
|
+ @PostMapping("getCommonMaterial")
|
|
|
+ public Mono<RStatus<PlanNewCommonMaterialRes>> getCommonMaterial(@RequestBody PlanNewCommonMaterialReq request) {
|
|
|
+ Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("计划code异常 返回结果为空")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
|
|
|
+ Mono<PlanNewCommonMaterialRes> res = planNewCommonMono.flatMap(plan -> {
|
|
|
+ // 群音频
|
|
|
+ Mono<Audio> groupAudio = this.getAudio(request.getAudioId());
|
|
|
+ // 返回音频
|
|
|
+ Mono<Audio> retAudio = this.getAudio(request.getRetAudioId());
|
|
|
+ // 返回广告
|
|
|
+ Mono<ReturnLoop> returnLoop;
|
|
|
+ if (Objects.isNull(request.getReturnLoopId()) || request.getReturnLoopId() <= 0) {
|
|
|
+ returnLoop = Mono.just(getReturnLoop());
|
|
|
+ } else {
|
|
|
+ returnLoop = template.selectOne(Query.query(Criteria.where("id").is(request.getReturnLoopId())
|
|
|
+ .and("deleted_at").isNull()), ReturnLoop.class)
|
|
|
+ .switchIfEmpty(Mono.just(getReturnLoop()))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage() + "3")));
|
|
|
+ }
|
|
|
+ // 分享背景组
|
|
|
+ Mono<List<BackgroupImageItem>> backgroupImageItemMono;
|
|
|
+ if (Objects.isNull(request.getBackgroundGroupId()) || request.getBackgroundGroupId() <= 0) {
|
|
|
+ backgroupImageItemMono = Mono.just(List.of());
|
|
|
+ } else {
|
|
|
+ backgroupImageItemMono = template.select(Query.query(Criteria
|
|
|
+ .where("group_id").is(request.getBackgroundGroupId())), BackgroupImageItem.class).collectList()
|
|
|
+ .switchIfEmpty(Mono.just(List.of()))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage() + "4")));
|
|
|
+ }
|
|
|
+ return Mono.zip(groupAudio, retAudio, returnLoop, backgroupImageItemMono).flatMap(f -> {
|
|
|
+ PlanNewCommonMaterialRes materialRes = new PlanNewCommonMaterialRes();
|
|
|
+ materialRes.setGroupAudio(f.getT1());
|
|
|
+ materialRes.setRetAudio(f.getT2());
|
|
|
+ materialRes.setReturnLoop(f.getT3());
|
|
|
+ if (!f.getT4().isEmpty()) {
|
|
|
+ materialRes.setShareUrls(f.getT4().stream().map(BackgroupImageItem::image).collect(Collectors.toList()));
|
|
|
+ }
|
|
|
+ return Mono.just(materialRes);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return RStatus.success(res);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取音频
|
|
|
+ */
|
|
|
+ private Mono<Audio> getAudio(Long id) {
|
|
|
+ if (Objects.isNull(id)) {
|
|
|
+ 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")));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Audio getAudio() {
|
|
|
+ return new Audio(null, null, null, null, null, null, null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ private ReturnLoop getReturnLoop() {
|
|
|
+ return new ReturnLoop(-1L, null, null, null, null, null, null, null, null, null, null, null, null, null);
|
|
|
+ }
|
|
|
+
|
|
|
+ public Mono<RStatus<PlanNewCommonShareRes>> planCommonShare(@RequestBody PlanNewCommonShareReq request) {
|
|
|
+ if (MAP.containsKey(request.getUnique())) {
|
|
|
+ Integer integer = MAP.get(request.getUnique());
|
|
|
+ MAP.put(request.getUnique(), integer + 1);
|
|
|
+ request.setUserVisits(integer + 1);
|
|
|
+ } else {
|
|
|
+ MAP.put(request.getUnique(), 0);
|
|
|
+ request.setUserVisits(0);
|
|
|
+ }
|
|
|
+ Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(request.getCode())), PlanNewCommon.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException(" code错误")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
|
|
|
+ Mono<PlanNewCommonShareRes> resMono = planNewCommonMono.flatMap(plan -> {
|
|
|
+ Mono<StringBuilder> stringBuilderMono;
|
|
|
+ if (Objects.nonNull(request.getRedirectType()) && request.getRedirectType() == 2) {
|
|
|
+ stringBuilderMono = goGenerateService.byPlanNewIdGetUrl(request.getRedirectPlanId(),
|
|
|
+ Objects.nonNull(request.getWx_user_id()) && !request.getWx_user_id().isEmpty());
|
|
|
+ } else {
|
|
|
+ stringBuilderMono = Mono.just(new StringBuilder(request.getLink()));
|
|
|
+ }
|
|
|
+ Mono<PlanNewCommon> code = Mono.just(plan);
|
|
|
+ return Mono.zip(code, getPosterTemplate(code), getPoster(code), getPlanNewBackgroupPoster(code), getEwm(code), stringBuilderMono).flatMap(f -> {
|
|
|
+ PlanNewCommonShareRes res = new PlanNewCommonShareRes();
|
|
|
+ res.setPlanNew(f.getT1());
|
|
|
+ res.setPosterTemplate(f.getT2());
|
|
|
+ res.setSpare(f.getT5().toString());
|
|
|
+ res.setRedirectType(request.getRedirectType());
|
|
|
+ List<Poster> t3 = f.getT3();
|
|
|
+ if (!t3.isEmpty()) {
|
|
|
+ if (t3.size() <= request.getUserVisits()) {
|
|
|
+ res.setPoster(t3.getLast());
|
|
|
+ } else {
|
|
|
+ res.setPoster(t3.get(request.getUserVisits()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map<Integer, List<PlanNewBackgroupPoster>> backgroupPoster = f.getT4().stream().collect(Collectors.groupingBy(PlanNewBackgroupPoster::qsOrFx));
|
|
|
+ // 营销-清水
|
|
|
+ if (Objects.nonNull(request.getWx_user_id()) && !request.getWx_user_id().isEmpty()) {
|
|
|
+ List<PlanNewBackgroupPoster> qs = backgroupPoster.get(2).stream()
|
|
|
+ .sorted(Comparator.comparing(PlanNewBackgroupPoster::index))
|
|
|
+ .toList();
|
|
|
+ if (!qs.isEmpty()) {
|
|
|
+ if (qs.size() <= request.getUserVisits()) {
|
|
|
+ Integer userVisits = request.getUserVisits();
|
|
|
+ int v = userVisits % qs.size();
|
|
|
+ res.setQsSetting(qs.get(v));
|
|
|
+ if (f.getT6().toString().isEmpty()) {
|
|
|
+ throw new BaseException("计划链接 查询匹配域名为空");
|
|
|
+ }
|
|
|
+ res.setLink(f.getT6().toString());
|
|
|
+ } else {
|
|
|
+ res.setQsSetting(qs.get(request.getUserVisits()));
|
|
|
+ res.setLink(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PlanNewBackgroupPoster qsSetting = res.getQsSetting();
|
|
|
+ if (Objects.nonNull(qsSetting)) {
|
|
|
+ res.setLimitTime(qsSetting.limitTime());
|
|
|
+ res.setLimitTimeRemark(qsSetting.limitTimeRemark());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ List<PlanNewBackgroupPoster> fx = backgroupPoster.get(1).stream()
|
|
|
+ .sorted(Comparator.comparing(PlanNewBackgroupPoster::index)).toList();
|
|
|
+ if (!fx.isEmpty()) {
|
|
|
+ if (fx.size() <= request.getUserVisits()) {
|
|
|
+ Integer userVisits = request.getUserVisits();
|
|
|
+ int v = userVisits % fx.size();
|
|
|
+ res.setFxSetting(fx.get(v));
|
|
|
+ if (f.getT6().toString().isEmpty()) {
|
|
|
+ throw new BaseException("计划链接 查询匹配域名为空");
|
|
|
+ }
|
|
|
+ res.setLink(f.getT6().toString());
|
|
|
+ } else {
|
|
|
+ res.setLink(null);
|
|
|
+ res.setFxSetting(fx.get(request.getUserVisits()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ PlanNewBackgroupPoster fxSetting = res.getFxSetting();
|
|
|
+ if (Objects.nonNull(fxSetting)) {
|
|
|
+ res.setLimitTime(fxSetting.limitTime());
|
|
|
+ res.setLimitTimeRemark(fxSetting.limitTimeRemark());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Mono.just(res);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ Mono<PlanNewCommonShareRes> resMono1 = this.setEndData(request, setFmV(request, setAudioV(request, resMono)));
|
|
|
+ return RStatus.successList(resMono1);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置二维码 生成图片
|
|
|
+ */
|
|
|
+ private Mono<PlanNewCommonShareRes> setEndData(PlanNewCommonShareReq request, Mono<PlanNewCommonShareRes> resMono) {
|
|
|
+ Mono<PlanNewCommonShareRes> resMono1 = resMono.flatMap(fm -> {
|
|
|
+ Poster poster = fm.getPoster();
|
|
|
+ if (Objects.isNull(poster)) {
|
|
|
+ return Mono.just(fm);
|
|
|
+ }
|
|
|
+ String posterTemplate = poster.posterTemplate();
|
|
|
+ GoRequest goRequest;
|
|
|
+ if (Objects.nonNull(request.getWx_user_id()) && !request.getWx_user_id().isEmpty()) {
|
|
|
+ PlanNewBackgroupPoster qsSetting = fm.getQsSetting();
|
|
|
+ goRequest = setNameVal(posterTemplate, qsSetting, fm.getSpare());
|
|
|
+ } else {
|
|
|
+ PlanNewBackgroupPoster fxSetting = fm.getFxSetting();
|
|
|
+ goRequest = setNameVal(posterTemplate, fxSetting, fm.getSpare());
|
|
|
+ }
|
|
|
+ String ret;
|
|
|
+ if (Objects.nonNull(goRequest)) {
|
|
|
+ ret = goGenerateService.goGenerate(JSONUtil.toJsonStr(goRequest));
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ret = goGenerateService.goGenerate(posterTemplate);
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(ret)) {
|
|
|
+ JSONObject jsonObject1;
|
|
|
+ try {
|
|
|
+ jsonObject1 = JSONUtil.parseObj(ret);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BaseException(e.getMessage() + "---" + JSONUtil.parseObj(goRequest));
|
|
|
+ }
|
|
|
+ if (jsonObject1.containsKey("code") && jsonObject1.get("code", Integer.class) == 0 && jsonObject1.containsKey("data")) {
|
|
|
+ JSONObject data = jsonObject1.get("data", JSONObject.class);
|
|
|
+ if (data.containsKey("Url")) {
|
|
|
+ String url = data.get("Url", String.class);
|
|
|
+ if (Objects.nonNull(request.getWx_user_id()) && !request.getWx_user_id().isEmpty()) {
|
|
|
+ fm.setQsGenerateImagesUrl(url);
|
|
|
+ } else {
|
|
|
+ fm.setFxGenerateImagesUrl(url);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Mono.just(fm);
|
|
|
+ });
|
|
|
+ return resMono1;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * qrcode 二维码设置
|
|
|
+ */
|
|
|
+ private GoRequest setNameVal(String posterTemplate, PlanNewBackgroupPoster qsSetting, String spare) {
|
|
|
+ JSONObject jsonObject;
|
|
|
+ try {
|
|
|
+ jsonObject = JSONUtil.parseObj(posterTemplate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BaseException(e.getMessage() + "---" + posterTemplate);
|
|
|
+ }
|
|
|
+ // JSONObject jsonObject = JSONUtil.parseObj(posterTemplate);
|
|
|
+ GoRequest goRequest = new GoRequest();
|
|
|
+ BeanUtil.copyProperties(jsonObject, goRequest);
|
|
|
+ if (Objects.nonNull(qsSetting)) {
|
|
|
+ Optional<Item> first = goRequest.getItem().stream().filter(f -> "qrcode".equals(f.getT())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ Item item = first.get();
|
|
|
+ Boolean isRandom = item.getIsRandom();
|
|
|
+ if (isRandom && Objects.nonNull(qsSetting.status()) && qsSetting.status() == 1
|
|
|
+ && Objects.nonNull(qsSetting.serviceGroupType()) && qsSetting.serviceGroupType() == 2) {
|
|
|
+ String kefu = qsSetting.kefu();
|
|
|
+ if (Objects.nonNull(kefu) && kefu.contains("[") && kefu.contains("]")) {
|
|
|
+ JSONArray jsonArray = JSONUtil.parseArray(kefu);
|
|
|
+ if (!jsonArray.isEmpty()) {
|
|
|
+ String s = jsonArray.get(0, String.class);
|
|
|
+ item.setV(s);
|
|
|
+ item.setName("客服二维码");
|
|
|
+ return goRequest;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (Objects.nonNull(qsSetting.status()) && qsSetting.status() == 0) {
|
|
|
+ item.setV(spare);
|
|
|
+ item.setName("H5二维码");
|
|
|
+ return goRequest;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置封面等
|
|
|
+ */
|
|
|
+ private Mono<PlanNewCommonShareRes> setFmV(PlanNewCommonShareReq request, Mono<PlanNewCommonShareRes> zip) {
|
|
|
+ Mono<PlanNewCommonShareRes> resMono = zip.flatMap(fm -> {
|
|
|
+ Poster poster = fm.getPoster();
|
|
|
+ if (Objects.isNull(poster)) {
|
|
|
+ return Mono.just(fm);
|
|
|
+ }
|
|
|
+ String posterTemplate = poster.posterTemplate();
|
|
|
+ JSONObject jsonObject;
|
|
|
+ try {
|
|
|
+ jsonObject = JSONUtil.parseObj(posterTemplate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BaseException(e.getMessage() + "---" + posterTemplate);
|
|
|
+ }
|
|
|
+ GoRequest goRequest = new GoRequest();
|
|
|
+ BeanUtil.copyProperties(jsonObject, goRequest);
|
|
|
+ Mono<String> outTemPoster;
|
|
|
+
|
|
|
+ Long aLong = fm.getPlanNew().groupId();
|
|
|
+ outTemPoster = goGenerateService.getOutTemPosterYx(goRequest,
|
|
|
+ goGenerateService.setCusqrcodeSetV(goRequest),
|
|
|
+ aLong);
|
|
|
+
|
|
|
+ return Mono.zip(Mono.just(fm), outTemPoster, (a, b) -> {
|
|
|
+ Poster poster1 = new Poster(poster.posterId(),
|
|
|
+ poster.posterTemplateId(),
|
|
|
+ b,
|
|
|
+ poster.createUser(),
|
|
|
+ poster.createId(),
|
|
|
+ poster.createdAt(),
|
|
|
+ poster.updatedAt(),
|
|
|
+ poster.generateImagesJson(),
|
|
|
+ poster.generateImagesUrl());
|
|
|
+ a.setPoster(poster1);
|
|
|
+ return a;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return resMono;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 音频
|
|
|
+ */
|
|
|
+ private Mono<PlanNewCommonShareRes> setAudioV(PlanNewCommonShareReq request, Mono<PlanNewCommonShareRes> resMono) {
|
|
|
+ Mono<PlanNewCommonShareRes> zip = resMono.flatMap(f -> {
|
|
|
+ Mono<Audio> id = null;
|
|
|
+ if (Objects.nonNull(request.getWx_user_id()) && !request.getWx_user_id().isEmpty()) {
|
|
|
+ PlanNewBackgroupPoster qsSetting = f.getQsSetting();
|
|
|
+ if (Objects.nonNull(qsSetting) && Objects.nonNull(qsSetting.audioId()) && 0 != qsSetting.audioId()) {
|
|
|
+ id = template.selectOne(Query.query(Criteria.where("id").is(qsSetting.audioId()).and("deleted_at").isNull()), Audio.class);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ PlanNewBackgroupPoster fxSetting = f.getFxSetting();
|
|
|
+ if (Objects.nonNull(fxSetting) && Objects.nonNull(fxSetting.audioId()) && 0 != fxSetting.audioId()) {
|
|
|
+ id = template.selectOne(Query.query(Criteria.where("id").is(fxSetting.audioId()).and("deleted_at").isNull()), Audio.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (Objects.isNull(id)) {
|
|
|
+ return Mono.just(f);
|
|
|
+ }
|
|
|
+ return Mono.zip(Mono.just(f), id, (a, b) -> {
|
|
|
+ a.setAudio(b);
|
|
|
+ return a;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return zip;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Mono<List<PlanNewBackgroupPoster>> getPlanNewBackgroupPoster(Mono<PlanNewCommon> code) {
|
|
|
+ return code.flatMap(plan -> template.select(Query.query(Criteria.where("plan_new_id")
|
|
|
+ .is(plan.id())).sort(Sort.by(Sort.Order.asc("idx"))), PlanNewBackgroupPoster.class)
|
|
|
+ .collectList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private Mono<List<Poster>> getPoster(Mono<PlanNewCommon> code) {
|
|
|
+ return code.flatMap(plan -> template.select(Query.query(Criteria.where("poster_template_id")
|
|
|
+ .is(plan.posterTemplateId())).sort(Sort.by(Sort.Order.asc("created_at"))), Poster.class).collectList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private Mono<PosterTemplate> getPosterTemplate(Mono<PlanNewCommon> code) {
|
|
|
+ return code.flatMap(plan -> template.selectOne(Query.query(Criteria.where("poster_template_id")
|
|
|
+ .is(plan.posterTemplateId())), PosterTemplate.class));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Mono<StringBuilder> getEwm(Mono<PlanNewCommon> code) {
|
|
|
+ return goGenerateService.getOutImportDomainCommon(code);
|
|
|
+ }
|
|
|
+}
|