Prechádzať zdrojové kódy

听书裂变3.19

(cherry picked from commit da7f0504c97045b3f9545519053c836876f67d67)
(cherry picked from commit bf44cec011ba93ac900a286e6569b9beabd22a22)
MOKASZ\lw12420 2 rokov pred
rodič
commit
59f306528c

+ 78 - 19
launch-admin/src/main/java/com/webflux/launchadmin/mysql/service/listening/ListeningPlanServiceImpl.java

@@ -562,16 +562,33 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
 
     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> 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();
+//        }
+
+
+        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);
         }
-        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();
+        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())).findFirst();
         Long imageGroupId2=0L;
         if (firstImage2.isPresent() && Objects.nonNull(firstImage2.get().getGroupTypeIdSc())) {
@@ -585,7 +602,7 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
                 stringBuilderMono,
                 getBgImageYx(imageGroupIdBj),
                 getFmImageListsYx(imageGroupId),
-                getTextListsYx(imageGroupId1),
+                getTextListsYx(textIds),
                 getImageTypeYx(imageGroupId2),
                 getTextListsTitleH5(goRequest));
     }
@@ -609,7 +626,7 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
                                          Mono<List<Image>> fmImage,
                                          Mono<List<Material>> text,
                                          Mono<List<Image>> fm1,
-                                         Mono<List<Material>> title) {
+                                         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()) {
@@ -662,10 +679,30 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
             //图片
             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())));
+
+                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()){
+                    throw 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());
+                        });
+
+//                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())
@@ -677,10 +714,32 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
             //文本
             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()
+
+                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())
-                        .findFirst()
-                        .ifPresent(item -> {item.setV(material.content());}));
+                        .map(Item::getGroupTypeIdSc)
+                        .distinct()
+                        .collect(Collectors.toList());
+                if(collect.size() != collect1.size()){
+                    throw 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());
+                        });
+//                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())
@@ -767,7 +826,7 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
             return   Mono.just(List.of(getMaterialNull()));
         }
     }
-    private Mono<List<Material>> getTextListsYx(Long id) {
+    private Mono<List<Material>> getTextListsYx( ArrayList<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();
@@ -777,7 +836,7 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
                 .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) {
+    private Mono<List<Image>> getFmImageListsYx( ArrayList<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();