优化
This commit is contained in:
@ -1,8 +1,10 @@
|
|||||||
package com.ruoyi.web.controller.common;
|
package com.ruoyi.web.controller.common;
|
||||||
|
|
||||||
|
import cn.hutool.crypto.digest.DigestUtil;
|
||||||
import com.ruoyi.bgt.domain.BgtProjectRecruit;
|
import com.ruoyi.bgt.domain.BgtProjectRecruit;
|
||||||
import com.ruoyi.bgt.domain.dto.BgtUploadDTO;
|
import com.ruoyi.bgt.domain.dto.BgtUploadDTO;
|
||||||
import com.ruoyi.bgt.service.IBgtProjectRecruitService;
|
import com.ruoyi.bgt.service.IBgtProjectRecruitService;
|
||||||
|
import com.ruoyi.common.utils.PinYinUtil;
|
||||||
import com.ruoyi.wgz.domain.WgzUser;
|
import com.ruoyi.wgz.domain.WgzUser;
|
||||||
import com.ruoyi.wgz.service.IWgzUserService;
|
import com.ruoyi.wgz.service.IWgzUserService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@ -50,7 +52,8 @@ public class TemplateDownloadController {
|
|||||||
public ResponseEntity<Resource> downloadFolders(@RequestBody BgtUploadDTO dto) {
|
public ResponseEntity<Resource> downloadFolders(@RequestBody BgtUploadDTO dto) {
|
||||||
|
|
||||||
BgtProjectRecruit recruit = recruitService.queryById(dto.getRecruitId());
|
BgtProjectRecruit recruit = recruitService.queryById(dto.getRecruitId());
|
||||||
String firstLevelFolderName = recruit.getId() + "_" + recruit.getRecruitName();
|
String s = DigestUtil.md5Hex(recruit.getRecruitName());
|
||||||
|
String firstLevelFolderName = recruit.getId() + "_" + s;
|
||||||
|
|
||||||
File baseDir = new File(TEMP_DIR);
|
File baseDir = new File(TEMP_DIR);
|
||||||
File folderToZip = new File(baseDir, firstLevelFolderName);
|
File folderToZip = new File(baseDir, firstLevelFolderName);
|
||||||
@ -93,7 +96,8 @@ public class TemplateDownloadController {
|
|||||||
// 获取招工名
|
// 获取招工名
|
||||||
BgtProjectRecruit recruit = recruitService.queryById(dto.getRecruitId());
|
BgtProjectRecruit recruit = recruitService.queryById(dto.getRecruitId());
|
||||||
// 第一层文件夹名
|
// 第一层文件夹名
|
||||||
String firstLevelFolderName = recruit.getId() + "_" + recruit.getRecruitName();
|
String s = DigestUtil.md5Hex(recruit.getRecruitName());
|
||||||
|
String firstLevelFolderName = recruit.getId() + "_" + s;
|
||||||
File baseDir = new File(TEMP_DIR);
|
File baseDir = new File(TEMP_DIR);
|
||||||
if (!baseDir.exists()) {
|
if (!baseDir.exists()) {
|
||||||
if (!baseDir.mkdirs()) {
|
if (!baseDir.mkdirs()) {
|
||||||
@ -122,7 +126,7 @@ public class TemplateDownloadController {
|
|||||||
String userName = wgzUser.getUsername();
|
String userName = wgzUser.getUsername();
|
||||||
String idCard = wgzUser.getIdentityCard();
|
String idCard = wgzUser.getIdentityCard();
|
||||||
// 第二层文件夹名
|
// 第二层文件夹名
|
||||||
String secondLevelFolderName = userName + "_" + idCard;
|
String secondLevelFolderName = PinYinUtil.getChineseNameInitials(userName) + "_" + idCard;
|
||||||
|
|
||||||
byte[] bytes2 = secondLevelFolderName.getBytes(StandardCharsets.UTF_8);
|
byte[] bytes2 = secondLevelFolderName.getBytes(StandardCharsets.UTF_8);
|
||||||
// 将 UTF - 8 字节数组转换回字符串
|
// 将 UTF - 8 字节数组转换回字符串
|
||||||
@ -139,7 +143,7 @@ public class TemplateDownloadController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 创建第三层的两个固定文件夹
|
// 创建第三层的两个固定文件夹
|
||||||
String[] thirdLevelFolderNames = {"劳务合同", "保险"};
|
String[] thirdLevelFolderNames = {"HeTong", "BaoXian"};
|
||||||
for (String thirdLevelFolderName : thirdLevelFolderNames) {
|
for (String thirdLevelFolderName : thirdLevelFolderNames) {
|
||||||
byte[] bytes3 = thirdLevelFolderName.getBytes(StandardCharsets.UTF_8);
|
byte[] bytes3 = thirdLevelFolderName.getBytes(StandardCharsets.UTF_8);
|
||||||
// 将 UTF - 8 字节数组转换回字符串
|
// 将 UTF - 8 字节数组转换回字符串
|
||||||
|
@ -169,6 +169,11 @@
|
|||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.belerweb</groupId>
|
||||||
|
<artifactId>pinyin4j</artifactId>
|
||||||
|
<version>2.5.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.ruoyi.common.utils;
|
||||||
|
|
||||||
|
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||||
|
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
|
||||||
|
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
|
||||||
|
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
|
||||||
|
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
|
||||||
|
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
|
||||||
|
|
||||||
|
public class PinYinUtil {
|
||||||
|
|
||||||
|
public static String getChineseNameInitials(String chineseName) {
|
||||||
|
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
|
||||||
|
// 设置拼音大小写格式为大写
|
||||||
|
format.setCaseType(HanyuPinyinCaseType.UPPERCASE);
|
||||||
|
// 设置拼音声调格式为无音调
|
||||||
|
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
|
||||||
|
// 设置 ü 的显示格式
|
||||||
|
format.setVCharType(HanyuPinyinVCharType.WITH_V);
|
||||||
|
|
||||||
|
StringBuilder initials = new StringBuilder();
|
||||||
|
for (char c : chineseName.toCharArray()) {
|
||||||
|
if (Character.toString(c).matches("[\\u4E00-\\u9FA5]+")) {
|
||||||
|
try {
|
||||||
|
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(c, format);
|
||||||
|
if (pinyinArray != null) {
|
||||||
|
// 取拼音的首字母
|
||||||
|
initials.append(pinyinArray[0].charAt(0));
|
||||||
|
}
|
||||||
|
} catch (BadHanyuPinyinOutputFormatCombination e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 非中文字符直接添加
|
||||||
|
initials.append(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return initials.toString();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user