|
@@ -1,16 +1,55 @@
|
|
|
package com.webflux.launchadmin.mysql.service.sourceMaterial.materialManagement;
|
|
package com.webflux.launchadmin.mysql.service.sourceMaterial.materialManagement;
|
|
|
|
|
|
|
|
-import com.webflux.launchadmin.mysql.controller.planNew.res.BackgroupImageRes;
|
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.hutool.json.JSONArray;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
|
|
+import com.webflux.launchadmin.config.BaseContextHandler;
|
|
|
|
|
+import com.webflux.launchadmin.global.BaseException;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.controller.sourceMaterial.data.BackgroupGroup.*;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.controller.sourceMaterial.data.album.AlbumDto;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.controller.sourceMaterial.data.album.AlbumItemReq;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.controller.sourceMaterial.data.album.AlbumReq;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.controller.sourceMaterial.data.image.ImageSaveRes;
|
|
|
import com.webflux.launchadmin.mysql.entity.planNew.BackgroupImage;
|
|
import com.webflux.launchadmin.mysql.entity.planNew.BackgroupImage;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.planNew.BackgroupImageItem;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.planNew.GroupType;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.planNew.Image;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.sourceMaterial.Album;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.entity.sourceMaterial.AlbumItem;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.repository.sourceMaterial.*;
|
|
|
import com.webflux.launchadmin.mysql.service.sourceMaterial.SourceMaterialInterface;
|
|
import com.webflux.launchadmin.mysql.service.sourceMaterial.SourceMaterialInterface;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.service.sourceMaterial.data.image.ImageExcelRedisCache;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.service.sourceMaterial.data.sql.Where;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.service.sourceMaterial.materialManagement.redisCache.interfacelist.AlbumInterface;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.service.sourceMaterial.materialManagement.redisCache.interfacelist.AlbumItemInterface;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.service.sourceMaterial.materialManagement.redisCache.interfacelist.BackgroupImageInterface;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.service.sourceMaterial.materialManagement.redisCache.BackgroupImageItemService;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.service.sourceMaterial.materialManagement.redisCache.interfacelist.GroupTypeinterface;
|
|
|
|
|
+import com.webflux.launchadmin.mysql.service.upload.UploadOssInterface;
|
|
|
import com.webflux.launchcommon.returnObj.Paged;
|
|
import com.webflux.launchcommon.returnObj.Paged;
|
|
|
import com.webflux.launchcommon.returnObj.RStatus;
|
|
import com.webflux.launchcommon.returnObj.RStatus;
|
|
|
|
|
+import com.webflux.launchcommon.utils.StringUtils;
|
|
|
import jakarta.annotation.Resource;
|
|
import jakarta.annotation.Resource;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
|
|
|
|
|
+import org.springframework.data.redis.core.ReactiveRedisTemplate;
|
|
|
|
|
+import org.springframework.data.relational.core.query.Criteria;
|
|
|
|
|
+import org.springframework.data.relational.core.query.Query;
|
|
|
|
|
+import org.springframework.data.relational.core.query.Update;
|
|
|
|
|
+import org.springframework.http.codec.multipart.FilePart;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
+import reactor.core.publisher.Flux;
|
|
|
import reactor.core.publisher.Mono;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
|
|
+import java.io.ByteArrayInputStream;
|
|
|
|
|
+import java.io.IOException;
|
|
|
|
|
+import java.time.Duration;
|
|
|
|
|
+import java.time.ZonedDateTime;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -19,18 +58,574 @@ public class MaterialManagementImpl implements MaterialManagementInterface {
|
|
|
@Resource
|
|
@Resource
|
|
|
private SourceMaterialInterface sourceMaterialInterface;
|
|
private SourceMaterialInterface sourceMaterialInterface;
|
|
|
@Resource
|
|
@Resource
|
|
|
|
|
+ private BackgroupImageRepository backgroupImageRepository;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private GroupTypeRepository groupTypeRepository;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private BackgroupImageItemRepository backgroupImageItemRepository;
|
|
|
|
|
+ @Resource
|
|
|
private R2dbcEntityTemplate template;
|
|
private R2dbcEntityTemplate template;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private UploadOssInterface uploadService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ ReactiveRedisTemplate<String, Image> reactiveRedisImageTemplate;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ ReactiveRedisTemplate<String, Object> reactiveRedisTemplate;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ GroupTypeinterface groupTypeinterface;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ BackgroupImageInterface backgroupImageInterface;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ BackgroupImageItemService backgroupImageItemInterface;
|
|
|
|
|
+ //素材图片缓存
|
|
|
|
|
+ private static final String hashKey = "execel_upload_cache_Image_";
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //Todo GroupType
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<GroupType> saveMysqlAndRedisGroupType( GroupType groupType) {
|
|
|
|
|
+ return groupTypeRepository.save( groupType)
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("保存GroupType失败" + throwable.getMessage())))
|
|
|
|
|
+ .flatMap(groupTypeinterface::saveMysqlAndRedisGroupType);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //Todo BackgroupImage <<<<<<<<<<<<<<
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<Void> saveMysqlAndRedisBackgroupItem(BackgroupImageItem backgroupImageItem) {
|
|
|
|
|
+ return backgroupImageItemRepository.insertImageItem(backgroupImageItem.image(),backgroupImageItem.index(),backgroupImageItem.groupId());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<BackgroupImage> saveMysqlAndRedisBackgroupImage(BackgroupImage backgroupImage) {
|
|
|
|
|
+ return template.insert(backgroupImage)
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("保存backgroupImage失败" + throwable.getMessage())))
|
|
|
|
|
+ .flatMap(backgroupImageInterface::saveMysqlAndRedisBackgroupImageCache);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Mono<BackgroupImage> updateMysqlAndRedisBackgroupImage(BackgroupImage backgroupImage) {
|
|
|
|
|
+ return template.update(backgroupImage)
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("保存backgroupImage失败" + throwable.getMessage())))
|
|
|
|
|
+ .flatMap(backgroupImageInterface::saveMysqlAndRedisBackgroupImageCache);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<BackgroupImage> removeRedisAndMysqlBackgroupImage(Long id) {
|
|
|
|
|
+ return backgroupImageRepository.deleteLogicFor(ZonedDateTime.now(),id)
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("删除失败" + throwable.getMessage())))
|
|
|
|
|
+ .flatMap(backgroupImage -> backgroupImageInterface.deleteMysqlAndRedisBackgroupImageCache(backgroupImage))
|
|
|
|
|
+ .flatMap(backgroupImage -> {
|
|
|
|
|
+ Mono<List<BackgroupImageItem>> listMono =
|
|
|
|
|
+ backgroupImageItemRepository
|
|
|
|
|
+ .findByGroupId(backgroupImage.id())
|
|
|
|
|
+ .flatMap(backgroupImageItem ->
|
|
|
|
|
+ backgroupImageItemInterface
|
|
|
|
|
+ .deleteMysqlAndRedisBackgroupImageCache(backgroupImageItem))
|
|
|
|
|
+ .collectList();
|
|
|
|
|
+ return listMono.then(Mono.just(backgroupImage));
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ // Todo Api
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<Paged<BackgroupImageResNew>>> pageBackgroup(Integer page, Integer size) {
|
|
|
|
|
+ return sourceMaterialInterface.pageAndFunctionRtE(List.of(),BackgroupImage.class,size,page,(f)-> Flux.fromIterable(f).flatMap(fe -> {
|
|
|
|
|
+ String string = sourceMaterialInterface.tToString(fe);
|
|
|
|
|
+ BackgroupImageResNew backgroupImageRes = sourceMaterialInterface.strParseT(string, BackgroupImageResNew.class);
|
|
|
|
|
+ Mono<List<BackgroupImageItem>> listMono =
|
|
|
|
|
+ template.select(Query.query(Criteria.where("group_id").is(fe.id())),
|
|
|
|
|
+ BackgroupImageItem.class).collectList();
|
|
|
|
|
+
|
|
|
|
|
+ return Mono.zip(Mono.just(backgroupImageRes), listMono).flatMap(all -> {
|
|
|
|
|
+ BackgroupImageResNew t1 = all.getT1();
|
|
|
|
|
+ List<BackgroupImageItem> t2 = all.getT2();
|
|
|
|
|
+ Mono<Boolean> backgroupImageMono=Mono.just(true);
|
|
|
|
|
+ if (Objects.isNull(t1.getItemIds()) || "".equals(t1.getItemIds())) {
|
|
|
|
|
+ //主任务绑定子任务id 实现缓存cache 查询 此表是go服务设计 不能修改只能兼容
|
|
|
|
|
+ List<Long> collect = t2.stream().map(BackgroupImageItem::id).collect(Collectors.toList());
|
|
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
|
|
+ String ids = JSONUtil.toJsonStr(collect);
|
|
|
|
|
+ backgroupImageMono = template.update(Query.query(Criteria.where("id").is(t1.getId())),
|
|
|
|
|
+ Update.update("item_ids", ids),
|
|
|
|
|
+ BackgroupImage.class)
|
|
|
|
|
+ .flatMap(id -> backgroupImageRepository
|
|
|
|
|
+ .findById(id)
|
|
|
|
|
+ .flatMap(backgroupImage1 ->
|
|
|
|
|
+ backgroupImageInterface
|
|
|
|
|
+ .saveMysqlAndRedisBackgroupImageCache(backgroupImage1))).then(Mono.just(true));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!t2.isEmpty()) {
|
|
|
|
|
+ t2.stream().filter(f1->f1.index()==1).map(BackgroupImageItem::image).findFirst().ifPresent(t1::setImage);
|
|
|
|
|
+ }
|
|
|
|
|
+ return backgroupImageMono.then(Mono.just(t1));
|
|
|
|
|
+ });
|
|
|
|
|
+ }).collectList());
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Mono<RStatus<BackgroupImageSaveResNew>> add(BackgroupImageSaveReqNew dto) {
|
|
|
|
|
+ String groupTypeName = dto.getGroupTypeName();
|
|
|
|
|
+ String userName = BaseContextHandler.getUserName();
|
|
|
|
|
+ Mono<BackgroupImageSaveResNew> end = groupTypeRepository.findByName(groupTypeName).collectList()
|
|
|
|
|
+ .switchIfEmpty(Mono.just(List.of()))
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("查询GroupType Error::" + throwable.getMessage())))
|
|
|
|
|
+ .flatMap(list -> {
|
|
|
|
|
+ Mono<GroupType> groupTypeMono;
|
|
|
|
|
+ if (list.isEmpty()) {
|
|
|
|
|
+ groupTypeMono = saveMysqlAndRedisGroupType(new GroupType(null, groupTypeName, "1"));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ groupTypeMono = Mono.just(list.get(0));
|
|
|
|
|
+ }
|
|
|
|
|
+ return groupTypeMono;
|
|
|
|
|
+ }).flatMap(groupType -> {
|
|
|
|
|
+ BackgroupImage backgroupImage = new BackgroupImage(null,
|
|
|
|
|
+ dto.getName(),
|
|
|
|
|
+ userName,
|
|
|
|
|
+ ZonedDateTime.now(),
|
|
|
|
|
+ null,
|
|
|
|
|
+ null,
|
|
|
|
|
+ 1,
|
|
|
|
|
+ groupType.name(),
|
|
|
|
|
+ Integer.valueOf(String.valueOf(groupType.id())),null);
|
|
|
|
|
+ return saveMysqlAndRedisBackgroupImage(backgroupImage);
|
|
|
|
|
+ }).flatMap(backgroupImage -> {
|
|
|
|
|
+ List<ImageItem> images = dto.getImages();
|
|
|
|
|
+ if (images.isEmpty()) {
|
|
|
|
|
+ return Mono.error(new BaseException("图片素材不可为空"));
|
|
|
|
|
+ }
|
|
|
|
|
+ Mono<List<BackgroupImageItem>> then = Flux.fromIterable(images)
|
|
|
|
|
+ .flatMap(imageItem ->
|
|
|
|
|
+ saveMysqlAndRedisBackgroupItem(new BackgroupImageItem(null,
|
|
|
|
|
+ imageItem.getImage(),
|
|
|
|
|
+ imageItem.getIndex(),
|
|
|
|
|
+ backgroupImage.id()))
|
|
|
|
|
+ ).collectList().then(backgroupImageItemRepository
|
|
|
|
|
+ .findByGroupId(backgroupImage.id())
|
|
|
|
|
+ .flatMap(backgroupImageItem ->
|
|
|
|
|
+ backgroupImageItemInterface
|
|
|
|
|
+ .saveMysqlAndRedisBackgroupImageCache(backgroupImageItem))
|
|
|
|
|
+ .collectList());
|
|
|
|
|
+ return Mono.zip(then, Mono.just(backgroupImage)).flatMap(all -> {
|
|
|
|
|
+ BackgroupImageSaveResNew backgroupImageSaveResNew = new BackgroupImageSaveResNew();
|
|
|
|
|
+ backgroupImageSaveResNew.setId(all.getT2().id());
|
|
|
|
|
+ //主任务绑定子任务id 实现缓存cache 查询 此表是go服务设计 不能修改只能兼容
|
|
|
|
|
+ List<Long> collect = all.getT1().stream().map(BackgroupImageItem::id).collect(Collectors.toList());
|
|
|
|
|
+ Mono<BackgroupImage> backgroupImageMono;
|
|
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
|
|
+ String ids = JSONUtil.toJsonStr(collect);
|
|
|
|
|
+ backgroupImageMono = template.update(Query.query(Criteria.where("id")
|
|
|
|
|
+ .is(backgroupImageSaveResNew.getId())),
|
|
|
|
|
+ Update.update("item_ids", ids),
|
|
|
|
|
+ BackgroupImage.class)
|
|
|
|
|
+ .flatMap(id -> backgroupImageRepository
|
|
|
|
|
+ .findById(id)
|
|
|
|
|
+ .flatMap(backgroupImage1 ->
|
|
|
|
|
+ backgroupImageInterface
|
|
|
|
|
+ .saveMysqlAndRedisBackgroupImageCache(backgroupImage1)));
|
|
|
|
|
+ }else {
|
|
|
|
|
+ backgroupImageMono=Mono.just(all.getT2());
|
|
|
|
|
+ }
|
|
|
|
|
+ return backgroupImageMono.then(Mono.just(backgroupImageSaveResNew));
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ return RStatus.success(end);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public Mono<RStatus<BackgroupImageSaveResNew>> update(BackgroupImageSaveReqNew dto) {
|
|
|
|
|
+ if (Objects.isNull(dto.getId())) {
|
|
|
|
|
+ return Mono.error(new BaseException("id is null"));
|
|
|
|
|
+ }
|
|
|
|
|
+ String groupTypeName = dto.getGroupTypeName();
|
|
|
|
|
+ Mono<BackgroupImageSaveResNew> end = groupTypeRepository.findByName(groupTypeName).collectList()
|
|
|
|
|
+ .switchIfEmpty(Mono.just(List.of()))
|
|
|
|
|
+ .onErrorResume(throwable -> Mono.error(new BaseException("查询GroupType Error::" + throwable.getMessage())))
|
|
|
|
|
+ .flatMap(list -> {
|
|
|
|
|
+ Mono<GroupType> groupTypeMono;
|
|
|
|
|
+ if (list.isEmpty()) {
|
|
|
|
|
+ groupTypeMono = saveMysqlAndRedisGroupType(new GroupType(null, groupTypeName, "1"));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ groupTypeMono = Mono.just(list.get(0));
|
|
|
|
|
+ }
|
|
|
|
|
+ return groupTypeMono;
|
|
|
|
|
+ }).flatMap(groupType ->backgroupImageRepository.findById(dto.getId())
|
|
|
|
|
+ .switchIfEmpty(Mono.error(new BaseException("id 查询结果为空")))
|
|
|
|
|
+ .flatMap(backgroupImage -> {
|
|
|
|
|
+ BackgroupImage backgroupImagesave = new BackgroupImage(dto.getId(),
|
|
|
|
|
+ dto.getName(),
|
|
|
|
|
+ backgroupImage.createUser(),
|
|
|
|
|
+ backgroupImage.createdAt(),
|
|
|
|
|
+ ZonedDateTime.now(),
|
|
|
|
|
+ null,
|
|
|
|
|
+ 1,
|
|
|
|
|
+ groupType.name(),
|
|
|
|
|
+ Integer.valueOf(String.valueOf(groupType.id())),null);
|
|
|
|
|
+ return updateMysqlAndRedisBackgroupImage(backgroupImagesave);
|
|
|
|
|
+ }) ).flatMap(backgroupImage -> {
|
|
|
|
|
+ List<ImageItem> images = dto.getImages();
|
|
|
|
|
+ if (images.isEmpty()) {
|
|
|
|
|
+ return Mono.error(new BaseException("图片素材不可为空"));
|
|
|
|
|
+ }
|
|
|
|
|
+ Mono<List<BackgroupImageItem>> listMono1 = backgroupImageItemRepository
|
|
|
|
|
+ .findByGroupId(backgroupImage.id())
|
|
|
|
|
+ .flatMap(backgroupImageItem ->
|
|
|
|
|
+ backgroupImageItemRepository
|
|
|
|
|
+ .deleteById(backgroupImageItem.id())
|
|
|
|
|
+ .onErrorResume(throwable ->
|
|
|
|
|
+ Mono.error(new BaseException("删除item异常" + throwable.getMessage())))
|
|
|
|
|
+ .then(backgroupImageItemInterface
|
|
|
|
|
+ .deleteMysqlAndRedisBackgroupImageCache(backgroupImageItem)))
|
|
|
|
|
+ .collectList();
|
|
|
|
|
+ Mono<List<BackgroupImageItem>> then1 = Flux.fromIterable(images)
|
|
|
|
|
+ .flatMap(imageItem ->
|
|
|
|
|
+ saveMysqlAndRedisBackgroupItem(new BackgroupImageItem(null,
|
|
|
|
|
+ imageItem.getImage(),
|
|
|
|
|
+ imageItem.getIndex(),
|
|
|
|
|
+ backgroupImage.id()))).collectList().then(backgroupImageItemRepository
|
|
|
|
|
+ .findByGroupId(backgroupImage.id())
|
|
|
|
|
+ .flatMap(backgroupImageItem ->
|
|
|
|
|
+ backgroupImageItemInterface
|
|
|
|
|
+ .saveMysqlAndRedisBackgroupImageCache(backgroupImageItem))
|
|
|
|
|
+ .collectList());
|
|
|
|
|
+ Mono<List<BackgroupImageItem>> then = listMono1.then(then1);
|
|
|
|
|
+ return Mono.zip(then, Mono.just(backgroupImage)).flatMap(all -> {
|
|
|
|
|
+ BackgroupImageSaveResNew backgroupImageSaveResNew = new BackgroupImageSaveResNew();
|
|
|
|
|
+ backgroupImageSaveResNew.setId(all.getT2().id());
|
|
|
|
|
+ //主任务绑定子任务id 实现缓存cache 查询 此表是go服务设计 不能修改只能兼容
|
|
|
|
|
+ List<Long> collect = all.getT1().stream().map(BackgroupImageItem::id).collect(Collectors.toList());
|
|
|
|
|
+ Mono<BackgroupImage> backgroupImageMono;
|
|
|
|
|
+ if (!collect.isEmpty()) {
|
|
|
|
|
+ String ids = JSONUtil.toJsonStr(collect);
|
|
|
|
|
+ backgroupImageMono = template.update(Query.query(Criteria.where("id")
|
|
|
|
|
+ .is(backgroupImageSaveResNew.getId())),
|
|
|
|
|
+ Update.update("item_ids", ids),
|
|
|
|
|
+ BackgroupImage.class)
|
|
|
|
|
+ .flatMap(id -> backgroupImageRepository
|
|
|
|
|
+ .findById(id)
|
|
|
|
|
+ .flatMap(backgroupImage1 ->
|
|
|
|
|
+ backgroupImageInterface
|
|
|
|
|
+ .saveMysqlAndRedisBackgroupImageCache(backgroupImage1)));
|
|
|
|
|
+ }else {
|
|
|
|
|
+ backgroupImageMono=Mono.just(all.getT2());
|
|
|
|
|
+ }
|
|
|
|
|
+ return backgroupImageMono.then(Mono.just(backgroupImageSaveResNew));
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ return RStatus.success(end);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<BackgroupImagInfoeResNew>> info(BackgroupImageSaveResNew dto) {
|
|
|
|
|
+ Mono<BackgroupImage> backgroupImageMono = backgroupImageInterface.getRedisOrMysqlBackgroupImage(dto.getId());
|
|
|
|
|
+ Mono<BackgroupImagInfoeResNew> backgroupImagInfoeResNewMono = backgroupImageMono.flatMap(backgroupImage -> {
|
|
|
|
|
+ BackgroupImagInfoeResNew backgroupImagInfoeResNew = new BackgroupImagInfoeResNew();
|
|
|
|
|
+ backgroupImagInfoeResNew.setId(backgroupImage.id());
|
|
|
|
|
+ backgroupImagInfoeResNew.setCreateUser(backgroupImage.createUser());
|
|
|
|
|
+ backgroupImagInfoeResNew.setCreatedAt(backgroupImage.createdAt());
|
|
|
|
|
+ backgroupImagInfoeResNew.setGroupTypeName(backgroupImage.groupTypeName());
|
|
|
|
|
+ backgroupImagInfoeResNew.setUpdatedAt(backgroupImage.updatedAt());
|
|
|
|
|
+ backgroupImagInfoeResNew.setName(backgroupImage.name());
|
|
|
|
|
+ backgroupImagInfoeResNew.setItemId(backgroupImage.itemIds());
|
|
|
|
|
+ return Mono.just(backgroupImagInfoeResNew);
|
|
|
|
|
+ }).flatMap(res -> {
|
|
|
|
|
+ String itemId = res.getItemId();
|
|
|
|
|
+ if (Objects.nonNull(itemId)) {
|
|
|
|
|
+ List<Long> list = JSONUtil.parseArray(itemId).toList(Long.class);
|
|
|
|
|
+ return Flux.fromIterable(list).flatMap(id->
|
|
|
|
|
+ backgroupImageItemInterface
|
|
|
|
|
+ .getGroupImageItemMonoCache(id))
|
|
|
|
|
+ .collectList()
|
|
|
|
|
+ .flatMap(lists->{
|
|
|
|
|
+ if (lists.isEmpty()) {
|
|
|
|
|
+ return Mono.just(res);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<ImageItem> collect = lists.stream().map(item -> new ImageItem(item.image(), item.index())).collect(Collectors.toList());
|
|
|
|
|
+ res.setImages(collect);
|
|
|
|
|
+ return Mono.just(res);
|
|
|
|
|
+ });
|
|
|
|
|
+ }else {
|
|
|
|
|
+ return backgroupImageItemRepository.findByGroupId(res.getId())
|
|
|
|
|
+ .collectList()
|
|
|
|
|
+ .switchIfEmpty(Mono.just(List.of())).flatMap(list -> {
|
|
|
|
|
+ if (list.isEmpty()) {
|
|
|
|
|
+ return Mono.just(res);
|
|
|
|
|
+ }
|
|
|
|
|
+ List<ImageItem> collect = list.stream().map(item -> new ImageItem(item.image(), item.index())).collect(Collectors.toList());
|
|
|
|
|
+ res.setImages(collect);
|
|
|
|
|
+ return Mono.just(res);
|
|
|
|
|
+ });
|
|
|
|
|
+ }}
|
|
|
|
|
+ );
|
|
|
|
|
+ return RStatus.success(backgroupImagInfoeResNewMono);
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<BackgroupImageSaveResNew>> delete(BackgroupImageSaveResNew dto) {
|
|
|
|
|
+ Mono<BackgroupImage> backgroupImageMono = removeRedisAndMysqlBackgroupImage(dto.getId());
|
|
|
|
|
+ Mono<BackgroupImageSaveResNew> backgroupImageSaveResNewMono = backgroupImageMono.flatMap(f -> {
|
|
|
|
|
+ BackgroupImageSaveResNew backgroupImageSaveResNew =
|
|
|
|
|
+ new BackgroupImageSaveResNew();
|
|
|
|
|
+ backgroupImageSaveResNew.setId(f.id());
|
|
|
|
|
+ return Mono.just(backgroupImageSaveResNew);
|
|
|
|
|
+ });
|
|
|
|
|
+ return RStatus.success(backgroupImageSaveResNewMono);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //Todo BackgroupImage >>>>>>>>>>>>>>>>>
|
|
|
|
|
+
|
|
|
|
|
+ //Todo Image <<<<<<<<<<<<<<
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<ExcelDataRes> importExcel(Mono<FilePart> file) {
|
|
|
|
|
+ return file.flatMap(filePart -> {
|
|
|
|
|
+ String filename = filePart.filename();
|
|
|
|
|
+ Mono<ByteArrayInputStream> byteArrayInputStreamMono = uploadService.convertFilePartToByteArrayInputStream(filePart);
|
|
|
|
|
+ return byteArrayInputStreamMono.flatMap(in -> {
|
|
|
|
|
+ ArrayList<ImageExcelRedisCache> images = new ArrayList<>();
|
|
|
|
|
+ try (XSSFWorkbook workbook = new XSSFWorkbook(in)) {
|
|
|
|
|
+ // 处理 Excel 文件
|
|
|
|
|
+ workbook.forEach(sheet -> {
|
|
|
|
|
+ for (Row row : sheet) {
|
|
|
|
|
+ Iterator<Cell> cellIterator = row.cellIterator();
|
|
|
|
|
+ ArrayList<String> strings = new ArrayList<>();
|
|
|
|
|
+ while (cellIterator.hasNext()) {
|
|
|
|
|
+ Cell cell = cellIterator.next();
|
|
|
|
|
+ strings.add(Objects.isNull(cell.getStringCellValue()) ? "" : cell.getStringCellValue());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!strings.isEmpty()) {
|
|
|
|
|
+ if (Objects.nonNull(strings.get(0))
|
|
|
|
|
+ && !"图片链接".equals(strings.get(0))
|
|
|
|
|
+ && !"".equals(strings.get(0).trim())) {
|
|
|
|
|
+ Integer type = getImageType(strings);
|
|
|
|
|
+ ImageExcelRedisCache cache =new ImageExcelRedisCache();
|
|
|
|
|
+ cache.setImage(strings.get(0));
|
|
|
|
|
+ cache.setType(type);
|
|
|
|
|
+ cache.setGroupTypeName(strings.get(2));
|
|
|
|
|
+ cache.setSizeType( getImageSizeType(strings));
|
|
|
|
|
+ images.add(cache);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
|
+ throw new RuntimeException("文件处理失败", e);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!images.isEmpty()) {
|
|
|
|
|
+ long currentTimeMillis = System.currentTimeMillis();
|
|
|
|
|
+ String k = hashKey + currentTimeMillis;
|
|
|
|
|
+ String cacheJsonStr = JSONUtil.toJsonStr(images);
|
|
|
|
|
+ Mono<Boolean> listMono = reactiveRedisTemplate.opsForValue().set(k, cacheJsonStr, Duration.ofHours(10));
|
|
|
|
|
+ return Mono.zip(listMono, Mono.just(currentTimeMillis)).flatMap(f -> {
|
|
|
|
|
+ ExcelDataRes excelDataRes = new ExcelDataRes();
|
|
|
|
|
+ excelDataRes.setId(f.getT2());
|
|
|
|
|
+ excelDataRes.setName(filename);
|
|
|
|
|
+ return Mono.just(excelDataRes);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ return Mono.error(new BaseException("上传失败"));
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ private Integer getImageSizeType(ArrayList<String> strings) {
|
|
|
|
|
+ int type=1;
|
|
|
|
|
+ if(strings.size()>=4){
|
|
|
|
|
+ if ("单列".equals(strings.get(3))) {
|
|
|
|
|
+ type = 2;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return type;
|
|
|
|
|
+ }
|
|
|
|
|
+ private Integer getImageType(ArrayList<String> strings) {
|
|
|
|
|
+ int type=0;
|
|
|
|
|
+ if(strings.size()<2){
|
|
|
|
|
+ return type;
|
|
|
|
|
+ }
|
|
|
|
|
+ switch (strings.get(1)) {
|
|
|
|
|
+ case "群封面" -> type = 1;
|
|
|
|
|
+ case "海报背景图" -> type = 2;
|
|
|
|
|
+ case "分享背景图" -> type = 3;
|
|
|
|
|
+ case "中转动图" -> type = 4;
|
|
|
|
|
+ case "简介" -> type = 5;
|
|
|
|
|
+ case "微信头像" -> type = 6;
|
|
|
|
|
+ case "海报封面" -> type = 7;
|
|
|
|
|
+ case "加企微海报" -> type = 8;
|
|
|
|
|
+ case "分享封面" -> type = 9;
|
|
|
|
|
+ case "海报图片" -> type = 10;
|
|
|
|
|
+ case "外卖商品图" -> type = 11;
|
|
|
|
|
+ case "企微群码" -> type = 12;
|
|
|
|
|
+ case "假视频封面" -> type = 13;
|
|
|
|
|
+ }
|
|
|
|
|
+ return type;
|
|
|
|
|
+ }
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<String> importDataExcel(ImageSaveRes data) {
|
|
|
|
|
+ Long id = data.getId();
|
|
|
|
|
+ String userName = BaseContextHandler.getUserName();
|
|
|
|
|
+ Mono<String> objectMono = reactiveRedisImageTemplate.opsForValue().get(hashKey + id).flatMap(f->{
|
|
|
|
|
+ if(Objects.nonNull(f)){
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return Mono.just(f.toString());
|
|
|
|
|
+
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+// reactiveRedisImageTemplate.opsForHash().scan(hashKey+id).(entry->{
|
|
|
|
|
+//
|
|
|
|
|
+//
|
|
|
|
|
+// })
|
|
|
|
|
+ return objectMono;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //Todo Image >>>>>>>>>>>>>>>>>
|
|
|
|
|
+ //Todo 相册 Album <<<<<<<<<<<<<<
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private AlbumInterface albumInterface;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private AlbumRepository albumRepository;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private AlbumItemInterface albumItemInterface;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private AlbumItemRepository albumItemRepository;
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public Mono<RStatus<Paged<Album>>> pageAlbum(AlbumDto albumDto) {
|
|
|
|
|
+
|
|
|
|
|
+ ArrayList<Where> wheres = new ArrayList<>();
|
|
|
|
|
+ if(StrUtil.isNotBlank(albumDto.getUserName())){
|
|
|
|
|
+ Where where = new Where();
|
|
|
|
|
+ where.setKey("user_name");
|
|
|
|
|
+ where.setWhereType(2);
|
|
|
|
|
+ where.setValue(albumDto.getUserName());
|
|
|
|
|
+ wheres.add(where);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(Objects.nonNull(albumDto.getGroupId())){
|
|
|
|
|
+ Where where = new Where();
|
|
|
|
|
+ where.setKey("group_id");
|
|
|
|
|
+ where.setWhereType(1);
|
|
|
|
|
+ where.setValue(albumDto.getGroupId());
|
|
|
|
|
+ wheres.add(where);
|
|
|
|
|
+ }
|
|
|
|
|
+ Mono<RStatus<Paged<Album>>> page = sourceMaterialInterface.page(wheres, Album.class, albumDto.getSize(), albumDto.getPage());
|
|
|
|
|
+ return page;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public Mono<RStatus<Boolean>> addOrUpdate(AlbumReq albumReq) {
|
|
|
|
|
+ List<AlbumItemReq> list = albumReq.getList();
|
|
|
|
|
+ return Objects.isNull(albumReq.getAlbumId())?
|
|
|
|
|
+ addAlbum(albumReq,BaseContextHandler.getUserName(),BaseContextHandler.getUserId(),list)
|
|
|
|
|
+ :updateAlbum(albumReq, list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
- public Mono<RStatus<Paged<BackgroupImageRes>>> pageBackgroup(Integer page, Integer size) {
|
|
|
|
|
- sourceMaterialInterface.pageAndFunctionRtE(List.of(),BackgroupImage.class,size,page,(f)->{
|
|
|
|
|
- return f.stream().map(fe->{
|
|
|
|
|
- String string = sourceMaterialInterface.tToString(fe);
|
|
|
|
|
- BackgroupImageRes backgroupImageRes1 = sourceMaterialInterface.strParseT(string, BackgroupImageRes.class);
|
|
|
|
|
- BackgroupImageRes backgroupImageRes = new BackgroupImageRes();
|
|
|
|
|
- return backgroupImageRes;
|
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
|
|
|
+ public Mono<RStatus<AlbumReq>> infoAlbum(Long id) {
|
|
|
|
|
+ Mono<AlbumReq> albumReqMono = albumInterface.getRedisOrMysql(id).flatMap(album -> {
|
|
|
|
|
+ AlbumReq albumReq = new AlbumReq();
|
|
|
|
|
+ albumReq.setAlbumId(album.albumId());
|
|
|
|
|
+ albumReq.setGroupId(album.groupId());
|
|
|
|
|
+ albumReq.setHeadUrl(album.headUrl());
|
|
|
|
|
+ albumReq.setGroupId(album.groupId());
|
|
|
|
|
+ albumReq.setUserName(album.groupName());
|
|
|
|
|
+ String s = album.imageListId();
|
|
|
|
|
+ Mono<List<AlbumItemReq>> listMono = Mono.just(List.of());
|
|
|
|
|
+ if (StringUtils.isNotEmpty(s)) {
|
|
|
|
|
+ List<Long> list1 = JSONUtil.parseArray(s).toList(Long.class);
|
|
|
|
|
+ listMono = Flux.fromIterable(list1).flatMap(itemid -> {
|
|
|
|
|
+ return albumItemInterface.getRedisOrMysql(itemid);
|
|
|
|
|
+ }).flatMap(item -> {
|
|
|
|
|
+ AlbumItemReq albumItemReq = new AlbumItemReq();
|
|
|
|
|
+ albumItemReq.setId(item.id());
|
|
|
|
|
+ albumItemReq.setUrl(item.url());
|
|
|
|
|
+ albumItemReq.setStatus(item.status());
|
|
|
|
|
+ return Mono.just(albumItemReq);
|
|
|
|
|
+ }).collectList();
|
|
|
|
|
+ }
|
|
|
|
|
+ return Mono.zip(listMono, Mono.just(albumReq)).flatMap(tuple -> {
|
|
|
|
|
+ List<AlbumItemReq> t1 =
|
|
|
|
|
+ tuple.getT1().stream()
|
|
|
|
|
+ .sorted(Comparator.comparing(AlbumItemReq::getStatus))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ AlbumReq t2 = tuple.getT2();
|
|
|
|
|
+ t2.setList(t1);
|
|
|
|
|
+ return Mono.just(t2);
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
|
|
+ return RStatus.success(albumReqMono);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return null;
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public Mono<RStatus<Boolean>> deleteAlbum(Long id) {
|
|
|
|
|
+ Mono<Boolean> booleanMono = albumInterface.getRedisOrMysql(id).flatMap(album -> {
|
|
|
|
|
+ Mono<Boolean> then = Mono.just(true);
|
|
|
|
|
+ if (StringUtils.isNotEmpty(album.imageListId())) {
|
|
|
|
|
+ List<Long> list1 = JSONUtil.parseArray(album.imageListId()).toList(Long.class);
|
|
|
|
|
+ then = Flux.fromIterable(list1).flatMap(item -> {
|
|
|
|
|
+ return albumItemInterface.deleteMysqlAndRedisCache(item);
|
|
|
|
|
+ }).then(Mono.just(true));
|
|
|
|
|
+ }
|
|
|
|
|
+ return then.then(albumInterface.deleteMysqlAndRedisCache(album.albumId())).then(Mono.just(true));
|
|
|
|
|
+ });
|
|
|
|
|
+ return RStatus.success(booleanMono);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private Mono<RStatus<Boolean>> addAlbum(AlbumReq albumReq, String userName, String userId, List<AlbumItemReq> list) {
|
|
|
|
|
+
|
|
|
|
|
+ Mono<Boolean> then = Flux.fromIterable(list).flatMap(item -> {
|
|
|
|
|
+ return albumItemInterface.saveMysqlAndRedisCache(new AlbumItem(null, item.getUrl(), item.getStatus()));
|
|
|
|
|
+ }).collectList().switchIfEmpty(Mono.just(List.of()))
|
|
|
|
|
+ .flatMap(items -> {
|
|
|
|
|
+ Album album = new Album(albumReq.getAlbumId(),
|
|
|
|
|
+ albumReq.getHeadUrl(),
|
|
|
|
|
+ albumReq.getGroupId(),
|
|
|
|
|
+ albumReq.getGroupName(),
|
|
|
|
|
+ items.size(),
|
|
|
|
|
+ userName,
|
|
|
|
|
+ userId,
|
|
|
|
|
+ ZonedDateTime.now(),
|
|
|
|
|
+ null,
|
|
|
|
|
+ null,
|
|
|
|
|
+ JSONUtil.toJsonStr(items.stream().map(AlbumItem::id).collect(Collectors.toList())),
|
|
|
|
|
+ albumReq.getUserName()
|
|
|
|
|
+ );
|
|
|
|
|
+ return albumInterface.saveMysqlAndRedisCache(album);
|
|
|
|
|
+ }).then(Mono.just(true));
|
|
|
|
|
+ return RStatus.success(then);
|
|
|
|
|
+ }
|
|
|
|
|
+ private Mono<RStatus<Boolean>> updateAlbum(AlbumReq albumReq, List<AlbumItemReq> list) {
|
|
|
|
|
+ Mono<Boolean> booleanMono = albumInterface.getRedisOrMysql(albumReq.getAlbumId()).flatMap(album -> {
|
|
|
|
|
+ String s = album.imageListId();
|
|
|
|
|
+ Mono<Boolean> then = Mono.just(true);
|
|
|
|
|
+ if (StringUtils.isNotEmpty(s)) {
|
|
|
|
|
+ List<Long> list1 = JSONUtil.parseArray(s).toList(Long.class);
|
|
|
|
|
+ then = Flux.fromIterable(list1).flatMap(id -> {
|
|
|
|
|
+ return albumItemInterface.deleteMysqlAndRedisCache(id);
|
|
|
|
|
+ }).then(Mono.just(true));
|
|
|
|
|
+ }
|
|
|
|
|
+ return then.then(Flux.fromIterable(list).flatMap(item -> {
|
|
|
|
|
+ return albumItemInterface.saveMysqlAndRedisCache(new AlbumItem(null, item.getUrl(), item.getStatus()));
|
|
|
|
|
+ }).collectList().switchIfEmpty(Mono.just(List.of()))
|
|
|
|
|
+ .flatMap(items -> {
|
|
|
|
|
+ Album albumNew = new Album(albumReq.getAlbumId(),
|
|
|
|
|
+ albumReq.getHeadUrl(),
|
|
|
|
|
+ albumReq.getGroupId(),
|
|
|
|
|
+ albumReq.getGroupName(),
|
|
|
|
|
+ items.size(),
|
|
|
|
|
+ album.createUser(),
|
|
|
|
|
+ album.createId(),
|
|
|
|
|
+ null,
|
|
|
|
|
+ ZonedDateTime.now(),
|
|
|
|
|
+ null,
|
|
|
|
|
+ JSONUtil.toJsonStr(items.stream().map(AlbumItem::id).collect(Collectors.toList())),
|
|
|
|
|
+ albumReq.getUserName()
|
|
|
|
|
+ );
|
|
|
|
|
+ return albumInterface.saveMysqlAndRedisCache(albumNew);
|
|
|
|
|
+ }).then(Mono.just(true)));
|
|
|
|
|
+ });
|
|
|
|
|
+ return RStatus.success(booleanMono);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //Todo 相册 Album >>>>>>>>>>>>>>>>
|
|
|
}
|
|
}
|