fix: 优化生产环境报错逻辑
This commit is contained in:
parent
2c7b5b8bd1
commit
eadea5945c
@ -20,6 +20,7 @@ import com.yfd.platform.utils.SecurityUtils;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -34,6 +35,7 @@ import java.util.*;
|
||||
@RestController
|
||||
@RequestMapping("/data/fishDraft")
|
||||
@Tag(name = "过鱼数据")
|
||||
@Slf4j
|
||||
public class FishDraftDataController {
|
||||
|
||||
@Resource
|
||||
@ -211,18 +213,22 @@ public class FishDraftDataController {
|
||||
@PostMapping("/importZip")
|
||||
@Operation(summary = "导入ZIP过鱼数据(每个用户同时只能进行一次导入)")
|
||||
public ResponseResult importZip(@RequestParam("file") MultipartFile file) {
|
||||
log.info("开始导入ZIP文件");
|
||||
if (file == null || file.isEmpty()) {
|
||||
return ResponseResult.error("请上传文件");
|
||||
}
|
||||
log.info("开始上传文件");
|
||||
String fileName = file.getOriginalFilename();
|
||||
if (fileName == null || (!fileName.endsWith(".zip"))) {
|
||||
return ResponseResult.error("请上传ZIP文件(.zip)");
|
||||
}
|
||||
log.info("开始处理文件");
|
||||
String uploadUserId = SecurityUtils.getUserId();
|
||||
if (importTaskService.hasImportingTask(uploadUserId)) {
|
||||
return ResponseResult.error("您有正在进行的导入任务,请等待完成后重试");
|
||||
}
|
||||
|
||||
log.info("开始保存导入任务");
|
||||
String importNo = "IMP" + System.currentTimeMillis();
|
||||
String taskId = UUID.randomUUID().toString();
|
||||
|
||||
@ -236,8 +242,10 @@ public class FishDraftDataController {
|
||||
task.setStatus("UPLOADED");
|
||||
task.setUploadUserId(uploadUserId);
|
||||
task.setUploadTime(new Date());
|
||||
log.info("保存导入任务成功");
|
||||
importTaskService.save(task);
|
||||
|
||||
log.info("开始保存文件");
|
||||
FishImportRequest request = new FishImportRequest();
|
||||
request.setImportNo(importNo);
|
||||
request.setUploadUserId(uploadUserId);
|
||||
|
||||
@ -13,6 +13,7 @@ import com.yfd.platform.system.domain.SysDictionaryItems;
|
||||
import com.yfd.platform.system.service.ISysDictionaryItemsService;
|
||||
import com.yfd.platform.system.service.ISysDictionaryService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.stereotype.Service;
|
||||
@ -29,6 +30,7 @@ import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class FishImportServiceImpl implements IFishImportService {
|
||||
|
||||
@Resource
|
||||
@ -737,6 +739,7 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
FishImportResult result = new FishImportResult();
|
||||
|
||||
try {
|
||||
log.info("开始解析ZIP文件...");
|
||||
ZipFileUtil.ZipContent zipContent = ZipFileUtil.extractZipToTemp(file);
|
||||
|
||||
if (zipContent.excelFilePath == null) {
|
||||
@ -756,8 +759,10 @@ public class FishImportServiceImpl implements IFishImportService {
|
||||
result.setExcelFileName(zipContent.excelFileName);
|
||||
result.setExcelFilePath(zipContent.excelFilePath);
|
||||
|
||||
log.info("ZIP文件解析完成");
|
||||
processAttachments(result, zipContent);
|
||||
|
||||
log.info("ZIP文件处理完成");
|
||||
result.setSummary(result.getSummary() + String.format("\nZIP内容: 发现%d张图片, %d个视频, 临时目录: %s",
|
||||
zipContent.images.size(), zipContent.videos.size(), zipContent.tempDir));
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.yfd.platform.data.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
@ -18,6 +19,7 @@ import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ZipFileUtil {
|
||||
|
||||
private static String tempBaseDir;
|
||||
@ -76,14 +78,17 @@ public class ZipFileUtil {
|
||||
|
||||
String taskId = UUID.randomUUID().toString().substring(0, 8);
|
||||
Path tempDirPath = Paths.get(baseTempDir, "zip_" + taskId);
|
||||
|
||||
log.info("extractZipToTemp: {}", tempDirPath);
|
||||
Files.createDirectories(tempDirPath);
|
||||
content.tempDir = tempDirPath.toString();
|
||||
|
||||
File zipFile = new File(tempDirPath.toFile(), "upload.zip");
|
||||
file.transferTo(zipFile);
|
||||
|
||||
try {
|
||||
log.info("--------------isValidZipFile------------");
|
||||
if (!isValidZipFile(zipFile)) {
|
||||
log.info("--------------文件不是有效的ZIP格式或已损坏------------");
|
||||
throw new IOException("文件不是有效的ZIP格式或已损坏");
|
||||
}
|
||||
|
||||
@ -107,6 +112,7 @@ public class ZipFileUtil {
|
||||
}
|
||||
}
|
||||
|
||||
log.error("extractZipToTemp: {}", lastException.getMessage());
|
||||
throw lastException != null ? lastException : new IOException("无法解析ZIP文件");
|
||||
|
||||
} finally {
|
||||
|
||||
@ -1,5 +1,8 @@
|
||||
package com.yfd.platform.utils;
|
||||
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
/**
|
||||
@ -189,9 +192,13 @@ public class PasswordGenerator {
|
||||
|
||||
public static void main(String[] args) {
|
||||
configure(10, 12);
|
||||
String username = "admin";
|
||||
String username = "button";
|
||||
String resetPwd = generateRandomPassword(username);
|
||||
|
||||
PasswordEncoder passwordEncoder=new BCryptPasswordEncoder();
|
||||
String cryptPassword = passwordEncoder.encode(resetPwd);
|
||||
System.out.println("Generated password: " + resetPwd);
|
||||
System.out.println("Generated cryptPassword: " + cryptPassword);
|
||||
System.out.println("Password length: " + resetPwd.length());
|
||||
System.out.println("First char: '" + resetPwd.charAt(0) + "' (is special: " + !isNormalChar(resetPwd.charAt(0)) + ")");
|
||||
System.out.println("Last char: '" + resetPwd.charAt(resetPwd.length() - 1) + "' (is special: " + !isNormalChar(resetPwd.charAt(resetPwd.length() - 1)) + ")");
|
||||
|
||||
@ -32,11 +32,11 @@ spring:
|
||||
|
||||
logging:
|
||||
file:
|
||||
name: logs/projectname.log
|
||||
name: logs/platform-dev.log
|
||||
level:
|
||||
com.genersoft.iot: debug
|
||||
com.genersoft.iot.vmp.storager.dao: info
|
||||
com.genersoft.iot.vmp.gb28181: info
|
||||
root: info
|
||||
com.yfd.platform: info
|
||||
com.yfd.platform.*.mapper: trace
|
||||
|
||||
# 在线文档: swagger-ui(生产环境建议关闭)
|
||||
swagger-ui:
|
||||
|
||||
@ -32,11 +32,11 @@ spring:
|
||||
|
||||
logging:
|
||||
file:
|
||||
name: logs/projectname.log
|
||||
name: logs/platform-dev.log
|
||||
level:
|
||||
com.genersoft.iot: debug
|
||||
com.genersoft.iot.vmp.storager.dao: info
|
||||
com.genersoft.iot.vmp.gb28181: info
|
||||
root: info
|
||||
com.yfd.platform: info
|
||||
com.yfd.platform.*.mapper: trace
|
||||
|
||||
# 在线文档: swagger-ui(生产环境建议关闭)
|
||||
swagger-ui:
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
spring:
|
||||
profiles:
|
||||
active: prod
|
||||
active: devtw
|
||||
|
||||
jasypt:
|
||||
encryptor:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user