优化
This commit is contained in:
@ -126,7 +126,7 @@ public class TemplateDownloadController {
|
|||||||
String userName = wgzUser.getUsername();
|
String userName = wgzUser.getUsername();
|
||||||
String idCard = wgzUser.getIdentityCard();
|
String idCard = wgzUser.getIdentityCard();
|
||||||
// 第二层文件夹名
|
// 第二层文件夹名
|
||||||
String secondLevelFolderName = PinYinUtil.getChineseNameInitials(userName) + "_" + idCard;
|
String secondLevelFolderName = PinYinUtil.chineseToFullPinyin(userName) + "_" + idCard;
|
||||||
|
|
||||||
byte[] bytes2 = secondLevelFolderName.getBytes(StandardCharsets.UTF_8);
|
byte[] bytes2 = secondLevelFolderName.getBytes(StandardCharsets.UTF_8);
|
||||||
// 将 UTF - 8 字节数组转换回字符串
|
// 将 UTF - 8 字节数组转换回字符串
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.ruoyi.web.controller.common;
|
package com.ruoyi.web.controller.common;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
import com.ruoyi.bgt.domain.BgtProjectRecruit;
|
import com.ruoyi.bgt.domain.BgtProjectRecruit;
|
||||||
import com.ruoyi.bgt.domain.BgtProjectRecruitApply;
|
import com.ruoyi.bgt.domain.BgtProjectRecruitApply;
|
||||||
import com.ruoyi.bgt.service.IBgtProjectRecruitApplyService;
|
import com.ruoyi.bgt.service.IBgtProjectRecruitApplyService;
|
||||||
@ -29,7 +30,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -78,8 +79,8 @@ public class UploadZipController {
|
|||||||
if(split.length != 2 || !split[0].equals(recruitId.toString())){
|
if(split.length != 2 || !split[0].equals(recruitId.toString())){
|
||||||
throw new BaseException("文件名与所选择招工不匹配");
|
throw new BaseException("文件名与所选择招工不匹配");
|
||||||
}
|
}
|
||||||
|
BgtProjectRecruit recruit = recruitService.queryById(recruitId);
|
||||||
if(recruitService.queryById(recruitId) == null){
|
if( recruit== null){
|
||||||
throw new BaseException("招工信息不存在!");
|
throw new BaseException("招工信息不存在!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,15 +93,15 @@ public class UploadZipController {
|
|||||||
String firstLevelFolderName ="";
|
String firstLevelFolderName ="";
|
||||||
try {
|
try {
|
||||||
// 保存上传的压缩文件
|
// 保存上传的压缩文件
|
||||||
File zipFile = new File(TEMP_DIR, file.getOriginalFilename());
|
String s = DigestUtil.md5Hex(recruit.getRecruitName());
|
||||||
|
firstLevelFolderName = recruitId + "_" + s;
|
||||||
|
File zipFile = new File(TEMP_DIR, firstLevelFolderName);
|
||||||
ensureDirectoryExists(zipFile.getParentFile());
|
ensureDirectoryExists(zipFile.getParentFile());
|
||||||
try (OutputStream os = new FileOutputStream(zipFile)) {
|
try (OutputStream os = new FileOutputStream(zipFile)) {
|
||||||
os.write(file.getBytes());
|
os.write(file.getBytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解压压缩文件
|
// 解压压缩文件
|
||||||
BgtProjectRecruit recruit = recruitService.queryById(recruitId);
|
|
||||||
firstLevelFolderName = recruit.getId() + "_" + recruit.getRecruitName();
|
|
||||||
File extractDir = new File(TEMP_DIR, firstLevelFolderName);
|
File extractDir = new File(TEMP_DIR, firstLevelFolderName);
|
||||||
ensureDirectoryExists(extractDir);
|
ensureDirectoryExists(extractDir);
|
||||||
extractZipFile(zipFile, extractDir);
|
extractZipFile(zipFile, extractDir);
|
||||||
@ -163,7 +164,7 @@ public class UploadZipController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void extractZipFile(File zipFile, File extractDir) throws IOException {
|
private void extractZipFile(File zipFile, File extractDir) throws IOException {
|
||||||
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile), Charset.forName("GBK"))) {
|
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile), StandardCharsets.UTF_8)) {
|
||||||
ZipEntry zipEntry;
|
ZipEntry zipEntry;
|
||||||
while ((zipEntry = zis.getNextEntry()) != null) {
|
while ((zipEntry = zis.getNextEntry()) != null) {
|
||||||
File newFile = newFile(extractDir, zipEntry);
|
File newFile = newFile(extractDir, zipEntry);
|
||||||
@ -235,10 +236,10 @@ public class UploadZipController {
|
|||||||
File[] thirdLevelFiles = secondLevelFile.listFiles();
|
File[] thirdLevelFiles = secondLevelFile.listFiles();
|
||||||
if (thirdLevelFiles != null && thirdLevelFiles.length > 0) {
|
if (thirdLevelFiles != null && thirdLevelFiles.length > 0) {
|
||||||
// 删除数据库里的附件
|
// 删除数据库里的附件
|
||||||
if ("保险".equals(secondLevelFolderName)) {
|
if ("BaoXian".equals(secondLevelFolderName)) {
|
||||||
insurance.add(wgzUser.getUserId());
|
insurance.add(wgzUser.getUserId());
|
||||||
}
|
}
|
||||||
if ("劳务合同".equals(secondLevelFolderName)) {
|
if ("HeTong".equals(secondLevelFolderName)) {
|
||||||
contract.add(wgzUser.getUserId());
|
contract.add(wgzUser.getUserId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,10 +336,10 @@ public class UploadZipController {
|
|||||||
String name = destination.getName();
|
String name = destination.getName();
|
||||||
System.out.println("上一级文件名: " + name);
|
System.out.println("上一级文件名: " + name);
|
||||||
String type = "";
|
String type = "";
|
||||||
if ("保险".equals(name)) {
|
if ("BaoXian".equals(name)) {
|
||||||
type = "2";
|
type = "2";
|
||||||
}
|
}
|
||||||
if ("劳务合同".equals(name)) {
|
if ("HeTong".equals(name)) {
|
||||||
type = "1";
|
type = "1";
|
||||||
}
|
}
|
||||||
Annex annex = new Annex();
|
Annex annex = new Annex();
|
||||||
@ -411,10 +412,10 @@ public class UploadZipController {
|
|||||||
|
|
||||||
String name = destination.getName();
|
String name = destination.getName();
|
||||||
String type = "";
|
String type = "";
|
||||||
if ("保险".equals(name)) {
|
if ("BaoXian".equals(name)) {
|
||||||
type = "2";
|
type = "2";
|
||||||
}
|
}
|
||||||
if ("劳务合同".equals(name)) {
|
if ("HeTong".equals(name)) {
|
||||||
type = "1";
|
type = "1";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,32 +9,32 @@ import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombi
|
|||||||
|
|
||||||
public class PinYinUtil {
|
public class PinYinUtil {
|
||||||
|
|
||||||
public static String getChineseNameInitials(String chineseName) {
|
public static String chineseToFullPinyin(String chinese) {
|
||||||
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
|
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
|
||||||
// 设置拼音大小写格式为大写
|
// 设置拼音大小写格式为小写
|
||||||
format.setCaseType(HanyuPinyinCaseType.UPPERCASE);
|
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
|
||||||
// 设置拼音声调格式为无音调
|
// 设置拼音声调格式为无音调
|
||||||
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
||||||
// 设置 ü 的显示格式
|
// 设置 ü 的显示格式
|
||||||
format.setVCharType(HanyuPinyinVCharType.WITH_V);
|
format.setVCharType(HanyuPinyinVCharType.WITH_V);
|
||||||
|
|
||||||
StringBuilder initials = new StringBuilder();
|
StringBuilder pinyin = new StringBuilder();
|
||||||
for (char c : chineseName.toCharArray()) {
|
for (char c : chinese.toCharArray()) {
|
||||||
if (Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) {
|
if (Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) {
|
||||||
try {
|
try {
|
||||||
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, format);
|
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, format);
|
||||||
if (pinyinArray != null) {
|
if (pinyinArray != null) {
|
||||||
// 取拼音的首字母
|
// 取第一个拼音结果添加到结果中
|
||||||
initials.append(pinyinArray[0].charAt(0));
|
pinyin.append(pinyinArray[0]);
|
||||||
}
|
}
|
||||||
} catch (BadHanyuPinyinOutputFormatCombination e) {
|
} catch (BadHanyuPinyinOutputFormatCombination e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 非中文字符直接添加
|
// 非中文字符直接添加
|
||||||
initials.append(c);
|
pinyin.append(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return initials.toString();
|
return pinyin.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user