mirror of
https://github.com/1024-lab/smart-admin.git
synced 2026-06-02 03:55:59 +00:00
v3.31 【增加】字典值反序列增加int类型;【优化】java17版本S3上传文件Bug;【优化】本地文件上传优化文件操作符
This commit is contained in:
@@ -38,7 +38,7 @@
|
|||||||
<commons-text.version>1.13.1</commons-text.version>
|
<commons-text.version>1.13.1</commons-text.version>
|
||||||
<fast-excel.version>1.2.0</fast-excel.version>
|
<fast-excel.version>1.2.0</fast-excel.version>
|
||||||
<poi.version>5.4.1</poi.version>
|
<poi.version>5.4.1</poi.version>
|
||||||
<awssdk-s3.version>2.31.78</awssdk-s3.version>
|
<awssdk-s3.version>2.42.6</awssdk-s3.version>
|
||||||
<mysql-connector-j.version>9.3.0</mysql-connector-j.version>
|
<mysql-connector-j.version>9.3.0</mysql-connector-j.version>
|
||||||
<hutool.version>5.8.39</hutool.version>
|
<hutool.version>5.8.39</hutool.version>
|
||||||
<velocity-engine-core.version>2.4.1</velocity-engine-core.version>
|
<velocity-engine-core.version>2.4.1</velocity-engine-core.version>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package net.lab1024.sa.base.common.json.deserializer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.ObjectCodec;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典值为 int类型的 反序列化
|
||||||
|
*
|
||||||
|
* @Author 1024创新实验室: 卓大
|
||||||
|
* @Date 2026-04-05 22:17:53
|
||||||
|
* @Wechat zhuoda1024
|
||||||
|
* @Email lab1024@163.com
|
||||||
|
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class DictDataIntDeserializer extends JsonDeserializer<Integer> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
|
||||||
|
ObjectCodec objectCodec = jsonParser.getCodec();
|
||||||
|
JsonNode listOrObjectNode = objectCodec.readTree(jsonParser);
|
||||||
|
return Integer.parseInt(listOrObjectNode.asText());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -41,15 +41,15 @@ public class SmartBeanUtil {
|
|||||||
*
|
*
|
||||||
* @param source 源 要复制的对象
|
* @param source 源 要复制的对象
|
||||||
* @param target 目标 复制到此对象
|
* @param target 目标 复制到此对象
|
||||||
* @param <T>
|
* @param <T> 目标对象的类型
|
||||||
* @return
|
* @return 目标对象
|
||||||
*/
|
*/
|
||||||
public static <T> T copy(Object source, Class<T> target) {
|
public static <T> T copy(Object source, Class<T> target) {
|
||||||
if (source == null || target == null) {
|
if (source == null || target == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
T newInstance = target.newInstance();
|
T newInstance = target.getDeclaredConstructor().newInstance();
|
||||||
BeanUtils.copyProperties(source, newInstance);
|
BeanUtils.copyProperties(source, newInstance);
|
||||||
return newInstance;
|
return newInstance;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@@ -60,11 +60,11 @@ public class SmartBeanUtil {
|
|||||||
/**
|
/**
|
||||||
* 复制list
|
* 复制list
|
||||||
*
|
*
|
||||||
* @param source
|
* @param source 源 要复制的列表
|
||||||
* @param target
|
* @param target 目标 复制到此对象
|
||||||
* @param <T>
|
* @param <T> 源列表的类型
|
||||||
* @param <K>
|
* @param <K> 目标列表的类型
|
||||||
* @return
|
* @return 目标列表
|
||||||
*/
|
*/
|
||||||
public static <T, K> List<K> copyList(List<T> source, Class<K> target) {
|
public static <T, K> List<K> copyList(List<T> source, Class<K> target) {
|
||||||
if (null == source || source.isEmpty()) {
|
if (null == source || source.isEmpty()) {
|
||||||
@@ -74,11 +74,11 @@ public class SmartBeanUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 手动验证对象 Model的属性
|
* 手动验证对象 Model 的属性
|
||||||
* 需要配合 hibernate-validator 校验注解
|
* 需要配合 hibernate-validator 校验注解
|
||||||
*
|
*
|
||||||
* @param t
|
* @param t 需要验证的对象
|
||||||
* @return String 返回null代表验证通过,否则返回错误的信息
|
* @return String 返回 null 代表验证通过,否则返回错误的信息
|
||||||
*/
|
*/
|
||||||
public static <T> String verify(T t) {
|
public static <T> String verify(T t) {
|
||||||
// 获取验证结果
|
// 获取验证结果
|
||||||
@@ -88,7 +88,7 @@ public class SmartBeanUtil {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
// 返回错误信息
|
// 返回错误信息
|
||||||
List<String> messageList = validate.stream().map(ConstraintViolation::getMessage).collect(Collectors.toList());
|
List<String> messageList = validate.stream().map(ConstraintViolation::getMessage).toList();
|
||||||
return messageList.toString();
|
return messageList.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
import software.amazon.awssdk.core.ResponseBytes;
|
import software.amazon.awssdk.core.ResponseBytes;
|
||||||
import software.amazon.awssdk.core.sync.RequestBody;
|
import software.amazon.awssdk.core.sync.RequestBody;
|
||||||
import software.amazon.awssdk.core.sync.ResponseTransformer;
|
import software.amazon.awssdk.core.sync.ResponseTransformer;
|
||||||
import software.amazon.awssdk.regions.Region;
|
|
||||||
import software.amazon.awssdk.services.s3.S3Client;
|
import software.amazon.awssdk.services.s3.S3Client;
|
||||||
import software.amazon.awssdk.services.s3.model.*;
|
import software.amazon.awssdk.services.s3.model.*;
|
||||||
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
|
import software.amazon.awssdk.services.s3.presigner.S3Presigner;
|
||||||
@@ -116,15 +115,11 @@ public class FileStorageCloudServiceImpl implements IFileStorageService {
|
|||||||
.contentDisposition("attachment;filename=" + urlEncoderFilename)
|
.contentDisposition("attachment;filename=" + urlEncoderFilename)
|
||||||
.acl(acl)
|
.acl(acl)
|
||||||
.build();
|
.build();
|
||||||
InputStream inputStream = null;
|
|
||||||
try {
|
try {
|
||||||
inputStream = file.getInputStream();
|
s3Client.putObject(putObjectRequest, RequestBody.fromBytes(file.getBytes()));
|
||||||
s3Client.putObject(putObjectRequest, RequestBody.fromInputStream(inputStream, file.getSize()));
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("文件上传-发生异常:", e);
|
log.error("文件上传-发生异常:", e);
|
||||||
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "上传失败");
|
return ResponseDTO.error(SystemErrorCode.SYSTEM_ERROR, "上传失败");
|
||||||
} finally {
|
|
||||||
IOUtils.closeQuietly(inputStream);
|
|
||||||
}
|
}
|
||||||
// 返回上传结果
|
// 返回上传结果
|
||||||
FileUploadVO uploadVO = new FileUploadVO();
|
FileUploadVO uploadVO = new FileUploadVO();
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import java.util.UUID;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class FileStorageLocalServiceImpl implements IFileStorageService {
|
public class FileStorageLocalServiceImpl implements IFileStorageService {
|
||||||
|
|
||||||
|
private static final String FILE_SEPARATOR = "/";
|
||||||
|
|
||||||
public static final String UPLOAD_MAPPING = "/upload";
|
public static final String UPLOAD_MAPPING = "/upload";
|
||||||
|
|
||||||
@@ -78,8 +79,8 @@ public class FileStorageLocalServiceImpl implements IFileStorageService {
|
|||||||
// 目录不存在,新建
|
// 目录不存在,新建
|
||||||
directory.mkdirs();
|
directory.mkdirs();
|
||||||
}
|
}
|
||||||
if (!path.endsWith(File.separator)) {
|
if (!path.endsWith(FILE_SEPARATOR)) {
|
||||||
path = path + File.separator;
|
path = path + FILE_SEPARATOR;
|
||||||
}
|
}
|
||||||
FileUploadVO fileUploadVO = new FileUploadVO();
|
FileUploadVO fileUploadVO = new FileUploadVO();
|
||||||
//原文件名
|
//原文件名
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package net.lab1024.sa.base.common.json.deserializer;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.ObjectCodec;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 字典值为 int类型的 反序列化
|
||||||
|
*
|
||||||
|
* @Author 1024创新实验室: 卓大
|
||||||
|
* @Date 2026-04-05 22:17:53
|
||||||
|
* @Wechat zhuoda1024
|
||||||
|
* @Email lab1024@163.com
|
||||||
|
* @Copyright <a href="https://1024lab.net">1024创新实验室</a>
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class DictDataIntDeserializer extends JsonDeserializer<Integer> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
|
||||||
|
ObjectCodec objectCodec = jsonParser.getCodec();
|
||||||
|
JsonNode listOrObjectNode = objectCodec.readTree(jsonParser);
|
||||||
|
return Integer.parseInt(listOrObjectNode.asText());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -37,6 +37,7 @@ import java.util.UUID;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class FileStorageLocalServiceImpl implements IFileStorageService {
|
public class FileStorageLocalServiceImpl implements IFileStorageService {
|
||||||
|
|
||||||
|
private static final String FILE_SEPARATOR = "/";
|
||||||
|
|
||||||
public static final String UPLOAD_MAPPING = "/upload";
|
public static final String UPLOAD_MAPPING = "/upload";
|
||||||
|
|
||||||
@@ -78,8 +79,8 @@ public class FileStorageLocalServiceImpl implements IFileStorageService {
|
|||||||
// 目录不存在,新建
|
// 目录不存在,新建
|
||||||
directory.mkdirs();
|
directory.mkdirs();
|
||||||
}
|
}
|
||||||
if (!path.endsWith(File.separator)) {
|
if (!path.endsWith(FILE_SEPARATOR)) {
|
||||||
path = path + File.separator;
|
path = path + FILE_SEPARATOR;
|
||||||
}
|
}
|
||||||
FileUploadVO fileUploadVO = new FileUploadVO();
|
FileUploadVO fileUploadVO = new FileUploadVO();
|
||||||
//原文件名
|
//原文件名
|
||||||
|
|||||||
Reference in New Issue
Block a user