优化
This commit is contained in:
@ -93,6 +93,13 @@ public class AppBgtProjectRecruitApplyController extends BaseController {
|
||||
return AjaxResult.success(iBgtProjectRecruitApplyService.confirm(id));
|
||||
}
|
||||
|
||||
@ApiOperation("App检查材料")
|
||||
@GetMapping("/check/{id}")
|
||||
public AjaxResult<Boolean> check(@NotNull(message = "主键不能为空")
|
||||
@PathVariable("id") Long id) {
|
||||
return AjaxResult.success(false);
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("App务工者退场")
|
||||
@Log(title = "App务工者退场", businessType = BusinessType.UPDATE)
|
||||
|
@ -1,6 +1,15 @@
|
||||
package com.ruoyi.web.controller.common;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import com.ruoyi.bgt.domain.BgtProjectRecruit;
|
||||
import com.ruoyi.bgt.service.IBgtProjectRecruitService;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.common.domain.Annex;
|
||||
import com.ruoyi.common.domain.AnnexRecord;
|
||||
import com.ruoyi.common.service.IAnnexRecordService;
|
||||
import com.ruoyi.common.service.IAnnexService;
|
||||
import com.ruoyi.common.utils.SecurityUtils;
|
||||
import com.ruoyi.wgz.domain.WgzUser;
|
||||
import com.ruoyi.wgz.service.IWgzUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
@ -14,6 +23,10 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@ -27,13 +40,19 @@ import java.util.zip.ZipInputStream;
|
||||
@RestController()
|
||||
public class UploadZipController {
|
||||
|
||||
@Autowired
|
||||
private IWgzUserService wgzUserService;
|
||||
|
||||
@Autowired
|
||||
private IBgtProjectRecruitService recruitService;
|
||||
private final IWgzUserService wgzUserService;
|
||||
|
||||
private static final String TEMP_DIR = "ruoyi/uploadPath/temporary";
|
||||
private final IBgtProjectRecruitService recruitService;
|
||||
|
||||
private final IAnnexService annexService;
|
||||
|
||||
private final IAnnexRecordService annexRecordService;
|
||||
|
||||
private static final String TEMP_DIR = "ruoyi/uploadPath/temporaryZip";
|
||||
|
||||
private static final String SAVE_DIR = "ruoyi/uploadPath/recruit";
|
||||
private static final String RECORD_DIR = "ruoyi/uploadPath/record";
|
||||
|
||||
|
||||
@ApiOperation("上传压缩文件")
|
||||
@ -52,13 +71,18 @@ public class UploadZipController {
|
||||
}
|
||||
|
||||
// 解压压缩文件
|
||||
File extractDir = new File(TEMP_DIR, "extracted");
|
||||
BgtProjectRecruit recruit = recruitService.queryById(recruitId);
|
||||
String firstLevelFolderName = recruit.getId() + "_" + recruit.getRecruitName();
|
||||
File extractDir = new File(TEMP_DIR, firstLevelFolderName);
|
||||
ensureDirectoryExists(extractDir);
|
||||
extractZipFile(zipFile, extractDir);
|
||||
|
||||
// 处理解压后的文件夹
|
||||
processExtractedFolder(extractDir, recruitId);
|
||||
|
||||
// 将解压后的文件移动到 SAVE_DIR 和 RECORD_DIR
|
||||
moveFilesToSaveDir(extractDir, recruitId);
|
||||
|
||||
// 删除临时文件和文件夹
|
||||
deleteFolder(extractDir);
|
||||
if (!zipFile.delete()) {
|
||||
@ -121,33 +145,26 @@ public class UploadZipController {
|
||||
File[] firstLevelFiles = extractDir.listFiles();
|
||||
if (firstLevelFiles != null) {
|
||||
for (File firstLevelFile : firstLevelFiles) {
|
||||
String firstLevelFolderName = firstLevelFile.getName();
|
||||
System.out.println("第一层文件夹名称: " + firstLevelFolderName);
|
||||
String[] split = firstLevelFolderName.split("_");
|
||||
String card = split[1];
|
||||
WgzUser wgzUser = wgzUserService.findByIdentityCard(card);
|
||||
if (firstLevelFile.isDirectory()) {
|
||||
File[] secondLevelFiles = firstLevelFile.listFiles();
|
||||
if (secondLevelFiles != null) {
|
||||
for (File secondLevelFile : secondLevelFiles) {
|
||||
String secondLevelFolderName = secondLevelFile.getName();
|
||||
System.out.println("第二层文件夹名称: " + secondLevelFolderName);
|
||||
if (secondLevelFile.isDirectory()) {
|
||||
File[] thirdLevelFiles = secondLevelFile.listFiles();
|
||||
if (thirdLevelFiles != null) {
|
||||
for (File thirdLevelFile : thirdLevelFiles) {
|
||||
if (!thirdLevelFile.isDirectory()) {
|
||||
String fullPath = firstLevelFile.getName() + "/" + secondLevelFile.getName() + "/" + thirdLevelFile.getName();
|
||||
System.out.println("完整路径: " + fullPath);
|
||||
String thirdLevelFolderName = secondLevelFile.getName();
|
||||
System.out.println("第三层文件夹名称: " + thirdLevelFolderName);
|
||||
// 这里可以添加你需要的处理逻辑,比如保存到数据库等
|
||||
// 以下是数据库操作示例,根据实际情况修改
|
||||
String folderName = secondLevelFile.getName();
|
||||
String[] parts = folderName.split("_");
|
||||
if (parts.length > 1) {
|
||||
String idCard = parts[1];
|
||||
System.out.println("身份证: " + idCard);
|
||||
// 新增逻辑,根据实际情况实现
|
||||
// WgzUser user = new WgzUser();
|
||||
// user.setRecruitId(recruitId);
|
||||
// user.setIdentityCard(idCard);
|
||||
// wgzUserService.save(user);
|
||||
}
|
||||
}
|
||||
//删除数据库里的附件
|
||||
if("保险".equals(secondLevelFolderName)){
|
||||
annexService.deleteByUserIdAndRecruitIdAndType(wgzUser.getUserId(), recruitId, "2");
|
||||
}
|
||||
if("劳务合同".equals(secondLevelFolderName)){
|
||||
annexService.deleteByUserIdAndRecruitIdAndType(wgzUser.getUserId(), recruitId, "1");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -158,6 +175,180 @@ public class UploadZipController {
|
||||
}
|
||||
}
|
||||
|
||||
private void moveFilesToSaveDir(File sourceDir, Long recruitId) throws IOException {
|
||||
// 移动到 SAVE_DIR
|
||||
File saveDestDir = new File(SAVE_DIR);
|
||||
ensureDirectoryExists(saveDestDir);
|
||||
|
||||
BgtProjectRecruit recruit = recruitService.queryById(recruitId);
|
||||
String firstLevelFolderName = recruit.getId() + "_" + recruit.getRecruitName();
|
||||
File firstLevelDestDir = new File(saveDestDir, firstLevelFolderName);
|
||||
ensureDirectoryExists(firstLevelDestDir);
|
||||
|
||||
File[] firstLevelFiles = sourceDir.listFiles();
|
||||
List<Annex> annexList = new ArrayList<>();
|
||||
if (firstLevelFiles != null) {
|
||||
for (File firstLevelFile : firstLevelFiles) {
|
||||
if (firstLevelFile.isDirectory()) {
|
||||
String secondLevelName = firstLevelFile.getName();
|
||||
File secondLevelDestDir = new File(firstLevelDestDir, secondLevelName);
|
||||
if (secondLevelDestDir.exists()) {
|
||||
// 删除和解压出来的二级目录同名字的目录
|
||||
deleteFolder(secondLevelDestDir);
|
||||
}
|
||||
moveFilesRecursively(firstLevelFile, firstLevelDestDir,annexList,recruitId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(annexList)){
|
||||
annexService.saveBatch(annexList);
|
||||
}
|
||||
|
||||
// 移动到 RECORD_DIR
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||
String timeStamp = LocalDateTime.now().format(formatter);
|
||||
File recordDestDir = new File(RECORD_DIR, firstLevelFolderName);
|
||||
ensureDirectoryExists(recordDestDir);
|
||||
|
||||
List<AnnexRecord> annexRecordList = new ArrayList<>();
|
||||
moveFilesToRecordDirRecursively(sourceDir, recordDestDir, timeStamp,annexRecordList,recruitId);
|
||||
|
||||
if(CollectionUtil.isNotEmpty(annexRecordList)){
|
||||
annexRecordService.saveBatch(annexRecordList);
|
||||
}
|
||||
}
|
||||
|
||||
private void moveFilesRecursively(File source, File destination,List<Annex> annexList,Long recruitId) throws IOException {
|
||||
if (source.isDirectory()) {
|
||||
File newDir = new File(destination, source.getName());
|
||||
ensureDirectoryExists(newDir);
|
||||
File[] files = source.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
moveFilesRecursively(file, newDir,annexList,recruitId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
File destFile = new File(destination, source.getName());
|
||||
ensureDirectoryExists(destFile.getParentFile());
|
||||
try (InputStream in = new FileInputStream(source);
|
||||
OutputStream out = new FileOutputStream(destFile)) {
|
||||
byte[] buffer = new byte[4096];
|
||||
int length;
|
||||
while ((length = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
}
|
||||
String relativePath = SAVE_DIR + File.separator + getRelativePath(source, new File(TEMP_DIR));
|
||||
relativePath = relativePath.replace("\\", "/").replace("ruoyi/uploadPath", "/profile");
|
||||
System.out.println("文件在项目里的相对目录: " + relativePath);
|
||||
//存到数据库
|
||||
String parentName= destination.getParentFile().getName();
|
||||
System.out.println("上上一级文件名: "+parentName);
|
||||
String[] split = parentName.split("_");
|
||||
String card = split[1];
|
||||
WgzUser wgzUser = wgzUserService.findByIdentityCard(card);
|
||||
|
||||
String name = destination.getName();
|
||||
System.out.println("上一级文件名: "+name);
|
||||
String type = "";
|
||||
if("保险".equals(name)){
|
||||
type= "2";
|
||||
}
|
||||
if("劳务合同".equals(name)){
|
||||
type="1";
|
||||
}
|
||||
Annex annex = new Annex();
|
||||
annex.setAnnexName(destFile.getName());
|
||||
annex.setAnnexUrl(relativePath);
|
||||
annex.setAnnexType(type);
|
||||
annex.setUserType(Constants.WGZ);
|
||||
annex.setUserId(wgzUser.getUserId());
|
||||
annex.setRecruitId(recruitId);
|
||||
annex.setCreateBy(SecurityUtils.getUsername());
|
||||
annex.setUpdateBy(SecurityUtils.getUsername());
|
||||
annexList.add(annex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void moveFilesToRecordDirRecursively(File source, File destination, String timeStamp, List<AnnexRecord> annexRecordList, Long recruitId) throws IOException {
|
||||
if (source.isDirectory()) {
|
||||
String folderName = source.getName();
|
||||
String[] parts = folderName.split("_");
|
||||
if (parts.length > 0 && parts[0].matches("\\d+") && parts.length > 1) {
|
||||
// 如果parts第一部分是数字并且长度大于1,跳过这一级目录的创建,直接处理下一级目录
|
||||
File[] files = source.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
moveFilesToRecordDirRecursively(file, destination, timeStamp,annexRecordList,recruitId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (parts.length > 1) {
|
||||
folderName = folderName + "_" + timeStamp;
|
||||
}
|
||||
File newDir = new File(destination, folderName);
|
||||
ensureDirectoryExists(newDir);
|
||||
File[] files = source.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
moveFilesToRecordDirRecursively(file, newDir, timeStamp,annexRecordList,recruitId);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
File destFile = new File(destination, source.getName());
|
||||
ensureDirectoryExists(destFile.getParentFile());
|
||||
try (InputStream in = new FileInputStream(source);
|
||||
OutputStream out = new FileOutputStream(destFile)) {
|
||||
byte[] buffer = new byte[4096];
|
||||
int length;
|
||||
while ((length = in.read(buffer)) > 0) {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
}
|
||||
String relativePath = RECORD_DIR + File.separator + getRelativePath(source, new File(TEMP_DIR));
|
||||
relativePath = relativePath.replace("\\", "/").replace("ruoyi/uploadPath", "/profile");
|
||||
System.out.println("文件在记录目录里的相对目录: " + relativePath);
|
||||
|
||||
//存到数据库作为记录
|
||||
String parentName= destination.getParentFile().getName();
|
||||
System.out.println("上上一级文件名: "+parentName);
|
||||
String[] split = parentName.split("_");
|
||||
String card = split[1];
|
||||
WgzUser wgzUser = wgzUserService.findByIdentityCard(card);
|
||||
|
||||
String name = destination.getName();
|
||||
System.out.println("上一级文件名: "+name);
|
||||
String type = "";
|
||||
if("保险".equals(name)){
|
||||
type= "2";
|
||||
}
|
||||
if("劳务合同".equals(name)){
|
||||
type="1";
|
||||
}
|
||||
AnnexRecord annex = new AnnexRecord();
|
||||
annex.setAnnexName(destFile.getName());
|
||||
annex.setAnnexUrl(relativePath);
|
||||
annex.setAnnexType(type);
|
||||
annex.setUserType(Constants.WGZ);
|
||||
annex.setUserId(wgzUser.getUserId());
|
||||
annex.setRecruitId(recruitId);
|
||||
annex.setCreateBy(SecurityUtils.getUsername());
|
||||
annex.setUpdateBy(SecurityUtils.getUsername());
|
||||
annex.setCreateUserId(SecurityUtils.getAppUserId());
|
||||
annex.setCreateUserType(Constants.BGT);
|
||||
annexRecordList.add(annex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private String getRelativePath(File file, File baseDir) {
|
||||
String filePath = file.getAbsolutePath();
|
||||
String basePath = baseDir.getAbsolutePath();
|
||||
return filePath.substring(basePath.length() + 1);
|
||||
}
|
||||
|
||||
private static void deleteFolder(File folder) {
|
||||
if (folder.isDirectory()) {
|
||||
|
Reference in New Issue
Block a user