add:第一版测试版本,第二次联调。

This commit is contained in:
2025-12-26 15:27:54 +08:00
parent cd483c81d1
commit 6e554b6bf7
32 changed files with 903 additions and 73 deletions

View File

@@ -1,9 +1,11 @@
package org.nl.config;
import org.nl.util.FileProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
@@ -14,6 +16,24 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@EnableWebMvc
public class CorsConfig implements WebMvcConfigurer {
/** 文件配置 */
private final FileProperties properties;
public CorsConfig(FileProperties properties) {
this.properties = properties;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
FileProperties.ElPath path = properties.getPath();
String qrcodeUtl = "file:" + path.getQrcode().replace("\\","/");
String pathUtl = "file:" + path.getPath().replace("\\","/");
registry.addResourceHandler("/qrcode/**").addResourceLocations(qrcodeUtl).setCachePeriod(0);
registry.addResourceHandler("/file/**").addResourceLocations(pathUtl).setCachePeriod(0);
registry.addResourceHandler("/**").addResourceLocations("classpath:/META-INF/resources/").setCachePeriod(0);
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")

View File

@@ -0,0 +1,45 @@
package org.nl.util;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
/**
* @author dsh
* 2025/12/18
*/
@Data
@Configuration
@ConfigurationProperties(prefix = "file")
public class FileProperties {
/** 文件大小限制 */
private Long maxSize;
/** 头像大小限制 */
private Long avatarMaxSize;
private ElPath mac;
private ElPath linux;
private ElPath windows;
public ElPath getPath(){
String os = System.getProperty("os.name");
if(os.toLowerCase().startsWith("win")) {
return windows;
} else if(os.toLowerCase().startsWith("mac")){
return mac;
}
return linux;
}
@Data
public static class ElPath{
private String path;
private String qrcode;
}
}

View File

@@ -0,0 +1,73 @@
package org.nl.util;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import lombok.extern.slf4j.Slf4j;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
/**
* @author dsh
* 2025/12/22
*/
@Slf4j
public class QRCodeUtil {
/**
* 生成二维码图片并保存到指定路径
*
* @param data 二维码内容(文本/URL/WiFi配置等
* @param width 二维码宽度(像素)
* @param height 二维码高度(像素)
* @param filePath 保存路径(需包含.png后缀
* @return 生成的二维码文件路径失败时返回null
*/
public static String generateQRCode(String data, int width, int height, String filePath,String fileName) {
try {
//1.设置二维码生成参数
Map<EncodeHintType, Object> hints = new HashMap<>();
// 支持中文等特殊字符
hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
// 30%容错率
hints.put(EncodeHintType.ERROR_CORRECTION, com.google.zxing.qrcode.decoder.ErrorCorrectionLevel.H);
// 二维码边框空白宽度
hints.put(EncodeHintType.MARGIN, 1);
//2.生成二维码矩阵数据
MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix bitMatrix = writer.encode(data, BarcodeFormat.QR_CODE, width, height, hints);
//3.转换为图像对象
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bitMatrix.get(x, y) ? Color.BLACK.getRGB() : Color.WHITE.getRGB());
}
}
// 确保目录存在
File outputDir = new File(filePath);
if (!outputDir.exists()) {
outputDir.mkdirs();
log.info("目录已创建: {}", outputDir.getAbsolutePath());
}
//4.保存为PNG文件
File qrCodeFile = new File(filePath, fileName);
ImageIO.write(image, "png", qrCodeFile);
log.info("二维码已生成并保存到: {}", filePath);
return filePath;
} catch (Exception e) {
log.info("生成二维码错误:{}", e.getMessage());
return null;
}
}
}

View File

@@ -0,0 +1,13 @@
package org.nl.util;
/**
* @author dsh
* 2025/12/16
*/
public class URLConstant {
/**
* 调度IP及端口
*/
public static String SCHEDULE_IP_PORT = "127.0.0.1:55200";
}