fix(content): 短剧保存时始终同步分集价格
This commit is contained in:
1 parent
8bb7f63c62
commit
9adf8c5630
4 files changed
+52
-15
No files matched your search
+1
-15
@@ -30,7 +30,6 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
@@ -111,8 +110,6 @@ public class DramaService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(Long id, DramaSaveReqVO req) {
|
||||
Drama drama = getExisting(id);
|
||||
Integer oldFreeEpisodes = drama.getFreeEpisodes();
|
||||
Integer oldUnlockCoin = drama.getUnlockCoin();
|
||||
apply(drama, req, false);
|
||||
if (req.getFavoriteCount() != null) {
|
||||
drama.setFavoriteCount(nonNegative(req.getFavoriteCount(), "收藏数"));
|
||||
@@ -124,18 +121,7 @@ public class DramaService {
|
||||
drama.setViewCount(nonNegative(req.getHeat(), "热度"));
|
||||
}
|
||||
dramaMapper.updateById(drama);
|
||||
syncEpisodePricesIfNeeded(drama, oldFreeEpisodes, oldUnlockCoin);
|
||||
}
|
||||
|
||||
/** 免费集数或解锁金币变化时,按定价规则回写分集。 */
|
||||
private void syncEpisodePricesIfNeeded(Drama drama, Integer oldFreeEpisodes, Integer oldUnlockCoin) {
|
||||
if (Objects.equals(oldFreeEpisodes, drama.getFreeEpisodes())
|
||||
&& Objects.equals(oldUnlockCoin, drama.getUnlockCoin())) {
|
||||
return;
|
||||
}
|
||||
int freeEpisodes = drama.getFreeEpisodes() == null ? 0 : Math.max(0, drama.getFreeEpisodes());
|
||||
int unlockCoin = drama.getUnlockCoin() == null ? 0 : Math.max(0, drama.getUnlockCoin());
|
||||
episodePriceSync.syncByDramaRule(drama.getId(), freeEpisodes, unlockCoin);
|
||||
episodePriceSync.syncByDramaRule(drama);
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
|
||||
+12
@@ -3,6 +3,7 @@
|
||||
package com.fruitshorts.content.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.fruitshorts.content.dal.entity.Drama;
|
||||
import com.fruitshorts.content.dal.entity.DramaEpisode;
|
||||
import com.fruitshorts.content.dal.mapper.DramaEpisodeMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -22,6 +23,17 @@ public class EpisodePriceSync {
|
||||
|
||||
private final DramaEpisodeMapper dramaEpisodeMapper;
|
||||
|
||||
/**
|
||||
* 按短剧当前免费集数与解锁金币同步全部分集。
|
||||
*
|
||||
* @return 实际写库的分集数
|
||||
*/
|
||||
public int syncByDramaRule(Drama drama) {
|
||||
int freeEpisodes = drama.getFreeEpisodes() == null ? 0 : Math.max(0, drama.getFreeEpisodes());
|
||||
int unlockCoin = drama.getUnlockCoin() == null ? 0 : Math.max(0, drama.getUnlockCoin());
|
||||
return syncByDramaRule(drama.getId(), freeEpisodes, unlockCoin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 全量同步某剧全部分集价格。
|
||||
*
|
||||
|
||||
Reference in new issue
Block a user