clean code

This commit is contained in:
chenxudong 2024-11-28 12:03:41 +08:00
parent 8344baed68
commit 74b3d9714f
3 changed files with 14 additions and 33 deletions

View File

@ -12,9 +12,6 @@ logging.config=classpath:${LOG_CONFIG:log4j2-spring.xml}
spring.datasource.typd=com.alibaba.druid.pool.DruidDataSource spring.datasource.typd=com.alibaba.druid.pool.DruidDataSource
#spring.datasource.url=jdbc:mysql://${DATASOURCE_URL:obproxy-0c63.ops.cloud.cic.inter}:3306/${DATASOURCE_HOST:dataplatform_ptst}?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true
#spring.datasource.username=${DATASOURCE_NAME:dataplatform@ProjectTest_tenant5#testdb}
#spring.datasource.password=${DATASOURCE_PASSWORD:Y7G6v4_3ijn77K_Kbl_U85}
spring.datasource.url=jdbc:mysql://139.224.43.89:3306/em_data?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true spring.datasource.url=jdbc:mysql://139.224.43.89:3306/em_data?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true&rewriteBatchedStatements=true
spring.datasource.username=comac spring.datasource.username=comac
spring.datasource.password=2024*Comac spring.datasource.password=2024*Comac
@ -27,7 +24,6 @@ mybatis.mapper-locations=classpath:sqlmapper/*.xml
pagehelper.helperDialect=mysql pagehelper.helperDialect=mysql
pagehelper.reasonable=false pagehelper.reasonable=false
server.port=8888 server.port=8888
zip.password=~~BYE6cWGBJJjsU9DczYtZIQ==
#windows文件存储目录 #windows文件存储目录
data.windows.path=E:/comacFileStorage/ data.windows.path=E:/comacFileStorage/
@ -41,3 +37,4 @@ data.upload.cache.dir=upload
data.export.cache.dir=export data.export.cache.dir=export
#导入数据时文件的缓存文件夹名称 #导入数据时文件的缓存文件夹名称
data.import.cache.dir=import data.import.cache.dir=import
file.encode.passwd=adknfhkj87654knd

View File

@ -54,15 +54,11 @@ import java.util.*;
@Slf4j @Slf4j
public class EDDataServiceImpl implements EDDataService { public class EDDataServiceImpl implements EDDataService {
// private static final Logger LOGGER = LoggerFactory.getLogger(LoggerConstant.DOMAIN_SERVICE);
@Resource @Resource
private EDDataRepository edDataRepository; private EDDataRepository edDataRepository;
@Resource @Resource
private CategoryRepository categoryRepository; private CategoryRepository categoryRepository;
@Value("${zip.password}")
private String passwordZIP;
@Value("${data.windows.path}") @Value("${data.windows.path}")
private String windowsDir; private String windowsDir;
@Value("${data.file.cache.dir}") @Value("${data.file.cache.dir}")
@ -73,6 +69,8 @@ public class EDDataServiceImpl implements EDDataService {
private String uploadCacheDir; private String uploadCacheDir;
@Value("${data.export.cache.dir}") @Value("${data.export.cache.dir}")
private String exportCacheDir; private String exportCacheDir;
@Value("${file.encode.passwd}")
private String encodePasswd;
// 文件夹名称分隔符 // 文件夹名称分隔符
private static final String FOLDER_NAME_SEPARATOR = "_"; private static final String FOLDER_NAME_SEPARATOR = "_";
@ -537,7 +535,6 @@ public class EDDataServiceImpl implements EDDataService {
log.info("文件数据已成功复制到目标目录。"); log.info("文件数据已成功复制到目标目录。");
// 将目录树数据 文件夹及文件夹内数据 进行压缩打包 // 将目录树数据 文件夹及文件夹内数据 进行压缩打包
Date date = new Date(); Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
@ -545,11 +542,10 @@ public class EDDataServiceImpl implements EDDataService {
zipPathFileName = dataCachePath + "/exportData_" + dateString; zipPathFileName = dataCachePath + "/exportData_" + dateString;
enCodeZipPathFileName = dataCachePath + "/exportData_" + dateString + ".comac"; enCodeZipPathFileName = dataCachePath + "/exportData_" + dateString + ".comac";
// EleZipUtil.zipFile(exportDataDirectory, zipPathFileName, passwordZIP);
ZipUtil.zip(exportDataCachePath, zipPathFileName); ZipUtil.zip(exportDataCachePath, zipPathFileName);
String password = "adknfhkj87654knd";
AES aes = SecureUtil.aes(password.getBytes()); // aesKey是加密密钥 AES aes = SecureUtil.aes(encodePasswd.getBytes()); // aesKey是加密密钥
try ( try (
InputStream inputStream = new FileInputStream(zipPathFileName); InputStream inputStream = new FileInputStream(zipPathFileName);
OutputStream outputStream = new FileOutputStream(enCodeZipPathFileName); OutputStream outputStream = new FileOutputStream(enCodeZipPathFileName);
@ -565,8 +561,6 @@ public class EDDataServiceImpl implements EDDataService {
log.error("导出数据异常..", e); log.error("导出数据异常..", e);
} }
finally { finally {
//删除临时文件
//FileUtil.del(zipPathFileName);
// 删除 导出数据的 缓存目录 // 删除 导出数据的 缓存目录
FileUtil.del(exportDataCachePath); FileUtil.del(exportDataCachePath);
} }

View File

@ -4,7 +4,6 @@ import cn.hutool.core.codec.Base64;
import cn.hutool.core.io.FileUtil; import cn.hutool.core.io.FileUtil;
import cn.hutool.core.io.IoUtil; import cn.hutool.core.io.IoUtil;
import cn.hutool.core.lang.Assert; import cn.hutool.core.lang.Assert;
import cn.hutool.core.text.StrFormatter;
import cn.hutool.core.util.ZipUtil; import cn.hutool.core.util.ZipUtil;
import cn.hutool.crypto.SecureUtil; import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES; import cn.hutool.crypto.symmetric.AES;
@ -33,8 +32,6 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -47,19 +44,17 @@ public class EDDataFacadeImpl implements EDDataFacade {
@Value("${data.windows.path}") @Value("${data.windows.path}")
private String uploadFilePath; private String uploadFilePath;
@Value("${data.windows.path}")
private String windowsDir;
@Value("${data.file.cache.dir}")
private String fileCacheDir;
@Value("${data.file.storage.dir}") @Value("${data.file.storage.dir}")
private String fileStorageDir; private String fileStorageDir;
@Value("${data.upload.cache.dir}")
private String uploadCacheDir;
@Value("${data.export.cache.dir}")
private String exportCacheDir;
@Value("${data.import.cache.dir}") @Value("${data.import.cache.dir}")
private String importCacheDir; private String importCacheDir;
@Value("${file.encode.passwd}")
private String encodePasswd;
private static final String UPLOAD_FILE_CHUNK_SUFFIX = ".part"; private static final String UPLOAD_FILE_CHUNK_SUFFIX = ".part";
@ -228,13 +223,10 @@ public class EDDataFacadeImpl implements EDDataFacade {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.add("Cache-Control", "no-cache, no-store, must-revalidate"); headers.add("Cache-Control", "no-cache, no-store, must-revalidate");
String fileName = fileSystemResource.getFilename(); String fileName = Base64.encode(fileSystemResource.getFilename());
byte[] fileNameBytes = fileName.getBytes(StandardCharsets.UTF_8);
fileName = new String(fileNameBytes, 0, fileNameBytes.length, StandardCharsets.ISO_8859_1);
String attachment = StrFormatter.format("attachment;filename={}", fileName);
headers.add("Pragma", "no-cache"); headers.add("Pragma", "no-cache");
headers.add("Expires", "0"); headers.add("Expires", "0");
response.setHeader("content-disposition","attachment;filename=" + URLEncoder.encode(fileName,"UTF-8")); response.setHeader("content-disposition","attachment;filename=" + fileName);
// 构建响应实体(可以返回<byte[]或Resource返回类型取决body入参类型) // 构建响应实体(可以返回<byte[]或Resource返回类型取决body入参类型)
return ResponseEntity return ResponseEntity
@ -303,7 +295,6 @@ public class EDDataFacadeImpl implements EDDataFacade {
String dataCachePath = edDataService.getDataCachePath(); String dataCachePath = edDataService.getDataCachePath();
String importDataCachePath = dataCachePath + importCacheDir; String importDataCachePath = dataCachePath + importCacheDir;
String destPath = importDataCachePath + identifier; String destPath = importDataCachePath + identifier;
if (!FileUtil.exist(new File(destPath))) { if (!FileUtil.exist(new File(destPath))) {
return new ArrayList<>(); return new ArrayList<>();
} }
@ -362,8 +353,7 @@ public class EDDataFacadeImpl implements EDDataFacade {
// 解密文件 // 解密文件
String decryptFilePath = destZipPath + "_decrypted"; String decryptFilePath = destZipPath + "_decrypted";
String password = "adknfhkj87654knd"; AES aes = SecureUtil.aes(encodePasswd.getBytes()); // aesKey是加密密钥
AES aes = SecureUtil.aes(password.getBytes()); // aesKey是加密密钥
try( try(
InputStream inputStream = new FileInputStream(destZipPath); InputStream inputStream = new FileInputStream(destZipPath);
OutputStream outputStream = new FileOutputStream(decryptFilePath); OutputStream outputStream = new FileOutputStream(decryptFilePath);