Просмотр исходного кода

plan-java v0.29

(cherry picked from commit 24d6e9dab8da7324d98ca580607b931a5c402f78)
MOKASZ\lw12420 2 лет назад
Родитель
Сommit
c403c8407e

+ 23 - 2
launch-admin/src/main/java/com/webflux/launchadmin/mysql/controller/planNew/PlanNewController.java

@@ -183,7 +183,28 @@ public class PlanNewController {
 //        Mono<Poster> insert = template.insert(poster);
 //        return RStatus.success(insert);
     }
-
+    @PostMapping("test11")
+    public Mono<RStatus<Poster>> test11(){
+        return goGenerateService.updatePoster1();
+//        Criteria empty = Criteria.where("poster_id").is(posterRequset.getPosterId());
+//        Update update = Update.update("updated_at", ZonedDateTime.now());
+//        if(Objects.nonNull(posterRequset.getPosterTemplate()) && !"".equals(posterRequset.getPosterTemplate())){
+//            update.set("poster_template",posterRequset.getPosterTemplate());
+//        }
+//        Mono<Long> update1 = template.update(Query.query(empty), update, Poster.class);
+//        return  RStatus.success(update1);
+    }
+    @PostMapping("test12")
+    public Mono<String> test112(){
+        return goGenerateService.updatePoster12();
+//        Criteria empty = Criteria.where("poster_id").is(posterRequset.getPosterId());
+//        Update update = Update.update("updated_at", ZonedDateTime.now());
+//        if(Objects.nonNull(posterRequset.getPosterTemplate()) && !"".equals(posterRequset.getPosterTemplate())){
+//            update.set("poster_template",posterRequset.getPosterTemplate());
+//        }
+//        Mono<Long> update1 = template.update(Query.query(empty), update, Poster.class);
+//        return  RStatus.success(update1);
+    }
     /**
      * 海报修改
      * @param posterRequset
@@ -300,7 +321,7 @@ public class PlanNewController {
         if (Objects.nonNull(request.getName()) && "" != request.getName()) {
             criteria = criteria.and("name").like(request.getName());
         }
-        Mono<List<PosterTemplate>> listMono = template.select(Query.query(criteria), PosterTemplate.class).collectList();
+        Mono<List<PosterTemplate>> listMono = template.select(Query.query(criteria).sort(Sort.by(Sort.Order.desc("created_at"))), PosterTemplate.class).collectList();
         return RStatus.successList(listMono);
     }
 

+ 192 - 96
launch-admin/src/main/java/com/webflux/launchadmin/mysql/service/planNew/goGenerate/GoGenerateService.java

@@ -1,7 +1,9 @@
 package com.webflux.launchadmin.mysql.service.planNew.goGenerate;
 
 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.HttpResponse;
 import cn.hutool.http.HttpUtil;
 import cn.hutool.json.JSONObject;
@@ -11,10 +13,7 @@ import com.webflux.launchadmin.global.BaseException;
 import com.webflux.launchadmin.mysql.controller.planNew.req.AudioRequest;
 import com.webflux.launchadmin.mysql.controller.planNew.req.PosterRequest;
 import com.webflux.launchadmin.mysql.controller.planNew.res.PosterRes;
-import com.webflux.launchadmin.mysql.entity.planNew.Ad;
-import com.webflux.launchadmin.mysql.entity.planNew.Image;
-import com.webflux.launchadmin.mysql.entity.planNew.Material;
-import com.webflux.launchadmin.mysql.entity.planNew.Poster;
+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.RStatus;
@@ -26,6 +25,7 @@ import org.springframework.data.relational.core.query.Query;
 import org.springframework.data.relational.core.query.Update;
 import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.RequestBody;
+import reactor.core.publisher.Flux;
 import reactor.core.publisher.Mono;
 
 import java.time.ZonedDateTime;
@@ -34,6 +34,7 @@ import java.util.Objects;
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicReference;
 import java.util.concurrent.locks.Lock;
+import java.util.stream.Collectors;
 
 @Service
 public class GoGenerateService {
@@ -49,65 +50,132 @@ public class GoGenerateService {
 
     //http://wx-share-8.duiweize.com 正式
     public String goGenerate(String temStr){
-        JSONObject jsonObject = JSONUtil.parseObj(temStr);
-        GoRequest goRequest = new GoRequest();
-        BeanUtil.copyProperties(jsonObject,goRequest);
-        //HttpResponse response = HttpUtil.createPost(value + "/api/image/createImage").body(temStr).timeout(300000).execute();
-        //String body = response.body();
-
-        String body = HttpUtil.post(value + "/api/image/createImage", JSONUtil.parseObj(goRequest),100000);
+//        JSONObject jsonObject = JSONUtil.parseObj(temStr);
+//        GoRequest goRequest = new GoRequest();
+//        BeanUtil.copyProperties(jsonObject,goRequest);
+//        JSONObject jsonObject1 = JSONUtil.parseObj(goRequest);
+        String body = HttpUtil.post(value + "/api/image/createImage",temStr,100000);
         return body;
 
     }
+    public String goGenerateStr(String temStr){
+        try {
+            JSONObject jsonObject = JSONUtil.parseObj(temStr);
+            String body = HttpUtil.post(value + "/api/image/createImage",temStr,100000);
+            return body;
+        } catch (Exception e) {
+            System.out.println(e);
+            throw new BaseException(e.getMessage());
+        }
 
-    public Mono<RStatus<Poster>> savePoster(PosterRequest posterRequset){
 
-//        Mono<Poster> insert = template.insert(poster)
-//                .switchIfEmpty(Mono.error(new BaseException(" 操作失败")))
-//                .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
+
+    }
+    public Mono<RStatus<Poster>> savePoster(PosterRequest posterRequset){
 
         String posterTemplate = posterRequset.getPosterTemplate();
         JSONObject jsonObject = JSONUtil.parseObj(posterTemplate);
         GoRequest goRequest = new GoRequest();
-        BeanUtil.copyProperties(jsonObject,goRequest);
+        BeanUtil.copyProperties(jsonObject,goRequest);//cusqrcode
+        Mono<List<StringBuilder>> stringBuilderMono = getStringBuilderMono(goRequest);
         if (goRequest.getIsRandom()) {
-            // 背景
-            Mono<List<Image>> bgImage = template.select(Query.query(Criteria.where("type").is(2)), Image.class).collectList();
-            //封面
-            Mono<List<Image>> fmImage = template.select(Query.query(Criteria.where("type").is(1)), Image.class).collectList();
-            //文字
-            Mono<List<Material>> text = template.select(Query.query(Criteria.where("type").is(1)), Material.class).collectList();
-            Mono<String> stringMono = Mono.zip(bgImage, fmImage, text).flatMap(f -> {
-                Optional<Image> first = f.getT1().stream().findFirst();
-                first.ifPresent(image -> goRequest.setBg_img_src(image.image()));
-                Optional<Image> first1 = f.getT2().stream().findFirst();
-                first1.ifPresent(image -> goRequest.getItem().stream()
-                        .filter(ff -> "image".equals(ff.getT()))
-                        .findFirst()
-                        .ifPresent(item -> item.setV(image.image())));
-                Optional<Material> first2 = f.getT3().stream().findFirst();
-                first2.ifPresent(material -> goRequest.getItem().stream()
-                        .filter(ff -> "text".equals(ff.getT()))
-                        .findFirst()
-                        .ifPresent(item -> item.setV(material.content())));
-                String s1 = JSONUtil.toJsonStr(goRequest);
-                String s = goGenerate(s1);
-                return Mono.just(s);
-            });
-            Mono<Poster> zip = getPosterResMono1(Mono.just(posterRequset), stringMono);
-            Mono<Poster> posterMono = zip.switchIfEmpty(Mono.error(new BaseException(" 操作失败")))
-                    .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
-            Mono<Poster> posterMono1 = posterMono.flatMap(f -> template.insert(f));
+//            // 背景
+//            Mono<List<Image>> bgImage = getBgImage();
+//            //封面
+//            Mono<List<Image>> fmImage = getFmImageLists0();
+//            //文字
+//            Mono<List<Material>> text = getTextLists();
+            Mono<Poster> posterMono1 = getPosterResMono1(Mono.just(posterRequset),
+                    getStringMono(goRequest, stringBuilderMono, getBgImage(), getFmImageLists0(), getTextLists()))
+                    .switchIfEmpty(Mono.error(new BaseException(" 操作失败")))
+                    .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())))
+                    .flatMap(f -> template.insert(f));
             return RStatus.success(posterMono1);
         }else {
-            String s = goGenerate(JSONUtil.toJsonStr(goRequest));
-            Mono<Poster> zip = getPosterResMono1(Mono.just(posterRequset), Mono.just(s));
-            Mono<Poster> posterMono = zip.switchIfEmpty(Mono.error(new BaseException(" 操作失败")))
-                    .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
-            Mono<Poster> posterMono1 = posterMono.flatMap(f -> template.insert(f));
+            Mono<Poster> posterMono1 = getPosterResMono1(Mono.just(posterRequset),
+                    stringBuilderMono.flatMap(f -> Mono.just(goGenerateStr(JSONUtil.toJsonStr(goRequest)))))
+                    .switchIfEmpty(Mono.error(new BaseException(" 操作失败")))
+                    .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())))
+                    .flatMap(f -> template.insert(f));
             return RStatus.success(posterMono1);
         }
     }
+
+    private Mono<List<Material>> getTextLists() {
+        return template.select(Query.query(Criteria.where("type").is(1)), Material.class).collectList();
+    }
+
+    private Mono<List<Image>> getBgImage() {
+        return template.select(Query.query(Criteria.where("type").is(2)), Image.class).collectList();
+    }
+
+    private Mono<String> getStringMono(GoRequest goRequest, Mono<List<StringBuilder>> stringBuilderMono, Mono<List<Image>> bgImage, Mono<List<Image>> fmImage, Mono<List<Material>> text) {
+        Mono<String> stringMono = Mono.zip(bgImage, fmImage, text, stringBuilderMono).flatMap(f -> {
+            List<StringBuilder> t4 = f.getT4();
+           // System.out.println(t4);
+            Optional<Image> first = f.getT1().stream().findFirst();
+            first.ifPresent(image -> goRequest.setBg_img_src(image.image()));
+            Optional<Image> first1 = f.getT2().stream().findFirst();
+            first1.ifPresent(image -> goRequest.getItem().stream()
+                    .filter(ff -> "image".equals(ff.getT()))
+                    .findFirst()
+                    .ifPresent(item -> item.setV(image.image())));
+            Optional<Material> first2 = f.getT3().stream().findFirst();
+            first2.ifPresent(material -> goRequest.getItem().stream()
+                    .filter(ff -> "text".equals(ff.getT()))
+                    .findFirst()
+                    .ifPresent(item -> item.setV(material.content())));
+            String s1 = JSONUtil.toJsonStr(goRequest);
+            String s = goGenerateStr(s1);
+            return Mono.just(s);
+        });
+        return stringMono;
+    }
+
+    private Mono<List<StringBuilder>> getStringBuilderMono(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()) {
+            //Item item = first3.get();
+            //Long planid = item.getPlanId();
+            List<Long> collect1 = collect.stream().map(Item::getPlanId).collect(Collectors.toList());
+             stringBuilderMono = template.select(Query.query(Criteria.where("plan_new_id").in(collect1)), PlanNew.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)), DomainSelect.class)
+                                    .collectList()
+                                    .switchIfEmpty(Mono.just(List.of())), (a, b) -> {
+                                StringBuilder stringBuilder = new StringBuilder();
+                                if (Objects.isNull(b) || b.isEmpty()) {
+                                    stringBuilder.append("生成计划链接 匹配域名为空");
+                                } else {
+                                    DomainSelect domainSelect = b.get(RandomUtil.randomInt(0, b.size()));
+                                    stringBuilder.append("http://");
+                                    stringBuilder.append(IdUtil.fastSimpleUUID().substring(0, 6));
+                                    stringBuilder.append(".");
+                                    stringBuilder.append(domainSelect.domain());
+                                    stringBuilder.append("/index.html?code=");
+                                    stringBuilder.append(a.code());
+                                    stringBuilder.append("&sk=");
+                                    stringBuilder.append(IdUtil.fastSimpleUUID());
+                                }
+                                Optional<Item> first = collect.stream()
+                                        .filter(ft -> ft.getPlanId()
+                                                .equals(f.planNewId()) && (Objects.isNull(ft.getV()) || "".equals(ft.getV()))).findFirst();
+                                if (first.isPresent()) {
+                                    first.get().setName(stringBuilder.toString());
+                                }
+
+                                System.out.println(stringBuilder);
+                                return stringBuilder;
+                            })
+                    ).collectList();
+        }
+        if (Objects.isNull(stringBuilderMono)) {
+            return Mono.just(List.of(new StringBuilder("空空如也")));
+        }
+        return stringBuilderMono;
+    }
+
     private Mono<Poster> getPosterResMono1(Mono<PosterRequest> insert, Mono<String> stringMono) {
         Mono<Poster> zip = Mono.zip(insert, stringMono, (entry, ret) -> {
             JSONObject jsonObject1 = JSONUtil.parseObj(ret);
@@ -127,6 +195,35 @@ public class GoGenerateService {
         return zip;
     }
 
+    private Mono<Poster> getPosterResMonoUpdate(Mono<PosterRequest> insert, Mono<String> stringMono,PosterRequest posterRequset) {
+
+        Mono<Poster> posterMono = Mono.zip(insert, stringMono).flatMap(f -> {
+            PosterRequest entry = f.getT1();
+            String ret = f.getT2();
+            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")) {
+                    String url = data.get("Url", String.class);
+                    return template.selectOne(Query.query(Criteria.where("poster_id").is(posterRequset.getPosterId())), Poster.class).map(ff -> {
+                        Poster poster = new Poster(ff.posterId(), entry.getPosterTemplateId()
+                                , entry.getPosterTemplate(), BaseContextHandler.getUserName(),
+                                BaseContextHandler.getUserId(), ZonedDateTime.now(),
+                                ZonedDateTime.now(), ret, url);
+                        return poster;
+                    });
+
+                }
+            }
+            return Mono.empty();
+
+        });
+        return posterMono;
+    }
+
+
+
+
     private Mono<PosterRes> getPosterResMono(Mono<Poster> insert, Mono<String> stringMono) {
         Mono<PosterRes> zip = Mono.zip(insert, stringMono, (entry, ret) -> {
             PosterRes posterRes = new PosterRes();
@@ -153,66 +250,65 @@ public class GoGenerateService {
         return zip;
     }
 
+
+    public Mono<RStatus<Poster>> updatePoster1(){
+        Mono<RStatus<Poster>> poster_id = template.selectOne(Query.query(Criteria.where("poster_id").is(37)), Poster.class).flatMap(f -> {
+
+            PosterRequest posterRequest = new PosterRequest();
+            posterRequest.setPosterId(f.posterId());
+            posterRequest.setPosterTemplate(f.posterTemplate());
+            posterRequest.setPosterTemplateId(f.posterTemplateId());
+            Mono<RStatus<Poster>> rStatusMono = updatePoster(posterRequest);
+            // String s = goGenerate(JSONUtil.toJsonStr(f.posterTemplate()));
+            // System.out.println(s);
+            return rStatusMono;
+        });
+        return poster_id;
+
+
+    }
+    public Mono<String> updatePoster12(){
+        Mono<String> poster_id = template.selectOne(Query.query(Criteria.where("poster_id").is(37)), Poster.class).flatMap(f -> {
+
+            PosterRequest posterRequest = new PosterRequest();
+            posterRequest.setPosterTemplate(f.posterTemplate());
+            posterRequest.setPosterTemplateId(f.posterTemplateId());
+           // Mono<RStatus<Poster>> rStatusMono = savePoster(posterRequest);
+             String s = goGenerate(JSONUtil.toJsonStr(f.posterTemplate()));
+             System.out.println(s);
+            return Mono.just(s);
+        });
+        return poster_id;
+
+
+    }
     public Mono<RStatus<Poster>> updatePoster(@RequestBody PosterRequest posterRequset){
 
         String posterTemplate = posterRequset.getPosterTemplate();
         JSONObject jsonObject = JSONUtil.parseObj(posterTemplate);
         GoRequest goRequest = new GoRequest();
         BeanUtil.copyProperties(jsonObject,goRequest);
+        Mono<List<StringBuilder>> stringBuilderMono = getStringBuilderMono(goRequest);
         if (goRequest.getIsRandom()) {
-            // 背景
-            Mono<List<Image>> bgImage = template.select(Query.query(Criteria.where("type").is(2)), Image.class).collectList();
-            //封面
-            Mono<List<Image>> fmImage = template.select(Query.query(Criteria.where("type").is(1)), Image.class).collectList();
-            //文字
-            Mono<List<Material>> text = template.select(Query.query(Criteria.where("type").is(1)), Material.class).collectList();
-            Mono<String> stringMono = Mono.zip(bgImage, fmImage, text).flatMap(f -> {
-                Optional<Image> first = f.getT1().stream().findFirst();
-                first.ifPresent(image -> goRequest.setBg_img_src(image.image()));
-                Optional<Image> first1 = f.getT2().stream().findFirst();
-                first1.ifPresent(image -> goRequest.getItem().stream()
-                        .filter(ff -> "image".equals(ff.getT()))
-                        .findFirst()
-                        .ifPresent(item -> item.setV(image.image())));
-                Optional<Material> first2 = f.getT3().stream().findFirst();
-                first2.ifPresent(material -> goRequest.getItem().stream()
-                        .filter(ff -> "text".equals(ff.getT()))
-                        .findFirst()
-                        .ifPresent(item -> item.setV(material.content())));
-                String s = goGenerate(JSONUtil.toJsonStr(goRequest));
-                return Mono.just(s);
-            });
-            Mono<Poster> zip = getPosterResMono2(Mono.just(posterRequset), stringMono);
-            Mono<Poster> posterMono = zip.switchIfEmpty(Mono.error(new BaseException(" 操作失败")))
-                    .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
-            Mono<Poster> posterMono1 = posterMono.flatMap(f -> template.update(f));
+            Mono<Poster> posterMono1 = getPosterResMonoUpdate(Mono.just(posterRequset),
+                    getStringMono(goRequest, stringBuilderMono, getBgImage(), getFmImageLists0(), getTextLists()),posterRequset)
+                    .switchIfEmpty(Mono.error(new BaseException(" 操作失败")))
+                    .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())))
+                    .flatMap(f -> template.update(f));
             return RStatus.success(posterMono1);
         }else {
-            String s = goGenerate(JSONUtil.toJsonStr(goRequest));
-            Mono<Poster> zip = getPosterResMono2(Mono.just(posterRequset), Mono.just(s));
-            Mono<Poster> posterMono = zip.switchIfEmpty(Mono.error(new BaseException(" 操作失败")))
-                    .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())));
-            Mono<Poster> posterMono1 = posterMono.flatMap(f -> template.update(f));
+            Mono<Poster> posterMono1 = getPosterResMonoUpdate(Mono.just(posterRequset),
+                    stringBuilderMono.flatMap(f -> Mono.just(goGenerateStr(JSONUtil.toJsonStr(goRequest)))),posterRequset)
+                    .switchIfEmpty(Mono.error(new BaseException(" 操作失败")))
+                    .onErrorResume(throwable -> Mono.error(new Exception(throwable.getMessage())))
+                    .flatMap(f -> template.update(f));
             return RStatus.success(posterMono1);
         }
+
     }
 
-    private Mono<Poster> getPosterResMono2(Mono<PosterRequest> insert, Mono<String> stringMono) {
-        Mono<Poster> zip = Mono.zip(insert, stringMono, (entry, 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")) {
-                    String url = data.get("Url", String.class);
-                    Poster poster = new Poster(null, entry.getPosterTemplateId()
-                            ,entry.getPosterTemplate(), BaseContextHandler.getUserName(),
-                            BaseContextHandler.getUserId(), ZonedDateTime.now(),
-                            ZonedDateTime.now(),ret,url);
-                    return poster;
-                }
-            }
-            return null;
-        });
-        return zip;
+    private Mono<List<Image>> getFmImageLists0() {
+        return template.select(Query.query(Criteria.where("type").is(1)), Image.class).collectList();
     }
+
 }

+ 2 - 0
launch-admin/src/main/java/com/webflux/launchadmin/mysql/service/planNew/structure/Item.java

@@ -45,4 +45,6 @@ public class Item {
 
     private Boolean isRandom;
 
+    private Long planId;
+
 }