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