[*] 日常优化
This commit is contained in:
@@ -788,6 +788,9 @@ class Taoyao extends RemoteClient {
|
||||
const { header, body } = message;
|
||||
const { signal } = header;
|
||||
switch (signal) {
|
||||
case "client::broadcast":
|
||||
me.defaultClientBroadcast(message);
|
||||
break;
|
||||
case "client::reboot":
|
||||
me.defaultClientReboot(message);
|
||||
break;
|
||||
@@ -1002,6 +1005,52 @@ class Taoyao extends RemoteClient {
|
||||
return track;
|
||||
}
|
||||
|
||||
/**
|
||||
* 终端告警信令
|
||||
*
|
||||
* @param {*} message
|
||||
*/
|
||||
clientAlarm(message) {
|
||||
const me = this;
|
||||
const date = new Date();
|
||||
const datetime = "" +
|
||||
date.getFullYear() +
|
||||
((date.getMonth() < 9 ? "0" : "") + (date.getMonth() + 1)) +
|
||||
((date.getDate() < 10 ? "0" : "") + date.getDate()) +
|
||||
((date.getHours() < 10 ? "0" : "") + date.getHours()) +
|
||||
((date.getMinutes() < 10 ? "0" : "") + date.getMinutes()) +
|
||||
((date.getSeconds() < 10 ? "0" : "") + date.getSeconds());
|
||||
me.push(protocol.buildMessage("client::alarm", {
|
||||
message,
|
||||
datetime,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 终端广播信令
|
||||
*
|
||||
* @param {*} message 广播信息
|
||||
* @param {*} clientType 终端类型(可选)
|
||||
*/
|
||||
clientBroadcast(message, clientType) {
|
||||
const me = this;
|
||||
me.push(protocol.buildMessage("client::broadcast", {
|
||||
...message,
|
||||
clientType,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* 终端广播信令
|
||||
*
|
||||
* @param {*} message 信令消息
|
||||
*/
|
||||
defaultClientBroadcast(message) {
|
||||
const me = this;
|
||||
const { header, body } = message;
|
||||
console.debug("终端广播", header, body);
|
||||
}
|
||||
|
||||
/**
|
||||
* 终端配置信令
|
||||
*
|
||||
|
||||
@@ -62,17 +62,18 @@ public class ClientStatus {
|
||||
* @param body 消息主体
|
||||
*/
|
||||
public void copy(Map<String, Object> body) {
|
||||
this.setLatitude(MapUtils.getDouble(body, Constant.LATITUDE));
|
||||
this.setLongitude(MapUtils.getDouble(body, Constant.LONGITUDE));
|
||||
this.setHumidity(MapUtils.getDouble(body, Constant.HUMIDITY));
|
||||
this.setTemperature(MapUtils.getDouble(body, Constant.TEMPERATURE));
|
||||
this.setSignal(MapUtils.getInteger(body, Constant.SIGNAL));
|
||||
this.setBattery(MapUtils.getInteger(body, Constant.BATTERY));
|
||||
this.setAlarming(MapUtils.getBoolean(body, Constant.ALARMING));
|
||||
this.setCharging(MapUtils.getBoolean(body, Constant.CHARGING));
|
||||
this.setClientRecording(MapUtils.getBoolean(body, Constant.CLIENT_RECORDING));
|
||||
this.status(MapUtils.get(body, Constant.STATUS));
|
||||
this.config(MapUtils.get(body, Constant.CONFIG));
|
||||
this.setLatitude(MapUtils.get(body, Constant.LATITUDE, this.latitude));
|
||||
this.setLongitude(MapUtils.get(body, Constant.LONGITUDE, this.longitude));
|
||||
this.setHumidity(MapUtils.get(body, Constant.HUMIDITY, this.humidity));
|
||||
this.setTemperature(MapUtils.get(body, Constant.TEMPERATURE, this.temperature));
|
||||
this.setSignal(MapUtils.get(body, Constant.SIGNAL, this.signal));
|
||||
this.setBattery(MapUtils.get(body, Constant.BATTERY, this.battery));
|
||||
this.setAlarming(MapUtils.get(body, Constant.ALARMING, this.alarming));
|
||||
this.setCharging(MapUtils.get(body, Constant.CHARGING, this.charging));
|
||||
this.setClientRecording(MapUtils.get(body, Constant.CLIENT_RECORDING, this.clientRecording));
|
||||
// this.setServerRecording(MapUtils.get(body, Constant.SERVER_RECORDING, this.serverRecording));
|
||||
this.status(MapUtils.get(body, Constant.STATUS, this.status));
|
||||
this.config(MapUtils.get(body, Constant.CONFIG, this.config));
|
||||
this.setLastHeartbeat(LocalDateTime.now());
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Description(
|
||||
body = """
|
||||
{
|
||||
"message": "告警描述",
|
||||
"message" : "告警描述",
|
||||
"datetime": "告警时间(yyyyMMddHHmmss)"
|
||||
}
|
||||
""",
|
||||
@@ -40,9 +40,9 @@ public class ClientAlarmProtocol extends ProtocolClientAdapter {
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
final String alarmMessage = MapUtils.get(body, Constant.MESSAGE);
|
||||
final String alarmMessage = MapUtils.get(body, Constant.MESSAGE);
|
||||
final String alarmDatetime = MapUtils.get(body, Constant.DATETIME);
|
||||
log.warn(
|
||||
log.info(
|
||||
"""
|
||||
终端告警:{}
|
||||
终端类型:{}
|
||||
|
||||
@@ -33,20 +33,20 @@ import com.acgist.taoyao.signal.protocol.ProtocolClientAdapter;
|
||||
)
|
||||
public class ClientBroadcastProtocol extends ProtocolClientAdapter {
|
||||
|
||||
public static final String SIGNAL = "client::broadcast";
|
||||
public static final String SIGNAL = "client::broadcast";
|
||||
|
||||
public ClientBroadcastProtocol() {
|
||||
super("终端广播信令", SIGNAL);
|
||||
}
|
||||
public ClientBroadcastProtocol() {
|
||||
super("终端广播信令", SIGNAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
final String queryClientType = MapUtils.get(body, Constant.CLIENT_TYPE);
|
||||
if(StringUtils.isEmpty(queryClientType)) {
|
||||
this.clientManager.broadcast(client, message);
|
||||
} else {
|
||||
this.clientManager.broadcast(client, message, ClientType.of(queryClientType));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void execute(String clientId, ClientType clientType, Client client, Message message, Map<String, Object> body) {
|
||||
final String queryClientType = MapUtils.get(body, Constant.CLIENT_TYPE);
|
||||
if(StringUtils.isEmpty(queryClientType)) {
|
||||
this.clientManager.broadcast(client, message);
|
||||
} else {
|
||||
this.clientManager.broadcast(client, message, ClientType.of(queryClientType));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user