Browse Source

中山站部署内容

dev-zs
yj 2 years ago
parent
commit
20360b1647
  1. 40
      device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/MeterReadController.java
  2. 5
      device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/MeterReadingRecord.java
  3. 7
      device_cars/src/main/java/com/xr/device_car/modules/analysis/mapper/MeterReadingRecordMapper.java
  4. 5
      device_cars/src/main/java/com/xr/device_car/modules/analysis/service/MeterReadingRecordService.java
  5. 8
      device_cars/src/main/java/com/xr/device_car/modules/analysis/service/impl/MeterReadingRecordServiceImpl.java
  6. 7
      device_cars/src/main/resources/modules/analysis/MeterReadingRecordMapper.xml
  7. 2
      device_display/src/main/java/com/xr/device_display/modules/analysis/controller/MeterReadingController.java
  8. BIN
      device_iec61850clent/src/main/resources/IEC61850.xlsx
  9. 67
      device_udpclent/src/main/java/com/xr/device_udpclent/common/utils/Files.java
  10. 131
      device_udpclent/src/main/java/com/xr/device_udpclent/models/scheduled/UdpClentScheduled.java
  11. 2
      device_udpclent/src/main/resources/application-dev.yml
  12. 3
      device_udpclent/src/main/resources/application.yml

40
device_cars/src/main/java/com/xr/device_car/modules/analysis/controller/MeterReadController.java

@ -0,0 +1,40 @@
package com.xr.device_car.modules.analysis.controller;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xr.device_car.config.utils.StringFormatterUtil;
import com.xr.device_car.config.utils.StringUtils;
import com.xr.device_car.modules.analysis.entity.DataTransferCamera;
import com.xr.device_car.modules.analysis.entity.MeterReadingRecord;
import com.xr.device_car.modules.analysis.service.MeterReadingRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
@RestController
@RequestMapping("read")
@RequiredArgsConstructor
public class MeterReadController {
private final MeterReadingRecordService meterReadingRecordService;
@RequestMapping("/pageList")
public IPage<MeterReadingRecord> pageList(MeterReadingRecord readingRecord, HttpServletRequest req){
Page<MeterReadingRecord> page = StringFormatterUtil.returnPage(req);
QueryWrapper<MeterReadingRecord> query=new QueryWrapper<>();
if(StringUtils.isNotEmpty(readingRecord.getMeterName())){
query.like("b.meter_name",readingRecord.getMeterName());
}
if(StringUtils.isNotEmpty(readingRecord.getOwningInterval())){
query.like("b.owning_interval",readingRecord.getOwningInterval());
}
IPage<MeterReadingRecord> ipage = meterReadingRecordService.pageList(page,query);
return ipage;
}
}

5
device_cars/src/main/java/com/xr/device_car/modules/analysis/entity/MeterReadingRecord.java

