feat:期刊

desc:期刊添加图片和描述
main
zjb 10 months ago
parent cb1d9ef00a
commit 34089d10f9

@ -59,6 +59,11 @@
<groupId>com.h2database</groupId> <groupId>com.h2database</groupId>
<artifactId>h2</artifactId> <artifactId>h2</artifactId>
</dependency> </dependency>
<!-- s3 sdk -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<finalName>app</finalName> <finalName>app</finalName>

@ -53,6 +53,16 @@ public class Tag implements Serializable {
*/ */
private Integer state; private Integer state;
/**
*
*/
private String desc;
/**
*
*/
private String image;
/** /**
* ID * ID
*/ */

@ -24,4 +24,10 @@ public class TagCreateReq implements Serializable {
@ApiModelProperty(value = "标签英文名") @ApiModelProperty(value = "标签英文名")
@NotBlank(message = "标签英文名称必填") @NotBlank(message = "标签英文名称必填")
private String nameEn; private String nameEn;
@ApiModelProperty(value = "文案")
private String desc;
@ApiModelProperty(value = "图片路径")
private String image;
} }

@ -31,6 +31,12 @@ public class TagDTO implements Serializable {
@ApiModelProperty(value = "标签状态 0=禁用1=启用") @ApiModelProperty(value = "标签状态 0=禁用1=启用")
private Integer state; private Integer state;
@ApiModelProperty(value = "说明文案")
private String desc;
@ApiModelProperty(value = "图片")
private String image;
@ApiModelProperty(value = "子标签数量") @ApiModelProperty(value = "子标签数量")
private Long childTagCount = 0L; private Long childTagCount = 0L;

@ -31,4 +31,10 @@ public class TagUpdateReq implements Serializable {
@ApiModelProperty(value = "标签英文名") @ApiModelProperty(value = "标签英文名")
@NotBlank(message = "标签英文名称必填") @NotBlank(message = "标签英文名称必填")
private String nameEn; private String nameEn;
@ApiModelProperty(value = "文案")
private String desc;
@ApiModelProperty(value = "图片路径")
private String image;
} }

@ -0,0 +1,74 @@
package com.luoo.tag.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import software.amazon.awssdk.http.SdkHttpResponse;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.CopyObjectRequest;
import software.amazon.awssdk.services.s3.model.CopyObjectResponse;
import util.IdWorker;
import javax.annotation.Resource;
/**
* ClassName: TagImageUtil
* Description: TagImageUtil
* Date: 2024-02-04
*
* @author zjb
*/
@Service
public class TagS3Service {
@Resource
private S3Client s3Client;
public static final String DOT = ".";
public static final String TAG_RESOURCE_PREFIX = "http://cdn.indie.cn/tag/";
public static final String BUCKET = "indie";
public static final String TEMP_KEY_PREFIX = "temp/";
public String moveTagImage(String srcKey, String oldImage, String tagId) {
String image = oldImage;
String suffix = image.substring(image.lastIndexOf(DOT));
String destKeySuffix = String.format("%s%s", tagId, suffix);
String destKey = TAG_RESOURCE_PREFIX + destKeySuffix;
int copy = copy(BUCKET, srcKey, destKey);
if (copy > 0) {
return destKeySuffix;
}
return null;
}
/**
* s3
*
* @param bucket
* @param srcKey key
* @param destKey key
* @return -
*/
public int copy(String bucket, String srcKey, String destKey) {
try {
CopyObjectRequest copyObjectRequest = CopyObjectRequest.builder()
.sourceBucket(bucket).sourceKey(srcKey).destinationBucket(bucket).destinationKey(destKey).build();
CopyObjectResponse copyObjectResponse = s3Client.copyObject(copyObjectRequest);
SdkHttpResponse sdkHttpResponse = copyObjectResponse.sdkHttpResponse();
if (!sdkHttpResponse.isSuccessful()) {
return -1;
} else {
return 1;
}
} catch (Exception e) {
return -1;
} finally {
s3Client.close();
}
}
public static String getSrcKey(String srcFullPath) {
return srcFullPath.substring(srcFullPath.indexOf(TEMP_KEY_PREFIX));
}
}

@ -40,6 +40,7 @@ public class TagService {
private final AdminUserClient userClient; private final AdminUserClient userClient;
private final JournalTagDao journalTagDao; private final JournalTagDao journalTagDao;
private final SongTagDao songTagDao; private final SongTagDao songTagDao;
private final TagS3Service tagS3Service;
/** /**
@ -101,6 +102,13 @@ public class TagService {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
tag.setCreateTime(now); tag.setCreateTime(now);
tag.setUpdateTime(now); tag.setUpdateTime(now);
if (null != createReq.getImage() && !createReq.getImage().isEmpty()) {
tag.setImage(tagS3Service.moveTagImage(
TagS3Service.getSrcKey(createReq.getImage()), createReq.getImage(), tag.getId()
));
}
// //
// UserInfo userInfo = RequestContext.get(); // UserInfo userInfo = RequestContext.get();
// tag.setCreatorId(userInfo.getId()); // tag.setCreatorId(userInfo.getId());
@ -113,6 +121,7 @@ public class TagService {
* @param updateReq * @param updateReq
*/ */
public void update(TagUpdateReq updateReq){ public void update(TagUpdateReq updateReq){
// TODO: 添加desc和image
String id = updateReq.getId(); String id = updateReq.getId();
Optional<Tag> tagOptional = tagDao.findById(id); Optional<Tag> tagOptional = tagDao.findById(id);
AssertUtil.mustTrue(tagOptional.isPresent(), "标签记录不存在"); AssertUtil.mustTrue(tagOptional.isPresent(), "标签记录不存在");
@ -134,6 +143,21 @@ public class TagService {
tag.setNameEn(updateReq.getNameEn()); tag.setNameEn(updateReq.getNameEn());
tag.setUpdateTime(LocalDateTime.now()); tag.setUpdateTime(LocalDateTime.now());
// tag.setUpdaterId(RequestContext.get().getId()); // tag.setUpdaterId(RequestContext.get().getId());
String srcKey = null;
if (null == updateReq.getImage()) {
tag.setImage(null);
}
if (updateReq.getImage().contains(TagS3Service.TEMP_KEY_PREFIX)) {
srcKey = updateReq.getImage().substring(updateReq.getImage().indexOf(TagS3Service.TEMP_KEY_PREFIX));
}
if (StringUtils.isNotBlank(srcKey)) {
tag.setImage(
tagS3Service.moveTagImage(srcKey, updateReq.getImage(), id)
);
}
tagDao.save(tag); tagDao.save(tag);
} }

Loading…
Cancel
Save