#更新计算累计路程相关
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user