提交代码

main
姜玉琦 2024-10-26 15:54:47 +08:00
parent a32bb3c79c
commit 72f534622c
5 changed files with 212 additions and 94 deletions

View File

@ -11,9 +11,15 @@ package com.ruoyi.iot.conf;
public class HzApiConf { public class HzApiConf {
/** /**
* IOTHOST * IOTHOST&&
*/ */
public static String IOT_POWER_HOST = "http://api.1357.cn/hz-condition-monitor"; public static String IOT_POWER_HOST = "http://api.1357.cn/hz-condition-monitor";
/**
* IOTHOST&&
*/
public static String SD_IOT_POWER_HOST = "https://api.e.v1.i-sada.net";
/** /**
* HOST * HOST
*/ */

View File

@ -42,6 +42,10 @@ public class IotDeviceInfo extends BaseEntity
private String hzTenantId; private String hzTenantId;
private String hzProjectId; private String hzProjectId;
private String factoryName;
private String companyName;
private String projectName;
public void setId(Long id) public void setId(Long id)
{ {
this.id = id; this.id = id;
@ -121,6 +125,30 @@ public class IotDeviceInfo extends BaseEntity
this.hzProjectId = hzProjectId; this.hzProjectId = hzProjectId;
} }
public String getFactoryName() {
return factoryName;
}
public void setFactoryName(String factoryName) {
this.factoryName = factoryName;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getProjectName() {
return projectName;
}
public void setProjectName(String projectName) {
this.projectName = projectName;
}
@Override @Override
public String toString() { public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)

View File

@ -5,6 +5,7 @@ import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.HttpUtils; import com.ruoyi.common.utils.HttpUtils;
import com.ruoyi.iot.conf.HzApiConf; import com.ruoyi.iot.conf.HzApiConf;
@ -46,7 +47,6 @@ import java.util.*;
@Component("gainHzDataTask") @Component("gainHzDataTask")
public class GainHzDataTask { public class GainHzDataTask {
private static final Logger log = LoggerFactory.getLogger(GainHzDataTask.class); private static final Logger log = LoggerFactory.getLogger(GainHzDataTask.class);
@Autowired @Autowired
@ -61,7 +61,6 @@ public class GainHzDataTask {
@Autowired @Autowired
private IStandardCuringRoomDeviceService iStandardCuringRoomDeviceService; private IStandardCuringRoomDeviceService iStandardCuringRoomDeviceService;
@Autowired @Autowired
private IEnvironmentService environmentService; private IEnvironmentService environmentService;
@ -73,6 +72,7 @@ public class GainHzDataTask {
public static Boolean[] warrning = 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}; public static Boolean[] warrning = 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};
public static Boolean[] warrning1 = 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}; public static Boolean[] warrning1 = 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};
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 @Test
public void getPowerData() { public void getPowerData() {
@ -87,6 +87,7 @@ public class GainHzDataTask {
iotDeviceInfo.setDeviceName("配电箱"); iotDeviceInfo.setDeviceName("配电箱");
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());
@ -168,8 +169,110 @@ public class GainHzDataTask {
iotWarningInfoService.batchInsertWarning(iotWarningInfos); 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) {
iotPowerService.batchInsertPower(iotPowers);
}
if (iotWarningInfos.size() > 0) {
iotWarningInfoService.batchInsertWarning(iotWarningInfos);
}
}
});
} }
@Test @Test

View File

@ -1,43 +1,20 @@
package com.ruoyi.iot.task; package com.ruoyi.iot.task;
import cc.casually.htmlParse.http.*;
import cc.casually.htmlParse.util.HttpUtil;
import cn.hutool.http.HttpRequest; import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.message.MessageOneUtil; import com.ruoyi.common.message.MessageOneUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.iot.conf.HzApiConf;
import com.ruoyi.iot.domain.IotPower;
import com.ruoyi.iot.domain.IotWarningInfo;
import com.ruoyi.iot.domain.StandardCuringRoomDevice;
import com.ruoyi.iot.service.IIotPowerService;
import com.ruoyi.iot.service.IIotWarningInfoService;
import com.ruoyi.iot.service.IStandardCuringRoomDeviceService;
import com.ruoyi.system.mapper.MeasureDeviceMapper; import com.ruoyi.system.mapper.MeasureDeviceMapper;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.utils.HttpUtils; import com.ruoyi.utils.HttpUtils;
import com.ruoyi.weixin.domain.Environment;
import com.ruoyi.weixin.mapper.ConcreteStrengthDataMapper; import com.ruoyi.weixin.mapper.ConcreteStrengthDataMapper;
import com.ruoyi.weixin.mapper.EnvironmentMapper;
import com.ruoyi.weixin.service.IEnvironmentService;
import org.apache.commons.collections.map.HashedMap; import org.apache.commons.collections.map.HashedMap;
import org.apache.http.HttpResponse;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
import java.util.stream.Collectors;
/** /**
* *

View File

@ -14,10 +14,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="typeName" column="type_name" /> <result property="typeName" column="type_name" />
<result property="hzTenantId" column="hz_tenant_id" /> <result property="hzTenantId" column="hz_tenant_id" />
<result property="hzProjectId" column="hz_project_id" /> <result property="hzProjectId" column="hz_project_id" />
<result property="factoryName" column="factory_name" />
<result property="companyName" column="company_name" />
<result property="projectName" column="project_name" />
</resultMap> </resultMap>
<sql id="selectIotDeviceInfoVo"> <sql id="selectIotDeviceInfoVo">
select id, device_id, device_name, state, project_id, points,type_name,hz_tenant_id,hz_project_id from iot_device_info select id, device_id, device_name, state, project_id, points, type_name, hz_tenant_id, hz_project_id, factory_name, company_name, project_name from iot_device_info
</sql> </sql>
<select id="selectIotDeviceInfoList" parameterType="IotDeviceInfo" resultMap="IotDeviceInfoResult"> <select id="selectIotDeviceInfoList" parameterType="IotDeviceInfo" resultMap="IotDeviceInfoResult">
@ -29,6 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="projectId != null "> and project_id = #{projectId}</if> <if test="projectId != null "> and project_id = #{projectId}</if>
<if test="points != null "> and points = #{points}</if> <if test="points != null "> and points = #{points}</if>
<if test="typeName != null "> and type_name = #{typeName}</if> <if test="typeName != null "> and type_name = #{typeName}</if>
<if test="factoryName != null and factoryName != ''"> and factory_name = #{factoryName}</if>
</where> </where>
</select> </select>