|
|
@@ -81,6 +81,104 @@ public class PlanNewCommonOutController {
|
|
|
* @param code
|
|
|
* @return {@link Mono}<{@link RStatus}<{@link PlanNewCommon}>>
|
|
|
*/
|
|
|
+ @GetMapping("getPlanNewCommonH5Copy")
|
|
|
+ public Mono<RStatus<PlanNewCommonRes>> getPlanNewCommonH5Copy(@RequestParam("code") String code, ServerWebExchange exchange) {
|
|
|
+
|
|
|
+ Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(code)).columns(COLUMNARRAYCOMMON), PlanNewCommon.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("计划code异")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("计划code异")));
|
|
|
+ Mono<PlanNewCommonRes> resMono = planNewCommonMono.flatMap(f -> {
|
|
|
+ if(Objects.nonNull(f.type()) && 5==f.type()){
|
|
|
+ PlanNewCommonRes res = new PlanNewCommonRes();
|
|
|
+ res.setCode(code);
|
|
|
+ res.setConfigJson(f.configJson());
|
|
|
+ return Mono.just(res);
|
|
|
+ }
|
|
|
+ // 群成员
|
|
|
+ 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()));
|
|
|
+ String content = material.content();
|
|
|
+ String clientIP=null ;//exchange.getRequest().getHeaders().getFirst("X-Forwarded-For");
|
|
|
+ if ( Objects.nonNull(exchange.getRequest().getRemoteAddress())) {
|
|
|
+ clientIP = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
|
|
|
+ }
|
|
|
+ if (StrUtil.isNotBlank(clientIP)) {
|
|
|
+ JSONObject ipInfo = ipAnalyzeServiceInterface.getIpInfo(clientIP);
|
|
|
+ if (null != ipInfo) {
|
|
|
+ String city = ipInfo.getStr("city");
|
|
|
+ if (StrUtil.isNotBlank(city)) {
|
|
|
+ content = city + content;
|
|
|
+ } else {
|
|
|
+ String province = ipInfo.getStr("region");
|
|
|
+ if (StrUtil.isNotBlank(province)) {
|
|
|
+ content = province + content;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ h5ImageAndText.setName(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(resMono);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通过 code 获取计划配置H5信息
|
|
|
+ *
|
|
|
+ * @param code
|
|
|
+ * @return {@link Mono}<{@link RStatus}<{@link PlanNewCommon}>>
|
|
|
+ */
|
|
|
@GetMapping("getPlanNewCommonH5")
|
|
|
public Mono<RStatus<byte[]>> getPlanNewCommonH5(@RequestParam("code") String code, ServerWebExchange exchange) {
|
|
|
Mono<PlanNewCommon> planNewCommonMono = template.selectOne(Query.query(Criteria.where("code").is(code)).columns(COLUMNARRAYCOMMON), PlanNewCommon.class)
|
|
|
@@ -570,12 +668,56 @@ public class PlanNewCommonOutController {
|
|
|
} else {
|
|
|
takeaway = Mono.just(new TakeawayH5Data());
|
|
|
}
|
|
|
- return Mono.zip(groupAudio, retAudio, returnLoop, backgroupImageItemMono, takeaway).flatMap(f -> {
|
|
|
+ Mono<List<Ad>> adtop ;
|
|
|
+ if (Objects.nonNull(request.getTopAdvBl()) && request.getTopAdvBl()) {
|
|
|
+ adtop = template.select(Query.query(Criteria.where("type").is(1)
|
|
|
+ .and("deleted_at").isNull()).columns("id,name,type,image,show_beg_at,show_end_at,link".split(",")), Ad.class)
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException(throwable.getMessage()+"4")))
|
|
|
+ .collectList();////广告类型1顶部2底部3返回4安卓,ios的返回
|
|
|
+ }else {
|
|
|
+ adtop=Mono.just(List.of());
|
|
|
+ }
|
|
|
+ Mono<List<Ad>> adBottom ;
|
|
|
+ if (Objects.nonNull(request.getBottomAdvBl()) && request.getBottomAdvBl()) {
|
|
|
+ adBottom = template.select(Query.query(Criteria.where("type").is(2)
|
|
|
+ .and("deleted_at").isNull()).columns("id,name,type,image,show_beg_at,show_end_at,link".split(",")), Ad.class)
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException(throwable.getMessage()+"4")))
|
|
|
+ .collectList();////广告类型1顶部2底部3返回4安卓,ios的返回
|
|
|
+ }else {
|
|
|
+ adBottom=Mono.just(List.of());
|
|
|
+ }
|
|
|
+ //假视频
|
|
|
+ Mono<List<Image>> imageMono ;
|
|
|
+ if (Objects.nonNull(plan.type()) && 6==plan.type()) {
|
|
|
+ imageMono = template.select(Query.query(Criteria.where("type").is(13)
|
|
|
+ .and("group_type_id").is(plan.groupId())
|
|
|
+ .and("deleted_at").isNull()), Image.class)
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("获取假视频计划图片异常"))).collectList();
|
|
|
+ }else {
|
|
|
+ imageMono=Mono.just(List.of());
|
|
|
+ }
|
|
|
+
|
|
|
+ return Mono.zip(groupAudio, retAudio, returnLoop, backgroupImageItemMono, takeaway,adtop,adBottom,imageMono).flatMap(f -> {
|
|
|
PlanNewCommonMaterialRes materialRes = new PlanNewCommonMaterialRes();
|
|
|
materialRes.setGroupAudio(f.getT1());
|
|
|
materialRes.setRetAudio(f.getT2());
|
|
|
materialRes.setReturnLoop(f.getT3());
|
|
|
materialRes.setTakeawayH5Data(f.getT5());
|
|
|
+ List<Ad> t6 = f.getT6();
|
|
|
+ if (!t6.isEmpty()) {
|
|
|
+ Ad ad = t6.get(RandomUtil.randomInt(0, t6.size()));
|
|
|
+ materialRes.setTopAdv(ad);
|
|
|
+ }
|
|
|
+ List<Ad> t7 = f.getT7();
|
|
|
+ if (!t7.isEmpty()) {
|
|
|
+ Ad ad = t7.get(RandomUtil.randomInt(0, t7.size()));
|
|
|
+ materialRes.setBottomAdv(ad);
|
|
|
+ }
|
|
|
+ List<Image> t8 = f.getT8();
|
|
|
+ if (!t8.isEmpty()) {
|
|
|
+ Image image = t8.get(RandomUtil.randomInt(0, t8.size()));
|
|
|
+ materialRes.setImageUrl(image.image());
|
|
|
+ }
|
|
|
if (!f.getT4().isEmpty()) {
|
|
|
materialRes.setShareUrls(f.getT4().stream().map(BackgroupImageItem::image).collect(Collectors.toList()));
|
|
|
}
|