فهرست منبع

听书裂变3.18

(cherry picked from commit ac5fe6f2bcadd495f26f3d65a3b51826bb63025e)
(cherry picked from commit a3528a24635e7f7ffa037d9c6ab941afc6b4a271)
MOKASZ\lw12420 2 سال پیش
والد
کامیت
0c76fa1631

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

@@ -798,17 +798,33 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
                                                         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> 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();
+
+        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();
@@ -817,10 +833,10 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
         if(goRequest.getIsRandom()){
             imageGroupIdBj=goRequest.getGroupTypeIdSc();
         }
-        return   saveAndUpdatePlanGenerateImage1(goRequest, stringBuilderMono,
+        return  saveAndUpdatePlanGenerateImage1(goRequest, stringBuilderMono,
                 getBgImage(imageGroupIdBj),
                 getImageSaveOrUpdatePlan(imageGroupId),
-                getTextListsPlan(imageGroupId1),
+                getTextListsPlan(textIds),
                 getImageType1Plan(imageGroupId2),
                 qsSetting,
                 saveRequest,
@@ -847,14 +863,16 @@ public class ListeningPlanServiceImpl implements ListeningPlanServiceInterface{
                 .and("size_type").is(1)
                 .and("deleted_at").isNull()), Image.class).collectList();
     }
-    private Mono<List<Material>> getTextListsPlan(Long groupTypeId) {
+    private Mono<List<Material>> getTextListsPlan(ArrayList<Long> groupTypeId) {
         return template.select(Query.query(Criteria.where("type").is(14)
-                .and("group_type_id").is(groupTypeId)
+                .and("group_type_id").in(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)
+    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();
     }
     public Mono<String> saveAndUpdatePlanGenerateImage1(GoRequest goRequest,
@@ -944,10 +962,28 @@ 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())
@@ -959,10 +995,31 @@ 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())

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

@@ -81,22 +81,22 @@ public class GoGenerateService {
         GoRequest goRequest = new GoRequest();
         BeanUtil.copyProperties(jsonObject,goRequest);//cusqrcode
         Mono<List<StringBuilder>> stringBuilderMono = getStringBuilderMono(goRequest);
-        List<Item> imageGroup = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT())).collect(Collectors.toList());
-        //Long imageGroupId=0L;
+
+        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())).collect(Collectors.toList());
+        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();
+        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();
@@ -150,9 +150,9 @@ public class GoGenerateService {
                 .and("deleted_at").isNull()), Material.class)
                 .collectList();
     }
-    private Mono<List<Material>> getTextListsPlan(Long groupTypeId) {
+    private Mono<List<Material>> getTextListsPlan( ArrayList<Long> groupTypeId) {
         return template.select(Query.query(Criteria.where("type").is(14)
-                .and("group_type_id").is(groupTypeId)
+                .and("group_type_id").in(groupTypeId)
                 .and("deleted_at").isNull()), Material.class)
                 .collectList();
     }
@@ -225,17 +225,33 @@ public class GoGenerateService {
 //            groupId=0L;
 //        }
 
-        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();
+
+        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();
@@ -248,7 +264,7 @@ public class GoGenerateService {
              stringBuilderMono,
              getBgImageYx(imageGroupIdBj),
              getFmImageListsYx(imageGroupId),
-             getTextListsYx(imageGroupId1),
+             getTextListsYx(textIds),
              getImageTypeYx(imageGroupId2),
              getTextListsTitleH5(goRequest));
     }
@@ -261,17 +277,34 @@ public class GoGenerateService {
 //        }else {
 //            groupId=0L;
 //        }
-        Optional<Item> firstImage = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT())).findFirst();
-        Long imageGroupId=0L;
-        if (firstImage.isPresent() && Objects.nonNull(firstImage.get().getGroupTypeIdQs())) {
-            imageGroupId=firstImage.get().getGroupTypeIdQs();
+//        Optional<Item> firstImage = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT())).findFirst();
+//        Long imageGroupId=0L;
+//        if (firstImage.isPresent() && Objects.nonNull(firstImage.get().getGroupTypeIdQs())) {
+//            imageGroupId=firstImage.get().getGroupTypeIdQs();
+//        }
+//        Optional<Item> firstImage1 = goRequest.getItem().stream().filter(ft -> "text".equals(ft.getT())).findFirst();
+//        Long imageGroupId1=0L;
+//        if (firstImage1.isPresent() && Objects.nonNull(firstImage1.get().getGroupTypeIdQs())) {
+//            imageGroupId1=firstImage1.get().getGroupTypeIdQs();
+//        }
+
+        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::getGroupTypeIdQs).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().getGroupTypeIdQs())) {
-            imageGroupId1=firstImage1.get().getGroupTypeIdQs();
+        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::getGroupTypeIdQs).collect(Collectors.toList()));
+        }else {
+            textIds.add(0L);
         }
