#位置信息增加当前设备任务执行情况
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.maibu.enums;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 设备回调状态
|
||||
*
|
||||
* @author bill
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum DeviceStatusEnum {
|
||||
|
||||
offline("0", "离线"),
|
||||
idle("1", "空闲中"),
|
||||
working("2", "工作中"),
|
||||
charging("3", "充电中"),
|
||||
error("4", "故障");
|
||||
|
||||
String code;
|
||||
String message;
|
||||
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import com.maibu.core.host.HostTaskStatusDTO;
|
||||
import com.maibu.core.host.HostVehicleRelTimeDTO;
|
||||
import com.maibu.core.host.LocationMessage;
|
||||
import com.maibu.core.redis.RedisCache;
|
||||
import com.maibu.enums.DeviceStatusEnum;
|
||||
import com.maibu.memory.DeviceSessionManager;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.memory.SiteMemory;
|
||||
@@ -128,7 +129,7 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
log.debug("【位置数据】deviceId={}, payload={}", deviceId, payload);
|
||||
HostLocationRelTimeDTO locationRelTimeDTO = JsonUtils.parseObject(payload, HostLocationRelTimeDTO.class);
|
||||
if (locationRelTimeDTO != null) {
|
||||
WebStatusMessageDTO dto = createWebDeviceLocationMessage(locationRelTimeDTO);
|
||||
WebStatusMessageDTO dto = createWebDeviceLocationMessage(locationRelTimeDTO, deviceId);
|
||||
List<NettyDevice> controlMasters = deviceSessionManager
|
||||
.getAllSlaveControl(deviceId);
|
||||
if (!CollectionUtils.isEmpty(controlMasters)) {
|
||||
@@ -154,11 +155,12 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("位置消息解析失败: deviceId={}, payload={}, error={}", deviceId, payload, e.getMessage());
|
||||
log.error("位置消息解析失败: deviceId={}, payload={}, error={}", deviceId, payload, e);
|
||||
}
|
||||
}
|
||||
|
||||
public WebStatusMessageDTO createWebDeviceLocationMessage(HostLocationRelTimeDTO locationRelTimeDTO) {
|
||||
public WebStatusMessageDTO createWebDeviceLocationMessage(HostLocationRelTimeDTO locationRelTimeDTO,
|
||||
String deviceId) {
|
||||
WebStatusMessageDTO webStatusMessageDTO = new WebStatusMessageDTO();
|
||||
List<DeviceStatusDetail> transferData = new ArrayList<>();
|
||||
DeviceStatusDetail lat = new DeviceStatusDetail();
|
||||
@@ -192,6 +194,27 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
altitude.setUnit("");
|
||||
transferData.add(altitude);
|
||||
|
||||
DeviceStatusDetail status = new DeviceStatusDetail();
|
||||
status.setName("status");
|
||||
|
||||
NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
||||
// todo error故障
|
||||
if (nettyDevice != null) {
|
||||
if (nettyDevice.getOnlineStatus() == 0) {
|
||||
status.setValue(DeviceStatusEnum.offline.getCode());
|
||||
} else {
|
||||
if (nettyDevice.getTask() != null && nettyDevice.getTask().isTaskAccepted()) {
|
||||
status.setValue(DeviceStatusEnum.working.getCode());
|
||||
} else {
|
||||
status.setValue(DeviceStatusEnum.idle.getCode());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
status.setValue(DeviceStatusEnum.offline.getCode());
|
||||
}
|
||||
status.setUnit("");
|
||||
transferData.add(status);
|
||||
|
||||
webStatusMessageDTO.setData(transferData);
|
||||
webStatusMessageDTO.setType(MesType.locationInfo);
|
||||
return webStatusMessageDTO;
|
||||
@@ -440,7 +463,6 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onConnectionLost(String deviceKey, Throwable cause) {
|
||||
log.warn("主机监控连接断开: deviceKey={}, reason={}", deviceKey, cause.getMessage());
|
||||
|
||||
@@ -272,6 +272,14 @@ public class DeviceController extends BaseController {
|
||||
return getDataTable(deviceService.getSiteList(getLoginUser(), device));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备列表 分配页面
|
||||
*/
|
||||
@GetMapping("/getDeviceBySpiltCode")
|
||||
public AjaxResult getDeviceBySpiltCode(@RequestParam String code) {
|
||||
return AjaxResult.success(deviceService.getDeviceBySpiltCode(code));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备列表 分配页面
|
||||
*/
|
||||
|
||||
@@ -152,8 +152,10 @@ public class HostComputerController extends BaseController {
|
||||
try {
|
||||
WebRouteStatusMessageDTO dto = new WebRouteStatusMessageDTO();
|
||||
String deviceId = deviceSessionManager.getDeviceByTaskId(taskId);
|
||||
log.debug("sendMessage: taskId={}, deviceId={}", taskId, deviceId);
|
||||
List<NettyDevice> controlMasters = deviceSessionManager
|
||||
.getAllSlaveControl(deviceId);
|
||||
log.debug("sendMessage: controlMasters={}", JsonUtils.toJsonString(controlMasters));
|
||||
dto.setData(data);
|
||||
dto.setDeviceId(deviceId);
|
||||
dto.setTaskId(taskId);
|
||||
@@ -162,9 +164,9 @@ public class HostComputerController extends BaseController {
|
||||
for (NettyDevice x : controlMasters) {
|
||||
try {
|
||||
websocketMesDispather.dispather(x.getConnectorId(), JsonUtils.toJsonString(dto));
|
||||
log.info("位置数据websocket推送成功: connectorId={}, taskId={}", x.getConnectorId(), taskId);
|
||||
log.info("sendMessage推送成功: connectorId={}, taskId={}", x.getConnectorId(), taskId);
|
||||
} catch (Exception e) {
|
||||
log.error("位置数据websocket推送失败: connectorId={}, error={}", x.getConnectorId(),
|
||||
log.error("sendMessage推送失败: connectorId={}, error={}", x.getConnectorId(),
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.List;
|
||||
@Repository
|
||||
public interface DeviceMapper extends BaseMapperX<Device> {
|
||||
|
||||
|
||||
/**
|
||||
* 根据设备编号查询设备
|
||||
*
|
||||
@@ -25,7 +24,6 @@ public interface DeviceMapper extends BaseMapperX<Device> {
|
||||
*/
|
||||
public Device selectDeviceBySerialNumber(String serialNumber);
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
*
|
||||
@@ -34,7 +32,6 @@ public interface DeviceMapper extends BaseMapperX<Device> {
|
||||
*/
|
||||
public List<Device> selectDeviceList(Device device);
|
||||
|
||||
|
||||
/**
|
||||
* 根据产品ID查询产品下所有设备的编号
|
||||
*
|
||||
@@ -66,7 +63,6 @@ public interface DeviceMapper extends BaseMapperX<Device> {
|
||||
*/
|
||||
public int updateDevice(Device device);
|
||||
|
||||
|
||||
/**
|
||||
* 重置设备状态
|
||||
*
|
||||
@@ -74,7 +70,6 @@ public interface DeviceMapper extends BaseMapperX<Device> {
|
||||
*/
|
||||
public int resetDeviceStatus(String deviceNum);
|
||||
|
||||
|
||||
/**
|
||||
* 根据产品ID获取产品下所有编号
|
||||
*
|
||||
@@ -91,4 +86,6 @@ public interface DeviceMapper extends BaseMapperX<Device> {
|
||||
*/
|
||||
public List<String> selectSerialNumbersByProductId(@Param("productId") Long productId);
|
||||
|
||||
public Device selectDeviceBySpiltCode(@Param("code") String code);
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,8 @@ import java.util.List;
|
||||
*/
|
||||
public interface IDeviceService {
|
||||
|
||||
|
||||
public AjaxResult updateDeviceBySelf(Device device);
|
||||
|
||||
|
||||
public Device insertDeviceBySelf(Device device);
|
||||
|
||||
/**
|
||||
@@ -30,7 +28,6 @@ public interface IDeviceService {
|
||||
*/
|
||||
public Device selectDeviceBySerialNumber(String serialNumber);
|
||||
|
||||
|
||||
/**
|
||||
* 查询设备列表
|
||||
*
|
||||
@@ -39,7 +36,6 @@ public interface IDeviceService {
|
||||
*/
|
||||
public List<Device> selectDeviceList(Device device);
|
||||
|
||||
|
||||
/**
|
||||
* 根据产品ID查询产品下所有设备的编号
|
||||
*
|
||||
@@ -55,7 +51,6 @@ public interface IDeviceService {
|
||||
*/
|
||||
public int selectDeviceCountByProductId(Long productId);
|
||||
|
||||
|
||||
/**
|
||||
* 重置设备状态
|
||||
*
|
||||
@@ -63,7 +58,6 @@ public interface IDeviceService {
|
||||
*/
|
||||
public int resetDeviceStatus(String deviceNum);
|
||||
|
||||
|
||||
/**
|
||||
* 根据产品ID获取产品下所有编号
|
||||
*
|
||||
@@ -72,7 +66,6 @@ public interface IDeviceService {
|
||||
*/
|
||||
public String[] getDeviceNumsByProductId(Long productId);
|
||||
|
||||
|
||||
/**
|
||||
* 查询产品下所有设备,返回设备编号
|
||||
*
|
||||
@@ -81,17 +74,16 @@ public interface IDeviceService {
|
||||
*/
|
||||
public List<String> selectSerialNumbersByProductId(Long productId);
|
||||
|
||||
|
||||
public boolean bind(DeviceBindDTO bindDTO, String username);
|
||||
|
||||
|
||||
public boolean unbind(DeviceBindDTO bindDTO, String username);
|
||||
|
||||
|
||||
public List<Device> getSiteList(LoginUser loginUser, Device device);
|
||||
|
||||
public List<Device> getDeviceList(LoginUser loginUser, Device device);
|
||||
|
||||
public Device getDeviceBySpiltCode(String code);
|
||||
|
||||
public boolean paramModifyAuth(DeviceParamAuthDTO dto);
|
||||
|
||||
public boolean hasPermission(String deviceId);
|
||||
|
||||
@@ -440,4 +440,9 @@ public class DeviceServiceImpl implements IDeviceService {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Device getDeviceBySpiltCode(String code) {
|
||||
return deviceMapper.selectDeviceBySpiltCode(code);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -504,4 +504,9 @@
|
||||
#{deviceId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<select id="selectDeviceBySpiltCode" parameterType="String" resultMap="DeviceResult">
|
||||
<include refid="selectDeviceVo"/>
|
||||
where device_name like concat('%', #{code}, '%')
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user