#更新计算累计路程相关
This commit is contained in:
@@ -1,17 +1,17 @@
|
||||
package com.maibu.core.business;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.maibu.core.domain.BaseDO;
|
||||
import com.maibu.core.domain.OrgBaseDO;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@TableName("iot_device_task")
|
||||
|
||||
@@ -20,6 +20,8 @@ public class DeviceTaskCommandDTO {
|
||||
|
||||
private Long taskId;
|
||||
|
||||
private Long regionId;
|
||||
|
||||
private boolean forceCancel = false; //强制取消 不等回复
|
||||
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.maibu.dto;
|
||||
package com.maibu.core.business.dto;
|
||||
|
||||
import com.maibu.core.business.path.LatAndLngEntity;
|
||||
import com.maibu.core.enums.MesType;
|
||||
@@ -1,14 +1,15 @@
|
||||
package com.maibu.core.domain.entity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.maibu.core.domain.BaseDO;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@TableName(value = "sys_region")
|
||||
@@ -29,4 +30,6 @@ public class SysRegion extends BaseDO {
|
||||
|
||||
private Integer status;
|
||||
|
||||
private Long bindRoute;// 绑定的线路id
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
package com.maibu.core.host;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class VehicleMessage {
|
||||
|
||||
private double speed;
|
||||
private double battery_percentage;//电量
|
||||
private double battery_voltage;//电压
|
||||
private String motion;//moving|stopped|blocked
|
||||
private boolean emergency_stop; //急停状态
|
||||
private double battery_percentage;// 电量
|
||||
private double battery_voltage;// 电压
|
||||
private String motion;// moving|stopped|blocked
|
||||
private boolean emergency_stop; // 急停状态
|
||||
|
||||
private double distance; // 里程数
|
||||
|
||||
}
|
||||
|
||||
@@ -53,6 +53,28 @@ public class SiteMemory {
|
||||
// key deviceId execute
|
||||
public static ConcurrentHashMap<String, DevicePlanTask> devicePlanTaskExecuteMap = new ConcurrentHashMap<>();
|
||||
|
||||
// 记录 设备上线后的运行数据 下线后清除并保存到数据库
|
||||
public static ConcurrentHashMap<String, DeviceRunStatistics> deviceRunStatisticsMap = new ConcurrentHashMap<>();
|
||||
|
||||
public void saveRunStatistics(DeviceRunStatistics deviceRunStatistics) {
|
||||
if (deviceRunStatistics != null && !StringUtils.isEmpty(deviceRunStatistics.getDeviceId())) {
|
||||
deviceRunStatisticsMap.put(deviceRunStatistics.getDeviceId(), deviceRunStatistics);
|
||||
}
|
||||
}
|
||||
|
||||
public DeviceRunStatistics getRunStatistics(String deviceId) {
|
||||
if (!StringUtils.isEmpty(deviceId)) {
|
||||
return deviceRunStatisticsMap.get(deviceId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeRunStatistics(String deviceId) {
|
||||
if (!StringUtils.isEmpty(deviceId)) {
|
||||
deviceRunStatisticsMap.remove(deviceId);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveDevice(Device device) {
|
||||
deviceMap.put(device.getSerialNumber(), device);
|
||||
}
|
||||
@@ -135,7 +157,6 @@ public class SiteMemory {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void saveDeviceRunParam(DeviceRunParam deviceRunParam) {
|
||||
deviceRunParamMap.put(deviceRunParam.getDeviceId(), deviceRunParam);
|
||||
}
|
||||
|
||||
@@ -1,27 +1,37 @@
|
||||
package com.maibu.mqtt;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.maibu.constant.Constant;
|
||||
import com.maibu.constant.NettyCacheKey;
|
||||
import com.maibu.core.business.DeviceRunStatistics;
|
||||
import com.maibu.core.business.device.DeviceStatusDetail;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.business.dto.WebDeviceTaskStatusMessageDTO;
|
||||
import com.maibu.core.business.dto.WebStatusMessageDTO;
|
||||
import com.maibu.core.business.inter.WebsocketMesDispather;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
import com.maibu.core.enums.MesType;
|
||||
import com.maibu.core.host.*;
|
||||
import com.maibu.core.host.HeartBeatDTO;
|
||||
import com.maibu.core.host.HostLocationRelTimeDTO;
|
||||
import com.maibu.core.host.HostNavigationReplyDTO;
|
||||
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.memory.DeviceSessionManager;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
import com.maibu.memory.SiteMemory;
|
||||
import com.maibu.utils.StringUtils;
|
||||
import com.maibu.utils.json.JsonUtils;
|
||||
import com.maibu.utils.spring.SpringUtils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* mqtt相关的 上位机处理器
|
||||
@@ -230,6 +240,26 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
try {
|
||||
HostVehicleRelTimeDTO vehicleRelTimeDTO = JsonUtils.parseObject(payload, HostVehicleRelTimeDTO.class);
|
||||
if (vehicleRelTimeDTO != null) {
|
||||
|
||||
// todo 更新里程数 里程数 * 割幅0.8
|
||||
vehicleRelTimeDTO.getData().getDistance();
|
||||
NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
||||
if (nettyDevice != null) {
|
||||
Long orgId = nettyDevice.getDevice().getOrgId();
|
||||
Long siteId = nettyDevice.getDevice().getSiteId();
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if (siteMemory != null) {
|
||||
DeviceRunStatistics deviceRunStatistics = siteMemory.getRunStatistics(deviceId);
|
||||
if (deviceRunStatistics == null) {
|
||||
deviceRunStatistics = new DeviceRunStatistics();
|
||||
}
|
||||
deviceRunStatistics.setDeviceId(deviceId);
|
||||
deviceRunStatistics.setDistance(vehicleRelTimeDTO.getData().getDistance());
|
||||
deviceRunStatistics.setWorkArea(vehicleRelTimeDTO.getData().getDistance() * 0.8);
|
||||
siteMemory.saveRunStatistics(deviceRunStatistics);
|
||||
}
|
||||
}
|
||||
|
||||
WebStatusMessageDTO dto = createWebDeviceRealtimeMessage(vehicleRelTimeDTO);
|
||||
List<NettyDevice> controlMasters = deviceSessionManager
|
||||
.getAllSlaveControl(deviceId);
|
||||
@@ -243,10 +273,6 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
}
|
||||
}
|
||||
}
|
||||
// GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||
// String.format(MqttTopic.DEVICE_STATUS_TOPIC, deviceId),
|
||||
// JsonUtils.toJsonString(dto));
|
||||
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("实时消息解析失败: deviceId={}, payload={}, error={}", deviceId, payload, e.getMessage());
|
||||
@@ -285,7 +311,27 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
if (dto != null && !StringUtils.isEmpty(dto.getStatus())) {
|
||||
NettyDevice nettyDevice = deviceSessionManager.getDevice(deviceId);
|
||||
if ("completed".equals(dto.getStatus())) {
|
||||
nettyDevice.finishTask();
|
||||
Long taskId = nettyDevice.finishTask();
|
||||
|
||||
WebDeviceTaskStatusMessageDTO sendDto = new WebDeviceTaskStatusMessageDTO();
|
||||
sendDto.setDeviceId(deviceId);
|
||||
sendDto.setTaskId(taskId);
|
||||
sendDto.setStatus(DeviceTaskStaus.FINISH.toString());
|
||||
sendDto.setType(MesType.device_task_change);
|
||||
|
||||
List<NettyDevice> controlMasters = deviceSessionManager
|
||||
.getAllSlaveControl(deviceId);
|
||||
if (!CollectionUtils.isEmpty(controlMasters)) {
|
||||
for (NettyDevice x : controlMasters) {
|
||||
try {
|
||||
websocketMesDispather.dispather(x.getConnectorId(), JsonUtils.toJsonString(sendDto));
|
||||
} catch (Exception e) {
|
||||
log.error("实时数据websocket推送失败: connectorId={}, error={}", x.getConnectorId(),
|
||||
e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if ("cancelled".equals(dto.getStatus())) {
|
||||
nettyDevice.canceledTask();
|
||||
@@ -394,60 +440,6 @@ public class HostMessageHandler implements CustomMqttMessageHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
private double getDouble(JsonNode node, String... names) {
|
||||
for (String name : names) {
|
||||
JsonNode fn = node.get(name);
|
||||
if (fn != null && !fn.isNull()) {
|
||||
if (fn.isNumber())
|
||||
return fn.asDouble();
|
||||
try {
|
||||
return Double.parseDouble(fn.asText());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1.0;
|
||||
}
|
||||
|
||||
private Double getDoubleObj(JsonNode node, String... names) {
|
||||
for (String name : names) {
|
||||
JsonNode fn = node.get(name);
|
||||
if (fn != null && !fn.isNull()) {
|
||||
if (fn.isNumber())
|
||||
return fn.asDouble();
|
||||
try {
|
||||
return Double.parseDouble(fn.asText());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private int getInt(JsonNode node, String... names) {
|
||||
for (String name : names) {
|
||||
JsonNode fn = node.get(name);
|
||||
if (fn != null && !fn.isNull()) {
|
||||
if (fn.isNumber())
|
||||
return fn.asInt();
|
||||
try {
|
||||
return Integer.parseInt(fn.asText());
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private String getString(JsonNode node, String... names) {
|
||||
for (String name : names) {
|
||||
JsonNode fn = node.get(name);
|
||||
if (fn != null && !fn.isNull()) {
|
||||
return fn.asText();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectionLost(String deviceKey, Throwable cause) {
|
||||
|
||||
@@ -46,10 +46,10 @@ public class DeviceTaskController extends BaseController {
|
||||
|
||||
@GetMapping("/getSiteDevicePlan")
|
||||
public AjaxResult getSiteDevicePlan(@RequestParam Long siteId,
|
||||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startTime,
|
||||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime,
|
||||
@RequestParam(required = false) String deviceId,
|
||||
@RequestParam(required = false) DeviceTaskStaus taskStaus) {
|
||||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startTime,
|
||||
@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endTime,
|
||||
@RequestParam(required = false) String deviceId,
|
||||
@RequestParam(required = false) DeviceTaskStaus taskStaus) {
|
||||
return AjaxResult.success(deviceTaskService.getSiteDevicePlan(siteId, startTime, endTime, deviceId, taskStaus));
|
||||
}
|
||||
|
||||
@@ -86,7 +86,6 @@ public class DeviceTaskController extends BaseController {
|
||||
return AjaxResult.success(deviceTaskService.concurrentDevicePlanTask(deviceId));
|
||||
}
|
||||
|
||||
|
||||
@GetMapping("/workStatistics")
|
||||
public AjaxResult workStatistics(@RequestParam Long userId) {
|
||||
return AjaxResult.success(deviceTaskService.workStatistics(userId));
|
||||
@@ -94,13 +93,13 @@ public class DeviceTaskController extends BaseController {
|
||||
|
||||
@PostMapping("/deviceTaskPool")
|
||||
public TableDataInfo deviceTaskPool(@RequestBody DeviceTaskQueryDTO dto) {
|
||||
startPostPage(dto.getPageNum(),dto.getPageSize());
|
||||
startPostPage(dto.getPageNum(), dto.getPageSize());
|
||||
return getDataTable(deviceTaskService.deviceTaskPool(dto));
|
||||
}
|
||||
|
||||
@PostMapping("/getSiteDeviceTaskHistory")
|
||||
public TableDataInfo getSiteDeviceTaskHistory(@RequestBody DeviceTaskQueryDTO dto) {
|
||||
startPostPage(dto.getPageNum(),dto.getPageSize());
|
||||
startPostPage(dto.getPageNum(), dto.getPageSize());
|
||||
return getDataTable(deviceTaskService.getSiteDeviceTaskHistory(dto));
|
||||
}
|
||||
|
||||
@@ -125,6 +124,31 @@ public class DeviceTaskController extends BaseController {
|
||||
return AjaxResult.success(deviceTaskService.createDeviceTask(dto, getLoginUser().getUsername()));
|
||||
}
|
||||
|
||||
@PostMapping("/createRegionDeviceTask")
|
||||
public AjaxResult createRegionDeviceTask(@RequestBody DeviceTaskCommandDTO dto) {
|
||||
String deviceId = dto.getDeviceId();
|
||||
Long siteId = dto.getSiteId();
|
||||
Long orgId = dto.getOrgId();
|
||||
Long regionId = dto.getRegionId();
|
||||
if (StringUtils.isEmpty(deviceId)) {
|
||||
return AjaxResult.error("deviceId为空!");
|
||||
}
|
||||
if (siteId == null) {
|
||||
return AjaxResult.error("siteId为空!");
|
||||
}
|
||||
if (orgId == null) {
|
||||
return AjaxResult.error("orgId为空!");
|
||||
}
|
||||
if (regionId == null) {
|
||||
return AjaxResult.error("regionId为空!");
|
||||
}
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if (siteMemory.hasTask(deviceId)) {
|
||||
return AjaxResult.error("当前设备存在任务!");
|
||||
}
|
||||
return AjaxResult.success(deviceTaskService.createRegionDeviceTask(dto, getLoginUser().getUsername()));
|
||||
}
|
||||
|
||||
@PostMapping("/cancelTask")
|
||||
public AjaxResult cancelTask(@RequestBody DeviceTaskCommandDTO dto) throws MqttException {
|
||||
String deviceId = dto.getDeviceId();
|
||||
@@ -152,5 +176,4 @@ public class DeviceTaskController extends BaseController {
|
||||
return AjaxResult.success(deviceTaskService.recoveryTask(dto, getUsername()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ public class DataToDataBaseHandler extends SimpleChannelInboundHandler<String> {
|
||||
@Autowired
|
||||
private DeviceRunParamMapper deviceRunParamMapper;
|
||||
|
||||
|
||||
@Value("${mqtt.client-id}")
|
||||
private String mqttClientId;
|
||||
|
||||
@@ -99,8 +98,9 @@ public class DataToDataBaseHandler extends SimpleChannelInboundHandler<String> {
|
||||
String deviceStatus = new String(bytes, 2, bytes.length - 4, StandardCharsets.UTF_8).trim();
|
||||
String[] split = deviceStatus.split(",");
|
||||
WebStatusMessageDTO dto = createWebDeviceStatusMessage(split);
|
||||
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId, String.format(MqttTopic.DEVICE_STATUS_TOPIC, deviceID),
|
||||
JsonUtils.toJsonString(dto));
|
||||
GlobalMemory.customMqttDeviceMonitor.publish(mqttClientId,
|
||||
String.format(MqttTopic.DEVICE_STATUS_TOPIC, deviceID),
|
||||
JsonUtils.toJsonString(dto));
|
||||
List<NettyDevice> controlMasters = deviceSessionManager
|
||||
.getAllSlaveControl(deviceID);
|
||||
if (!CollectionUtils.isEmpty(controlMasters)) {
|
||||
@@ -134,19 +134,15 @@ public class DataToDataBaseHandler extends SimpleChannelInboundHandler<String> {
|
||||
latestStatus.setDeviceId(deviceID);
|
||||
} else {
|
||||
latestStatus = nettyDevice.getLatestStatus();
|
||||
// 使用Duration.between计算两个时间点之间的持续时间
|
||||
Duration duration = Duration.between(latestStatus.getStartTime(), LocalDateTime.now());
|
||||
long minutes = duration.toMinutes();
|
||||
latestStatus.setTime(minutes);
|
||||
}
|
||||
latestStatus.setWorkArea(Double.valueOf(workArea));
|
||||
latestStatus.setDistance(Double.valueOf(workArea) / 0.8);
|
||||
nettyDevice.setLatestStatus(latestStatus);
|
||||
}
|
||||
} else if (bytes[2] == CommandConstant.readConfig) {
|
||||
DeviceRunParam runParam = DeviceRunParam.fromBytes(bytes);
|
||||
logger.debug("收到返回的设备运行参数: {}", JsonUtils.toJsonString(runParam));
|
||||
CompletableFuture<DeviceRunParam> future =
|
||||
ctx.channel().attr(Constant.READ_CONFIG_KEY).get();
|
||||
CompletableFuture<DeviceRunParam> future = ctx.channel().attr(Constant.READ_CONFIG_KEY).get();
|
||||
if (future != null) {
|
||||
future.complete(runParam);
|
||||
ctx.channel().attr(Constant.READ_CONFIG_KEY).set(null);
|
||||
@@ -158,7 +154,6 @@ public class DataToDataBaseHandler extends SimpleChannelInboundHandler<String> {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public WebStatusMessageDTO createWebDeviceStatusMessage(String[] split) {
|
||||
WebStatusMessageDTO webStatusMessageDTO = new WebStatusMessageDTO();
|
||||
List<DeviceStatusDetail> transferData = transferStatusData(split);
|
||||
|
||||
@@ -18,9 +18,11 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.maibu.constant.CommandConstant;
|
||||
import com.maibu.constant.Constant;
|
||||
import com.maibu.core.business.Device;
|
||||
import com.maibu.core.business.DeviceRunStatistics;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.business.inter.WebsocketMesDispather;
|
||||
import com.maibu.core.enums.CommandRequestType;
|
||||
@@ -143,8 +145,24 @@ public class DeviceConnectHandler extends SimpleChannelInboundHandler<String> {
|
||||
// todo 更新历史作业消息
|
||||
}
|
||||
if (nettyDevice.getLatestStatus() != null) {
|
||||
nettyDevice.getLatestStatus().setEndTime(LocalDateTime.now());
|
||||
deviceRunStatisticsMapper.insert(nettyDevice.getLatestStatus());
|
||||
|
||||
LambdaQueryWrapper<DeviceRunStatistics> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DeviceRunStatistics::getDeviceId, deviceId);
|
||||
DeviceRunStatistics existing = deviceRunStatisticsMapper
|
||||
.selectOne(queryWrapper);
|
||||
if (existing != null) {
|
||||
nettyDevice.getLatestStatus().setId(existing.getId());
|
||||
nettyDevice.getLatestStatus().setDistance(
|
||||
existing.getDistance() + nettyDevice.getLatestStatus().getDistance());
|
||||
nettyDevice.getLatestStatus().setWorkArea(
|
||||
existing.getWorkArea() + nettyDevice.getLatestStatus().getWorkArea());
|
||||
long time = System.currentTimeMillis() - nettyDevice.getLatestLoginTime();
|
||||
nettyDevice.getLatestStatus().setTime(existing.getTime() + time / (1000 * 60)); // 累加时长,单位为分钟
|
||||
} else {
|
||||
long time = System.currentTimeMillis() - nettyDevice.getLatestLoginTime();
|
||||
nettyDevice.getLatestStatus().setTime(time / (1000 * 60)); // 累加时长,单位为分钟
|
||||
}
|
||||
deviceRunStatisticsMapper.saveOrUpdate(nettyDevice.getLatestStatus());
|
||||
}
|
||||
}
|
||||
sessionManager.removeDevice(deviceId);
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.maibu.core.business.DeviceTaskPlanRule;
|
||||
import com.maibu.core.business.WorkRecord;
|
||||
import com.maibu.core.business.device.NettyDevice;
|
||||
import com.maibu.core.business.dto.DeviceTaskCommandDTO;
|
||||
import com.maibu.core.domain.entity.SysRegion;
|
||||
import com.maibu.core.domain.entity.SysSite;
|
||||
import com.maibu.core.domain.model.LoginUser;
|
||||
import com.maibu.core.enums.DeviceTaskStaus;
|
||||
@@ -34,6 +35,7 @@ import com.maibu.dto.DeviceWorkStatisticsDTO;
|
||||
import com.maibu.mapper.DeviceMapper;
|
||||
import com.maibu.mapper.DevicePlanMapper;
|
||||
import com.maibu.mapper.DevicePlanTaskMapper;
|
||||
import com.maibu.mapper.SysRegionMapper;
|
||||
import com.maibu.mapper.SysSiteMapper;
|
||||
import com.maibu.mapper.WorkRecordMapper;
|
||||
import com.maibu.memory.GlobalMemory;
|
||||
@@ -63,6 +65,9 @@ public class DeviceTaskService {
|
||||
@Autowired
|
||||
private SysSiteMapper sysSiteMapper;
|
||||
|
||||
@Autowired
|
||||
private SysRegionMapper sysRegionMapper;
|
||||
|
||||
public int insertOrUpdate(DevicePlan devicePlan, LoginUser loginUser) {
|
||||
Long id = devicePlan.getId();
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(devicePlan.getOrgId(), devicePlan.getSiteId());
|
||||
@@ -477,6 +482,35 @@ public class DeviceTaskService {
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
public Long createRegionDeviceTask(DeviceTaskCommandDTO dto, String username) {
|
||||
LambdaQueryWrapper<SysRegion> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(SysRegion::getId, dto.getRegionId());
|
||||
SysRegion region = sysRegionMapper.selectOne(queryWrapper);
|
||||
|
||||
if (region == null || region.getBindRoute() == null) {
|
||||
throw new RuntimeException("区域未绑定线路!");
|
||||
}
|
||||
DevicePlanTask task = new DevicePlanTask();
|
||||
task.setRouteId(region.getBindRoute());
|
||||
task.setOrgId(dto.getOrgId());
|
||||
task.setSiteId(dto.getSiteId());
|
||||
task.setTaskStaus(DeviceTaskStaus.NEW);
|
||||
task.setDeviceId(dto.getDeviceId());
|
||||
task.setCreateBy(username);
|
||||
task.setCreateTime(LocalDateTime.now());
|
||||
task.setStartTime(dto.getStartTime());
|
||||
devicePlanTaskMapper.saveOrUpdate(task);
|
||||
if (dto.getOrgId() == null) {
|
||||
SysSite site = sysSiteMapper.selectById(dto.getSiteId());
|
||||
if (site != null) {
|
||||
dto.setOrgId(site.getOrgId());
|
||||
}
|
||||
}
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(task.getOrgId(), task.getSiteId());
|
||||
siteMemory.addDevicePlanPrepare(task);
|
||||
return task.getId();
|
||||
}
|
||||
|
||||
public boolean cancelTask(DeviceTaskCommandDTO dto) throws MqttException {
|
||||
String deviceId = dto.getDeviceId();
|
||||
DevicePlanTask devicePlanTask = null;
|
||||
@@ -489,9 +523,9 @@ public class DeviceTaskService {
|
||||
}
|
||||
NettyDevice device = deviceSessionManager.getDevice(deviceId);
|
||||
if (device != null && device.getTask() != null) {
|
||||
if(dto.isForceCancel()){
|
||||
if (dto.isForceCancel()) {
|
||||
return device.canceledTask();
|
||||
}else {
|
||||
} else {
|
||||
return device.cancelingTask();
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -15,6 +15,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.checkerframework.checker.units.qual.s;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.Resource;
|
||||
@@ -27,6 +28,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.maibu.constant.Constant;
|
||||
import com.maibu.constant.NettyCacheKey;
|
||||
import com.maibu.core.business.Device;
|
||||
import com.maibu.core.business.DeviceRunStatistics;
|
||||
import com.maibu.core.business.DeviceRunningStatusHistory;
|
||||
import com.maibu.core.business.DeviceStatusRecordDTO;
|
||||
import com.maibu.core.business.ErrorIdentificationStandard;
|
||||
@@ -42,6 +44,7 @@ import com.maibu.core.host.HeartBeatDTO;
|
||||
import com.maibu.core.host.LocationMessage;
|
||||
import com.maibu.core.redis.RedisCache;
|
||||
import com.maibu.dto.DeviceErrorPushDTO;
|
||||
import com.maibu.mapper.DeviceRunStatisticsMapper;
|
||||
import com.maibu.mapper.ErrorIdentificationStandardMapper;
|
||||
import com.maibu.mapper.HostLocationMapper;
|
||||
import com.maibu.memory.DeviceSessionManager;
|
||||
@@ -88,6 +91,9 @@ public class DeviceThreadService {
|
||||
@Autowired
|
||||
private HostLocationMapper hostLocationMapper;
|
||||
|
||||
@Autowired
|
||||
private DeviceRunStatisticsMapper deviceRunStatisticsMapper;
|
||||
|
||||
public void deviceErrorMonitor() throws InterruptedException, IOException {
|
||||
initStandard();
|
||||
|
||||
@@ -305,6 +311,36 @@ public class DeviceThreadService {
|
||||
device.setUpdateTime(LocalDateTime.now());
|
||||
deviceService.updateDeviceBySelf(device);
|
||||
}
|
||||
|
||||
Long orgId = nettyDevice.getDevice().getOrgId();
|
||||
Long siteId = nettyDevice.getDevice().getSiteId();
|
||||
SiteMemory siteMemory = GlobalMemory.getSiteMemory(orgId, siteId);
|
||||
if (siteMemory != null) {
|
||||
DeviceRunStatistics deviceRunStatistics = siteMemory.getRunStatistics(deviceId);
|
||||
if (deviceRunStatistics != null) {
|
||||
LambdaQueryWrapper<DeviceRunStatistics> queryWrapper = new LambdaQueryWrapper<>();
|
||||
queryWrapper.eq(DeviceRunStatistics::getDeviceId, deviceId);
|
||||
DeviceRunStatistics existing = deviceRunStatisticsMapper
|
||||
.selectOne(queryWrapper);
|
||||
if (existing != null) {
|
||||
deviceRunStatistics.setId(existing.getId());
|
||||
deviceRunStatistics.setDistance(
|
||||
existing.getDistance() + deviceRunStatistics.getDistance());
|
||||
deviceRunStatistics.setWorkArea(
|
||||
existing.getWorkArea() + deviceRunStatistics.getWorkArea());
|
||||
long time = System.currentTimeMillis() - nettyDevice.getLatestLoginTime();
|
||||
deviceRunStatistics.setTime(existing.getTime() + time / (1000 * 60)); // 累加时长,单位为分钟
|
||||
} else {
|
||||
long time = System.currentTimeMillis() - nettyDevice.getLatestLoginTime();
|
||||
deviceRunStatistics.setTime(time / (1000 * 60)); // 累加时长,单位为分钟
|
||||
}
|
||||
deviceRunStatisticsMapper.saveOrUpdate(deviceRunStatistics);
|
||||
}
|
||||
}
|
||||
|
||||
sessionManager.removeDevice(deviceId);
|
||||
// TODO 统计总里程、总作业面积
|
||||
|
||||
}
|
||||
} else {
|
||||
if (nettyDevice == null) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.maibu.core.business.dto.WebDeviceTaskStatusMessageDTO;
|
||||
import com.maibu.core.business.dto.WebStatusMessageDTO;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.java_websocket.WebSocket;
|
||||
@@ -23,7 +24,6 @@ import com.maibu.dto.DeviceRespondDTO;
|
||||
import com.maibu.dto.NettySwitchDeviceDTO;
|
||||
import com.maibu.dto.ResultDTO;
|
||||
import com.maibu.dto.WebAuthResponseDTO;
|
||||
import com.maibu.dto.WebDeviceTaskStatusMessageDTO;
|
||||
import com.maibu.dto.WebOlineStatusMessageDTO;
|
||||
import com.maibu.dto.WebSwitchControlResponseDTO;
|
||||
import com.maibu.memory.MiddleGlobalMemory;
|
||||
|
||||
Reference in New Issue
Block a user