-        Optional<Item> firstImage2 = goRequest.getItem().stream().filter(ft -> "cover".equals(ft.getT())).findFirst();
+
+
+        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().getGroupTypeIdQs())) {
             imageGroupId2=firstImage2.get().getGroupTypeIdQs();
@@ -284,7 +317,7 @@ public class GoGenerateService {
                 stringBuilderMono,
                 getBgImageQs(imageGroupIdBj),
                 getFmImageListsQs(imageGroupId),
-                getTextListsQs(imageGroupId1),
+                getTextListsQs(textIds),
                 getImageTypeQs(imageGroupId2),
                 getTextListsTitleH5(goRequest));
     }
@@ -295,17 +328,17 @@ public class GoGenerateService {
                 .and("deleted_at").isNull()), Image.class).collectList();
     }
 
-    private Mono<List<Image>> getFmImageListsQs(Long id) {
+    private Mono<List<Image>> getFmImageListsQs(ArrayList<Long> id) {
         return template.select(Query.query(Criteria.where("type").is(10)
                 .and("group_type").is(2)
-                .and("group_type_id").is(id)
+                .and("group_type_id").in(id)
                 .and("deleted_at").isNull()), Image.class).collectList();
     }
 
-    private Mono<List<Material>> getTextListsQs(Long id) {
+    private Mono<List<Material>> getTextListsQs(ArrayList<Long> id) {
         return template.select(Query.query(Criteria.where("type").is(14)
                 .and("group_type").is(2)
-                .and("group_type_id").is(id)
+                .and("group_type_id").in(id)
                 .and("deleted_at").isNull()), Material.class).collectList();
     }
     private Mono<List<Image>> getImageTypeQs(Long id){
@@ -316,9 +349,9 @@ public class GoGenerateService {
     }
 
 
-    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_id").in(id)
                 .and("group_type").is(1).and("deleted_at").isNull()), Material.class).collectList();
     }
     private Mono<List<Image>> getBgImageYx(Long id) {
@@ -326,9 +359,9 @@ public class GoGenerateService {
                 .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")
+                .and("group_type_id").in(id).and("group_type")
                 .is(1).and("deleted_at").isNull()), Image.class).collectList();
     }
     private Mono<List<Image>> getImageTypeYx(Long id){
@@ -467,17 +500,33 @@ public class GoGenerateService {
                                                         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> 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();
+
+        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();
@@ -489,7 +538,7 @@ public class GoGenerateService {
         return    saveAndUpdatePlanGenerateImage1(goRequest, stringBuilderMono,
                                                     getBgImage(imageGroupIdBj),
                                                     getImageSaveOrUpdatePlan(imageGroupId),
-                                                    getTextListsPlan(imageGroupId1),
+                                                    getTextListsPlan(textIds),
                                                     getImageType1Plan(imageGroupId2),
                                                     qsSetting,
                                                     saveRequest,
@@ -594,10 +643,30 @@ public class GoGenerateService {
             //图片
             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())
@@ -609,10 +678,31 @@ public class GoGenerateService {
             //文本
             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())
@@ -1033,7 +1123,7 @@ public class GoGenerateService {
         GoRequest goRequest = new GoRequest();
         BeanUtil.copyProperties(jsonObject,goRequest);
         Mono<List<StringBuilder>> stringBuilderMono = getStringBuilderMono(goRequest);
-        List<Item> imageGroup = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT())).collect(Collectors.toList());
+        List<Item> imageGroup = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT()) && ft.getIsRandom()).collect(Collectors.toList());
         //Long imageGroupId=0L;
         ArrayList<Long> imageGroupId = new ArrayList<>();
         if ( Objects.nonNull(imageGroup) && !imageGroup.isEmpty()) {
@@ -1041,14 +1131,14 @@ public class GoGenerateService {
         }else {
             imageGroupId.add(0L);
         }
-        List<Item> collect = goRequest.getItem().stream().filter(ft -> "text".equals(ft.getT())).collect(Collectors.toList());
+        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();
+        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();
@@ -1083,9 +1173,9 @@ public class GoGenerateService {
                 .and("deleted_at").isNull()), Image.class)
                 .collectList();
     }
-    private Mono<List<Image>> getImageSaveOrUpdatePlan(Long id) {
+    private Mono<List<Image>> getImageSaveOrUpdatePlan( ArrayList<Long> id) {
         return template.select(Query.query(Criteria.where("type").is(10)
-                .and("group_type_id").is(id)
+                .and("group_type_id").in(id)
                 .and("deleted_at").isNull()), Image.class)
                 .collectList();
     }