|
|
@@ -31,12 +31,13 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
import java.time.ZonedDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
-
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
|
|
|
@Service
|
|
|
@@ -80,15 +81,20 @@ public class GoGenerateService {
|
|
|
GoRequest goRequest = new GoRequest();
|
|
|
BeanUtil.copyProperties(jsonObject,goRequest);//cusqrcode
|
|
|
Mono<List<StringBuilder>> stringBuilderMono = getStringBuilderMono(goRequest);
|
|
|
- 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();
|
|
|
+ List<Item> imageGroup = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT())).collect(Collectors.toList());
|
|
|
+ //Long imageGroupId=0L;
|
|
|
+ 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())).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;
|
|
|
@@ -104,7 +110,7 @@ public class GoGenerateService {
|
|
|
stringBuilderMono,
|
|
|
getBgImage(imageGroupIdBj),
|
|
|
getImageSaveOrUpdatePoster(imageGroupId),
|
|
|
- getTextListsPoster(imageGroupId1),
|
|
|
+ getTextListsPoster(textIds),
|
|
|
getImageType1Poster(imageGroupId2),
|
|
|
getTextListsTitleSaveOrUpdatePoster(posterRequset)))
|
|
|
.switchIfEmpty(Mono.error(new BaseException(" 操作失败")))
|
|
|
@@ -138,9 +144,9 @@ public class GoGenerateService {
|
|
|
.collectList();
|
|
|
}
|
|
|
|
|
|
- private Mono<List<Material>> getTextListsPoster(Long groupTypeId) {
|
|
|
+ private Mono<List<Material>> getTextListsPoster(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();
|
|
|
}
|
|
|
@@ -801,10 +807,28 @@ 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())
|
|
|
@@ -815,10 +839,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())
|
|
|
@@ -988,15 +1033,20 @@ public class GoGenerateService {
|
|
|
GoRequest goRequest = new GoRequest();
|
|
|
BeanUtil.copyProperties(jsonObject,goRequest);
|
|
|
Mono<List<StringBuilder>> stringBuilderMono = getStringBuilderMono(goRequest);
|
|
|
- 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();
|
|
|
+ List<Item> imageGroup = goRequest.getItem().stream().filter(ft -> "image".equals(ft.getT())).collect(Collectors.toList());
|
|
|
+ //Long imageGroupId=0L;
|
|
|
+ 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())).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;
|
|
|
@@ -1012,7 +1062,7 @@ public class GoGenerateService {
|
|
|
stringBuilderMono,
|
|
|
getBgImage(imageGroupIdBj),
|
|
|
getImageSaveOrUpdatePoster(imageGroupId),
|
|
|
- getTextListsPoster(imageGroupId1),
|
|
|
+ getTextListsPoster(textIds),
|
|
|
getImageType1Poster(imageGroupId2),
|
|
|
getTextListsTitleSaveOrUpdatePoster(posterRequset)),
|
|
|
posterRequset)
|
|
|
@@ -1027,8 +1077,10 @@ public class GoGenerateService {
|
|
|
.collectList();
|
|
|
}
|
|
|
|
|
|
- private Mono<List<Image>> getImageSaveOrUpdatePoster(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>> getImageSaveOrUpdatePoster(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<Image>> getImageSaveOrUpdatePlan(Long id) {
|