任务相关
This commit is contained in:
parent
c5f5136314
commit
4d1c4b56d1
|
@ -106,7 +106,7 @@ public class Scenario extends SearchInputVo {
|
|||
private String leftBottomLat;
|
||||
@TableField(value = "right_bottom_lat")
|
||||
private String rightBottomLat;
|
||||
private String desc;
|
||||
private String mark;
|
||||
/**
|
||||
* 想定关联的资源列表
|
||||
*/
|
||||
|
|
|
@ -83,4 +83,7 @@ public class RoomManager {
|
|||
}
|
||||
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<>();
|
||||
dataMap.put("resourceId", scenarioTask.getResourceId());
|
||||
dataMap.put("points", coordinates);
|
||||
|
||||
if(RoomManager.getRoom(roomId)!=null){
|
||||
RoomManager.getRoom(roomId).addResourcePath(this.scenarioTask.getResourceId(),coordinates);
|
||||
}
|
||||
//推送路径任务
|
||||
Global.sendCmdInfoQueue.add(
|
||||
ResponseCmdInfo.create(WsCmdTypeEnum.PATH_INIT.getCode(), roomId,
|
||||
|
@ -233,7 +237,7 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
endPoint = distanceInfoMap.lastEntry();
|
||||
}
|
||||
|
||||
// log.info("enPoint::{}",endPoint);
|
||||
|
||||
//ws数据
|
||||
List<double[]> dataList = new ArrayList<>();
|
||||
HashMap<Object, Object> dataMap = new HashMap<>();
|
||||
|
@ -293,6 +297,8 @@ public abstract class AbtParentTask implements TaskAction {
|
|||
if (finishedAction != null) {
|
||||
finishedAction.doSomeThing();
|
||||
}
|
||||
|
||||
|
||||
//完成路径
|
||||
Global.sendCmdInfoQueue.add(
|
||||
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.room.func.TaskAction;
|
||||
import com.hivekion.scenario.bean.ScenarioWsParam;
|
||||
import com.hivekion.scenario.entity.ScenarioResource;
|
||||
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.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -26,10 +29,6 @@ import java.util.concurrent.ThreadPoolExecutor;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
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.extern.slf4j.Slf4j;
|
||||
|
||||
|
@ -47,6 +46,10 @@ import lombok.extern.slf4j.Slf4j;
|
|||
public class Room implements AutoCloseable {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public void initRoomParam(){
|
||||
if( scenarioService == null) {
|
||||
public void initRoomParam() {
|
||||
if (scenarioService == null) {
|
||||
scenarioService = SpringUtil.getBean(com.hivekion.statistic.service.ScenarioService.class);
|
||||
}
|
||||
//设置资源列表
|
||||
scenario.setResourceList(SpringUtil.getBean(ScenarioResourceServiceImpl.class).getResourceListByScenarioId(scenario.getId()));
|
||||
for(ScenarioResource scenarioResource:this.scenario.getResourceList() ){
|
||||
ScenarioInfo scenarioInfo = scenarioService.listScenarioInfo(scenarioResource.getScenarioId(),roomId,scenarioResource.getId());
|
||||
EditScenarioInfo updScenarioInfo = scenarioService.listEditScenarioInfo(scenarioResource.getScenarioId(),roomId,scenarioResource.getId());
|
||||
if( redisUtil == null){
|
||||
scenario.setResourceList(SpringUtil.getBean(ScenarioResourceServiceImpl.class)
|
||||
.getResourceListByScenarioId(scenario.getId()));
|
||||
for (ScenarioResource scenarioResource : this.scenario.getResourceList()) {
|
||||
ScenarioInfo scenarioInfo = scenarioService.listScenarioInfo(scenarioResource.getScenarioId(),
|
||||
roomId, scenarioResource.getId());
|
||||
EditScenarioInfo updScenarioInfo = scenarioService.listEditScenarioInfo(
|
||||
scenarioResource.getScenarioId(), roomId, scenarioResource.getId());
|
||||
if (redisUtil == null) {
|
||||
redisUtil = SpringUtil.getBean(RedisUtil.class);
|
||||
}
|
||||
redisUtil.hset(scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(),"scenarioInfo",JSON.toJSONString(scenarioInfo));
|
||||
redisUtil.hset(scenarioResource.getScenarioId() + "-" + roomId + "-" + scenarioResource.getId(),"updScenarioInfo", JSON.toJSONString(updScenarioInfo));
|
||||
redisUtil.hset(
|
||||
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;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.hivekion.common.entity.ResponseData;
|
||||
import com.hivekion.common.uuid.IdUtils;
|
||||
import com.hivekion.scenario.entity.ScenarioResource;
|
||||
import com.hivekion.scenario.entity.ScenarioTask;
|
||||
import com.hivekion.scenario.service.ScenarioResourceService;
|
||||
import com.hivekion.scenario.service.ScenarioTaskService;
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
|
@ -28,13 +29,33 @@ public class ScenarioTaskController {
|
|||
|
||||
@Resource
|
||||
private ScenarioTaskService scenarioTaskService;
|
||||
@Resource
|
||||
private ScenarioResourceService scenarioResourceService;
|
||||
|
||||
@PostMapping("/save")
|
||||
public ResponseData<Void> save(@RequestBody ScenarioTask scenarioTask) {
|
||||
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());
|
||||
|
||||
scenarioTaskService.save(scenarioTask);
|
||||
} else {
|
||||
|
||||
scenarioTaskService.updateById(scenarioTask);
|
||||
}
|
||||
return ResponseData.success(null);
|
||||
|
|
|
@ -19,4 +19,5 @@ public interface ScenarioTaskService extends IService<ScenarioTask> {
|
|||
void wakeup(Integer id,String roomId);
|
||||
|
||||
List<ScenarioTask> queryTaskList(ScenarioTask task);
|
||||
|
||||
}
|
||||
|
|
|
@ -85,6 +85,7 @@ public class ScenarioTaskServiceImpl extends
|
|||
if (StringUtils.isNotBlank(task.getResourceId())) {
|
||||
queryWrapper.eq("resource_id", task.getResourceId());
|
||||
}
|
||||
queryWrapper.orderByAsc("start_time");
|
||||
return this.list(queryWrapper);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,10 @@ import cn.hutool.extra.spring.SpringUtil;
|
|||
import com.alibaba.fastjson.JSON;
|
||||
import com.hivekion.Global;
|
||||
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 java.util.Map;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
|
@ -23,14 +25,21 @@ public class HandleReceiveRunnable implements Runnable {
|
|||
@Override
|
||||
public void run() {
|
||||
while (!Thread.currentThread().isInterrupted()) {
|
||||
try {
|
||||
|
||||
try {
|
||||
RequestCmdInfo requestCmdInfo = Global.receiveCmdInfoQueue.take();
|
||||
|
||||
//消息分发业务bean处理
|
||||
if(SpringUtil.getBean(WebsocketMsgWrapper.class) != null){
|
||||
WebsocketMsgWrapper websocketMsgWrapper = SpringUtil.getBean(WebsocketMsgWrapper.class);
|
||||
websocketMsgWrapper.msgHandle(requestCmdInfo.getScenarioId(),requestCmdInfo.getRoom(),requestCmdInfo.getResourceId(),requestCmdInfo.getMessage());
|
||||
}else{
|
||||
if (SpringUtil.getBean(WebsocketMsgWrapper.class) != null) {
|
||||
try {
|
||||
WebsocketMsgWrapper websocketMsgWrapper = SpringUtil.getBean(WebsocketMsgWrapper.class);
|
||||
websocketMsgWrapper.msgHandle(requestCmdInfo.getScenarioId(), requestCmdInfo.getRoom(),
|
||||
requestCmdInfo.getResourceId(), requestCmdInfo.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("error::", e);
|
||||
}
|
||||
|
||||
} else {
|
||||
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
|
||||
@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 (
|
||||
SELECT * FROM tbl_scenario
|
||||
<where>
|
||||
|
@ -32,7 +32,7 @@
|
|||
<select id="List" resultType="com.hivekion.baseData.entity.Scenario" parameterType="com.hivekion.baseData.entity.Scenario" databaseId="dm">
|
||||
select
|
||||
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 (
|
||||
SELECT
|
||||
ROW_NUMBER() OVER (ORDER BY id ASC) AS seq,
|
||||
|
@ -73,7 +73,8 @@
|
|||
left_bottom_lng AS leftBottomLng,
|
||||
right_bottom_lng AS rightBottomLng,
|
||||
left_bottom_lat AS leftBottomLat,
|
||||
right_bottom_lat AS rightBottomLat
|
||||
right_bottom_lat AS rightBottomLat,
|
||||
mark
|
||||
FROM
|
||||
tbl_scenario
|
||||
WHERE
|
||||
|
|
Loading…
Reference in New Issue
Block a user