diff --git a/BUILD.MD b/BUILD.MD index f499e9896..2eac27cf2 100644 --- a/BUILD.MD +++ b/BUILD.MD @@ -72,12 +72,20 @@ commit之前,用checkstyle检查下代码,确认没有问题后再commit。 => `Scheme` 选择 `Project` 选择右边设置,导入checkstyle文件 +(如没有该项,则需要先安装checkstyle-idea插件) 最后OK保存 ## 本地开发 在`IkarosApplication`的运行配置里,将`Active profiles` 配置成:`dev,win,debug` +### Console编译 +需要先运行任务进行Console的前端文件编译: + +```text +./gradlew buildFrontend -x test +``` + ## IDEA格式化配置 1. 打开 `Setting` => `Editor` => `Code Style` => `Java` diff --git a/CHANGELOG.MD b/CHANGELOG.MD index 736c2998f..ae55f0551 100644 --- a/CHANGELOG.MD +++ b/CHANGELOG.MD @@ -20,6 +20,7 @@ - 启动console,找不到`@runikaros/api-client`和`@runikaros/shared` [#527](https://github.com/ikaros-dev/ikaros/issues/527) +- 修复附件移动时,子附件的`path`属性没有及时更新的问题 # 0.11.7 diff --git a/server/src/main/java/run/ikaros/server/core/attachment/service/impl/AttachmentServiceImpl.java b/server/src/main/java/run/ikaros/server/core/attachment/service/impl/AttachmentServiceImpl.java index 89d4d0589..66fd216e4 100644 --- a/server/src/main/java/run/ikaros/server/core/attachment/service/impl/AttachmentServiceImpl.java +++ b/server/src/main/java/run/ikaros/server/core/attachment/service/impl/AttachmentServiceImpl.java @@ -65,6 +65,7 @@ public class AttachmentServiceImpl implements AttachmentService { private final R2dbcEntityTemplate template; private final IkarosProperties ikarosProperties; private final ApplicationEventPublisher applicationEventPublisher; + private final AttachmentRepository attachmentRepository; /** * Construct. @@ -72,12 +73,14 @@ public class AttachmentServiceImpl implements AttachmentService { public AttachmentServiceImpl(AttachmentRepository repository, AttachmentReferenceRepository referenceRepository, R2dbcEntityTemplate template, IkarosProperties ikarosProperties, - ApplicationEventPublisher applicationEventPublisher) { + ApplicationEventPublisher applicationEventPublisher, + AttachmentRepository attachmentRepository) { this.repository = repository; this.referenceRepository = referenceRepository; this.template = template; this.ikarosProperties = ikarosProperties; this.applicationEventPublisher = applicationEventPublisher; + this.attachmentRepository = attachmentRepository; } @Override @@ -94,16 +97,32 @@ public Mono save(Attachment attachment) { Assert.notNull(attachment, "'attachment' must not be null."); attachment.setParentId(Optional.ofNullable(attachment.getParentId()) .orElse(AttachmentConst.ROOT_DIRECTORY_ID)); + final Long newParentId = attachment.getParentId(); Mono attachmentEntityMono = Objects.isNull(attachment.getId()) ? copyProperties(attachment, new AttachmentEntity()) : repository.findById(attachment.getId()) - .flatMap(attachmentEntity -> copyProperties(attachment, attachmentEntity)); + .flatMap(attachmentEntity -> + copyProperties(attachment, attachmentEntity, "parentId")); + return attachmentEntityMono + .flatMap(attachmentEntity -> updatePathWhenNewParentId(attachmentEntity, newParentId)) .flatMap(this::saveEntity) .flatMap(attachmentEntity -> copyProperties(attachmentEntity, attachment)); } + private Mono updatePathWhenNewParentId(AttachmentEntity attachmentEntity, + Long newParentId) { + if (Objects.equals(newParentId, attachmentEntity.getParentId())) { + return Mono.just(attachmentEntity); + } + + String name = attachmentEntity.getName(); + return findPathByParentId(newParentId, name) + .map(attachmentEntity::setPath) + .map(attEntity -> attEntity.setParentId(newParentId)); + } + @Override public Mono> listEntitiesByCondition( AttachmentSearchCondition searchCondition) { @@ -148,7 +167,13 @@ public Mono> listEntitiesByCondition( template.select(query, AttachmentEntity.class); Mono countMono = template.count(query, AttachmentEntity.class); - return countMono.flatMap(total -> attachmentEntityFlux.collectList() + return countMono.flatMap(total -> attachmentEntityFlux + .flatMap(attEntity -> findPathByParentId(attEntity.getParentId(), attEntity.getName()) + .filter(newPath -> !newPath.equals(attEntity.getPath())) + .map(attEntity::setPath) + .flatMap(attachmentRepository::save) + .switchIfEmpty(Mono.just(attEntity))) + .collectList() .map(attachmentEntities -> new PagingWrap<>(page, size, total, attachmentEntities))); }