Commit 2737dc87 by xmh

Channel 增加字段 deviceType

ChannelTag 修改 tag 为字符串类型
转发服务提高线程池大小
gateway 添加路由配置

运维服务
1. 删除录像文件记录时同时删除文件
2. 录像文件大小由 expand 来记录
3. 上传录像文件时先写库再写入文件再更新库
4. 不能删除带有任务的Channel
5. 不能上传同名或同编号的录像文件和视频设备

任务服务整体调整
1 parent f7e3280c
Showing 31 changed files with 679 additions and 288 deletions
...@@ -46,13 +46,15 @@ public class Channel extends BaseModel { ...@@ -46,13 +46,15 @@ public class Channel extends BaseModel {
private Date createTime; private Date createTime;
private List<Long> tags; private String deviceType;
public List<Long> getTags() { private List<String> tags;
public List<String> getTags() {
return tags; return tags;
} }
public Channel setTags(List<Long> tags) { public Channel setTags(List<String> tags) {
this.tags = tags; this.tags = tags;
return this; return this;
} }
...@@ -216,4 +218,12 @@ public class Channel extends BaseModel { ...@@ -216,4 +218,12 @@ public class Channel extends BaseModel {
public void setCreateTime(Date createTime) { public void setCreateTime(Date createTime) {
this.createTime = createTime; this.createTime = createTime;
} }
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -1408,6 +1408,76 @@ public class ChannelExample extends BaseExample { ...@@ -1408,6 +1408,76 @@ public class ChannelExample extends BaseExample {
addCriterion("`channel`.create_time not between", value1, value2, "createTime"); addCriterion("`channel`.create_time not between", value1, value2, "createTime");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andDeviceTypeIsNull() {
addCriterion("`channel`.device_type is null");
return (Criteria) this;
}
public Criteria andDeviceTypeIsNotNull() {
addCriterion("`channel`.device_type is not null");
return (Criteria) this;
}
public Criteria andDeviceTypeEqualTo(String value) {
addCriterion("`channel`.device_type =", value, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeNotEqualTo(String value) {
addCriterion("`channel`.device_type <>", value, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeGreaterThan(String value) {
addCriterion("`channel`.device_type >", value, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeGreaterThanOrEqualTo(String value) {
addCriterion("`channel`.device_type >=", value, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeLessThan(String value) {
addCriterion("`channel`.device_type <", value, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeLessThanOrEqualTo(String value) {
addCriterion("`channel`.device_type <=", value, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeLike(String value) {
addCriterion("`channel`.device_type like", value, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeNotLike(String value) {
addCriterion("`channel`.device_type not like", value, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeIn(List<String> values) {
addCriterion("`channel`.device_type in", values, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeNotIn(List<String> values) {
addCriterion("`channel`.device_type not in", values, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeBetween(String value1, String value2) {
addCriterion("`channel`.device_type between", value1, value2, "deviceType");
return (Criteria) this;
}
public Criteria andDeviceTypeNotBetween(String value1, String value2) {
addCriterion("`channel`.device_type not between", value1, value2, "deviceType");
return (Criteria) this;
}
} }
public static class ColumnContainer extends ColumnContainerBase { public static class ColumnContainer extends ColumnContainerBase {
...@@ -1515,5 +1585,10 @@ public class ChannelExample extends BaseExample { ...@@ -1515,5 +1585,10 @@ public class ChannelExample extends BaseExample {
addColumnStr("`channel`.create_time as channel_create_time "); addColumnStr("`channel`.create_time as channel_create_time ");
return (ColumnContainer) this; return (ColumnContainer) this;
} }
public ColumnContainer hasDeviceTypeColumn() {
addColumnStr("`channel`.device_type as channel_device_type ");
return (ColumnContainer) this;
}
} }
} }
\ No newline at end of file \ No newline at end of file
...@@ -7,7 +7,7 @@ public class ChannelTag extends BaseModel { ...@@ -7,7 +7,7 @@ public class ChannelTag extends BaseModel {
private Long channelId; private Long channelId;
private Long tagId; private String tag;
private Channel channel; private Channel channel;
...@@ -27,12 +27,12 @@ public class ChannelTag extends BaseModel { ...@@ -27,12 +27,12 @@ public class ChannelTag extends BaseModel {
this.channelId = channelId; this.channelId = channelId;
} }
public Long getTagId() { public String getTag() {
return tagId; return tag;
} }
public void setTagId(Long tagId) { public void setTag(String tag) {
this.tagId = tagId; this.tag = tag == null ? null : tag.trim();
} }
public Channel getChannel() { public Channel getChannel() {
......
...@@ -250,63 +250,73 @@ public class ChannelTagExample extends BaseExample { ...@@ -250,63 +250,73 @@ public class ChannelTagExample extends BaseExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdIsNull() { public Criteria andTagIsNull() {
addCriterion("`channel_tag`.tag_id is null"); addCriterion("`channel_tag`.tag is null");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdIsNotNull() { public Criteria andTagIsNotNull() {
addCriterion("`channel_tag`.tag_id is not null"); addCriterion("`channel_tag`.tag is not null");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdEqualTo(Long value) { public Criteria andTagEqualTo(String value) {
addCriterion("`channel_tag`.tag_id =", value, "tagId"); addCriterion("`channel_tag`.tag =", value, "tag");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdNotEqualTo(Long value) { public Criteria andTagNotEqualTo(String value) {
addCriterion("`channel_tag`.tag_id <>", value, "tagId"); addCriterion("`channel_tag`.tag <>", value, "tag");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdGreaterThan(Long value) { public Criteria andTagGreaterThan(String value) {
addCriterion("`channel_tag`.tag_id >", value, "tagId"); addCriterion("`channel_tag`.tag >", value, "tag");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdGreaterThanOrEqualTo(Long value) { public Criteria andTagGreaterThanOrEqualTo(String value) {
addCriterion("`channel_tag`.tag_id >=", value, "tagId"); addCriterion("`channel_tag`.tag >=", value, "tag");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdLessThan(Long value) { public Criteria andTagLessThan(String value) {
addCriterion("`channel_tag`.tag_id <", value, "tagId"); addCriterion("`channel_tag`.tag <", value, "tag");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdLessThanOrEqualTo(Long value) { public Criteria andTagLessThanOrEqualTo(String value) {
addCriterion("`channel_tag`.tag_id <=", value, "tagId"); addCriterion("`channel_tag`.tag <=", value, "tag");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdIn(List<Long> values) { public Criteria andTagLike(String value) {
addCriterion("`channel_tag`.tag_id in", values, "tagId"); addCriterion("`channel_tag`.tag like", value, "tag");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdNotIn(List<Long> values) { public Criteria andTagNotLike(String value) {
addCriterion("`channel_tag`.tag_id not in", values, "tagId"); addCriterion("`channel_tag`.tag not like", value, "tag");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdBetween(Long value1, Long value2) { public Criteria andTagIn(List<String> values) {
addCriterion("`channel_tag`.tag_id between", value1, value2, "tagId"); addCriterion("`channel_tag`.tag in", values, "tag");
return (Criteria) this; return (Criteria) this;
} }
public Criteria andTagIdNotBetween(Long value1, Long value2) { public Criteria andTagNotIn(List<String> values) {
addCriterion("`channel_tag`.tag_id not between", value1, value2, "tagId"); addCriterion("`channel_tag`.tag not in", values, "tag");
return (Criteria) this;
}
public Criteria andTagBetween(String value1, String value2) {
addCriterion("`channel_tag`.tag between", value1, value2, "tag");
return (Criteria) this;
}
public Criteria andTagNotBetween(String value1, String value2) {
addCriterion("`channel_tag`.tag not between", value1, value2, "tag");
return (Criteria) this; return (Criteria) this;
} }
} }
...@@ -327,8 +337,8 @@ public class ChannelTagExample extends BaseExample { ...@@ -327,8 +337,8 @@ public class ChannelTagExample extends BaseExample {
return (ColumnContainer) this; return (ColumnContainer) this;
} }
public ColumnContainer hasTagIdColumn() { public ColumnContainer hasTagColumn() {
addColumnStr("`channel_tag`.tag_id as channel_tag_tag_id "); addColumnStr("`channel_tag`.tag as channel_tag_tag ");
return (ColumnContainer) this; return (ColumnContainer) this;
} }
} }
......
...@@ -40,19 +40,10 @@ public class ChannelTagVoBase extends ChannelTag implements VoInterface<ChannelT ...@@ -40,19 +40,10 @@ public class ChannelTagVoBase extends ChannelTag implements VoInterface<ChannelT
private Long channelId_lte; private Long channelId_lte;
@JsonIgnore @JsonIgnore
private ArrayList<Long> tagId_arr; private ArrayList<String> tag_arr;
@JsonIgnore @JsonIgnore
private Long tagId_gt; private String tag_like;
@JsonIgnore
private Long tagId_lt;
@JsonIgnore
private Long tagId_gte;
@JsonIgnore
private Long tagId_lte;
public ChannelTagVoBase() { public ChannelTagVoBase() {
this(null); this(null);
...@@ -176,64 +167,40 @@ public class ChannelTagVoBase extends ChannelTag implements VoInterface<ChannelT ...@@ -176,64 +167,40 @@ public class ChannelTagVoBase extends ChannelTag implements VoInterface<ChannelT
} }
public void setChannelId(Long channelId) { public void setChannelId(Long channelId) {
if(getModel() == null ){ if (getModel() == null) {
throw new RuntimeException("model is null"); throw new RuntimeException("model is null");
} }
this.getModel().setChannelId(channelId); this.getModel().setChannelId(channelId);
} }
public ArrayList<Long> getTagId_arr() { public ArrayList<String> getTag_arr() {
return tagId_arr; return tag_arr;
}
public void setTagId_arr(ArrayList<Long> tagId_arr) {
this.tagId_arr = tagId_arr;
}
public Long getTagId_gt() {
return tagId_gt;
} }
public void setTagId_gt(Long tagId_gt) { public void setTag_arr(ArrayList<String> tag_arr) {
this.tagId_gt = tagId_gt; this.tag_arr = tag_arr;
} }
public Long getTagId_lt() { public String getTag_like() {
return tagId_lt; return tag_like;
} }
public void setTagId_lt(Long tagId_lt) { public void setTag_like(String tag_like) {
this.tagId_lt = tagId_lt; this.tag_like = tag_like;
} }
public Long getTagId_gte() { public String getTag() {
return tagId_gte; if (getModel() == null) {
}
public void setTagId_gte(Long tagId_gte) {
this.tagId_gte = tagId_gte;
}
public Long getTagId_lte() {
return tagId_lte;
}
public void setTagId_lte(Long tagId_lte) {
this.tagId_lte = tagId_lte;
}
public Long getTagId() {
if(getModel() == null ){
throw new RuntimeException("model is null"); throw new RuntimeException("model is null");
} }
return this.getModel().getTagId(); return this.getModel().getTag();
} }
public void setTagId(Long tagId) { public void setTag(String tag) {
if(getModel() == null ){ if (getModel() == null) {
throw new RuntimeException("model is null"); throw new RuntimeException("model is null");
} }
this.getModel().setTagId(tagId); this.getModel().setTag(tag);
} }
public Channel getChannel() { public Channel getChannel() {
......
...@@ -243,12 +243,21 @@ public class ChannelVoBase extends Channel implements VoInterface<Channel> { ...@@ -243,12 +243,21 @@ public class ChannelVoBase extends Channel implements VoInterface<Channel> {
@JsonIgnore @JsonIgnore
private Date createTime_lte; private Date createTime_lte;
@JsonIgnore
private Boolean deviceType_null;
@JsonIgnore
private ArrayList<String> deviceType_arr;
@JsonIgnore
private String deviceType_like;
public ChannelVoBase() { public ChannelVoBase() {
this(null); this(null);
} }
public ChannelVoBase(Channel channel) { public ChannelVoBase(Channel channel) {
if(channel == null) { if (channel == null) {
channel = new Channel(); channel = new Channel();
} }
this.channel = channel; this.channel = channel;
...@@ -1161,9 +1170,47 @@ public class ChannelVoBase extends Channel implements VoInterface<Channel> { ...@@ -1161,9 +1170,47 @@ public class ChannelVoBase extends Channel implements VoInterface<Channel> {
} }
public void setCreateTime(Date createTime) { public void setCreateTime(Date createTime) {
if(getModel() == null ){ if (getModel() == null) {
throw new RuntimeException("model is null"); throw new RuntimeException("model is null");
} }
this.getModel().setCreateTime(createTime); this.getModel().setCreateTime(createTime);
} }
public Boolean getDeviceType_null() {
return deviceType_null;
}
public void setDeviceType_null(Boolean deviceType_null) {
this.deviceType_null = deviceType_null;
}
public ArrayList<String> getDeviceType_arr() {
return deviceType_arr;
}
public void setDeviceType_arr(ArrayList<String> deviceType_arr) {
this.deviceType_arr = deviceType_arr;
}
public String getDeviceType_like() {
return deviceType_like;
}
public void setDeviceType_like(String deviceType_like) {
this.deviceType_like = deviceType_like;
}
public String getDeviceType() {
if (getModel() == null) {
throw new RuntimeException("model is null");
}
return this.getModel().getDeviceType();
}
public void setDeviceType(String deviceType) {
if (getModel() == null) {
throw new RuntimeException("model is null");
}
this.getModel().setDeviceType(deviceType);
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -44,8 +44,8 @@ public class ForwardApp { ...@@ -44,8 +44,8 @@ public class ForwardApp {
@Bean @Bean
public TaskExecutor taskExecutor() { public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor(); ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setMaxPoolSize(30); threadPoolTaskExecutor.setMaxPoolSize(50);
threadPoolTaskExecutor.setCorePoolSize(10); threadPoolTaskExecutor.setCorePoolSize(20);
threadPoolTaskExecutor.setThreadNamePrefix("fanxing-forward-process-"); threadPoolTaskExecutor.setThreadNamePrefix("fanxing-forward-process-");
return threadPoolTaskExecutor; return threadPoolTaskExecutor;
} }
......
...@@ -25,6 +25,16 @@ spring: ...@@ -25,6 +25,16 @@ spring:
- Path=/auth-serv/** - Path=/auth-serv/**
filters: filters:
- RewritePath=/auth-serv/?(?<segment>.*),/auth_serv/$\{segment} - RewritePath=/auth-serv/?(?<segment>.*),/auth_serv/$\{segment}
- id: images
uri: http://192.168.9.233:30007/
predicates:
- Path=/images/**
- id: videoService
uri: http://192.168.9.233:10350/
predicates:
- Path=/video-server/**
filters:
- RewritePath=/video-server/?(?<segment>.*),/$\{segment}
consul: consul:
# 服务发现配置 # 服务发现配置
discovery: discovery:
......
...@@ -2,12 +2,13 @@ package com.viontech.fanxing.ops.controller.base; ...@@ -2,12 +2,13 @@ package com.viontech.fanxing.ops.controller.base;
import com.viontech.fanxing.commons.base.BaseController; import com.viontech.fanxing.commons.base.BaseController;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseService; import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.Channel; import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.ChannelExample; import com.viontech.fanxing.commons.model.ChannelExample;
import com.viontech.fanxing.commons.vo.ChannelVo; import com.viontech.fanxing.commons.vo.ChannelVo;
import com.viontech.fanxing.ops.mapper.ChannelMapper;
import com.viontech.fanxing.ops.service.adapter.ChannelService; import com.viontech.fanxing.ops.service.adapter.ChannelService;
import javax.annotation.Resource; import javax.annotation.Resource;
public abstract class ChannelBaseController extends BaseController<Channel, ChannelVo> { public abstract class ChannelBaseController extends BaseController<Channel, ChannelVo> {
...@@ -368,6 +369,22 @@ public abstract class ChannelBaseController extends BaseController<Channel, Chan ...@@ -368,6 +369,22 @@ public abstract class ChannelBaseController extends BaseController<Channel, Chan
if (channelVo.getCreateTime_lte() != null) { if (channelVo.getCreateTime_lte() != null) {
criteria.andCreateTimeLessThanOrEqualTo(channelVo.getCreateTime_lte()); criteria.andCreateTimeLessThanOrEqualTo(channelVo.getCreateTime_lte());
} }
if (channelVo.getDeviceType() != null) {
criteria.andDeviceTypeEqualTo(channelVo.getDeviceType());
}
if (channelVo.getDeviceType_null() != null) {
if (channelVo.getDeviceType_null().booleanValue()) {
criteria.andDeviceTypeIsNull();
} else {
criteria.andDeviceTypeIsNotNull();
}
}
if (channelVo.getDeviceType_arr() != null) {
criteria.andDeviceTypeIn(channelVo.getDeviceType_arr());
}
if (channelVo.getDeviceType_like() != null) {
criteria.andDeviceTypeLike(channelVo.getDeviceType_like());
}
return channelExample; return channelExample;
} }
......
...@@ -46,32 +46,23 @@ public abstract class ChannelTagBaseController extends BaseController<ChannelTag ...@@ -46,32 +46,23 @@ public abstract class ChannelTagBaseController extends BaseController<ChannelTag
if(channelTagVo.getChannelId_gt() != null) { if(channelTagVo.getChannelId_gt() != null) {
criteria.andChannelIdGreaterThan(channelTagVo.getChannelId_gt()); criteria.andChannelIdGreaterThan(channelTagVo.getChannelId_gt());
} }
if(channelTagVo.getChannelId_lt() != null) { if (channelTagVo.getChannelId_lt() != null) {
criteria.andChannelIdLessThan(channelTagVo.getChannelId_lt()); criteria.andChannelIdLessThan(channelTagVo.getChannelId_lt());
} }
if(channelTagVo.getChannelId_gte() != null) { if (channelTagVo.getChannelId_gte() != null) {
criteria.andChannelIdGreaterThanOrEqualTo(channelTagVo.getChannelId_gte()); criteria.andChannelIdGreaterThanOrEqualTo(channelTagVo.getChannelId_gte());
} }
if(channelTagVo.getChannelId_lte() != null) { if (channelTagVo.getChannelId_lte() != null) {
criteria.andChannelIdLessThanOrEqualTo(channelTagVo.getChannelId_lte()); criteria.andChannelIdLessThanOrEqualTo(channelTagVo.getChannelId_lte());
} }
if(channelTagVo.getTagId() != null) { if (channelTagVo.getTag() != null) {
criteria.andTagIdEqualTo(channelTagVo.getTagId()); criteria.andTagEqualTo(channelTagVo.getTag());
} }
if(channelTagVo.getTagId_arr() != null) { if (channelTagVo.getTag_arr() != null) {
criteria.andTagIdIn(channelTagVo.getTagId_arr()); criteria.andTagIn(channelTagVo.getTag_arr());
} }
if(channelTagVo.getTagId_gt() != null) { if (channelTagVo.getTag_like() != null) {
criteria.andTagIdGreaterThan(channelTagVo.getTagId_gt()); criteria.andTagLike(channelTagVo.getTag_like());
}
if(channelTagVo.getTagId_lt() != null) {
criteria.andTagIdLessThan(channelTagVo.getTagId_lt());
}
if(channelTagVo.getTagId_gte() != null) {
criteria.andTagIdGreaterThanOrEqualTo(channelTagVo.getTagId_gte());
}
if(channelTagVo.getTagId_lte() != null) {
criteria.andTagIdLessThanOrEqualTo(channelTagVo.getTagId_lte());
} }
return channelTagExample; return channelTagExample;
} }
......
...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.ops.service.main.VideoService; import com.viontech.fanxing.ops.service.main.VideoService;
import com.viontech.keliu.util.JsonMessageUtil; import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -26,8 +27,12 @@ public class VideoController { ...@@ -26,8 +27,12 @@ public class VideoController {
private VideoService videoService; private VideoService videoService;
@PostMapping("/upload") @PostMapping("/upload")
public Object uploadVideo(@RequestParam List<MultipartFile> files, @RequestParam(required = false) List<Long> tags) { public Object uploadVideo(@RequestParam List<MultipartFile> files, @RequestParam(required = false) List<String> tags) {
videoService.uploadVideo(files, tags); try {
videoService.uploadVideo(files, tags);
} catch (DuplicateKeyException e) {
return JsonMessageUtil.getErrorJsonMsg("设备编号或名称重复");
}
return JsonMessageUtil.getSuccessJsonMsg("success"); return JsonMessageUtil.getSuccessJsonMsg("success");
} }
......
...@@ -14,8 +14,9 @@ import com.viontech.fanxing.ops.controller.base.ChannelBaseController; ...@@ -14,8 +14,9 @@ import com.viontech.fanxing.ops.controller.base.ChannelBaseController;
import com.viontech.fanxing.ops.service.adapter.ChannelTagService; import com.viontech.fanxing.ops.service.adapter.ChannelTagService;
import com.viontech.keliu.util.JsonMessageUtil; import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
...@@ -71,9 +72,9 @@ public class ChannelController extends ChannelBaseController { ...@@ -71,9 +72,9 @@ public class ChannelController extends ChannelBaseController {
ChannelTagExample channelTagExample = new ChannelTagExample(); ChannelTagExample channelTagExample = new ChannelTagExample();
channelTagExample.createCriteria().andChannelIdIn(channelIdList); channelTagExample.createCriteria().andChannelIdIn(channelIdList);
List<ChannelTag> channelTags = channelTagService.selectByExample(channelTagExample); List<ChannelTag> channelTags = channelTagService.selectByExample(channelTagExample);
Map<Long, List<Long>> channel_tag_map = channelTags.stream().collect(Collectors.groupingBy(ChannelTag::getChannelId, Collectors.mapping(ChannelTag::getTagId, Collectors.toList()))); Map<Long, List<String>> channel_tag_map = channelTags.stream().collect(Collectors.groupingBy(ChannelTag::getChannelId, Collectors.mapping(ChannelTag::getTag, Collectors.toList())));
for (Channel channel : channels) { for (Channel channel : channels) {
List<Long> tags = channel_tag_map.get(channel.getId()); List<String> tags = channel_tag_map.get(channel.getId());
channel.setTags(tags); channel.setTags(tags);
} }
} }
...@@ -87,4 +88,26 @@ public class ChannelController extends ChannelBaseController { ...@@ -87,4 +88,26 @@ public class ChannelController extends ChannelBaseController {
return JsonMessageUtil.getSuccessJsonMsg(result); return JsonMessageUtil.getSuccessJsonMsg(result);
} }
@RequestMapping(value = "", method = RequestMethod.POST)
@ResponseBody
@Override
public Object add(@RequestBody ChannelVo channelVo) {
Assert.notNull(channelVo.getChannelUnid(), "设备编号不能为空");
Assert.notNull(channelVo.getName(), "设备名称不能为空");
Assert.notNull(channelVo.getBrand(), "厂家不能为空");
Assert.notNull(channelVo.getIp(), "IP不能为空");
Assert.notNull(channelVo.getPort(), "端口不能为空");
Assert.notNull(channelVo.getStreamType(), "视频流类型不能为空");
Assert.notNull(channelVo.getUsername(), "用户名不能为空");
Assert.notNull(channelVo.getPassword(), "密码不能为空");
Assert.notNull(channelVo.getStreamPath(), "视频流地址不能为空");
Assert.notNull(channelVo.getType(), "类型不能为空");
try {
return super.add(channelVo);
} catch (DuplicateKeyException e) {
log.error("", e);
return JsonMessageUtil.getErrorJsonMsg("设备编号或名称重复");
}
}
} }
\ No newline at end of file \ No newline at end of file
...@@ -5,6 +5,7 @@ import com.viontech.keliu.util.JsonMessageUtil; ...@@ -5,6 +5,7 @@ import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
...@@ -22,4 +23,7 @@ public interface TaskFeignClient { ...@@ -22,4 +23,7 @@ public interface TaskFeignClient {
@GetMapping("/tasks") @GetMapping("/tasks")
JsonMessageUtil.JsonMessage<List<Task>> getAllTask(); JsonMessageUtil.JsonMessage<List<Task>> getAllTask();
@GetMapping("/tasks")
JsonMessageUtil.JsonMessage<List<Task>> getTaskByChannelUnid(@RequestParam("channelUnid") String channelUnid);
} }
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<result column="channel_latitude" property="latitude" /> <result column="channel_latitude" property="latitude" />
<result column="channel_status" property="status" /> <result column="channel_status" property="status" />
<result column="channel_create_time" property="createTime" /> <result column="channel_create_time" property="createTime" />
<result column="channel_device_type" property="deviceType"/>
</resultMap> </resultMap>
<resultMap id="BaseResultMap" type="com.viontech.fanxing.commons.model.Channel" extends="BaseResultMapRoot" /> <resultMap id="BaseResultMap" type="com.viontech.fanxing.commons.model.Channel" extends="BaseResultMapRoot" />
<sql id="Example_Where_Clause" > <sql id="Example_Where_Clause" >
...@@ -83,14 +84,18 @@ ...@@ -83,14 +84,18 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List_Root" > <sql id="Base_Column_List_Root" >
`channel`.id as channel_id, `channel`.unid as channel_unid, `channel`.channel_unid as channel_channel_unid, ` channel `.id as channel_id,
`channel`.device_unid as channel_device_unid, `channel`.`type` as `channel_type`, ` channel `.unid as channel_unid,
` channel `.channel_unid as channel_channel_unid,
` channel `.device_unid as channel_device_unid,
` channel `.`type` as `channel_type`,
`channel`.stream_type as channel_stream_type, `channel`.stream_path as channel_stream_path, `channel`.stream_type as channel_stream_type, `channel`.stream_path as channel_stream_path,
`channel`.username as channel_username, `channel`.`password` as `channel_password`, `channel`.username as channel_username, `channel`.`password` as `channel_password`,
`channel`.brand as channel_brand, `channel`.direction as channel_direction, `channel`.address_unid as channel_address_unid, `channel`.brand as channel_brand, `channel`.direction as channel_direction, `channel`.address_unid as channel_address_unid,
`channel`.`name` as `channel_name`, `channel`.ip as channel_ip, `channel`.port as channel_port, `channel`.`name` as `channel_name`, `channel`.ip as channel_ip, `channel`.port as channel_port,
`channel`.expand as channel_expand, `channel`.longitude as channel_longitude, `channel`.latitude as channel_latitude, `channel`.expand as channel_expand, `channel`.longitude as channel_longitude, `channel`.latitude as channel_latitude,
`channel`.`status` as `channel_status`, `channel`.create_time as channel_create_time `channel`.`status` as `channel_status`, `channel`.create_time as channel_create_time,
`channel`.device_type as channel_device_type
</sql> </sql>
<sql id="Base_Column_List" > <sql id="Base_Column_List" >
<if test="!(_parameter.getClass().getSimpleName() == 'ChannelExample')" > <if test="!(_parameter.getClass().getSimpleName() == 'ChannelExample')" >
...@@ -145,20 +150,20 @@ ...@@ -145,20 +150,20 @@
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="com.viontech.fanxing.commons.model.Channel" useGeneratedKeys="true" keyProperty="id" keyColumn="id" > <insert id="insert" parameterType="com.viontech.fanxing.commons.model.Channel" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `s_channel` (unid, channel_unid, device_unid, insert into `s_channel` (unid, channel_unid, device_unid,
`type`, stream_type, stream_path, `type`, stream_type, stream_path,
username, `password`, brand, username, `password`, brand,
direction, address_unid, `name`, direction, address_unid, `name`,
ip, port, expand, longitude, ip, port, expand, longitude,
latitude, `status`, create_time latitude, `status`, create_time,
) device_type)
values (#{unid,jdbcType=VARCHAR}, #{channelUnid,jdbcType=VARCHAR}, #{deviceUnid,jdbcType=VARCHAR}, values (#{unid,jdbcType=VARCHAR}, #{channelUnid,jdbcType=VARCHAR}, #{deviceUnid,jdbcType=VARCHAR},
#{type,jdbcType=INTEGER}, #{streamType,jdbcType=INTEGER}, #{streamPath,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, #{streamType,jdbcType=INTEGER}, #{streamPath,jdbcType=VARCHAR},
#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{brand,jdbcType=VARCHAR}, #{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{brand,jdbcType=VARCHAR},
#{direction,jdbcType=VARCHAR}, #{addressUnid,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{direction,jdbcType=VARCHAR}, #{addressUnid,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{ip,jdbcType=VARCHAR}, #{port,jdbcType=INTEGER}, #{expand,jdbcType=VARCHAR}, #{longitude,jdbcType=REAL}, #{ip,jdbcType=VARCHAR}, #{port,jdbcType=INTEGER}, #{expand,jdbcType=VARCHAR}, #{longitude,jdbcType=REAL},
#{latitude,jdbcType=REAL}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP} #{latitude,jdbcType=REAL}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
) #{deviceType,jdbcType=VARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="com.viontech.fanxing.commons.model.Channel" useGeneratedKeys="true" keyProperty="id" keyColumn="id" > <insert id="insertSelective" parameterType="com.viontech.fanxing.commons.model.Channel" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `s_channel` insert into `s_channel`
...@@ -209,17 +214,20 @@ ...@@ -209,17 +214,20 @@
expand, expand,
</if> </if>
<if test="longitude != null" > <if test="longitude != null" >
longitude, longitude,
</if>
<if test="latitude != null" >
latitude,
</if>
<if test="status != null" >
`status`,
</if>
<if test="createTime != null" >
create_time,
</if> </if>
<if test="latitude != null">
latitude,
</if>
<if test="status != null">
`status`,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="deviceType != null">
device_type,
</if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides="," > <trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="unid != null" > <if test="unid != null" >
...@@ -270,15 +278,18 @@ ...@@ -270,15 +278,18 @@
<if test="longitude != null" > <if test="longitude != null" >
#{longitude,jdbcType=REAL}, #{longitude,jdbcType=REAL},
</if> </if>
<if test="latitude != null" > <if test="latitude != null">
#{latitude,jdbcType=REAL}, #{latitude,jdbcType=REAL},
</if> </if>
<if test="status != null" > <if test="status != null">
#{status,jdbcType=INTEGER}, #{status,jdbcType=INTEGER},
</if> </if>
<if test="createTime != null" > <if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="deviceType != null">
#{deviceType,jdbcType=VARCHAR},
</if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.viontech.fanxing.commons.model.ChannelExample" resultType="java.lang.Integer" > <select id="countByExample" parameterType="com.viontech.fanxing.commons.model.ChannelExample" resultType="java.lang.Integer" >
...@@ -339,17 +350,20 @@ ...@@ -339,17 +350,20 @@
expand = #{record.expand,jdbcType=VARCHAR}, expand = #{record.expand,jdbcType=VARCHAR},
</if> </if>
<if test="record.longitude != null" > <if test="record.longitude != null" >
longitude = #{record.longitude,jdbcType=REAL}, longitude = #{record.longitude,jdbcType=REAL},
</if>
<if test="record.latitude != null" >
latitude = #{record.latitude,jdbcType=REAL},
</if>
<if test="record.status != null" >
`status` = #{record.status,jdbcType=INTEGER},
</if>
<if test="record.createTime != null" >
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="record.latitude != null">
latitude = #{record.latitude,jdbcType=REAL},
</if>
<if test="record.status != null">
`status` = #{record.status,jdbcType=INTEGER},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
<if test="record.deviceType != null">
device_type = #{record.deviceType,jdbcType=VARCHAR},
</if>
</set> </set>
<if test="_parameter != null" > <if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
...@@ -376,8 +390,9 @@ ...@@ -376,8 +390,9 @@
longitude = #{record.longitude,jdbcType=REAL}, longitude = #{record.longitude,jdbcType=REAL},
latitude = #{record.latitude,jdbcType=REAL}, latitude = #{record.latitude,jdbcType=REAL},
`status` = #{record.status,jdbcType=INTEGER}, `status` = #{record.status,jdbcType=INTEGER},
create_time = #{record.createTime,jdbcType=TIMESTAMP} create_time = #{record.createTime,jdbcType=TIMESTAMP},
<if test="_parameter != null" > device_type = #{record.deviceType,jdbcType=VARCHAR}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
</update> </update>
...@@ -432,15 +447,18 @@ ...@@ -432,15 +447,18 @@
<if test="longitude != null" > <if test="longitude != null" >
longitude = #{longitude,jdbcType=REAL}, longitude = #{longitude,jdbcType=REAL},
</if> </if>
<if test="latitude != null" > <if test="latitude != null">
latitude = #{latitude,jdbcType=REAL}, latitude = #{latitude,jdbcType=REAL},
</if> </if>
<if test="status != null" > <if test="status != null">
`status` = #{status,jdbcType=INTEGER}, `status` = #{status,jdbcType=INTEGER},
</if> </if>
<if test="createTime != null" > <if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP}, create_time = #{createTime,jdbcType=TIMESTAMP},
</if> </if>
<if test="deviceType != null">
device_type = #{deviceType,jdbcType=VARCHAR},
</if>
</set> </set>
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
...@@ -464,7 +482,8 @@ ...@@ -464,7 +482,8 @@
longitude = #{longitude,jdbcType=REAL}, longitude = #{longitude,jdbcType=REAL},
latitude = #{latitude,jdbcType=REAL}, latitude = #{latitude,jdbcType=REAL},
`status` = #{status,jdbcType=INTEGER}, `status` = #{status,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP} create_time = #{createTime,jdbcType=TIMESTAMP},
where id = #{id,jdbcType=BIGINT} device_type = #{deviceType,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update> </update>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -4,28 +4,30 @@ ...@@ -4,28 +4,30 @@
<resultMap id="BaseResultMapRoot" type="com.viontech.fanxing.commons.model.ChannelTag" > <resultMap id="BaseResultMapRoot" type="com.viontech.fanxing.commons.model.ChannelTag" >
<id column="channel_tag_id" property="id" /> <id column="channel_tag_id" property="id" />
<result column="channel_tag_channel_id" property="channelId" /> <result column="channel_tag_channel_id" property="channelId" />
<result column="channel_tag_tag_id" property="tagId" /> <result column="channel_tag_tag" property="tag"/>
</resultMap>
<resultMap id="BaseResultMap" type="com.viontech.fanxing.commons.model.ChannelTag" extends="BaseResultMapRoot" >
<result column="channel_id" property="channel.id" />
<result column="channel_unid" property="channel.unid" />
<result column="channel_channel_unid" property="channel.channelUnid" />
<result column="channel_device_unid" property="channel.deviceUnid" />
<result column="channel_type" property="channel.type" />
<result column="channel_stream_type" property="channel.streamType" />
<result column="channel_stream_path" property="channel.streamPath" />
<result column="channel_username" property="channel.username" />
<result column="channel_password" property="channel.password" />
<result column="channel_address_unid" property="channel.addressUnid" />
<result column="channel_name" property="channel.name" />
<result column="channel_ip" property="channel.ip" />
<result column="channel_port" property="channel.port" />
<result column="channel_expand" property="channel.expand" />
<result column="channel_longitude" property="channel.longitude" />
<result column="channel_latitude" property="channel.latitude" />
<result column="channel_status" property="channel.status" />
<result column="channel_create_time" property="channel.createTime" />
</resultMap> </resultMap>
<resultMap id="BaseResultMap" type="com.viontech.fanxing.commons.model.ChannelTag" extends="BaseResultMapRoot">
<result column="channel_id" property="channel.id"/>
<result column="channel_unid" property="channel.unid"/>
<result column="channel_channel_unid" property="channel.channelUnid"/>
<result column="channel_device_unid" property="channel.deviceUnid"/>
<result column="channel_type" property="channel.type"/>
<result column="channel_stream_type" property="channel.streamType"/>
<result column="channel_stream_path" property="channel.streamPath"/>
<result column="channel_username" property="channel.username"/>
<result column="channel_password" property="channel.password"/>
<result column="channel_brand" property="channel.brand"/>
<result column="channel_direction" property="channel.direction"/>
<result column="channel_address_unid" property="channel.addressUnid"/>
<result column="channel_name" property="channel.name"/>
<result column="channel_ip" property="channel.ip"/>
<result column="channel_port" property="channel.port"/>
<result column="channel_expand" property="channel.expand"/>
<result column="channel_longitude" property="channel.longitude"/>
<result column="channel_latitude" property="channel.latitude"/>
<result column="channel_status" property="channel.status"/>
<result column="channel_create_time" property="channel.createTime"/>
</resultMap>
<sql id="Left_Join_List" > <sql id="Left_Join_List" >
<foreach collection="leftJoinTableSet" item="leftJoinTable" > <foreach collection="leftJoinTableSet" item="leftJoinTable" >
<choose > <choose >
...@@ -94,8 +96,9 @@ ...@@ -94,8 +96,9 @@
</where> </where>
</sql> </sql>
<sql id="Base_Column_List_Root" > <sql id="Base_Column_List_Root" >
`channel_tag`.id as channel_tag_id, `channel_tag`.channel_id as channel_tag_channel_id, ` channel_tag `.id as channel_tag_id,
`channel_tag`.tag_id as channel_tag_tag_id ` channel_tag `.channel_id as channel_tag_channel_id,
` channel_tag `.tag as channel_tag_tag
</sql> </sql>
<sql id="Base_Column_List" > <sql id="Base_Column_List" >
<if test="!(_parameter.getClass().getSimpleName() == 'ChannelTagExample')" > <if test="!(_parameter.getClass().getSimpleName() == 'ChannelTagExample')" >
...@@ -159,27 +162,27 @@ ...@@ -159,27 +162,27 @@
</if> </if>
</delete> </delete>
<insert id="insert" parameterType="com.viontech.fanxing.commons.model.ChannelTag" useGeneratedKeys="true" keyProperty="id" keyColumn="id" > <insert id="insert" parameterType="com.viontech.fanxing.commons.model.ChannelTag" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `r_channel_tag` (channel_id, tag_id) insert into `r_channel_tag` (channel_id, tag)
values (#{channelId,jdbcType=BIGINT}, #{tagId,jdbcType=BIGINT}) values (#{channelId,jdbcType=BIGINT}, #{tag,jdbcType=VARCHAR})
</insert> </insert>
<insert id="insertSelective" parameterType="com.viontech.fanxing.commons.model.ChannelTag" useGeneratedKeys="true" keyProperty="id" keyColumn="id" > <insert id="insertSelective" parameterType="com.viontech.fanxing.commons.model.ChannelTag" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `r_channel_tag` insert into `r_channel_tag`
<trim prefix="(" suffix=")" suffixOverrides="," > <trim prefix="(" suffix=")" suffixOverrides=",">
<if test="channelId != null" > <if test="channelId != null">
channel_id, channel_id,
</if> </if>
<if test="tagId != null" > <if test="tag != null">
tag_id, tag,
</if> </if>
</trim> </trim>
<trim prefix="values (" suffix=")" suffixOverrides="," > <trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="channelId != null" > <if test="channelId != null">
#{channelId,jdbcType=BIGINT}, #{channelId,jdbcType=BIGINT},
</if> </if>
<if test="tagId != null" > <if test="tag != null">
#{tagId,jdbcType=BIGINT}, #{tag,jdbcType=VARCHAR},
</if> </if>
</trim> </trim>
</insert> </insert>
<select id="countByExample" parameterType="com.viontech.fanxing.commons.model.ChannelTagExample" resultType="java.lang.Integer" > <select id="countByExample" parameterType="com.viontech.fanxing.commons.model.ChannelTagExample" resultType="java.lang.Integer" >
select count(*) from `r_channel_tag` `channel_tag` select count(*) from `r_channel_tag` `channel_tag`
...@@ -190,46 +193,46 @@ ...@@ -190,46 +193,46 @@
</select> </select>
<update id="updateByExampleSelective" parameterType="map" > <update id="updateByExampleSelective" parameterType="map" >
update `r_channel_tag` `channel_tag` update `r_channel_tag` `channel_tag`
<set > <set>
<if test="record.id != null" > <if test="record.id != null">
id = #{record.id,jdbcType=BIGINT}, id = #{record.id,jdbcType=BIGINT},
</if> </if>
<if test="record.channelId != null" > <if test="record.channelId != null">
channel_id = #{record.channelId,jdbcType=BIGINT}, channel_id = #{record.channelId,jdbcType=BIGINT},
</if> </if>
<if test="record.tagId != null" > <if test="record.tag != null">
tag_id = #{record.tagId,jdbcType=BIGINT}, tag = #{record.tag,jdbcType=VARCHAR},
</if> </if>
</set> </set>
<if test="_parameter != null" > <if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
</update> </update>
<update id="updateByExample" parameterType="map" > <update id="updateByExample" parameterType="map" >
update `r_channel_tag` `channel_tag` update `r_channel_tag` `channel_tag`
set id = #{record.id,jdbcType=BIGINT}, set id = #{record.id,jdbcType=BIGINT},
channel_id = #{record.channelId,jdbcType=BIGINT}, channel_id = #{record.channelId,jdbcType=BIGINT},
tag_id = #{record.tagId,jdbcType=BIGINT} tag = #{record.tag,jdbcType=VARCHAR}
<if test="_parameter != null" > <if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" /> <include refid="Update_By_Example_Where_Clause" />
</if> </if>
</update> </update>
<update id="updateByPrimaryKeySelective" parameterType="com.viontech.fanxing.commons.model.ChannelTag" > <update id="updateByPrimaryKeySelective" parameterType="com.viontech.fanxing.commons.model.ChannelTag" >
update `r_channel_tag` update `r_channel_tag`
<set > <set>
<if test="channelId != null" > <if test="channelId != null">
channel_id = #{channelId,jdbcType=BIGINT}, channel_id = #{channelId,jdbcType=BIGINT},
</if> </if>
<if test="tagId != null" > <if test="tag != null">
tag_id = #{tagId,jdbcType=BIGINT}, tag = #{tag,jdbcType=VARCHAR},
</if> </if>
</set> </set>
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
<update id="updateByPrimaryKey" parameterType="com.viontech.fanxing.commons.model.ChannelTag" > <update id="updateByPrimaryKey" parameterType="com.viontech.fanxing.commons.model.ChannelTag" >
update `r_channel_tag` update `r_channel_tag`
set channel_id = #{channelId,jdbcType=BIGINT}, set channel_id = #{channelId,jdbcType=BIGINT},
tag_id = #{tagId,jdbcType=BIGINT} tag = #{tag,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT} where id = #{id,jdbcType=BIGINT}
</update> </update>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
...@@ -7,14 +7,17 @@ import com.viontech.fanxing.commons.base.BaseMapper; ...@@ -7,14 +7,17 @@ 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.config.VionConfig;
import com.viontech.fanxing.commons.constant.ChannelType; import com.viontech.fanxing.commons.constant.ChannelType;
import com.viontech.fanxing.commons.exception.FanXingException;
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;
import com.viontech.fanxing.commons.vo.DictCodeVo; import com.viontech.fanxing.commons.vo.DictCodeVo;
import com.viontech.fanxing.ops.feign.TaskFeignClient;
import com.viontech.fanxing.ops.mapper.ChannelMapper; import com.viontech.fanxing.ops.mapper.ChannelMapper;
import com.viontech.fanxing.ops.service.adapter.ChannelService; import com.viontech.fanxing.ops.service.adapter.ChannelService;
import com.viontech.fanxing.ops.service.adapter.ChannelTagService; import com.viontech.fanxing.ops.service.adapter.ChannelTagService;
import com.viontech.fanxing.ops.service.adapter.DictCateService; import com.viontech.fanxing.ops.service.adapter.DictCateService;
import com.viontech.fanxing.ops.service.adapter.DictCodeService; import com.viontech.fanxing.ops.service.adapter.DictCodeService;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.ImmutablePair;
...@@ -22,6 +25,7 @@ import org.springframework.stereotype.Service; ...@@ -22,6 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File;
import java.time.Duration; import java.time.Duration;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -39,8 +43,11 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan ...@@ -39,8 +43,11 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
private ChannelTagService channelTagService; private ChannelTagService channelTagService;
@Resource @Resource
private VionConfig vionConfig; private VionConfig vionConfig;
@Resource
private TaskFeignClient taskFeignClient;
@Override @Override
public BaseMapper<Channel> getMapper() { public BaseMapper<Channel> getMapper() {
return channelMapper; return channelMapper;
} }
...@@ -49,7 +56,7 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan ...@@ -49,7 +56,7 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
public List<Channel> selectByExample(BaseExample example) { public List<Channel> selectByExample(BaseExample example) {
List<Channel> channels = getMapper().selectByExample(example); List<Channel> channels = getMapper().selectByExample(example);
for (Channel channel : channels) { for (Channel channel : channels) {
if (ChannelType.FILE.value == channel.getType()) { if (channel.getType() != null && ChannelType.FILE.value == channel.getType()) {
channel.setStreamPath(vionConfig.getImage().getUrlPrefix() + channel.getStreamPath()); channel.setStreamPath(vionConfig.getImage().getUrlPrefix() + channel.getStreamPath());
} }
} }
...@@ -65,6 +72,22 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan ...@@ -65,6 +72,22 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
return channel; return channel;
} }
@Override
public int deleteByPrimaryKey(Object id) {
Channel channel = super.selectByPrimaryKey(id);
JsonMessageUtil.JsonMessage<List<Task>> res = taskFeignClient.getTaskByChannelUnid(channel.getChannelUnid());
if (res.getData().size() > 0) {
throw new FanXingException("设备或文件使用中");
}
if (channel.getType().equals(ChannelType.FILE.value)) {
File file = new File(vionConfig.getImage().getPath() + channel.getStreamPath());
file.delete();
file.deleteOnExit();
}
return super.deleteByPrimaryKey(id);
}
/** /**
* 以树状结构获取所有的组织关系和视频资源 * 以树状结构获取所有的组织关系和视频资源
*/ */
......
...@@ -21,9 +21,10 @@ import org.springframework.web.multipart.MultipartFile; ...@@ -21,9 +21,10 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.IntSummaryStatistics; import java.util.DoubleSummaryStatistics;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -47,7 +48,7 @@ public class VideoService { ...@@ -47,7 +48,7 @@ public class VideoService {
* 上传存储视频文件 * 上传存储视频文件
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void uploadVideo(List<MultipartFile> files, List<Long> tags) { public void uploadVideo(List<MultipartFile> files, List<String> tags) {
for (MultipartFile file : files) { for (MultipartFile file : files) {
String originalFilename = file.getOriginalFilename(); String originalFilename = file.getOriginalFilename();
String basePath = vionConfig.getImage().getPath() + File.separator + "uploadVideo" + File.separator; String basePath = vionConfig.getImage().getPath() + File.separator + "uploadVideo" + File.separator;
...@@ -57,16 +58,8 @@ public class VideoService { ...@@ -57,16 +58,8 @@ public class VideoService {
} }
String unid = UUID.randomUUID().toString(); String unid = UUID.randomUUID().toString();
String filename = unid + "." + extension; String filename = unid + "." + extension;
File video = new File(basePath + filename);
video.getParentFile().mkdirs();
try {
FileUtils.copyToFile(file.getInputStream(), video);
} catch (IOException e) {
throw new RuntimeException(e);
}
long videoLength = video.length(); // 先写库
long mbSize = videoLength / 1024 / 1024;
Channel channel = new Channel(); Channel channel = new Channel();
channel.setUnid(unid); channel.setUnid(unid);
channel.setChannelUnid(unid); channel.setChannelUnid(unid);
...@@ -75,14 +68,28 @@ public class VideoService { ...@@ -75,14 +68,28 @@ public class VideoService {
channel.setStreamPath("/uploadVideo/" + filename); channel.setStreamPath("/uploadVideo/" + filename);
channel.setType(ChannelType.FILE.value); channel.setType(ChannelType.FILE.value);
channel.setStreamType(ChannelType.STREAM_FILE.value); channel.setStreamType(ChannelType.STREAM_FILE.value);
channel.setPort(Math.toIntExact(mbSize));
channel = channelService.insertSelective(channel); channel = channelService.insertSelective(channel);
// 再上文件
File video = new File(basePath + filename);
video.getParentFile().mkdirs();
try {
FileUtils.copyToFile(file.getInputStream(), video);
} catch (IOException e) {
throw new RuntimeException(e);
}
double videoLength = (double) video.length();
double mbSize = videoLength / 1024 / 1024;
// 再更新
channel.setExpand(String.valueOf(mbSize));
channelService.updateByPrimaryKeySelective(channel);
if (tags != null && tags.size() > 0) { if (tags != null && tags.size() > 0) {
for (Long tagId : tags) { for (String tagId : tags) {
ChannelTag channelTag = new ChannelTag(); ChannelTag channelTag = new ChannelTag();
channelTag.setChannelId(channel.getId()); channelTag.setChannelId(channel.getId());
channelTag.setTagId(tagId); channelTag.setTag(tagId);
channelTagService.insertSelective(channelTag); channelTagService.insertSelective(channelTag);
} }
} }
...@@ -91,19 +98,20 @@ public class VideoService { ...@@ -91,19 +98,20 @@ public class VideoService {
/** /**
* 获取录像文件头部概览 * 获取录像文件头部概览
*
* @return
*/ */
@LocalCache(value = "video_overView", duration = 5) @LocalCache(value = "video_overView", duration = 20, timeunit = TimeUnit.SECONDS)
public JSONObject overview() { public JSONObject overview() {
ChannelExample channelExample = new ChannelExample(); ChannelExample channelExample = new ChannelExample();
channelExample.createCriteria().andTypeEqualTo(ChannelType.FILE.value); channelExample.createCriteria().andTypeEqualTo(ChannelType.FILE.value);
channelExample.createColumns().hasPortColumn(); channelExample.createColumns().hasExpandColumn();
List<Channel> channels = channelService.selectByExample(channelExample); List<Channel> channels = channelService.selectByExample(channelExample);
IntSummaryStatistics summary = channels.stream().map(Channel::getPort).collect(Collectors.summarizingInt(x -> x)); DoubleSummaryStatistics summary = channels.stream()
.map(x -> Double.valueOf(StringUtils.isBlank(x.getExpand()) ? "0" : x.getExpand()))
.collect(Collectors.summarizingDouble(x -> x));
JSONObject res = new JSONObject(); JSONObject res = new JSONObject();
res.put("fileCount", summary.getCount()); res.put("fileCount", summary.getCount());
res.put("size", summary.getSum()); res.put("size", summary.getSum());
res.put("unit", "MB");
return res; return res;
} }
} }
...@@ -3,9 +3,12 @@ package com.viontech.fanxing.ops; ...@@ -3,9 +3,12 @@ package com.viontech.fanxing.ops;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.model.DictCode; import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.vo.ChannelVo; import com.viontech.fanxing.commons.vo.ChannelVo;
import com.viontech.fanxing.ops.feign.TaskFeignClient;
import com.viontech.fanxing.ops.service.adapter.ChannelService; import com.viontech.fanxing.ops.service.adapter.ChannelService;
import com.viontech.fanxing.ops.service.adapter.DictCodeService; import com.viontech.fanxing.ops.service.adapter.DictCodeService;
import com.viontech.keliu.util.JsonMessageUtil;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
...@@ -29,6 +32,8 @@ public class MainTest { ...@@ -29,6 +32,8 @@ public class MainTest {
@Resource @Resource
private ChannelService channelService; private ChannelService channelService;
@Resource
private TaskFeignClient taskFeignClient;
@Test @Test
public void nvs3000CodeTest() { public void nvs3000CodeTest() {
...@@ -42,4 +47,11 @@ public class MainTest { ...@@ -42,4 +47,11 @@ public class MainTest {
} }
@Test
public void getTaskByChannelTest() {
JsonMessageUtil.JsonMessage<List<Task>> taskByChannelUnid =
taskFeignClient.getTaskByChannelUnid("5e19f4e3-ee71-44d9-82ad-99391b1031b5");
System.out.println(taskByChannelUnid.toString());
}
} }
...@@ -115,6 +115,11 @@ public class VAServerController { ...@@ -115,6 +115,11 @@ public class VAServerController {
return vaServerService.getRotationStatus(taskUnid); return vaServerService.getRotationStatus(taskUnid);
} }
@GetMapping("/getCurrentScene")
public Object getCurrentScene(@RequestParam String taskUnid) {
return vaServerService.getCurrentScene(taskUnid);
}
/** /**
* @param type 任务的类型 0 交通, 1 客流, 2 安防, 3 违停, 4 人脸 * @param type 任务的类型 0 交通, 1 客流, 2 安防, 3 违停, 4 人脸
*/ */
......
package com.viontech.fanxing.task.controller.web; package com.viontech.fanxing.task.controller.web;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample; import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseModel; import com.viontech.fanxing.commons.base.BaseModel;
import com.viontech.fanxing.commons.model.Task; import com.viontech.fanxing.commons.model.Task;
...@@ -15,6 +16,8 @@ import java.util.List; ...@@ -15,6 +16,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg;
@RestController @RestController
@RequestMapping("/tasks") @RequestMapping("/tasks")
@Slf4j @Slf4j
...@@ -27,6 +30,24 @@ public class TaskController extends TaskBaseController { ...@@ -27,6 +30,24 @@ public class TaskController extends TaskBaseController {
return taskExample; return taskExample;
} }
@Override
@RequestMapping(value = "", method = RequestMethod.GET)
@ResponseBody
public Object page(TaskVo taskVo, @RequestParam(value = "page", defaultValue = "-1") int page, @RequestParam(value = "pageSize", defaultValue = "100") int pageSize, String sortName, String sortOrder) {
BaseExample baseExample = getExample(taskVo, EXAMPLE_TYPE_PAGE);
if (isNotNull(sortOrder) && isNotNull(sortName)) {
baseExample.setOrderByClause(baseExample.getTableAlias() + "." + sortName + " " + sortOrder);
} else if (isNotNull(sortName) && !isNotNull(sortOrder)) {
baseExample.setOrderByClause(sortName);
}
if (page <= 0) {
List result = taskService.selectByExample(baseExample);
return getSuccessJsonMsg(MESSAGE_SELECT_SUCCESS, result);
} else {
PageInfo pageInfo = getService().pagedQuery(baseExample, page, pageSize);
return getSuccessJsonMsg(MESSAGE_PAGE_SUCCESS, pageInfo);
}
}
@PostMapping @PostMapping
@Override @Override
......
...@@ -17,14 +17,14 @@ import java.util.UUID; ...@@ -17,14 +17,14 @@ import java.util.UUID;
@Setter @Setter
@Accessors(chain = true) @Accessors(chain = true)
public class Scene { public class Scene {
private String algo_type; private Integer algo_type;
/** 标定,后端不需要关心 */ /** 标定,后端不需要关心 */
private Calibration calibration; private Calibration calibration;
/** 配置信息 */ /** 配置信息 */
private Config config; private Config config;
private String position_name; private String position_name;
private String position_num; private String position_num;
private String scene_unid = UUID.randomUUID().toString(); private String scene_unid;
private String vchan_refid; private String vchan_refid;
private Integer runtime = -1; private Integer runtime = -1;
private PlayUrls play_urls; private PlayUrls play_urls;
......
...@@ -24,7 +24,7 @@ public class VATask { ...@@ -24,7 +24,7 @@ public class VATask {
private String task_unid; private String task_unid;
private String task_name; private String task_name;
private String alg_type; private Integer alg_type;
private String store_config; private String store_config;
private String channel_unid; private String channel_unid;
private String stream_path; private String stream_path;
...@@ -35,7 +35,7 @@ public class VATask { ...@@ -35,7 +35,7 @@ public class VATask {
Task task = taskData.getTask(); Task task = taskData.getTask();
this.task_unid = task.getUnid(); this.task_unid = task.getUnid();
this.task_name = task.getName(); this.task_name = task.getName();
this.alg_type = task.getAlgType(); this.alg_type = Integer.parseInt(task.getAlgType());
this.store_config = taskData.getStoreConfig(); this.store_config = taskData.getStoreConfig();
this.channel_unid = task.getChannelUnid(); this.channel_unid = task.getChannelUnid();
this.stream_path = task.getStreamPath(); this.stream_path = task.getStreamPath();
......
package com.viontech.fanxing.task.repository; package com.viontech.fanxing.task.repository;
import com.viontech.fanxing.commons.constant.RedisKeys; import com.viontech.fanxing.commons.constant.RedisKeys;
import com.viontech.fanxing.task.model.vaserver.VaServerInfo;
import com.viontech.fanxing.commons.service.RedisService; import com.viontech.fanxing.commons.service.RedisService;
import com.viontech.fanxing.task.model.vaserver.VaServerInfo;
import org.redisson.api.RBucket; import org.redisson.api.RBucket;
import org.redisson.api.RLock;
import org.redisson.api.RMap; import org.redisson.api.RMap;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -62,5 +63,9 @@ public class VAServerRedisRepository { ...@@ -62,5 +63,9 @@ public class VAServerRedisRepository {
return bucket.isExists(); return bucket.isExists();
} }
public RLock getDevLock(String devId) {
return redisService.getLockMust("lock:vaserver:" + devId);
}
} }
package com.viontech.fanxing.task.runner; package com.viontech.fanxing.task.runner;
import com.viontech.fanxing.commons.constant.TaskStatus;
import com.viontech.fanxing.commons.model.Task; import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.model.TaskExample; import com.viontech.fanxing.commons.model.TaskExample;
import com.viontech.fanxing.task.mapper.TaskMapper; import com.viontech.fanxing.task.mapper.TaskMapper;
...@@ -38,7 +39,7 @@ public class TaskInitRunner implements CommandLineRunner { ...@@ -38,7 +39,7 @@ public class TaskInitRunner implements CommandLineRunner {
List<Task> tasks = taskMapper.selectByExampleWithBLOBs(new TaskExample()); List<Task> tasks = taskMapper.selectByExampleWithBLOBs(new TaskExample());
for (Task task : tasks) { for (Task task : tasks) {
if (StringUtils.isNotBlank(task.getScene()) && task.getStoreConfigId() != null) { if (StringUtils.isNotBlank(task.getScene()) && task.getStoreConfigId() != null && !TaskStatus.PAUSE.valEqual(task.getStatus())) {
try { try {
TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(task.getUnid()); TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(task.getUnid());
if (taskData == null) { if (taskData == null) {
......
...@@ -10,6 +10,7 @@ import com.viontech.fanxing.task.service.TaskDataService; ...@@ -10,6 +10,7 @@ import com.viontech.fanxing.task.service.TaskDataService;
import com.viontech.fanxing.task.service.VAServerService; import com.viontech.fanxing.task.service.VAServerService;
import com.viontech.fanxing.task.service.adapter.TaskService; import com.viontech.fanxing.task.service.adapter.TaskService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock; import org.redisson.api.RLock;
import org.redisson.api.RMap; import org.redisson.api.RMap;
import org.redisson.api.RScoredSortedSet; import org.redisson.api.RScoredSortedSet;
...@@ -71,8 +72,14 @@ public class TaskRunner { ...@@ -71,8 +72,14 @@ public class TaskRunner {
if (temp.getStatus() == 0) { if (temp.getStatus() == 0) {
continue; continue;
} }
// 指定了VAServer
if (StringUtils.isNotBlank(taskVaType)) {
if (!taskVaType.equals(temp.getServiceName())) {
continue;
}
}
if (temp.getAvailableResources() > resourceNeed) { if (temp.getAvailableResources() > resourceNeed) {
devLock = redisService.getLockMust("lock:vaserver:" + devId); devLock = vaServerService.getVaServerRedisRepository().getDevLock(devId);
temp = vaServerMap.get(devId); temp = vaServerMap.get(devId);
if (temp.getAvailableResources() > resourceNeed) { if (temp.getAvailableResources() > resourceNeed) {
server = temp; server = temp;
......
package com.viontech.fanxing.task.runner;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.task.model.vaserver.VaServerInfo;
import com.viontech.fanxing.task.service.VAServerService;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RMap;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Map;
import java.util.Set;
/**
* .
*
* @author 谢明辉
* @date 2021/10/19
*/
@Component
@Slf4j
public class VaServerCheckRunner {
@Resource
private VAServerService vaServerService;
@Scheduled(cron = "3 0/5 * * * ? ")
public void check() {
try {
RMap<String, VaServerInfo> vaServerInfoMap = vaServerService.getVaServerRedisRepository().getVaServerInfoMap();
Set<Map.Entry<String, VaServerInfo>> entries = vaServerInfoMap.readAllEntrySet();
for (Map.Entry<String, VaServerInfo> entry : entries) {
RLock devLock = null;
try {
String devId = entry.getKey();
VaServerInfo vaServerInfo = entry.getValue();
if (vaServerInfo.getStatus() == 1) {
devLock = vaServerService.getVaServerRedisRepository().getDevLock(devId);
JSONObject status = vaServerService.getStatus(devId);
JSONObject resource = status.getJSONObject("resource");
JSONObject brief = resource.getJSONObject("brief");
float videoResource = brief.getFloatValue("video_total");
float availableResource = brief.getFloatValue("video_free");
vaServerInfo.setAvailableResources(availableResource);
vaServerInfo.setVideoResource(videoResource);
vaServerService.getVaServerRedisRepository().addOrUpdate(devId, vaServerInfo);
} else {
log.info("设备处于离线状态:{}", devId);
}
} catch (Exception e) {
log.info("", e);
if (devLock != null) {
devLock.forceUnlock();
}
}
}
} catch (Exception e) {
log.error("", e);
}
}
}
...@@ -119,12 +119,14 @@ public class TaskDataService { ...@@ -119,12 +119,14 @@ public class TaskDataService {
public void updateTask(Task task) { public void updateTask(Task task) {
String taskUnid = task.getUnid(); String taskUnid = task.getUnid();
VaServerInfo vaServerInfo = taskRunOn(taskUnid); VaServerInfo vaServerInfo = taskRunOn(taskUnid);
// vaServerId 为空说明任务未执行可以先删除再建立新任务 // vaServerId 为空说明任务未执行可以先删除再建立新任务
if (vaServerInfo == null) { if (vaServerInfo == null) {
deleteTask(taskUnid); deleteTask(taskUnid);
addTask(task); addTask(task);
} else if (vaServerInfo.getStatus() == 0) {
throw new FanXingException("设备离线");
} else { } else {
TaskData taskData = new TaskData(task); TaskData taskData = new TaskData(task);
// 需要更新taskData,并且向vaServer更新任务信息 // 需要更新taskData,并且向vaServer更新任务信息
taskDataRedisRepository.addOrUpdateTaskData(taskData); taskDataRedisRepository.addOrUpdateTaskData(taskData);
......
...@@ -28,7 +28,7 @@ public class VAServerHttpService { ...@@ -28,7 +28,7 @@ public class VAServerHttpService {
/** /**
* 下发任务 * 下发任务
*/ */
public Object addTask(TaskData taskData, VaServerInfo vaServerInfo) { public JSONObject addTask(TaskData taskData, VaServerInfo vaServerInfo) {
VATask vaTask = new VATask(taskData); VATask vaTask = new VATask(taskData);
String path = "/api/vaserver/v1/task"; String path = "/api/vaserver/v1/task";
Mono<String> stringMono = WebClient.create(vaServerInfo.getServiceBaseUrl()) Mono<String> stringMono = WebClient.create(vaServerInfo.getServiceBaseUrl())
...@@ -45,7 +45,7 @@ public class VAServerHttpService { ...@@ -45,7 +45,7 @@ public class VAServerHttpService {
/** /**
* 编辑任务 * 编辑任务
*/ */
public Object updateTask(TaskData taskData, VaServerInfo vaServerInfo) { public JSONObject updateTask(TaskData taskData, VaServerInfo vaServerInfo) {
String path = "/api/vaserver/v1/task"; String path = "/api/vaserver/v1/task";
VATask vaTask = new VATask(taskData); VATask vaTask = new VATask(taskData);
...@@ -63,7 +63,7 @@ public class VAServerHttpService { ...@@ -63,7 +63,7 @@ public class VAServerHttpService {
/** /**
* 删除任务 * 删除任务
*/ */
public Object rmTask(String taskUnid, VaServerInfo vaServerInfo) { public JSONObject rmTask(String taskUnid, VaServerInfo vaServerInfo) {
String path = "/api/vaserver/v1/deleteTask"; String path = "/api/vaserver/v1/deleteTask";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
...@@ -83,7 +83,7 @@ public class VAServerHttpService { ...@@ -83,7 +83,7 @@ public class VAServerHttpService {
/** /**
* 截图 * 截图
*/ */
public Object snapshot(String taskUnid, VaServerInfo vaServerInfo) { public JSONObject snapshot(String taskUnid, VaServerInfo vaServerInfo) {
String path = "/api/vaserver/v1/snapshot"; String path = "/api/vaserver/v1/snapshot";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
...@@ -103,7 +103,7 @@ public class VAServerHttpService { ...@@ -103,7 +103,7 @@ public class VAServerHttpService {
/** /**
* 获取点播地址 * 获取点播地址
*/ */
public Object getAnalyzeStream(String taskUnid, VaServerInfo vaServerInfo) { public JSONObject getAnalyzeStream(String taskUnid, VaServerInfo vaServerInfo) {
String path = "/api/vaserver/v1/get_analyze_stream"; String path = "/api/vaserver/v1/get_analyze_stream";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
...@@ -124,7 +124,7 @@ public class VAServerHttpService { ...@@ -124,7 +124,7 @@ public class VAServerHttpService {
/** /**
* 开始输出分析流 * 开始输出分析流
*/ */
public Object startAnalyzeStream(String taskUnid, VaServerInfo vaServerInfo, String url) { public JSONObject startAnalyzeStream(String taskUnid, VaServerInfo vaServerInfo, String url) {
String path = "/api/vaserver/v1/start_analyze_stream"; String path = "/api/vaserver/v1/start_analyze_stream";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
...@@ -147,7 +147,7 @@ public class VAServerHttpService { ...@@ -147,7 +147,7 @@ public class VAServerHttpService {
/** /**
* 切换预置位 * 切换预置位
*/ */
public Object switchScene(String taskUnid, VaServerInfo vaServerInfo, String sceneId) { public JSONObject switchScene(String taskUnid, VaServerInfo vaServerInfo, String sceneId) {
String path = "/api/vaserver/v1/switch_scene"; String path = "/api/vaserver/v1/switch_scene";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
...@@ -169,7 +169,7 @@ public class VAServerHttpService { ...@@ -169,7 +169,7 @@ public class VAServerHttpService {
/** /**
* 任务轮训状态切换 * 任务轮训状态切换
*/ */
public Object updateRotationStatus(String taskUnid, Integer rotationStatus, VaServerInfo vaServerInfo) { public JSONObject updateRotationStatus(String taskUnid, Integer rotationStatus, VaServerInfo vaServerInfo) {
String path = "/api/vaserver/v1/alternate"; String path = "/api/vaserver/v1/alternate";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
...@@ -191,7 +191,7 @@ public class VAServerHttpService { ...@@ -191,7 +191,7 @@ public class VAServerHttpService {
/** /**
* 任务轮训状态查询 * 任务轮训状态查询
*/ */
public Object getRotationStatus(String taskUnid, VaServerInfo vaServerInfo) { public JSONObject getRotationStatus(String taskUnid, VaServerInfo vaServerInfo) {
String path = "/api/vaserver/v1/getAlternate"; String path = "/api/vaserver/v1/getAlternate";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
...@@ -212,7 +212,7 @@ public class VAServerHttpService { ...@@ -212,7 +212,7 @@ public class VAServerHttpService {
/** /**
* 运行状态查询 * 运行状态查询
*/ */
public Object status(VaServerInfo vaServerInfo) { public JSONObject status(VaServerInfo vaServerInfo) {
String path = "/api/vaserver/v1/status"; String path = "/api/vaserver/v1/status";
Mono<String> stringMono = WebClient.create(vaServerInfo.getServiceBaseUrl()) Mono<String> stringMono = WebClient.create(vaServerInfo.getServiceBaseUrl())
...@@ -231,7 +231,7 @@ public class VAServerHttpService { ...@@ -231,7 +231,7 @@ public class VAServerHttpService {
/** /**
* 获取默认算法配置 * 获取默认算法配置
*/ */
public Object getDefaultAlgorithmConfig(VaServerInfo vaServerInfo, String taskAlgType) { public JSONObject getDefaultAlgorithmConfig(VaServerInfo vaServerInfo, String taskAlgType) {
String path = "/api/vaserver/v1/get_algo_param_template"; String path = "/api/vaserver/v1/get_algo_param_template";
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("task_algo_type", taskAlgType); jsonObject.put("task_algo_type", taskAlgType);
...@@ -249,4 +249,24 @@ public class VAServerHttpService { ...@@ -249,4 +249,24 @@ public class VAServerHttpService {
} }
/**
* 获取任务当前预置位
*/
public JSONObject getCurrentScene(String taskUnid, VaServerInfo vaServerInfo) {
String path = "/api/vaserver/v1/get_current_scene";
JSONObject obj = new JSONObject();
obj.put("task_unid", taskUnid);
Mono<String> mono = WebClient.create(vaServerInfo.getServiceBaseUrl())
.post()
.uri(path)
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.bodyValue(obj)
.retrieve()
.bodyToMono(String.class);
String block = mono.block(Duration.ofSeconds(20));
log.info("获取当前预置位:{}", block);
return JSON.parseObject(block);
}
} }
package com.viontech.fanxing.task.service; package com.viontech.fanxing.task.service;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.constant.RedisKeys; import com.viontech.fanxing.commons.constant.RedisKeys;
import com.viontech.fanxing.commons.exception.FanXingException; import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.Task; import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.service.RedisService; import com.viontech.fanxing.commons.service.RedisService;
import com.viontech.fanxing.task.model.TaskData; import com.viontech.fanxing.task.model.TaskData;
import com.viontech.fanxing.task.repository.VAServerRedisRepository;
import com.viontech.fanxing.task.model.vaserver.VaServerInfo; import com.viontech.fanxing.task.model.vaserver.VaServerInfo;
import com.viontech.fanxing.task.repository.VAServerRedisRepository;
import org.redisson.api.RBucket; import org.redisson.api.RBucket;
import org.redisson.api.RLock; import org.redisson.api.RLock;
import org.redisson.api.RMap; import org.redisson.api.RMap;
...@@ -40,23 +41,25 @@ public class VAServerService { ...@@ -40,23 +41,25 @@ public class VAServerService {
*/ */
public void registerVAServer(VaServerInfo vaServerInfo) { public void registerVAServer(VaServerInfo vaServerInfo) {
String devId = vaServerInfo.getDevID(); String devId = vaServerInfo.getDevID();
keepalive(devId);
vaServerRedisRepository.addOrUpdate(devId, vaServerInfo); vaServerRedisRepository.addOrUpdate(devId, vaServerInfo);
keepalive(devId);
} }
/** /**
* 设备心跳 * 设备心跳
*/ */
public void keepalive(String devId) { public void keepalive(String devId) {
RBucket<Date> bucket = redisService.getValue(RedisKeys.getVAServerKeepAliveKey(devId));
bucket.set(new Date());
bucket.expire(2, TimeUnit.MINUTES);
VaServerInfo vaserverInfo = vaServerRedisRepository.getVAServerInfoById(devId); VaServerInfo vaserverInfo = vaServerRedisRepository.getVAServerInfoById(devId);
if (vaserverInfo != null) { if (vaserverInfo != null) {
vaserverInfo.setStatus(1); vaserverInfo.setStatus(1);
vaServerRedisRepository.addOrUpdate(devId, vaserverInfo); vaServerRedisRepository.addOrUpdate(devId, vaserverInfo);
} else {
throw new FanXingException("设备未注册");
} }
RBucket<Date> bucket = redisService.getValue(RedisKeys.getVAServerKeepAliveKey(devId));
bucket.set(new Date());
bucket.expire(2, TimeUnit.MINUTES);
} }
...@@ -86,7 +89,7 @@ public class VAServerService { ...@@ -86,7 +89,7 @@ public class VAServerService {
public boolean terminateTask(String taskUnid) { public boolean terminateTask(String taskUnid) {
TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(taskUnid); TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(taskUnid);
if (taskData == null) { if (taskData == null) {
return false; return true;
} }
Task task = taskData.getTask(); Task task = taskData.getTask();
...@@ -180,7 +183,7 @@ public class VAServerService { ...@@ -180,7 +183,7 @@ public class VAServerService {
/** /**
* 获取 VAServer 运行状态配置参数等 * 获取 VAServer 运行状态配置参数等
*/ */
public Object getStatus(String devId) { public JSONObject getStatus(String devId) {
VaServerInfo vaServerInfo = vaServerRedisRepository.getVAServerInfoById(devId); VaServerInfo vaServerInfo = vaServerRedisRepository.getVAServerInfoById(devId);
if (vaServerInfo != null) { if (vaServerInfo != null) {
return vaServerHttpService.status(vaServerInfo); return vaServerHttpService.status(vaServerInfo);
...@@ -225,6 +228,15 @@ public class VAServerService { ...@@ -225,6 +228,15 @@ public class VAServerService {
} }
} }
public JSONObject getCurrentScene(String taskUnid) {
VaServerInfo vaServerInfo = taskDataService.taskRunOn(taskUnid);
if (vaServerInfo != null) {
return vaServerHttpService.getCurrentScene(taskUnid, vaServerInfo);
} else {
throw new FanXingException("任务不在运行状态", taskUnid);
}
}
public Object getDefaultAlgorithmConfig(String taskAlgType) { public Object getDefaultAlgorithmConfig(String taskAlgType) {
RMap<String, VaServerInfo> map = vaServerRedisRepository.getVaServerInfoMap(); RMap<String, VaServerInfo> map = vaServerRedisRepository.getVaServerInfoMap();
VaServerInfo temp = null; VaServerInfo temp = null;
......
...@@ -2,6 +2,10 @@ package com.viontech.fanxing.task.service.impl; ...@@ -2,6 +2,10 @@ package com.viontech.fanxing.task.service.impl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
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.base.LocalCache; import com.viontech.fanxing.commons.base.LocalCache;
...@@ -27,6 +31,8 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -27,6 +31,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Service @Service
public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskService { public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskService {
...@@ -46,6 +52,28 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic ...@@ -46,6 +52,28 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
return taskMapper; return taskMapper;
} }
@Override
public List<Task> selectByExample(BaseExample example) {
return taskMapper.selectByExampleWithBLOBs((TaskExample) example);
}
@Override
public PageInfo<Task> pagedQuery(BaseExample example, int pageNum, int pageSize) {
if (pageSize > 0) {
PageHelper.startPage(pageNum, pageSize);
Page<Task> result = (Page<Task>) taskMapper.selectByExampleWithBLOBs((TaskExample) example);
PageInfo<Task> pageInfo = new PageInfo<Task>(result);
return pageInfo;
} else {
List<Task> result = taskMapper.selectByExampleWithBLOBs((TaskExample) example);
Page<Task> p = new Page<>();
p.addAll(result);
PageInfo<Task> pageInfo = new PageInfo<>(p);
return pageInfo;
}
}
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public TaskVo addTask(Task task) { public TaskVo addTask(Task task) {
...@@ -100,7 +128,8 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic ...@@ -100,7 +128,8 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
.setPosition_num(String.valueOf(i)) .setPosition_num(String.valueOf(i))
.setPosition_name(String.valueOf(i)) .setPosition_name(String.valueOf(i))
.setVchan_refid(channelUnid) .setVchan_refid(channelUnid)
.setAlgo_type(algType) .setScene_unid(UUID.randomUUID().toString())
.setAlgo_type(Integer.parseInt(algType))
.setConfig(config) .setConfig(config)
.setPlay_urls(playUrls); .setPlay_urls(playUrls);
if (streamPath.contains("http")) { if (streamPath.contains("http")) {
...@@ -181,7 +210,7 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic ...@@ -181,7 +210,7 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
} }
@Override @Override
@LocalCache(value = "task_overview", duration = 3) @LocalCache(value = "task_overview", duration = 30, timeunit = TimeUnit.SECONDS)
public JSONObject overview() { public JSONObject overview() {
List<Task> tasks = selectByExample(new TaskExample()); List<Task> tasks = selectByExample(new TaskExample());
int resourceCount = 0; int resourceCount = 0;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!