From a505e17a3df0349a72dfdad6d849ad2eb5c14f45 Mon Sep 17 00:00:00 2001 From: lj7788 Date: Mon, 16 Mar 2026 17:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9LED=E7=BB=98=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yanzhu/led/service/LedDrawService.java | 4 +- .../service/impl/LedScreenServiceImpl.java | 4 + .../com/yanzhu/led/utils/Uni2LedDrawer.java | 160 ++++++++++++++++++ .../com/yanzhu/led/utils/UniLedDrawer.java | 29 ++-- 4 files changed, 181 insertions(+), 16 deletions(-) create mode 100644 yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/utils/Uni2LedDrawer.java diff --git a/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/service/LedDrawService.java b/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/service/LedDrawService.java index 0a62c441..ae207ee9 100644 --- a/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/service/LedDrawService.java +++ b/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/service/LedDrawService.java @@ -74,7 +74,7 @@ public class LedDrawService { // 使用屏幕配置文件 Bx6GScreenProfile profile = screen.getProfile(); ProgramBxFile programFile = new ProgramBxFile("P000", profile); - + // 根据LED屏的配置参数进行绘制 String[] imagePaths = ledScreenService.getImagePathsForScreen(ledScreen); // 获取要显示的图片路径 createBx6MProgram(programFile, ledScreen, imagePaths, profile); @@ -179,7 +179,7 @@ public class LedDrawService { for (Map.Entry entry : connectedScreens.entrySet()) { String deviceSn = entry.getKey(); Bx6GScreen screen = entry.getValue(); - + try { // 尝试ping设备,检测其是否仍然在线 Bx6GScreen.Result result = screen.ping(); diff --git a/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/service/impl/LedScreenServiceImpl.java b/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/service/impl/LedScreenServiceImpl.java index 42fff90f..181351a6 100644 --- a/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/service/impl/LedScreenServiceImpl.java +++ b/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/service/impl/LedScreenServiceImpl.java @@ -3,6 +3,7 @@ package com.yanzhu.led.service.impl; import com.yanzhu.led.config.LedProperties; import com.yanzhu.led.service.ILedScreenService; import com.yanzhu.led.utils.LedFileUtils; +import com.yanzhu.led.utils.Uni2LedDrawer; import com.yanzhu.led.utils.UniLedDrawer; import com.yanzhu.manage.domain.ProMobileAttendanceData; import com.yanzhu.manage.mapper.ProMobileAttendanceDataMapper; @@ -140,6 +141,9 @@ public class LedScreenServiceImpl implements ILedScreenService { // 获取考勤数据 List attendanceDataList = getAttendanceDataByWorkAreaId(ledScreen); return UniLedDrawer.drawLedScreen(ledScreen, ledProperties, attendanceDataList); + }else if (ledScreen.getDrawType().intValue()==2){ + List attendanceDataList = getAttendanceDataByWorkAreaId(ledScreen); + return Uni2LedDrawer.drawLedScreen(ledScreen, ledProperties, attendanceDataList); } return new String[]{}; // 实际使用时应从配置或数据库获取 } diff --git a/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/utils/Uni2LedDrawer.java b/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/utils/Uni2LedDrawer.java new file mode 100644 index 00000000..b6ee11e7 --- /dev/null +++ b/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/utils/Uni2LedDrawer.java @@ -0,0 +1,160 @@ +package com.yanzhu.led.utils; + +import com.yanzhu.led.config.LedProperties; +import com.yanzhu.manage.domain.ProMobileAttendanceData; +import com.yanzhu.system.domain.SysLedscreen; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +public class Uni2LedDrawer extends BaseDrawer{ + + + public static String[] drawLedScreen(SysLedscreen ledScreen, LedProperties ledProperties, List attendanceDataList) { + String ledSavePath=ledProperties.getSavePath()+ledScreen.getDeviceSn()+"/"; + //检查目录及子目录是否已存在,不存在创建目 + LedFileUtils.createDir(ledSavePath); + + + int screenHeight=ledScreen.getHeight().intValue(); + int dataLine = Math.max(3, (screenHeight-32)/16-1); // 确保dataLine至少为1 + List imagePaths = new ArrayList<>(); + //根据dataLine来对list进行分页,调用绘制方法 + if (!attendanceDataList.isEmpty() && dataLine > 0) { // 检查列表不为空且dataLine大于0 + for (int i = 0; i < attendanceDataList.size(); i += dataLine) { + List subList = attendanceDataList.subList(i, Math.min(i + dataLine, attendanceDataList.size())); + String imagePath=ledSavePath + "image" + (i / dataLine + 1) + ".bmp"; + drawImage(ledScreen, subList, imagePath); + imagePaths.add(imagePath); + } + } + imagePaths.clear(); + return imagePaths.toArray(new String[0]); + } + + private static void drawImage(SysLedscreen ledScreen, List subList, String imagePath) { + int screenWidth=ledScreen.getWidth().intValue(); + int lineHeight = 16; + int headerHeight = lineHeight; + int rowHeight = lineHeight; + + int margin = 3; + int drawWidth = screenWidth - 2 * margin; + int totalHeight = headerHeight + subList.size() * rowHeight; + + int imageWidth = screenWidth; + int imageHeight = totalHeight + 2 * margin; + + // 创建4位16色的BMP图片 + BufferedImage image = create4BitBmpImage(imageWidth, imageHeight); + Graphics2D g2d = image.createGraphics(); + + try { + // 设置背景色为黑色 + g2d.setColor(Color.BLACK); + g2d.fillRect(0, 0, imageWidth, imageHeight); + + // 设置字体 + Font font = new Font("宋体", Font.PLAIN, 12); + g2d.setFont(font); + g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); + + // 设置文字颜色为白色 + g2d.setColor(Color.WHITE); + + // 表头:姓名 班组 进入时间 + String[] headers = {"姓名", "班组", "进入时间"}; + int[] columnWidths = {drawWidth / 3, drawWidth / 3, drawWidth / 3}; + + // 绘制表头 + int x = margin; + for (int i = 0; i < headers.length; i++) { + g2d.drawString(headers[i], x + 2, margin + headerHeight - 4); + x += columnWidths[i]; + } + + // 绘制表头下划线 + g2d.setColor(Color.WHITE); + g2d.drawLine(margin, margin + headerHeight, margin + drawWidth, margin + headerHeight); + + // 绘制数据行 + g2d.setColor(Color.WHITE); + for (int i = 0; i < subList.size(); i++) { + ProMobileAttendanceData data = subList.get(i); + int rowY = margin + headerHeight + i * rowHeight; + + // 获取数据 + String userName = data.getUserName() != null ? data.getUserName() : ""; + String subDeptGroupName = data.getSubDeptGroupName() != null ? data.getSubDeptGroupName() : ""; + + // 格式化考勤时间 + String attTime = ""; + if (data.getAttDate() != null) { + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm"); + attTime = sdf.format(data.getAttDate()); + } + + // 绘制数据行 + x = margin; + g2d.drawString(userName, x + 2, rowY + rowHeight - 4); + x += columnWidths[0]; + g2d.drawString(subDeptGroupName, x + 2, rowY + rowHeight - 4); + x += columnWidths[1]; + g2d.drawString(attTime, x + 2, rowY + rowHeight - 4); + + // 绘制行下划线 + g2d.setColor(Color.WHITE); + g2d.drawLine(margin, rowY + rowHeight, margin + drawWidth, rowY + rowHeight); + } + + // 绘制垂直分割线 + g2d.setColor(Color.WHITE); + int x1 = margin + columnWidths[0]; + int x2 = margin + columnWidths[0] + columnWidths[1]; + g2d.drawLine(x1, margin, x1, margin + totalHeight); + g2d.drawLine(x2, margin, x2, margin + totalHeight); + + // 绘制表格外边框 + g2d.setColor(Color.WHITE); + g2d.drawRect(margin, margin, drawWidth, totalHeight); + + // 保存图片为BMP格式 + File outputFile = new File(imagePath); + ImageIO.write(image, "bmp", outputFile); + + } catch (IOException e) { + e.printStackTrace(); + } finally { + g2d.dispose(); + } + } + + public static void main(String[] args) { + SysLedscreen led=new SysLedscreen(); + led.setWidth(256l); + led.setHeight(160l); + led.setDeviceSn("B06M3P2501160132"); + led.setTitle("abc"); + LedProperties ledProperties=new LedProperties(); + List attendanceDataList = + Arrays.stream("1,2,3,4,5,6,7,8,9,10".split(",")).map(id -> { + ProMobileAttendanceData d=new ProMobileAttendanceData(); + d.setId(Long.parseLong(id)); + d.setUserName("张三李四"); + d.setSubDeptGroupName("爆破组"); + d.setAttDate(new Date()); + return d; + }).collect(Collectors.toList()); + drawLedScreen(led, ledProperties, attendanceDataList); + } + +} \ No newline at end of file diff --git a/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/utils/UniLedDrawer.java b/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/utils/UniLedDrawer.java index 954d93ba..e243b821 100644 --- a/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/utils/UniLedDrawer.java +++ b/yanzhu-modules/yanzhu-led/src/main/java/com/yanzhu/led/utils/UniLedDrawer.java @@ -47,11 +47,12 @@ public class UniLedDrawer extends BaseDrawer{ int lineHeight = 16; int headerHeight = lineHeight; int rowHeight = lineHeight; + + int margin = 3; + int drawWidth = screenWidth - 2 * margin; int totalHeight = headerHeight + subList.size() * rowHeight; - // 添加边距 - int margin = 3; - int imageWidth = screenWidth + 2 * margin; + int imageWidth = screenWidth; int imageHeight = totalHeight + 2 * margin; // 创建4位16色的BMP图片 @@ -73,20 +74,20 @@ public class UniLedDrawer extends BaseDrawer{ // 表头:姓名 班组 进入时间 String[] headers = {"姓名", "班组", "进入时间"}; - int[] columnWidths = {screenWidth / 3, screenWidth / 3, screenWidth / 3}; + int[] columnWidths = {drawWidth / 3, drawWidth / 3, drawWidth / 3}; - // 绘制表头,考虑左边距 + // 绘制表头 int x = margin; for (int i = 0; i < headers.length; i++) { g2d.drawString(headers[i], x + 2, margin + headerHeight - 4); x += columnWidths[i]; } - // 绘制表头下划线,考虑边距 + // 绘制表头下划线 g2d.setColor(Color.WHITE); - g2d.drawLine(margin, margin + headerHeight, margin + screenWidth, margin + headerHeight); + g2d.drawLine(margin, margin + headerHeight, margin + drawWidth, margin + headerHeight); - // 绘制数据行,考虑边距 + // 绘制数据行 g2d.setColor(Color.WHITE); for (int i = 0; i < subList.size(); i++) { ProMobileAttendanceData data = subList.get(i); @@ -103,7 +104,7 @@ public class UniLedDrawer extends BaseDrawer{ attTime = sdf.format(data.getAttDate()); } - // 绘制数据行,考虑左边距 + // 绘制数据行 x = margin; g2d.drawString(userName, x + 2, rowY + rowHeight - 4); x += columnWidths[0]; @@ -111,12 +112,12 @@ public class UniLedDrawer extends BaseDrawer{ x += columnWidths[1]; g2d.drawString(attTime, x + 2, rowY + rowHeight - 4); - // 绘制行下划线,考虑边距 + // 绘制行下划线 g2d.setColor(Color.WHITE); - g2d.drawLine(margin, rowY + rowHeight, margin + screenWidth, rowY + rowHeight); + g2d.drawLine(margin, rowY + rowHeight, margin + drawWidth, rowY + rowHeight); } - // 绘制垂直分割线,考虑边距 + // 绘制垂直分割线 g2d.setColor(Color.WHITE); int x1 = margin + columnWidths[0]; int x2 = margin + columnWidths[0] + columnWidths[1]; @@ -125,7 +126,7 @@ public class UniLedDrawer extends BaseDrawer{ // 绘制表格外边框 g2d.setColor(Color.WHITE); - g2d.drawRect(margin, margin, screenWidth, totalHeight); + g2d.drawRect(margin, margin, drawWidth, totalHeight); // 保存图片为BMP格式 File outputFile = new File(imagePath); @@ -140,7 +141,7 @@ public class UniLedDrawer extends BaseDrawer{ public static void main(String[] args) { SysLedscreen led=new SysLedscreen(); - led.setWidth(230l); + led.setWidth(192l); led.setHeight(128l); led.setDeviceSn("B06M3P2501160132"); led.setTitle("abc");