吊装监控设备告警推送开发
This commit is contained in:
parent
722af680d4
commit
95e496c0a4
|
|
@ -0,0 +1,29 @@
|
|||
package com.bonus.common.entity.tcp;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* 静电感应
|
||||
*/
|
||||
@Data
|
||||
public class ElectricityVo {
|
||||
|
||||
private String id;
|
||||
|
||||
private String devCode;
|
||||
|
||||
private String devName;
|
||||
|
||||
private String warnContent;
|
||||
|
||||
|
||||
private String warnTime;
|
||||
|
||||
|
||||
private String userId;
|
||||
|
||||
private String proId;
|
||||
|
||||
private String warnType;
|
||||
}
|
||||
Binary file not shown.
|
|
@ -100,17 +100,33 @@
|
|||
<version>24.6.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<!--吊装监控sdk-->
|
||||
<dependency>
|
||||
<groupId>gps-push-client</groupId>
|
||||
<artifactId>gps-push-client</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${project.basedir}/libs/gps-push-client.jar</systemPath>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<finalName>${project.artifactId}</finalName>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import com.bonus.common.security.annotation.EnableCustomConfig;
|
|||
import com.bonus.common.security.annotation.EnableRyFeignClients;
|
||||
import com.bonus.common.swagger.annotation.EnableCustomSwagger2;
|
||||
import com.bonus.tcp.server.server.BootNettyServer;
|
||||
import com.bonus.tcp.warn.DevWarnImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
|
|
@ -16,8 +18,25 @@ import org.springframework.scheduling.annotation.Async;
|
|||
@EnableRyFeignClients
|
||||
@SpringBootApplication(exclude = MongoAutoConfiguration.class)
|
||||
public class BonusTcpApplication implements CommandLineRunner {//实现CommandLineRunner
|
||||
|
||||
|
||||
@Value("${tcp.server.port}")
|
||||
private int port;
|
||||
|
||||
@Value("${dev.video.ip}")
|
||||
private String videIp;
|
||||
|
||||
@Value("${dev.video.port}")
|
||||
private int videPort;
|
||||
|
||||
@Value("${dev.video.username}")
|
||||
private String username;
|
||||
|
||||
@Value("${dev.video.pwd}")
|
||||
private String pwd;
|
||||
|
||||
@Value("${dev.video.msgId}")
|
||||
private String msgId;
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(BonusTcpApplication.class, args);
|
||||
System.err.println("(♥◠‿◠)ノ゙ TCP模块启动成功 ლ(´ڡ`ლ)゙");
|
||||
|
|
@ -28,6 +47,27 @@ public class BonusTcpApplication implements CommandLineRunner {//实现CommandLi
|
|||
@Async
|
||||
@Override
|
||||
public void run(String... args) throws Exception {
|
||||
clientDevWarn();
|
||||
new BootNettyServer().bind(port);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建链接数据推送接口
|
||||
* @throws Exception
|
||||
*/
|
||||
public void clientDevWarn() throws Exception {
|
||||
DevWarnImpl client = new DevWarnImpl();
|
||||
client.setLog(false);
|
||||
client.setHost(videIp);
|
||||
client.setPort(videPort);
|
||||
client.setUserName(username);
|
||||
client.setPwd(pwd);
|
||||
client.setSubMsgIds(msgId);
|
||||
client.setDesc("测试客户端");
|
||||
client.start();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -17,6 +17,7 @@ import org.springframework.scheduling.annotation.Async;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
|
|
@ -134,4 +135,16 @@ public class TcpDataService {
|
|||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 告警数据入库
|
||||
* @param jsonString
|
||||
*/
|
||||
public void insertDevWarnInfo(Map<String,Object> jsonString) {
|
||||
try{
|
||||
|
||||
}catch (Exception e){
|
||||
log.error(e.toString(),e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,116 @@
|
|||
package com.bonus.tcp.warn;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.bonus.common.core.utils.SpringUtils;
|
||||
import com.bonus.tcp.smartIdentify.service.impl.TcpDataService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.gps31.push.netty.PushClient;
|
||||
import com.gps31.push.netty.PushMsg;
|
||||
import com.gps31.push.netty.client.TcpClient;
|
||||
import com.gps31.push.util.MapUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 吊装监控告警推送
|
||||
* @author 黑子
|
||||
*/
|
||||
@Slf4j
|
||||
public class DevWarnImpl extends PushClient{
|
||||
|
||||
public TcpDataService service = SpringUtils.getBean(TcpDataService.class);
|
||||
private ThreadPoolExecutor pool = new ThreadPoolExecutor(10,10,30, TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(),new ThreadPoolExecutor.AbortPolicy());
|
||||
@Override
|
||||
public void messageReceived(TcpClient tcpClient, PushMsg pushMsg)
|
||||
throws Exception {
|
||||
if("8001".equals(pushMsg.getCmd())) {//登录应答
|
||||
String rspResult = MapUtil.getStrVal(pushMsg.getJsonMap(),"rspResult","1");
|
||||
if("0".equals(rspResult)) {//登录成功,定阅动态消息
|
||||
Map<String,Object> map = new HashMap<String,Object>();
|
||||
map.put("seq", "1");
|
||||
map.put("action", "add");
|
||||
map.put("msgIds", JSON.toJSONString(getSubCmdSet()));
|
||||
PushMsg subMsg = getInstance("0003",map);
|
||||
sendMsg(subMsg);
|
||||
}
|
||||
}else if("8002".equals(pushMsg.getCmd())){//心跳应答
|
||||
}else if("8003".equals(pushMsg.getCmd())){//订阅动态消息应答
|
||||
String rspResult = MapUtil.getStrVal(pushMsg.getJsonMap(),"rspResult","1");
|
||||
log.error(String.format(" 订阅应答:%s", "0".equals(rspResult)?"成功":"失败"));
|
||||
}else if("0200".equals(pushMsg.getCmd())) {//定位信息
|
||||
Map<String,Object> gpsMap = pushMsg.getJsonMap();
|
||||
String carName = MapUtil.getStrVal(gpsMap, "carName","");//获取车牌号
|
||||
log.error(String.format(" ---->收到定位数据:%s",JSON.toJSONString(gpsMap)));
|
||||
/**
|
||||
* 请加入三方集成方的业务逻辑
|
||||
* 注意:下面的代码不要出现阻塞操作(比如数据库操作),否则会出现推送的数据延迟情况;
|
||||
*/
|
||||
|
||||
//有阻塞的业务,请使用线程池处理接收到的每个消息。
|
||||
pool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
}
|
||||
});
|
||||
}else if("0300".equals(pushMsg.getCmd())) {//报警消息
|
||||
Map<String,Object> alarmMap = pushMsg.getJsonMap();
|
||||
String carName = MapUtil.getStrVal(alarmMap, "carName","");//获取车牌号
|
||||
log.error(String.format(" ---->收到报警数据:%s",JSON.toJSONString(alarmMap)));
|
||||
/**
|
||||
* 请加入三方集成方的业务逻辑
|
||||
* 注意:下面的代码不要出现阻塞操作(比如数据库操作),否则会出现推送的数据延迟情况;
|
||||
*/
|
||||
//有阻塞的业务,请使用线程池处理接收到的每个消息。
|
||||
pool.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
service.insertDevWarnInfo( alarmMap);
|
||||
}
|
||||
});
|
||||
}else if("0401".equals(pushMsg.getCmd())) {//透传消息
|
||||
Map<String,Object> dataMap = pushMsg.getJsonMap();
|
||||
String carName = MapUtil.getStrVal(dataMap, "carName","");//获取车牌号
|
||||
log.error(String.format(" ---->收到透传数据:%s",JSON.toJSONString(dataMap)));
|
||||
/**
|
||||
* 请加入三方集成方的业务逻辑
|
||||
*/
|
||||
}
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
//下面是指向的是我们演示服务器,可以直接执行,用于验证数据推送。正式使用时,请修改相应的参数:比如IP,帐号,密码
|
||||
DevWarnImpl client = new DevWarnImpl();
|
||||
client.setLog(true);//是否打印明文的交互信息
|
||||
// client.setLogBytes(true);//是否打印网络字节流
|
||||
if(args == null || args.length>=5) {
|
||||
client.setHost(args[0]);//服务器IP
|
||||
client.setPort(Integer.parseInt(args[1]));//服务器端口
|
||||
client.setUserName(args[2]);//系统用户名
|
||||
client.setPwd(args[3]);//系统用户密码
|
||||
client.setSubMsgIds(args[4]);//订阅的动态消息,当前示例是订阅 定位消息(0x0200)
|
||||
}else {
|
||||
client.setHost("115.233.219.190");//服务器IP
|
||||
client.setPort(10100);//服务器端口
|
||||
client.setUserName("ys_admin");//系统用户名
|
||||
client.setPwd("123456");//系统用户密码
|
||||
client.setSubMsgIds("0200|0300");//订阅的动态消息,多个动态消息使用|辟分,当前示例是订阅 定位消息(0x0200)和报警消息(0x0300)
|
||||
}
|
||||
client.setDesc("测试客户端");//客户端的描述,
|
||||
client.start();
|
||||
while(true) {
|
||||
// Thread.sleep(1000);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue