消息,确认进场
This commit is contained in:
@ -84,6 +84,15 @@ public class AppBgtProjectRecruitApplyController extends BaseController {
|
||||
return AjaxResult.success(iBgtProjectRecruitApplyService.consent(dto));
|
||||
}
|
||||
|
||||
@ApiOperation("App确认进场")
|
||||
@Log(title = "App确认进场", businessType = BusinessType.UPDATE)
|
||||
@RepeatSubmit
|
||||
@PutMapping("/confirm/{id}")
|
||||
public AjaxResult<Boolean> confirm(@NotNull(message = "主键不能为空")
|
||||
@PathVariable("id") Long id) {
|
||||
return AjaxResult.success(iBgtProjectRecruitApplyService.confirm(id));
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation("App务工者退场")
|
||||
@Log(title = "App务工者退场", businessType = BusinessType.UPDATE)
|
||||
|
@ -0,0 +1,175 @@
|
||||
package com.ruoyi.web.controller.common;
|
||||
|
||||
import com.ruoyi.bgt.service.IBgtProjectRecruitService;
|
||||
import com.ruoyi.wgz.service.IWgzUserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
/**
|
||||
* 登录验证
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Api(value = "网页模板上传", tags = {"网页模板上传"})
|
||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||
@RestController()
|
||||
public class UploadZipController {
|
||||
|
||||
@Autowired
|
||||
private IWgzUserService wgzUserService;
|
||||
|
||||
@Autowired
|
||||
private IBgtProjectRecruitService recruitService;
|
||||
|
||||
private static final String TEMP_DIR = "ruoyi/uploadPath/temporary";
|
||||
|
||||
|
||||
@ApiOperation("上传压缩文件")
|
||||
@PostMapping("/upload-zip")
|
||||
public ResponseEntity<String> uploadZipFile(@RequestParam("file") MultipartFile file, @RequestParam("recruitId") Long recruitId) {
|
||||
if (file.isEmpty()) {
|
||||
return ResponseEntity.badRequest().body("上传的文件为空");
|
||||
}
|
||||
|
||||
try {
|
||||
// 保存上传的压缩文件
|
||||
File zipFile = new File(TEMP_DIR, file.getOriginalFilename());
|
||||
ensureDirectoryExists(zipFile.getParentFile());
|
||||
try (OutputStream os = new FileOutputStream(zipFile)) {
|
||||
os.write(file.getBytes());
|
||||
}
|
||||
|
||||
// 解压压缩文件
|
||||
File extractDir = new File(TEMP_DIR, "extracted");
|
||||
ensureDirectoryExists(extractDir);
|
||||
extractZipFile(zipFile, extractDir);
|
||||
|
||||
// 处理解压后的文件夹
|
||||
processExtractedFolder(extractDir, recruitId);
|
||||
|
||||
// 删除临时文件和文件夹
|
||||
deleteFolder(extractDir);
|
||||
if (!zipFile.delete()) {
|
||||
System.err.println("无法删除压缩文件: " + zipFile.getAbsolutePath());
|
||||
}
|
||||
|
||||
return ResponseEntity.ok("文件上传并处理成功");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return ResponseEntity.status(500).body("文件处理过程中出现错误: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureDirectoryExists(File directory) throws IOException {
|
||||
if (!directory.exists()) {
|
||||
if (!directory.mkdirs()) {
|
||||
throw new IOException("无法创建目录: " + directory.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void extractZipFile(File zipFile, File extractDir) throws IOException {
|
||||
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(zipFile), Charset.forName("GBK"))) {
|
||||
ZipEntry zipEntry;
|
||||
while ((zipEntry = zis.getNextEntry()) != null) {
|
||||
File newFile = newFile(extractDir, zipEntry);
|
||||
if (zipEntry.isDirectory()) {
|
||||
ensureDirectoryExists(newFile);
|
||||
} else {
|
||||
// 为文件创建父目录
|
||||
ensureDirectoryExists(newFile.getParentFile());
|
||||
|
||||
// 写入文件内容
|
||||
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(newFile))) {
|
||||
byte[] bytesIn = new byte[4096];
|
||||
int read;
|
||||
while ((read = zis.read(bytesIn)) != -1) {
|
||||
bos.write(bytesIn, 0, read);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private File newFile(File destinationDir, ZipEntry zipEntry) throws IOException {
|
||||
File destFile = new File(destinationDir, zipEntry.getName());
|
||||
|
||||
String destDirPath = destinationDir.getCanonicalPath();
|
||||
String destFilePath = destFile.getCanonicalPath();
|
||||
|
||||
if (!destFilePath.startsWith(destDirPath + File.separator)) {
|
||||
throw new IOException("Entry is outside of the target dir: " + zipEntry.getName());
|
||||
}
|
||||
|
||||
return destFile;
|
||||
}
|
||||
|
||||
private void processExtractedFolder(File extractDir, Long recruitId) {
|
||||
File[] firstLevelFiles = extractDir.listFiles();
|
||||
if (firstLevelFiles != null) {
|
||||
for (File firstLevelFile : firstLevelFiles) {
|
||||
if (firstLevelFile.isDirectory()) {
|
||||
File[] secondLevelFiles = firstLevelFile.listFiles();
|
||||
if (secondLevelFiles != null) {
|
||||
for (File secondLevelFile : secondLevelFiles) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static void deleteFolder(File folder) {
|
||||
if (folder.isDirectory()) {
|
||||
File[] files = folder.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
deleteFolder(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!folder.delete()) {
|
||||
System.err.println("无法删除文件夹: " + folder.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user