Merge branch 'release3.0.4' into develop

This commit is contained in:
chenxudong 2025-08-06 16:54:52 +08:00
commit 490287e815
8 changed files with 27 additions and 14 deletions

View File

@ -7,6 +7,8 @@ import com.electromagnetic.industry.software.backup.pojo.BackupPro;
import com.electromagnetic.industry.software.backup.service.FileService; import com.electromagnetic.industry.software.backup.service.FileService;
import com.electromagnetic.industry.software.common.util.EleCommonUtil; import com.electromagnetic.industry.software.common.util.EleCommonUtil;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
@ -17,14 +19,16 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import static com.electromagnetic.industry.software.common.cons.ElectromagneticConstants.FILE_SEC_PASSWD;
@Service @Service
public class FileServiceImpl implements FileService { public class FileServiceImpl implements FileService {
@Resource @Resource
private BackupPro backupPro; private BackupPro backupPro;
@Getter
@Value("${file.enc.passwd}")
private String fileEncPasswd;
@Override @Override
public void upload(MultipartFile file) throws IOException { public void upload(MultipartFile file) throws IOException {
String name = FileUtil.mainName(file.getOriginalFilename()); String name = FileUtil.mainName(file.getOriginalFilename());
@ -60,7 +64,7 @@ public class FileServiceImpl implements FileService {
int index = destPath.lastIndexOf("."); int index = destPath.lastIndexOf(".");
String zipPath = destPath.substring(0, index) + ".zip"; String zipPath = destPath.substring(0, index) + ".zip";
ZipUtil.zip(destPath, zipPath); ZipUtil.zip(destPath, zipPath);
EleCommonUtil.encryptFile(zipPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes())); EleCommonUtil.encryptFile(zipPath, SecureUtil.aes(fileEncPasswd.getBytes()));
FileUtil.del(destPath); FileUtil.del(destPath);
} }

View File

@ -11,4 +11,8 @@ spring:
max-request-size: 500MB max-request-size: 500MB
server: server:
port: 12491 port: 12491
file:
enc:
passwd: adknfhkj87654knd

View File

@ -92,6 +92,10 @@ public class ElePropertyConfig {
@Value("${ai.file.upload.store.dir}") @Value("${ai.file.upload.store.dir}")
private String aiFileUploadStoreDir; private String aiFileUploadStoreDir;
@Getter
@Value("${file.enc.passwd}")
private String fileEncPasswd;
public String getAiFileUploadStoreDir() { public String getAiFileUploadStoreDir() {
if (EleCommonUtil.isWinOs()) { if (EleCommonUtil.isWinOs()) {
return FileUtil.normalize(winPrefix + File.separator + aiFileUploadStoreDir); return FileUtil.normalize(winPrefix + File.separator + aiFileUploadStoreDir);
@ -213,4 +217,5 @@ public class ElePropertyConfig {
} }
} }

View File

@ -663,7 +663,7 @@ public class CommonService {
edFileInfoMapper.insertOrUpdate(newEdFileInfo); edFileInfoMapper.insertOrUpdate(newEdFileInfo);
String fileDestPath = getFileSysPath(newEdFileInfo.getId()); String fileDestPath = getFileSysPath(newEdFileInfo.getId());
FileUtil.writeFromStream(file.getInputStream(), fileDestPath); FileUtil.writeFromStream(file.getInputStream(), fileDestPath);
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes())); EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(elePropertyConfig.getFileEncPasswd().getBytes()));
finalEdFileInfo = newEdFileInfo; finalEdFileInfo = newEdFileInfo;
newEdFileInfo.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code); newEdFileInfo.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code);
edFileInfoMapper.insertOrUpdate(newEdFileInfo); edFileInfoMapper.insertOrUpdate(newEdFileInfo);
@ -765,7 +765,7 @@ public class CommonService {
edFileInfoMapper.insert(newEdFileInfo); edFileInfoMapper.insert(newEdFileInfo);
String fileDestPath = getFileSysPath(newEdFileInfo.getId()); String fileDestPath = getFileSysPath(newEdFileInfo.getId());
fileSystemService.save(file.getInputStream(), fileDestPath); fileSystemService.save(file.getInputStream(), fileDestPath);
EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes())); EleCommonUtil.encryptFile(fileDestPath, SecureUtil.aes(elePropertyConfig.getFileEncPasswd().getBytes()));
newEdFileInfo.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code); newEdFileInfo.setSaveStatus(EleDataSaveStatusEnum.SUCCESS.code);
edFileInfoMapper.insertOrUpdate(newEdFileInfo); edFileInfoMapper.insertOrUpdate(newEdFileInfo);
return newEdFileInfo; return newEdFileInfo;

View File

