fix(content): 短剧编辑未传字段不再覆盖存量数据
This commit is contained in:
1 parent
652ef050ee
commit
c9b8ec6805
1 file changed
+44
-15
+44
-15
@@ -92,7 +92,7 @@ public class DramaService {
|
||||
|
||||
private Long insert(DramaSaveReqVO req, Long operatorId, Long creatorId) {
|
||||
Drama drama = new Drama();
|
||||
apply(drama, req);
|
||||
apply(drama, req, true);
|
||||
drama.setCode(generateCode());
|
||||
drama.setStatus(ContentStatus.DRAFT.getCode());
|
||||
drama.setCreatorId(creatorId == null ? 0L : creatorId);
|
||||
@@ -109,7 +109,7 @@ public class DramaService {
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void update(Long id, DramaSaveReqVO req) {
|
||||
Drama drama = getExisting(id);
|
||||
apply(drama, req);
|
||||
apply(drama, req, false);
|
||||
if (req.getFavoriteCount() != null) {
|
||||
drama.setFavoriteCount(nonNegative(req.getFavoriteCount(), "收藏数"));
|
||||
}
|
||||
@@ -345,21 +345,50 @@ public class DramaService {
|
||||
}
|
||||
}
|
||||
|
||||
private void apply(Drama drama, DramaSaveReqVO req) {
|
||||
/**
|
||||
* 字段映射。新建时(isNew=true)缺省字段按默认值补齐;
|
||||
* 更新时只覆盖请求里显式传入的字段,漏传的字段保持库里原值,
|
||||
* 避免编辑表单没带 sort / language / trailerUrl 时把已有数据清掉。
|
||||
*/
|
||||
private void apply(Drama drama, DramaSaveReqVO req, boolean isNew) {
|
||||
drama.setTitle(req.getTitle());
|
||||
drama.setSubtitle(req.getSubtitle() == null ? "" : req.getSubtitle());
|
||||
DramaMultiTagSupport.applyCategoryIds(drama, req);
|
||||
drama.setGenre(req.getGenre() == null ? "" : req.getGenre());
|
||||
drama.setSynopsis(req.getDescription() == null ? "" : req.getDescription());
|
||||
drama.setCoverUrl(req.getCover() == null ? "" : req.getCover());
|
||||
drama.setTrailerUrl(req.getTrailerUrl() == null ? "" : req.getTrailerUrl());
|
||||
if (isNew || req.getSubtitle() != null) {
|
||||
drama.setSubtitle(req.getSubtitle() == null ? "" : req.getSubtitle());
|
||||
}
|
||||
if (isNew || req.getCategoryIds() != null || req.getCategoryId() != null) {
|
||||
DramaMultiTagSupport.applyCategoryIds(drama, req);
|
||||
}
|
||||
if (isNew || req.getGenre() != null) {
|
||||
drama.setGenre(req.getGenre() == null ? "" : req.getGenre());
|
||||
}
|
||||
if (isNew || req.getDescription() != null) {
|
||||
drama.setSynopsis(req.getDescription() == null ? "" : req.getDescription());
|
||||
}
|
||||
if (isNew || req.getCover() != null) {
|
||||
drama.setCoverUrl(req.getCover() == null ? "" : req.getCover());
|
||||
}
|
||||
if (isNew || req.getTrailerUrl() != null) {
|
||||
drama.setTrailerUrl(req.getTrailerUrl() == null ? "" : req.getTrailerUrl());
|
||||
}
|
||||
drama.setHorizontalCoverUrl(drama.getHorizontalCoverUrl() == null ? "" : drama.getHorizontalCoverUrl());
|
||||
drama.setLanguage(req.getLanguage() == null ? "zh-CN" : req.getLanguage());
|
||||
DramaMultiTagSupport.applyDramaTypes(drama, req);
|
||||
drama.setFreeEpisodes(req.getFreeEpisodes() == null ? 3 : req.getFreeEpisodes());
|
||||
drama.setUnlockCoin(req.getUnlockCoin() == null ? 0 : req.getUnlockCoin());
|
||||
drama.setIsHot(Boolean.TRUE.equals(req.getIsHot()) ? 1 : 0);
|
||||
drama.setSort(req.getSort() == null ? 0 : req.getSort());
|
||||
if (isNew || req.getLanguage() != null) {
|
||||
drama.setLanguage(req.getLanguage() == null ? "zh-CN" : req.getLanguage());
|
||||
}
|
||||
if (isNew || req.getDramaTypes() != null || req.getDramaType() != null) {
|
||||
DramaMultiTagSupport.applyDramaTypes(drama, req);
|
||||
}
|
||||
if (isNew || req.getFreeEpisodes() != null) {
|
||||
drama.setFreeEpisodes(req.getFreeEpisodes() == null ? 3 : req.getFreeEpisodes());
|
||||
}
|
||||
if (isNew || req.getUnlockCoin() != null) {
|
||||
drama.setUnlockCoin(req.getUnlockCoin() == null ? 0 : req.getUnlockCoin());
|
||||
}
|
||||
if (isNew || req.getIsHot() != null) {
|
||||
drama.setIsHot(Boolean.TRUE.equals(req.getIsHot()) ? 1 : 0);
|
||||
}
|
||||
if (isNew || req.getSort() != null) {
|
||||
drama.setSort(req.getSort() == null ? 0 : req.getSort());
|
||||
}
|
||||
}
|
||||
|
||||
private String generateCode() {
|
||||
|
||||
Reference in new issue
Block a user