Commit b1598822 authored by tangwei's avatar tangwei

场站104预警推送

parent 9bc23146
package com.yeejoin.equipmanage.common.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.yeejoin.equipmanage.common.entity.publics.BaseEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
/**
* @description:
* @author: tw
* @createDate: 2023/6/19
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@TableName("dz_point_system")
@ApiModel(value="PointSystem对象", description="")
public class PointSystem extends BaseEntity {
@ApiModelProperty(value = "场站")
@TableField("station")
private String station;
@ApiModelProperty(value = "二维码")
@TableField("number")
private String number;
@ApiModelProperty(value = "类型")
@TableField("type")
private String type;
@ApiModelProperty(value = "'地址'")
@TableField("address")
private String address;
@ApiModelProperty(value = "测点类型")
@TableField("point_type")
private String pointType;
@ApiModelProperty(value = "测点值")
@TableField("value")
private String value;
@ApiModelProperty(value = "功能码")
@TableField("function_num")
private String functionNum;
@ApiModelProperty(value = "kks码")
@TableField("kks")
private String kks;
}
package com.yeejoin.equipmanage.dto;
import lombok.Data;
import java.util.List;
/**
* @description:
* @author: tw
* @createDate: 2023/6/19
*/
@Data
public class BizInfo {
private String sourceAttributionDesc;
private String sourceAttribution;
private List<DynamicDetails> dynamicDetails;
private String warningObjectCode;
private String warningTime;
private String warningObjectName;
public BizInfo(String sourceAttributionDesc,
String sourceAttribution,
List<DynamicDetails> dynamicDetails,
String warningObjectCode,
String warningTime,
String warningObjectName) {
this.sourceAttributionDesc = sourceAttributionDesc;
this.sourceAttribution = sourceAttribution;
this.dynamicDetails = dynamicDetails;
this.warningObjectCode = warningObjectCode;
this.warningTime = warningTime;
this.warningObjectName = warningObjectName;
}
}
package com.yeejoin.equipmanage.dto;
import lombok.Data;
import java.util.List;
/**
* @description:
* @author: tw
* @createDate: 2023/6/19
*/
@Data
public class DynamicDetails {
private String tabName;
private List<TabContent> tabContent;
public DynamicDetails(String tabName, List<TabContent> tabContent) {
this.tabName = tabName;
this.tabContent = tabContent;
}
}
package com.yeejoin.equipmanage.dto;
import lombok.Data;
/**
* @description:
* @author: tw
* @createDate: 2023/6/19
*/
@Data
public class TabContent {
private String label;
private String type;
private Object value;
private String key;
public TabContent(String label, String type, Object value, String key) {
this.label = label;
this.type = type;
this.value = value;
this.key = key;
}
}
package com.yeejoin.equipmanage.dto;
import lombok.Data;
import java.util.List;
/**
* @description:
* @author: tw
* @createDate: 2023/6/19
*/
@Data
public class WarningDto {
private BizInfo bizInfo;
private String indexKey;
private String indexValue;
private String traceId;
public WarningDto( String indexKey, String indexValue, String traceId,
String sourceAttributionDesc,
String sourceAttribution,
List<DynamicDetails> dynamicDetails,
String warningObjectCode,
String warningTime,
String warningObjectName
) {
this.bizInfo = new BizInfo( sourceAttributionDesc, sourceAttribution, dynamicDetails, warningObjectCode, warningTime, warningObjectName);
this.indexKey = indexKey;
this.indexValue = indexValue;
this.traceId = traceId;
}
}
package com.yeejoin.equipmanage.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.equipmanage.common.entity.PointSystem;
/**
* @description:
* @author: tw
* @createDate: 2023/6/19
*/
public interface PointSystemMapper extends BaseMapper<PointSystem> {
//推送预警
public void sendWarning();
}
package com.yeejoin.equipmanage.service;
import com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex;
/**
* @description:
* @author: tw
* @createDate: 2023/6/19
*/
public interface IPointSystemService {
//触发风险预警
public void sendWarning(String address, String value);
}
package com.yeejoin.equipmanage.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yeejoin.equipmanage.common.entity.EquipmentSpecific;
import com.yeejoin.equipmanage.common.entity.EquipmentSpecificIndex;
import com.yeejoin.equipmanage.common.entity.PointSystem;
import com.yeejoin.equipmanage.common.utils.HttpContentTypeUtil;
import com.yeejoin.equipmanage.dto.DynamicDetails;
import com.yeejoin.equipmanage.dto.TabContent;
import com.yeejoin.equipmanage.dto.WarningDto;
import com.yeejoin.equipmanage.mapper.PointSystemMapper;
import com.yeejoin.equipmanage.service.IPointSystemService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.component.emq.EmqKeeper;
import java.text.SimpleDateFormat;
import java.util.*;
/**
* @description:
* @author: tw
* @createDate: 2023/6/19
*/
@Service
public class PointSystemServiceImpl extends ServiceImpl<PointSystemMapper, PointSystem> implements IPointSystemService {
@Autowired
PointSystemMapper pointSystemMapper;
@Value("${power.station.url}")
private String powerStationUrl;
private final String TABNAME="预警问题";
private final String TEXT= "text";
@Value("${power.station.warning:104/data/analysis}")
private String STATIONWARNING;
@Autowired
protected EmqKeeper emqKeeper;
@Override
public void sendWarning(String address, String value) {
try {
//通过测点地址获取,和对应值 获取kks
QueryWrapper<PointSystem> pointSystemWrapper = new QueryWrapper<>();
pointSystemWrapper.lambda().eq(PointSystem::getAddress, address);
pointSystemWrapper.lambda().eq(PointSystem::getValue, value);
PointSystem pointSystem = pointSystemMapper.selectOne(pointSystemWrapper);
if (pointSystem == null) {
throw new RuntimeException("获取kks码失败!");
}
//调用获取设备相关信息
Map<String, String> maps = new HashMap<>();
maps.put("type", "equipinfo");
maps.put("kksbm", pointSystem.getKks());
String data = HttpContentTypeUtil.sendHttpPost(powerStationUrl, maps);
if (StringUtils.isEmpty(data) || !(Boolean) JSON.parseObject(data).get("success")) {
throw new RuntimeException("获取设备信息失败!");
}
JSONObject json = JSON.parseObject(data);
JSONObject jsond = (JSONObject) json.get("dataset");
JSONArray list = (JSONArray) jsond.get("datas");
JSONObject eqdata = null;
if (list == null || list.isEmpty()) {
throw new RuntimeException("获取设备信息失败!");
}
eqdata = (JSONObject) list.get(0);
//组装数据,发送预警
WarningDto warningDto = setWarningDto(pointSystem, eqdata);
emqKeeper.getMqttClient().publish(STATIONWARNING, JSON.toJSONString(warningDto).getBytes(), 0, false);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("预警消息发送失败!");
}
}
public WarningDto setWarningDto(PointSystem pointSystem,JSONObject eqdata ){
SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time= sdf.format(new Date());
String warningObjectCode=pointSystem.getKks();
List<TabContent> tabContent=new ArrayList<>();
tabContent.add(new TabContent( "KKS编码", TEXT, warningObjectCode, "key1"));
tabContent.add(new TabContent( "设备名称", TEXT, eqdata.get("kksms"), "key2"));
tabContent.add(new TabContent( "发生时间", TEXT, time, "key3"));
DynamicDetails dynamicDetails=new DynamicDetails( TABNAME, tabContent);
List<DynamicDetails> dynamicDetailsList=new ArrayList<>();
dynamicDetailsList.add(dynamicDetails);
StringBuffer indexKey=new StringBuffer(pointSystem.getStation())
.append("#")
.append(pointSystem.getNumber())
.append("#")
.append(pointSystem.getFunctionNum());
StringBuffer indexValue=new StringBuffer(pointSystem.getPointType())
.append("#")
.append(pointSystem.getValue());
WarningDto WarningDto=new WarningDto(
indexKey.toString(),
indexValue.toString(),
null,
(String)eqdata.get("sourceAttributionDesc"),
(String)eqdata.get("sourceAttribution"),
dynamicDetailsList,
warningObjectCode,
time ,
(String)eqdata.get("kksms")
);
return WarningDto;
}
}
......@@ -24,7 +24,7 @@ pagehelper.support-methods-arguments=true
spring.main.allow-bean-definition-overriding=true
#liquibase
spring.liquibase.change-log=classpath:/changelog/changelog-master.xml
spring.liquibase.enabled=true
spring.liquibase.enabled=false
#\u4E0A\u4F20\u6587\u4EF6\u8BBE\u7F6E
spring.servlet.multipart.maxFileSize=100MB
......@@ -158,4 +158,8 @@ spring.security.user.password=a1234560
#\u6BCF\u500B\u7AD9\u8868\u793A
stationCode=LSHLZ1bZAJU645Pgl7
##\u4EE3\u7801\u4E2D\u6709\u90E8\u5206\u903B\u8F91\u51B2\u7A81\u9700\u8981\u5904\u7406 \u4E3A\u533A\u5206\u673A\u573A\u548C\u7535\u529B\u903B\u8F91 \u589E\u52A0\u5F00\u5173 \u82E5\u4E3Atrue \u5219\u4E3A\u673A\u573A\u903B\u8F91 \u4E3Afalse \u5219\u4E3A\u7535\u529B\u903B\u8F91
logic=false
\ No newline at end of file
logic=false
#电站对接第三方查询设备kks码
power.station.url=http://139.9.169.123:5024/process/DataInterface
#电站104采集预警
power.station.warning=104/data/analysis
\ No newline at end of file
......@@ -915,4 +915,29 @@
alter table `wl_equipment_specific_index` add column `gateway_id` varchar(50) COMMENT '网关标识ID';
</sql>
</changeSet>
<changeSet author="20230620" id="20230620-1" runAlways="true">
<comment>`dz_point_system`</comment>
<sql endDelimiter="#">
CREATE TABLE `dz_point_system` (
`id` bigint(0) NOT NULL,
`station` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '场站',
`number` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '型号',
`type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '类型',
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '地址',
`point_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '测点类型',
`value` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '测点值',
`function_num` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '功能码',
`kks` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'kks码',
`create_date` datetime(0) NULL DEFAULT NULL,
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;
</sql>
</changeSet>
</databaseChangeLog>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment