提交代码
parent
8f665d4ff4
commit
09351213fb
|
@ -85,9 +85,9 @@ public class GainHzDataTask {
|
||||||
|
|
||||||
IotDeviceInfo iotDeviceInfo = new IotDeviceInfo();
|
IotDeviceInfo iotDeviceInfo = new IotDeviceInfo();
|
||||||
iotDeviceInfo.setDeviceName("配电箱");
|
iotDeviceInfo.setDeviceName("配电箱");
|
||||||
|
iotDeviceInfo.setFactoryName("华筑");
|
||||||
List<IotDeviceInfo> iotDeviceInfos = iIotDeviceInfoService.selectIotDeviceInfoList(iotDeviceInfo);
|
List<IotDeviceInfo> iotDeviceInfos = iIotDeviceInfoService.selectIotDeviceInfoList(iotDeviceInfo);
|
||||||
iotDeviceInfos.forEach(item -> {
|
iotDeviceInfos.forEach(item -> {
|
||||||
if(Objects.equals("华筑",item.getFactoryName())){
|
|
||||||
if(item.getHzTenantId() != null && item.getHzProjectId() != null) {
|
if(item.getHzTenantId() != null && item.getHzProjectId() != null) {
|
||||||
JSONObject body = new JSONObject();
|
JSONObject body = new JSONObject();
|
||||||
body.put("tenantId", item.getHzTenantId());
|
body.put("tenantId", item.getHzTenantId());
|
||||||
|
@ -162,109 +162,6 @@ public class GainHzDataTask {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (iotPowers.size() > 0) {
|
|
||||||
iotPowerService.batchInsertPower(iotPowers);
|
|
||||||
}
|
|
||||||
if (iotWarningInfos.size() > 0) {
|
|
||||||
iotWarningInfoService.batchInsertWarning(iotWarningInfos);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else if(Objects.equals("华筑",item.getFactoryName())){
|
|
||||||
String res_str = HttpRequest.get(HzApiConf.SD_IOT_POWER_HOST + "/metric/box/"+item.getDeviceId())
|
|
||||||
.execute().body();
|
|
||||||
JSONObject res = JSONObject.parseObject(res_str).getJSONObject("result");
|
|
||||||
// 电能检测数据
|
|
||||||
JSONObject metric = res.getJSONObject("metric");
|
|
||||||
// 温度检测数据
|
|
||||||
JSONArray temperatures = res.getJSONArray("temperatures");
|
|
||||||
// 漏电检测数据
|
|
||||||
JSONArray leakages = res.getJSONArray("leakages");
|
|
||||||
// 报警数据
|
|
||||||
JSONObject ticketStatus = res.getJSONObject("ticketStatus");
|
|
||||||
List<IotPower> iotPowers = new ArrayList<>(16);
|
|
||||||
List<IotWarningInfo> iotWarningInfos = new ArrayList<>(16);
|
|
||||||
IotPower iotPower = new IotPower();
|
|
||||||
iotPower.setUid(item.getDeviceId());
|
|
||||||
iotPower.setTime(DateUtils.getNowDate());
|
|
||||||
BigDecimal power = metric.getBigDecimal("power_a").add(metric.getBigDecimal("power_b")).add(metric.getBigDecimal("power_c"));
|
|
||||||
iotPower.setPower(power.divide(new BigDecimal(3), 2, BigDecimal.ROUND_HALF_UP));
|
|
||||||
int leak = 0;
|
|
||||||
for (int i = 0; i < leakages.size(); i++) {
|
|
||||||
JSONObject leakage = leakages.getJSONObject(i);
|
|
||||||
if(Convert.toInt(leakage.get("leakage"),0)>leak){
|
|
||||||
leak = leakage.getInteger("leakage");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
iotPower.setLeak(BigDecimal.valueOf(leak));
|
|
||||||
iotPower.setC1(BigDecimal.valueOf(metric.getFloat("current_a")));
|
|
||||||
iotPower.setC2(BigDecimal.valueOf(metric.getFloat("current_b")));
|
|
||||||
iotPower.setC3(BigDecimal.valueOf(metric.getFloat("current_c")));
|
|
||||||
iotPower.setV1(BigDecimal.valueOf(metric.getFloat("voltage_a")));
|
|
||||||
iotPower.setV2(BigDecimal.valueOf(metric.getFloat("voltage_b")));
|
|
||||||
iotPower.setV3(BigDecimal.valueOf(metric.getFloat("voltage_c")));
|
|
||||||
BigDecimal data = temperatures.getJSONObject(0).getBigDecimal("temperature");
|
|
||||||
iotPower.setT1(data);
|
|
||||||
iotPower.setT2(data);
|
|
||||||
iotPower.setT3(data);
|
|
||||||
iotPower.setT4(data);
|
|
||||||
|
|
||||||
// 预警数据
|
|
||||||
if (t % 2 == 0 && !warrning_power_sd[t]) {
|
|
||||||
warrning_power_sd = new Boolean[]{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
|
|
||||||
warrning_power_sd[t] = true;
|
|
||||||
|
|
||||||
if(ticketStatus.getInteger("is_blackout")>0){
|
|
||||||
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
|
||||||
iotWarningInfo.setDeviceId(iotPower.getUid());
|
|
||||||
iotWarningInfo.setType("断电预警");
|
|
||||||
iotWarningInfo.setContent("设备触发断电,请排查异常情况");
|
|
||||||
iotWarningInfo.setCreateTime(new Date());
|
|
||||||
iotWarningInfos.add(iotWarningInfo);
|
|
||||||
}
|
|
||||||
if(ticketStatus.getInteger("is_smoke")>0){
|
|
||||||
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
|
||||||
iotWarningInfo.setDeviceId(iotPower.getUid());
|
|
||||||
iotWarningInfo.setType("烟感报警");
|
|
||||||
iotWarningInfo.setContent("设备烟感报警,请排查异常情况");
|
|
||||||
iotWarningInfo.setCreateTime(new Date());
|
|
||||||
iotWarningInfos.add(iotWarningInfo);
|
|
||||||
}
|
|
||||||
if(ticketStatus.getInteger("is_overload")>0){
|
|
||||||
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
|
||||||
iotWarningInfo.setDeviceId(iotPower.getUid());
|
|
||||||
iotWarningInfo.setType("过载报警");
|
|
||||||
iotWarningInfo.setContent("设备过载报警,请排查异常情况");
|
|
||||||
iotWarningInfo.setCreateTime(new Date());
|
|
||||||
iotWarningInfos.add(iotWarningInfo);
|
|
||||||
}
|
|
||||||
if(ticketStatus.getInteger("is_disconnect")>0){
|
|
||||||
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
|
||||||
iotWarningInfo.setDeviceId(iotPower.getUid());
|
|
||||||
iotWarningInfo.setType("断开报警");
|
|
||||||
iotWarningInfo.setContent("设备断开报警,请排查异常情况");
|
|
||||||
iotWarningInfo.setCreateTime(new Date());
|
|
||||||
iotWarningInfos.add(iotWarningInfo);
|
|
||||||
}
|
|
||||||
if(ticketStatus.getInteger("is_overheat")>0){
|
|
||||||
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
|
||||||
iotWarningInfo.setDeviceId(iotPower.getUid());
|
|
||||||
iotWarningInfo.setType(" 高温报警");
|
|
||||||
iotWarningInfo.setContent("设备高温报警,请排查异常情况");
|
|
||||||
iotWarningInfo.setCreateTime(new Date());
|
|
||||||
iotWarningInfos.add(iotWarningInfo);
|
|
||||||
}
|
|
||||||
if(ticketStatus.getInteger("is_leakage")>0){
|
|
||||||
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
|
||||||
iotWarningInfo.setDeviceId(iotPower.getUid());
|
|
||||||
iotWarningInfo.setType(" 漏电报警");
|
|
||||||
iotWarningInfo.setContent("设备漏电报警,请排查异常情况");
|
|
||||||
iotWarningInfo.setCreateTime(new Date());
|
|
||||||
iotWarningInfos.add(iotWarningInfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
iotPowers.add(iotPower);
|
|
||||||
|
|
||||||
if (iotPowers.size() > 0) {
|
if (iotPowers.size() > 0) {
|
||||||
iotPowerService.batchInsertPower(iotPowers);
|
iotPowerService.batchInsertPower(iotPowers);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,168 @@
|
||||||
|
package com.ruoyi.iot.task;
|
||||||
|
|
||||||
|
import cn.hutool.http.HttpRequest;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.ruoyi.common.core.text.Convert;
|
||||||
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
|
import com.ruoyi.iot.conf.HzApiConf;
|
||||||
|
import com.ruoyi.iot.domain.IotDeviceInfo;
|
||||||
|
import com.ruoyi.iot.domain.IotPower;
|
||||||
|
import com.ruoyi.iot.domain.IotWarningInfo;
|
||||||
|
import com.ruoyi.iot.service.IIotDeviceInfoService;
|
||||||
|
import com.ruoyi.iot.service.IIotPowerService;
|
||||||
|
import com.ruoyi.iot.service.IIotWarningInfoService;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Description: 萨达配电箱数据定时任务
|
||||||
|
* @Title: SadaHzDataTask
|
||||||
|
* @Package com.yanzhu.xd.system.task
|
||||||
|
* @Author: JiangYuQi
|
||||||
|
* @Copyright 版权归"陕西马卡鲁信息技术有限公司(或个⼈)"所有
|
||||||
|
* @CreateTime: 2024/10/26 17:05
|
||||||
|
*/
|
||||||
|
@Component("sadaHzDataTask")
|
||||||
|
public class SadaHzDataTask {
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(SadaHzDataTask.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IIotPowerService iotPowerService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IIotWarningInfoService iotWarningInfoService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IIotDeviceInfoService iIotDeviceInfoService;
|
||||||
|
|
||||||
|
public static Boolean[] warrning_power_sd = new Boolean[]{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPowerData() {
|
||||||
|
//获取当前时间是否需要预警两小时预警一次0,2,4,6,8,10,12,14,16,18,20,22
|
||||||
|
Integer t = Integer.valueOf(new SimpleDateFormat("HH").format(new Date()));
|
||||||
|
|
||||||
|
//1.通过接口获取数据
|
||||||
|
Long endTime = System.currentTimeMillis();
|
||||||
|
Long startTime = endTime - HzApiConf.INTERVAL_TIME;
|
||||||
|
|
||||||
|
IotDeviceInfo iotDeviceInfo = new IotDeviceInfo();
|
||||||
|
iotDeviceInfo.setDeviceName("配电箱");
|
||||||
|
iotDeviceInfo.setFactoryName("萨达");
|
||||||
|
List<IotDeviceInfo> iotDeviceInfos = iIotDeviceInfoService.selectIotDeviceInfoList(iotDeviceInfo);
|
||||||
|
iotDeviceInfos.forEach(item -> {
|
||||||
|
String res_str = HttpRequest.get(HzApiConf.SD_IOT_POWER_HOST + "/metric/box/"+item.getDeviceId())
|
||||||
|
.execute().body();
|
||||||
|
JSONObject res = JSONObject.parseObject(res_str).getJSONObject("result");
|
||||||
|
// 电能检测数据
|
||||||
|
JSONObject metric = res.getJSONObject("metric");
|
||||||
|
// 温度检测数据
|
||||||
|
JSONArray temperatures = res.getJSONArray("temperatures");
|
||||||
|
// 漏电检测数据
|
||||||
|
JSONArray leakages = res.getJSONArray("leakages");
|
||||||
|
// 报警数据
|
||||||
|
JSONObject ticketStatus = res.getJSONObject("ticketStatus");
|
||||||
|
List<IotPower> iotPowers = new ArrayList<>(16);
|
||||||
|
List<IotWarningInfo> iotWarningInfos = new ArrayList<>(16);
|
||||||
|
IotPower iotPower = new IotPower();
|
||||||
|
iotPower.setUid(item.getDeviceId());
|
||||||
|
iotPower.setTime(DateUtils.getNowDate());
|
||||||
|
BigDecimal power = metric.getBigDecimal("power_a").add(metric.getBigDecimal("power_b")).add(metric.getBigDecimal("power_c"));
|
||||||
|
iotPower.setPower(power.divide(new BigDecimal(3), 2, BigDecimal.ROUND_HALF_UP));
|
||||||
|
int leak = 0;
|
||||||
|
for (int i = 0; i < leakages.size(); i++) {
|
||||||
|
JSONObject leakage = leakages.getJSONObject(i);
|
||||||
|
if(Convert.toInt(leakage.get("leakage"),0)>leak){
|
||||||
|
leak = leakage.getInteger("leakage");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iotPower.setLeak(BigDecimal.valueOf(leak));
|
||||||
|
iotPower.setC1(BigDecimal.valueOf(metric.getFloat("current_a")));
|
||||||
|
iotPower.setC2(BigDecimal.valueOf(metric.getFloat("current_b")));
|
||||||
|
iotPower.setC3(BigDecimal.valueOf(metric.getFloat("current_c")));
|
||||||
|
iotPower.setV1(BigDecimal.valueOf(metric.getFloat("voltage_a")));
|
||||||
|
iotPower.setV2(BigDecimal.valueOf(metric.getFloat("voltage_b")));
|
||||||
|
iotPower.setV3(BigDecimal.valueOf(metric.getFloat("voltage_c")));
|
||||||
|
BigDecimal data = temperatures.getJSONObject(0).getBigDecimal("temperature");
|
||||||
|
iotPower.setT1(data);
|
||||||
|
iotPower.setT2(data);
|
||||||
|
iotPower.setT3(data);
|
||||||
|
iotPower.setT4(data);
|
||||||
|
|
||||||
|
// 预警数据
|
||||||
|
if (t % 2 == 0 && !warrning_power_sd[t]) {
|
||||||
|
warrning_power_sd = new Boolean[]{false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false};
|
||||||
|
warrning_power_sd[t] = true;
|
||||||
|
|
||||||
|
if(ticketStatus.getInteger("is_blackout")>0){
|
||||||
|
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
||||||
|
iotWarningInfo.setDeviceId(iotPower.getUid());
|
||||||
|
iotWarningInfo.setType("断电预警");
|
||||||
|
iotWarningInfo.setContent("设备触发断电,请排查异常情况");
|
||||||
|
iotWarningInfo.setCreateTime(new Date());
|
||||||
|
iotWarningInfos.add(iotWarningInfo);
|
||||||
|
}
|
||||||
|
if(ticketStatus.getInteger("is_smoke")>0){
|
||||||
|
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
||||||
|
iotWarningInfo.setDeviceId(iotPower.getUid());
|
||||||
|
iotWarningInfo.setType("烟感报警");
|
||||||
|
iotWarningInfo.setContent("设备烟感报警,请排查异常情况");
|
||||||
|
iotWarningInfo.setCreateTime(new Date());
|
||||||
|
iotWarningInfos.add(iotWarningInfo);
|
||||||
|
}
|
||||||
|
if(ticketStatus.getInteger("is_overload")>0){
|
||||||
|
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
||||||
|
iotWarningInfo.setDeviceId(iotPower.getUid());
|
||||||
|
iotWarningInfo.setType("过载报警");
|
||||||
|
iotWarningInfo.setContent("设备过载报警,请排查异常情况");
|
||||||
|
iotWarningInfo.setCreateTime(new Date());
|
||||||
|
iotWarningInfos.add(iotWarningInfo);
|
||||||
|
}
|
||||||
|
if(ticketStatus.getInteger("is_disconnect")>0){
|
||||||
|
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
||||||
|
iotWarningInfo.setDeviceId(iotPower.getUid());
|
||||||
|
iotWarningInfo.setType("断开报警");
|
||||||
|
iotWarningInfo.setContent("设备断开报警,请排查异常情况");
|
||||||
|
iotWarningInfo.setCreateTime(new Date());
|
||||||
|
iotWarningInfos.add(iotWarningInfo);
|
||||||
|
}
|
||||||
|
if(ticketStatus.getInteger("is_overheat")>0){
|
||||||
|
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
||||||
|
iotWarningInfo.setDeviceId(iotPower.getUid());
|
||||||
|
iotWarningInfo.setType(" 高温报警");
|
||||||
|
iotWarningInfo.setContent("设备高温报警,请排查异常情况");
|
||||||
|
iotWarningInfo.setCreateTime(new Date());
|
||||||
|
iotWarningInfos.add(iotWarningInfo);
|
||||||
|
}
|
||||||
|
if(ticketStatus.getInteger("is_leakage")>0){
|
||||||
|
IotWarningInfo iotWarningInfo = new IotWarningInfo();
|
||||||
|
iotWarningInfo.setDeviceId(iotPower.getUid());
|
||||||
|
iotWarningInfo.setType(" 漏电报警");
|
||||||
|
iotWarningInfo.setContent("设备漏电报警,请排查异常情况");
|
||||||
|
iotWarningInfo.setCreateTime(new Date());
|
||||||
|
iotWarningInfos.add(iotWarningInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
iotPowers.add(iotPower);
|
||||||
|
|
||||||
|
if (iotPowers.size() > 0) {
|
||||||
|
iotPowerService.batchInsertPower(iotPowers);
|
||||||
|
}
|
||||||
|
if (iotWarningInfos.size() > 0) {
|
||||||
|
iotWarningInfoService.batchInsertWarning(iotWarningInfos);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,5 @@
|
||||||
package com.ruoyi.weixin.controller;
|
package com.ruoyi.weixin.controller;
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
|
Loading…
Reference in New Issue