Commit f7e3280c by xmh

gateway:

<refactor> 接口修正,配置重写修正

ops:
查询设备列表或单个设备后,如果是录像文件类型,那么拼接 streamPath

task:
<feat> 添加停止任务接口
<docs> 添加注释
1 parent b79ddbd7
...@@ -22,24 +22,34 @@ import java.util.List; ...@@ -22,24 +22,34 @@ import java.util.List;
public class VionConfig { public class VionConfig {
private Image image; private Image image;
/** 是否启用转发 */
private boolean enableForward; private boolean enableForward;
/** auth 服务地址 */
private String authPath; private String authPath;
private Gateway gateway; private Gateway gateway;
/** 支持的视频格式列表 */
private List<String> supportedVideoFormats; private List<String> supportedVideoFormats;
/** 需要跳过 token 验证的 url 的正则表达式列表 */
private List<String> skipAuth; private List<String> skipAuth;
public @Getter public @Getter
@Setter @Setter
static class Image { static class Image {
/** images 本地存储路径 */
private String path; private String path;
/** 图片保存天数 */
private Integer keep; private Integer keep;
/** 访问 images 前缀,images 包含录像文件和分析图片 */
private String urlPrefix;
} }
public @Getter public @Getter
@Setter @Setter
static class Gateway { static class Gateway {
/** 网关 ip,以后可能改为 nginx */
private String ip; private String ip;
/** 网关端口 */
private String port; private String port;
} }
......
...@@ -18,7 +18,7 @@ import java.util.Map; ...@@ -18,7 +18,7 @@ import java.util.Map;
@FeignClient(name = "auth", url = "${vion.auth-path}") @FeignClient(name = "auth", url = "${vion.auth-path}")
public interface AuthClient { public interface AuthClient {
@PostMapping(value = "/api/v1/auth/authorize", produces = MediaType.APPLICATION_JSON_VALUE) @PostMapping(value = "/auth_serv/api/v1/auth/authorize", produces = MediaType.APPLICATION_JSON_VALUE)
JSONObject checkToken(@RequestHeader("authorization") String token, @RequestBody Map<String, Object> data); JSONObject checkToken(@RequestHeader("authorization") String token, @RequestBody Map<String, Object> data);
} }
...@@ -20,11 +20,11 @@ spring: ...@@ -20,11 +20,11 @@ spring:
lower-case-service-id: true lower-case-service-id: true
routes: routes:
- id: auth - id: auth
uri: http://192.168.9.62:20080/ uri: http://192.168.9.233:30010/
predicates: predicates:
- Path=/auth-serv/** - Path=/auth-serv/**
filters: filters:
- RewritePath=/auth-serv/?(?<segment>.*),/$\{segment} - RewritePath=/auth-serv/?(?<segment>.*),/auth_serv/$\{segment}
consul: consul:
# 服务发现配置 # 服务发现配置
discovery: discovery:
...@@ -62,7 +62,7 @@ spring: ...@@ -62,7 +62,7 @@ spring:
logging: logging:
config: classpath:logback-${spring.profiles.active}.xml config: classpath:logback-${spring.profiles.active}.xml
vion: vion:
auth-path: http://192.168.9.62:20080 auth-path: http://192.168.9.233:30010
skip-auth: skip-auth:
- .*login.* - .*login.*
- .*fanxing-task/register.* - .*fanxing-task/register.*
......
...@@ -2,8 +2,10 @@ package com.viontech.fanxing.ops.service.impl; ...@@ -2,8 +2,10 @@ package com.viontech.fanxing.ops.service.impl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseMapper; import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl; import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.config.VionConfig;
import com.viontech.fanxing.commons.constant.ChannelType; import com.viontech.fanxing.commons.constant.ChannelType;
import com.viontech.fanxing.commons.model.*; import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.vo.ChannelVo; import com.viontech.fanxing.commons.vo.ChannelVo;
...@@ -35,12 +37,34 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan ...@@ -35,12 +37,34 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
private DictCateService dictCateService; private DictCateService dictCateService;
@Resource @Resource
private ChannelTagService channelTagService; private ChannelTagService channelTagService;
@Resource
private VionConfig vionConfig;
@Override @Override
public BaseMapper<Channel> getMapper() { public BaseMapper<Channel> getMapper() {
return channelMapper; return channelMapper;
} }
@Override
public List<Channel> selectByExample(BaseExample example) {
List<Channel> channels = getMapper().selectByExample(example);
for (Channel channel : channels) {
if (ChannelType.FILE.value == channel.getType()) {
channel.setStreamPath(vionConfig.getImage().getUrlPrefix() + channel.getStreamPath());
}
}
return channels;
}
@Override
public Channel selectByPrimaryKey(Object id) {
Channel channel = super.selectByPrimaryKey(id);
if (ChannelType.FILE.value == channel.getType()) {
channel.setStreamPath(vionConfig.getImage().getUrlPrefix() + channel.getStreamPath());
}
return channel;
}
/** /**
* 以树状结构获取所有的组织关系和视频资源 * 以树状结构获取所有的组织关系和视频资源
*/ */
......
...@@ -54,6 +54,7 @@ pagehelper: ...@@ -54,6 +54,7 @@ pagehelper:
vion: vion:
image: image:
path: G:\data path: G:\data
url-prefix: http://192.168.9.233:30007/images
redisson: redisson:
path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml
supported-video-formats: supported-video-formats:
......
...@@ -47,11 +47,11 @@ public class TaskController extends TaskBaseController { ...@@ -47,11 +47,11 @@ public class TaskController extends TaskBaseController {
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public Object del(@PathVariable(value = "id") Long id) { public Object del(@PathVariable(value = "id") Long id) {
taskService.removeTask(id); taskService.removeTask(id);
return JsonMessageUtil.getSuccessJsonMsg("success"); return JsonMessageUtil.getSuccessJsonMsg();
} }
@GetMapping("/startTask/{id}") @GetMapping("/{id}/start")
public JsonMessageUtil.JsonMessage<TaskVo> startTask(@PathVariable("id") Long id) { public JsonMessageUtil.JsonMessage<TaskVo> startTask(@PathVariable("id") Long id) {
try { try {
taskService.startTask(id); taskService.startTask(id);
...@@ -59,7 +59,18 @@ public class TaskController extends TaskBaseController { ...@@ -59,7 +59,18 @@ public class TaskController extends TaskBaseController {
log.error("启动任务异常", e); log.error("启动任务异常", e);
return JsonMessageUtil.getErrorJsonMsg(e.getMessage()); return JsonMessageUtil.getErrorJsonMsg(e.getMessage());
} }
return JsonMessageUtil.getSuccessJsonMsg("success"); return JsonMessageUtil.getSuccessJsonMsg();
}
@GetMapping("/{id}/stop")
public JsonMessageUtil.JsonMessage stopTask(@PathVariable("id") Long id) {
try {
taskService.stopTask(id);
} catch (Exception e) {
log.error("停止任务异常", e);
return JsonMessageUtil.getErrorJsonMsg(e.getMessage());
}
return JsonMessageUtil.getSuccessJsonMsg();
} }
@GetMapping("overview") @GetMapping("overview")
......
...@@ -16,5 +16,21 @@ public interface TaskService extends BaseService<Task> { ...@@ -16,5 +16,21 @@ public interface TaskService extends BaseService<Task> {
void startTask(Long id); void startTask(Long id);
/**
* 任务概览
* <ul>
* <li>1.视频分析服务资源总数</li>
* <li>2.使用中的资源数</li>
* <li>3.任务总数</li>
* <li>4.运行中任务总数</li>
* </ul>
*
* @return
*/
JSONObject overview(); JSONObject overview();
/**
* 停止任务
*/
void stopTask(Long id);
} }
\ No newline at end of file \ No newline at end of file
...@@ -56,6 +56,12 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic ...@@ -56,6 +56,12 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
return new TaskVo(task); return new TaskVo(task);
} }
/**
* 构建任务
* 1. 构建视频流地址
* 2. 构建基础的 scene
* 3. 构建基础的算法配置,添加到 scene 中
*/
private void buildTask(Task task) { private void buildTask(Task task) {
String channelUnid = task.getChannelUnid(); String channelUnid = task.getChannelUnid();
Channel channel = opsClientService.getChannelByChannelUnid(channelUnid); Channel channel = opsClientService.getChannelByChannelUnid(channelUnid);
...@@ -108,6 +114,9 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic ...@@ -108,6 +114,9 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
task.setScene(sceneString); task.setScene(sceneString);
} }
/**
* 更新任务,先更新数据后,再尝试更新 VAServer
*/
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public TaskVo updateTask(Task task) { public TaskVo updateTask(Task task) {
...@@ -131,6 +140,9 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic ...@@ -131,6 +140,9 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
deleteByPrimaryKey(id); deleteByPrimaryKey(id);
} }
/**
* 只更新任务的状态
*/
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateStatus(Long id, Integer status) { public void updateStatus(Long id, Integer status) {
...@@ -144,6 +156,9 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic ...@@ -144,6 +156,9 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void startTask(Long id) { public void startTask(Long id) {
Task task = selectByPrimaryKey(id); Task task = selectByPrimaryKey(id);
if (task.getStatus().equals(TaskStatus.RUNNING.val)) {
return;
}
if (StringUtils.isBlank(task.getScene())) { if (StringUtils.isBlank(task.getScene())) {
throw new IllegalArgumentException("场景配置为空,无法执行"); throw new IllegalArgumentException("场景配置为空,无法执行");
} }
...@@ -154,6 +169,17 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic ...@@ -154,6 +169,17 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
taskDataService.addTask(task); taskDataService.addTask(task);
} }
/**
* 停止任务
*/
@Transactional(rollbackFor = Exception.class)
@Override
public void stopTask(Long id) {
Task task = selectByPrimaryKey(id);
taskDataService.deleteTask(task.getUnid());
updateStatus(id, TaskStatus.PAUSE.val);
}
@Override @Override
@LocalCache(value = "task_overview", duration = 3) @LocalCache(value = "task_overview", duration = 3)
public JSONObject overview() { public JSONObject overview() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!