|
|
@@ -0,0 +1,1066 @@
|
|
|
+package com.webflux.launchadmin.mysql.service.listening;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.webflux.launchadmin.config.BaseContextHandler;
|
|
|
+import com.webflux.launchadmin.global.BaseException;
|
|
|
+import com.webflux.launchadmin.mysql.controller.listening.req.*;
|
|
|
+import com.webflux.launchadmin.mysql.controller.listening.res.DataListsShare;
|
|
|
+import com.webflux.launchadmin.mysql.controller.listening.res.ListeningPlanNewRes;
|
|
|
+import com.webflux.launchadmin.mysql.controller.listening.res.ListeningPlanNewRes2;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.req.PlanReq;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.req.PlanReqPage;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.req.ServiceGroupSettingItemRequest;
|
|
|
+import com.webflux.launchadmin.mysql.entity.listening.ListeningAudio;
|
|
|
+import com.webflux.launchadmin.mysql.entity.listening.ListeningPlanNew;
|
|
|
+import com.webflux.launchadmin.mysql.entity.listening.ListeningPlanNewBackgroupPoster;
|
|
|
+import com.webflux.launchadmin.mysql.entity.planNew.*;
|
|
|
+import com.webflux.launchadmin.mysql.service.planNew.structure.GoRequest;
|
|
|
+import com.webflux.launchadmin.mysql.service.planNew.structure.Item;
|
|
|
+import com.webflux.launchcommon.returnObj.Paged;
|
|
|
+import com.webflux.launchcommon.returnObj.RStatus;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+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.stereotype.Service;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import reactor.core.publisher.Flux;
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
+
|
|
|
+import java.time.ZonedDateTime;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.ConcurrentHashMap;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
|
|
|
+ @Value("${go.data.createImage}")
|
|
|
+ private String value;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private R2dbcEntityTemplate template;
|
|
|
+ @Override
|
|
|
+ public Mono<RStatus<Paged<ListeningPlanNewRes2>>> page(PlanReqPage request) {
|
|
|
+ Criteria criteria= Criteria.empty() ; //poster_template_id
|
|
|
+ if (Objects.nonNull(request.getCode()) && "" != request.getCode().trim()) {
|
|
|
+ criteria = criteria.and("code").like("%"+request.getCode()+"%");
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(request.getName()) && "" != request.getName().trim()) {
|
|
|
+ criteria = criteria.and("name").like("%"+request.getName()+"%");
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(request.getCreateUser()) && "" != request.getCreateUser().trim()) {
|
|
|
+ criteria = criteria.and("create_user").like("%"+request.getCreateUser()+"%");
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(request.getPosterTemplateId()) && 0L != request.getPosterTemplateId()) {
|
|
|
+ criteria = criteria.and("poster_template_id").is(request.getPosterTemplateId());
|
|
|
+ }
|
|
|
+// if (Objects.nonNull(request.getType()) && 0 != request.getType()) {
|
|
|
+// criteria = criteria.and("type").is(request.getType());
|
|
|
+// }
|
|
|
+ Query query = Query.query(criteria);
|
|
|
+ Criteria finalCriteria = criteria;
|
|
|
+ int skip = (request.getPage() - 1) * request.getSize();
|
|
|
+ int limit = request.getPage() * request.getSize();
|
|
|
+ return RStatus.successList(Mono.zip(template.count(query, ListeningPlanNew.class), template.select(Query.query(finalCriteria)
|
|
|
+ .offset(skip)
|
|
|
+ .limit(limit)
|
|
|
+ .sort(Sort.by(Sort.Order.desc("created_at"))), ListeningPlanNew.class).flatMap(f -> {
|
|
|
+ Mono<String> poster_template_id = template.selectOne(Query.query(Criteria.where("poster_template_id")
|
|
|
+ .is(f.posterTemplateId())), PosterTemplate.class).flatMap(f0 -> Mono.just(f0.posterTemplateName()))
|
|
|
+ .switchIfEmpty(Mono.just("")) //Mono.error(new BaseException("查询海报模版 id:"+f.posterTemplateId()+"=>空"))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception("查询海报模版 id:" + f.posterTemplateId() + "error:" + throwable.getMessage())));
|
|
|
+ Mono<String> id = template.selectOne(Query.query(Criteria.where("id").is(f.groupId())), GroupType.class)
|
|
|
+ .flatMap(f1 -> Mono.just(f1.name()))
|
|
|
+ .switchIfEmpty(Mono.just(""))//Mono.error(new BaseException("查询GroupType id:"+f.groupId()+"=>空"))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception("查询GroupType id:" + f.groupId() + "error:" + throwable.getMessage())));
|
|
|
+ return Mono.zip(Mono.just(f), poster_template_id, id).flatMap(ff -> {
|
|
|
+ ListeningPlanNew t1 = ff.getT1();
|
|
|
+ ListeningPlanNewRes2 listeningPlanNewRes = new ListeningPlanNewRes2();
|
|
|
+ listeningPlanNewRes.setPlanNewId(t1.listeningPlanNewId());
|
|
|
+ listeningPlanNewRes.setCode(t1.code());
|
|
|
+ listeningPlanNewRes.setName(t1.name());
|
|
|
+ listeningPlanNewRes.setCreatedAt(t1.createdAt());
|
|
|
+ listeningPlanNewRes.setCreateUser(t1.createUser());
|
|
|
+ listeningPlanNewRes.setType(t1.type());
|
|
|
+ listeningPlanNewRes.setGroupName(ff.getT3());
|
|
|
+ listeningPlanNewRes.setPreviewUrl(t1.previewUrl());
|
|
|
+ listeningPlanNewRes.setPosterTemplateName(ff.getT2());
|
|
|
+ return Mono.just(listeningPlanNewRes);
|
|
|
+ });
|
|
|
+ }).collectList()).flatMap(ff -> {
|
|
|
+ Long t1 = ff.getT1();
|
|
|
+ Paged<ListeningPlanNewRes2> planNewResPaged = new Paged<>(t1, ff.getT2(), request.getPage(), request.getSize());
|
|
|
+ return Mono.just(planNewResPaged);
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public Mono<RStatus<List<GroupType>>> groupTypeSlt (String name){
|
|
|
+ Criteria criteria= Criteria.where("group_type").is(1);
|
|
|
+ if (Objects.nonNull(name) && "" != name) {
|
|
|
+ criteria = criteria.and("name").like("%"+name+"%");
|
|
|
+ }
|
|
|
+ Mono<List<GroupType>> listMono = template.select(Query.query(criteria), GroupType.class).collectList();
|
|
|
+ return RStatus.success(listMono);
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public Mono<RStatus<String>> savePlan(PlanReq saveRequest) {
|
|
|
+ String userName = BaseContextHandler.getUserName();
|
|
|
+ String userId = BaseContextHandler.getUserId();
|
|
|
+ boolean bl=Objects.nonNull(saveRequest.getPlanNewId()) || "".equals(saveRequest.getPlanNewId().trim());
|
|
|
+ saveRequest.setCode(IdUtil.fastSimpleUUID());
|
|
|
+ Long posterTemplateId = saveRequest.getPosterTemplateId();
|
|
|
+ //预览Url
|
|
|
+ Mono<String> stringMono1 = template
|
|
|
+ .select(Query.query(Criteria.where("poster_template_id")
|
|
|
+ .is(posterTemplateId)).sort(Sort.by(Sort.Order.asc("created_at"))), Poster.class)
|
|
|
+ .collectList().flatMap(f -> {
|
|
|
+ Poster poster = f.get(0);
|
|
|
+ String posterTemplate = poster.posterTemplate();
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(posterTemplate);
|
|
|
+ GoRequest goRequest = new GoRequest();
|
|
|
+ BeanUtil.copyProperties(jsonObject, goRequest);
|
|
|
+ ServiceGroupSettingItemRequest serviceGroupSettingItemRequest = saveRequest.getBackgroupFxSetting().get(0);
|
|
|
+ System.out.println(goRequest);
|
|
|
+ Mono<String> stringMono = saveAndUpdatePlanGenerateImage0(goRequest,
|
|
|
+ setCusqrcodeRtUrl(goRequest),
|
|
|
+ serviceGroupSettingItemRequest,
|
|
|
+ saveRequest);
|
|
|
+ return stringMono;
|
|
|
+ });
|
|
|
+ Mono<StringBuilder> link=Mono.just(new StringBuilder(saveRequest.getLink()));
|
|
|
+ Mono<ListeningPlanNew> insert = Mono.zip(stringMono1, link).flatMap(f->{
|
|
|
+
|
|
|
+ ListeningPlanNew plan = new ListeningPlanNew(
|
|
|
+ bl ?IdUtil.fastSimpleUUID():saveRequest.getPlanNewId(),
|
|
|
+ saveRequest.getName(),
|
|
|
+ userName,
|
|
|
+ userId,
|
|
|
+ ZonedDateTime.now(),
|
|
|
+ ZonedDateTime.now(),
|
|
|
+ null,
|
|
|
+ saveRequest.getType(),
|
|
|
+ saveRequest.getCode(),
|
|
|
+ saveRequest.getGroupId(),
|
|
|
+ null,
|
|
|
+ saveRequest.getPosterTemplateId(),
|
|
|
+ saveRequest.getPageShow(),
|
|
|
+ saveRequest.getPageLine(),
|
|
|
+ f.getT2().toString(),
|
|
|
+ saveRequest.getBackgroundGroupId(),
|
|
|
+ saveRequest.getBaiduDot(),
|
|
|
+ f.getT1()
|
|
|
+ );
|
|
|
+ return !bl? template.update(plan) : template.insert(plan);
|
|
|
+ });
|
|
|
+ Mono<String> map = insert.flatMap(f -> {
|
|
|
+ List<ServiceGroupSettingItemRequest> backgroupFxSetting = saveRequest.getBackgroupFxSetting();
|
|
|
+ //Flux<ListeningPlanNewBackgroupPoster> just = Flux.just();
|
|
|
+ ArrayList<ListeningPlanNewBackgroupPoster> listeningPlanNewBackgroupPosters = new ArrayList<>();
|
|
|
+ backgroupFxSetting.forEach(fx -> {
|
|
|
+ ListeningPlanNewBackgroupPoster listeningPlanNewBackgroupPoster = fxBackgroupSettingsSave(fx, f.listeningPlanNewId(), 1);
|
|
|
+ listeningPlanNewBackgroupPosters.add(listeningPlanNewBackgroupPoster);
|
|
|
+ // just.concatWith(Flux.just(listeningPlanNewBackgroupPoster));
|
|
|
+ });
|
|
|
+ Flux<ListeningPlanNewBackgroupPoster> just = Flux.fromIterable(listeningPlanNewBackgroupPosters);
|
|
|
+ Mono<Long> ml;
|
|
|
+ if(!bl){
|
|
|
+ ml= template.delete(Query.query(Criteria.where("plan_new_id").is(f.listeningPlanNewId())),ListeningPlanNewBackgroupPoster.class);
|
|
|
+ }else {
|
|
|
+ ml=Mono.just(1l);
|
|
|
+ }
|
|
|
+
|
|
|
+ return Mono.zip(batchInsert(just), Mono.just(f),ml).flatMap(ff -> {
|
|
|
+ ListeningPlanNew t2 = ff.getT2();
|
|
|
+ return Mono.just(t2.listeningPlanNewId());
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return RStatus.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Mono<List<ListeningPlanNewBackgroupPoster>> batchInsert(Flux<ListeningPlanNewBackgroupPoster> entities) {
|
|
|
+ Mono<List<ListeningPlanNewBackgroupPoster>> listMono = entities.flatMap(entity -> template.insert(ListeningPlanNewBackgroupPoster.class).using(entity)).collectList();
|
|
|
+ return listMono;
|
|
|
+ }
|
|
|
+ public ListeningPlanNewBackgroupPoster fxBackgroupSettingsSave( ServiceGroupSettingItemRequest request,String planNewId,Integer qsOrFx){
|
|
|
+ return new ListeningPlanNewBackgroupPoster(null,
|
|
|
+ request.getAudioId(),
|
|
|
+ request.getGroupId(),
|
|
|
+ request.getImage(),
|
|
|
+ request.getKefu(),
|
|
|
+ request.getLimitTime(),
|
|
|
+ request.getLimitTimeRemark(),
|
|
|
+ request.getStatus(),
|
|
|
+ request.getIndex(),
|
|
|
+ request.getServiceGroupId(),
|
|
|
+ request.getServiceGroupType(),
|
|
|
+ qsOrFx,
|
|
|
+ ZonedDateTime.now(),
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ planNewId,
|
|
|
+ null,
|
|
|
+ null);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public Mono<List<StringBuilder>> setCusqrcodeRtUrl(GoRequest goRequest) {
|
|
|
+ List<Item> collect = goRequest.getItem().stream()
|
|
|
+ .filter(f -> "cusqrcode".equals(f.getT())
|
|
|
+ && Objects.nonNull(f.getPlanId())
|
|
|
+ && f.getIsRandom()).collect(Collectors.toList());
|
|
|
+ Mono<List<StringBuilder>> stringBuilderMono =null;
|
|
|
+ if (Objects.nonNull(collect) && !collect.isEmpty()) {
|
|
|
+ List<Long> collect1 = collect.stream().map(Item::getPlanId).collect(Collectors.toList());
|
|
|
+ stringBuilderMono = template.select(Query.query(Criteria.where("listening_plan_new_id").in(collect1)), ListeningPlanNew.class)
|
|
|
+ .flatMap(f -> Mono.zip(Mono.just(f), template.select(Query.query(Criteria.where("group_type_id").is(f.groupId())
|
|
|
+ .and("status").is(1).and("type").is(1).and("deleted_at").isNull()), DomainSelect.class)
|
|
|
+ .collectList()
|
|
|
+ .switchIfEmpty(Mono.just(List.of())), (a, b) -> {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ if (Objects.nonNull(b) && !b.isEmpty()) {
|
|
|
+ DomainSelect domainSelect = b.get(RandomUtil.randomInt(0, b.size()));
|
|
|
+ stringBuilder.append("http://");
|
|
|
+ stringBuilder.append( get6Str());
|
|
|
+ stringBuilder.append(".");
|
|
|
+ stringBuilder.append(domainSelect.domain());
|
|
|
+ stringBuilder.append("/index.html?code=");
|
|
|
+ stringBuilder.append(a.code());
|
|
|
+ stringBuilder.append("&sk=");
|
|
|
+ stringBuilder.append(IdUtil.fastSimpleUUID());
|
|
|
+ }else {
|
|
|
+ throw new BaseException("通过计划id:"+a.listeningPlanNewId() +"的营销类型查询域名为空");
|
|
|
+ }
|
|
|
+ Optional<Item> first = collect.stream()
|
|
|
+ .filter(ft -> ft.getPlanId()
|
|
|
+ .equals(f.listeningPlanNewId()) && (Objects.isNull(ft.getV()) || "".equals(ft.getV()))).findFirst();
|
|
|
+ first.ifPresent(item -> item.setV(stringBuilder.toString()));
|
|
|
+ return stringBuilder;
|
|
|
+ })
|
|
|
+ ).collectList();
|
|
|
+ }
|
|
|
+ if (Objects.isNull(stringBuilderMono)) {
|
|
|
+ return Mono.just(List.of());
|
|
|
+ }
|
|
|
+ return stringBuilderMono;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Mono<RStatus<ListeningAudio>> saveOrUpdateAudio(ListeningAudioReq saveRequest) {
|
|
|
+ String userName = BaseContextHandler.getUserName();
|
|
|
+ String userId = BaseContextHandler.getUserId();
|
|
|
+ ListeningAudio listeningAudio = new ListeningAudio(
|
|
|
+ saveRequest.getNewAudioId(),
|
|
|
+ saveRequest.getAudioName(),
|
|
|
+ saveRequest.getAudioImageUrl(),
|
|
|
+ saveRequest.getAudioUrl(),
|
|
|
+ saveRequest.getPopupNode(),
|
|
|
+ saveRequest.getIdxNum(),
|
|
|
+ userName,
|
|
|
+ userId,
|
|
|
+ ZonedDateTime.now(),
|
|
|
+ ZonedDateTime.now(),
|
|
|
+ null
|
|
|
+ );
|
|
|
+ Mono<ListeningAudio> updateOrinsert;
|
|
|
+ if (Objects.nonNull(saveRequest.getNewAudioId())) {
|
|
|
+ updateOrinsert = template.update(listeningAudio);
|
|
|
+ } else {
|
|
|
+ updateOrinsert = template.insert(listeningAudio);
|
|
|
+ }
|
|
|
+ return RStatus.success(updateOrinsert);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Mono<RStatus<Paged<ListeningAudioRes>>> audioList(ListeningAudioReqPage request) {
|
|
|
+ Criteria criteria= Criteria.empty() ; //poster_template_id
|
|
|
+ if (Objects.nonNull(request.getName()) && "" != request.getName().trim()) {
|
|
|
+ criteria = criteria.and("audio_name").like("%"+request.getName()+"%");
|
|
|
+ }
|
|
|
+ Query query = Query.query(criteria);
|
|
|
+ Criteria finalCriteria = criteria;
|
|
|
+ int skip = (request.getPage() - 1) * request.getSize();
|
|
|
+ int limit = request.getPage() * request.getSize();
|
|
|
+ return RStatus.successList(Mono.zip(template.count(query, ListeningAudio.class),
|
|
|
+ template.select(Query.query(finalCriteria)
|
|
|
+ .offset(skip)
|
|
|
+ .limit(limit)
|
|
|
+ .sort(Sort.by(Sort.Order.asc("idx_num"))), ListeningAudio.class).collectList()).flatMap(f -> {
|
|
|
+ Long t1 = f.getT1();
|
|
|
+ List<ListeningAudio> t2 = f.getT2();
|
|
|
+ List<ListeningAudioRes> collect = t2.stream().map(fm -> {
|
|
|
+ ListeningAudioRes listeningAudioRes = new ListeningAudioRes();
|
|
|
+ listeningAudioRes.setAudioUrl(fm.audioUrl());
|
|
|
+ listeningAudioRes.setAudioImageUrl(fm.audioImageUrl());
|
|
|
+ listeningAudioRes.setAudioName(fm.audioName());
|
|
|
+ listeningAudioRes.setNewAudioId(fm.newAudioId());
|
|
|
+ listeningAudioRes.setCreatedAt(fm.createdAt());
|
|
|
+ listeningAudioRes.setCreateUser(fm.createUser());
|
|
|
+ listeningAudioRes.setIdxNum(fm.idxNum());
|
|
|
+ listeningAudioRes.setPopupNode(fm.popupNode());
|
|
|
+ return listeningAudioRes;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ Paged<ListeningAudioRes> planNewResPaged = new Paged<>(t1, collect, request.getPage(), request.getSize());
|
|
|
+ return Mono.just(planNewResPaged);
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Mono<RStatus<String>> copyById(String listeningPlanNewId) {
|
|
|
+ String userName = BaseContextHandler.getUserName();
|
|
|
+ String userId = BaseContextHandler.getUserId();
|
|
|
+ Mono<ListeningPlanNew> listening_plan_new_id = template
|
|
|
+ .selectOne(Query.query(Criteria.where("listening_plan_new_id").is(listeningPlanNewId)), ListeningPlanNew.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("计划错误")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())))
|
|
|
+ .flatMap(f -> {
|
|
|
+ ListeningPlanNew listeningPlanNew = new ListeningPlanNew(null,
|
|
|
+ f.name(),
|
|
|
+ userName,
|
|
|
+ userId,
|
|
|
+ ZonedDateTime.now(),
|
|
|
+ ZonedDateTime.now(),
|
|
|
+ null,
|
|
|
+ f.type(),
|
|
|
+ f.code(),
|
|
|
+ f.groupId(),
|
|
|
+ f.groupName(),
|
|
|
+ f.posterTemplateId(),
|
|
|
+ f.pageShow(),
|
|
|
+ f.pageLine(),
|
|
|
+ f.link(),
|
|
|
+ f.backgroundGroupId(),
|
|
|
+ f.baiduDot(),
|
|
|
+ f.previewUrl()
|
|
|
+ );
|
|
|
+ return Mono.just(listeningPlanNew);
|
|
|
+ }).flatMap(f -> template.insert(f));
|
|
|
+ Mono<List<ListeningPlanNewBackgroupPoster>> listening_plan_new_id1 =
|
|
|
+ template.select(Query.query(Criteria.where("listening_plan_new_id")
|
|
|
+ .is(listeningPlanNewId)), ListeningPlanNewBackgroupPoster.class)
|
|
|
+ .collectList();
|
|
|
+ Mono<String> stringMono = Mono.zip(listening_plan_new_id, listening_plan_new_id1).flatMap(f -> {
|
|
|
+ ListeningPlanNew t1 = f.getT1();
|
|
|
+ List<ListeningPlanNewBackgroupPoster> t2 = f.getT2();
|
|
|
+ if (!t2.isEmpty()) {
|
|
|
+ List<ListeningPlanNewBackgroupPoster> collect = t2.stream().map(request -> new ListeningPlanNewBackgroupPoster(null,
|
|
|
+ request.audioId(),
|
|
|
+ request.groupId(),
|
|
|
+ request.image(),
|
|
|
+ request.kefu(),
|
|
|
+ request.limitTime(),
|
|
|
+ request.limitTimeRemark(),
|
|
|
+ request.status(),
|
|
|
+ request.index(),
|
|
|
+ request.serviceGroupId(),
|
|
|
+ request.serviceGroupType(),
|
|
|
+ request.qsOrFx(),
|
|
|
+ ZonedDateTime.now(),
|
|
|
+ null,
|
|
|
+ null,
|
|
|
+ t1.listeningPlanNewId(),
|
|
|
+ request.generateImagesJson(),
|
|
|
+ request.generateImagesUrl())).collect(Collectors.toList());
|
|
|
+ Mono<List<ListeningPlanNewBackgroupPoster>> listMono =
|
|
|
+ Flux.fromIterable(collect).flatMap(entity -> template.insert(entity)).collectList();
|
|
|
+ return Mono.zip(Mono.just(t1), listMono).flatMap(ff -> {
|
|
|
+ ListeningPlanNew t11 = ff.getT1();
|
|
|
+ return Mono.just(t11.listeningPlanNewId());
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ return Mono.just(t1.listeningPlanNewId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return RStatus.success(stringMono);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Mono<RStatus<ListeningDataLists>> LandingPageList(OutListeningRequest outListeningRequest) {
|
|
|
+ Mono<ListeningPlanNew> code1 = template.selectOne(Query.query(Criteria.where("code")
|
|
|
+ .is(outListeningRequest.getCode())), ListeningPlanNew.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException(" code错误")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
|
|
|
+ Mono<ListeningDataLists> idx_num1 = code1.flatMap(f -> {
|
|
|
+ Mono<List<ListeningAudio>> idx_num = template.select(Query.query(Criteria.empty())
|
|
|
+ .sort(Sort.by(Sort.Order.asc("idx_num")))
|
|
|
+ .limit(f.pageShow()), ListeningAudio.class).collectList();
|
|
|
+ return Mono.zip(Mono.just(f), idx_num).flatMap(ff -> {
|
|
|
+ ListeningDataLists listeningDataLists = new ListeningDataLists();
|
|
|
+ ListeningPlanNew t1 = ff.getT1();
|
|
|
+ List<ListeningAudio> t2 = ff.getT2();
|
|
|
+ if (t2.size() < t1.pageShow()) {
|
|
|
+ throw new BaseException("听书音频小于计划设置数");
|
|
|
+ }
|
|
|
+ List<H5ImageAndTextListening> collect = t2.stream().map(f1 -> {
|
|
|
+ H5ImageAndTextListening h5ImageAndTextListening = new H5ImageAndTextListening();
|
|
|
+ h5ImageAndTextListening.setAudioImageUrl(f1.audioImageUrl());
|
|
|
+ h5ImageAndTextListening.setAudioName(f1.audioName());
|
|
|
+ h5ImageAndTextListening.setAudioUrl(f1.audioUrl());
|
|
|
+ h5ImageAndTextListening.setIdxNum(f1.idxNum());
|
|
|
+ h5ImageAndTextListening.setPopupNode(f1.popupNode());
|
|
|
+ return h5ImageAndTextListening;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ listeningDataLists.setPlanNew(t1);
|
|
|
+ listeningDataLists.setImages(collect);
|
|
|
+ listeningDataLists.setPageLine(t1.pageLine());
|
|
|
+ listeningDataLists.setPageShow(t1.pageShow());
|
|
|
+ return Mono.just(listeningDataLists);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return RStatus.success(idx_num1);
|
|
|
+ }
|
|
|
+ private static final ConcurrentHashMap<String,Integer> map = new ConcurrentHashMap<>();
|
|
|
+ //清空用户Map数据
|
|
|
+ @Scheduled(cron="1 2 4 * * ?")
|
|
|
+ public void clearUserContextMap(){
|
|
|
+ log.info("清空听书裂变计划-H5用户Map数据》》》》》》》》》》》》》》》》》》》》》》开始");
|
|
|
+ map.clear();
|
|
|
+ log.info("空听书裂变计划-H5用户Map数据》》》》》》》》》》》》》》》》》》》》》》 结束");
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public Mono<RStatus<DataListsShare>> share(OutListeningShareRequest 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<ListeningPlanNew> code1 = template.selectOne(Query.query(Criteria.where("code")
|
|
|
+ .is(request.getCode())), ListeningPlanNew.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("hello!!! code错误")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
|
|
|
+ Mono<DataListsShare> dataListsShareMono = code1.flatMap(ftmp -> {
|
|
|
+ Mono<ListeningPlanNew> code = Mono.just(ftmp);
|
|
|
+ return Mono.zip(code, getPoster_template_id(code), getPoster(code), getPlanNewBackgroupPoster(code), getQrcode(code)).flatMap(f -> {
|
|
|
+ DataListsShare dataListsShare = new DataListsShare();
|
|
|
+ //按照访问次数设置海报
|
|
|
+ List<Poster> t3 = f.getT3();
|
|
|
+ if (t3.size() != 0) {
|
|
|
+ if (t3.size() <= request.getUserVisits()) {
|
|
|
+ dataListsShare.setPoster(t3.getLast());
|
|
|
+ } else {
|
|
|
+ dataListsShare.setPoster(t3.get(request.getUserVisits()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //背景海报顺序
|
|
|
+ List<ListeningPlanNewBackgroupPoster> qs = f.getT4().stream()
|
|
|
+ .sorted(Comparator.comparing(ListeningPlanNewBackgroupPoster::index))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ dataListsShare.setBackgroupPosterSum(qs.size());
|
|
|
+ if (!qs.isEmpty()) {
|
|
|
+ //大于背景设置数
|
|
|
+ if (qs.size() <= request.getUserVisits()) {
|
|
|
+ Integer userVisits = request.getUserVisits();
|
|
|
+ int v = userVisits % qs.size();
|
|
|
+ dataListsShare.setFxSetting(qs.get(v));
|
|
|
+ dataListsShare.setLink(f.getT1().link());//结束后开始设置link
|
|
|
+ } else {
|
|
|
+ dataListsShare.setFxSetting(qs.get(request.getUserVisits()));
|
|
|
+ dataListsShare.setLink(null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String posterTemplate = dataListsShare.getPoster().posterTemplate();
|
|
|
+ JSONObject jsonObject;
|
|
|
+ try {
|
|
|
+ jsonObject = JSONUtil.parseObj(posterTemplate);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BaseException(e.getMessage() + "--解析海报模版--Errrrrrrrr" + posterTemplate);
|
|
|
+ }
|
|
|
+ GoRequest goRequest = new GoRequest();
|
|
|
+ BeanUtil.copyProperties(jsonObject, goRequest);
|
|
|
+ ListeningPlanNewBackgroupPoster fxSetting = dataListsShare.getFxSetting();
|
|
|
+ setQrcodeV(f, goRequest, fxSetting);
|
|
|
+ Mono<String> stringMono = generatePosterUrl(goRequest, generateCusqrcode(goRequest));
|
|
|
+ return Mono.zip(Mono.just(dataListsShare), stringMono).flatMap(fm -> {
|
|
|
+ DataListsShare t1 = fm.getT1();
|
|
|
+ t1.setPosterTemplate(null);
|
|
|
+ t1.setPoster(null);
|
|
|
+ t1.setUserVisits(request.getUserVisits());
|
|
|
+ t1.setFxGenerateImagesUrl(fm.getT2());
|
|
|
+ return Mono.just(t1);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return RStatus.success(dataListsShareMono);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setQrcodeV(reactor.util.function.Tuple5<ListeningPlanNew, PosterTemplate, List<Poster>, List<ListeningPlanNewBackgroupPoster>, StringBuilder> f, GoRequest goRequest, ListeningPlanNewBackgroupPoster fxSetting) {
|
|
|
+ if (Objects.nonNull(fxSetting)) {
|
|
|
+ Optional<Item> first = goRequest.getItem().stream().filter(fz -> "qrcode".equals(fz.getT())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ Item item = first.get();
|
|
|
+ Boolean isRandom = item.getIsRandom();
|
|
|
+ if (isRandom && Objects.nonNull(fxSetting.status())
|
|
|
+ && fxSetting.status() == 1
|
|
|
+ && Objects.nonNull(fxSetting.serviceGroupType())
|
|
|
+ && fxSetting.serviceGroupType() == 2) {
|
|
|
+ String kefu = fxSetting.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("客服二维码");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new BaseException("设置qrcode 上传图片为空");
|
|
|
+ }
|
|
|
+ } else if (Objects.nonNull(fxSetting.status()) && fxSetting.status() == 0) {
|
|
|
+ item.setV(f.getT5().toString());
|
|
|
+ item.setName("H5二维码");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Mono<StringBuilder> getQrcode( Mono<ListeningPlanNew> code) {
|
|
|
+ return code.flatMap(f9 -> Mono.zip(code, template.select(Query.query(Criteria.where("group_type_id").is(f9.groupId())
|
|
|
+ .and("status").is(1).and("type").is(1)
|
|
|
+ .and("group_type").is(1)
|
|
|
+ .and("deleted_at").isNull()), DomainSelect.class)
|
|
|
+ .collectList()
|
|
|
+ .switchIfEmpty(Mono.just(List.of())), (a, b) -> {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ if (Objects.nonNull(b) && !b.isEmpty()) {
|
|
|
+ DomainSelect domainSelect = b.get(RandomUtil.randomInt(0, b.size()));
|
|
|
+ stringBuilder.append("http://");
|
|
|
+ stringBuilder.append(get6Str());
|
|
|
+ stringBuilder.append(".");
|
|
|
+ stringBuilder.append(domainSelect.domain());
|
|
|
+ stringBuilder.append("/index.html?code=");
|
|
|
+ stringBuilder.append(a.code());
|
|
|
+ stringBuilder.append("&sk=");
|
|
|
+ stringBuilder.append(IdUtil.fastSimpleUUID());
|
|
|
+ }else {
|
|
|
+ throw new BaseException("二维码链接:::通过计划id:"+a.listeningPlanNewId() +"的营销类型查询域名为空");
|
|
|
+ }
|
|
|
+ return stringBuilder;
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ public Mono<String> generatePosterUrl(GoRequest goRequest,Mono<List<StringBuilder>> stringBuilderMono){
|
|
|
+
|
|
|
+ Optional<Item> firstImage = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT())).findFirst();
|
|
|
+ Long imageGroupId=0L;
|
|
|
+ if (firstImage.isPresent() && Objects.nonNull(firstImage.get().getGroupTypeIdSc())) {
|
|
|
+ imageGroupId=firstImage.get().getGroupTypeIdSc();
|
|
|
+ }
|
|
|
+ Optional<Item> firstImage1 = goRequest.getItem().stream().filter(ft -> "text".equals(ft.getT())).findFirst();
|
|
|
+ Long imageGroupId1=0L;
|
|
|
+ if (firstImage1.isPresent() && Objects.nonNull(firstImage1.get().getGroupTypeIdSc())) {
|
|
|
+ imageGroupId1=firstImage1.get().getGroupTypeIdSc();
|
|
|
+ }
|
|
|
+ Optional<Item> firstImage2 = goRequest.getItem().stream().filter(ft -> "cover".equals(ft.getT())).findFirst();
|
|
|
+ Long imageGroupId2=0L;
|
|
|
+ if (firstImage2.isPresent() && Objects.nonNull(firstImage2.get().getGroupTypeIdSc())) {
|
|
|
+ imageGroupId2=firstImage2.get().getGroupTypeIdSc();
|
|
|
+ }
|
|
|
+ Long imageGroupIdBj=0L;
|
|
|
+ if(goRequest.getIsRandom()){
|
|
|
+ imageGroupIdBj=goRequest.getGroupTypeIdSc();
|
|
|
+ }
|
|
|
+ return getStringMonoOut(goRequest,
|
|
|
+ stringBuilderMono,
|
|
|
+ getBgImageYx(imageGroupIdBj),
|
|
|
+ getFmImageListsYx(imageGroupId),
|
|
|
+ getTextListsYx(imageGroupId1),
|
|
|
+ getImageTypeYx(imageGroupId2),
|
|
|
+ getTextListsTitleH5(goRequest));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Mono<List<ListeningPlanNewBackgroupPoster>> getPlanNewBackgroupPoster(Mono<ListeningPlanNew> code) {
|
|
|
+ return code.flatMap(plan -> template.select(Query.query(Criteria.where("poster_template_id")
|
|
|
+ .is(plan.posterTemplateId())).sort(Sort.by(Sort.Order.asc("idx"))), ListeningPlanNewBackgroupPoster.class)
|
|
|
+ .collectList());
|
|
|
+ }
|
|
|
+ private Mono<PosterTemplate> getPoster_template_id(Mono<ListeningPlanNew> code) {
|
|
|
+ return code.flatMap(plan -> template.selectOne(Query.query(Criteria.where("poster_template_id")
|
|
|
+ .is(plan.posterTemplateId())), PosterTemplate.class));
|
|
|
+ }
|
|
|
+ private Mono<List<Poster>> getPoster(Mono<ListeningPlanNew> 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());
|
|
|
+ }
|
|
|
+ public Mono<String> getStringMonoOut(GoRequest goRequest,
|
|
|
+ Mono<List<StringBuilder>> stringBuilderMono,
|
|
|
+ Mono<List<Image>> bgImage,
|
|
|
+ Mono<List<Image>> fmImage,
|
|
|
+ Mono<List<Material>> text,
|
|
|
+ Mono<List<Image>> fm1,
|
|
|
+ Mono<List<Material>> title) {
|
|
|
+ Mono<String> stringMono = Mono.zip(bgImage, fmImage, text, stringBuilderMono,fm1,title).flatMap(f -> {
|
|
|
+ List<Material> t6 = f.getT6().stream().filter(ft->Objects.nonNull(ft.id())).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(t6) &&!t6.isEmpty()) {
|
|
|
+ Optional.ofNullable(t6.get(RandomUtil.randomInt(0,t6.size()))).ifPresent(material -> goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "title".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(item -> {item.setV(material.content());}));
|
|
|
+ }else {
|
|
|
+ Optional<Item> first = goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "title".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ throw new BaseException("海报标题素材为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<StringBuilder> t4 = f.getT4();
|
|
|
+ if (Objects.nonNull(t4) && !t4.isEmpty()) {
|
|
|
+ goRequest.getItem().stream().filter(fc->"cusqrcode".equals(fc.getT())).forEach(fe->fe.setName("H5二维码"));
|
|
|
+ }else{
|
|
|
+ goRequest.getItem().stream().filter(fc->"cusqrcode".equals(fc.getT())).forEach(fe->fe.setName("客服二维码"));
|
|
|
+ }
|
|
|
+ Optional<Item> first2 = goRequest
|
|
|
+ .getItem()
|
|
|
+ .stream()
|
|
|
+ .filter(fc -> "cusqrcode".equals(fc.getT()) && (Objects.isNull(fc.getV()) || "".equals(fc.getV())))
|
|
|
+ .findFirst();
|
|
|
+ if (first2.isPresent()) {
|
|
|
+ throw new BaseException("自定义二维码素材为空");
|
|
|
+ }
|
|
|
+ List<Image> t1 = f.getT1();
|
|
|
+ if (goRequest.getIsRandom()) {
|
|
|
+ if (t1.isEmpty()) {
|
|
|
+ throw new BaseException("背景素材为空");
|
|
|
+ }
|
|
|
+ int i = RandomUtil.randomInt(0, t1.size());
|
|
|
+ Image image = t1.get(i);
|
|
|
+ goRequest.setBg_img_src(image.image());
|
|
|
+ }
|
|
|
+ //封面
|
|
|
+ List<Image> t5 = f.getT5().stream().filter(ft->Objects.nonNull(ft.id())).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(t5) &&!t5.isEmpty()) {
|
|
|
+ goRequest.getItem().stream().filter(ff -> "cover".equals(ff.getT()) && ff.getIsRandom()).findFirst()
|
|
|
+ .ifPresent(item -> item.setV(t5.get(RandomUtil.randomInt(0, t5.size())).image()));
|
|
|
+ }else {
|
|
|
+ Optional<Item> first1 = goRequest.getItem().stream().filter(ff -> "cover".equals(ff.getT()) && ff.getIsRandom()).findFirst();
|
|
|
+ if (first1.isPresent()) {
|
|
|
+ throw new BaseException("群封面素材为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //图片
|
|
|
+ List<Image> t2 = f.getT2().stream().filter(ft->Objects.nonNull(ft.id())).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(t2) &&!t2.isEmpty()) {
|
|
|
+ Optional.ofNullable(t2.get(RandomUtil.randomInt(0, t2.size()))).ifPresent(image -> goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "image".equals(ff.getT()) && ff.getIsRandom() )
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(item -> item.setV(image.image())));
|
|
|
+ }else {
|
|
|
+ Optional<Item> first1 = goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "image".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst();
|
|
|
+ if (first1.isPresent()) {
|
|
|
+ throw new BaseException("图片素材为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //文本
|
|
|
+ List<Material> t3 = f.getT3().stream().filter(ft->Objects.nonNull(ft.id())).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(t3) &&!t3.isEmpty()) {
|
|
|
+ Optional.ofNullable(t3.get(RandomUtil.randomInt(0,t3.size()))).ifPresent(material -> goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "text".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(item -> {item.setV(material.content());}));
|
|
|
+ }else{
|
|
|
+ Optional<Item> first1 = goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "text".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst();
|
|
|
+ if (first1.isPresent()) {
|
|
|
+ throw new BaseException("文字素材为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String ret = goGenerateStr(JSONUtil.toJsonStr(JSONUtil.toJsonStr(goRequest)));
|
|
|
+ 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")) {
|
|
|
+ return Mono.just(data.get("Url", String.class)) ;
|
|
|
+ }else {
|
|
|
+ throw new BaseException("--生成海报Url结果异常::::"+jsonObject1);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new BaseException("--生成海报code结果异常::::"+jsonObject1);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new BaseException("--生成海报结果null异常::::"+ret);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return stringMono;
|
|
|
+ }
|
|
|
+ public Mono<List<StringBuilder>> generateCusqrcode(GoRequest goRequest) {
|
|
|
+ List<Item> collect = goRequest.getItem().stream().filter(f -> "cusqrcode".equals(f.getT())
|
|
|
+ && Objects.nonNull(f.getPlanId())
|
|
|
+ && f.getIsRandom())
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Mono<List<StringBuilder>> stringBuilderMono =null;
|
|
|
+ if (Objects.nonNull(collect) && !collect.isEmpty()) {
|
|
|
+ List<Long> collect1 = collect.stream().map(Item::getPlanId).collect(Collectors.toList());
|
|
|
+ stringBuilderMono = template.select(Query.query(Criteria.where("listening_plan_new_id").in(collect1)), ListeningPlanNew.class)
|
|
|
+ .flatMap(f -> Mono.zip(Mono.just(f), template.select(Query.query(Criteria.where("group_type_id").is(f.groupId())
|
|
|
+ .and("status").is(1)
|
|
|
+ .and("type").is(1)
|
|
|
+ .and("deleted_at").isNull()), DomainSelect.class)
|
|
|
+ .collectList()
|
|
|
+ .switchIfEmpty(Mono.just(List.of())), (a, b) -> {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ if (Objects.nonNull(b) && !b.isEmpty()) {
|
|
|
+ DomainSelect domainSelect = b.get(RandomUtil.randomInt(0, b.size()));
|
|
|
+ stringBuilder.append("http://");
|
|
|
+ stringBuilder.append( get6Str());
|
|
|
+ stringBuilder.append(".");
|
|
|
+ stringBuilder.append(domainSelect.domain());
|
|
|
+ stringBuilder.append("/index.html?code=");
|
|
|
+ stringBuilder.append(a.code());
|
|
|
+ stringBuilder.append("&sk=");
|
|
|
+ stringBuilder.append(IdUtil.fastSimpleUUID());
|
|
|
+ }else {
|
|
|
+ throw new BaseException("通过计划id:"+a.listeningPlanNewId() +"的营销类型查询域名为空");
|
|
|
+ }
|
|
|
+ Optional<Item> first = collect.stream()
|
|
|
+ .filter(ft -> ft.getPlanId()
|
|
|
+ .equals(f.listeningPlanNewId()) && (Objects.isNull(ft.getV()) || "".equals(ft.getV()))).findFirst();
|
|
|
+ first.ifPresent(item -> item.setV(stringBuilder.toString()));
|
|
|
+ return stringBuilder;
|
|
|
+ })
|
|
|
+ ).collectList();
|
|
|
+ }
|
|
|
+ if (Objects.isNull(stringBuilderMono)) {
|
|
|
+ return Mono.just(List.of());
|
|
|
+ }
|
|
|
+ return stringBuilderMono;
|
|
|
+ }
|
|
|
+ private Mono<List<Material>> getTextListsTitleH5(GoRequest goRequest) {
|
|
|
+
|
|
|
+ Optional<Item> first = goRequest.getItem().stream().filter(ft -> "title".equals(ft.getT())).findFirst();
|
|
|
+ if (first.isPresent() && Objects.nonNull(first.get().getGroupTypeIdSc())) {
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(6)
|
|
|
+ .and("group_type_id").is(first.get().getGroupTypeIdSc())
|
|
|
+ .and("deleted_at").isNull()), Material.class)
|
|
|
+ .collectList();
|
|
|
+ }else {
|
|
|
+ return Mono.just(List.of(getMaterialNull()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private Mono<List<Material>> getTextListsYx(Long id) {
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(14)
|
|
|
+ .and("group_type_id").is(id)
|
|
|
+ .and("group_type").is(1).and("deleted_at").isNull()), Material.class).collectList();
|
|
|
+ }
|
|
|
+ private Mono<List<Image>> getBgImageYx(Long id) {
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(2)
|
|
|
+ .and("group_type").is(1).and("group_type_id").is(id)
|
|
|
+ .and("deleted_at").isNull()), Image.class).collectList();
|
|
|
+ }
|
|
|
+ private Mono<List<Image>> getFmImageListsYx(Long id) {
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(10)
|
|
|
+ .and("group_type_id").is(id).and("group_type")
|
|
|
+ .is(1).and("deleted_at").isNull()), Image.class).collectList();
|
|
|
+ }
|
|
|
+ private Mono<List<Image>> getImageTypeYx(Long id){
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(1) .and("group_type_id").is(id).and("group_type").is(1).and("deleted_at").isNull()), Image.class).collectList();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 计划保存修改生成图片
|
|
|
+ * @param goRequest
|
|
|
+ * @param stringBuilderMono
|
|
|
+ * @param qsSetting
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+
|
|
|
+ public Mono<String> saveAndUpdatePlanGenerateImage0(GoRequest goRequest,
|
|
|
+ Mono<List<StringBuilder>> stringBuilderMono,
|
|
|
+ ServiceGroupSettingItemRequest qsSetting,
|
|
|
+ PlanReq saveRequest ){
|
|
|
+
|
|
|
+ Optional<Item> firstImage = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT())).findFirst();
|
|
|
+ Long imageGroupId=0L;
|
|
|
+ if (firstImage.isPresent() && Objects.nonNull(firstImage.get().getGroupTypeIdSc())) {
|
|
|
+ imageGroupId=firstImage.get().getGroupTypeIdSc();
|
|
|
+ }
|
|
|
+ Optional<Item> firstImage1 = goRequest.getItem().stream().filter(ft -> "text".equals(ft.getT())).findFirst();
|
|
|
+ Long imageGroupId1=0L;
|
|
|
+ if (firstImage1.isPresent() && Objects.nonNull(firstImage1.get().getGroupTypeIdSc())) {
|
|
|
+ imageGroupId1=firstImage1.get().getGroupTypeIdSc();
|
|
|
+ }
|
|
|
+ Optional<Item> firstImage2 = goRequest.getItem().stream().filter(ft -> "cover".equals(ft.getT())).findFirst();
|
|
|
+ Long imageGroupId2=0L;
|
|
|
+ if (firstImage2.isPresent() && Objects.nonNull(firstImage2.get().getGroupTypeIdSc())) {
|
|
|
+ imageGroupId2=firstImage2.get().getGroupTypeIdSc();
|
|
|
+ }
|
|
|
+ Long imageGroupIdBj=0L;
|
|
|
+ if(goRequest.getIsRandom()){
|
|
|
+ imageGroupIdBj=goRequest.getGroupTypeIdSc();
|
|
|
+ }
|
|
|
+ return saveAndUpdatePlanGenerateImage1(goRequest, stringBuilderMono,
|
|
|
+ getBgImage(imageGroupIdBj),
|
|
|
+ getImageSaveOrUpdatePlan(imageGroupId),
|
|
|
+ getTextListsPlan(imageGroupId1),
|
|
|
+ getImageType1Plan(imageGroupId2),
|
|
|
+ qsSetting,
|
|
|
+ saveRequest,
|
|
|
+ getTextListsTitleSaveOrUpdatePlan( goRequest));
|
|
|
+ }
|
|
|
+
|
|
|
+ private Material getMaterialNull() {
|
|
|
+ return new Material(null, null, null, null, null, null, null, null, null, null, null);
|
|
|
+ }
|
|
|
+ private Mono<List<Material>> getTextListsTitleSaveOrUpdatePlan(GoRequest goRequest) {
|
|
|
+ Optional<Item> first = goRequest.getItem().stream().filter(ft -> "title".equals(ft.getT())).findFirst();
|
|
|
+ if (first.isPresent() && Objects.nonNull(first.get().getGroupTypeIdSc())) {
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(6)
|
|
|
+ .and("group_type_id").is(first.get().getGroupTypeIdSc())
|
|
|
+ .and("deleted_at").isNull()), Material.class)
|
|
|
+ .collectList();
|
|
|
+ }else {
|
|
|
+ return Mono.just(List.of(getMaterialNull()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private Mono<List<Image>> getImageType1Plan(Long groupTypeId){
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(1)
|
|
|
+ .and("group_type_id").is(groupTypeId)
|
|
|
+ .and("size_type").is(1)
|
|
|
+ .and("deleted_at").isNull()), Image.class).collectList();
|
|
|
+ }
|
|
|
+ private Mono<List<Material>> getTextListsPlan(Long groupTypeId) {
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(14)
|
|
|
+ .and("group_type_id").is(groupTypeId)
|
|
|
+ .and("deleted_at").isNull()), Material.class)
|
|
|
+ .collectList();
|
|
|
+ }
|
|
|
+ private Mono<List<Image>> getImageSaveOrUpdatePlan(Long id) {
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(10).and("group_type_id").is(id).and("deleted_at").isNull()), Image.class)
|
|
|
+ .collectList();
|
|
|
+ }
|
|
|
+ public Mono<String> saveAndUpdatePlanGenerateImage1(GoRequest goRequest,
|
|
|
+ Mono<List<StringBuilder>> stringBuilderMono,
|
|
|
+ Mono<List<Image>> bgImage,
|
|
|
+ Mono<List<Image>> images,
|
|
|
+ Mono<List<Material>> text,
|
|
|
+ Mono<List<Image>> coverFm,
|
|
|
+ ServiceGroupSettingItemRequest qsSetting,
|
|
|
+ PlanReq saveRequest,
|
|
|
+ Mono<List<Material>> title) {
|
|
|
+ Mono<String> stringMono = Mono.zip(bgImage, images, text, stringBuilderMono,coverFm,getQrcode(saveRequest),title).flatMap(f -> {
|
|
|
+ List<StringBuilder> t4 = f.getT4();//自定义二维码
|
|
|
+ if (Objects.nonNull(t4) && !t4.isEmpty()) {
|
|
|
+ goRequest.getItem().stream().filter(fc->"cusqrcode".equals(fc.getT())).forEach(fe->fe.setName("H5二维码"));
|
|
|
+ }else{
|
|
|
+ goRequest.getItem().stream().filter(fc->"cusqrcode".equals(fc.getT())).forEach(fe->fe.setName("客服二维码"));
|
|
|
+ }
|
|
|
+
|
|
|
+ Optional<Item> first2 = goRequest.getItem().stream().filter(fc -> "cusqrcode".equals(fc.getT()) && (Objects.isNull(fc.getV()) || "".equals(fc.getV()))).findFirst();
|
|
|
+ if (first2.isPresent()) {
|
|
|
+ throw new BaseException("自定义二维码素材为空");
|
|
|
+ }
|
|
|
+ //背景
|
|
|
+ List<Image> t1 = f.getT1();
|
|
|
+ if (goRequest.getIsRandom()) {
|
|
|
+ if (t1.isEmpty()) {
|
|
|
+ throw new BaseException("背景素材为空");
|
|
|
+ }
|
|
|
+ int i = RandomUtil.randomInt(0, t1.size());
|
|
|
+ Image image = t1.get(i);
|
|
|
+ goRequest.setBg_img_src(image.image());
|
|
|
+ }
|
|
|
+ //海报标题
|
|
|
+ List<Material> t7 = f.getT7().stream().filter(ft->Objects.nonNull(ft.id())).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(t7) &&!t7.isEmpty()) {
|
|
|
+ Optional.ofNullable(t7.get(RandomUtil.randomInt(0,t7.size()))).ifPresent(material -> goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "title".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(item -> item.setV(material.content())));
|
|
|
+ }else {
|
|
|
+ Optional<Item> first = goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "title".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ throw new BaseException("海报标题素材为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //群封面
|
|
|
+ List<Image> t5 = f.getT5().stream().filter(ft->Objects.nonNull(ft.id())).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(t5) &&!t5.isEmpty()) {
|
|
|
+ goRequest.getItem().stream().filter(ff -> "cover".equals(ff.getT()) && ff.getIsRandom()).findFirst()
|
|
|
+ .ifPresent(item -> item.setV(t5.get(RandomUtil.randomInt(0, t5.size())).image()));
|
|
|
+ }else {
|
|
|
+ Optional<Item> first1 = goRequest.getItem().stream().filter(ff -> "cover".equals(ff.getT()) && ff.getIsRandom()).findFirst();
|
|
|
+ if (first1.isPresent()) {
|
|
|
+ throw new BaseException("群封面素材为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //二维码链接
|
|
|
+ Optional<Item> first5 = goRequest.getItem().stream().filter(f1 -> "qrcode".equals(f1.getT())).findFirst();
|
|
|
+ if (first5.isPresent()) {
|
|
|
+ Item item = first5.get();
|
|
|
+ Boolean isRandom = item.getIsRandom();
|
|
|
+ if (isRandom && Objects.nonNull(qsSetting.getStatus()) && qsSetting.getStatus()==1
|
|
|
+ &&Objects.nonNull(qsSetting.getServiceGroupType()) && qsSetting.getServiceGroupType()==2 ) {
|
|
|
+ String kefu = qsSetting.getKefu();
|
|
|
+ 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("客服二维码");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ throw new BaseException("客服二维码 上传图片 为空");
|
|
|
+ }
|
|
|
+ }else if(Objects.nonNull(qsSetting.getStatus()) && qsSetting.getStatus()==0 ) {
|
|
|
+ StringBuilder t6 = f.getT6();
|
|
|
+ if ("".equals(t6)) {
|
|
|
+ throw new BaseException("获取H5链接为空");
|
|
|
+ }
|
|
|
+ item.setV(t6.toString());
|
|
|
+ item.setName("H5二维码");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //图片
|
|
|
+ List<Image> t2 = f.getT2().stream().filter(ft->Objects.nonNull(ft.id())).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(t2) &&!t2.isEmpty()) {
|
|
|
+ Optional.ofNullable(t2.get(RandomUtil.randomInt(0, t2.size()))).ifPresent(image -> goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "image".equals(ff.getT()) && ff.getIsRandom() )
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(item -> item.setV(image.image())));
|
|
|
+ }else {
|
|
|
+ Optional<Item> first1 = goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "image".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst();
|
|
|
+ if (first1.isPresent()) {
|
|
|
+ throw new BaseException("图片素材为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //文本
|
|
|
+ List<Material> t3 = f.getT3().stream().filter(ft->Objects.nonNull(ft.id())).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(t3) &&!t3.isEmpty()) {
|
|
|
+ Optional.ofNullable(t3.get(RandomUtil.randomInt(0,t3.size()))).ifPresent(material -> goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "text".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(item -> {item.setV(material.content());}));
|
|
|
+ }else{
|
|
|
+ Optional<Item> first1 = goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "text".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst();
|
|
|
+ if (first1.isPresent()) {
|
|
|
+ throw new BaseException("文字素材为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String s1 = JSONUtil.toJsonStr(goRequest);
|
|
|
+ System.out.println(s1);
|
|
|
+ String ret = goGenerateStr(s1);
|
|
|
+ System.out.println(ret);
|
|
|
+ String url=ret;
|
|
|
+ JSONObject jsonObject1 = JSONUtil.parseObj(ret);
|
|
|
+ if (jsonObject1.containsKey("code") && jsonObject1.get("code", Integer.class) == 0 && jsonObject1.containsKey("data")) {
|
|
|
+ JSONObject data = jsonObject1.get("data", JSONObject.class);
|
|
|
+ if (data.containsKey("Url")) {
|
|
|
+ url = data.get("Url", String.class);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Mono.just(url);
|
|
|
+ });
|
|
|
+ return stringMono;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String goGenerateStr(String temStr){
|
|
|
+ String body="";
|
|
|
+ try {
|
|
|
+ body = HttpUtil.post(value + "/api/image/createImage",temStr,100000);
|
|
|
+ return body;
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new BaseException(e.getMessage() + "body:::" +body);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ public Mono<StringBuilder> getQrcode(PlanReq saveRequest) {
|
|
|
+ if (Objects.isNull(saveRequest.getPlanNewId())|| "".equals(saveRequest.getPlanNewId())) {
|
|
|
+ return template.select(Query.query(Criteria.where("group_type_id").is(saveRequest.getGroupId())
|
|
|
+ .and("status").is(1)
|
|
|
+ .and("type").is(1)
|
|
|
+ .and("deleted_at").isNull()), DomainSelect.class)
|
|
|
+ .collectList()
|
|
|
+ .switchIfEmpty(Mono.just(List.of())).flatMap(b->{
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ getUrl(saveRequest, b, stringBuilder);
|
|
|
+ return Mono.just(stringBuilder);
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ return template.selectOne(Query.query(Criteria.where("listening_plan_new_id").is(saveRequest.getPlanNewId())), ListeningPlanNew.class)
|
|
|
+ .flatMap(f9 -> Mono.zip(Mono.just(f9), template.select(Query.query(Criteria.where("group_type_id").is(f9.groupId())
|
|
|
+ .and("status").is(1)
|
|
|
+ .and("type").is(1)
|
|
|
+ .and("deleted_at").isNull()), DomainSelect.class)
|
|
|
+ .collectList()
|
|
|
+ .switchIfEmpty(Mono.just(List.of())), (a, b) -> {
|
|
|
+ StringBuilder stringBuilder = new StringBuilder();
|
|
|
+ getUrl1(a, b, stringBuilder);
|
|
|
+ return stringBuilder;
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void getUrl1(ListeningPlanNew a, List<DomainSelect> b, StringBuilder stringBuilder) {
|
|
|
+ if (Objects.nonNull(b) && !b.isEmpty()) {
|
|
|
+ DomainSelect domainSelect = b.get(RandomUtil.randomInt(0, b.size()));
|
|
|
+ stringBuilder.append("http://");
|
|
|
+ stringBuilder.append(get6Str());
|
|
|
+ stringBuilder.append(".");
|
|
|
+ stringBuilder.append(domainSelect.domain());
|
|
|
+ stringBuilder.append("/index.html?code=");
|
|
|
+ stringBuilder.append(a.code());
|
|
|
+ stringBuilder.append("&sk=");
|
|
|
+ stringBuilder.append(IdUtil.fastSimpleUUID());
|
|
|
+ }else {
|
|
|
+ throw new BaseException("通过计划id:"+a.listeningPlanNewId() +"的营销类型查询域名为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void getUrl(PlanReq saveRequest, List<DomainSelect> b, StringBuilder stringBuilder) {
|
|
|
+ if (Objects.nonNull(b) && !b.isEmpty()) {
|
|
|
+ DomainSelect domainSelect = b.get(RandomUtil.randomInt(0, b.size()));
|
|
|
+ stringBuilder.append("http://");
|
|
|
+ stringBuilder.append(get6Str());
|
|
|
+ stringBuilder.append(".");
|
|
|
+ stringBuilder.append(domainSelect.domain());
|
|
|
+ stringBuilder.append("/index.html?code=");
|
|
|
+ stringBuilder.append(saveRequest.getCode());
|
|
|
+ stringBuilder.append("&sk=");
|
|
|
+ stringBuilder.append(IdUtil.fastSimpleUUID());
|
|
|
+ }else {
|
|
|
+ throw new BaseException("通过计划id:"+saveRequest.getPlanNewId() +"的营销类型查询域名为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String get6Str() {
|
|
|
+ String string = RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
|
+ return string;
|
|
|
+ }
|
|
|
+ //背景
|
|
|
+ private Mono<List<Image>> getBgImage(Long id) {
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(2).and("group_type_id").is(id).and("deleted_at").isNull()), Image.class)
|
|
|
+ .collectList();
|
|
|
+ }
|
|
|
+}
|