@ -32,6 +32,11 @@ public class MeterReadingRecord implements Serializable {
*/ */
private String meterCode; private String meterCode;
@TableField(exist = false)
private String meterName;
private String readingUrl;
private String readingType; private String readingType;

7
device_cars/src/main/java/com/xr/device_car/modules/analysis/mapper/MeterReadingRecordMapper.java

@ -1,7 +1,12 @@
package com.xr.device_car.modules.analysis.mapper; package com.xr.device_car.modules.analysis.mapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xr.device_car.modules.analysis.entity.MeterReadingRecord; import com.xr.device_car.modules.analysis.entity.MeterReadingRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
/** /**
* @author asus * @author asus
@ -15,6 +20,8 @@ public interface MeterReadingRecordMapper extends BaseMapper<MeterReadingRecord>
void deleteToLog(); void deleteToLog();
IPage<MeterReadingRecord> pageList(@Param("page") Page page, @Param(Constants.WRAPPER)Wrapper<MeterReadingRecord> wrapper);
} }

5
device_cars/src/main/java/com/xr/device_car/modules/analysis/service/MeterReadingRecordService.java

@ -1,5 +1,8 @@
package com.xr.device_car.modules.analysis.service; package com.xr.device_car.modules.analysis.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xr.device_car.modules.analysis.entity.MeterReadingRecord; import com.xr.device_car.modules.analysis.entity.MeterReadingRecord;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
@ -13,4 +16,6 @@ public interface MeterReadingRecordService extends IService<MeterReadingRecord>
void deleteToZt(); void deleteToZt();
void deleteToLog(); void deleteToLog();
IPage<MeterReadingRecord> pageList(Page<MeterReadingRecord> page, QueryWrapper<MeterReadingRecord> query);
} }

8
device_cars/src/main/java/com/xr/device_car/modules/analysis/service/impl/MeterReadingRecordServiceImpl.java

@ -1,6 +1,9 @@
package com.xr.device_car.modules.analysis.service.impl; package com.xr.device_car.modules.analysis.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xr.device_car.modules.analysis.entity.MeterReadingRecord; import com.xr.device_car.modules.analysis.entity.MeterReadingRecord;
import com.xr.device_car.modules.analysis.service.MeterReadingRecordService; import com.xr.device_car.modules.analysis.service.MeterReadingRecordService;
@ -26,6 +29,11 @@ public class MeterReadingRecordServiceImpl extends ServiceImpl<MeterReadingRecor
public void deleteToLog() { public void deleteToLog() {
((MeterReadingRecordMapper)this.baseMapper).deleteToLog(); ((MeterReadingRecordMapper)this.baseMapper).deleteToLog();
} }
@Override
public IPage<MeterReadingRecord> pageList(Page<MeterReadingRecord> page, QueryWrapper<MeterReadingRecord> query) {
return ((MeterReadingRecordMapper)this.baseMapper).pageList(page,query);
}
} }

7
device_cars/src/main/resources/modules/analysis/MeterReadingRecordMapper.xml

@ -33,4 +33,11 @@
<delete id="deleteToLog"> <delete id="deleteToLog">
delete from send_udp_log WHERE DATE(request_time) = DATE(NOW() - INTERVAL 1 DAY); delete from send_udp_log WHERE DATE(request_time) = DATE(NOW() - INTERVAL 1 DAY);
</delete> </delete>
<select id="pageList" resultType="com.xr.device_car.modules.analysis.entity.MeterReadingRecord">
select a.id,a.meter_id,a.meter_code,a.meter_type_name,
a.reading_time,a.reading_value,a.reading_url,b.meter_name,b.owning_interval
from meter_reading_record a left join meter_config b on a.meter_id=b.id
${ew.customSqlSegment}
</select>
</mapper> </mapper>

2
device_display/src/main/java/com/xr/device_display/modules/analysis/controller/MeterReadingController.java

@ -17,5 +17,7 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/meter-reading") @RequestMapping("/meter-reading")
public class MeterReadingController { public class MeterReadingController {
} }

BIN
device_iec61850clent/src/main/resources/IEC61850.xlsx

Binary file not shown.

67
device_udpclent/src/main/java/com/xr/device_udpclent/common/utils/Files.java

@ -6,6 +6,7 @@ import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.net.Authenticator; import java.net.Authenticator;
@ -355,13 +356,79 @@ public class Files {
return rqImg; return rqImg;
} }
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;
}
public static void delFile(String url){
String filePath = url.replace(StaticPropUtil.imageUrl,StaticPropUtil.imagePath).replace("/","\\");
File file = new File(filePath);
if(file.exists()){
file.delete();
}
}
} }

131
device_udpclent/src/main/java/com/xr/device_udpclent/models/scheduled/UdpClentScheduled.java

@ -39,6 +39,9 @@ public class UdpClentScheduled {
@Autowired @Autowired
private FocalLengthConfigService focalLengthConfigService; private FocalLengthConfigService focalLengthConfigService;
@Autowired
private MeterConfigService meterConfigService;
@Scheduled(cron = "0 0/3 * * * ?") @Scheduled(cron = "0 0/3 * * * ?")
//定时发送监测数据 //定时发送监测数据
@ -48,68 +51,74 @@ public class UdpClentScheduled {
} }
List<MeterReadingRecord> list = meterReadingRecordService.selectMaxReading(); List<MeterReadingRecord> list = meterReadingRecordService.selectMaxReading();
for (MeterReadingRecord record:list){ for (MeterReadingRecord record:list){
// QueryWrapper<FocalLengthConfig> wrapper=new QueryWrapper<>(); QueryWrapper<FocalLengthConfig> wrapper=new QueryWrapper<>();
// wrapper.eq("config_id",record.getMeterId()); wrapper.eq("config_id",record.getMeterId());
// List<FocalLengthConfig> configs=focalLengthConfigService.list(wrapper); List<FocalLengthConfig> configs=focalLengthConfigService.list(wrapper);
// if(configs.size()>0){ if(configs.size()>0){
// BufferedImage image = Files.bytesTobufferedImage(configs.get(0).getFocalPicture()); FocalLengthConfig config = configs.get(0);
// try { MeterConfig meterConfig=meterConfigService.getById(config.getConfigId());
// String url = Files.uploadImage(image,record.getMeterId()); BufferedImage image = Files.bytesTobufferedImage(config.getFocalPicture());
// record.setReadingUrl(url); if(image!=null && config.getCopperX()!=null){
// meterReadingRecordService.updateById(record); image = Files.drawRectangleAndText(image,config.getCopperX(),config.getCopperY(),config.getCopperX2(),config.getCopperWid(),config.getCopperHei(),record.getReadingValue(),meterConfig.getMeterName());
// }catch (Exception e){ try {
// e.printStackTrace(); Files.delFile(record.getReadingUrl());
// } String url = Files.uploadImage(image,record.getMeterId());
// } record.setReadingUrl(url);
ByteBuf buf = Unpooled.buffer(); meterReadingRecordService.updateById(record);
ByteBuf checksumBuffer = Unpooled.buffer(Long.BYTES); }catch (Exception e){
buf.writeBytes(new byte[]{(byte) 0xEB, (byte) 0x90,(byte) 0xEB, (byte) 0x90,(byte)0x78}); e.printStackTrace();
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);
} }
// 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);
// }
} }
} }

2
device_udpclent/src/main/resources/application-dev.yml

@ -91,7 +91,7 @@ udp:
host: 172.26.4.59 host: 172.26.4.59
port: 9300 port: 9300
upLoad: upLoad:
url: http://116.196.120.81:18081/file/img/zs/ url: http://192.168.1.83:18081/file/img/zs/
path: D:\\service\\fileService\\img\\zs\\ path: D:\\service\\fileService\\img\\zs\\
python: python:
path: C:\\Users\\admin\\Anaconda3\\envs\\myconda310\\python.exe path: C:\\Users\\admin\\Anaconda3\\envs\\myconda310\\python.exe

3
device_udpclent/src/main/resources/application.yml

@ -11,4 +11,7 @@ logging:
boot: boot:
autoconfigure: autoconfigure:
logging: debug logging: debug
level:
com.xr.device_udpclent: debug

Loading…
Cancel
Save