优化
This commit is contained in:
@ -22,7 +22,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
@ -51,6 +51,7 @@ public class TemplateDownloadController {
|
||||
|
||||
BgtProjectRecruit recruit = recruitService.queryById(dto.getRecruitId());
|
||||
String firstLevelFolderName = recruit.getId() + "_" + recruit.getRecruitName();
|
||||
|
||||
File baseDir = new File(TEMP_DIR);
|
||||
File folderToZip = new File(baseDir, firstLevelFolderName);
|
||||
File zipFile = new File(baseDir, folderToZip.getName() + ".zip");
|
||||
@ -100,6 +101,10 @@ public class TemplateDownloadController {
|
||||
return;
|
||||
}
|
||||
}
|
||||
byte[] bytes = firstLevelFolderName.getBytes(StandardCharsets.UTF_8);
|
||||
// 将 UTF - 8 字节数组转换回字符串
|
||||
firstLevelFolderName = new String(bytes, StandardCharsets.UTF_8);
|
||||
|
||||
File firstLevelFolder = new File(baseDir, firstLevelFolderName);
|
||||
if (!firstLevelFolder.exists()) {
|
||||
if (firstLevelFolder.mkdirs()) {
|
||||
@ -118,6 +123,11 @@ public class TemplateDownloadController {
|
||||
String idCard = wgzUser.getIdentityCard();
|
||||
// 第二层文件夹名
|
||||
String secondLevelFolderName = userName + "_" + idCard;
|
||||
|
||||
byte[] bytes2 = secondLevelFolderName.getBytes(StandardCharsets.UTF_8);
|
||||
// 将 UTF - 8 字节数组转换回字符串
|
||||
secondLevelFolderName = new String(bytes2, StandardCharsets.UTF_8);
|
||||
|
||||
File secondLevelFolder = new File(firstLevelFolder, secondLevelFolderName);
|
||||
if (!secondLevelFolder.exists()) {
|
||||
if (secondLevelFolder.mkdirs()) {
|
||||
@ -131,6 +141,10 @@ public class TemplateDownloadController {
|
||||
// 创建第三层的两个固定文件夹
|
||||
String[] thirdLevelFolderNames = {"劳务合同", "保险"};
|
||||
for (String thirdLevelFolderName : thirdLevelFolderNames) {
|
||||
byte[] bytes3 = thirdLevelFolderName.getBytes(StandardCharsets.UTF_8);
|
||||
// 将 UTF - 8 字节数组转换回字符串
|
||||
thirdLevelFolderName = new String(bytes3, StandardCharsets.UTF_8);
|
||||
|
||||
File thirdLevelFolder = new File(secondLevelFolder, thirdLevelFolderName);
|
||||
if (!thirdLevelFolder.exists()) {
|
||||
if (thirdLevelFolder.mkdirs()) {
|
||||
@ -144,7 +158,7 @@ public class TemplateDownloadController {
|
||||
}
|
||||
|
||||
public static void zipFolder(File folder, File zipFile) throws IOException {
|
||||
try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile), Charset.forName("GBK"))) {
|
||||
try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile), StandardCharsets.UTF_8)) {
|
||||
// 去掉添加根文件夹这一步
|
||||
File[] subFiles = folder.listFiles();
|
||||
if (subFiles != null) {
|
||||
|
Reference in New Issue
Block a user