diff --git a/device_cars/src/main/java/com/xr/device_car/config/getconfigvalue/StaticProperties.java b/device_cars/src/main/java/com/xr/device_car/config/getconfigvalue/StaticProperties.java index 73239f7..d33a555 100644 --- a/device_cars/src/main/java/com/xr/device_car/config/getconfigvalue/StaticProperties.java +++ b/device_cars/src/main/java/com/xr/device_car/config/getconfigvalue/StaticProperties.java @@ -8,10 +8,10 @@ import org.springframework.stereotype.Component; @Data public class StaticProperties { - @Value("${upLoad.path}") + @Value("${upload.img.path}") private String path; - @Value("${upLoad.url}") + @Value("${upload.img.url}") private String url; @Value("${python.path}") diff --git a/device_cars/src/main/java/com/xr/device_car/config/utils/FileUtil.java b/device_cars/src/main/java/com/xr/device_car/config/utils/FileUtil.java index 3d2ed92..dfea0fd 100644 --- a/device_cars/src/main/java/com/xr/device_car/config/utils/FileUtil.java +++ b/device_cars/src/main/java/com/xr/device_car/config/utils/FileUtil.java @@ -3,6 +3,11 @@ package com.xr.device_car.config.utils; import org.springframework.core.io.ClassPathResource; import java.io.*; +import java.net.URL; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Date; public class FileUtil { @@ -120,6 +125,45 @@ public class FileUtil { } + public static String uploadImage(String clentIp,Integer configId,String fileName) throws Exception { + // 构建完整的路径 + String url = "http://"+clentIp+":8080/tao/snapshot"; + SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd-HH"); + String date = sim.format(new Date()); + String dates[] = date.split("-"); + + String year = dates[0]; + String month = dates[1]; + String day = dates[2]; + String ho = dates[3]; + String fullPath = StaticPropUtil.imagePath+configId + File.separator + year + File.separator + month + File.separator + day + File.separator +ho+File.separator+ fileName+".jpg"; + + // 创建目录结构 + Path directoryPath = Paths.get(StaticPropUtil.imagePath,configId.toString(), year, month, day,ho); + if (!java.nio.file.Files.exists(directoryPath)) { + java.nio.file.Files.createDirectories(directoryPath); + } + + downloadImage(url,fullPath); + + // 构建URL + String url1 = StaticPropUtil.imageUrl+ configId + "/" + year + "/"+ month + "/" + day + "/" +ho+"/"+ fileName+".jpg"; + return url1; + } + + public static void downloadImage(String imageUrl, String destinationPath) throws IOException { + URL url = new URL(imageUrl); + try (InputStream in = url.openStream(); + FileOutputStream out = new FileOutputStream(destinationPath)) { + byte[] buffer = new byte[1024]; + int bytesRead; + while ((bytesRead = in.read(buffer)) != -1) { + out.write(buffer, 0, bytesRead); + } + } + } + + } diff --git a/device_cars/src/main/java/com/xr/device_car/config/utils/Files.java b/device_cars/src/main/java/com/xr/device_car/config/utils/Files.java index 5f38ef2..01111d0 100644 --- a/device_cars/src/main/java/com/xr/device_car/config/utils/Files.java +++ b/device_cars/src/main/java/com/xr/device_car/config/utils/Files.java @@ -6,6 +6,7 @@ import sun.misc.BASE64Encoder; import javax.imageio.ImageIO; import java.awt.*; +import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.*; import java.net.Authenticator; @@ -13,6 +14,7 @@ import java.net.PasswordAuthentication; import java.net.URL; import java.net.URLConnection; import java.nio.file.Path; +import java.text.SimpleDateFormat; import java.util.Base64; import java.util.Date; import java.util.Random; @@ -345,32 +347,66 @@ public class Files { return fileName; } - /** - * 给图片化框 - *image 图片 - * */ - public static BufferedImage drawRectangleAndText(BufferedImage image, int x1, int y1, int x2, int y2, String text) { + public static BufferedImage drawRectangleAndText(BufferedImage image, double x1, double y1,double x2, double wid, double hei, String text1, String text2) { // 创建一个Graphics2D对象 Graphics2D g2d = image.createGraphics(); + // 设置抗锯齿 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + // 创建一个Rectangle2D.Double对象 + Rectangle2D.Double rect = new Rectangle2D.Double(x1, y1, wid, hei); + // 绘制红色框 g2d.setColor(Color.RED); - g2d.drawRect(x1, y1, x2 - x1, y2 - y1); + g2d.draw(rect); + // 设置粗线条 + g2d.setStroke(new BasicStroke(3.0f * 30)); // 设置线条宽度为3.0f // 设置字体和颜色 - g2d.setFont(new Font("Arial", Font.BOLD, 12)); - g2d.setColor(Color.RED); + g2d.setFont(new Font("微软雅黑", Font.BOLD, 38)); // 使用支持中文的字体,增加字体大小 + // 获取当前时间 + String currentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); // 获取文本的宽度和高度 FontMetrics fm = g2d.getFontMetrics(); - int textWidth = fm.stringWidth(text); - int textHeight = fm.getHeight(); - // 绘制文本 - g2d.drawString(text, x2 - textWidth - 5, y1 + textHeight - 5); + // 绘制当前时间的背景矩形 + int padding = 20; + int currentTimeWidth = fm.stringWidth(currentTime); + int currentTimeHeight = fm.getHeight(); + int rectPadding = 5; // 背景矩形内边距 + g2d.setColor(new Color(0, 0, 0, 50)); // 黑色半透明背景 + g2d.fillRect(padding, padding, currentTimeWidth + 2 * rectPadding, currentTimeHeight + 2 * rectPadding); + + // 绘制当前时间在左上角,内边距为20px + g2d.setColor(Color.WHITE); + int currentTimeX = padding + rectPadding + (currentTimeWidth + rectPadding - currentTimeWidth) / 2; + int currentTimeY = padding + rectPadding + fm.getAscent(); + g2d.drawString(currentTime, currentTimeX, currentTimeY); + + // 绘制文本2的背景矩形 + int text2Width = fm.stringWidth(text2); + int text2Height = fm.getHeight(); + g2d.setColor(new Color(0, 0, 0, 50)); // 黑色半透明背景 + g2d.fillRect(padding, padding + currentTimeHeight + rectPadding * 2, text2Width + 2 * rectPadding, text2Height + 2 * rectPadding); + + // 绘制文本2在时间的下面,内边距为20px + g2d.setColor(Color.WHITE); + int text2X = padding + rectPadding + (text2Width + rectPadding - text2Width) / 2; + int text2Y = padding + currentTimeHeight + rectPadding * 3 + fm.getAscent(); + g2d.drawString(text2, text2X, text2Y); + + // 计算文本1的右上角位置 + int text1Width = fm.stringWidth(text1); + int text1X = (int) (x1 + wid); // 框的右上角位置 + int text1Y = (int) (y1 + fm.getAscent()); // 框的右上角紧挨着框 + g2d.setColor(Color.RED); + + g2d.drawString(text1, text1X, text1Y); + // 释放资源 g2d.dispose(); diff --git a/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/FocalLengthConfigController.java b/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/FocalLengthConfigController.java index caa0f06..6867836 100644 --- a/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/FocalLengthConfigController.java +++ b/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/FocalLengthConfigController.java @@ -69,172 +69,172 @@ public class FocalLengthConfigController { focalLengthConfig.setUpdateUser(userInfo.getUserName()); focalLengthConfig.setUpdateTime(new Date()); focalLengthConfigService.updateById(focalLengthConfig); - MeterConfig meterConfig=meterConfigService.getById(focalLengthConfig.getConfigId()) ; - DeviceCamera device=deviceCameraService.getById(meterConfig.getCameraId()); - QueryWrapper query=new QueryWrapper<>(); - query.eq("camera_id",meterConfig.getCameraId()); - List list=meterConfigService.list(query); - List meters=list.stream().map(n->n.getId()).collect(Collectors.toList()); - QueryWrapper query1=new QueryWrapper<>(); - query1.in("config_id",meters); - List lists=focalLengthConfigService.list(query1); - - if(focalLengthConfig.getRotate() == null){ - focalLengthConfig.setRotate(0); - } - BufferedImage bufferedImage=Files.bytesTobufferedImage(config.getFocalPicture()); - int width=bufferedImage.getWidth(); - int height=bufferedImage.getHeight(); - File file = new File("D:\\images\\path\\config"); - if (!file.getParentFile().exists()) { - file.getParentFile().mkdirs(); - } - DecimalFormat df = new DecimalFormat("#0.00000"); - if(file.exists()){ - file.delete(); - } - String deviceType=""; - if(device.getDeviceType().equals("1")){ - deviceType="usb"; - }else if(device.getDeviceType().equals("2")){ - deviceType="mipi"; - }else{ - return Result.OK("保存成功!"); - } - file.createNewFile(); - StringBuffer stringBuffer = new StringBuffer(); - stringBuffer.append("{\n"); - stringBuffer.append("\t\"device_id\": \"" + meterConfig.getCameraId() + "\",\n"); - stringBuffer.append("\t\"device_name\": \""+device.getDeviceModel()+"\",\n"); - stringBuffer.append("\t\"camera_type\": \""+deviceType+"\",\n");//mipi设设一体 usb usb摄像头 - stringBuffer.append("\t\"interval\": 60,\n"); - stringBuffer.append("\t\"warmup\": 150,\n");//对焦时间 - stringBuffer.append("\t\"http\": {\n");//url - stringBuffer.append("\t\t\"url\": \"http://192.168.1.252:8081/dataAnalysisCamera/getComer\"\n"); - stringBuffer.append("\t},\n"); - //stringBuffer.append("\t\"url\": null,\n"); - stringBuffer.append("\t\"meters\": [\n"); - int i=0; - int j=0; - for (FocalLengthConfig config1 : lists) { - String meterType=config1.getConfigType(); - String algorithm="CrocodileCircle"; - if(meterType.equals("1")){ - meterType="crocodile"; - }else if(meterType.equals("2")){ - meterType="floatocr"; - }else if(meterType.equals("3")){ - meterType="swmet"; - }else if(meterType.equals("5")){ - meterType = "crocodile_non_scale"; - }else if(meterType.equals("4")){ - meterType = "crocodile_watershed"; - } - if(config1.getAlgorithm() ==null || config1.getAlgorithm()==0){ - algorithm="CrocodileCircle"; - }else{ - algorithm="CrocodileEllipse"; - } - double x=config1.getCopperX()/width; - double y=config1.getCopperY()/height; - double x2=config1.getCopperX2()/width; - double y2=config1.getCopperY2()/height; - String xx=df.format(x); - String yy=df.format(y); - String xx2=df.format(x2); - String yy2= df.format(y2); - if(i>0){ - stringBuffer.append("\n"); - } - i++; - stringBuffer.append("\t\t{\n\t\t\t\"id\": "+ config1.getId() +",\n"); - stringBuffer.append("\t\t\t\"crocodile_algo\":\"" + algorithm + "\",\n"); - stringBuffer.append("\t\t\t\"meter_id\": \"" + config1.getConfigId() + "\",\n"); - stringBuffer.append("\t\t\t\"meter_type\": \"" + meterType + "\",\n"); - stringBuffer.append("\t\t\t\"bbox\": [" + xx + "," + yy + "," + xx2 + "," + yy2 + "],\n"); - if (config1.getConfigType().equals("1")) { - List> meterZz=focalLengthConfig.getMeterZz(); - List doubleList=new ArrayList<>(); - for(Map map:meterZz){ - doubleList.add(Double.valueOf(map.get("bfb"))); - doubleList.add(Double.valueOf(map.get("zzwz"))); - } - stringBuffer.append("\t\t\t\"num_needles\": " + focalLengthConfig.getZzsl() + ",\n"); - stringBuffer.append("\t\t\t\"needle_seg\": \"" + focalLengthConfig.getNeedleSeg() + "\",\n"); - stringBuffer.append("\t\t\t").append("\"modbus\": {\n"); - stringBuffer.append("\t\t\t\t").append("\"type\": \"float\",\n"); - stringBuffer.append("\t\t\t\t\"register_address\":" + j + ",\n"); - stringBuffer.append("\t\t\t\t").append("\"num_register\": 2,\n"); - stringBuffer.append("\t\t\t\t").append("\"multiplier\": 10000.0\n"); - stringBuffer.append("\t\t\t},\n"); - stringBuffer.append("\t\t\t\"scales\": "+ Arrays.toString(doubleList.toArray())+"\n\t\t},"); - } else if(config1.getConfigType().equals("2")) { - stringBuffer.append("\t\t\t").append("\"modbus\": {\n"); - stringBuffer.append("\t\t\t\t").append("\"type\": \"int32\",\n"); - stringBuffer.append("\t\t\t\t\"register_address\":" + j + ",\n"); - stringBuffer.append("\t\t\t\t").append("\"num_register\": 1\n"); - stringBuffer.append("\t\t\t},\n"); - stringBuffer.append("\t\t\t").append("\"prior\": {\n"); - stringBuffer.append("\t\t\t\t").append("\"invalid_chars\": \""+focalLengthConfig.getInvalidChars()+"\",\n"); - stringBuffer.append("\t\t\t\t").append("\"expected_len\":"+focalLengthConfig.getExpectedLen()+",\n"); - stringBuffer.append("\t\t\t\t\"padding\":\"0\",\n"); - stringBuffer.append("\t\t\t\t\"append_from\":\"head\",\n"); - stringBuffer.append("\t\t\t\t\"shorten_from\":\"tail\"\n"); - stringBuffer.append("\t\t\t},\n"); - stringBuffer.append("\t\t\t\"scales\": [0.0,0.0,1.0,5.0]\n\t\t},"); - } else if(config1.getConfigType().equals("5")){ - String lighting = "uniform"; - if(focalLengthConfig.getGb().equals("1")){ - lighting = "blob"; - } - stringBuffer.append("\t\t\t\"lighting\": \"" + lighting + "\",\n"); - stringBuffer.append("\t\t\t\"blob_gap\": "+ focalLengthConfig.getGbcs() + ",\n"); - stringBuffer.append("\t\t\t").append("\"modbus\": {\n"); - stringBuffer.append("\t\t\t\t").append("\"type\": \"float\",\n"); - stringBuffer.append("\t\t\t\t\"register_address\":" + j + ",\n"); - stringBuffer.append("\t\t\t\t").append("\"num_register\": 2,\n"); - stringBuffer.append("\t\t\t\t").append("\"multiplier\": 10000.0\n"); - stringBuffer.append("\t\t\t}\n}\t\t\n"); - }else if(config1.getConfigType().equals("4")){ - stringBuffer.append("\t\t\t").append("\"modbus\": {\n"); - stringBuffer.append("\t\t\t\t").append("\"type\": \"float\",\n"); - stringBuffer.append("\t\t\t\t\"register_address\":" + j + ",\n"); - stringBuffer.append("\t\t\t\t").append("\"num_register\": 2,\n"); - stringBuffer.append("\t\t\t\t").append("\"multiplier\": 10000.0\n"); - stringBuffer.append("\t\t\t}\n}\t\t\n"); - } - - j+=10; - } - int rotate = focalLengthConfig.getRotate(); - if(rotate>0){ - rotate = ((~rotate)+1); - }else{ - rotate = Math.abs(rotate); - } - stringBuffer.deleteCharAt(stringBuffer.length() - 1); - stringBuffer.append("\n"); - stringBuffer.append("\t],\n"); - stringBuffer.append("\t\"imaging\": {\n"); - stringBuffer.append("\t\t\"geometry\": {\n"); - stringBuffer.append("\t\t\t\"angle\": "+rotate+",\n"); - stringBuffer.append("\t\t\t\"scale\": 1.0,\n"); - stringBuffer.append("\t\t\t\"x\": 0.5,\n"); - stringBuffer.append("\t\t\t\"y\": 0.5\n"); - stringBuffer.append("\t\t}\n"); - stringBuffer.append("\t},\n"); - stringBuffer.append("\t\"storage\": {\n"); - stringBuffer.append("\t\t\"sdcard\": 30.0\n"); - stringBuffer.append("\t},\n"); - stringBuffer.append("\t\"light\": {\n"); - stringBuffer.append("\t\t\"brightness\": 0.5\n"); - stringBuffer.append("\t}\n"); - stringBuffer.append("}"); - FileWriter writer = new FileWriter(file.getAbsoluteFile()); - BufferedWriter writer1 = new BufferedWriter(writer); - writer1.write(stringBuffer.toString()); - writer1.close(); - AdbUtil.pushConfigFile("D:\\images\\path\\config","/oem/wanwu/data/"); +// MeterConfig meterConfig=meterConfigService.getById(focalLengthConfig.getConfigId()) ; +// DeviceCamera device=deviceCameraService.getById(meterConfig.getCameraId()); +// QueryWrapper query=new QueryWrapper<>(); +// query.eq("camera_id",meterConfig.getCameraId()); +// List list=meterConfigService.list(query); +// List meters=list.stream().map(n->n.getId()).collect(Collectors.toList()); +// QueryWrapper query1=new QueryWrapper<>(); +// query1.in("config_id",meters); +// List lists=focalLengthConfigService.list(query1); +// +// if(focalLengthConfig.getRotate() == null){ +// focalLengthConfig.setRotate(0); +// } +// BufferedImage bufferedImage=Files.bytesTobufferedImage(config.getFocalPicture()); +// int width=bufferedImage.getWidth(); +// int height=bufferedImage.getHeight(); +// File file = new File("D:\\images\\path\\config"); +// if (!file.getParentFile().exists()) { +// file.getParentFile().mkdirs(); +// } +// DecimalFormat df = new DecimalFormat("#0.00000"); +// if(file.exists()){ +// file.delete(); +// } +// String deviceType=""; +// if(device.getDeviceType().equals("1")){ +// deviceType="usb"; +// }else if(device.getDeviceType().equals("2")){ +// deviceType="mipi"; +// }else{ +// return Result.OK("保存成功!"); +// } +// file.createNewFile(); +// StringBuffer stringBuffer = new StringBuffer(); +// stringBuffer.append("{\n"); +// stringBuffer.append("\t\"device_id\": \"" + meterConfig.getCameraId() + "\",\n"); +// stringBuffer.append("\t\"device_name\": \""+device.getDeviceModel()+"\",\n"); +// stringBuffer.append("\t\"camera_type\": \""+deviceType+"\",\n");//mipi设设一体 usb usb摄像头 +// stringBuffer.append("\t\"interval\": 60,\n"); +// stringBuffer.append("\t\"warmup\": 150,\n");//对焦时间 +// stringBuffer.append("\t\"http\": {\n");//url +// stringBuffer.append("\t\t\"url\": \"http://192.168.1.252:8081/dataAnalysisCamera/getComer\"\n"); +// stringBuffer.append("\t},\n"); +// //stringBuffer.append("\t\"url\": null,\n"); +// stringBuffer.append("\t\"meters\": [\n"); +// int i=0; +// int j=0; +// for (FocalLengthConfig config1 : lists) { +// String meterType=config1.getConfigType(); +// String algorithm="CrocodileCircle"; +// if(meterType.equals("1")){ +// meterType="crocodile"; +// }else if(meterType.equals("2")){ +// meterType="floatocr"; +// }else if(meterType.equals("3")){ +// meterType="swmet"; +// }else if(meterType.equals("5")){ +// meterType = "crocodile_non_scale"; +// }else if(meterType.equals("4")){ +// meterType = "crocodile_watershed"; +// } +// if(config1.getAlgorithm() ==null || config1.getAlgorithm()==0){ +// algorithm="CrocodileCircle"; +// }else{ +// algorithm="CrocodileEllipse"; +// } +// double x=config1.getCopperX()/width; +// double y=config1.getCopperY()/height; +// double x2=config1.getCopperX2()/width; +// double y2=config1.getCopperY2()/height; +// String xx=df.format(x); +// String yy=df.format(y); +// String xx2=df.format(x2); +// String yy2= df.format(y2); +// if(i>0){ +// stringBuffer.append("\n"); +// } +// i++; +// stringBuffer.append("\t\t{\n\t\t\t\"id\": "+ config1.getId() +",\n"); +// stringBuffer.append("\t\t\t\"crocodile_algo\":\"" + algorithm + "\",\n"); +// stringBuffer.append("\t\t\t\"meter_id\": \"" + config1.getConfigId() + "\",\n"); +// stringBuffer.append("\t\t\t\"meter_type\": \"" + meterType + "\",\n"); +// stringBuffer.append("\t\t\t\"bbox\": [" + xx + "," + yy + "," + xx2 + "," + yy2 + "],\n"); +// if (config1.getConfigType().equals("1")) { +// List> meterZz=focalLengthConfig.getMeterZz(); +// List doubleList=new ArrayList<>(); +// for(Map map:meterZz){ +// doubleList.add(Double.valueOf(map.get("bfb"))); +// doubleList.add(Double.valueOf(map.get("zzwz"))); +// } +// stringBuffer.append("\t\t\t\"num_needles\": " + focalLengthConfig.getZzsl() + ",\n"); +// stringBuffer.append("\t\t\t\"needle_seg\": \"" + focalLengthConfig.getNeedleSeg() + "\",\n"); +// stringBuffer.append("\t\t\t").append("\"modbus\": {\n"); +// stringBuffer.append("\t\t\t\t").append("\"type\": \"float\",\n"); +// stringBuffer.append("\t\t\t\t\"register_address\":" + j + ",\n"); +// stringBuffer.append("\t\t\t\t").append("\"num_register\": 2,\n"); +// stringBuffer.append("\t\t\t\t").append("\"multiplier\": 10000.0\n"); +// stringBuffer.append("\t\t\t},\n"); +// stringBuffer.append("\t\t\t\"scales\": "+ Arrays.toString(doubleList.toArray())+"\n\t\t},"); +// } else if(config1.getConfigType().equals("2")) { +// stringBuffer.append("\t\t\t").append("\"modbus\": {\n"); +// stringBuffer.append("\t\t\t\t").append("\"type\": \"int32\",\n"); +// stringBuffer.append("\t\t\t\t\"register_address\":" + j + ",\n"); +// stringBuffer.append("\t\t\t\t").append("\"num_register\": 1\n"); +// stringBuffer.append("\t\t\t},\n"); +// stringBuffer.append("\t\t\t").append("\"prior\": {\n"); +// stringBuffer.append("\t\t\t\t").append("\"invalid_chars\": \""+focalLengthConfig.getInvalidChars()+"\",\n"); +// stringBuffer.append("\t\t\t\t").append("\"expected_len\":"+focalLengthConfig.getExpectedLen()+",\n"); +// stringBuffer.append("\t\t\t\t\"padding\":\"0\",\n"); +// stringBuffer.append("\t\t\t\t\"append_from\":\"head\",\n"); +// stringBuffer.append("\t\t\t\t\"shorten_from\":\"tail\"\n"); +// stringBuffer.append("\t\t\t},\n"); +// stringBuffer.append("\t\t\t\"scales\": [0.0,0.0,1.0,5.0]\n\t\t},"); +// } else if(config1.getConfigType().equals("5")){ +// String lighting = "uniform"; +// if(focalLengthConfig.getGb().equals("1")){ +// lighting = "blob"; +// } +// stringBuffer.append("\t\t\t\"lighting\": \"" + lighting + "\",\n"); +// stringBuffer.append("\t\t\t\"blob_gap\": "+ focalLengthConfig.getGbcs() + ",\n"); +// stringBuffer.append("\t\t\t").append("\"modbus\": {\n"); +// stringBuffer.append("\t\t\t\t").append("\"type\": \"float\",\n"); +// stringBuffer.append("\t\t\t\t\"register_address\":" + j + ",\n"); +// stringBuffer.append("\t\t\t\t").append("\"num_register\": 2,\n"); +// stringBuffer.append("\t\t\t\t").append("\"multiplier\": 10000.0\n"); +// stringBuffer.append("\t\t\t}\n}\t\t\n"); +// }else if(config1.getConfigType().equals("4")){ +// stringBuffer.append("\t\t\t").append("\"modbus\": {\n"); +// stringBuffer.append("\t\t\t\t").append("\"type\": \"float\",\n"); +// stringBuffer.append("\t\t\t\t\"register_address\":" + j + ",\n"); +// stringBuffer.append("\t\t\t\t").append("\"num_register\": 2,\n"); +// stringBuffer.append("\t\t\t\t").append("\"multiplier\": 10000.0\n"); +// stringBuffer.append("\t\t\t}\n}\t\t\n"); +// } +// +// j+=10; +// } +// int rotate = focalLengthConfig.getRotate(); +// if(rotate>0){ +// rotate = ((~rotate)+1); +// }else{ +// rotate = Math.abs(rotate); +// } +// stringBuffer.deleteCharAt(stringBuffer.length() - 1); +// stringBuffer.append("\n"); +// stringBuffer.append("\t],\n"); +// stringBuffer.append("\t\"imaging\": {\n"); +// stringBuffer.append("\t\t\"geometry\": {\n"); +// stringBuffer.append("\t\t\t\"angle\": "+rotate+",\n"); +// stringBuffer.append("\t\t\t\"scale\": 1.0,\n"); +// stringBuffer.append("\t\t\t\"x\": 0.5,\n"); +// stringBuffer.append("\t\t\t\"y\": 0.5\n"); +// stringBuffer.append("\t\t}\n"); +// stringBuffer.append("\t},\n"); +// stringBuffer.append("\t\"storage\": {\n"); +// stringBuffer.append("\t\t\"sdcard\": 30.0\n"); +// stringBuffer.append("\t},\n"); +// stringBuffer.append("\t\"light\": {\n"); +// stringBuffer.append("\t\t\"brightness\": 0.5\n"); +// stringBuffer.append("\t}\n"); +// stringBuffer.append("}"); +// FileWriter writer = new FileWriter(file.getAbsoluteFile()); +// BufferedWriter writer1 = new BufferedWriter(writer); +// writer1.write(stringBuffer.toString()); +// writer1.close(); +// AdbUtil.pushConfigFile("D:\\images\\path\\config","/oem/wanwu/data/"); return Result.OK("保存成功!"); } @@ -245,7 +245,9 @@ public class FocalLengthConfigController { DeviceCamera deviceCamera = deviceCameraService.getById(meterConfig.getCameraId()); BufferedImage bufferedImage=null; if(deviceCamera.getDeviceType().equals("1")|| deviceCamera.getDeviceType().equals("2")){ - bufferedImage= AdbUtil.getCamDevice(); + //bufferedImage= AdbUtil.getCamDevice(); + String buffered =FileUtil.uploadImage(deviceCamera.getDeviceIp(),meterConfig.getId(),deviceCamera.getDeviceIp()); + bufferedImage = Files.urlByImage(buffered); } if(deviceCamera.getDeviceType().equals("3") || deviceCamera.getDeviceType().equals("4")){ // 拉取球机 bufferedImage= HkComUtil.getBole(deviceCamera); diff --git a/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/MeterInitializationController.java b/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/MeterInitializationController.java index fcb6e9b..c886595 100644 --- a/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/MeterInitializationController.java +++ b/device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/MeterInitializationController.java @@ -40,8 +40,6 @@ import java.awt.image.BufferedImage; @RequestMapping("/meterInitialization") @RequiredArgsConstructor public class MeterInitializationController { - @Value("${upLoad.file}") - private String uploadDir; private final MeterConfigService meterConfigService; diff --git a/device_cars/src/main/resources/application-dev.yml b/device_cars/src/main/resources/application-dev.yml index df32622..a86a2b4 100644 --- a/device_cars/src/main/resources/application-dev.yml +++ b/device_cars/src/main/resources/application-dev.yml @@ -62,10 +62,10 @@ swagger: analysis: url: http://192.168.1.123:9000/vi/syncrec -upLoad: - path: D:\\images\\images\\ - url: http://localhost:85/upload/ - file: D:\\images\\images\\ +upload: + img: + url: http://192.168.1.83:18081/file/img/zs/ + path: D:\\service\\fileService\\img\\zs\\ python: path: C:\\Users\\admin\\Anaconda3\\envs\\myconda310\\python.exe modelPath: D:\\smartGrid\\smartGrid\\models diff --git a/device_cars/src/main/resources/application-prod.yml b/device_cars/src/main/resources/application-prod.yml index 9ba8158..c5a8db5 100644 --- a/device_cars/src/main/resources/application-prod.yml +++ b/device_cars/src/main/resources/application-prod.yml @@ -62,10 +62,10 @@ swagger: analysis: url: http://192.168.1.123:9000/vi/syncrec -upLoad: - path: D:\\images\\images\\ - url: http://localhost:85/upload/ - file: D:\\images\\images\\ +upload: + img: + url: http://192.168.1.94:18081/file/img/zs/ + path: E:\\service\\fileService\\img\\zs\\ python: path: C:\\Users\\admin\\Anaconda3\\envs\\myconda310\\python.exe modelPath: D:\\smartGrid\\smartGrid\\models diff --git a/device_cars/src/main/resources/application.yml b/device_cars/src/main/resources/application.yml index c854e41..8d7945b 100644 --- a/device_cars/src/main/resources/application.yml +++ b/device_cars/src/main/resources/application.yml @@ -2,7 +2,7 @@ spring: profiles: #active: dev #开发环境 # active: test #测试环境5 - active: prod #生产环境 + active: dev #生产环境 # active: prod #生产环境 application: name: deviceCars diff --git a/device_gateway/pom.xml b/device_gateway/pom.xml index 51fa099..36975dc 100644 --- a/device_gateway/pom.xml +++ b/device_gateway/pom.xml @@ -13,7 +13,7 @@ device-gateway device-gateway - 8 + 1.8 @@ -63,6 +63,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/Iec61850ClentApplication.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/Iec61850ClentApplication.java index 9b0ff9b..978f2b5 100644 --- a/device_iec61850clent/src/main/java/com/xr/iec61850clent/Iec61850ClentApplication.java +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/Iec61850ClentApplication.java @@ -1,6 +1,7 @@ package com.xr.iec61850clent; import com.xr.iec61850clent.models.iec61850run.Iec61850clent; +import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.CommandLineRunner; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -8,6 +9,7 @@ import org.springframework.cloud.client.discovery.EnableDiscoveryClient; import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.annotation.EnableScheduling; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -16,6 +18,8 @@ import java.util.concurrent.Executors; @EnableAsync//开启异步 @EnableDiscoveryClient @EnableFeignClients +@EnableScheduling//开启定时任务 +@MapperScan("com.xr.iec61850clent.models.mapper") public class Iec61850ClentApplication implements CommandLineRunner { public static ExecutorService executor = Executors.newFixedThreadPool(2); @@ -30,8 +34,8 @@ public class Iec61850ClentApplication implements CommandLineRunner { @Override @Async public void run(String[] args){ - Iec61850clent iec61850clent=new Iec61850clent(args,"192.168.1.93",102); - executor.execute(iec61850clent); + //Iec61850clent iec61850clent=new Iec61850clent(args,"192.168.1.93",102); + //executor.execute(iec61850clent); // Iec61850clent iec61850clent1=new Iec61850clent(args,"192.168.1.138",102); // executor.submit(iec61850clent1); } diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/configvalue/StaticProperties.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/configvalue/StaticProperties.java index f216b27..0d0f329 100644 --- a/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/configvalue/StaticProperties.java +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/configvalue/StaticProperties.java @@ -2,6 +2,7 @@ package com.xr.iec61850clent.common.configvalue; import lombok.Data; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; @Component diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/IEC61850Config.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/IEC61850Config.java index 925d529..a913776 100644 --- a/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/IEC61850Config.java +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/IEC61850Config.java @@ -83,6 +83,15 @@ public class IEC61850Config { Cell cell7 = row.getCell(7); cell1.setCellType(Cell.CELL_TYPE_STRING); excelConfig.setMsg(getCellValue(wb, cell7)); + + Cell cell8 = row.getCell(8); + cell1.setCellType(Cell.CELL_TYPE_STRING); + excelConfig.setClientIp(getCellValue(wb,cell8)); + + Cell cell9 = row.getCell(9); + cell1.setCellType(Cell.CELL_TYPE_STRING); + excelConfig.setMeterId(getCellValue(wb,cell9)); + dataList.add(excelConfig); } } catch (Exception e) { diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/ModeUtil.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/ModeUtil.java index e1d309b..94be39c 100644 --- a/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/ModeUtil.java +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/ModeUtil.java @@ -32,6 +32,8 @@ public class ModeUtil { lds5000.setClentIp(eunm.getDeviceIp()); lds5000.setNode(node.getReference().toString()); lds5000.setFc(node.getFc().toString()); + lds5000.setMeterId(eunm.getMeterId()); + lds5000.setClientIp(eunm.getClientIp()); List modelNodes=new ArrayList(node.getChildren()); for (ModelNode modelNode:modelNodes){ FcModelNode fcModelNode=(FcModelNode) modelNode; diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/UploadUtil.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/UploadUtil.java index 15dafbd..ce72cd2 100644 --- a/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/UploadUtil.java +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/common/util/UploadUtil.java @@ -3,6 +3,8 @@ package com.xr.iec61850clent.common.util; import org.apache.poi.ss.usermodel.Workbook; import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; @@ -38,10 +40,10 @@ public class UploadUtil { String month = dates[1]; String day = dates[2]; String ho = dates[3]; - String fullPath = StaticPropUtil.imgUrl+configId + File.separator + year + File.separator + month + File.separator + day + File.separator +ho+File.separator+ fileName; + String fullPath = StaticPropUtil.imgPath+configId + File.separator + year + File.separator + month + File.separator + day + File.separator +ho+File.separator+ fileName; // 创建目录结构 - Path directoryPath = Paths.get(StaticPropUtil.imgUrl,configId.toString(), year, month, day,ho); + Path directoryPath = Paths.get(StaticPropUtil.imgPath,configId.toString(), year, month, day,ho); if (!java.nio.file.Files.exists(directoryPath)) { java.nio.file.Files.createDirectories(directoryPath); } @@ -53,6 +55,39 @@ public class UploadUtil { return url1; } + public static String uploadImage(BufferedImage buffer,Integer configId,String fileName) throws Exception { + // 构建完整的路径 + SimpleDateFormat sim=new SimpleDateFormat("yyyy-MM-dd-HH"); + String date = sim.format(new Date()); + String dates[] = date.split("-"); + + String year = dates[0]; + String month = dates[1]; + String day = dates[2]; + String ho = dates[3]; + String fullPath = StaticPropUtil.imgPath+configId + File.separator + year + File.separator + month + File.separator + day + File.separator +ho+File.separator+ fileName; + + // 创建目录结构 + Path directoryPath = Paths.get(StaticPropUtil.imgPath,configId.toString(), year, month, day,ho); + if (!java.nio.file.Files.exists(directoryPath)) { + java.nio.file.Files.createDirectories(directoryPath); + } + + downloadImage(buffer,fullPath); + + // 构建URL + String url1 = StaticPropUtil.imgUrl+ configId + "/" + year + "/"+ month + "/" + day + "/" +ho+"/"+ fileName; + return url1; + } + + + public static BufferedImage urlByImage(String url) throws IOException { + URL urlfile = new URL(url); + InputStream is2 = urlfile.openStream(); + BufferedImage uImg= ImageIO.read(is2); + return uImg; + } + public static void delFile(String path,String url,String fileUrl){ String filePath = fileUrl.replace(url,path).replace("/","\\"); File file = new File(filePath); @@ -73,4 +108,79 @@ public class UploadUtil { } } + public static void downloadImage(BufferedImage bufferedImage, String destinationPath) throws IOException { + File file = new File(destinationPath); + ImageIO.write(bufferedImage,"jpg",file); + } + + public static BufferedImage drawRectangleAndText(BufferedImage image, double x1, double y1,double x2, double wid, double hei, String text1, String text2) { + // 创建一个Graphics2D对象 + Graphics2D g2d = image.createGraphics(); + + + // 设置抗锯齿 + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + + + // 创建一个Rectangle2D.Double对象 + Rectangle2D.Double rect = new Rectangle2D.Double(x1, y1, wid, hei); + + // 绘制红色框 + g2d.setColor(Color.RED); + g2d.draw(rect); + // 设置粗线条 + g2d.setStroke(new BasicStroke(3.0f * 30)); // 设置线条宽度为3.0f + + // 设置字体和颜色 + g2d.setFont(new Font("微软雅黑", Font.BOLD, 38)); // 使用支持中文的字体,增加字体大小 + + // 获取当前时间 + String currentTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()); + // 获取文本的宽度和高度 + FontMetrics fm = g2d.getFontMetrics(); + + // 绘制当前时间的背景矩形 + int padding = 20; + int currentTimeWidth = fm.stringWidth(currentTime); + int currentTimeHeight = fm.getHeight(); + int rectPadding = 5; // 背景矩形内边距 + g2d.setColor(new Color(0, 0, 0, 50)); // 黑色半透明背景 + g2d.fillRect(padding, padding, currentTimeWidth + 2 * rectPadding, currentTimeHeight + 2 * rectPadding); + + // 绘制当前时间在左上角,内边距为20px + g2d.setColor(Color.WHITE); + int currentTimeX = padding + rectPadding + (currentTimeWidth + rectPadding - currentTimeWidth) / 2; + int currentTimeY = padding + rectPadding + fm.getAscent(); + g2d.drawString(currentTime, currentTimeX, currentTimeY); + + // 绘制文本2的背景矩形 + int text2Width = fm.stringWidth(text2); + int text2Height = fm.getHeight(); + g2d.setColor(new Color(0, 0, 0, 50)); // 黑色半透明背景 + g2d.fillRect(padding, padding + currentTimeHeight + rectPadding * 2, text2Width + 2 * rectPadding, text2Height + 2 * rectPadding); + + // 绘制文本2在时间的下面,内边距为20px + g2d.setColor(Color.WHITE); + int text2X = padding + rectPadding + (text2Width + rectPadding - text2Width) / 2; + int text2Y = padding + currentTimeHeight + rectPadding * 3 + fm.getAscent(); + g2d.drawString(text2, text2X, text2Y); + + // 计算文本1的右上角位置 + int text1Width = fm.stringWidth(text1); + int text1X = (int) (x1 + wid); // 框的右上角位置 + int text1Y = (int) (y1 + fm.getAscent()); // 框的右上角紧挨着框 + g2d.setColor(Color.RED); + + g2d.drawString(text1, text1X, text1Y); + + + // 释放资源 + g2d.dispose(); + + return image; + } + + + + } diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/DeviceCamera.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/DeviceCamera.java new file mode 100644 index 0000000..c1f0db7 --- /dev/null +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/DeviceCamera.java @@ -0,0 +1,127 @@ +package com.xr.iec61850clent.models.entity; +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; +import java.util.List; + +/** + * 摄像头管理 + * + * @TableName device_camera + */ +@TableName(value = "device_camera") +@Data +public class DeviceCamera implements Serializable { + /** + * 主键 + */ + @TableId(type = IdType.AUTO) + private Integer id; + + /** + * 摄像头编号 + */ + private String deviceNo; + + /** + * 类型(1 usb 2 mipi 3 球机 4 枪机) + */ + private String deviceType; + + /** + * IP + */ + private String deviceIp; + + /** + * 端口 + */ + private String devicePort; + + /** + * 账号 + */ + private String account; + + /** + * 密码 + */ + private String password; + + private String x; + + private String y; + + private String z; + + /** + * 摄像头型号 + */ + private String deviceModel; + + /** + * 安装位置 + */ + private String position; + + /** + * 品牌 + */ + private String brand; + + /** + * 备注 + */ + private String remarks; + + /** + * 状态(0未使用 1已使用) + */ + private String status; + + /** + * 创建人 + */ + private String createUser; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改人 + */ + private String updateUser; + + /** + * 修改时间 + */ + private Date updateTime; + + /** + * 传输间隔 + */ + private Integer transmissionInterval; + + /** + * 对焦时间 + */ + private Integer warmup; + + @TableField(exist = false) + private List ids; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + /** + * 算法类型 + */ + @TableField(exist = false) + private String algorithmType; +} \ No newline at end of file diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/ExcelConfig.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/ExcelConfig.java index 368b025..60f485d 100644 --- a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/ExcelConfig.java +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/ExcelConfig.java @@ -21,4 +21,8 @@ public class ExcelConfig { private String msg; + private String meterId; + + private String clientIp; + } diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/FocalLengthConfig.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/FocalLengthConfig.java new file mode 100644 index 0000000..b722199 --- /dev/null +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/FocalLengthConfig.java @@ -0,0 +1,260 @@ +package com.xr.iec61850clent.models.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; + +/** + * + * @TableName focal_length_config + */ +@TableName(value ="focal_length_config") +@Data +public class FocalLengthConfig implements Serializable { + /** + * 主键 + */ + @TableId(type = IdType.AUTO) + private Integer id; + + /** + * 表计配置编号 + */ + private Integer configId; + + /** + * 焦距名称 + */ + private String focalName; + + /** + * 焦距tabs下标 + */ + private String focalIndex; + + /** + * 截图框宽 + */ + private Double copperWid; + + /** + * 截图框高 + */ + private Double copperHei; + + /** + * + */ + private Double copperX; + + /** + * + */ + private Double copperY; + + /** + * + */ + private Double copperX2; + + /** + * + */ + private Double copperY2; + + /** + * clock 1指针表计,2数字表计,3状态类 + */ + private String configType; + + /** + * 表计范围起 + */ + private Double meterMin; + + /** + * + */ + private Double meterMax; + + private Double scale; + + /** + * 旋转角度 + */ + private Integer rotate; + + /** + * 状态类状态数量 + */ + private Integer stateNum; + + /** + * 保存状态类多个状态的结果集 + */ + private String parameter; + + /** + * 解析得测试结果 + */ + private String result; + + /** + * 算法:0圆形表计1扇形表计 + */ + private Integer algorithm; + + /** + * 创建人 + */ + private String createUser; + + /** + * 创建时间 + */ + private Date createTime; + + /** + * 修改人 + */ + private String updateUser; + + @TableField(exist = false) + private String gb; + + @TableField(exist = false) + private String gbcs; + + @TableField(exist = false) + private Integer zzsl; + + @TableField(exist = false) + private String needleSeg; + + @TableField(exist = false) + private String invalidChars; + + @TableField(exist = false) + private Integer expectedLen; + + /** + * 修改时间 + */ + private Date updateTime; + @TableField(exist = false) + private List> meterZz; + + /** + * 焦距图片 + */ + private byte[] focalPicture; + + @TableField(exist = false) + private String basePicture; + + @TableField(exist = false) + private static final long serialVersionUID = 1L; + + @Override + public boolean equals(Object that) { + if (this == that) { + return true; + } + if (that == null) { + return false; + } + if (getClass() != that.getClass()) { + return false; + } + FocalLengthConfig other = (FocalLengthConfig) that; + return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) + && (this.getConfigId() == null ? other.getConfigId() == null : this.getConfigId().equals(other.getConfigId())) + && (this.getFocalName() == null ? other.getFocalName() == null : this.getFocalName().equals(other.getFocalName())) + && (this.getFocalIndex() == null ? other.getFocalIndex() == null : this.getFocalIndex().equals(other.getFocalIndex())) + && (this.getCopperWid() == null ? other.getCopperWid() == null : this.getCopperWid().equals(other.getCopperWid())) + && (this.getCopperHei() == null ? other.getCopperHei() == null : this.getCopperHei().equals(other.getCopperHei())) + && (this.getCopperX() == null ? other.getCopperX() == null : this.getCopperX().equals(other.getCopperX())) + && (this.getCopperY() == null ? other.getCopperY() == null : this.getCopperY().equals(other.getCopperY())) + && (this.getConfigType() == null ? other.getConfigType() == null : this.getConfigType().equals(other.getConfigType())) + && (this.getMeterMin() == null ? other.getMeterMin() == null : this.getMeterMin().equals(other.getMeterMin())) + && (this.getMeterMax() == null ? other.getMeterMax() == null : this.getMeterMax().equals(other.getMeterMax())) + && (this.getRotate() == null ? other.getRotate() == null : this.getRotate().equals(other.getRotate())) + && (this.getStateNum() == null ? other.getStateNum() == null : this.getStateNum().equals(other.getStateNum())) + && (this.getParameter() == null ? other.getParameter() == null : this.getParameter().equals(other.getParameter())) + && (this.getResult() == null ? other.getResult() == null : this.getResult().equals(other.getResult())) + && (this.getAlgorithm() == null ? other.getAlgorithm() == null : this.getAlgorithm().equals(other.getAlgorithm())) + && (this.getCreateUser() == null ? other.getCreateUser() == null : this.getCreateUser().equals(other.getCreateUser())) + && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) + && (this.getUpdateUser() == null ? other.getUpdateUser() == null : this.getUpdateUser().equals(other.getUpdateUser())) + && (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime())) + && (Arrays.equals(this.getFocalPicture(), other.getFocalPicture())); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); + result = prime * result + ((getConfigId() == null) ? 0 : getConfigId().hashCode()); + result = prime * result + ((getFocalName() == null) ? 0 : getFocalName().hashCode()); + result = prime * result + ((getFocalIndex() == null) ? 0 : getFocalIndex().hashCode()); + result = prime * result + ((getCopperWid() == null) ? 0 : getCopperWid().hashCode()); + result = prime * result + ((getCopperHei() == null) ? 0 : getCopperHei().hashCode()); + result = prime * result + ((getCopperX() == null) ? 0 : getCopperX().hashCode()); + result = prime * result + ((getCopperY() == null) ? 0 : getCopperY().hashCode()); + result = prime * result + ((getConfigType() == null) ? 0 : getConfigType().hashCode()); + result = prime * result + ((getMeterMin() == null) ? 0 : getMeterMin().hashCode()); + result = prime * result + ((getMeterMax() == null) ? 0 : getMeterMax().hashCode()); + result = prime * result + ((getRotate() == null) ? 0 : getRotate().hashCode()); + result = prime * result + ((getStateNum() == null) ? 0 : getStateNum().hashCode()); + result = prime * result + ((getParameter() == null) ? 0 : getParameter().hashCode()); + result = prime * result + ((getResult() == null) ? 0 : getResult().hashCode()); + result = prime * result + ((getAlgorithm() == null) ? 0 : getAlgorithm().hashCode()); + result = prime * result + ((getCreateUser() == null) ? 0 : getCreateUser().hashCode()); + result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); + result = prime * result + ((getUpdateUser() == null) ? 0 : getUpdateUser().hashCode()); + result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode()); + result = prime * result + (Arrays.hashCode(getFocalPicture())); + return result; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append(getClass().getSimpleName()); + sb.append(" ["); + sb.append("Hash = ").append(hashCode()); + sb.append(", id=").append(id); + sb.append(", configId=").append(configId); + sb.append(", focalName=").append(focalName); + sb.append(", focalIndex=").append(focalIndex); + sb.append(", copperWid=").append(copperWid); + sb.append(", copperHei=").append(copperHei); + sb.append(", copperX=").append(copperX); + sb.append(", copperY=").append(copperY); + sb.append(", configType=").append(configType); + sb.append(", meterMin=").append(meterMin); + sb.append(", meterMax=").append(meterMax); + sb.append(", rotate=").append(rotate); + sb.append(", stateNum=").append(stateNum); + sb.append(", parameter=").append(parameter); + sb.append(", result=").append(result); + sb.append(", algorithm=").append(algorithm); + sb.append(", createUser=").append(createUser); + sb.append(", createTime=").append(createTime); + sb.append(", updateUser=").append(updateUser); + sb.append(", updateTime=").append(updateTime); + sb.append(", focalPicture=").append(focalPicture); + sb.append(", serialVersionUID=").append(serialVersionUID); + sb.append("]"); + return sb.toString(); + } +} \ No newline at end of file diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/Lds5000.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/Lds5000.java index cc43dce..d675e81 100644 --- a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/Lds5000.java +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/entity/Lds5000.java @@ -63,6 +63,10 @@ public class Lds5000 implements Serializable { */ private String f; + private String meterId; + + private String clientIp; + @TableField(exist = false) private static final long serialVersionUID = 1L; diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/iec61850run/Iec61850Scheduled.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/iec61850run/Iec61850Scheduled.java new file mode 100644 index 0000000..f9b09b8 --- /dev/null +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/iec61850run/Iec61850Scheduled.java @@ -0,0 +1,301 @@ +package com.xr.iec61850clent.models.iec61850run; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.beanit.iec61850bean.*; +import com.beanit.iec61850bean.internal.cli.*; +import com.xr.iec61850clent.common.util.ModeUtil; +import com.xr.iec61850clent.common.util.SpringUtils; +import com.xr.iec61850clent.common.util.UploadUtil; +import com.xr.iec61850clent.models.entity.*; +import com.xr.iec61850clent.models.service.*; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.net.InetAddress; +import java.net.UnknownHostException; +import java.util.*; + +import static java.lang.Thread.sleep; + +@Component +public class Iec61850Scheduled { + + private static final ActionProcessor actionProcessor = new ActionProcessor(new ActionExecutor()); + private static volatile ClientAssociation association; + private static ServerModel serverModel; + private int conner =0; + String[] args = new String[] {"param1", "param2", "param3"}; + + @Scheduled(cron = "0 0/1 * * * ?")//每10分钟执行一次 + public void run(){ + StringCliParameter hostParam = new CliParameterBuilder("-h") .setDescription("要访问的服务器的IP域地址。").buildStringParameter("host","192.168.1.93"); + IntCliParameter portParam = new CliParameterBuilder("-p").setDescription("要连接的端口。").buildIntParameter("port", 102); + StringCliParameter modelFileParam= new CliParameterBuilder("-m").setDescription("要从中读取模型的SCL文件的文件名。如果省略此参数,则在连接后将从服务器设备读取模型。").buildStringParameter("model-file"); + List cliParameters = new ArrayList<>(); + cliParameters.add(hostParam); + cliParameters.add(portParam); + cliParameters.add(modelFileParam); + + CliParser cliParser = + new CliParser( + "iec61850bean-console-client", "用于访问IEC61850 MMS服务器的客户端应用程序。"); + cliParser.addParameters(cliParameters); + +// try { +// cliParser.parseArguments(args); +// } catch (CliParseException e1) { +// System.err.println("分析命令行参数时出错:" + e1.getMessage()); +// System.out.println(cliParser.getUsageString()); +// System.exit(1); +// } + + InetAddress address; + try { + address = InetAddress.getByName(hostParam.getValue()); + } catch (UnknownHostException e) { + System.out.println("未知主机:" + hostParam.getValue()); + return; + } + + ClientSap clientSap = new ClientSap(); + try { + association = clientSap.associate(address, portParam.getValue(), null, new EventListener()); + conner = 0; + } catch (IOException e) { + System.out.println("host"+"第"+(conner+1)+"次无法连接到远程主机。"); + conner++; + try{ + sleep(60000); + }catch (Exception p){ + p.printStackTrace(); + } + run(); + } + + Runtime.getRuntime() + .addShutdownHook( + new Thread() { + @Override + public void run() { + association.close(); + } + }); + + System.out.println("192.168.1.93已成功连接"); + + if (modelFileParam.isSelected()) { + System.out.println("正在从文件中读取模型。。。"); + + try { + serverModel = SclParser.parse(modelFileParam.getValue()).get(0); + } catch (SclParseException e1) { + System.out.println("分析SCL文件时出错: " + e1.getMessage()); + return; + } + + association.setServerModel(serverModel); + + System.out.println("成功读取模型"); + + } else { + System.out.println("正在检索模型。。。"); + + try { + serverModel = association.retrieveModel(); + } catch (ServiceError e) { + System.out.println("服务错误: " + e.getMessage()); + return; + } catch (IOException e) { + System.out.println("致命错误: " + e.getMessage()); + return; + } + + System.out.println("成功读取模型"); + System.out.println(serverModel); + Lds5000Service lds5000Service = SpringUtils.getBean(Lds5000Service.class); + MeterConfigService meterConfigService=SpringUtils.getBean(MeterConfigService.class); + MeterReadingRecordService meterReadingRecordService=SpringUtils.getBean(MeterReadingRecordService.class); + MeterTypeService meterTypeService=SpringUtils.getBean(MeterTypeService.class); + FocalLengthConfigService configService = SpringUtils.getBean(FocalLengthConfigService.class); + DeviceCameraService deviceCameraService = SpringUtils.getBean(DeviceCameraService.class); + try { + DataSet dSet = serverModel.getDataSet("TEMPLATELD0/LLN0.dsMeasureInfo1"); + association.getDataSetValues(dSet); + System.out.println("更新模型成功!"); + System.out.println(Arrays.toString(new Collection[]{serverModel.getDataSets()})); + List dataSets=new ArrayList<>(serverModel.getDataSets()); + for (DataSet dataSet:dataSets){ + List fas=dataSet.getMembers(); + for (FcModelNode node:fas){ + Lds5000 lds5000= ModeUtil.getLdsVlue("192.168.1.93",node); + if(lds5000==null){ + continue; + } + if(lds5000.getClentIp().equals("192.168.1.57")){ + System.out.println("-----------------------"); + } + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("node",lds5000.getNode()); + queryWrapper.eq("clent_ip","192.168.1.93"); + Lds5000 lds=lds5000Service.getOne(queryWrapper); + if (lds != null) { + lds.setUpdateTime(new Date()); + lds.setF(lds5000.getF()); + lds5000Service.updateById(lds); + MeterConfig config=meterConfigService.getById(lds5000.getMeterId()); + QueryWrapper query=new QueryWrapper<>(); + query.eq("config_id",config.getId()); + FocalLengthConfig fa= configService.getOne(query); + if(config!=null){ + String fileName = config.getId()+new Date().getTime()+".jpg"; + String url = "http://"+lds5000.getClientIp()+":8080/tao/snapshot"; + BufferedImage bufferedImage = UploadUtil.urlByImage(url); + MeterType type=meterTypeService.getById(config.getTypeId()); + MeterReadingRecord meterReadingRecord=new MeterReadingRecord(); + meterReadingRecord.setMeterId(config.getId()); + meterReadingRecord.setReadingType(lds5000.getType()); + if(node.getFc().name().equals("MX")){ + String value = "0"; + float f = Float.valueOf(lds5000.getF()); + if(config.getTypeId() == 3 || config.getTypeId() == 5 || config.getTypeId() == 7){//油位计,保留2位小数 + value = String.format("%.2f", f); + } + if(config.getTypeId() == 4 || config.getTypeId() == 11){//开关计数器 + //处理为整数 + int s = (int) f; + value = s+""; + } + if(config.getTypeId() == 8){//档位数据处理 + //处理为整数 + int s = Math.round(f); + if(s>8){ + int t = s-8; + if(t<9){ + value=t+""; + } + if(t == 9){ + value = "9A"; + } + if(t == 10){ + value = "9B"; + } + if(t == 11){ + value = "9C"; + } + if(t>11){ + value = t-2+""; + } + }else { + value=s+""; + } + } + if(config.getTypeId() == 10){//放电计数器 + int s = Math.round(f); + if(s>=10){ + value = 0+""; + } + } + if(config.getIsJz() == 1){ + value = config.getJzVal(); + } + meterReadingRecord.setReadingValue(value); + }else{ + meterReadingRecord.setReadingValue(lds5000.getStVal()); + } + + BufferedImage buffer = UploadUtil.drawRectangleAndText(bufferedImage, + fa.getCopperX(),fa.getCopperY(),fa.getCopperX2(),fa.getCopperWid(),fa.getCopperHei(),meterReadingRecord.getReadingValue(),config.getMeterName()); + String url1 = UploadUtil.uploadImage(buffer,config.getId(),fileName); + meterReadingRecord.setMeterTypeName(type.getTypeAlias()); + meterReadingRecord.setMeterCode(config.getMeterCode()); + meterReadingRecord.setReadingTime(new Date()); + meterReadingRecord.setCreateUser("SYSTEM"); + meterReadingRecord.setCreateTime(new Date()); + meterReadingRecord.setReadingUrl(url1); + meterReadingRecord.setMeterTypeId(config.getTypeId()); + meterReadingRecord.setOwningInterval(config.getOwningInterval()); + if(config.getIsJz()!=1){ + meterReadingRecordService.save(meterReadingRecord); + } + //abnormalReadingJudgment(meterReadingRecord); + } + }else{ + lds5000.setCreateTime(new Date()); + lds5000Service.save(lds5000); + } + } + } + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("is_jz",1); + queryWrapper.eq("status",1); + List meterConfigs = meterConfigService.list(queryWrapper); + for (MeterConfig config:meterConfigs){ + DeviceCamera camera = deviceCameraService.getById(config.getCameraId()); + String fileName = config.getId()+new Date().getTime()+".jpg"; + MeterReadingRecord meterReadingRecord=new MeterReadingRecord(); + meterReadingRecord.setMeterId(config.getId()); + meterReadingRecord.setReadingType(config.getTypeId()); + meterReadingRecord.setReadingTime(new Date()); + meterReadingRecord.setReadingType(2); + meterReadingRecord.setReadingValue(config.getJzVal()); + meterReadingRecord.setMeterTypeName(""); + meterReadingRecord.setMeterCode(config.getMeterCode()); + meterReadingRecord.setReadingTime(new Date()); + meterReadingRecord.setCreateUser("SYSTEM"); + meterReadingRecord.setCreateTime(new Date()); + QueryWrapper query=new QueryWrapper<>(); + query.eq("config_id",config.getId()); + FocalLengthConfig fa= configService.getOne(query); + String url2 = "http://"+camera.getDeviceIp()+":8080/tao/snapshot"; + BufferedImage bufferedImage = UploadUtil.urlByImage(url2); + BufferedImage buffer = UploadUtil.drawRectangleAndText(bufferedImage, + fa.getCopperX(),fa.getCopperY(),fa.getCopperX2(),fa.getCopperWid(),fa.getCopperHei(),meterReadingRecord.getReadingValue(),config.getMeterName()); + String url1 = UploadUtil.uploadImage(buffer,config.getId(),fileName); + meterReadingRecord.setReadingUrl(url1); + meterReadingRecord.setMeterTypeId(config.getTypeId()); + meterReadingRecord.setOwningInterval(config.getOwningInterval()); + meterReadingRecordService.save(meterReadingRecord); + } + } catch (Exception e) { + e.printStackTrace(); + } + association.close(); + } + } + + private static class ActionExecutor implements ActionListener { + @Override + public void actionCalled(String actionKey) throws ActionException { + } + @Override + public void quit() { + System.out.println("** 正在关闭连接。"); + association.close(); + } + } + + private static class EventListener implements ClientEventListener { + + @Override + public void newReport(Report report) { + System.out.println("\n----------------"); + System.out.println("收到的报告: "); + System.err.println(report); + System.out.println("------------------"); + } + + @Override + public void associationClosed(IOException e) { + System.out.print("接收到连接关闭信号。原因: "); + if (!e.getMessage().isEmpty()) { + System.out.println(e.getMessage()); + } else { + System.out.println("unknown"); + } + actionProcessor.close(); + } + } + +} diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/iec61850run/Iec61850clent.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/iec61850run/Iec61850clent.java index 396f23f..8bf150d 100644 --- a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/iec61850run/Iec61850clent.java +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/iec61850run/Iec61850clent.java @@ -14,9 +14,11 @@ import com.xr.iec61850clent.models.entity.*; import com.xr.iec61850clent.models.service.*; import lombok.Data; +import java.awt.image.BufferedImage; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; +import java.nio.file.Files; import java.time.LocalDateTime; import java.util.*; @@ -131,6 +133,8 @@ public class Iec61850clent extends Thread{ MeterConfigService meterConfigService=SpringUtils.getBean(MeterConfigService.class); MeterReadingRecordService meterReadingRecordService=SpringUtils.getBean(MeterReadingRecordService.class); MeterTypeService meterTypeService=SpringUtils.getBean(MeterTypeService.class); + FocalLengthConfigService configService = SpringUtils.getBean(FocalLengthConfigService.class); + DeviceCameraService deviceCameraService = SpringUtils.getBean(DeviceCameraService.class); while (true){ try { DataSet dSet = serverModel.getDataSet("TEMPLATELD0/LLN0.dsMeasureInfo1"); @@ -153,10 +157,14 @@ public class Iec61850clent extends Thread{ lds.setUpdateTime(new Date()); lds.setF(lds5000.getF()); lds5000Service.updateById(lds); - MeterConfig config=meterConfigService.selectNoJzConfig(lds.getId()); + MeterConfig config=meterConfigService.getById(lds5000.getMeterId()); + QueryWrapper query=new QueryWrapper<>(); + query.eq("config_id",config.getId()); + FocalLengthConfig fa= configService.getOne(query); if(config!=null){ String fileName = config.getId()+new Date().getTime()+".jpg"; - String url= UploadUtil.uploadImage(config.getDeviceIp(),config.getId(),fileName); + String url = "http://"+lds5000.getClientIp()+":8080/tao/snapshot"; + BufferedImage bufferedImage = UploadUtil.urlByImage(url); MeterType type=meterTypeService.getById(config.getTypeId()); MeterReadingRecord meterReadingRecord=new MeterReadingRecord(); meterReadingRecord.setMeterId(config.getId()); @@ -174,9 +182,12 @@ public class Iec61850clent extends Thread{ } if(config.getTypeId() == 8){//档位数据处理 //处理为整数 - int s = (int) f; - if(s>7){ - int t = s-7; + int s = Math.round(f); + if(s>8){ + int t = s-8; + if(t<9){ + value=t+""; + } if(t == 9){ value = "9A"; } @@ -206,12 +217,16 @@ public class Iec61850clent extends Thread{ }else{ meterReadingRecord.setReadingValue(lds5000.getStVal()); } + + BufferedImage buffer = UploadUtil.drawRectangleAndText(bufferedImage, + fa.getCopperX(),fa.getCopperY(),fa.getCopperX2(),fa.getCopperWid(),fa.getCopperHei(),meterReadingRecord.getReadingValue(),config.getMeterName()); + String url1 = UploadUtil.uploadImage(buffer,config.getId(),fileName); meterReadingRecord.setMeterTypeName(type.getTypeAlias()); meterReadingRecord.setMeterCode(config.getMeterCode()); meterReadingRecord.setReadingTime(new Date()); meterReadingRecord.setCreateUser("SYSTEM"); meterReadingRecord.setCreateTime(new Date()); - meterReadingRecord.setReadingUrl(url); + meterReadingRecord.setReadingUrl(url1); meterReadingRecord.setMeterTypeId(config.getTypeId()); meterReadingRecord.setOwningInterval(config.getOwningInterval()); if(config.getIsJz()!=1){ @@ -225,10 +240,13 @@ public class Iec61850clent extends Thread{ } } } - List meterConfigs=meterConfigService.selectJzConfig(); + QueryWrapper queryWrapper=new QueryWrapper<>(); + queryWrapper.eq("is_jz",1); + queryWrapper.eq("status",1); + List meterConfigs = meterConfigService.list(queryWrapper); for (MeterConfig config:meterConfigs){ + DeviceCamera camera = deviceCameraService.getById(config.getCameraId()); String fileName = config.getId()+new Date().getTime()+".jpg"; - String url= UploadUtil.uploadImage(config.getDeviceIp(),config.getId(),fileName); MeterReadingRecord meterReadingRecord=new MeterReadingRecord(); meterReadingRecord.setMeterId(config.getId()); meterReadingRecord.setReadingType(config.getTypeId()); @@ -240,7 +258,15 @@ public class Iec61850clent extends Thread{ meterReadingRecord.setReadingTime(new Date()); meterReadingRecord.setCreateUser("SYSTEM"); meterReadingRecord.setCreateTime(new Date()); - meterReadingRecord.setReadingUrl(url); + QueryWrapper query=new QueryWrapper<>(); + query.eq("config_id",config.getId()); + FocalLengthConfig fa= configService.getOne(query); + String url2 = "http://"+camera.getDeviceIp()+":8080/tao/snapshot"; + BufferedImage bufferedImage = UploadUtil.urlByImage(url2); + BufferedImage buffer = UploadUtil.drawRectangleAndText(bufferedImage, + fa.getCopperX(),fa.getCopperY(),fa.getCopperX2(),fa.getCopperWid(),fa.getCopperHei(),meterReadingRecord.getReadingValue(),config.getMeterName()); + String url1 = UploadUtil.uploadImage(buffer,config.getId(),fileName); + meterReadingRecord.setReadingUrl(url1); meterReadingRecord.setMeterTypeId(config.getTypeId()); meterReadingRecord.setOwningInterval(config.getOwningInterval()); meterReadingRecordService.save(meterReadingRecord); diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/mapper/DeviceCameraMapper.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/mapper/DeviceCameraMapper.java new file mode 100644 index 0000000..db3ffe4 --- /dev/null +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/mapper/DeviceCameraMapper.java @@ -0,0 +1,25 @@ +package com.xr.iec61850clent.models.mapper; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xr.iec61850clent.models.entity.DeviceCamera; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** +* @author admin +* @description 针对表【device_camera(摄像头管理)】的数据库操作Mapper +* @createDate 2023-02-21 11:22:23 +* @Entity com.xr.device_car.modules.analysis.entity.DeviceCamera +*/ +@DS("db2") +@Mapper +public interface DeviceCameraMapper extends BaseMapper { +} + + + + diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/mapper/FocalLengthConfigMapper.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/mapper/FocalLengthConfigMapper.java new file mode 100644 index 0000000..ae6a3fc --- /dev/null +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/mapper/FocalLengthConfigMapper.java @@ -0,0 +1,20 @@ +package com.xr.iec61850clent.models.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.xr.iec61850clent.models.entity.FocalLengthConfig; +import org.apache.ibatis.annotations.Mapper; + +/** +* @author asus +* @description 针对表【focal_length_config】的数据库操作Mapper +* @createDate 2023-03-08 17:05:15 +* @Entity com.xr.device_car.modules.analysis.entity.FocalLengthConfig +*/ +@Mapper +public interface FocalLengthConfigMapper extends BaseMapper { + +} + + + + diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/mapper/MeterConfigMapper.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/mapper/MeterConfigMapper.java index 36e5ca7..2073c48 100644 --- a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/mapper/MeterConfigMapper.java +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/mapper/MeterConfigMapper.java @@ -12,7 +12,7 @@ import java.util.List; @Mapper public interface MeterConfigMapper extends BaseMapper { - List selectJzConfig(); + List selectConfig(); MeterConfig selectNoJzConfig(Integer ids5000Id); diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/DeviceCameraService.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/DeviceCameraService.java new file mode 100644 index 0000000..11fa190 --- /dev/null +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/DeviceCameraService.java @@ -0,0 +1,14 @@ +package com.xr.iec61850clent.models.service; + +import com.baomidou.mybatisplus.extension.service.IService; +import com.xr.iec61850clent.models.entity.DeviceCamera; + +import java.util.List; + +/** +* @author admin +* @description 针对表【device_camera(摄像头管理)】的数据库操作Service +* @createDate 2023-02-21 11:22:23 +*/ +public interface DeviceCameraService extends IService { +} diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/FocalLengthConfigService.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/FocalLengthConfigService.java new file mode 100644 index 0000000..04189bd --- /dev/null +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/FocalLengthConfigService.java @@ -0,0 +1,18 @@ +package com.xr.iec61850clent.models.service; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.IService; +import com.xr.iec61850clent.models.entity.FocalLengthConfig; + +import java.util.List; + +/** +* @author asus +* @description 针对表【focal_length_config】的数据库操作Service +* @createDate 2023-03-08 17:05:15 +*/ +public interface FocalLengthConfigService extends IService { + + List getImgFocalList(QueryWrapper queryWrappe); + +} diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/impl/DeviceCameraServiceImpl.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/impl/DeviceCameraServiceImpl.java new file mode 100644 index 0000000..9031b7d --- /dev/null +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/impl/DeviceCameraServiceImpl.java @@ -0,0 +1,24 @@ +package com.xr.iec61850clent.models.service.impl; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.xr.iec61850clent.models.entity.DeviceCamera; +import com.xr.iec61850clent.models.mapper.DeviceCameraMapper; +import com.xr.iec61850clent.models.service.DeviceCameraService; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author admin + * @description 针对表【device_camera(摄像头管理)】的数据库操作Service实现 + * @createDate 2023-02-21 11:22:23 + */ +@Service +@DS("db2") +public class DeviceCameraServiceImpl extends ServiceImpl implements DeviceCameraService { +} + + + + diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/impl/FocalLengthConfigServiceImpl.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/impl/FocalLengthConfigServiceImpl.java new file mode 100644 index 0000000..89a6f10 --- /dev/null +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/impl/FocalLengthConfigServiceImpl.java @@ -0,0 +1,43 @@ +package com.xr.iec61850clent.models.service.impl; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.xr.iec61850clent.models.entity.FocalLengthConfig; +import com.xr.iec61850clent.models.mapper.FocalLengthConfigMapper; +import com.xr.iec61850clent.models.service.FocalLengthConfigService; +import org.springframework.stereotype.Service; + +import java.util.Base64; +import java.util.List; + +/** +* @author asus +* @description 针对表【focal_length_config】的数据库操作Service实现 +* @createDate 2023-03-08 17:05:15 +*/ +@Service +@DS("db2") +public class FocalLengthConfigServiceImpl extends ServiceImpl + implements FocalLengthConfigService { + + @Override + public List getImgFocalList(QueryWrapper queryWrappe) { + List list = ((FocalLengthConfigMapper)this.baseMapper).selectList(queryWrappe); + for(FocalLengthConfig config:list){ + if(config.getFocalPicture()!=null){ + String base64 = Base64.getEncoder().encodeToString(config.getFocalPicture()); + if(base64.contains("data:image/jpg;base64,")){ + config.setBasePicture(base64); + }else{ + config.setBasePicture("data:image/jpg;base64,"+base64); + } + } + } + return list; + } +} + + + + diff --git a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/impl/MeterConfigServiceImpl.java b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/impl/MeterConfigServiceImpl.java index c70637d..13fca70 100644 --- a/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/impl/MeterConfigServiceImpl.java +++ b/device_iec61850clent/src/main/java/com/xr/iec61850clent/models/service/impl/MeterConfigServiceImpl.java @@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.xr.iec61850clent.models.entity.MeterConfig; import com.xr.iec61850clent.models.mapper.MeterConfigMapper; import com.xr.iec61850clent.models.service.MeterConfigService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.List; @@ -17,9 +18,12 @@ import java.util.List; public class MeterConfigServiceImpl extends ServiceImpl implements MeterConfigService{ + @Autowired + private MeterConfigMapper mapper; + @Override public List selectJzConfig() { - return ((MeterConfigMapper)this.baseMapper).selectJzConfig(); + return mapper.selectConfig(); } @Override diff --git a/device_iec61850clent/src/main/resources/IEC61850.xlsx b/device_iec61850clent/src/main/resources/IEC61850.xlsx index fa770a2..6de85d6 100644 Binary files a/device_iec61850clent/src/main/resources/IEC61850.xlsx and b/device_iec61850clent/src/main/resources/IEC61850.xlsx differ diff --git a/device_iec61850clent/src/main/resources/application-dev.yml b/device_iec61850clent/src/main/resources/application-dev.yml index c9d2327..507aa08 100644 --- a/device_iec61850clent/src/main/resources/application-dev.yml +++ b/device_iec61850clent/src/main/resources/application-dev.yml @@ -82,5 +82,5 @@ device: upload: img: - url: http://192.168.1.83:18081/file/img/zs/ + url: http://localhost:18081/file/img/zs/ path: D:\\service\\fileService\\img\\zs\\ \ No newline at end of file diff --git a/device_iec61850clent/src/main/resources/application-prod.yml b/device_iec61850clent/src/main/resources/application-prod.yml index c59bee5..317334c 100644 --- a/device_iec61850clent/src/main/resources/application-prod.yml +++ b/device_iec61850clent/src/main/resources/application-prod.yml @@ -77,9 +77,11 @@ eureka: enabled: true service-url: defaultZone: http://localhost:8084/eureka + device: deviceId: 3 + upload: img: url: http://192.168.1.94:18081/file/img/zs/ - path: D:\\service\\fileService\\img\\zs\\ \ No newline at end of file + path: E:\\service\\fileService\\img\\zs\\ \ No newline at end of file diff --git a/device_iec61850clent/src/main/resources/application.yml b/device_iec61850clent/src/main/resources/application.yml index d378267..c2e7b9c 100644 --- a/device_iec61850clent/src/main/resources/application.yml +++ b/device_iec61850clent/src/main/resources/application.yml @@ -7,7 +7,7 @@ spring: application: name: deviceIec61850clent mybatis-plus: - mapper-locations: classpath:mappers/**/*Mapper.xml + mapper-locations: classpath:mapper/*Mapper.xml type-aliases-package: com.xr.iec61850clent # 在查询语句的是否,对Map或者是entity进行映射赋值的时候null也进行映射。默认false,不进行映射 configuration: @@ -25,3 +25,8 @@ logging: boot: autoconfigure: logging: debug + level: + org: + apache: + ibatis: DEBUG + com.xr.iec61850clent.models.mapper: DEBUG diff --git a/device_iec61850clent/src/main/resources/mapper/FocalLengthConfigMapper.xml b/device_iec61850clent/src/main/resources/mapper/FocalLengthConfigMapper.xml new file mode 100644 index 0000000..4fb88f0 --- /dev/null +++ b/device_iec61850clent/src/main/resources/mapper/FocalLengthConfigMapper.xml @@ -0,0 +1,15 @@ + + + + + id,config_id,focal_name, + focal_index,copper_wid,copper_hei, + copper_x,copper_y,config_type, + meter_min,meter_max,rotate, + state_num,parameter,result,scale, + algorithm,create_user,create_time, + update_user,update_time,focal_picture + + diff --git a/device_iec61850clent/src/main/resources/mapper/MeterConfigMapper.xml b/device_iec61850clent/src/main/resources/mapper/MeterConfigMapper.xml index 37bbcbc..dbfade3 100644 --- a/device_iec61850clent/src/main/resources/mapper/MeterConfigMapper.xml +++ b/device_iec61850clent/src/main/resources/mapper/MeterConfigMapper.xml @@ -34,7 +34,7 @@ - select a.*,b.device_ip from meter_config a left join device_camera b on a.camera_id = b.id where a.is_jz=1 diff --git a/device_udpclent/src/main/java/com/xr/device_udpclent/models/scheduled/UdpClentScheduled.java b/device_udpclent/src/main/java/com/xr/device_udpclent/models/scheduled/UdpClentScheduled.java index 10b1f2b..3a15938 100644 --- a/device_udpclent/src/main/java/com/xr/device_udpclent/models/scheduled/UdpClentScheduled.java +++ b/device_udpclent/src/main/java/com/xr/device_udpclent/models/scheduled/UdpClentScheduled.java @@ -43,7 +43,7 @@ public class UdpClentScheduled { private MeterConfigService meterConfigService; - @Scheduled(cron = "0 0/3 * * * ?") + @Scheduled(cron = "0 0/1 * * * ?") //定时发送监测数据 public void udpTask(){ if(meterReadingRecordService == null){ @@ -51,74 +51,74 @@ public class UdpClentScheduled { } List list = meterReadingRecordService.selectMaxReading(); for (MeterReadingRecord record:list){ - QueryWrapper wrapper=new QueryWrapper<>(); - wrapper.eq("config_id",record.getMeterId()); - List configs=focalLengthConfigService.list(wrapper); - if(configs.size()>0){ - FocalLengthConfig config = configs.get(0); - MeterConfig meterConfig=meterConfigService.getById(config.getConfigId()); - BufferedImage image = Files.bytesTobufferedImage(config.getFocalPicture()); - if(image!=null && config.getCopperX()!=null){ - image = Files.drawRectangleAndText(image,config.getCopperX(),config.getCopperY(),config.getCopperX2(),config.getCopperWid(),config.getCopperHei(),record.getReadingValue(),meterConfig.getMeterName()); - try { - Files.delFile(record.getReadingUrl()); - String url = Files.uploadImage(image,record.getMeterId()); - record.setReadingUrl(url); - meterReadingRecordService.updateById(record); - }catch (Exception e){ - e.printStackTrace(); - } - } - } -// ByteBuf buf = Unpooled.buffer(); -// ByteBuf checksumBuffer = Unpooled.buffer(Long.BYTES); -// buf.writeBytes(new byte[]{(byte) 0xEB, (byte) 0x90,(byte) 0xEB, (byte) 0x90,(byte)0x78}); -// buf.writeShortLE(3); -// buf.writeShort(record.getMeterId()); -// buf.writeByte(2); -// String s="在线监测#"+record.getReadingUrl(); -// byte [] sx; -// try { -// sx = s.getBytes("GB2312"); -// } catch (UnsupportedEncodingException e) { -// throw new RuntimeException(e); -// } -// buf.writeByte(sx.length); -// buf.writeBytes(sx); -// byte [] sz; -// try { -// sz = record.getReadingValue().getBytes("GB2312"); -// } catch (UnsupportedEncodingException e) { -// throw new RuntimeException(e); -// } -// buf.writeByte(sz.length); -// buf.writeBytes(sz); -// buf.writeBytes(generateCP56Time2a()); -// -// // 计算要校验的部分的开始索引和结束索引 -// byte c = 0; -// int startIndex = 5; // 从第6位开始,索引是5(因为索引从0开始) -// int endIndex = buf.readableBytes() - 1; // 到倒数第二位结束 -// // 截取并处理指定范围内的字节 -// if (startIndex <= endIndex) { -// // 临时存放截取的字节 -// byte[] slice = new byte[endIndex - startIndex + 1]; -// // 从ByteBuf中获取数据 -// buf.getBytes(startIndex, slice); -// c=checksum8(slice); -// // 更新Checksum对象 -// //checksum.update(slice, 0, slice.length); -// } -// buf.writeByte(c); -// // 将checksumBuffer追加到buffer末尾 -// buf.writeBytes(checksumBuffer); -// System.out.println(EnumUtil.byteBufTo16Str(buf)); -// udpClientService.sendData(buf); -// try { -// Thread.sleep(100); -// } catch (InterruptedException e) { -// throw new RuntimeException(e); +// QueryWrapper wrapper=new QueryWrapper<>(); +// wrapper.eq("config_id",record.getMeterId()); +// List configs=focalLengthConfigService.list(wrapper); +// if(configs.size()>0){ +// FocalLengthConfig config = configs.get(0); +// MeterConfig meterConfig=meterConfigService.getById(config.getConfigId()); +// BufferedImage image = Files.bytesTobufferedImage(config.getFocalPicture()); +// if(image!=null && config.getCopperX()!=null){ +// image = Files.drawRectangleAndText(image,config.getCopperX(),config.getCopperY(),config.getCopperX2(),config.getCopperWid(),config.getCopperHei(),record.getReadingValue(),meterConfig.getMeterName()); +// try { +// Files.delFile(record.getReadingUrl()); +// String url = Files.uploadImage(image,record.getMeterId()); +// record.setReadingUrl(url); +// meterReadingRecordService.updateById(record); +// }catch (Exception e){ +// e.printStackTrace(); +// } +// } // } + ByteBuf buf = Unpooled.buffer(); + ByteBuf checksumBuffer = Unpooled.buffer(Long.BYTES); + buf.writeBytes(new byte[]{(byte) 0xEB, (byte) 0x90,(byte) 0xEB, (byte) 0x90,(byte)0x78}); + buf.writeShortLE(3); + buf.writeShort(record.getMeterId()); + buf.writeByte(2); + String s="在线监测#"+record.getReadingUrl(); + byte [] sx; + try { + sx = s.getBytes("GB2312"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + buf.writeByte(sx.length); + buf.writeBytes(sx); + byte [] sz; + try { + sz = record.getReadingValue().getBytes("GB2312"); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } + buf.writeByte(sz.length); + buf.writeBytes(sz); + buf.writeBytes(generateCP56Time2a()); + + // 计算要校验的部分的开始索引和结束索引 + byte c = 0; + int startIndex = 5; // 从第6位开始,索引是5(因为索引从0开始) + int endIndex = buf.readableBytes() - 1; // 到倒数第二位结束 + // 截取并处理指定范围内的字节 + if (startIndex <= endIndex) { + // 临时存放截取的字节 + byte[] slice = new byte[endIndex - startIndex + 1]; + // 从ByteBuf中获取数据 + buf.getBytes(startIndex, slice); + c=checksum8(slice); + // 更新Checksum对象 + //checksum.update(slice, 0, slice.length); + } + buf.writeByte(c); + // 将checksumBuffer追加到buffer末尾 + buf.writeBytes(checksumBuffer); + System.out.println(EnumUtil.byteBufTo16Str(buf)); + udpClientService.sendData(buf); + try { + Thread.sleep(100); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } } } diff --git a/device_udpclent/src/main/resources/application.yml b/device_udpclent/src/main/resources/application.yml index 19a3b56..9fd79d5 100644 --- a/device_udpclent/src/main/resources/application.yml +++ b/device_udpclent/src/main/resources/application.yml @@ -1,6 +1,6 @@ spring: profiles: - active: dev #开发环境 + active: prod #开发环境 # active: test #测试环境5 #active: prod #生产环境 application: diff --git a/drone_data/pom.xml b/drone_data/pom.xml index e7d6dbe..758fffd 100644 --- a/drone_data/pom.xml +++ b/drone_data/pom.xml @@ -13,7 +13,7 @@ drone_data Demo project for Spring Boot - 17 + 8 @@ -118,6 +118,14 @@ + + org.apache.maven.plugins + maven-compiler-plugin + + 8 + 8 + + diff --git a/drone_data/src/main/java/com/xr/drone/aliyun/common/MqttClientTest.java b/drone_data/src/main/java/com/xr/drone/aliyun/common/MqttClientTest.java index 363f2b3..fcd3025 100644 --- a/drone_data/src/main/java/com/xr/drone/aliyun/common/MqttClientTest.java +++ b/drone_data/src/main/java/com/xr/drone/aliyun/common/MqttClientTest.java @@ -5,7 +5,7 @@ import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence; public class MqttClientTest { - public static void main(String[] args) { + public static void main(String[] args) throws MqttException { // EMQX服务器地址 String broker = "tcp://broker.emqx.io:1883"; String clientId = "JavaClient"; @@ -51,7 +51,7 @@ public class MqttClientTest { mqttClient.disconnect(); System.out.println("Disconnected"); - } catch (MqttException | InterruptedException me) { + } catch (Exception me) { me.printStackTrace(); } diff --git a/drone_data/src/main/java/com/xr/drone/demo/Demo.java b/drone_data/src/main/java/com/xr/drone/demo/Demo.java new file mode 100644 index 0000000..e69efde --- /dev/null +++ b/drone_data/src/main/java/com/xr/drone/demo/Demo.java @@ -0,0 +1,126 @@ +package com.xr.drone.demo; + +import java.io.IOException; +import java.text.SimpleDateFormat; + +import com.jnrsmcu.sdk.netdevice.IDataListener; +import com.jnrsmcu.sdk.netdevice.LoginData; +import com.jnrsmcu.sdk.netdevice.NodeData; +import com.jnrsmcu.sdk.netdevice.ParamData; +import com.jnrsmcu.sdk.netdevice.ParamIdsData; +import com.jnrsmcu.sdk.netdevice.ParamItem; +import com.jnrsmcu.sdk.netdevice.RSServer; +import com.jnrsmcu.sdk.netdevice.RealTimeData; +import com.jnrsmcu.sdk.netdevice.StoreData; +import com.jnrsmcu.sdk.netdevice.TelecontrolAck; +import com.jnrsmcu.sdk.netdevice.TimmingAck; +import com.jnrsmcu.sdk.netdevice.TransDataAck; +import com.jnrsmcu.sdk.netdevice.WriteParamAck; + +public class Demo { + + public static void main(String[] args) throws IOException, + InterruptedException { + //RSServer rsServer = RSServer.Initiate(2404);// 初始化 + RSServer rsServer = RSServer.Initiate(2404,"C:\\Users\\PC\\Desktop\\JavaSDKV2.2.2\\param.dat"); + rsServer.addDataListener(new IDataListener() {// 添加监听 + @Override + public void receiveTimmingAck(TimmingAck data) {// 校时指令应答处理 + System.out.println("校时应答->设备编号:" + data.getDeviceId() + + "\t执行结果:" + data.getStatus()); + } + + @Override + public void receiveTelecontrolAck(TelecontrolAck data) {// 遥控指令应答处理 + System.out.println("遥控应答->设备编号:" + data.getDeviceId() + + "\t继电器编号:" + data.getRelayId() + "\t执行结果:" + + data.getStatus()); + } + + @Override + public void receiveStoreData(StoreData data) {// 已存储数据接收处理 + // 遍历节点数据。数据包括网络设备的数据以及各个节点数据。温湿度数据存放在节点数据中 + for (NodeData nd : data.getNodeList()) { + SimpleDateFormat sdf = new SimpleDateFormat( + "yy-MM-dd HH:mm:ss"); + String str = sdf.format(nd.getRecordTime()); + System.out.println("存储数据->设备地址:" + data.getDeviceId() + + "\t节点:" + nd.getNodeId() + "\t温度:" + nd.getTem() + + "\t湿度:" + nd.getHum() + "\t存储时间:" + str); + } + + } + + @Override + public void receiveRealtimeData(RealTimeData data) {// 实时数据接收处理 + // 遍历节点数据。数据包括网络设备的数据以及各个节点数据。温湿度数据存放在节点数据中 + for (NodeData nd : data.getNodeList()) { + System.out.println("实时数据->设备地址:" + data.getDeviceId() + + "\t节点:" + nd.getNodeId() + "\t温度:" + nd.getTem() + + "\t湿度:" + nd.getHum() + "\t经度:" + data.getLng() + + "\t纬度:" + data.getLat() + "\t坐标类型:" + + data.getCoordinateType() + "\t继电器状态:" + + data.getRelayStatus()); + } + + } + + @Override + public void receiveLoginData(LoginData data) {// 登录数据接收处理 + System.out.println("登录->设备地址:" + data.getDeviceId()); + + } + + @Override + public void receiveParamIds(ParamIdsData data) { + String str = "设备参数编号列表->设备编号:" + data.getDeviceId() + + "\t参数总数量:" + data.getTotalCount() + "\t本帧参数数量:" + + data.getCount() + "\r\n"; + for (int paramId : data.getPararmIdList())// 遍历设备中参数id编号 + { + str += paramId + ","; + } + System.out.println(str); + + } + + @Override + public void receiveParam(ParamData data) { + String str = "设备参数->设备编号:" + data.getDeviceId() + "\r\n"; + + for (ParamItem pararm : data.getParameterList()) { + str += "参数编号:" + + pararm.getParamId() + + "\t参数描述:" + + pararm.getDescription() + + "\t参数值:" + + (pararm.getValueDescription() == null ? pararm + .getValue() : pararm.getValueDescription() + .get(pararm.getValue())) + "\r\n"; + } + System.out.println(str); + + } + + @Override + public void receiveWriteParamAck(WriteParamAck data) { + String str = "下载设备参数->设备编号:" + data.getDeviceId() + "\t参数数量:" + + data.getCount() + "\t" + + (data.isSuccess() ? "下载成功" : "下载失败"); + System.out.println(str); + + } + + @Override + public void receiveTransDataAck(TransDataAck data) { + String str = "数据透传->设备编号:" + data.getDeviceId() + "\t响应结果:" + + data.getData() + "\r\n字节数:" + data.getTransDataLen(); + System.out.println(str); + + } + }); + rsServer.start(); + + } + +} diff --git a/drone_data/src/main/java/com/xr/drone/demo/SwingDemo.java b/drone_data/src/main/java/com/xr/drone/demo/SwingDemo.java new file mode 100644 index 0000000..410d291 --- /dev/null +++ b/drone_data/src/main/java/com/xr/drone/demo/SwingDemo.java @@ -0,0 +1,477 @@ +package com.xr.drone.demo; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.List; + +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +import com.jnrsmcu.sdk.netdevice.IDataListener; +import com.jnrsmcu.sdk.netdevice.LoginData; +import com.jnrsmcu.sdk.netdevice.NodeData; +import com.jnrsmcu.sdk.netdevice.ParamData; +import com.jnrsmcu.sdk.netdevice.ParamIdsData; +import com.jnrsmcu.sdk.netdevice.ParamItem; +import com.jnrsmcu.sdk.netdevice.RSServer; +import com.jnrsmcu.sdk.netdevice.RealTimeData; +import com.jnrsmcu.sdk.netdevice.StoreData; +import com.jnrsmcu.sdk.netdevice.TelecontrolAck; +import com.jnrsmcu.sdk.netdevice.TimmingAck; +import com.jnrsmcu.sdk.netdevice.TransDataAck; +import com.jnrsmcu.sdk.netdevice.WriteParamAck; + +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; +import javax.swing.JPanel; +import javax.swing.border.LineBorder; + +import java.awt.Color; + +import javax.swing.border.TitledBorder; +import javax.swing.LayoutStyle.ComponentPlacement; + +public class SwingDemo extends JFrame { + + /** + * + */ + private static final long serialVersionUID = -7855826301914463533L; + private JTextField txtPort; + private JScrollPane scrollPane; + private JTextArea textArea; + private JButton btnStart; + private JButton btnStop; + private JCheckBox chkRelay0; + private JCheckBox chkRelay1; + private JCheckBox chkRelay2; + private JCheckBox chkRelay3; + private JCheckBox chkRelay4; + private JCheckBox chkRelay5; + private JCheckBox chkRelay6; + private JCheckBox chkRelay7; + private JButton btnTimming; + private JButton btnCallStore; + private RSServer rsServer;// 定义监听服务对象 + private IDataListener listener = new IDataListener() { + + @Override + public void receiveTimmingAck(TimmingAck data) {// 校时指令应答处理 + textArea.append("校时应答->设备编号:" + data.getDeviceId() + "\t执行结果:" + + data.getStatus() + "\r\n"); + } + + @Override + public void receiveTelecontrolAck(TelecontrolAck data) {// 遥控指令应答处理 + textArea.append("遥控应答->设备编号:" + data.getDeviceId() + "\t继电器编号:" + + data.getRelayId() + "\t执行结果:" + data.getStatus() + "\r\n"); + } + + @Override + public void receiveStoreData(StoreData data) {// 已存储数据接收处理 + // 遍历节点数据。数据包括网络设备的数据以及各个节点数据。温湿度数据存放在节点数据中 + for (NodeData nd : data.getNodeList()) { + SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss"); + String str = sdf.format(nd.getRecordTime()); + + textArea.append("存储数据->设备地址:" + data.getDeviceId() + "\t节点:" + + nd.getNodeId() + "\t温度:" + nd.getTem() + "\t湿度:" + + nd.getHum() + "\t存储时间:" + str+"\t坐标类型:"+nd.getCoordinateType()+"\t经度:"+nd.getLng()+"\t纬度:"+nd.getLat() + "\r\n"); + + + + } + + } + + @Override + public void receiveRealtimeData(RealTimeData data) {// 实时数据接收处理 + // 遍历节点数据。数据包括网络设备的数据以及各个节点数据。温湿度数据存放在节点数据中 + for (NodeData nd : data.getNodeList()) { + textArea.append("实时数据->设备地址:" + data.getDeviceId() + "\t节点:" + + nd.getNodeId() + "\t温度:" + nd.getTem() + "\t湿度:" + + nd.getHum() + "\t经度:" + data.getLng() + "\t纬度:" + + data.getLat() + "\t坐标类型:" + data.getCoordinateType() + + "\t继电器状态" + data.getRelayStatus() + "\t浮点型数据:" + + nd.getFloatValue() + "\t32位有符号数据:" + + nd.getSignedInt32Value() + "\t32位无符号数据:" + + nd.getUnSignedInt32Value() + "\r\n"); + } + + } + + @Override + public void receiveLoginData(LoginData data) {// 登录数据接收处理 + textArea.append("登录->设备地址:" + data.getDeviceId() + "\r\n"); + + } + + @Override + public void receiveParamIds(ParamIdsData data) { + String str = "设备参数编号列表->设备编号:" + data.getDeviceId() + "\t参数总数量:" + + data.getTotalCount() + "\t本帧参数数量:" + data.getCount() + + "\r\n"; + for (int paramId : data.getPararmIdList())// 遍历设备中参数id编号 + { + str += paramId + ","; + } + textArea.append(str + "\r\n"); + + } + + @Override + public void receiveParam(ParamData data) { + String str = "设备参数->设备编号:" + data.getDeviceId() + "\r\n"; + + for (ParamItem pararm : data.getParameterList()) { + str += "参数编号:" + + pararm.getParamId() + + "\t参数描述:" + + pararm.getDescription() + + "\t参数值:" + + (pararm.getValueDescription() == null ? pararm + .getValue() : pararm.getValueDescription().get( + pararm.getValue())) + "\r\n"; + } + textArea.append(str + "\r\n"); + + } + + @Override + public void receiveWriteParamAck(WriteParamAck data) { + String str = "下载设备参数->设备编号:" + data.getDeviceId() + "\t参数数量:" + + data.getCount() + "\t" + + (data.isSuccess() ? "下载成功" : "下载失败"); + textArea.append(str + "\r\n"); + + } + + @Override + public void receiveTransDataAck(TransDataAck data) { + String str = "数据透传->设备编号:" + data.getDeviceId() + "\t响应结果:" + + data.getData() + "\r\n字节数:" + data.getTransDataLen(); + textArea.append(str + "\r\n"); + + } + }; + + private JTextField txtDeviceId; + private JTextField txtParamIds; + private JTextField txtParamId; + private JTextField txtParamVal; + private JPanel panel_2; + private JLabel label_4; + private JTextField txtTransData; + private JButton btnTrans; + + public SwingDemo() { + setTitle("Demo"); + setResizable(false); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + setSize(653, 710); + setLocationRelativeTo(null); + + JLabel lblNewLabel = new JLabel("\u7AEF\u53E3:"); + lblNewLabel.setBounds(10, 10, 40, 15); + + txtPort = new JTextField(); + txtPort.setBounds(45, 7, 66, 21); + txtPort.setText("2404"); + txtPort.setColumns(10); + + btnStart = new JButton("\u542F\u52A8"); + btnStart.setBounds(135, 6, 85, 23); + btnStart.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + btnStart.setEnabled(false); + new Thread(new Runnable() { + + @Override + public void run() { + + rsServer = RSServer.Initiate(Integer.parseInt(txtPort + .getText()),"C:\\Users\\PC\\Desktop\\JavaSDKV2.2.2\\param.dat");// 初始化 + + rsServer.addDataListener(listener);// 添加数据监听事件 + try { + rsServer.start(); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + }// 启动监听服务 + } + }).start(); + } + + }); + + btnStop = new JButton("\u505C\u6B62"); + btnStop.setBounds(237, 6, 85, 23); + btnStop.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + btnStart.setEnabled(true); + rsServer.stop(); + } + }); + + scrollPane = new JScrollPane(); + scrollPane.setBounds(10, 400, 624, 275); + + textArea = new JTextArea(); + scrollPane.setViewportView(textArea); + + JLabel label = new JLabel("\u8BBE\u5907\u5730\u5740:"); + label.setBounds(10, 48, 66, 15); + + txtDeviceId = new JTextField(); + txtDeviceId.setBounds(75, 45, 84, 21); + txtDeviceId.setText("10000000"); + txtDeviceId.setColumns(10); + + btnTimming = new JButton("\u6821\u65F6"); + btnTimming.setBounds(336, 6, 85, 23); + btnTimming.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + int deviceId = Integer.parseInt(txtDeviceId.getText()); + rsServer.timming(deviceId); + } + }); + + btnCallStore = new JButton("\u53EC\u5524\u6570\u636E"); + btnCallStore.setBounds(428, 6, 90, 23); + btnCallStore.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int deviceId = Integer.parseInt(txtDeviceId.getText()); + + rsServer.callStoreData(deviceId); + } + }); + + JPanel panel = new JPanel(); + panel.setBounds(10, 84, 624, 57); + panel.setBorder(new TitledBorder(null, + "\u7EE7\u7535\u5668\u63A7\u5236", TitledBorder.LEADING, + TitledBorder.TOP, null, null)); + + JPanel panel_1 = new JPanel(); + panel_1.setBounds(10, 147, 624, 112); + panel_1.setBorder(new TitledBorder(null, "\u8BBE\u5907\u53C2\u6570", + TitledBorder.LEADING, TitledBorder.TOP, null, null)); + + panel_2 = new JPanel(); + panel_2.setBounds(10, 269, 624, 113); + panel_2.setBorder(new TitledBorder(null, "\u6570\u636E\u900F\u4F20", + TitledBorder.LEADING, TitledBorder.TOP, null, null)); + panel_2.setLayout(null); + + label_4 = new JLabel( + "\u900F\u4F20\u6570\u636E\uFF0C16\u8FDB\u5236\u5B57\u7B26\u4E32"); + label_4.setBounds(10, 23, 419, 15); + panel_2.add(label_4); + + txtTransData = new JTextField(); + txtTransData.setBounds(10, 48, 604, 21); + panel_2.add(txtTransData); + txtTransData.setColumns(10); + + btnTrans = new JButton("\u6570\u636E\u900F\u4F20"); + btnTrans.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + int deviceId = Integer.parseInt(txtDeviceId.getText()); + + rsServer.trans(deviceId, txtTransData.getText()); + } + }); + btnTrans.setBounds(10, 79, 93, 23); + panel_2.add(btnTrans); + panel_1.setLayout(null); + + JLabel label_1 = new JLabel( + "\u53C2\u6570\u7F16\u53F7\uFF0C\u7528\u4E8E\u8BFB\u53D6\u8BBE\u5907\u53C2\u6570\uFF08\u591A\u4E2A\u7F16\u53F7\u7528\u82F1\u6587,\u5206\u9694\uFF09"); + label_1.setBounds(10, 22, 421, 15); + panel_1.add(label_1); + + txtParamIds = new JTextField(); + txtParamIds.setText("1,2,3,4,5,6,7,8,9,10"); + txtParamIds.setBounds(10, 47, 421, 21); + panel_1.add(txtParamIds); + txtParamIds.setColumns(10); + + JLabel label_2 = new JLabel("\u53C2\u6570\u7F16\u53F7"); + label_2.setBounds(10, 78, 54, 15); + panel_1.add(label_2); + + txtParamId = new JTextField(); + txtParamId.setBounds(68, 75, 66, 21); + panel_1.add(txtParamId); + txtParamId.setColumns(10); + + JLabel label_3 = new JLabel("\u53C2\u6570\u503C"); + label_3.setBounds(144, 78, 54, 15); + panel_1.add(label_3); + + txtParamVal = new JTextField(); + txtParamVal.setBounds(202, 75, 66, 21); + panel_1.add(txtParamVal); + txtParamVal.setColumns(10); + + JButton btnReadParametersList = new JButton( + "\u8BFB\u53D6\u8BBE\u5907\u53C2\u6570\u5217\u8868"); + btnReadParametersList.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + int deviceId = Integer.parseInt(txtDeviceId.getText()); + rsServer.callParamList(deviceId);// 发送召唤设备参数列表指令 + } + }); + btnReadParametersList.setBounds(460, 18, 142, 23); + panel_1.add(btnReadParametersList); + + JButton btnReadParameters = new JButton( + "\u8BFB\u53D6\u8BBE\u5907\u53C2\u6570"); + btnReadParameters.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + int deviceId = Integer.parseInt(txtDeviceId.getText()); + List ids = new ArrayList(); + String[] idArray = txtParamIds.getText().split(","); + for (String str : idArray) { + try { + ids.add(Integer.parseInt(str)); + } catch (Exception e) { + } + } + if (ids.size() >= 115) { + + JOptionPane.showMessageDialog(null, "一次读取参数数量不能超过115个", + "提示", JOptionPane.INFORMATION_MESSAGE); + return; + } + rsServer.callParam(deviceId, ids); + + } + }); + btnReadParameters.setBounds(460, 46, 142, 23); + panel_1.add(btnReadParameters); + + JButton btnWriteParameters = new JButton( + "\u4E0B\u8F7D\u8BBE\u5907\u53C2\u6570"); + btnWriteParameters.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + int deviceId = Integer.parseInt(txtDeviceId.getText()); + List parameters = new ArrayList(); + + try { + + parameters.add(ParamItem.New( + Integer.parseInt(txtParamId.getText()), + txtParamVal.getText())); + } catch (Exception ex) { + JOptionPane.showMessageDialog(null, ex.getMessage(), "提示", + JOptionPane.INFORMATION_MESSAGE); + return; + } + if (parameters.size() > 115) { + + JOptionPane.showMessageDialog(null, "一次性下发参数数量不能超过115个", + "提示", JOptionPane.INFORMATION_MESSAGE); + return; + } + rsServer.writeParam(deviceId, parameters); + } + }); + btnWriteParameters.setBounds(460, 74, 142, 23); + panel_1.add(btnWriteParameters); + + chkRelay0 = new JCheckBox("\u7EE7\u7535\u56680"); + panel.add(chkRelay0); + + chkRelay1 = new JCheckBox("\u7EE7\u7535\u56681"); + panel.add(chkRelay1); + + chkRelay2 = new JCheckBox("\u7EE7\u7535\u56682"); + panel.add(chkRelay2); + + chkRelay3 = new JCheckBox("\u7EE7\u7535\u56683"); + panel.add(chkRelay3); + + chkRelay4 = new JCheckBox("\u7EE7\u7535\u56684"); + panel.add(chkRelay4); + + chkRelay5 = new JCheckBox("\u7EE7\u7535\u56685"); + panel.add(chkRelay5); + + chkRelay6 = new JCheckBox("\u7EE7\u7535\u56686"); + panel.add(chkRelay6); + + chkRelay7 = new JCheckBox("\u7EE7\u7535\u56687"); + panel.add(chkRelay7); + chkRelay7.addItemListener(new ChkItemListener(7)); + chkRelay6.addItemListener(new ChkItemListener(6)); + chkRelay5.addItemListener(new ChkItemListener(5)); + chkRelay4.addItemListener(new ChkItemListener(4)); + chkRelay3.addItemListener(new ChkItemListener(3)); + chkRelay2.addItemListener(new ChkItemListener(2)); + chkRelay1.addItemListener(new ChkItemListener(1)); + chkRelay0.addItemListener(new ChkItemListener(0)); + getContentPane().setLayout(null); + getContentPane().add(txtPort); + getContentPane().add(lblNewLabel); + getContentPane().add(btnStart); + getContentPane().add(btnStop); + getContentPane().add(btnTimming); + getContentPane().add(btnCallStore); + getContentPane().add(txtDeviceId); + getContentPane().add(label); + getContentPane().add(panel_1); + getContentPane().add(panel); + getContentPane().add(panel_2); + getContentPane().add(scrollPane); + } + + class ChkItemListener implements ItemListener { + + private int relayId = 0; + + public ChkItemListener(int relayId) { + this.relayId = relayId; + } + + @Override + public void itemStateChanged(ItemEvent e) { + JCheckBox jcb = (JCheckBox) e.getItem(); + int deviceId = Integer.parseInt(txtDeviceId.getText()); + if (jcb.isSelected()) { + + try { + rsServer.telecontrol(deviceId, relayId, 0, 0); + } catch (Exception e1) { + e1.printStackTrace(); + } + + } else { + try { + rsServer.telecontrol(deviceId, relayId, 1, 0); + } catch (Exception e1) { + e1.printStackTrace(); + } + } + } + } + + public static void main(String[] args) { + new SwingDemo().setVisible(true); + + } +} diff --git a/drone_data/src/main/java/com/xr/drone/modules/entity/mqtt/MqttTop.java b/drone_data/src/main/java/com/xr/drone/modules/entity/mqtt/MqttTop.java new file mode 100644 index 0000000..9f6fb75 --- /dev/null +++ b/drone_data/src/main/java/com/xr/drone/modules/entity/mqtt/MqttTop.java @@ -0,0 +1,12 @@ +package com.xr.drone.modules.entity.mqtt; + +import lombok.Data; + +@Data +public class MqttTop { + + private String ts; + + private TopDetail topDetail; + +} diff --git a/drone_data/src/main/java/com/xr/drone/modules/entity/mqtt/TopDetail.java b/drone_data/src/main/java/com/xr/drone/modules/entity/mqtt/TopDetail.java new file mode 100644 index 0000000..7e8375a --- /dev/null +++ b/drone_data/src/main/java/com/xr/drone/modules/entity/mqtt/TopDetail.java @@ -0,0 +1,22 @@ +package com.xr.drone.modules.entity.mqtt; + +import lombok.Data; + +@Data +public class TopDetail { + + private String devName; + + private String devMac; + + private String battery; + + private String snapType; + + private String localtime; + + private String imageSize; + + private String image; + +} diff --git a/drone_data/src/main/java/com/xr/drone/modules/service/Impl/MqttServiceImpl.java b/drone_data/src/main/java/com/xr/drone/modules/service/Impl/MqttServiceImpl.java index c27af72..bf66a01 100644 --- a/drone_data/src/main/java/com/xr/drone/modules/service/Impl/MqttServiceImpl.java +++ b/drone_data/src/main/java/com/xr/drone/modules/service/Impl/MqttServiceImpl.java @@ -1,5 +1,8 @@ package com.xr.drone.modules.service.Impl; +import com.alibaba.fastjson.JSONObject; +import com.xr.drone.modules.entity.mqtt.MqttTop; +import com.xr.drone.modules.entity.mqtt.TopDetail; import com.xr.drone.modules.service.MqttService; import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; import org.eclipse.paho.client.mqttv3.MqttCallback; @@ -16,6 +19,8 @@ public class MqttServiceImpl implements MqttService, MqttCallback { System.out.println("接收消息主题 : " + topic); System.out.println("接收消息Qos : " + message.getQos()); String res = new String(message.getPayload()); + MqttTop mqttTop = JSONObject.parseObject(res,MqttTop.class); + TopDetail detail = mqttTop.getTopDetail(); System.out.println("接收消息内容 : " + res); } diff --git a/drone_data/src/main/resources/application-prod.yml b/drone_data/src/main/resources/application-prod.yml index bea89ab..37c3796 100644 --- a/drone_data/src/main/resources/application-prod.yml +++ b/drone_data/src/main/resources/application-prod.yml @@ -34,11 +34,11 @@ spring: mqtt: username: admin password: admin123 - url: tcp://116.196.120.81:1883 + url: tcp://localhost:1883 client: id: 456787654345 default: - topic: /sys/helloword + topic: X1SensingCam/Snapshot mqtt: connection: timeout: 30000 diff --git a/pom.xml b/pom.xml index 6cff70e..de6c445 100644 --- a/pom.xml +++ b/pom.xml @@ -41,6 +41,7 @@ 4.1.42.Final 3.9 2.10 + 1.8