From 08fcd0c56443e184a9bcdbc45269134ff74255f4 Mon Sep 17 00:00:00 2001 From: cdf <857448963@qq.com> Date: Mon, 26 Aug 2024 11:27:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 14 +- .../java/com/njcn/roma/RomaApplication.java | 3 + .../com/njcn/roma/client/ClientHandler.java | 211 +++++++++++++---- .../roma/controller/DeviceController.java | 183 +++++++++++++++ .../njcn/roma/controller/TestController.java | 216 ++++++++++-------- .../roma/mapper/MonitorRealDataMapper.java | 14 ++ .../roma/mapper/PmsHistoryDataMapper.java | 14 +- .../com/njcn/roma/pojo/MonitorRealData.java | 47 ++++ .../com/njcn/roma/pojo/PmsHistoryDataPO.java | 48 ++-- .../roma/service/MonitorRealDataService.java | 13 ++ .../impl/MonitorRealDataServiceImpl.java | 19 ++ .../njcn/roma/utils/JsonValueFluctuator.java | 49 +++- src/main/resources/application.yml | 26 ++- src/main/resources/static/index.html | 61 +---- 14 files changed, 669 insertions(+), 249 deletions(-) create mode 100644 src/main/java/com/njcn/roma/controller/DeviceController.java create mode 100644 src/main/java/com/njcn/roma/mapper/MonitorRealDataMapper.java create mode 100644 src/main/java/com/njcn/roma/pojo/MonitorRealData.java create mode 100644 src/main/java/com/njcn/roma/service/MonitorRealDataService.java create mode 100644 src/main/java/com/njcn/roma/service/impl/MonitorRealDataServiceImpl.java diff --git a/pom.xml b/pom.xml index 1d0aa03..065a22c 100644 --- a/pom.xml +++ b/pom.xml @@ -173,9 +173,13 @@ com.baomidou mybatis-plus-boot-starter - 3.4.3.1 + 3.4.2 + + + com.github.jeffreyning + mybatisplus-plus + 1.5.1-RELEASE - com.baomidou @@ -183,11 +187,7 @@ 3.5.0 - - com.github.jeffreyning - mybatisplus-plus - 1.5.1-RELEASE - + diff --git a/src/main/java/com/njcn/roma/RomaApplication.java b/src/main/java/com/njcn/roma/RomaApplication.java index c017d6f..004663a 100644 --- a/src/main/java/com/njcn/roma/RomaApplication.java +++ b/src/main/java/com/njcn/roma/RomaApplication.java @@ -1,13 +1,16 @@ package com.njcn.roma; +import com.github.jeffreyning.mybatisplus.conf.EnableMPP; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.context.annotation.DependsOn; @SpringBootApplication(scanBasePackages = "com.njcn") @MapperScan("com.njcn.roma.mapper") @DependsOn("proxyMapperRegister") +@EnableMPP public class RomaApplication { public static void main(String[] args) { diff --git a/src/main/java/com/njcn/roma/client/ClientHandler.java b/src/main/java/com/njcn/roma/client/ClientHandler.java index c2ab0d9..b1b108d 100644 --- a/src/main/java/com/njcn/roma/client/ClientHandler.java +++ b/src/main/java/com/njcn/roma/client/ClientHandler.java @@ -1,55 +1,101 @@ package com.njcn.roma.client; +import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.DatePattern; +import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.fasterxml.jackson.annotation.JsonFormat; import com.huawei.it.eip.ump.client.consumer.ConsumeStatus; import com.huawei.it.eip.ump.client.consumer.Consumer; import com.huawei.it.eip.ump.client.listener.MessageListener; import com.huawei.it.eip.ump.common.exception.UmpException; import com.huawei.it.eip.ump.common.message.Message; +import com.njcn.influx.imapper.DataHarmPowerPMapper; +import com.njcn.influx.imapper.DataHarmRateVMapper; +import com.njcn.influx.imapper.DataVMapper; +import com.njcn.influx.pojo.po.DataHarmPowerP; +import com.njcn.influx.pojo.po.DataHarmRateV; +import com.njcn.influx.pojo.po.DataV; +import com.njcn.influx.service.IDataVService; +import com.njcn.roma.mapper.EleEpdPqdMapper; +import com.njcn.roma.pojo.EleEpdPqd; import com.njcn.roma.pojo.MessageBodyDTO; +import com.njcn.roma.pojo.MonitorRealData; import com.njcn.roma.server.WebSocketServer; +import com.njcn.roma.service.MonitorRealDataService; +import com.njcn.roma.utils.JsonValueFluctuator; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.*; import java.io.*; +import java.lang.reflect.Field; import java.nio.charset.StandardCharsets; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.function.Function; +import java.util.stream.Collectors; + +import static com.njcn.roma.utils.JsonValueFluctuator.fluctuateValuesInJson; +import static com.njcn.roma.utils.JsonValueFluctuator.realToData; /** * roma * 客户端用于订阅主题消费数据 + * * @author cdf * @date 2024/6/20 */ -@RestController +@Component @RequiredArgsConstructor +@Slf4j public class ClientHandler extends Thread { + private final ExecutorService executor = Executors.newFixedThreadPool(10); // 假设使用10个线程的线程池 + private final WebSocketServer webSocketServer; - //@Autowired - //private JdbcTemplate jdbcTemplate; - + private final EleEpdPqdMapper eleEpdPqdMapper; private Consumer consumer; + private final DataVMapper dataVMapper; + private final DataHarmRateVMapper dataHarmRateVMapper; + + private final DataHarmPowerPMapper dataHarmPowerPMapper; + + private final MonitorRealDataService monitorRealDataService; + + private Map> classMap = null; + + private final String idKey = "pmswifi_"; + @Override public void run() { + List eleEpdPqdList = eleEpdPqdMapper.selectList(new LambdaQueryWrapper().eq(EleEpdPqd::getSystemType, "pms")); + classMap = eleEpdPqdList.stream().collect(Collectors.groupingBy(EleEpdPqd::getClassId)); + if (consumer == null) { - System.out.println("first join ++++++++++++++++++++++++++++++ roma client"); + + log.info("初始化独立线程作为roma客户端消费数据》》》》》》》》》》》》》"); consumer = new Consumer(); consumer.setUmpNamesrvUrls("25.36.190.3:19776;25.36.190.4:19776"); // 设置统一消息 //平台的服务器地址 @@ -62,32 +108,10 @@ public class ClientHandler extends Thread { consumer.subscribe(new MessageListener() { public ConsumeStatus consume(Message message) { // 消费消息的业务逻辑 - try { - System.out.println("收到新的一轮数据:******************"); - String topicMsg = new String(message.getBody(), "UTF-8"); - String devId = message.getProperties().get("deviceIdentifier"); - System.out.println("Receive>>>>>>>>>>>>: " + topicMsg); - JSONObject jsonObject = JSONObject.parseObject(topicMsg); - jsonObject.put("customDevId", devId); - String time = jsonObject.get("time").toString(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmssX"); - ZonedDateTime dateTime = ZonedDateTime.parse(time, formatter); - String tenTime = dateTime.format(DateTimeFormatter.ofPattern(DatePattern.NORM_DATETIME_PATTERN)); - jsonObject.put("time", tenTime); - String temJson = jsonObject.toJSONString(); - webSocketServer.sendSocketMessageToAll(temJson); - //System.out.println("插入数据:"+ret); - try { - // int ret = jdbcTemplate.update("INSERT INTO `pms_history_data` (`time`, `dev_id`, `content`) VALUES (?, ?, ?);", new Object[]{tenTime, devId, temJson}); - }catch (Exception e){ - System.out.println("执行sql语句错误"+e.getMessage()); - } - } catch (Exception e) { - System.out.println("帮忙拍个照这个是接收消息的报错------------------------------------------------------------"); - e.printStackTrace(); - } + onMessageReceived(message); + // 正常接收到消息后,请务必返回 CONSUME_SUCCESS,只有在业务处理失败才返回RECONSUME_LATER return ConsumeStatus.CONSUME_SUCCESS; } @@ -109,11 +133,7 @@ public class ClientHandler extends Thread { /** * 解析模板 */ - public void praTemplate(){ - - - - + public void praTemplate() { String template = "[{\"datatype\":\"string\",\"description\":\"数据时间\",\"method\":\"R\",\"name\":\"time\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"string\",\"description\":\"数据类型\",\"method\":\"R\",\"name\":\"DataType\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"数据标记\",\"method\":\"R\",\"name\":\"DataTag\",\"unit\":\"\",\"enumlist\":[],\"max\":\"1\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"频率\",\"method\":\"R\",\"name\":\"Freq\",\"unit\":\"Hz\",\"enumlist\":[],\"max\":\"60\",\"min\":\"40\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"频率偏差\",\"method\":\"R\",\"name\":\"FreqDev\",\"unit\":\"Hz\",\"enumlist\":[],\"max\":\"10\",\"min\":\"-10\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电流总有效值\",\"method\":\"R\",\"name\":\"A_phsA\",\"unit\":\"A\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电流总有效值\",\"method\":\"R\",\"name\":\"A_phsB\",\"unit\":\"A\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电流总有效值\",\"method\":\"R\",\"name\":\"A_phsC\",\"unit\":\"A\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压总有效值\",\"method\":\"R\",\"name\":\"PhV_phsA\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压总有效值\",\"method\":\"R\",\"name\":\"PhV_phsB\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压总有效值\",\"method\":\"R\",\"name\":\"PhV_phsC\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"AB线电压总有效值\",\"method\":\"R\",\"name\":\"PPV_phsAB\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"BC线电压总有效值\",\"method\":\"R\",\"name\":\"PPV_phsBC\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"CA线电压总有效值\",\"method\":\"R\",\"name\":\"PPV_phsCA\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压偏差\",\"method\":\"R\",\"name\":\"PhVDev_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压偏差\",\"method\":\"R\",\"name\":\"PhVDev_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压偏差\",\"method\":\"R\",\"name\":\"PhVDev_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"三相总有功功率\",\"method\":\"R\",\"name\":\"TotW\",\"unit\":\"kW\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"-65536\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"三相总无功功率\",\"method\":\"R\",\"name\":\"TotVar\",\"unit\":\"kVar\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"-65536\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"三相总视在功率\",\"method\":\"R\",\"name\":\"TotVA\",\"unit\":\"kVA\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"-65536\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"三相功率因数\",\"method\":\"R\",\"name\":\"TotPF\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"电压正序分量\",\"method\":\"R\",\"name\":\"SeqV_C1\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"电压负序分量\",\"method\":\"R\",\"name\":\"SeqV_C2\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"电压零序分量\",\"method\":\"R\",\"name\":\"SeqV_C0\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"电压负序不平衡度\",\"method\":\"R\",\"name\":\"ImbNgV\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"电压零序不平衡度\",\"method\":\"R\",\"name\":\"ImbZroV\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压基波有效值\",\"method\":\"R\",\"name\":\"HFundPhV_phsA\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压基波有效值\",\"method\":\"R\",\"name\":\"HFundPhV_phsB\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压基波有效值\",\"method\":\"R\",\"name\":\"HFundPhV_phsC\",\"unit\":\"V\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压谐波总畸变率\",\"method\":\"R\",\"name\":\"ThdPhV_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压谐波总畸变率\",\"method\":\"R\",\"name\":\"ThdPhV_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压谐波总畸变率\",\"method\":\"R\",\"name\":\"ThdPhV_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压2次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H2_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压3次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H3_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压4次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H4_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压5次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H5_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压6次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H6_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压7次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H7_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压8次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H8_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压9次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H9_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压10次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H10_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压11次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H11_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压12次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H12_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压13次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H13_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压14次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H14_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压15次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H15_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压16次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H16_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压17次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H17_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压18次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H18_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压19次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H19_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压20次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H20_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压21次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H21_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压22次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H22_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压23次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H23_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压24次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H24_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相电压25次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H25_phsA\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压2次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H2_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压3次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H3_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压4次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H4_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压5次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H5_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压6次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H6_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压7次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H7_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压8次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H8_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压9次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H9_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压10次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H10_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压11次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H11_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压12次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H12_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压13次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H13_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压14次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H14_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压15次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H15_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压16次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H16_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压17次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H17_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压18次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H18_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压19次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H19_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压20次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H20_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压21次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H21_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压22次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H22_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压23次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H23_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压24次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H24_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相电压25次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H25_phsB\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压2次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H2_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压3次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H3_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压4次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H4_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压5次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H5_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压6次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H6_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压7次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H7_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压8次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H8_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压9次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H9_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压10次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H10_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压11次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H11_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压12次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H12_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压13次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H13_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压14次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H14_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压15次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H15_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压16次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H16_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压17次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H17_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压18次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H18_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压19次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H19_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压20次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H20_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压21次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H21_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压22次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H22_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压23次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H23_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压24次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H24_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相电压25次谐波含有率\",\"method\":\"R\",\"name\":\"HRPhV_H25_phsC\",\"unit\":\"%\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相短时闪变\",\"method\":\"R\",\"name\":\"PstPhV_phsA\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相短时闪变\",\"method\":\"R\",\"name\":\"PstPhV_phsB\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相短时闪变\",\"method\":\"R\",\"name\":\"PstPhV_phsC\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"A相长时闪变\",\"method\":\"R\",\"name\":\"PltPhV_phsA\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"B相长时闪变\",\"method\":\"R\",\"name\":\"PltPhV_phsB\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1},{\"datatype\":\"decimal\",\"description\":\"C相长时闪变\",\"method\":\"R\",\"name\":\"PltPhV_phsC\",\"unit\":\"\",\"enumlist\":[],\"max\":\"65536\",\"min\":\"0\",\"maxlength\":32,\"required\":1,\"step\":1}]"; JSONArray jsonArray = JSONArray.parseArray(template); @@ -124,8 +144,6 @@ public class ClientHandler extends Thread { } - ExecutorService executor = Executors.newFixedThreadPool(10); // 假设使用10个线程的线程池 - // 消息消费回调 void onMessageReceived(Message message) { // 将消息处理逻辑封装为Runnable任务 @@ -144,20 +162,125 @@ public class ClientHandler extends Thread { } void processMessage(Message message) { + // 实际的消息处理逻辑 + try { + System.out.println("收到新的一轮数据:******************"); + String devId = idKey+message.getProperties().get("deviceIdentifier"); + String topicMsg = new String(message.getBody(), StandardCharsets.UTF_8); + JSONObject jsonObject = realToData(topicMsg); + jsonObject.put("customDevId", devId); + jsonObject.put("deviceId",message.getProperties().get("deviceId")); + + if(jsonObject.get("DataType").toString().charAt(0) == '0'){ + jsonObject.put("DataType","MAX"); + }else if(jsonObject.get("DataType").toString().charAt(0) == '1'){ + jsonObject.put("DataType","MIN"); + }else if(jsonObject.get("DataType").toString().charAt(0) == '2'){ + jsonObject.put("DataType","AVG"); + }else if(jsonObject.get("DataType").toString().charAt(0) == '3'){ + jsonObject.put("DataType","CP95"); + } + + + String temJson = jsonObject.toJSONString(); + System.out.println("Receive>>>>>>>>>>>>: " + temJson); + assData(devId,jsonObject,temJson); + + + List poList = new ArrayList<>(); + List dataHarmRateVList = new ArrayList<>(); + List dataHarmPowerPList = new ArrayList<>(); + + + String valueType = jsonObject.get("DataType").toString(); + Instant instant = (Instant) jsonObject.get("time"); + classMap.forEach((classId,classList)->{ + Map> elePhaseMap = classList.stream().collect(Collectors.groupingBy(EleEpdPqd::getPhase)); + elePhaseMap.forEach((phase, list) -> { + Map m = list.stream().collect(Collectors.toMap(EleEpdPqd::getName, Function.identity())); + Map map = new HashMap<>(); + m.forEach((mk, mv) -> { + if (jsonObject.containsKey(mk)) { + if (StrUtil.isNotBlank(mv.getOtherName())) { + map.put(mv.getOtherName(), Double.valueOf(jsonObject.get(mk).toString())); + } + } + }); + + + + if(classId.equals("data_v")) { + DataV dataV = new DataV(); + BeanUtil.copyProperties(map, dataV); + dataV.setPhaseType(phase); + dataV.setLineId(devId); + dataV.setValueType(valueType); + dataV.setQualityFlag("0"); + dataV.setTime(instant); + + JsonValueFluctuator.setNullNumberFieldsToZero(dataV); + poList.add(dataV); + }else if(classId.equals("data_harmrate_v")){ + DataHarmRateV dataHarmRateV = new DataHarmRateV(); + BeanUtil.copyProperties(map, dataHarmRateV); + dataHarmRateV.setPhaseType(phase); + dataHarmRateV.setLineId(devId); + dataHarmRateV.setValueType(valueType); + dataHarmRateV.setQualityFlag("0"); + dataHarmRateV.setTime(instant); + + JsonValueFluctuator.setNullNumberFieldsToZero(dataHarmRateV); + dataHarmRateVList.add(dataHarmRateV); + }else if(classId.equals("data_harmpower_p")){ + DataHarmPowerP dataHarmPowerP = new DataHarmPowerP(); + BeanUtil.copyProperties(map, dataHarmPowerP); + dataHarmPowerP.setPhaseType(phase); + dataHarmPowerP.setLineId(devId); + dataHarmPowerP.setValueType(valueType); + dataHarmPowerP.setQualityFlag("0"); + dataHarmPowerP.setTime(instant); + + JsonValueFluctuator.setNullNumberFieldsToZero(dataHarmPowerP); + dataHarmPowerPList.add(dataHarmPowerP); + } + + + }); + + }); + + try { + dataVMapper.insertBatch(poList); + dataHarmRateVMapper.insertBatch(dataHarmRateVList); + dataHarmPowerPMapper.insertBatch(dataHarmPowerPList); + } catch (Exception e) { + e.printStackTrace(); + } + + } catch (Exception e) { + e.printStackTrace(); + } } void handleError(Exception e) { + System.out.println("进入执行异常方法。。。。。。。。。。。。。。。。。。。。。。。。"); // 错误处理逻辑 + e.printStackTrace(); + } + + private void assData(String devId,JSONObject jsonObject,String temJson){ + MonitorRealData monitorRealData = new MonitorRealData(); + monitorRealData.setLineId(devId); + monitorRealData.setId(IdUtil.simpleUUID()); + ZoneId zoneId = ZoneId.systemDefault(); + LocalDateTime localDateTime = ((Instant)jsonObject.get("time")).atZone(zoneId).toLocalDateTime(); + + monitorRealData.setTimeId(localDateTime); + monitorRealData.setValueType(jsonObject.get("DataType").toString()); + monitorRealData.setPmsContent(temJson); + monitorRealDataService.saveOrUpdateByMultiId(monitorRealData); } - - - - - - - - } diff --git a/src/main/java/com/njcn/roma/controller/DeviceController.java b/src/main/java/com/njcn/roma/controller/DeviceController.java new file mode 100644 index 0000000..73d90ed --- /dev/null +++ b/src/main/java/com/njcn/roma/controller/DeviceController.java @@ -0,0 +1,183 @@ +package com.njcn.roma.controller; + +import lombok.RequiredArgsConstructor; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpUriRequest; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.TrustStrategy; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContextBuilder; +import org.apache.http.util.EntityUtils; +import org.json.JSONException; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import javax.net.ssl.SSLContext; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; + +/** + * roma + * 设备台账控制 + * @author cdf + * @date 2024/8/21 + */ +@RestController +@RequiredArgsConstructor +public class DeviceController { + + + @Value("${roma.acceptIp}") + private String acceptIp; + + @Value("${roma.sendIp}") + private String sendIp; + + @Value("${roma.appId}") + private String appId; + + @Value("${roma.appKey}") + private String appKey; + + + /** + * 查询设备信息 + * @author cdf + * @date 2024/8/21 + */ + @GetMapping("queryDevice") + public String queryDeviceById(@RequestParam String devId){ + try { + queryDeviceInfo(devId); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyStoreException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + return "获取成功"; + + } + + + + /** + * 查询告警信息 + * @author cdf + * @date 2024/8/21 + */ + + @GetMapping("alarmHistory") + public String alarmHistory(@RequestParam String devId){ + try { + queryAlarm(devId); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } catch (KeyStoreException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } catch (KeyManagementException e) { + e.printStackTrace(); + } + return "获取成功"; + + } + + + + + /** + * 查询设备信息 + * + * @throws JSONException + * @throws IOException + * @throws NoSuchAlgorithmException + * @throws KeyStoreException + * @throws KeyManagementException + */ + public void queryDeviceInfo(String deviceId) throws NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException { + String url = "https://" + sendIp + "/iot/1.0/devices?deviceId="+deviceId+"&appId=" + appId; + // /iot/1.0/devices?deviceId={deviceId}&appId={appId} + HttpGet httpGet = new HttpGet(url); //创建post请求 + setSSLHeader(httpGet); //设置请求的header + getSSLResponse(httpGet);//获取响应结果 + + } + + + public void queryAlarm(String deviceId) throws NoSuchAlgorithmException, KeyStoreException, IOException, KeyManagementException { + String url = "https://" + sendIp + "/iot/1.0/devices?deviceId="+deviceId+"&appId=" + appId; + // /iot/1.0/devices?deviceId={deviceId}&appId={appId} + HttpGet httpGet = new HttpGet(url); //创建post请求 + setSSLHeader(httpGet); //设置请求的header + getSSLResponse(httpGet);//获取响应结果 + + } + + + + + + + + + /** + * 创建ssl连接,设置客户端信任所有证书 + * @return CloseableHttpClient + * @throws KeyStoreException + * @throws NoSuchAlgorithmException + * @throws KeyManagementException + */ + private CloseableHttpClient createSSLClient() throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { + SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, (TrustStrategy) (chain, authType) -> true).build(); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[]{"TLSv1.2"}, null, + SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); + return HttpClients.custom().setSSLSocketFactory(sslsf).build(); + } + + /** + * 设置请求时的header + * @param httpUriRequest + */ + private void setSSLHeader(HttpUriRequest httpUriRequest) { + long time = System.currentTimeMillis(); + String authorization = DigestUtils.sha256Hex(appId + appKey + time); + httpUriRequest.addHeader("Content-Type", "application/json"); + httpUriRequest.addHeader("Authorization", authorization); + httpUriRequest.addHeader("timestamp", String.valueOf(time)); + } + /** + * 解析响应结果 + * @param httpUriRequest + * @return + * @throws NoSuchAlgorithmException + * @throws KeyStoreException + * @throws KeyManagementException + * @throws IOException + */ + private org.apache.http.HttpEntity getSSLResponse(HttpUriRequest httpUriRequest) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException { + CloseableHttpClient httpClient = createSSLClient(); + CloseableHttpResponse response = httpClient.execute(httpUriRequest); + org.apache.http.HttpEntity responseEntity = response.getEntity(); + System.out.println("响应状态为:" + response.getStatusLine()); + if (responseEntity != null) { + System.out.println("响应内容长度为:" + responseEntity.getContentLength()); + System.out.println("响应内容为:" + EntityUtils.toString(responseEntity)); + } + return responseEntity; + } + +} diff --git a/src/main/java/com/njcn/roma/controller/TestController.java b/src/main/java/com/njcn/roma/controller/TestController.java index eaf7bd3..e335493 100644 --- a/src/main/java/com/njcn/roma/controller/TestController.java +++ b/src/main/java/com/njcn/roma/controller/TestController.java @@ -2,39 +2,40 @@ package com.njcn.roma.controller; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.date.DatePattern; +import cn.hutool.core.util.IdUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.extension.toolkit.SqlHelper; -import com.baomidou.mybatisplus.extension.toolkit.SqlRunner; import com.huawei.it.eip.ump.client.producer.Producer; import com.huawei.it.eip.ump.client.producer.SendResult; import com.huawei.it.eip.ump.common.exception.UmpException; import com.huawei.it.eip.ump.common.message.Message; -import com.njcn.influx.base.InfluxDbBaseMapper; +import com.njcn.influx.imapper.DataHarmPowerPMapper; +import com.njcn.influx.imapper.DataHarmRateVMapper; import com.njcn.influx.imapper.DataVMapper; +import com.njcn.influx.pojo.po.DataHarmPowerP; +import com.njcn.influx.pojo.po.DataHarmRateV; import com.njcn.influx.pojo.po.DataV; -import com.njcn.influx.service.IDataVService; + import com.njcn.roma.client.ClientHandler; import com.njcn.roma.mapper.EleEpdPqdMapper; -import com.njcn.roma.mapper.PmsHistoryDataMapper; + import com.njcn.roma.pojo.EleEpdPqd; -import com.njcn.roma.pojo.PmsHistoryDataPO; + +import com.njcn.roma.pojo.MonitorRealData; import com.njcn.roma.server.WebSocketServer; +import com.njcn.roma.service.MonitorRealDataService; import com.njcn.roma.utils.JsonValueFluctuator; import lombok.RequiredArgsConstructor; -import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.ColumnMapRowMapper; -import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.io.UnsupportedEncodingException; -import java.lang.reflect.Field; -import java.math.BigDecimal; +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.*; @@ -55,16 +56,23 @@ public class TestController { private final WebSocketServer webSocketServer; - public String topicMsg = "{\"HRPhV_H14_phsC\":\"0.0000\",\"HRPhV_H14_phsB\":\"0.0000\",\"HRPhV_H14_phsA\":\"0.0000\",\"HRPhV_H2_phsB\":\"0.0100\",\"HRPhV_H2_phsA\":\"0.0100\",\"HRPhV_H2_phsC\":\"0.0100\",\"HRPhV_H15_phsA\":\"0.0120\",\"TotW\":\"19771.1367\",\"HRPhV_H15_phsB\":\"0.0120\",\"HRPhV_H15_phsC\":\"0.0120\",\"FreqDev\":\"0.0000\",\"PPV_phsAB\":\"384.0318\",\"A_phsC\":\"60.7116\",\"TotPF\":\"0.4946\",\"A_phsA\":\"60.7123\",\"A_phsB\":\"60.7111\",\"PPV_phsBC\":\"383.3656\",\"HRPhV_H25_phsB\":\"0.0080\",\"HRPhV_H25_phsC\":\"0.0080\",\"HRPhV_H25_phsA\":\"0.0080\",\"DataTag\":\"0\",\"HRPhV_H20_phsA\":\"0.0000\",\"HRPhV_H20_phsB\":\"0.0000\",\"HRPhV_H20_phsC\":\"0.0000\",\"PPV_phsCA\":\"383.3637\",\"HRPhV_H3_phsB\":\"0.0640\",\"HRPhV_H3_phsC\":\"0.0640\",\"HRPhV_H9_phsC\":\"0.0220\",\"ThdPhV_phsA\":\"0.0913\",\"HRPhV_H9_phsB\":\"0.0220\",\"HRPhV_H9_phsA\":\"0.0220\",\"ThdPhV_phsB\":\"0.0913\",\"ThdPhV_phsC\":\"0.0913\",\"HRPhV_H19_phsC\":\"0.0100\",\"HRPhV_H19_phsB\":\"0.0100\",\"HRPhV_H19_phsA\":\"0.0100\",\"HRPhV_H16_phsA\":\"0.0000\",\"HRPhV_H13_phsA\":\"0.0140\",\"HRPhV_H16_phsC\":\"0.0000\",\"HRPhV_H13_phsB\":\"0.0140\",\"HRPhV_H16_phsB\":\"0.0000\",\"TotVA\":\"39977.2305\",\"HRPhV_H13_phsC\":\"0.0140\",\"HRPhV_H6_phsB\":\"0.0026\",\"HRPhV_H3_phsA\":\"0.0640\",\"HRPhV_H6_phsA\":\"0.0026\",\"HRPhV_H10_phsA\":\"0.0026\",\"HRPhV_H10_phsB\":\"0.0026\",\"HRPhV_H6_phsC\":\"0.0026\",\"HRPhV_H10_phsC\":\"0.0026\",\"ImbNgV\":\"0.0012\",\"TotVar\":\"34745.9492\",\"HRPhV_H7_phsC\":\"0.0280\",\"HRPhV_H7_phsB\":\"0.0280\",\"HRPhV_H22_phsC\":\"0.0000\",\"HRPhV_H22_phsB\":\"0.0000\",\"ImbZroV\":\"0.0012\",\"HRPhV_H22_phsA\":\"0.0000\",\"HRPhV_H7_phsA\":\"0.0280\",\"HRPhV_H8_phsA\":\"0.0026\",\"HRPhV_H23_phsB\":\"0.0080\",\"PhV_phsA\":\"221.9935\",\"HRPhV_H8_phsB\":\"0.0026\",\"HRPhV_H23_phsC\":\"0.0080\",\"HRPhV_H8_phsC\":\"0.0026\",\"PhV_phsB\":\"221.9947\",\"PhV_phsC\":\"221.9979\",\"HRPhV_H23_phsA\":\"0.0080\",\"PstPhV_phsC\":\"3.2942\",\"PstPhV_phsA\":\"3.3086\",\"PstPhV_phsB\":\"3.2987\",\"Freq\":\"50.0000\",\"HRPhV_H11_phsA\":\"0.0180\",\"HRPhV_H11_phsB\":\"0.0180\",\"HRPhV_H17_phsC\":\"0.0100\",\"HRPhV_H11_phsC\":\"0.0180\",\"HRPhV_H17_phsB\":\"0.0100\",\"HRPhV_H17_phsA\":\"0.0100\",\"SeqV_C2\":\"0.0715\",\"HRPhV_H4_phsB\":\"0.0050\",\"SeqV_C1\":\"60.4601\",\"HRPhV_H4_phsA\":\"0.0050\",\"SeqV_C0\":\"0.0714\",\"PhVDev_phsC\":\"0.0119\",\"HRPhV_H5_phsA\":\"0.0400\",\"HRPhV_H5_phsB\":\"0.0400\",\"HRPhV_H5_phsC\":\"0.0400\",\"PhVDev_phsB\":\"0.0119\",\"HRPhV_H12_phsC\":\"0.0010\",\"PltPhV_phsA\":\"0.0000\",\"PhVDev_phsA\":\"0.0119\",\"HRPhV_H12_phsB\":\"0.0010\",\"HRPhV_H4_phsC\":\"0.0050\",\"HRPhV_H18_phsB\":\"0.0000\",\"HRPhV_H18_phsC\":\"0.0000\",\"HRPhV_H12_phsA\":\"0.0010\",\"HRPhV_H18_phsA\":\"0.0000\",\"HFundPhV_phsC\":\"220.8052\",\"HRPhV_H21_phsC\":\"0.0080\",\"HRPhV_H21_phsB\":\"0.0080\",\"HRPhV_H24_phsC\":\"0.0000\",\"HFundPhV_phsA\":\"220.8056\",\"HRPhV_H21_phsA\":\"0.0080\",\"HFundPhV_phsB\":\"220.8055\",\"HRPhV_H24_phsB\":\"0.0000\",\"PltPhV_phsC\":\"0.0000\",\"HRPhV_H24_phsA\":\"0.0000\",\"PltPhV_phsB\":\"0.0000\",\"time\":\"20240816T150000Z\"}"; + public String topicMsg = "{\"DataType\":\"1.000\",\"HRPhV_H14_phsC\":\"0.2000\",\"HRPhV_H14_phsB\":\"0.0000\",\"HRPhV_H14_phsA\":\"0.0000\",\"HRPhV_H2_phsB\":\"0.0100\",\"HRPhV_H2_phsA\":\"0.0100\",\"HRPhV_H2_phsC\":\"0.0100\",\"HRPhV_H15_phsA\":\"0.0120\",\"TotW\":\"19771.1367\",\"HRPhV_H15_phsB\":\"0.0120\",\"HRPhV_H15_phsC\":\"0.0120\",\"FreqDev\":\"0.0000\",\"PPV_phsAB\":\"384.0318\",\"A_phsC\":\"60.7116\",\"TotPF\":\"0.4946\",\"A_phsA\":\"60.7123\",\"A_phsB\":\"60.7111\",\"PPV_phsBC\":\"383.3656\",\"HRPhV_H25_phsB\":\"0.0080\",\"HRPhV_H25_phsC\":\"0.0080\",\"HRPhV_H25_phsA\":\"0.0080\",\"DataTag\":\"0\",\"HRPhV_H20_phsA\":\"0.0000\",\"HRPhV_H20_phsB\":\"0.0000\",\"HRPhV_H20_phsC\":\"0.0000\",\"PPV_phsCA\":\"383.3637\",\"HRPhV_H3_phsB\":\"0.0640\",\"HRPhV_H3_phsC\":\"0.0640\",\"HRPhV_H9_phsC\":\"0.0220\",\"ThdPhV_phsA\":\"0.0913\",\"HRPhV_H9_phsB\":\"0.0220\",\"HRPhV_H9_phsA\":\"0.0220\",\"ThdPhV_phsB\":\"0.0913\",\"ThdPhV_phsC\":\"0.0913\",\"HRPhV_H19_phsC\":\"0.0100\",\"HRPhV_H19_phsB\":\"0.0100\",\"HRPhV_H19_phsA\":\"0.0100\",\"HRPhV_H16_phsA\":\"0.0000\",\"HRPhV_H13_phsA\":\"0.0140\",\"HRPhV_H16_phsC\":\"0.0000\",\"HRPhV_H13_phsB\":\"0.0140\",\"HRPhV_H16_phsB\":\"0.0000\",\"TotVA\":\"39977.2305\",\"HRPhV_H13_phsC\":\"0.0140\",\"HRPhV_H6_phsB\":\"0.0026\",\"HRPhV_H3_phsA\":\"0.0640\",\"HRPhV_H6_phsA\":\"0.0026\",\"HRPhV_H10_phsA\":\"0.0026\",\"HRPhV_H10_phsB\":\"0.0026\",\"HRPhV_H6_phsC\":\"0.0026\",\"HRPhV_H10_phsC\":\"0.0026\",\"ImbNgV\":\"0.0012\",\"TotVar\":\"34745.9492\",\"HRPhV_H7_phsC\":\"0.0280\",\"HRPhV_H7_phsB\":\"0.0280\",\"HRPhV_H22_phsC\":\"0.0000\",\"HRPhV_H22_phsB\":\"0.0000\",\"ImbZroV\":\"0.0012\",\"HRPhV_H22_phsA\":\"0.0000\",\"HRPhV_H7_phsA\":\"0.0280\",\"HRPhV_H8_phsA\":\"0.0026\",\"HRPhV_H23_phsB\":\"0.0080\",\"PhV_phsA\":\"221.9935\",\"HRPhV_H8_phsB\":\"0.0026\",\"HRPhV_H23_phsC\":\"0.0080\",\"HRPhV_H8_phsC\":\"0.0026\",\"PhV_phsB\":\"221.9947\",\"PhV_phsC\":\"221.9979\",\"HRPhV_H23_phsA\":\"0.0080\",\"PstPhV_phsC\":\"3.2942\",\"PstPhV_phsA\":\"3.3086\",\"PstPhV_phsB\":\"3.2987\",\"Freq\":\"50.0000\",\"HRPhV_H11_phsA\":\"0.0180\",\"HRPhV_H11_phsB\":\"0.0180\",\"HRPhV_H17_phsC\":\"0.0100\",\"HRPhV_H11_phsC\":\"0.0180\",\"HRPhV_H17_phsB\":\"0.0100\",\"HRPhV_H17_phsA\":\"0.0100\",\"SeqV_C2\":\"0.0715\",\"HRPhV_H4_phsB\":\"0.0050\",\"SeqV_C1\":\"60.4601\",\"HRPhV_H4_phsA\":\"0.0050\",\"SeqV_C0\":\"0.0714\",\"PhVDev_phsC\":\"0.0119\",\"HRPhV_H5_phsA\":\"0.0400\",\"HRPhV_H5_phsB\":\"0.0400\",\"HRPhV_H5_phsC\":\"0.0400\",\"PhVDev_phsB\":\"0.0119\",\"HRPhV_H12_phsC\":\"0.0010\",\"PltPhV_phsA\":\"0.0000\",\"PhVDev_phsA\":\"0.0119\",\"HRPhV_H12_phsB\":\"0.0010\",\"HRPhV_H4_phsC\":\"0.0050\",\"HRPhV_H18_phsB\":\"0.0000\",\"HRPhV_H18_phsC\":\"0.0000\",\"HRPhV_H12_phsA\":\"0.0010\",\"HRPhV_H18_phsA\":\"0.0000\",\"HFundPhV_phsC\":\"220.8052\",\"HRPhV_H21_phsC\":\"0.0080\",\"HRPhV_H21_phsB\":\"0.0080\",\"HRPhV_H24_phsC\":\"0.0000\",\"HFundPhV_phsA\":\"220.8056\",\"HRPhV_H21_phsA\":\"0.0080\",\"HFundPhV_phsB\":\"220.8055\",\"HRPhV_H24_phsB\":\"0.0000\",\"PltPhV_phsC\":\"0.0000\",\"HRPhV_H24_phsA\":\"0.0000\",\"PltPhV_phsB\":\"0.0000\",\"time\":\"20240816T150000Z\"}"; public String devId = "暂无数据"; - private final PmsHistoryDataMapper pmsHistoryDataMapper; private final EleEpdPqdMapper eleEpdPqdMapper; - private final IDataVService iDataVService; + private final DataVMapper dataVMapper; + + private final DataHarmRateVMapper dataHarmRateVMapper; + + private final DataHarmPowerPMapper dataHarmPowerPMapper; + + private final MonitorRealDataService monitorRealDataService; + + private final String idKey = "pmswifi_"; @GetMapping("send") @@ -131,7 +139,6 @@ public class TestController { @GetMapping("list") - @DS("sqlite") public List list(@RequestParam("startTime") String startTime, @RequestParam("endTime") String endTime, @RequestParam("devId") String devId) { String sql = "select content from pms_history_data where dev_id ='" + devId + "' and time between '" + startTime + "' and '" + endTime + "'"; List list = new ArrayList<>(); //= this.jdbcTemplate.queryForList(sql, String.class); @@ -141,7 +148,6 @@ public class TestController { } - @DS("sqlite") @GetMapping("simulationWebSocket") public String simulationWebSocket() { devId = "NJCN230497"; @@ -205,15 +211,7 @@ public class TestController { map.put("time", ten); webSocketServer.sendSocketMessageToAll(map.toJSONString()); - //入库influxdb - List poList = new ArrayList<>(); - iDataVService.insertBatch(poList); - DataV dataV = new DataV(); - Class clazz = dataV.getClass(); - Field timeInflux = clazz.getDeclaredField("time"); - timeInflux.setAccessible(true); - timeInflux.set(dataV, dateTime.toInstant()); /* try { PmsHistoryDataPO pmsHistoryDataPO = new PmsHistoryDataPO(); @@ -245,92 +243,120 @@ public class TestController { @GetMapping("simulationInfluxdb") @DS("master") public String simulationInfluxdb() { + System.out.println("进入模拟数据生成接口++++++++++++++++++++++++++++++++++++++++"); List eleEpdPqdList = eleEpdPqdMapper.selectList(new LambdaQueryWrapper().eq(EleEpdPqd::getSystemType, "pms")); - Map> elePhaseMap = eleEpdPqdList.stream().collect(Collectors.groupingBy(EleEpdPqd::getPhase)); + Map> classMap = eleEpdPqdList.stream().collect(Collectors.groupingBy(EleEpdPqd::getClassId)); + //Map eleEpdPqdMap = eleEpdPqdList.stream().collect(Collectors.toMap(EleEpdPqd::getName, Function.identity())); devId = "NJCN230497"; - List poList = new ArrayList<>(); - - cn.hutool.json.JSONObject jsonObject = JsonValueFluctuator.fluctuateValuesInJson(topicMsg); + for (int j = 0; j < 6; j++) { + List poList = new ArrayList<>(); + List dataHarmRateVList = new ArrayList<>(); + List dataHarmPowerPList = new ArrayList<>(); - jsonObject.put("customDevId", devId); - elePhaseMap.forEach((phase,list)->{ + Instant instant = LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant(); + for (int i = 0; i < 4; i++) { - Map m = list.stream().collect(Collectors.toMap(EleEpdPqd::getName,Function.identity())); - Map map = new HashMap<>(); - m.forEach((mk,mv)->{ - if(jsonObject.containsKey(mk)){ - if(StrUtil.isNotBlank(mv.getOtherName())) { - map.put(mv.getOtherName(), Double.valueOf(jsonObject.get(mk).toString())); - } + JSONObject jsonObject = JsonValueFluctuator.fluctuateValuesInJson(topicMsg); + jsonObject.put("customDevId", devId); + + if (i == 0) { + jsonObject.put("DataType", "MAX"); + } else if (i == 1) { + jsonObject.put("DataType", "MIN"); + } else if (i == 2) { + jsonObject.put("DataType", "AVG"); + } else if (i == 3) { + jsonObject.put("DataType", "CP95"); } - }); + + String lineId = idKey + jsonObject.get("customDevId").toString(); + MonitorRealData monitorRealData = new MonitorRealData(); + monitorRealData.setLineId(lineId); + monitorRealData.setId(IdUtil.simpleUUID()); + ZoneId zoneId = ZoneId.systemDefault(); + LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime(); + + monitorRealData.setTimeId(localDateTime); + monitorRealData.setValueType(jsonObject.get("DataType").toString()); + monitorRealData.setPmsContent(jsonObject.toJSONString()); + monitorRealDataService.saveOrUpdateByMultiId(monitorRealData); - DataV dataV = new DataV(); - BeanUtil.copyProperties(map,dataV); + classMap.forEach((classId, classList) -> { + Map> elePhaseMap = classList.stream().collect(Collectors.groupingBy(EleEpdPqd::getPhase)); + elePhaseMap.forEach((phase, list) -> { + Map m = list.stream().collect(Collectors.toMap(EleEpdPqd::getName, Function.identity())); + Map map = new HashMap<>(); + m.forEach((mk, mv) -> { + if (jsonObject.containsKey(mk)) { + if (StrUtil.isNotBlank(mv.getOtherName())) { + map.put(mv.getOtherName(), Double.valueOf(jsonObject.get(mk).toString())); + } + } + }); - dataV.setPhaseType(phase); - dataV.setLineId(jsonObject.get("customDevId").toString()); - dataV.setValueType("CP95"); - dataV.setQualityFlag("0"); - Class clazz = dataV.getClass(); - Field timeInflux = null; + if (classId.equals("data_v")) { + DataV dataV = new DataV(); + BeanUtil.copyProperties(map, dataV); + dataV.setPhaseType(phase); + dataV.setLineId(lineId); + dataV.setValueType(jsonObject.get("DataType").toString()); + dataV.setQualityFlag("0"); + dataV.setTime(instant); + + JsonValueFluctuator.setNullNumberFieldsToZero(dataV); + poList.add(dataV); + } else if (classId.equals("data_harmrate_v")) { + DataHarmRateV dataHarmRateV = new DataHarmRateV(); + BeanUtil.copyProperties(map, dataHarmRateV); + dataHarmRateV.setPhaseType(phase); + dataHarmRateV.setLineId(lineId); + dataHarmRateV.setValueType(jsonObject.get("DataType").toString()); + dataHarmRateV.setQualityFlag("0"); + dataHarmRateV.setTime(instant); + + JsonValueFluctuator.setNullNumberFieldsToZero(dataHarmRateV); + dataHarmRateVList.add(dataHarmRateV); + } else if (classId.equals("data_harmpower_p")) { + DataHarmPowerP dataHarmPowerP = new DataHarmPowerP(); + BeanUtil.copyProperties(map, dataHarmPowerP); + dataHarmPowerP.setPhaseType(phase); + dataHarmPowerP.setLineId(lineId); + dataHarmPowerP.setValueType(jsonObject.get("DataType").toString()); + dataHarmPowerP.setQualityFlag("0"); + dataHarmPowerP.setTime(instant); + + JsonValueFluctuator.setNullNumberFieldsToZero(dataHarmPowerP); + dataHarmPowerPList.add(dataHarmPowerP); + } + + + }); + + + }); + } try { - timeInflux = clazz.getDeclaredField("time"); - timeInflux.setAccessible(true); - timeInflux.set(dataV, jsonObject.get("time")); - - - } catch (NoSuchFieldException e) { - throw new RuntimeException(e); - } catch (IllegalAccessException e) { + dataVMapper.insertBatch(poList); + dataHarmRateVMapper.insertBatch(dataHarmRateVList); + dataHarmPowerPMapper.insertBatch(dataHarmPowerPList); + System.out.println(instant.toString() + ">>>>>>>>>>>模拟数据至influxdb成功"); + } catch (Exception e) { + e.printStackTrace(); + } + try { + Thread.sleep(60000); + //Thread.sleep(180000); + } catch (InterruptedException e) { throw new RuntimeException(e); } - - JsonValueFluctuator.setNullNumberFieldsToZero(dataV); - poList.add(dataV); - - }); - //for (int i = 0; i < 30; i++) { - //for (int j = 0; j < 4; j++) { - - - try { - //入库influxdb - - - - iDataVService.insertBatch(poList); - /* try { - PmsHistoryDataPO pmsHistoryDataPO = new PmsHistoryDataPO(); - pmsHistoryDataPO.setTime(ten); - pmsHistoryDataPO.setDevId(devId); - pmsHistoryDataPO.setContent(map.toJSONString()); - pmsHistoryDataMapper.insert(pmsHistoryDataPO); - //int ret = jdbcTemplate.update(); - }catch (Exception e){ - System.out.println("执行sql语句错误"+e.getMessage()); - }*/ - - } catch (Exception e) { - e.printStackTrace(); - } - - try { - Thread.sleep(1000); - //Thread.sleep(180000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - //} - // } - - return "推送成功"; + } + return "模拟成功"; } diff --git a/src/main/java/com/njcn/roma/mapper/MonitorRealDataMapper.java b/src/main/java/com/njcn/roma/mapper/MonitorRealDataMapper.java new file mode 100644 index 0000000..80dccf5 --- /dev/null +++ b/src/main/java/com/njcn/roma/mapper/MonitorRealDataMapper.java @@ -0,0 +1,14 @@ +package com.njcn.roma.mapper; + +import com.github.jeffreyning.mybatisplus.base.MppBaseMapper; +import com.njcn.roma.pojo.MonitorRealData; +import org.apache.ibatis.annotations.Mapper; + +/** + * roma + * + * @author cdf + * @date 2024/8/25 + */ +public interface MonitorRealDataMapper extends MppBaseMapper { +} diff --git a/src/main/java/com/njcn/roma/mapper/PmsHistoryDataMapper.java b/src/main/java/com/njcn/roma/mapper/PmsHistoryDataMapper.java index 8963533..d86c9fa 100644 --- a/src/main/java/com/njcn/roma/mapper/PmsHistoryDataMapper.java +++ b/src/main/java/com/njcn/roma/mapper/PmsHistoryDataMapper.java @@ -1,7 +1,7 @@ -package com.njcn.roma.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.njcn.roma.pojo.PmsHistoryDataPO; - -public interface PmsHistoryDataMapper extends BaseMapper { -} +//package com.njcn.roma.mapper; +// +//import com.baomidou.mybatisplus.core.mapper.BaseMapper; +//import com.njcn.roma.pojo.PmsHistoryDataPO; +// +//public interface PmsHistoryDataMapper extends BaseMapper { +//} diff --git a/src/main/java/com/njcn/roma/pojo/MonitorRealData.java b/src/main/java/com/njcn/roma/pojo/MonitorRealData.java new file mode 100644 index 0000000..4325afa --- /dev/null +++ b/src/main/java/com/njcn/roma/pojo/MonitorRealData.java @@ -0,0 +1,47 @@ +package com.njcn.roma.pojo; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.github.jeffreyning.mybatisplus.anno.MppMultiId; + + +import java.time.LocalDateTime; +import lombok.Getter; +import lombok.Setter; + +/** + *

+ * + *

+ * + * @author xy + * @since 2024-08-25 + */ +@Getter +@Setter +@TableName("pms_real_data") +public class MonitorRealData { + + private static final long serialVersionUID = 1L; + + @TableField("id") + private String id; + + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") + @TableField("time_Id") + private LocalDateTime timeId; + + @MppMultiId + @TableField("line_id") + private String lineId; + + @MppMultiId + @TableField("value_type") + private String valueType; + + @TableField("pms_content") + private String pmsContent; + + +} diff --git a/src/main/java/com/njcn/roma/pojo/PmsHistoryDataPO.java b/src/main/java/com/njcn/roma/pojo/PmsHistoryDataPO.java index 87a1662..a46b93b 100644 --- a/src/main/java/com/njcn/roma/pojo/PmsHistoryDataPO.java +++ b/src/main/java/com/njcn/roma/pojo/PmsHistoryDataPO.java @@ -1,24 +1,24 @@ -package com.njcn.roma.pojo; - - -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; - -@Data -@TableName("pms_history_data") -public class PmsHistoryDataPO implements Serializable { - private static final long serialVersionUID = 1L; - - @TableField(value = "time") - private String time; - - @TableField(value = "dev_id") - private String devId; - - @TableField(value = "content") - private String content; -} +//package com.njcn.roma.pojo; +// +// +//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; +// +//@Data +//@TableName("pms_history_data") +//public class PmsHistoryDataPO implements Serializable { +// private static final long serialVersionUID = 1L; +// +// @TableField(value = "time") +// private String time; +// +// @TableField(value = "dev_id") +// private String devId; +// +// @TableField(value = "content") +// private String content; +//} diff --git a/src/main/java/com/njcn/roma/service/MonitorRealDataService.java b/src/main/java/com/njcn/roma/service/MonitorRealDataService.java new file mode 100644 index 0000000..1fa6050 --- /dev/null +++ b/src/main/java/com/njcn/roma/service/MonitorRealDataService.java @@ -0,0 +1,13 @@ +package com.njcn.roma.service; + +import com.github.jeffreyning.mybatisplus.service.IMppService; +import com.njcn.roma.pojo.MonitorRealData; + +/** + * roma + * + * @author cdf + * @date 2024/8/25 + */ +public interface MonitorRealDataService extends IMppService { +} diff --git a/src/main/java/com/njcn/roma/service/impl/MonitorRealDataServiceImpl.java b/src/main/java/com/njcn/roma/service/impl/MonitorRealDataServiceImpl.java new file mode 100644 index 0000000..4aa70b3 --- /dev/null +++ b/src/main/java/com/njcn/roma/service/impl/MonitorRealDataServiceImpl.java @@ -0,0 +1,19 @@ +package com.njcn.roma.service.impl; + +import com.github.jeffreyning.mybatisplus.service.MppServiceImpl; +import com.njcn.roma.mapper.MonitorRealDataMapper; +import com.njcn.roma.pojo.MonitorRealData; +import com.njcn.roma.service.MonitorRealDataService; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * roma + * + * @author cdf + * @date 2024/8/25 + */ +@Service +@RequiredArgsConstructor +public class MonitorRealDataServiceImpl extends MppServiceImpl implements MonitorRealDataService { +} diff --git a/src/main/java/com/njcn/roma/utils/JsonValueFluctuator.java b/src/main/java/com/njcn/roma/utils/JsonValueFluctuator.java index d93d050..8e9e556 100644 --- a/src/main/java/com/njcn/roma/utils/JsonValueFluctuator.java +++ b/src/main/java/com/njcn/roma/utils/JsonValueFluctuator.java @@ -1,6 +1,7 @@ package com.njcn.roma.utils; -import cn.hutool.json.JSONObject; + +import com.alibaba.fastjson.JSONObject; import java.lang.reflect.Field; import java.time.Instant; @@ -21,8 +22,39 @@ public class JsonValueFluctuator { * @return 修改后的JSON字符串 */ public static JSONObject fluctuateValuesInJson(String jsonString) { - JSONObject jsonObject = new JSONObject(jsonString); + JSONObject jsonObject = JSONObject.parseObject(jsonString); + // 遍历JSONObject的键值对 + jsonObject.keySet().forEach(key -> { + Object value = jsonObject.get(key); + if(key.equals("time")){ + //ZonedDateTime dateTime = ZonedDateTime.parse(value.toString(), formatter); + // dateTime = dateTime.minusHours(8); + //Instant instant = dateTime.toInstant(); + Instant instant = Instant.now(); + jsonObject.put(key,instant); + }else { + if(!key.equals("DataTag") && !key.equals("DataType")){ + // 假设只有Double类型(或可以转换为Double的)值需要变动 + double numberValue = Double.parseDouble(value.toString()); + double fluctuatedValue = fluctuateValue(numberValue); + jsonObject.put(key, fluctuatedValue); + } + } + + }); + + return jsonObject; + } + + + /** + * 真实环境使用 + * @author cdf + * @date 2024/8/21 + */ + public static JSONObject realToData(String jsonString) { + JSONObject jsonObject = JSONObject.parseObject(jsonString); // 遍历JSONObject的键值对 jsonObject.keySet().forEach(key -> { Object value = jsonObject.get(key); @@ -32,11 +64,10 @@ public class JsonValueFluctuator { Instant instant = dateTime.toInstant(); jsonObject.put(key,instant); }else { - // 假设只有Double类型(或可以转换为Double的)值需要变动 - if (value instanceof Number) { - double numberValue = ((Number) value).doubleValue(); - double fluctuatedValue = fluctuateValue(numberValue); - jsonObject.put(key, fluctuatedValue); + if(!key.equals("DataTag") && !key.equals("DataType")) { + // 假设只有Double类型(或可以转换为Double的)值需要变动 + double numberValue = Double.parseDouble(value.toString()); + jsonObject.put(key, numberValue); } } @@ -65,7 +96,9 @@ public class JsonValueFluctuator { try { // 检查字段是否为数字类型的包装类 if(Integer.class.isAssignableFrom(field.getType())){ - field.set(obj, 0); + if (field.get(obj) == null) { + field.set(obj, 0); + } } else if (Number.class.isAssignableFrom(field.getType())) { // 对于包装类型,我们可以安全地调用get和set // 如果字段为null,则设置为0 diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 8bdfccb..143a3d5 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -74,10 +74,14 @@ spring: username: root password: njcnpqs driver-class-name: com.mysql.cj.jdbc.Driver - sqlite: - url: "jdbc:sqlite:D:\\pmsTest.db" - driver-class-name: org.sqlite.JDBC - type: com.alibaba.druid.pool.DruidDataSource + #url: jdbc:mysql://25.36.232.37:13306/pmsinfo?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=CTT + #username: root + #password: Huawei12# + #driver-class-name: com.mysql.cj.jdbc.Driver + #sqlite: + # url: "jdbc:sqlite:D:\\pmsTest.db" + # driver-class-name: org.sqlite.JDBC + # type: com.alibaba.druid.pool.DruidDataSource #influxDB内容配置 @@ -87,6 +91,13 @@ spring: password: 123456 database: pqsinfo_pms + #influx: + #url: http://25.36.232.36:8086 + #user: admin + #password: admin + #database: pqsbase_hbcs + #mapper-location: com.njcn.influx.imapper + roma: acceptIp: 25.36.190.3:19776 @@ -100,4 +111,9 @@ mybatis-plus: #别名扫描 type-aliases-package: com.njcn.roma.pojo global-config: - enable-sql-runner: true \ No newline at end of file + enable-sql-runner: true + configuration: + #驼峰命名 + map-underscore-to-camel-case: true + #配置sql日志输出 + log-impl: org.apache.ibatis.logging.stdout.StdOutImpl diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index c8fa858..22de09d 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -510,6 +510,8 @@ table { width: 100%; border-collapse: collapse; + overflow-y: auto; /* 启用竖向滚动 */ + } table caption { @@ -604,62 +606,3 @@ -