feat: 标签

desc: 标签保存缩略图功能
main
zhangjiabao 9 months ago
parent fada0cdc3c
commit 07293b765f

@ -63,6 +63,11 @@ public class Tag implements Serializable {
*/ */
private String image; private String image;
/**
*
*/
private String thumbnail;
/** /**
* ID * ID
*/ */

@ -30,4 +30,7 @@ public class TagCreateReq implements Serializable {
@ApiModelProperty(value = "图片路径") @ApiModelProperty(value = "图片路径")
private String image; private String image;
@ApiModelProperty(value = "缩略图路径")
private String thumbnail;
} }

@ -37,6 +37,9 @@ public class TagDTO implements Serializable {
@ApiModelProperty(value = "图片") @ApiModelProperty(value = "图片")
private String image; private String image;
@ApiModelProperty(value = "缩略图")
private String thumbnail;
@ApiModelProperty(value = "子标签数量") @ApiModelProperty(value = "子标签数量")
private Long childTagCount = 0L; private Long childTagCount = 0L;

@ -37,4 +37,7 @@ public class TagUpdateReq implements Serializable {
@ApiModelProperty(value = "图片路径") @ApiModelProperty(value = "图片路径")
private String image; private String image;
@ApiModelProperty(value = "缩略图路径")
private String thumbnail;
} }

@ -70,7 +70,8 @@ public class TagService {
tagDTO.setChildTagCount(tagStatistic.getChildTagCount()); tagDTO.setChildTagCount(tagStatistic.getChildTagCount());
tagDTO.setJournalRefCount(tagStatistic.getJournalRefCount()); tagDTO.setJournalRefCount(tagStatistic.getJournalRefCount());
tagDTO.setSongRefCount(tagStatistic.getSongRefCount()); tagDTO.setSongRefCount(tagStatistic.getSongRefCount());
tagDTO.setImage(TagS3Service.TAG_RESOURCE_PREFIX + TagS3Service.TAG_KEY_PREFIX + tag.getImage()); tagDTO.setImage(null == tag.getImage() ? null : TagS3Service.TAG_RESOURCE_PREFIX + TagS3Service.TAG_KEY_PREFIX + tag.getImage());
tagDTO.setThumbnail(null == tag.getThumbnail() ? null : TagS3Service.TAG_RESOURCE_PREFIX + TagS3Service.TAG_KEY_PREFIX + tag.getThumbnail());
Tag parentTag = parentTagMap.get(tagDTO.getParentId()); Tag parentTag = parentTagMap.get(tagDTO.getParentId());
if (Objects.nonNull(parentTag)) { if (Objects.nonNull(parentTag)) {
tagDTO.setParentNameCh(parentTag.getNameCh()); tagDTO.setParentNameCh(parentTag.getNameCh());
@ -117,6 +118,16 @@ public class TagService {
tag.setImage(image); tag.setImage(image);
} }
if (null != createReq.getThumbnail() && !createReq.getThumbnail().isEmpty()) {
String thumbnail = tagS3Service.moveTagImageFromTempDir(
createReq.getThumbnail(), tag.getId()
);
if (null == thumbnail) {
Result.failed("缩略图更新失败");
}
tag.setThumbnail(thumbnail);
}
// //
// UserInfo userInfo = RequestContext.get(); // UserInfo userInfo = RequestContext.get();
// tag.setCreatorId(userInfo.getId()); // tag.setCreatorId(userInfo.getId());
@ -167,6 +178,19 @@ public class TagService {
} }
} }
if (null == updateReq.getThumbnail()) {
tag.setThumbnail(null);
} else {
if (updateReq.getThumbnail().contains(TagS3Service.TEMP_KEY_PREFIX)) {
srcKey = updateReq.getThumbnail().substring(updateReq.getThumbnail().indexOf(TagS3Service.TEMP_KEY_PREFIX));
}
if (StringUtils.isNotBlank(srcKey)) {
tag.setThumbnail(
tagS3Service.moveTagImageFromTempDir(updateReq.getThumbnail(), id)
);
}
}
tagDao.save(tag); tagDao.save(tag);
} }
@ -183,6 +207,8 @@ public class TagService {
Tag tag = tagOptional.get(); Tag tag = tagOptional.get();
TagDTO tagDTO = new TagDTO(); TagDTO tagDTO = new TagDTO();
BeanUtils.copyProperties(tag, tagDTO); BeanUtils.copyProperties(tag, tagDTO);
tagDTO.setImage(null == tag.getImage() ? null : TagS3Service.TAG_RESOURCE_PREFIX + TagS3Service.TAG_KEY_PREFIX + tag.getImage());
tagDTO.setThumbnail(null == tag.getThumbnail() ? null : TagS3Service.TAG_RESOURCE_PREFIX + TagS3Service.TAG_KEY_PREFIX + tag.getThumbnail());
TagStatistic tagStatistic = queryTagStatistic(tag.getId()); TagStatistic tagStatistic = queryTagStatistic(tag.getId());
tagDTO.setChildTagCount(tagStatistic.getChildTagCount()); tagDTO.setChildTagCount(tagStatistic.getChildTagCount());

Loading…
Cancel
Save