设备控制接口
parent
bbaaa45523
commit
aa8b384e12
|
|
@ -38,6 +38,18 @@ public class MqttMsgHandlers {
|
||||||
Tuqiang.enableWarn(terminalId, enable);
|
Tuqiang.enableWarn(terminalId, enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 启用报警
|
||||||
|
*/
|
||||||
|
@MqttListener(topic = "location/config_ip_port")
|
||||||
|
public void configIpPort(MqttMsg msg) {
|
||||||
|
ConfigIpPortParam configIpPortParam = msg.getMsg(ConfigIpPortParam.class);
|
||||||
|
String terminalId = configIpPortParam.getTerminalId();
|
||||||
|
String ip = configIpPortParam.getIp();
|
||||||
|
int port = configIpPortParam.getPort();
|
||||||
|
Tuqiang.configIpPort(terminalId, ip, port);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置速度阈值
|
* 设置速度阈值
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.njzscloud.common.localizer.mqtt.param;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class ConfigIpPortParam {
|
||||||
|
private String terminalId;
|
||||||
|
private String ip;
|
||||||
|
private int port;
|
||||||
|
}
|
||||||
|
|
@ -80,6 +80,21 @@ public final class Tuqiang {
|
||||||
JT808.sendTxtMessage(terminalId, StrUtil.format("<SPBSJ*P:BSJGPS*CS:{}*H:300>", speed));
|
JT808.sendTxtMessage(terminalId, StrUtil.format("<SPBSJ*P:BSJGPS*CS:{}*H:300>", speed));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备的连接地址
|
||||||
|
*
|
||||||
|
* @param terminalId 终端 Id
|
||||||
|
* @param ip 服务器 IP
|
||||||
|
* @param port 服务器端口
|
||||||
|
*/
|
||||||
|
public static void configIpPort(String terminalId, String ip, int port) {
|
||||||
|
Assert.notEmpty(terminalId);
|
||||||
|
Assert.notEmpty(ip);
|
||||||
|
Assert.isTrue(port > 0);
|
||||||
|
JT808.sendTxtMessage(terminalId, StrUtil.format("<SPBSJ*P:BSJGPS*T:{},{}*N:{}>", ip, port, terminalId));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前位置
|
* 获取当前位置
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import com.njzscloud.common.core.utils.R;
|
||||||
import com.njzscloud.common.mp.support.PageParam;
|
import com.njzscloud.common.mp.support.PageParam;
|
||||||
import com.njzscloud.common.mp.support.PageResult;
|
import com.njzscloud.common.mp.support.PageResult;
|
||||||
import com.njzscloud.supervisory.device.pojo.entity.DeviceLocalizerEntity;
|
import com.njzscloud.supervisory.device.pojo.entity.DeviceLocalizerEntity;
|
||||||
|
import com.njzscloud.supervisory.device.pojo.entity.LocalizerConfig;
|
||||||
import com.njzscloud.supervisory.device.service.DeviceLocalizerService;
|
import com.njzscloud.supervisory.device.service.DeviceLocalizerService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -65,4 +66,14 @@ public class DeviceLocalizerController {
|
||||||
return R.success(deviceLocalizerService.paging(pageParam, deviceLocalizerEntity));
|
return R.success(deviceLocalizerService.paging(pageParam, deviceLocalizerEntity));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改设备配置
|
||||||
|
*/
|
||||||
|
@PostMapping("/modify_config")
|
||||||
|
public R<?> modifyConfig(@RequestBody LocalizerConfig config,
|
||||||
|
@RequestParam Long id
|
||||||
|
) {
|
||||||
|
deviceLocalizerService.modifyConfig(id, config);
|
||||||
|
return R.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.njzscloud.supervisory.device.pojo.entity;
|
package com.njzscloud.supervisory.device.pojo.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import com.njzscloud.common.mp.support.handler.j.JsonTypeHandler;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
@ -39,6 +40,9 @@ public class DeviceLocalizerEntity {
|
||||||
*/
|
*/
|
||||||
private LocalDateTime lastTime;
|
private LocalDateTime lastTime;
|
||||||
|
|
||||||
|
@TableField(typeHandler = JsonTypeHandler.class)
|
||||||
|
private LocalizerConfig config;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建人 Id; sys_user.id
|
* 创建人 Id; sys_user.id
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
package com.njzscloud.supervisory.device.pojo.entity;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class LocalizerConfig {
|
||||||
|
private String ip;
|
||||||
|
private Integer port;
|
||||||
|
private Integer speedThreshold;
|
||||||
|
private Boolean enableWarn;
|
||||||
|
}
|
||||||
|
|
@ -1,8 +1,14 @@
|
||||||
package com.njzscloud.supervisory.device.service;
|
package com.njzscloud.supervisory.device.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.lang.Assert;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.njzscloud.common.core.ex.Exceptions;
|
||||||
|
import com.njzscloud.common.localizer.mqtt.param.ConfigIpPortParam;
|
||||||
|
import com.njzscloud.common.localizer.mqtt.param.EnableWarnParam;
|
||||||
|
import com.njzscloud.common.localizer.mqtt.param.SpeedThresholdParam;
|
||||||
import com.njzscloud.common.mp.support.PageParam;
|
import com.njzscloud.common.mp.support.PageParam;
|
||||||
import com.njzscloud.common.mp.support.PageResult;
|
import com.njzscloud.common.mp.support.PageResult;
|
||||||
import com.njzscloud.common.mqtt.support.MqttMsg;
|
import com.njzscloud.common.mqtt.support.MqttMsg;
|
||||||
|
|
@ -10,6 +16,7 @@ import com.njzscloud.common.mqtt.util.Mqtt;
|
||||||
import com.njzscloud.supervisory.biz.service.TruckLocationTrackService;
|
import com.njzscloud.supervisory.biz.service.TruckLocationTrackService;
|
||||||
import com.njzscloud.supervisory.device.mapper.DeviceLocalizerMapper;
|
import com.njzscloud.supervisory.device.mapper.DeviceLocalizerMapper;
|
||||||
import com.njzscloud.supervisory.device.pojo.entity.DeviceLocalizerEntity;
|
import com.njzscloud.supervisory.device.pojo.entity.DeviceLocalizerEntity;
|
||||||
|
import com.njzscloud.supervisory.device.pojo.entity.LocalizerConfig;
|
||||||
import com.njzscloud.supervisory.device.pojo.result.DeviceInfoResult;
|
import com.njzscloud.supervisory.device.pojo.result.DeviceInfoResult;
|
||||||
import com.njzscloud.supervisory.device.pojo.result.HeartbeatResult;
|
import com.njzscloud.supervisory.device.pojo.result.HeartbeatResult;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
@ -95,4 +102,74 @@ public class DeviceLocalizerService extends ServiceImpl<DeviceLocalizerMapper, D
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void modifyConfig(Long id, LocalizerConfig config) {
|
||||||
|
DeviceLocalizerEntity localizerEntity = this.getById(id);
|
||||||
|
Assert.notNull(localizerEntity, () -> Exceptions.exception("定位器不存在"));
|
||||||
|
|
||||||
|
String terminalId = localizerEntity.getTerminalId();
|
||||||
|
LocalizerConfig oldConfig = localizerEntity.getConfig();
|
||||||
|
if (oldConfig == null) oldConfig = new LocalizerConfig();
|
||||||
|
String ip = config.getIp();
|
||||||
|
Integer port = config.getPort();
|
||||||
|
Integer speedThreshold = config.getSpeedThreshold();
|
||||||
|
Boolean enableWarn = config.getEnableWarn();
|
||||||
|
|
||||||
|
if (StrUtil.isEmpty(ip) && port != null && port > 0) {
|
||||||
|
oldConfig.setIp(ip).setPort(port);
|
||||||
|
}
|
||||||
|
if (speedThreshold != null && speedThreshold > 0) {
|
||||||
|
oldConfig.setSpeedThreshold(speedThreshold);
|
||||||
|
}
|
||||||
|
if (enableWarn != null) {
|
||||||
|
oldConfig.setEnableWarn(enableWarn);
|
||||||
|
}
|
||||||
|
this.configDevice(terminalId, config);
|
||||||
|
|
||||||
|
this.updateById(new DeviceLocalizerEntity().setId(id).setConfig(oldConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void configDevice(String terminalId, LocalizerConfig config) {
|
||||||
|
String ip = config.getIp();
|
||||||
|
Integer port = config.getPort();
|
||||||
|
Integer speedThreshold = config.getSpeedThreshold();
|
||||||
|
Boolean enableWarn = config.getEnableWarn();
|
||||||
|
|
||||||
|
if (StrUtil.isEmpty(ip) && port != null && port > 0) {
|
||||||
|
modifyIpPort(terminalId, ip, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (speedThreshold != null && speedThreshold > 0) {
|
||||||
|
modifySpeedThreshold(terminalId, speedThreshold);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (enableWarn != null) {
|
||||||
|
enableWarn(terminalId, enableWarn);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void modifyIpPort(String terminalId, String ip, int port) {
|
||||||
|
if (StrUtil.isEmpty(ip) || port <= 0) return;
|
||||||
|
Mqtt.publish("location/config_ip_port", new ConfigIpPortParam()
|
||||||
|
.setTerminalId(terminalId)
|
||||||
|
.setIp(ip)
|
||||||
|
.setPort(port)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void modifySpeedThreshold(String terminalId, int modifySpeedThreshold) {
|
||||||
|
if (modifySpeedThreshold <= 0) return;
|
||||||
|
Mqtt.publish("location/speed_threshold", new SpeedThresholdParam()
|
||||||
|
.setTerminalId(terminalId)
|
||||||
|
.setSpeed(modifySpeedThreshold)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableWarn(String terminalId, boolean enableWarn) {
|
||||||
|
Mqtt.publish("location/speed_threshold", new EnableWarnParam()
|
||||||
|
.setTerminalId(terminalId)
|
||||||
|
.setEnable(enableWarn)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue