1、优化UI权限管理
2、增加MQTT推送
This commit is contained in:
parent
dcd6c2f73d
commit
c769c41184
@ -35,15 +35,6 @@
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-amqp</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
@ -73,29 +64,6 @@
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>31.1-jre</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>5.5.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.yulichang</groupId>
|
||||
<artifactId>mybatis-plus-join-boot-starter</artifactId>
|
||||
<version>1.4.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
@ -124,6 +92,12 @@
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.76</version>
|
||||
</dependency>
|
||||
<!--mqtt相关依赖-->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.paho</groupId>
|
||||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@ -0,0 +1,21 @@
|
||||
package com.imdroid.beidou_fwd.entity;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
|
||||
/**
|
||||
* MQTT数据推送 api
|
||||
*
|
||||
* @author LiGang
|
||||
*/
|
||||
@Data
|
||||
public class GZYMQTTData {
|
||||
private String deviceSn;
|
||||
private String collectTime;
|
||||
private int deviceType;
|
||||
// gnss数据
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
}
|
||||
@ -0,0 +1,62 @@
|
||||
package com.imdroid.beidou_fwd.service;
|
||||
|
||||
import org.eclipse.paho.client.mqttv3.*;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
public class MQTTClient {
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private MqttClient client;
|
||||
private String brokerUrl;
|
||||
private String username;
|
||||
private String password;
|
||||
private String clientid;
|
||||
private String topic;
|
||||
int qos = 1;//0、1、2
|
||||
|
||||
public MQTTClient(String brokerUrl, String username, String password,
|
||||
String clientid, String topic){
|
||||
this.brokerUrl = brokerUrl;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.clientid = clientid;
|
||||
this.topic = topic;
|
||||
}
|
||||
|
||||
public void connect() throws MqttException {
|
||||
// Create a new MQTT client.
|
||||
client = new MqttClient(brokerUrl, clientid, new MemoryPersistence());
|
||||
// Create a new MQTT connection options object.
|
||||
MqttConnectOptions options = new MqttConnectOptions();
|
||||
// Set the MQTT connection options.
|
||||
options.setCleanSession(true);
|
||||
options.setUserName(username);
|
||||
options.setPassword(password.toCharArray());
|
||||
// Connect to the MQTT broker.
|
||||
client.connect(options);
|
||||
}
|
||||
|
||||
public void publish(String message) throws MqttException {
|
||||
try { // Create a new MQTT message.
|
||||
MqttMessage mqttMessage = new MqttMessage(message.getBytes());
|
||||
mqttMessage.setQos(qos);
|
||||
// Publish the MQTT message to the topic.
|
||||
client.publish(topic, mqttMessage);
|
||||
System.out.println("Message published");
|
||||
System.out.println("topic: " + topic);
|
||||
System.out.println("message content: " + mqttMessage);
|
||||
} catch (Exception e) {
|
||||
logger.error("mqtt推送gnss数据异常:", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() throws MqttException {
|
||||
// Disconnect from the MQTT broker.
|
||||
client.disconnect();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,92 @@
|
||||
package com.imdroid.beidou_fwd.task;
|
||||
|
||||
|
||||
import com.imdroid.beidou_fwd.entity.GZYMQTTData;
|
||||
import com.imdroid.beidou_fwd.service.MQTTClient;
|
||||
import com.imdroid.common.util.GsonUtil;
|
||||
import com.imdroid.common.util.NumberUtils;
|
||||
import com.imdroid.secapi.dto.GnssCalcData;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
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 GZYMQTTForwarder extends Forwarder {
|
||||
private final Logger logger = LoggerFactory.getLogger(GZYMQTTForwarder.class);
|
||||
|
||||
static final String FORWARDER_NAME = "贵州交勘院";
|
||||
@Value("${mqtt.server.brokerUrl}")
|
||||
private String brokerUrl;
|
||||
@Value("${mqtt.server.username}")
|
||||
private String username;
|
||||
@Value("${mqtt.server.password}")
|
||||
private String password;
|
||||
@Value("${mqtt.server.clientid}")
|
||||
private String clientid;
|
||||
@Value("${mqtt.server.topic}")
|
||||
private String topic;
|
||||
|
||||
|
||||
MQTTClient mqttClient;
|
||||
|
||||
@PostConstruct
|
||||
void registerMe() throws MqttException {
|
||||
init(FORWARDER_NAME, "MQTT "+brokerUrl,2,true);
|
||||
mqttClient = new MQTTClient(brokerUrl, username, password,clientid,topic);
|
||||
mqttClient.connect();
|
||||
}
|
||||
|
||||
/**
|
||||
* 每半小时转发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;
|
||||
|
||||
for (GnssCalcData locationRecord : records) {
|
||||
GZYMQTTData tranData = new GZYMQTTData();
|
||||
tranData.setCollectTime(locationRecord.getCreatetime().format(formatter));
|
||||
double n = NumberUtils.scale(locationRecord.getRposn(), 2);
|
||||
double e = NumberUtils.scale(locationRecord.getRpose(), 2);
|
||||
double d = NumberUtils.scale(locationRecord.getRposd(), 2);
|
||||
tranData.setX(n);
|
||||
tranData.setY(e);
|
||||
tranData.setZ(d);
|
||||
String json = GsonUtil.toJson(tranData);
|
||||
String msg = "JGKJ" + json + "#!";
|
||||
logger.info("forward to GZY mqtt");
|
||||
logger.info(msg);
|
||||
try {
|
||||
mqttClient.publish(msg);
|
||||
Thread.sleep(200);
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
sendNum++;
|
||||
}
|
||||
|
||||
return sendNum;
|
||||
}
|
||||
|
||||
}
|
||||
@ -31,6 +31,12 @@ xfz.server.port = 31035
|
||||
gzy.server.host = 127.0.0.1
|
||||
gzy.server.port = 18088
|
||||
|
||||
mqtt.server.brokerUrl = tcp://8.134.58.55:1883
|
||||
mqtt.server.username = mqtt_test
|
||||
mqtt.server.password = test1234
|
||||
mqtt.server.clientid = GZY_client
|
||||
mqtt.server.topic = GXJY-01
|
||||
|
||||
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
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
<input type="text" name="sl_deviceid" id="deviceid" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline" th:if="${role=='SUPER_ADMIN' || role=='ADMIN'}">
|
||||
<div class="layui-inline" th:if="${tenant_id==0}">
|
||||
<label class="layui-form-label">所属部门</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="n_tenantid" id="n_tenantid" lay-search="">
|
||||
@ -92,7 +92,8 @@
|
||||
{field: 'enabled', title: '有效',templet: '#enabledTrans'},
|
||||
{field: 'pps', title: '平均延迟'}
|
||||
];
|
||||
if([[${role}]] != "ADMIN" && [[${role}]] != "SUPER_ADMIN") {
|
||||
if([[${role}]] != "ADMIN" && [[${role}]] != "SUPER_ADMIN" &&
|
||||
!([[${role}]] == "MANAGER" && [[${tenant_id}]] == 0)) {
|
||||
cfg_cols[9].hide = true;
|
||||
cfg_cols[10].hide = true;
|
||||
cfg_cols[11].hide = true;
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
<input type="text" name="project_id" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline" th:if="${role=='SUPER_ADMIN' || role=='ADMIN'}">
|
||||
<div class="layui-inline" th:if="${tenant_id==0}">
|
||||
<label class="layui-form-label">所属部门</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="tenantname" id="tenantname" lay-search="">
|
||||
@ -99,7 +99,8 @@
|
||||
{field: 'syn', title: '参数同步',templet: '#synTrans'},
|
||||
{title: '操作', toolbar: '#currentTableBar', align: "center", minWidth: 120}
|
||||
];
|
||||
if([[${role}]] != "ADMIN" && [[${role}]] != "SUPER_ADMIN") {
|
||||
if([[${role}]] != "ADMIN" && [[${role}]] != "SUPER_ADMIN" &&
|
||||
!([[${role}]] == "MANAGER" && [[${tenant_id}]] == 0)) {
|
||||
cfg_cols[9].hide = true;
|
||||
}
|
||||
/**
|
||||
|
||||
@ -24,7 +24,7 @@
|
||||
<input type="text" name="sl_d.deviceid" autocomplete="off" class="layui-input">
|
||||
</div>
|
||||
</div>
|
||||
<div class="layui-inline" th:if="${role=='SUPER_ADMIN' || role=='ADMIN'}">
|
||||
<div class="layui-inline" th:if="${tenant_id==0}">
|
||||
<label class="layui-form-label">所属部门</label>
|
||||
<div class="layui-input-inline">
|
||||
<select name="n_d.tenantid" id="n_d.tenantid" lay-search="">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user