|
|
@@ -0,0 +1,443 @@
|
|
|
+package com.webflux.launchadmin.mysql.service.readBookPlan;
|
|
|
+
|
|
|
+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.http.HttpUtil;
|
|
|
+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.PlanReq;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.req.ReadBookPlanGetImageReq;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.req.ServiceGroupSettingItemRequest;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.res.ReadBookGetOneMaterialRes;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.res.ReadBookGetPosterImageRes;
|
|
|
+import com.webflux.launchadmin.mysql.controller.planNew.res.ReadBookImageRes;
|
|
|
+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.structure.GoRequest;
|
|
|
+import com.webflux.launchadmin.mysql.service.planNew.structure.Item;
|
|
|
+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.stereotype.Service;
|
|
|
+import reactor.core.publisher.Mono;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ReadBookPlanServicesImpl implements ReadBookPlanServicesInterface{
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private R2dbcEntityTemplate template;
|
|
|
+ @Value("${go.data.contactWay}")
|
|
|
+ private String contactWayUrl;
|
|
|
+ @Resource
|
|
|
+ private GoGenerateService goGenerateService;
|
|
|
+ @Value("${go.data.createImage}")
|
|
|
+ private String value;
|
|
|
+ @Override
|
|
|
+ public Mono<ReadBookGetPosterImageRes> readBookGetPoster(ReadBookPlanGetImageReq 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 BaseException("请求异常:"+throwable.getMessage())));
|
|
|
+ return planNewCommonMono.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()
|
|
|
+ .flatMap(posters -> {
|
|
|
+ Poster poster = posters.get(RandomUtil.randomInt(0, posters.size()));
|
|
|
+ String posterTemplate = poster.posterTemplate();
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(posterTemplate);
|
|
|
+ GoRequest goRequest = new GoRequest();
|
|
|
+ BeanUtil.copyProperties(jsonObject, goRequest);
|
|
|
+ return readBookGenerateImagePasePoster(goRequest,
|
|
|
+ goGenerateService.setCusqrcodeSetV(goRequest),//设置自定义二维码
|
|
|
+ setQrcodeV(goRequest, request, plan));//设置二维码
|
|
|
+ }).flatMap(s -> {
|
|
|
+ ReadBookGetPosterImageRes readBookGetPosterImageRes = new ReadBookGetPosterImageRes();
|
|
|
+ readBookGetPosterImageRes.setPosterImagesUrl(s);
|
|
|
+ return Mono.just(readBookGetPosterImageRes);
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Mono<ReadBookGetOneMaterialRes> readBookGetOneMaterial(String code) {
|
|
|
+ return template.selectOne(Query.query(Criteria.where("code").is(code)), PlanNewCommon.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("计划code异")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("计划code异"))).flatMap(f -> {
|
|
|
+ Mono<ReadBookGetOneMaterialRes> readBookGetOneMaterialResMono = template
|
|
|
+ .select(Query.query(Criteria.where("type").is(15)
|
|
|
+ .and("deleted_at").isNull()
|
|
|
+ .and("group_type_id").is(f.groupId())), Material.class)
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("获取分享文案异常Err"+throwable.getMessage())))
|
|
|
+ .collectList()
|
|
|
+ .flatMap(f1 -> {
|
|
|
+ Material material = f1.get(RandomUtil.randomInt(0, f1.size()));
|
|
|
+ ReadBookGetOneMaterialRes res = new ReadBookGetOneMaterialRes();
|
|
|
+ res.setPosterImagesUrl(material.content());
|
|
|
+ return Mono.just(res);
|
|
|
+ });
|
|
|
+ return readBookGetOneMaterialResMono;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Mono<ReadBookImageRes> getRandomQWGroup( String code) {
|
|
|
+ return template.selectOne(Query.query(Criteria.where("code").is(code)), PlanNewCommon.class)
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("计划code异")))
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("计划code异"))).flatMap(f -> {
|
|
|
+ Mono<ReadBookImageRes> readBookGetOneMaterialResMono = template
|
|
|
+ .select(Query.query(Criteria.where("type").is(12)
|
|
|
+ .and("group_type_id").is(f.groupId())
|
|
|
+ .and("deleted_at").isNull()), Image.class)
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("获取企微群码异常Err"+throwable.getMessage())))
|
|
|
+ .collectList()
|
|
|
+ .flatMap(f1 -> {
|
|
|
+ Image image = f1.get(RandomUtil.randomInt(0, f1.size()));
|
|
|
+ ReadBookImageRes res = new ReadBookImageRes();
|
|
|
+ res.setUrl(image.image());
|
|
|
+ return Mono.just(res);
|
|
|
+ });
|
|
|
+ return readBookGetOneMaterialResMono;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public String byCustomerIdGetUrl(Long channelCodeId) {
|
|
|
+ //?channelCodeId=941873&state=1
|
|
|
+ long l = System.currentTimeMillis();
|
|
|
+ String body;
|
|
|
+ String url = contactWayUrl + "?channelCodeId="+channelCodeId+"&state="+l;
|
|
|
+ try {
|
|
|
+ body = HttpUtil.get(url, 100000);
|
|
|
+ } catch (Exception e) {
|
|
|
+ String format = StrUtil.format("请求【客服活码对外接口】errrr:{} channelCodeId:{} Get请求url:{}", e.getMessage(), channelCodeId, url);
|
|
|
+ log.error(format);
|
|
|
+ throw new BaseException(format);
|
|
|
+ }
|
|
|
+ if (Objects.isNull(body)||"".equals(body.trim()) ) {
|
|
|
+ String format = StrUtil.format("请求【客服活码对外接口】返回结果异常:{} channelCodeId:{} Get请求url:{}", body, channelCodeId, url);
|
|
|
+ log.error(format);
|
|
|
+ throw new BaseException(format);
|
|
|
+ }
|
|
|
+ JSONObject jsonObject;
|
|
|
+ try {
|
|
|
+ jsonObject = JSONUtil.parseObj(body);
|
|
|
+ }catch (Exception e){
|
|
|
+ String format = StrUtil.format("请求【客服活码对外接口】返回结果解析JSONERRR:{} channelCodeId:{} Get请求url:{} Body:{}", e.getMessage(), channelCodeId, url,body);
|
|
|
+ log.error(format);
|
|
|
+ throw new BaseException(format);
|
|
|
+ }
|
|
|
+ if (jsonObject.containsKey("code")
|
|
|
+ && Objects.nonNull(jsonObject.get("code"))
|
|
|
+ && jsonObject.get("code", Integer.class) == 200
|
|
|
+ && jsonObject.containsKey("data")
|
|
|
+ && Objects.nonNull(jsonObject.get("data"))
|
|
|
+ ) {
|
|
|
+ return jsonObject.get("data", String.class);
|
|
|
+ }else {
|
|
|
+ String format = StrUtil.format("请求【客服活码对外接口】返回结果失败 channelCodeId:{} Get请求url:{} Body:{}", channelCodeId, url,body);
|
|
|
+ log.error(format);
|
|
|
+ throw new BaseException(format);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public Mono<String> readBookGenerateImagePasePoster(GoRequest goRequest,
|
|
|
+ Mono<List<StringBuilder>> stringBuilderMono,
|
|
|
+ Mono<Boolean> booleanMono){
|
|
|
+ List<Item> imageGroup = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT()) && ft.getIsRandom()).collect(Collectors.toList());
|
|
|
+ ArrayList<Long> imageGroupId = new ArrayList<>();
|
|
|
+ if ( Objects.nonNull(imageGroup) && !imageGroup.isEmpty()) {
|
|
|
+ imageGroupId.addAll(imageGroup.stream().map(Item::getGroupTypeIdSc).collect(Collectors.toList()));
|
|
|
+ }else {
|
|
|
+ imageGroupId.add(0L);
|
|
|
+ }
|
|
|
+ List<Item> collect = goRequest.getItem().stream().filter(ft -> "text".equals(ft.getT())&& ft.getIsRandom()).collect(Collectors.toList());
|
|
|
+ ArrayList<Long> textIds = new ArrayList<>();
|
|
|
+ if ( Objects.nonNull(collect) && !collect.isEmpty() ) {
|
|
|
+ textIds.addAll(collect.stream().map(Item::getGroupTypeIdSc).collect(Collectors.toList()));
|
|
|
+ }else {
|
|
|
+ textIds.add(0L);
|
|
|
+ }
|
|
|
+ Optional<Item> firstImage2 = goRequest.getItem().stream().filter(ft -> "cover".equals(ft.getT())&& ft.getIsRandom()).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 readBookGenerateImage(goRequest, stringBuilderMono,
|
|
|
+ getBgImage(imageGroupIdBj),
|
|
|
+ getImageSaveOrUpdatePlan(imageGroupId),
|
|
|
+ getTextListsPlan(textIds),
|
|
|
+ getImageType1Plan(imageGroupId2),
|
|
|
+ booleanMono ,
|
|
|
+ getTextListsTitleSaveOrUpdatePlan( goRequest));
|
|
|
+ }
|
|
|
+ //背景
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ private Mono<List<Image>> getImageSaveOrUpdatePlan(ArrayList<Long> id) {
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(10)
|
|
|
+ .and("group_type_id").in(id)
|
|
|
+ .and("deleted_at").isNull()), Image.class)
|
|
|
+ .collectList();
|
|
|
+ }
|
|
|
+ private Mono<List<Material>> getTextListsPlan(ArrayList<Long> groupTypeId) {
|
|
|
+ return template.select(Query.query(Criteria.where("type").is(14)
|
|
|
+ .and("group_type_id").in(groupTypeId)
|
|
|
+ .and("deleted_at").isNull()), Material.class)
|
|
|
+ .collectList();
|
|
|
+ }
|
|
|
+ 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>> 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 Material getMaterialNull() {
|
|
|
+ return new Material(null, null, null, null, null, null, null, null, null, null, null);
|
|
|
+ }
|
|
|
+ public Mono<String> readBookGenerateImage(GoRequest goRequest,
|
|
|
+ Mono<List<StringBuilder>> stringBuilderMono,
|
|
|
+ Mono<List<Image>> bgImage,
|
|
|
+ Mono<List<Image>> images,
|
|
|
+ Mono<List<Material>> text,
|
|
|
+ Mono<List<Image>> coverFm,
|
|
|
+ Mono<Boolean> booleanMono ,
|
|
|
+ Mono<List<Material>> title) {
|
|
|
+ Mono<String> stringMono = Mono.zip(bgImage, images, text, stringBuilderMono,coverFm,booleanMono,title).flatMap(f -> {
|
|
|
+ List<StringBuilder> t4 = f.getT4();//自定义二维码
|
|
|
+ Boolean t6 = f.getT6();
|
|
|
+ Optional<Item> first2 = goRequest.getItem().stream().filter(fc -> "cusqrcode".equals(fc.getT()) && (Objects.isNull(fc.getV()) || "".equals(fc.getV()))).findFirst();
|
|
|
+ if (first2.isPresent()) {
|
|
|
+ return Mono.error(new BaseException("自定义二维码素材为空"));
|
|
|
+ }
|
|
|
+ //背景
|
|
|
+ List<Image> t1 = f.getT1();
|
|
|
+ if (goRequest.getIsRandom()) {
|
|
|
+ if (t1.isEmpty()) {
|
|
|
+ return Mono.error(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()) {
|
|
|
+ return Mono.error(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()) {
|
|
|
+ return Mono.error(new BaseException("群封面素材为空"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //图片
|
|
|
+ List<Image> t2 = f.getT2().stream().filter(ft->Objects.nonNull(ft.id())).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(t2) &&!t2.isEmpty()) {
|
|
|
+ List<Integer> collect = t2.stream().map(Image::groupTypeId).distinct().collect(Collectors.toList());
|
|
|
+ List<Long> collect1 = goRequest.getItem().stream().filter(ff -> "image".equals(ff.getT())
|
|
|
+ && ff.getIsRandom()).map(Item::getGroupTypeIdSc).distinct().collect(Collectors.toList());
|
|
|
+ if(collect.size() != collect1.size()){
|
|
|
+ return Mono.error(new BaseException("图片素材个数不匹配"));
|
|
|
+ }
|
|
|
+ goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "image".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .forEach(fe->{
|
|
|
+ List<Image> collect2 = t2.stream()
|
|
|
+ .filter(fter -> Long.valueOf(fter.groupTypeId()).equals(fe.getGroupTypeIdSc()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Image image = collect2.get(RandomUtil.randomInt(0, collect2.size()));
|
|
|
+ if (Objects.isNull(image)) {
|
|
|
+ throw new BaseException("图片素材为空");
|
|
|
+ }
|
|
|
+ fe.setV(image.image());
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ Optional<Item> first1 = goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "image".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst();
|
|
|
+ if (first1.isPresent()) {
|
|
|
+ return Mono.error(new BaseException("图片素材为空"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //文本
|
|
|
+ List<Material> t3 = f.getT3().stream().filter(ft->Objects.nonNull(ft.id())).collect(Collectors.toList());
|
|
|
+ if (Objects.nonNull(t3) &&!t3.isEmpty()) {
|
|
|
+ List<Integer> collect = t3.stream().map(Material::groupTypeId).distinct().collect(Collectors.toList());
|
|
|
+ List<Long> collect1 = goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "text".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .map(Item::getGroupTypeIdSc)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if(collect.size() != collect1.size()){
|
|
|
+ return Mono.error(new BaseException("文本素材个数不匹配"));
|
|
|
+ }
|
|
|
+ goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "text".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .forEach(fe->{
|
|
|
+ List<Material> collect2 = t3.stream()
|
|
|
+ .filter(fter -> Long.valueOf(fter.groupTypeId()).equals(fe.getGroupTypeIdSc()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ Material material = collect2.get(RandomUtil.randomInt(0, collect2.size()));
|
|
|
+ if (Objects.isNull(material)) {
|
|
|
+ throw new BaseException("图片素材为空");
|
|
|
+ }
|
|
|
+ fe.setV(material.content());
|
|
|
+ });
|
|
|
+ }else{
|
|
|
+ Optional<Item> first1 = goRequest.getItem().stream()
|
|
|
+ .filter(ff -> "text".equals(ff.getT()) && ff.getIsRandom())
|
|
|
+ .findFirst();
|
|
|
+ if (first1.isPresent()) {
|
|
|
+ return Mono.error(new BaseException("文字素材为空"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String s1 = JSONUtil.toJsonStr(goRequest);
|
|
|
+ String ret = goGenerateStr(s1);
|
|
|
+ String url;
|
|
|
+ JSONObject jsonObject1;
|
|
|
+ try {
|
|
|
+ jsonObject1 = JSONUtil.parseObj(ret);
|
|
|
+ }catch (Exception e){
|
|
|
+ String format = StrUtil.format("生成图片解析异常:{} 返回:{} 请求参数:{}", e.getMessage(), ret, s1);
|
|
|
+ log.error(format);
|
|
|
+ return Mono.error(new BaseException(format));
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+ }else {
|
|
|
+ String format = StrUtil.format("生成图片返回Url异常 返回:{} 请求参数:{}", ret, s1);
|
|
|
+ log.error(format);
|
|
|
+ return Mono.error(new BaseException(format));
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ String format = StrUtil.format("生成图片返回code或data异常 返回:{} 请求参数:{}", ret, s1);
|
|
|
+ log.error(format);
|
|
|
+ return Mono.error(new BaseException(format));
|
|
|
+ }
|
|
|
+ return Mono.just(url);
|
|
|
+ });
|
|
|
+ return stringMono;
|
|
|
+ }
|
|
|
+ //设置自定义二维码
|
|
|
+ private Mono<Boolean> setQrcodeV(GoRequest goRequest,ReadBookPlanGetImageReq request,PlanNewCommon plan){
|
|
|
+ Optional<Item> first = goRequest.getItem().stream().filter(fz -> "qrcode".equals(fz.getT())).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ Item item = first.get();
|
|
|
+ item.setName("客服二维码");
|
|
|
+ if(item.getIsRandom()){
|
|
|
+ Mono<String> url;
|
|
|
+ if(item.getIsChannel()){
|
|
|
+ //用客服
|
|
|
+ url = Mono.just(byCustomerIdGetUrl(request.getChannelCodeId()));
|
|
|
+ return Mono.zip(Mono.just(item),url).flatMap(f->{
|
|
|
+ f.getT1().setV(f.getT2());
|
|
|
+ f.getT1().setName("客服二维码");
|
|
|
+ return Mono.just(true);
|
|
|
+ });
|
|
|
+ }else {
|
|
|
+ //用计划
|
|
|
+ url = byGroupIdGetUrl(Mono.just(plan));
|
|
|
+ return Mono.zip(Mono.just(item),url).flatMap(f->{
|
|
|
+ f.getT1().setV(f.getT2());
|
|
|
+ f.getT1().setName("客服二维码");
|
|
|
+ return Mono.just(true);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Mono.just(true);
|
|
|
+ }
|
|
|
+ public Mono<String> byGroupIdGetUrl( Mono<PlanNewCommon> 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.id() +"的营销类型查询域名为空");
|
|
|
+ }
|
|
|
+ return stringBuilder.toString();
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private String get6Str() {
|
|
|
+ return RandomUtil.randomString("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", 6);
|
|
|
+ }
|
|
|
+ public String goGenerateStr(String temStr){
|
|
|
+ String body="";
|
|
|
+ try {
|
|
|
+ body = HttpUtil.post(value + "/api/image/createImage",temStr,100000);
|
|
|
+ return body;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage() + "body:::" +body, e);
|
|
|
+ throw new BaseException(e.getMessage() + "body:::" +body);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|