@ -482,7 +482,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
String mainName = FileUtil.mainName(destColibPath); String mainName = FileUtil.mainName(destColibPath);
String parentDir = FileUtil.getParent(destColibPath, 1); String parentDir = FileUtil.getParent(destColibPath, 1);
String zipDirPath = parentDir + File.separator + mainName + ".zip"; String zipDirPath = parentDir + File.separator + mainName + ".zip";
AES aes = SecureUtil.aes(FILE_SEC_PASSWD.getBytes()); AES aes = SecureUtil.aes(elePropertyConfig.getFileEncPasswd().getBytes());
try ( try (
InputStream inputStream = Files.newInputStream(Paths.get(destColibPath)); InputStream inputStream = Files.newInputStream(Paths.get(destColibPath));
OutputStream outputStream = Files.newOutputStream(Paths.get(zipDirPath)) OutputStream outputStream = Files.newOutputStream(Paths.get(zipDirPath))
@ -820,7 +820,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
String exportColibFile = userDownloadDataDir + File.separator + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + EXPORT_FILE_SUFFIX; String exportColibFile = userDownloadDataDir + File.separator + File.separator + EXPORT_PRJ_NAME + "_" + nowTimeStr + EXPORT_FILE_SUFFIX;
FileUtil.del(exportColibFile); FileUtil.del(exportColibFile);
ZipUtil.zip(prjDirPath, exportZipFile); ZipUtil.zip(prjDirPath, exportZipFile);
AES aes = SecureUtil.aes(FILE_SEC_PASSWD.getBytes()); AES aes = SecureUtil.aes(elePropertyConfig.getFileEncPasswd().getBytes());
try ( try (
InputStream inputStream = Files.newInputStream(Paths.get(exportZipFile)); InputStream inputStream = Files.newInputStream(Paths.get(exportZipFile));
OutputStream outputStream = Files.newOutputStream(Paths.get(exportColibFile)) OutputStream outputStream = Files.newOutputStream(Paths.get(exportColibFile))
@ -1320,7 +1320,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
String fileSysPath = commonService.getFileSysPath(fileInfo.getId()); String fileSysPath = commonService.getFileSysPath(fileInfo.getId());
fileSaveTmpPath = elePropertyConfig.getEleTmpPath() + File.separator + IdUtil.fastSimpleUUID() + "." + fileInfo.getFileType(); fileSaveTmpPath = elePropertyConfig.getEleTmpPath() + File.separator + IdUtil.fastSimpleUUID() + "." + fileInfo.getFileType();
FileUtil.copy(fileSysPath, fileSaveTmpPath, true); FileUtil.copy(fileSysPath, fileSaveTmpPath, true);
EleCommonUtil.decryptFile(fileSaveTmpPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes())); EleCommonUtil.decryptFile(fileSaveTmpPath, SecureUtil.aes(elePropertyConfig.getFileEncPasswd().getBytes()));
if (Arrays.asList("doc", "docx").contains(fileInfo.getFileType())) { if (Arrays.asList("doc", "docx").contains(fileInfo.getFileType())) {
String pdfTmpPath = elePropertyConfig.getEleTmpPath() + File.separator + fileInfo.getId() + ".pdf"; String pdfTmpPath = elePropertyConfig.getEleTmpPath() + File.separator + fileInfo.getId() + ".pdf";

View File

@ -127,12 +127,12 @@ public class ImportPrjServiceImpl extends ServiceImpl<ImportPrjInfoMapper, Impor
InputStream inputStream = zipFile.getInputStream(tmp); InputStream inputStream = zipFile.getInputStream(tmp);
String destPath = elePropertyConfig.getImportPrjPath() + File.separator + newId; String destPath = elePropertyConfig.getImportPrjPath() + File.separator + newId;
FileUtil.writeFromStream(inputStream, destPath); FileUtil.writeFromStream(inputStream, destPath);
EleCommonUtil.encryptFile(destPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes())); EleCommonUtil.encryptFile(destPath, SecureUtil.aes(elePropertyConfig.getFileEncPasswd().getBytes()));
} }
String prjId = items.stream().filter(e -> e.getParentId().equals(PRJ_PARENT_ID)).findFirst().get().getId(); String prjId = items.stream().filter(e -> e.getParentId().equals(PRJ_PARENT_ID)).findFirst().get().getId();
String prjPath = elePropertyConfig.getImportPrjPath() + File.separator + prjId; String prjPath = elePropertyConfig.getImportPrjPath() + File.separator + prjId;
FileUtil.writeFromStream(file.getInputStream(), prjPath); FileUtil.writeFromStream(file.getInputStream(), prjPath);
EleCommonUtil.encryptFile(prjPath, SecureUtil.aes(FILE_SEC_PASSWD.getBytes())); EleCommonUtil.encryptFile(prjPath, SecureUtil.aes(elePropertyConfig.getFileEncPasswd().getBytes()));
UserThreadLocal.setSuccessInfo("", prjId, "导入本地工程成功"); UserThreadLocal.setSuccessInfo("", prjId, "导入本地工程成功");
} catch (Exception e) { } catch (Exception e) {
throw new BizException("导入工程失败,原因 " + e.getMessage(), e); throw new BizException("导入工程失败,原因 " + e.getMessage(), e);

View File

@ -61,4 +61,6 @@ tmp.file.store.hour=48
backup.remote.host=127.0.0.1 backup.remote.host=127.0.0.1
backup.remote.port=1111 backup.remote.port=1111
backup.mysql.path=/workspace/mysqlbak/test backup.mysql.path=/workspace/mysqlbak/test
backup.mysql.script.path=/workspace/mysqlbak/back_dev.sh backup.mysql.script.path=/workspace/mysqlbak/back_dev.sh
file.enc.passwd=123456

View File

@ -14,8 +14,6 @@ public interface ElectromagneticConstants {
String NAME_VALID_MSG = "不符合规范只能包含中文字符、下划线、连字符、加号、数字和英文字符且长度小于32。"; String NAME_VALID_MSG = "不符合规范只能包含中文字符、下划线、连字符、加号、数字和英文字符且长度小于32。";
String FILE_SEC_PASSWD = "adknfhkj87654knd";
String ED_FILE_FAVORITE = "ed_file_favorite"; String ED_FILE_FAVORITE = "ed_file_favorite";
String ED_FILE_RELATION = "ed_file_relation"; String ED_FILE_RELATION = "ed_file_relation";