设备激活二维码生成逻辑修改,设备上报基本信息新增接口添加设备编码查重逻辑。
This commit is contained in:
@ -6,5 +6,4 @@ public class DeviceActivationDto {
|
||||
public double longitude;
|
||||
public double latitude;
|
||||
public String imgUrl;
|
||||
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class PrinterController extends BaseController {
|
||||
@PostMapping("/image/msg/generate")
|
||||
public AjaxResult generateImage(@RequestBody DeviceReportInfo deviceReportInfo ){
|
||||
System.err.println(deviceReportInfo);
|
||||
String qrCodeUrl = GenerateQRCodeImage.generateQRCodeUrl(deviceReportInfo.getName(), deviceReportInfo.getSerialNumber(), "山东翰臻物联公司");
|
||||
String qrCodeUrl = GenerateQRCodeImage.generateQRCodeUrl(deviceReportInfo);
|
||||
return AjaxResult.success("操作成功",qrCodeUrl);
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fastbee.iot.domain.DeviceReportInfo;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.MultiFormatWriter;
|
||||
@ -28,16 +29,16 @@ public class GenerateQRCodeImage {
|
||||
//设备激活接口地址
|
||||
private static final String ACTIVATE_URL = "https://open.10ss.net:8443/api/activate";
|
||||
|
||||
public static String generateQRCodeUrl(String deviceName, String deviceCode, String companyName){
|
||||
public static String generateQRCodeUrl(DeviceReportInfo deviceReportInfo){
|
||||
try {
|
||||
// 二维码内容
|
||||
Map<String,Object> qrCodeContent=new HashMap<>();
|
||||
qrCodeContent.put("deviceName",deviceName);
|
||||
qrCodeContent.put("deviceCode",deviceCode);
|
||||
qrCodeContent.put("deviceName",deviceReportInfo.getName());
|
||||
qrCodeContent.put("deviceCode",deviceReportInfo.getSerialNumber());
|
||||
String qrCodeContentStr=JSONUtil.toJsonStr(qrCodeContent);
|
||||
|
||||
// 生成二维码
|
||||
BitMatrix bitMatrix = generateQRCode(qrCodeContentStr, 220, 220);
|
||||
BitMatrix bitMatrix = generateQRCode(qrCodeContentStr, 200, 200);
|
||||
|
||||
// 将二维码转换为BufferedImage
|
||||
BufferedImage qrCodeImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
|
||||
@ -57,55 +58,84 @@ public class GenerateQRCodeImage {
|
||||
g2d.fillRect(0, 0, imageWidth, imageHeight);
|
||||
|
||||
// 绘制二维码
|
||||
g2d.drawImage(qrCodeImage, 40, 0, qrCodeWidth, qrCodeHeight, null);
|
||||
g2d.drawImage(qrCodeImage, 20, 10, qrCodeWidth, qrCodeHeight, null);
|
||||
//绘制虚线矩形
|
||||
Stroke dashed = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[]{10}, 0);
|
||||
g2d.setStroke(dashed);
|
||||
// 设置颜色
|
||||
g2d.setColor(Color.BLACK);
|
||||
// 绘制虚线矩形
|
||||
g2d.drawRect(70, 31, qrCodeImage.getWidth()-62, qrCodeImage.getHeight()-62);
|
||||
g2d.drawRect(50, 41, qrCodeImage.getWidth()-62, qrCodeImage.getHeight()-62);
|
||||
// 绘制文字
|
||||
g2d.setColor(Color.BLACK);
|
||||
g2d.setFont(new Font("黑体", Font.BOLD, 20));
|
||||
String text1 = deviceName;
|
||||
// 绘制第一段文字
|
||||
String text1 = deviceReportInfo.getName();
|
||||
FontMetrics fontMetrics = g2d.getFontMetrics();
|
||||
int textX = qrCodeWidth+15; // 间距20像素
|
||||
int textY1 = (imageHeight - fontMetrics.getHeight()) / 2 + fontMetrics.getAscent()-65;
|
||||
|
||||
|
||||
|
||||
int textX = qrCodeWidth-5; // 问文本与二维码的水平间距
|
||||
|
||||
|
||||
|
||||
int textY1 = (imageHeight - fontMetrics.getHeight()) / 2 + fontMetrics.getAscent()-55;
|
||||
|
||||
|
||||
g2d.drawString(text1, textX, textY1);
|
||||
|
||||
// 绘制第二段文字
|
||||
String text2 = "◉ 系列:"+"RF500780E";
|
||||
String text2 = "◉ 系列:"+deviceReportInfo.getMcuFw();
|
||||
g2d.setFont(new Font("Dialog", Font.BOLD, 18));
|
||||
|
||||
|
||||
int textY2 = textY1 + fontMetrics.getHeight() + 10; // 在第一段文字下方添加一些间距
|
||||
|
||||
|
||||
g2d.drawString(text2, textX, textY2);
|
||||
// 绘制第三段文字
|
||||
String text3 = "◉ 型号:" + "RF500 780E";
|
||||
String text3 = "◉ 型号:" + deviceReportInfo.getBspType()+deviceReportInfo.getLteType()+"";
|
||||
|
||||
|
||||
int textY3 = textY2 + fontMetrics.getHeight() + 10; // 在第一段文字下方添加一些间距
|
||||
|
||||
|
||||
g2d.drawString(text3, textX, textY3);
|
||||
//绘制第三段文字
|
||||
String text4 = "◉ 批次:" + "RF500C齐测780";
|
||||
String text4 = "◉ 批次:" + deviceReportInfo.getBatchNumber();
|
||||
|
||||
|
||||
int textY4 = textY3 + fontMetrics.getHeight() + 10; // 在第一段文字下方添加一些间距
|
||||
|
||||
|
||||
g2d.drawString(text4, textX, textY4);
|
||||
//绘制第五段文字
|
||||
// 确保Graphics2D对象的当前颜色是黑色(如果不是的话)
|
||||
g2d.setColor(Color.BLACK);
|
||||
// 计算文本宽度和高度
|
||||
String text5 =" SN:"+deviceCode+" ";
|
||||
String text5 =" SN:"+deviceReportInfo.getSerialNumber()+" ";
|
||||
|
||||
textWidth = fontMetrics.stringWidth(text5);
|
||||
int textHeight = fontMetrics.getHeight();
|
||||
// 计算矩形区域的X和Y坐标(留出内边距)
|
||||
int rectX = textX; // 左内边距
|
||||
|
||||
|
||||
int rectY = textY4+10; // 上内边距,确保文本顶部与矩形内部有一定的空间
|
||||
|
||||
|
||||
// 为了确保文本完全在矩形内,我们可以稍微调整rectHeight
|
||||
int rectHeight = textHeight + 10; // 文本高度加上上下内边距
|
||||
// 绘制黑色背景矩形
|
||||
g2d.fillRect(rectX, rectY, textWidth + 10, rectHeight);
|
||||
// 设置Graphics2D对象的当前颜色为白色
|
||||
g2d.setColor(Color.WHITE);
|
||||
|
||||
|
||||
// 绘制第四段文字
|
||||
int textY5 = textY4 + fontMetrics.getHeight() + 10; // 在前一段文字下方添加间距
|
||||
|
||||
|
||||
g2d.drawString(text5, textX, textY5); // 绘制白色文本
|
||||
// 释放Graphics2D资源
|
||||
g2d.dispose();
|
||||
@ -161,7 +191,34 @@ public class GenerateQRCodeImage {
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String url = GenerateQRCodeImage.generateQRCodeUrl("测试水电双计设备001","FD78944554","山东翰臻物联公司");
|
||||
// 创建DeviceReportInfo对象实例
|
||||
DeviceReportInfo deviceReportInfo = new DeviceReportInfo();
|
||||
|
||||
// 依次设置各个属性值
|
||||
deviceReportInfo.setImei("1231212");
|
||||
deviceReportInfo.setIccid("121212122");
|
||||
deviceReportInfo.setMcuId("MCU0023");
|
||||
deviceReportInfo.setBspType("RF500A");
|
||||
deviceReportInfo.setLteType("780E");
|
||||
deviceReportInfo.setMcuType("MCU型号Z");
|
||||
deviceReportInfo.setMcuFw("RF345X");
|
||||
deviceReportInfo.setLteFw("模组固件V2.1");
|
||||
deviceReportInfo.setLcdManufacturer(2L);
|
||||
deviceReportInfo.setVoiceManufacturer(5L);
|
||||
deviceReportInfo.setFramModel("FRAM-200");
|
||||
deviceReportInfo.setReplaceManufacturer(9L);
|
||||
deviceReportInfo.setTestRecord("测试脉冲次数为3次,第一次上电时间是2024-12-09");
|
||||
deviceReportInfo.setBatchNumber("RF500 齐河 780E");
|
||||
|
||||
// 对于示例JSON数据中未包含但类中定义了的属性,这里可以按需设置默认值(此处仅为示例,可按实际需求调整)
|
||||
deviceReportInfo.setSerialNumber("默认设备编号");
|
||||
deviceReportInfo.setQrCode("默认二维码");
|
||||
deviceReportInfo.setName("默认设备名称");
|
||||
deviceReportInfo.setLcdManufacturerName("默认LCD厂家名称");
|
||||
deviceReportInfo.setVoiceManufacturerName("默认语音厂家名称");
|
||||
deviceReportInfo.setReplaceManufacturerName("默认代工厂家名称");
|
||||
deviceReportInfo.setDeviceId(0L);
|
||||
String url = GenerateQRCodeImage.generateQRCodeUrl(deviceReportInfo);
|
||||
System.err.println(url);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user