任务相关
This commit is contained in:
parent
c5f5136314
commit
4d1c4b56d1
|
@ -106,7 +106,7 @@ public class Scenario extends SearchInputVo {
|
||||||
private String leftBottomLat;
|
private String leftBottomLat;
|
||||||
@TableField(value = "right_bottom_lat")
|
@TableField(value = "right_bottom_lat")
|
||||||
private String rightBottomLat;
|
private String rightBottomLat;
|
||||||
private String desc;
|
private String mark;
|
||||||
/**
|
/**
|
||||||
* 想定关联的资源列表
|
* 想定关联的资源列表
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -83,4 +83,7 @@ public class RoomManager {
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
public static Room getRoom(String id){
|
||||||
|
return roomsMap.get(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,6 +161,10 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
Map<String, Object> dataMap = new HashMap<>();
|
Map<String, Object> dataMap = new HashMap<>();
|
||||||
dataMap.put("resourceId", scenarioTask.getResourceId());
|
dataMap.put("resourceId", scenarioTask.getResourceId());
|
||||||
dataMap.put("points", coordinates);
|
dataMap.put("points", coordinates);
|
||||||
|
|
||||||
|
if(RoomManager.getRoom(roomId)!=null){
|
||||||
|
RoomManager.getRoom(roomId).addResourcePath(this.scenarioTask.getResourceId(),coordinates);
|
||||||
|
}
|
||||||
//推送路径任务
|
//推送路径任务
|
||||||
Global.sendCmdInfoQueue.add(
|
Global.sendCmdInfoQueue.add(
|
||||||
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_INIT.getCode(), roomId,
|
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_INIT.getCode(), roomId,
|
||||||
|
@ -233,7 +237,7 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
endPoint = distanceInfoMap.lastEntry();
|
endPoint = distanceInfoMap.lastEntry();
|
||||||
}
|
}
|
||||||
|
|
||||||
// log.info("enPoint::{}",endPoint);
|
|
||||||
//ws数据
|
//ws数据
|
||||||
List<double[]> dataList = new ArrayList<>();
|
List<double[]> dataList = new ArrayList<>();
|
||||||
HashMap<Object, Object> dataMap = new HashMap<>();
|
HashMap<Object, Object> dataMap = new HashMap<>();
|
||||||
|
@ -293,6 +297,8 @@ public abstract class AbtParentTask implements TaskAction {
|
||||||
if (finishedAction != null) {
|
if (finishedAction != null) {
|
||||||
finishedAction.doSomeThing();
|
finishedAction.doSomeThing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//完成路径
|
//完成路径
|
||||||
Global.sendCmdInfoQueue.add(
|
Global.sendCmdInfoQueue.add(
|
||||||
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_FINISHED.getCode(), roomId,
|
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_FINISHED.getCode(), roomId,
|
||||||
|
|
|
@ -10,7 +10,10 @@ import com.hivekion.common.utils;
|
||||||
import com.hivekion.common.uuid.IdUtils;
|
import com.hivekion.common.uuid.IdUtils;
|
||||||
import com.hivekion.room.func.TaskAction;
|
import com.hivekion.room.func.TaskAction;
|
||||||
import com.hivekion.scenario.bean.ScenarioWsParam;
|
import com.hivekion.scenario.bean.ScenarioWsParam;
|
||||||
|
import com.hivekion.scenario.entity.ScenarioResource;
|
||||||
import com.hivekion.scenario.service.impl.ScenarioResourceServiceImpl;
|
import com.hivekion.scenario.service.impl.ScenarioResourceServiceImpl;
|
||||||
|
import com.hivekion.statistic.bean.EditScenarioInfo;
|
||||||
|
import com.hivekion.statistic.bean.ScenarioInfo;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -26,10 +29,6 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import com.hivekion.scenario.entity.ScenarioResource;
|
|
||||||
import com.hivekion.statistic.bean.EditScenarioInfo;
|
|
||||||
import com.hivekion.statistic.bean.ScenarioInfo;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@ -47,6 +46,10 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
public class Room implements AutoCloseable {
|
public class Room implements AutoCloseable {
|
||||||
|
|
||||||
private AtomicBoolean status = new AtomicBoolean(false);
|
private AtomicBoolean status = new AtomicBoolean(false);
|
||||||
|
//资源最终坐标
|
||||||
|
private Map<String, Coordinate> resourceCoordinateMap = new ConcurrentHashMap<>();
|
||||||
|
//资源路线path
|
||||||
|
private Map<String, Object> resourcePathMap = new ConcurrentHashMap<>();
|
||||||
/**
|
/**
|
||||||
* 任务管理相关
|
* 任务管理相关
|
||||||
*/
|
*/
|
||||||
|
@ -218,24 +221,49 @@ public class Room implements AutoCloseable {
|
||||||
return status.get();
|
return status.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initRoomParam(){
|
public void initRoomParam() {
|
||||||
if( scenarioService == null) {
|
if (scenarioService == null) {
|
||||||
scenarioService = SpringUtil.getBean(com.hivekion.statistic.service.ScenarioService.class);
|
scenarioService = SpringUtil.getBean(com.hivekion.statistic.service.ScenarioService.class);
|
||||||
}
|
}
|
||||||
//设置资源列表
|
//设置资源列表
|
||||||
scenario.setResourceList(SpringUtil.getBean(ScenarioResourceServiceImpl.class).getResourceListByScenarioId(scenario.getId()));
|
scenario.setResourceList(SpringUtil.getBean(ScenarioResourceServiceImpl.class)
|
||||||
for(ScenarioResource scenarioResource:this.scenario.getResourceList() ){
|
.getResourceListByScenarioId(scenario.getId()));
|
||||||
ScenarioInfo scenarioInfo = scenarioService.listScenarioInfo(scenarioResource.getScenarioId(),roomId,scenarioResource.getId());
|
for (ScenarioResource scenarioResource : this.scenario.getResourceList()) {
|
||||||
EditScenarioInfo updScenarioInfo = scenarioService.listEditScenarioInfo(scenarioResource.getScenarioId(),roomId,scenarioResource.getId());
|
ScenarioInfo scenarioInfo = scenarioService.listScenarioInfo(scenarioResource.getScenarioId(),
|
||||||
if( redisUtil == null){
|
roomId, scenarioResource.getId());
|
||||||
|
EditScenarioInfo updScenarioInfo = scenarioService.listEditScenarioInfo(
|
||||||
|
scenarioResource.getScenarioId(), roomId, scenarioResource.getId());
|
||||||
|
if (redisUtil == null) {
|
||||||
redisUtil = SpringUtil.getBean(RedisUtil.class);
|
redisUtil = SpringUtil.getBean(RedisUtil.class);
|
||||||
}
|
}
|
||||||
redisUtil.hset(scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(),"scenarioInfo",JSON.toJSONString(scenarioInfo));
|
redisUtil.hset(
|
||||||
redisUtil.hset(scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(),"updScenarioInfo", JSON.toJSONString(updScenarioInfo));
|
scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(),
|
||||||
|
"scenarioInfo", JSON.toJSONString(scenarioInfo));
|
||||||
|
redisUtil.hset(
|
||||||
|
scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(),
|
||||||
|
"updScenarioInfo", JSON.toJSONString(updScenarioInfo));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addResourcePath(String resourceId, Object obj) {
|
||||||
|
resourcePathMap.put(resourceId, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getResourcePath(String resourceId) {
|
||||||
|
return resourcePathMap.get(resourceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addResourceLastPosition(String resourceId, Coordinate obj) {
|
||||||
|
resourceCoordinateMap.put(resourceId, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordinate getResourceLastPosition(String resourceId) {
|
||||||
|
return resourceCoordinateMap.get(resourceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getPathMap() {
|
||||||
|
return resourcePathMap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
package com.hivekion.scenario.controller;
|
package com.hivekion.scenario.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
||||||
import com.hivekion.common.entity.ResponseData;
|
import com.hivekion.common.entity.ResponseData;
|
||||||
import com.hivekion.common.uuid.IdUtils;
|
import com.hivekion.common.uuid.IdUtils;
|
||||||
|
import com.hivekion.scenario.entity.ScenarioResource;
|
||||||
import com.hivekion.scenario.entity.ScenarioTask;
|
import com.hivekion.scenario.entity.ScenarioTask;
|
||||||
|
import com.hivekion.scenario.service.ScenarioResourceService;
|
||||||
import com.hivekion.scenario.service.ScenarioTaskService;
|
import com.hivekion.scenario.service.ScenarioTaskService;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -28,13 +29,33 @@ public class ScenarioTaskController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ScenarioTaskService scenarioTaskService;
|
private ScenarioTaskService scenarioTaskService;
|
||||||
|
@Resource
|
||||||
|
private ScenarioResourceService scenarioResourceService;
|
||||||
|
|
||||||
@PostMapping("/save")
|
@PostMapping("/save")
|
||||||
public ResponseData<Void> save(@RequestBody ScenarioTask scenarioTask) {
|
public ResponseData<Void> save(@RequestBody ScenarioTask scenarioTask) {
|
||||||
if (scenarioTask.getId() == null) {
|
if (scenarioTask.getId() == null) {
|
||||||
|
|
||||||
|
ScenarioTask queryTask = new ScenarioTask();
|
||||||
|
queryTask.setScenarioId(scenarioTask.getScenarioId());
|
||||||
|
queryTask.setResourceId(scenarioTask.getResourceId());
|
||||||
|
|
||||||
|
List<ScenarioTask> exitTaskList = scenarioTaskService.queryTaskList(queryTask);
|
||||||
|
if (!exitTaskList.isEmpty()) {
|
||||||
|
ScenarioTask lastTask = exitTaskList.get(exitTaskList.size() - 1);
|
||||||
|
scenarioTask.setFromLat(lastTask.getFromLat());
|
||||||
|
scenarioTask.setFromLng(lastTask.getFromLng());
|
||||||
|
} else {
|
||||||
|
ScenarioResource scenarioResource = scenarioResourceService.getById(
|
||||||
|
scenarioTask.getResourceId());
|
||||||
|
scenarioTask.setFromLat(scenarioResource.getLat());
|
||||||
|
scenarioTask.setFromLng(scenarioResource.getLng());
|
||||||
|
}
|
||||||
scenarioTask.setId(IdUtils.simpleUUID());
|
scenarioTask.setId(IdUtils.simpleUUID());
|
||||||
|
|
||||||
scenarioTaskService.save(scenarioTask);
|
scenarioTaskService.save(scenarioTask);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
scenarioTaskService.updateById(scenarioTask);
|
scenarioTaskService.updateById(scenarioTask);
|
||||||
}
|
}
|
||||||
return ResponseData.success(null);
|
return ResponseData.success(null);
|
||||||
|
|
|
@ -19,4 +19,5 @@ public interface ScenarioTaskService extends IService<ScenarioTask> {
|
||||||
void wakeup(Integer id,String roomId);
|
void wakeup(Integer id,String roomId);
|
||||||
|
|
||||||
List<ScenarioTask> queryTaskList(ScenarioTask task);
|
List<ScenarioTask> queryTaskList(ScenarioTask task);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,6 +85,7 @@ public class ScenarioTaskServiceImpl extends
|
||||||
if (StringUtils.isNotBlank(task.getResourceId())) {
|
if (StringUtils.isNotBlank(task.getResourceId())) {
|
||||||
queryWrapper.eq("resource_id", task.getResourceId());
|
queryWrapper.eq("resource_id", task.getResourceId());
|
||||||
}
|
}
|
||||||
|
queryWrapper.orderByAsc("start_time");
|
||||||
return this.list(queryWrapper);
|
return this.list(queryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,10 @@ import cn.hutool.extra.spring.SpringUtil;
|
||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.hivekion.Global;
|
import com.hivekion.Global;
|
||||||
import com.hivekion.common.entity.RequestCmdInfo;
|
import com.hivekion.common.entity.RequestCmdInfo;
|
||||||
import com.hivekion.common.entity.ResponseCmdInfo;
|
import com.hivekion.room.RoomManager;
|
||||||
|
import com.hivekion.room.bean.Room;
|
||||||
import com.hivekion.ws.WsServer;
|
import com.hivekion.ws.WsServer;
|
||||||
|
import java.util.Map;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,14 +25,21 @@ public class HandleReceiveRunnable implements Runnable {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
while (!Thread.currentThread().isInterrupted()) {
|
while (!Thread.currentThread().isInterrupted()) {
|
||||||
try {
|
|
||||||
|
|
||||||
|
try {
|
||||||
RequestCmdInfo requestCmdInfo = Global.receiveCmdInfoQueue.take();
|
RequestCmdInfo requestCmdInfo = Global.receiveCmdInfoQueue.take();
|
||||||
|
|
||||||
//消息分发业务bean处理
|
//消息分发业务bean处理
|
||||||
if(SpringUtil.getBean(WebsocketMsgWrapper.class) != null){
|
if (SpringUtil.getBean(WebsocketMsgWrapper.class) != null) {
|
||||||
WebsocketMsgWrapper websocketMsgWrapper = SpringUtil.getBean(WebsocketMsgWrapper.class);
|
try {
|
||||||
websocketMsgWrapper.msgHandle(requestCmdInfo.getScenarioId(),requestCmdInfo.getRoom(),requestCmdInfo.getResourceId(),requestCmdInfo.getMessage());
|
WebsocketMsgWrapper websocketMsgWrapper = SpringUtil.getBean(WebsocketMsgWrapper.class);
|
||||||
}else{
|
websocketMsgWrapper.msgHandle(requestCmdInfo.getScenarioId(), requestCmdInfo.getRoom(),
|
||||||
|
requestCmdInfo.getResourceId(), requestCmdInfo.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("error::", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
log.warn("==================WebsocketMsgWrapper is null==========================");
|
log.warn("==================WebsocketMsgWrapper is null==========================");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,4 +49,39 @@ public class HandleReceiveRunnable implements Runnable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleMessage(RequestCmdInfo requestCmdInfo) {
|
||||||
|
try {
|
||||||
|
switch (requestCmdInfo.getCmdType()) {
|
||||||
|
case "get_init_path":
|
||||||
|
handleGetInitPath(requestCmdInfo);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("error::", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void handleGetInitPath(RequestCmdInfo requestCmdInfo) {
|
||||||
|
log.info("接收到请求路线信息::{}",JSON.toJSONString(requestCmdInfo));
|
||||||
|
Room room = RoomManager.getRoom(requestCmdInfo.getRoom());
|
||||||
|
if(room!=null){
|
||||||
|
Map<String, Object> pathMap = room.getPathMap();
|
||||||
|
pathMap.forEach((k,v)->{
|
||||||
|
try{
|
||||||
|
WsServer.sendMessage(requestCmdInfo.getScenarioId(),requestCmdInfo.getRoom(),
|
||||||
|
JSON.toJSONString(v));
|
||||||
|
|
||||||
|
}catch (Exception e){
|
||||||
|
log.error("error::",e);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
<select id="List" resultType="com.hivekion.baseData.entity.Scenario" parameterType="com.hivekion.baseData.entity.Scenario" >
|
<select id="List" resultType="com.hivekion.baseData.entity.Scenario" parameterType="com.hivekion.baseData.entity.Scenario" >
|
||||||
SELECT
|
SELECT
|
||||||
@rownum := @rownum + 1 AS seq,
|
@rownum := @rownum + 1 AS seq,
|
||||||
t.Guid,t.Name,t.TestMode,t.Author,t.CreateUserId,t.CreateTime,t.Content,t.id
|
t.Guid,t.Name,t.TestMode,t.Author,t.CreateUserId,t.CreateTime,t.Content,t.id,t.mark
|
||||||
FROM (
|
FROM (
|
||||||
SELECT * FROM tbl_scenario
|
SELECT * FROM tbl_scenario
|
||||||
<where>
|
<where>
|
||||||
|
@ -32,7 +32,7 @@
|
||||||
<select id="List" resultType="com.hivekion.baseData.entity.Scenario" parameterType="com.hivekion.baseData.entity.Scenario" databaseId="dm">
|
<select id="List" resultType="com.hivekion.baseData.entity.Scenario" parameterType="com.hivekion.baseData.entity.Scenario" databaseId="dm">
|
||||||
select
|
select
|
||||||
t.seq,
|
t.seq,
|
||||||
t.Guid,t.Name,t.TestMode,t.Author,t.CreateUserId,t.CreateTime,t.id
|
t.Guid,t.Name,t.TestMode,t.Author,t.CreateUserId,t.CreateTime,t.id,t.mark
|
||||||
FROM (
|
FROM (
|
||||||
SELECT
|
SELECT
|
||||||
ROW_NUMBER() OVER (ORDER BY id ASC) AS seq,
|
ROW_NUMBER() OVER (ORDER BY id ASC) AS seq,
|
||||||
|
@ -73,7 +73,8 @@
|
||||||
left_bottom_lng AS leftBottomLng,
|
left_bottom_lng AS leftBottomLng,
|
||||||
right_bottom_lng AS rightBottomLng,
|
right_bottom_lng AS rightBottomLng,
|
||||||
left_bottom_lat AS leftBottomLat,
|
left_bottom_lat AS leftBottomLat,
|
||||||
right_bottom_lat AS rightBottomLat
|
right_bottom_lat AS rightBottomLat,
|
||||||
|
mark
|
||||||
FROM
|
FROM
|
||||||
tbl_scenario
|
tbl_scenario
|
||||||
WHERE
|
WHERE
|
||||||
|
|
Loading…
Reference in New Issue
Block a user