add:第一版测试版本功能优化。1.F机器人修改调度上报异常信息,后端存储异常信息和异常处理,增加异常信息和异常处理方法excel导入功能。2.添加密码校验、修改密码功能。

This commit is contained in:
2026-01-04 09:34:07 +08:00
parent 6e554b6bf7
commit acf269e92a
33 changed files with 1089 additions and 9 deletions

View File

@@ -0,0 +1,23 @@
package org.nl.util;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
* @author dsh
* 2025/12/29
*/
@Component
public class FileConstant {
public static String ERROR_IMAGE_PATH = "";
@Resource
private FileProperties properties;
@Value("${customize.errorImage-dir}")
public void setErrorImagePath(String errorImagePath) {
FileConstant.ERROR_IMAGE_PATH = properties.getPath().getPath()+errorImagePath;
}
}

View File

@@ -0,0 +1,128 @@
package org.nl.util;
import lombok.extern.slf4j.Slf4j;
import org.nl.exception.BadRequestException;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
/**
* @author dsh
* 2025/12/29
*/
@Slf4j
@Service
public class ParseZip {
/**
* 处理上传的异常文件
* @param file
* @throws IOException
*/
public void processCompressedFile(MultipartFile file) throws IOException {
List<String> skippedFiles = new ArrayList<>();
String filename = file.getOriginalFilename();
String extension = filename.substring(filename.lastIndexOf("."));
try (InputStream inputStream = file.getInputStream()) {
if (extension.toLowerCase().equals(".zip")) {
extractZipFile(inputStream, skippedFiles);
} else {
throw new BadRequestException("不支持的压缩格式: " + extension);
}
}
}
/**
* 解压上传异常图片压缩文件
* @param inputStream
* @param skippedFiles
* @throws IOException
*/
private void extractZipFile(InputStream inputStream, List<String> skippedFiles)
throws IOException {
int processedCount = 0;
int skippedCount = 0;
try (ZipInputStream zipInputStream = new ZipInputStream(inputStream)) {
ZipEntry entry;
while ((entry = zipInputStream.getNextEntry()) != null) {
if (!entry.isDirectory() && isImageFile(entry.getName())) {
String filename = new File(entry.getName()).getName();
if (isFileExists(filename)) {
skippedFiles.add(filename);
skippedCount++;
continue;
}
if (saveImageFile(zipInputStream, filename)) {
processedCount++;
}
}
zipInputStream.closeEntry();
}
}
log.info("处理文件数:{},跳过文件数:{},跳过文件名称集合:{}",processedCount,skippedCount,skippedFiles);
}
/**
* 保存图片文件到目录
* @param inputStream
* @param filename
* @return
*/
private boolean saveImageFile(InputStream inputStream, String filename) {
try {
File outputFile = new File(FileConstant.ERROR_IMAGE_PATH + "/" + filename);
// 确保目录存在
File parentDir = outputFile.getParentFile();
if (!parentDir.exists()) {
parentDir.mkdirs();
}
Files.copy(inputStream, outputFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
return true;
} catch (IOException e) {
log.error("保存文件失败: " + filename, e);
return false;
}
}
/**
* 判断是否是图片文件或者视频文件
* @param filename
* @return
*/
private boolean isImageFile(String filename) {
String lowerCaseFilename = filename.toLowerCase();
return lowerCaseFilename.endsWith(".jpg") ||
lowerCaseFilename.endsWith(".jpeg") ||
lowerCaseFilename.endsWith(".png") ||
lowerCaseFilename.endsWith(".gif") ||
lowerCaseFilename.endsWith(".bmp") ||
lowerCaseFilename.endsWith(".webp")||
lowerCaseFilename.endsWith(".mp4");
}
/**
* 查看文件名是否有重名
* @param filename
* @return
*/
private boolean isFileExists(String filename) {
File targetFile = new File(FileConstant.ERROR_IMAGE_PATH+ "/" + filename);
return targetFile.exists();
}
}

View File

@@ -0,0 +1,90 @@
package org.nl.util;
import org.apache.tomcat.util.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.crypto.Cipher;
import java.security.*;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec;
/**
* @author liejiu
*/
@Component
public class RsaUtils {
public static String privateKey;
@Value("${rsa.private_key}")
public void setPrivateKey(String privateKey) {
RsaUtils.privateKey = privateKey;
}
public static void main(String[] args) throws Exception {
System.out.println("\n");
RsaKeyPair keyPair = generateKeyPair();
System.out.println("公钥:" + keyPair.getPublicKey());
System.out.println("私钥:" + keyPair.getPrivateKey());
}
/**
* 构建RSA密钥对
*
* @return /
* @throws NoSuchAlgorithmException /
*/
public static RsaKeyPair generateKeyPair() throws NoSuchAlgorithmException {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(1024);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
RSAPublicKey rsaPublicKey = (RSAPublicKey) keyPair.getPublic();
RSAPrivateKey rsaPrivateKey = (RSAPrivateKey) keyPair.getPrivate();
String publicKeyString = Base64.encodeBase64String(rsaPublicKey.getEncoded());
String privateKeyString = Base64.encodeBase64String(rsaPrivateKey.getEncoded());
return new RsaKeyPair(publicKeyString, privateKeyString);
}
/**
* RSA密钥对对象
*/
public static class RsaKeyPair {
private final String publicKey;
private final String privateKey;
public RsaKeyPair(String publicKey, String privateKey) {
this.publicKey = publicKey;
this.privateKey = privateKey;
}
public String getPublicKey() {
return publicKey;
}
public String getPrivateKey() {
return privateKey;
}
}
/**
* 私钥解密
*
* @param privateKeyText 私钥
* @param text 待解密的文本
* @return /
* @throws Exception /
*/
public static String decryptByPrivateKey(String privateKeyText, String text) throws Exception {
PKCS8EncodedKeySpec pkcs8EncodedKeySpec5 = new PKCS8EncodedKeySpec(Base64.decodeBase64(privateKeyText));
KeyFactory keyFactory = KeyFactory.getInstance("RSA");
PrivateKey privateKey = keyFactory.generatePrivate(pkcs8EncodedKeySpec5);
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, privateKey);
byte[] result = cipher.doFinal(Base64.decodeBase64(text));
return new String(result);
}
}