审核逻辑修改前项目保存
This commit is contained in:
32
src/main/java/com/zg/common/utils/EntityFillUtils.java
Normal file
32
src/main/java/com/zg/common/utils/EntityFillUtils.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.zg.common.utils;
|
||||
|
||||
import com.zg.framework.web.domain.BaseEntity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
public class EntityFillUtils {
|
||||
|
||||
/**
|
||||
* 设置新增操作的公共字段(创建人、创建时间、修改人、修改时间、逻辑删除)
|
||||
*/
|
||||
public static void fillCreateFields(BaseEntity entity) {
|
||||
String username = SecurityUtils.getUsername();
|
||||
Date now = new Date();
|
||||
|
||||
entity.setCreateBy(username);
|
||||
entity.setCreateTime(now);
|
||||
entity.setUpdateBy(username);
|
||||
entity.setUpdateTime(now);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置修改操作的公共字段(修改人、修改时间)
|
||||
*/
|
||||
public static void fillUpdateFields(BaseEntity entity) {
|
||||
String username = SecurityUtils.getUsername();
|
||||
Date now = new Date();
|
||||
|
||||
entity.setUpdateBy(username);
|
||||
entity.setUpdateTime(now);
|
||||
}
|
||||
}
|
||||
60
src/main/java/com/zg/common/utils/MinioUtil.java
Normal file
60
src/main/java/com/zg/common/utils/MinioUtil.java
Normal file
@@ -0,0 +1,60 @@
|
||||
package com.zg.common.utils;
|
||||
|
||||
import io.minio.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class MinioUtil {
|
||||
|
||||
@Value("${minio.endpoint}")
|
||||
private String endpoint;
|
||||
|
||||
@Value("${minio.accessKey}")
|
||||
private String accessKey;
|
||||
|
||||
@Value("${minio.secretKey}")
|
||||
private String secretKey;
|
||||
|
||||
@Value("${minio.bucketName}")
|
||||
private String bucketName;
|
||||
|
||||
/**
|
||||
* 上传文件到 MinIO,自动根据日期生成路径
|
||||
* 如:2025/07/10/uuid-xxx.jpg
|
||||
*/
|
||||
public String uploadFile(MultipartFile file) throws Exception {
|
||||
MinioClient client = MinioClient.builder()
|
||||
.endpoint(endpoint)
|
||||
.credentials(accessKey, secretKey)
|
||||
.build();
|
||||
|
||||
// 检查桶是否存在,不存在则创建
|
||||
boolean found = client.bucketExists(BucketExistsArgs.builder().bucket(bucketName).build());
|
||||
if (!found) {
|
||||
client.makeBucket(MakeBucketArgs.builder().bucket(bucketName).build());
|
||||
}
|
||||
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String datePath = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy/MM/dd"));
|
||||
String objectName = datePath + "/" + UUID.randomUUID().toString() + "-" + originalFilename;
|
||||
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
client.putObject(PutObjectArgs.builder()
|
||||
.bucket(bucketName)
|
||||
.object(objectName)
|
||||
.stream(inputStream, file.getSize(), -1)
|
||||
.contentType(file.getContentType())
|
||||
.build());
|
||||
}
|
||||
|
||||
// 返回完整可访问 URL(前端可直接使用)
|
||||
return endpoint + "/" + bucketName + "/" + objectName;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user