fix[project]: 修改推送报告的压缩包名称
This commit is contained in:
@@ -23,14 +23,20 @@ public class LyricParamConstants {
|
||||
public static final Long FINITE_ELEMENT_COMPONENT_INST_ID = 8000004142460000204L;
|
||||
// 有限元字段名称
|
||||
public static final String FINITE_ELEMENT_COLUMN_NAME = "simulation_table";
|
||||
// 有限元报告压缩包名称前缀
|
||||
public static final String FINITE_ELEMENT_PACKAGE_NAME_PREFIX = "有限元";
|
||||
// 机器人控件id
|
||||
public static final Long ROBOT_COMPONENT_INST_ID = 8000004142460000228L;
|
||||
// 机器人字段名称
|
||||
public static final String ROBOT_COLUMN_NAME = "robot_table";
|
||||
// 机器人报告压缩包名称前缀
|
||||
public static final String ROBOT_PACKAGE_NAME_PREFIX = "机器人";
|
||||
// 公差控件id
|
||||
public static final Long TOLERANCE_COMPONENT_INST_ID = 8000004144780000369L;
|
||||
// 公差字段名称
|
||||
public static final String TOLERANCE_COLUMN_NAME = "checkproducts_enclosure";
|
||||
// 公差报告压缩包名称前缀
|
||||
public static final String TOLERANCE_PACKAGE_NAME_PREFIX = "产品工艺";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,33 +2,34 @@ package com.sdm.project.common.generator;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class UniqueFileNameGenerator {
|
||||
|
||||
// 定义随机字符串的字符集(字母+数字,避免混淆的字符如0/O、1/l已剔除)
|
||||
private static final String CHARACTERS = "abcdefghjkmnpqrstuvwxyz";
|
||||
private static final int RANDOM_LENGTH = 12; // 随机字符串长度
|
||||
private static final SecureRandom SECURE_RANDOM = new SecureRandom(); // 安全随机数生成器
|
||||
// 日期格式化器(年月日,如20251221)
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
// private static final String CHARACTERS = "abcdefghjkmnpqrstuvwxyz";
|
||||
// private static final int RANDOM_LENGTH = 12; // 随机字符串长度
|
||||
// private static final SecureRandom SECURE_RANDOM = new SecureRandom(); // 安全随机数生成器
|
||||
// 日期格式化器(年月日时分秒毫秒,如20251221123456789)
|
||||
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");
|
||||
|
||||
/**
|
||||
* 生成唯一文件名:年月日 + 12位随机字符串
|
||||
* @return 格式化后的文件名(如20251221akdesgdiujfs)
|
||||
* 生成唯一文件名:年月日时分秒毫秒
|
||||
* @return 格式化后的文件名(如20251221123456789)
|
||||
*/
|
||||
public static String generateUniqueFileName() {
|
||||
// 1. 获取当前年月日并格式化
|
||||
String currentDate = LocalDate.now().format(DATE_FORMATTER);
|
||||
String currentDate = LocalDateTime.now().format(DATE_FORMATTER);
|
||||
// 2. 生成12位随机字符串
|
||||
StringBuilder randomStr = new StringBuilder(RANDOM_LENGTH);
|
||||
for (int i = 0; i < RANDOM_LENGTH; i++) {
|
||||
// 随机获取字符集索引
|
||||
int randomIndex = SECURE_RANDOM.nextInt(CHARACTERS.length());
|
||||
randomStr.append(CHARACTERS.charAt(randomIndex));
|
||||
}
|
||||
// StringBuilder randomStr = new StringBuilder(RANDOM_LENGTH);
|
||||
// for (int i = 0; i < RANDOM_LENGTH; i++) {
|
||||
// // 随机获取字符集索引
|
||||
// int randomIndex = SECURE_RANDOM.nextInt(CHARACTERS.length());
|
||||
// randomStr.append(CHARACTERS.charAt(randomIndex));
|
||||
// }
|
||||
// 3. 拼接日期和随机字符串
|
||||
return currentDate + "_" + randomStr;
|
||||
return "_" + currentDate;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1600,10 +1600,20 @@ public class LyricInternalServiceImpl implements ILyricInternalService {
|
||||
throw new RuntimeException("推送报告失败,原因为:创建临时文件夹失败");
|
||||
}
|
||||
}
|
||||
// 推送类型 1:有限元 2:机器人 3:公差(产品工艺专项验收)
|
||||
Integer pushType = req.getPushType();
|
||||
// 准备要打包的文件列表
|
||||
List<File> filesToZip = FilesUtil.getAllFiles(tempPath);
|
||||
// 指定生成的ZIP文件路径
|
||||
String zipFilePath = tempPath + File.separator + REPORT_ZIP_NAME + UniqueFileNameGenerator.generateUniqueFileName() + ZIP_SUFFIX;
|
||||
String reportZipName;
|
||||
if (pushType == 1) {
|
||||
reportZipName = LyricParamConstants.FINITE_ELEMENT_PACKAGE_NAME_PREFIX;
|
||||
} else if (pushType == 2) {
|
||||
reportZipName = LyricParamConstants.ROBOT_PACKAGE_NAME_PREFIX;
|
||||
} else {
|
||||
reportZipName = LyricParamConstants.TOLERANCE_PACKAGE_NAME_PREFIX;
|
||||
}
|
||||
String zipFilePath = tempPath + File.separator + reportZipName + UniqueFileNameGenerator.generateUniqueFileName() + ZIP_SUFFIX;
|
||||
log.info("zipFilePath为:{}", zipFilePath);
|
||||
// 执行打包
|
||||
try {
|
||||
@@ -1626,8 +1636,6 @@ public class LyricInternalServiceImpl implements ILyricInternalService {
|
||||
jobNumber = cidUserRespSdmResponse.getData().getUsername();
|
||||
}
|
||||
HkUploadFileReq uploadFileReq = new HkUploadFileReq();
|
||||
// 推送类型 1:有限元 2:机器人 3:公差(产品工艺专项验收)
|
||||
Integer pushType = req.getPushType();
|
||||
if (pushType == 1) {
|
||||
uploadFileReq.setComponentInstId(LyricParamConstants.FINITE_ELEMENT_COMPONENT_INST_ID);
|
||||
uploadFileReq.setColumnName(LyricParamConstants.FINITE_ELEMENT_COLUMN_NAME);
|
||||
|
||||
Reference in New Issue
Block a user