1、增加贵州院UDP推送
This commit is contained in:
parent
121771b068
commit
8a4fe22d0f
@ -1,6 +1,9 @@
|
||||
package com.imdroid.beidou_fwd.entity;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -8,73 +11,26 @@ import java.util.List;
|
||||
*
|
||||
* @author LiGang
|
||||
*/
|
||||
@Data
|
||||
public class GZYData {
|
||||
private String identityName;
|
||||
private String type = "dbwy";
|
||||
|
||||
private List<Data> TranData;
|
||||
|
||||
public String getIdentityName() {
|
||||
return identityName;
|
||||
public GZYData(){
|
||||
TranData = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setIdentityName(String identityName) {
|
||||
this.identityName = identityName;
|
||||
public void addData(Data data){
|
||||
TranData.add(data);
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public List<Data> getTranData() {
|
||||
return TranData;
|
||||
}
|
||||
|
||||
public void setTranData(List<Data> tranData) {
|
||||
TranData = tranData;
|
||||
}
|
||||
|
||||
static class Data {
|
||||
@lombok.Data
|
||||
public static class Data {
|
||||
private String CollectTime;
|
||||
|
||||
private Double X;
|
||||
private Double Y;
|
||||
private Double Z;
|
||||
|
||||
public String getCollectTime() {
|
||||
return CollectTime;
|
||||
}
|
||||
|
||||
public void setCollectTime(String collectTime) {
|
||||
CollectTime = collectTime;
|
||||
}
|
||||
|
||||
public Double getX() {
|
||||
return X;
|
||||
}
|
||||
|
||||
public void setX(Double x) {
|
||||
X = x;
|
||||
}
|
||||
|
||||
public Double getY() {
|
||||
return Y;
|
||||
}
|
||||
|
||||
public void setY(Double y) {
|
||||
Y = y;
|
||||
}
|
||||
|
||||
public Double getZ() {
|
||||
return Z;
|
||||
}
|
||||
|
||||
public void setZ(Double z) {
|
||||
Z = z;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,43 @@
|
||||
package com.imdroid.beidou_fwd.service;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.DatagramPacket;
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class UDPClient {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private DatagramSocket socket;
|
||||
|
||||
private InetAddress inetAddress;
|
||||
|
||||
private String host;
|
||||
|
||||
private int port;
|
||||
|
||||
public void init(String host, int port) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
try {
|
||||
logger.info("UDP client init "+host + ":" + port);
|
||||
this.socket = new DatagramSocket();
|
||||
this.inetAddress = InetAddress.getByName(host);
|
||||
} catch (Exception e) {
|
||||
logger.error("初始化udp客户端失败:", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(String msg) {
|
||||
try {
|
||||
logger.info("udp推送gnss数据:{}", msg);
|
||||
byte[] data = msg.getBytes();
|
||||
DatagramPacket packet = new DatagramPacket(data, data.length, inetAddress, port);
|
||||
socket.send(packet);
|
||||
} catch (Exception e) {
|
||||
logger.error("udp推送gnss数据异常:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,6 +27,8 @@ public class Forwarder {
|
||||
@Autowired
|
||||
GnssGroupFwdMapper fwdMapper;
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
void init(String name, String desc){
|
||||
this.name = name;
|
||||
this.description = desc;
|
||||
@ -51,7 +53,6 @@ public class Forwarder {
|
||||
ConcurrentHashMap<String, List<GnssCalcData>> projects = new ConcurrentHashMap<>();
|
||||
|
||||
// 转发数据
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
String sendAfterTime = nowTime.minusMinutes(30).format(formatter);
|
||||
|
||||
QueryWrapper<GnssDevice> queryWrapper = new QueryWrapper<>();
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
package com.imdroid.beidou_fwd.task;
|
||||
|
||||
import com.imdroid.beidou_fwd.entity.GZYData;
|
||||
import com.imdroid.beidou_fwd.service.UDPClient;
|
||||
import com.imdroid.common.util.GsonUtil;
|
||||
import com.imdroid.common.util.NumberUtils;
|
||||
import com.imdroid.secapi.dto.GnssCalcData;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
public class GZYForwarder extends Forwarder{
|
||||
private final Logger logger = LoggerFactory.getLogger(GZYForwarder.class);
|
||||
|
||||
static final String FORWARDER_NAME = "贵州交勘院";
|
||||
@Value("${gzy.server.host}")
|
||||
private String host;
|
||||
|
||||
@Value("${gzy.server.port}")
|
||||
private int port;
|
||||
|
||||
UDPClient udpClient;
|
||||
|
||||
@PostConstruct
|
||||
void registerMe(){
|
||||
init(FORWARDER_NAME, host+":"+port);
|
||||
udpClient = new UDPClient();
|
||||
udpClient.init(host, port);
|
||||
}
|
||||
/**
|
||||
* 每半小时转发GNSS解算结果
|
||||
*/
|
||||
@Scheduled(cron = "0 0/30 * * * ?") // 每30分钟执行一次
|
||||
private void forwardGnss() {
|
||||
forwardCurrentGnss(FORWARDER_NAME);
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 40 * * * ?") // 每小时的40分钟执行一次
|
||||
//@Scheduled(cron = "0 0/20 * * * ?") // 每20分钟执行一次
|
||||
private void forwardHistoryGnss() {
|
||||
forwardHistoryGnss(FORWARDER_NAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
int send(String projectId, List<GnssCalcData> records){
|
||||
int sendNum = 0;
|
||||
if(records.size() == 0) return 0;
|
||||
|
||||
GZYData gzyData = new GZYData();
|
||||
gzyData.setIdentityName(projectId);
|
||||
|
||||
|
||||
for(GnssCalcData locationRecord: records) {
|
||||
if(!locationRecord.getEnabled()) continue;
|
||||
GZYData.Data tranData = new GZYData.Data();
|
||||
tranData.setCollectTime(locationRecord.getCreatetime().format(formatter));
|
||||
double n = NumberUtils.scale(locationRecord.getRb562n(), 2);
|
||||
double e = NumberUtils.scale(locationRecord.getRb562e(), 2);
|
||||
double d = NumberUtils.scale(locationRecord.getRb562d(), 2);
|
||||
tranData.setX(n);
|
||||
tranData.setY(e);
|
||||
tranData.setZ(d);
|
||||
gzyData.addData(tranData);
|
||||
sendNum++;
|
||||
}
|
||||
String json = GsonUtil.toJson(gzyData);
|
||||
String msg = "JGKJ" + json + "#!";
|
||||
logger.info("forward to GZY");
|
||||
logger.info(msg);
|
||||
udpClient.sendMessage(msg);
|
||||
return sendNum;
|
||||
}
|
||||
|
||||
}
|
||||
@ -26,6 +26,9 @@ xfz.server.port = 52000
|
||||
#xfz.server.host = 115.236.153.174
|
||||
#xfz.server.port = 31035
|
||||
|
||||
gzy.server.host = 8.134.84.223
|
||||
gzy.server.port = 8088
|
||||
|
||||
kingma.server.login_user = ceshi
|
||||
kingma.server.login_pwd = ceshi!123
|
||||
kingma.server.login_host = https://www.everiaction.com/IOT-ADAPTER-CUSTOM/auth/anon/login
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user