Skip to content

Commit

Permalink
optimize: 标签创建 (#709)
Browse files Browse the repository at this point in the history
  • Loading branch information
chivehao authored Oct 19, 2024
1 parent ffb000a commit 5b1f3c7
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 23 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

更新日志文档,版本顺序从新到旧,最新版本在最前(上)面。

# 0.17.5

## 优化

- 优化标签创建逻辑
- 其它的一些简单优化

# 0.17.4

## 新特性
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=0.17.4
version=0.17.5
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.stereotype.Component;
import org.thymeleaf.context.Context;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Schedulers;
import run.ikaros.api.infra.properties.IkarosProperties;
import run.ikaros.api.infra.utils.StringUtils;
import run.ikaros.server.core.attachment.event.EpisodeAttachmentUpdateEvent;
Expand All @@ -18,7 +19,7 @@

@Slf4j
@Component
public class EpisodeUpdateListener {
public class EpisodeAttachmentUpdateEventListener {
private final AttachmentRepository attachmentRepository;
private final EpisodeRepository episodeRepository;
private final SubjectRepository subjectRepository;
Expand All @@ -30,10 +31,11 @@ public class EpisodeUpdateListener {
/**
* Construct.
*/
public EpisodeUpdateListener(AttachmentRepository attachmentRepository,
EpisodeRepository episodeRepository,
SubjectRepository subjectRepository,
NotifyService notifyService, IkarosProperties ikarosProperties) {
public EpisodeAttachmentUpdateEventListener(AttachmentRepository attachmentRepository,
EpisodeRepository episodeRepository,
SubjectRepository subjectRepository,
NotifyService notifyService,
IkarosProperties ikarosProperties) {
this.attachmentRepository = attachmentRepository;
this.episodeRepository = episodeRepository;
this.subjectRepository = subjectRepository;
Expand All @@ -46,12 +48,14 @@ public EpisodeUpdateListener(AttachmentRepository attachmentRepository,
*/
@EventListener(EpisodeAttachmentUpdateEvent.class)
public Mono<Void> onEpisodeAttachmentUpdateEvent(EpisodeAttachmentUpdateEvent event) {
log.debug("receive episode attachment update event: {}", event);
if (!event.getNotify()) {
return Mono.empty();
}
final Long attachmentId = event.getAttachmentId();
final Long episodeId = event.getEpisodeId();
return Mono.just(new Context())
.subscribeOn(Schedulers.boundedElastic())
.flatMap(context -> attachmentRepository.findById(attachmentId)
.map(entity -> {
context.setVariable("attachment", entity);
Expand Down Expand Up @@ -109,17 +113,17 @@ public Mono<Void> onEpisodeAttachmentUpdateEvent(EpisodeAttachmentUpdateEvent ev
return Mono.empty();
}

StringBuilder sb = new StringBuilder("番剧《");
sb.append(StringUtils.isBlank(subjectEntity.getNameCn())
? subjectEntity.getName() : subjectEntity.getNameCn())
.append("》第")
.append(episodeEntity.getSequence())
.append("集 [")
.append(StringUtils.isBlank(episodeEntity.getNameCn())
? episodeEntity.getName() : episodeEntity.getNameCn())
.append("] 更新了");
String sb = "番剧《"
+ (StringUtils.isBlank(subjectEntity.getNameCn())
? subjectEntity.getName() : subjectEntity.getNameCn())
+ "》第"
+ episodeEntity.getSequence()
+ "集 ["
+ (StringUtils.isBlank(episodeEntity.getNameCn())
? episodeEntity.getName() : episodeEntity.getNameCn())
+ "] 更新了";

return notifyService.send(sb.toString(), "mail/anime_update", context);
return notifyService.send(sb, "mail/anime_update", context);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ public Mono<Tag> create(Tag tag) {
Assert.notNull(tag.getType(), "'type' must not null.");
Assert.isTrue(tag.getMasterId() >= 0, "'masterId' must >=0.");
Assert.hasText(tag.getName(), "'name' must has text.");
return Mono.just(tag)
.flatMap(t -> copyProperties(t, new TagEntity()))
if (Objects.isNull(tag.getUserId())) {
tag.setUserId(-1L);
}
return tagRepository.existsByTypeAndMasterIdAndName(
tag.getType(), tag.getMasterId(), tag.getName())
.filter(exists -> !exists)
.flatMap(exists -> copyProperties(tag, new TagEntity()))
.flatMap(tagRepository::save)
.flatMap(tagEntity -> copyProperties(tagEntity, tag));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package run.ikaros.server.store.repository;

import org.springframework.data.r2dbc.repository.R2dbcRepository;
import reactor.core.publisher.Mono;
import run.ikaros.api.store.enums.TagType;
import run.ikaros.server.store.entity.TagEntity;

public interface TagRepository
extends R2dbcRepository<TagEntity, Long> {

Mono<Boolean> existsByTypeAndMasterIdAndName(TagType type, Long masterId, String name);
}
9 changes: 4 additions & 5 deletions server/src/main/resources/templates/temp/app-link-to.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
</head>
<body>
<div style="background: #fff;">
<div style="width:100%;max-width:720px;text-align: left;margin: 0 auto;padding-top: 20px;padding-bottom: 80px">
<div style="width:100%;text-align: left;margin: 0 auto;padding-top: 20px;padding-bottom: 80px">
<div style="border-radius: 5px;border:1px solid #eee;overflow: hidden;">
<h1 style="color:#fff;background: #3798e8;font-size:24px;font-weight:normal;padding-left:40px;margin:0">
番剧: 《<strong th:text="${subjectName}"></strong>
</h1>
<div style="background:#fff;padding:20px 32px 40px;">
<strong>前往app观看:</strong>
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">点击&nbsp;<a th:href="${subjectUrl}">跳转到app条目页面</a></p>

<!-- <p style="color: #6e6e6e;font-size:13px;line-height:24px;">放送进度:<span th:text="${updateEpsCount}"></span>/<span th:text="${allEpsCount}"></span></p>-->
<h2>番剧简介:</h2>
<p th:text="${subject.summary}" style="color: #6e6e6e;font-size:13px;line-height:24px;padding:10px 20px;background:#f8f8f8;margin:0">
</p>
Expand All @@ -24,6 +20,9 @@ <h2>封面:</h2>
<div align="center">
<img style="border-radius:5px;width: 100%;" th:src="${subjectCover}" alt="URL无法访问"></img>
</div>

<strong>前往app观看:</strong>
<p style="color: #6e6e6e;font-size:13px;line-height:24px;">点击&nbsp;<a th:href="${subjectUrl}">跳转到app条目页面</a></p>
</div>
</div>
</div>
Expand Down

0 comments on commit 5b1f3c7

Please sign in to comment.