Commit 2737dc87 by xmh

Channel 增加字段 deviceType

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

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

任务服务整体调整
1 parent f7e3280c
Showing 31 changed files with 615 additions and 224 deletions
......@@ -46,13 +46,15 @@ public class Channel extends BaseModel {
private Date createTime;
private List<Long> tags;
private String deviceType;
public List<Long> getTags() {
private List<String> tags;
public List<String> getTags() {
return tags;
}
public Channel setTags(List<Long> tags) {
public Channel setTags(List<String> tags) {
this.tags = tags;
return this;
}
......@@ -216,4 +218,12 @@ public class Channel extends BaseModel {
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
}
\ No newline at end of file
......@@ -1408,6 +1408,76 @@ public class ChannelExample extends BaseExample {
addCriterion("`channel`.create_time not between", value1, value2, "createTime");
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 {
......@@ -1515,5 +1585,10 @@ public class ChannelExample extends BaseExample {
addColumnStr("`channel`.create_time as channel_create_time ");
return (ColumnContainer) this;
}
public ColumnContainer hasDeviceTypeColumn() {
addColumnStr("`channel`.device_type as channel_device_type ");
return (ColumnContainer) this;
}
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ public class ChannelTag extends BaseModel {
private Long channelId;
private Long tagId;
private String tag;
private Channel channel;
......@@ -27,12 +27,12 @@ public class ChannelTag extends BaseModel {
this.channelId = channelId;
}
public Long getTagId() {
return tagId;
public String getTag() {
return tag;
}
public void setTagId(Long tagId) {
this.tagId = tagId;
public void setTag(String tag) {
this.tag = tag == null ? null : tag.trim();
}
public Channel getChannel() {
......
......@@ -250,63 +250,73 @@ public class ChannelTagExample extends BaseExample {
return (Criteria) this;
}
public Criteria andTagIdIsNull() {
addCriterion("`channel_tag`.tag_id is null");
public Criteria andTagIsNull() {
addCriterion("`channel_tag`.tag is null");
return (Criteria) this;
}
public Criteria andTagIdIsNotNull() {
addCriterion("`channel_tag`.tag_id is not null");
public Criteria andTagIsNotNull() {
addCriterion("`channel_tag`.tag is not null");
return (Criteria) this;
}
public Criteria andTagIdEqualTo(Long value) {
addCriterion("`channel_tag`.tag_id =", value, "tagId");
public Criteria andTagEqualTo(String value) {
addCriterion("`channel_tag`.tag =", value, "tag");
return (Criteria) this;
}
public Criteria andTagIdNotEqualTo(Long value) {
addCriterion("`channel_tag`.tag_id <>", value, "tagId");
public Criteria andTagNotEqualTo(String value) {
addCriterion("`channel_tag`.tag <>", value, "tag");
return (Criteria) this;
}
public Criteria andTagIdGreaterThan(Long value) {
addCriterion("`channel_tag`.tag_id >", value, "tagId");
public Criteria andTagGreaterThan(String value) {
addCriterion("`channel_tag`.tag >", value, "tag");
return (Criteria) this;
}
public Criteria andTagIdGreaterThanOrEqualTo(Long value) {
addCriterion("`channel_tag`.tag_id >=", value, "tagId");
public Criteria andTagGreaterThanOrEqualTo(String value) {
addCriterion("`channel_tag`.tag >=", value, "tag");
return (Criteria) this;
}
public Criteria andTagIdLessThan(Long value) {
addCriterion("`channel_tag`.tag_id <", value, "tagId");
public Criteria andTagLessThan(String value) {
addCriterion("`channel_tag`.tag <", value, "tag");
return (Criteria) this;
}
public Criteria andTagIdLessThanOrEqualTo(Long value) {
addCriterion("`channel_tag`.tag_id <=", value, "tagId");
public Criteria andTagLessThanOrEqualTo(String value) {
addCriterion("`channel_tag`.tag <=", value, "tag");
return (Criteria) this;
}
public Criteria andTagIdIn(List<Long> values) {
addCriterion("`channel_tag`.tag_id in", values, "tagId");
public Criteria andTagLike(String value) {
addCriterion("`channel_tag`.tag like", value, "tag");
return (Criteria) this;
}
public Criteria andTagIdNotIn(List<Long> values) {
addCriterion("`channel_tag`.tag_id not in", values, "tagId");
public Criteria andTagNotLike(String value) {
addCriterion("`channel_tag`.tag not like", value, "tag");
return (Criteria) this;
}
public Criteria andTagIdBetween(Long value1, Long value2) {
addCriterion("`channel_tag`.tag_id between", value1, value2, "tagId");
public Criteria andTagIn(List<String> values) {
addCriterion("`channel_tag`.tag in", values, "tag");
return (Criteria) this;
}
public Criteria andTagIdNotBetween(Long value1, Long value2) {
addCriterion("`channel_tag`.tag_id not between", value1, value2, "tagId");
public Criteria andTagNotIn(List<String> values) {
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;
}
}
......@@ -327,8 +337,8 @@ public class ChannelTagExample extends BaseExample {
return (ColumnContainer) this;
}
public ColumnContainer hasTagIdColumn() {
addColumnStr("`channel_tag`.tag_id as channel_tag_tag_id ");
public ColumnContainer hasTagColumn() {
addColumnStr("`channel_tag`.tag as channel_tag_tag ");
return (ColumnContainer) this;
}
}
......
......@@ -40,19 +40,10 @@ public class ChannelTagVoBase extends ChannelTag implements VoInterface<ChannelT
private Long channelId_lte;
@JsonIgnore
private ArrayList<Long> tagId_arr;
private ArrayList<String> tag_arr;
@JsonIgnore
private Long tagId_gt;
@JsonIgnore
private Long tagId_lt;
@JsonIgnore
private Long tagId_gte;
@JsonIgnore
private Long tagId_lte;
private String tag_like;
public ChannelTagVoBase() {
this(null);
......@@ -176,64 +167,40 @@ public class ChannelTagVoBase extends ChannelTag implements VoInterface<ChannelT
}
public void setChannelId(Long channelId) {
if(getModel() == null ){
if (getModel() == null) {
throw new RuntimeException("model is null");
}
this.getModel().setChannelId(channelId);
}
public ArrayList<Long> getTagId_arr() {
return tagId_arr;
}
public void setTagId_arr(ArrayList<Long> tagId_arr) {
this.tagId_arr = tagId_arr;
}
public Long getTagId_gt() {
return tagId_gt;
public ArrayList<String> getTag_arr() {
return tag_arr;
}
public void setTagId_gt(Long tagId_gt) {
this.tagId_gt = tagId_gt;
public void setTag_arr(ArrayList<String> tag_arr) {
this.tag_arr = tag_arr;
}
public Long getTagId_lt() {
return tagId_lt;
public String getTag_like() {
return tag_like;
}
public void setTagId_lt(Long tagId_lt) {
this.tagId_lt = tagId_lt;
public void setTag_like(String tag_like) {
this.tag_like = tag_like;
}
public Long getTagId_gte() {
return tagId_gte;
}
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 ){
public String getTag() {
if (getModel() == null) {
throw new RuntimeException("model is null");
}
return this.getModel().getTagId();
return this.getModel().getTag();
}
public void setTagId(Long tagId) {
if(getModel() == null ){
public void setTag(String tag) {
if (getModel() == null) {
throw new RuntimeException("model is null");
}
this.getModel().setTagId(tagId);
this.getModel().setTag(tag);
}
public Channel getChannel() {
......
......@@ -243,12 +243,21 @@ public class ChannelVoBase extends Channel implements VoInterface<Channel> {
@JsonIgnore
private Date createTime_lte;
@JsonIgnore
private Boolean deviceType_null;
@JsonIgnore
private ArrayList<String> deviceType_arr;
@JsonIgnore
private String deviceType_like;
public ChannelVoBase() {
this(null);
}
public ChannelVoBase(Channel channel) {
if(channel == null) {
if (channel == null) {
channel = new Channel();
}
this.channel = channel;
......@@ -1161,9 +1170,47 @@ public class ChannelVoBase extends Channel implements VoInterface<Channel> {
}
public void setCreateTime(Date createTime) {
if(getModel() == null ){
if (getModel() == null) {
throw new RuntimeException("model is null");
}
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
......@@ -44,8 +44,8 @@ public class ForwardApp {
@Bean
public TaskExecutor taskExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
threadPoolTaskExecutor.setMaxPoolSize(30);
threadPoolTaskExecutor.setCorePoolSize(10);
threadPoolTaskExecutor.setMaxPoolSize(50);
threadPoolTaskExecutor.setCorePoolSize(20);
threadPoolTaskExecutor.setThreadNamePrefix("fanxing-forward-process-");
return threadPoolTaskExecutor;
}
......
......@@ -25,6 +25,16 @@ spring:
- Path=/auth-serv/**
filters:
- 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:
# 服务发现配置
discovery:
......
......@@ -2,12 +2,13 @@ package com.viontech.fanxing.ops.controller.base;
import com.viontech.fanxing.commons.base.BaseController;
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.model.Channel;
import com.viontech.fanxing.commons.model.ChannelExample;
import com.viontech.fanxing.commons.vo.ChannelVo;
import com.viontech.fanxing.ops.mapper.ChannelMapper;
import com.viontech.fanxing.ops.service.adapter.ChannelService;
import javax.annotation.Resource;
public abstract class ChannelBaseController extends BaseController<Channel, ChannelVo> {
......@@ -368,6 +369,22 @@ public abstract class ChannelBaseController extends BaseController<Channel, Chan
if (channelVo.getCreateTime_lte() != null) {
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;
}
......
......@@ -46,32 +46,23 @@ public abstract class ChannelTagBaseController extends BaseController<ChannelTag
if(channelTagVo.getChannelId_gt() != null) {
criteria.andChannelIdGreaterThan(channelTagVo.getChannelId_gt());
}
if(channelTagVo.getChannelId_lt() != null) {
if (channelTagVo.getChannelId_lt() != null) {
criteria.andChannelIdLessThan(channelTagVo.getChannelId_lt());
}
if(channelTagVo.getChannelId_gte() != null) {
if (channelTagVo.getChannelId_gte() != null) {
criteria.andChannelIdGreaterThanOrEqualTo(channelTagVo.getChannelId_gte());
}
if(channelTagVo.getChannelId_lte() != null) {
if (channelTagVo.getChannelId_lte() != null) {
criteria.andChannelIdLessThanOrEqualTo(channelTagVo.getChannelId_lte());
}
if(channelTagVo.getTagId() != null) {
criteria.andTagIdEqualTo(channelTagVo.getTagId());
if (channelTagVo.getTag() != null) {
criteria.andTagEqualTo(channelTagVo.getTag());
}
if(channelTagVo.getTagId_arr() != null) {
criteria.andTagIdIn(channelTagVo.getTagId_arr());
if (channelTagVo.getTag_arr() != null) {
criteria.andTagIn(channelTagVo.getTag_arr());
}
if(channelTagVo.getTagId_gt() != null) {
criteria.andTagIdGreaterThan(channelTagVo.getTagId_gt());
}
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());
if (channelTagVo.getTag_like() != null) {
criteria.andTagLike(channelTagVo.getTag_like());
}
return channelTagExample;
}
......
......@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.ops.service.main.VideoService;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
......@@ -26,8 +27,12 @@ public class VideoController {
private VideoService videoService;
@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) {
try {
videoService.uploadVideo(files, tags);
} catch (DuplicateKeyException e) {
return JsonMessageUtil.getErrorJsonMsg("设备编号或名称重复");
}
return JsonMessageUtil.getSuccessJsonMsg("success");
}
......
......@@ -14,8 +14,9 @@ import com.viontech.fanxing.ops.controller.base.ChannelBaseController;
import com.viontech.fanxing.ops.service.adapter.ChannelTagService;
import com.viontech.keliu.util.JsonMessageUtil;
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.multipart.MultipartFile;
import javax.annotation.Resource;
import java.util.List;
......@@ -71,9 +72,9 @@ public class ChannelController extends ChannelBaseController {
ChannelTagExample channelTagExample = new ChannelTagExample();
channelTagExample.createCriteria().andChannelIdIn(channelIdList);
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) {
List<Long> tags = channel_tag_map.get(channel.getId());
List<String> tags = channel_tag_map.get(channel.getId());
channel.setTags(tags);
}
}
......@@ -87,4 +88,26 @@ public class ChannelController extends ChannelBaseController {
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
......@@ -5,6 +5,7 @@ import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
......@@ -22,4 +23,7 @@ public interface TaskFeignClient {
@GetMapping("/tasks")
JsonMessageUtil.JsonMessage<List<Task>> getAllTask();
@GetMapping("/tasks")
JsonMessageUtil.JsonMessage<List<Task>> getTaskByChannelUnid(@RequestParam("channelUnid") String channelUnid);
}
......@@ -22,6 +22,7 @@
<result column="channel_latitude" property="latitude" />
<result column="channel_status" property="status" />
<result column="channel_create_time" property="createTime" />
<result column="channel_device_type" property="deviceType"/>
</resultMap>
<resultMap id="BaseResultMap" type="com.viontech.fanxing.commons.model.Channel" extends="BaseResultMapRoot" />
<sql id="Example_Where_Clause" >
......@@ -83,14 +84,18 @@
</where>
</sql>
<sql id="Base_Column_List_Root" >
`channel`.id as channel_id, `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 `.id as channel_id,
` 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`.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`.`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`.`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 id="Base_Column_List" >
<if test="!(_parameter.getClass().getSimpleName() == 'ChannelExample')" >
......@@ -150,15 +155,15 @@
username, `password`, brand,
direction, address_unid, `name`,
ip, port, expand, longitude,
latitude, `status`, create_time
)
latitude, `status`, create_time,
device_type)
values (#{unid,jdbcType=VARCHAR}, #{channelUnid,jdbcType=VARCHAR}, #{deviceUnid,jdbcType=VARCHAR},
#{type,jdbcType=INTEGER}, #{streamType,jdbcType=INTEGER}, #{streamPath,jdbcType=VARCHAR},
#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{brand,jdbcType=VARCHAR},
#{direction,jdbcType=VARCHAR}, #{addressUnid,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR},
#{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 id="insertSelective" parameterType="com.viontech.fanxing.commons.model.Channel" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `s_channel`
......@@ -211,15 +216,18 @@
<if test="longitude != null" >
longitude,
</if>
<if test="latitude != null" >
<if test="latitude != null">
latitude,
</if>
<if test="status != null" >
<if test="status != null">
`status`,
</if>
<if test="createTime != null" >
<if test="createTime != null">
create_time,
</if>
<if test="deviceType != null">
device_type,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="unid != null" >
......@@ -270,15 +278,18 @@
<if test="longitude != null" >
#{longitude,jdbcType=REAL},
</if>
<if test="latitude != null" >
<if test="latitude != null">
#{latitude,jdbcType=REAL},
</if>
<if test="status != null" >
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="deviceType != null">
#{deviceType,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.viontech.fanxing.commons.model.ChannelExample" resultType="java.lang.Integer" >
......@@ -341,15 +352,18 @@
<if test="record.longitude != null" >
longitude = #{record.longitude,jdbcType=REAL},
</if>
<if test="record.latitude != null" >
<if test="record.latitude != null">
latitude = #{record.latitude,jdbcType=REAL},
</if>
<if test="record.status != null" >
<if test="record.status != null">
`status` = #{record.status,jdbcType=INTEGER},
</if>
<if test="record.createTime != null" >
<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>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
......@@ -376,7 +390,8 @@
longitude = #{record.longitude,jdbcType=REAL},
latitude = #{record.latitude,jdbcType=REAL},
`status` = #{record.status,jdbcType=INTEGER},
create_time = #{record.createTime,jdbcType=TIMESTAMP}
create_time = #{record.createTime,jdbcType=TIMESTAMP},
device_type = #{record.deviceType,jdbcType=VARCHAR}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
......@@ -432,15 +447,18 @@
<if test="longitude != null" >
longitude = #{longitude,jdbcType=REAL},
</if>
<if test="latitude != null" >
<if test="latitude != null">
latitude = #{latitude,jdbcType=REAL},
</if>
<if test="status != null" >
<if test="status != null">
`status` = #{status,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="deviceType != null">
device_type = #{deviceType,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
......@@ -464,7 +482,8 @@
longitude = #{longitude,jdbcType=REAL},
latitude = #{latitude,jdbcType=REAL},
`status` = #{status,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP}
create_time = #{createTime,jdbcType=TIMESTAMP},
device_type = #{deviceType,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
......@@ -4,27 +4,29 @@
<resultMap id="BaseResultMapRoot" type="com.viontech.fanxing.commons.model.ChannelTag" >
<id column="channel_tag_id" property="id" />
<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 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" >
<foreach collection="leftJoinTableSet" item="leftJoinTable" >
......@@ -94,8 +96,9 @@
</where>
</sql>
<sql id="Base_Column_List_Root" >
`channel_tag`.id as channel_tag_id, `channel_tag`.channel_id as channel_tag_channel_id,
`channel_tag`.tag_id as channel_tag_tag_id
` channel_tag `.id as channel_tag_id,
` channel_tag `.channel_id as channel_tag_channel_id,
` channel_tag `.tag as channel_tag_tag
</sql>
<sql id="Base_Column_List" >
<if test="!(_parameter.getClass().getSimpleName() == 'ChannelTagExample')" >
......@@ -159,25 +162,25 @@
</if>
</delete>
<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)
values (#{channelId,jdbcType=BIGINT}, #{tagId,jdbcType=BIGINT})
insert into `r_channel_tag` (channel_id, tag)
values (#{channelId,jdbcType=BIGINT}, #{tag,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.viontech.fanxing.commons.model.ChannelTag" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `r_channel_tag`
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="channelId != null" >
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="channelId != null">
channel_id,
</if>
<if test="tagId != null" >
tag_id,
<if test="tag != null">
tag,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="channelId != null" >
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="channelId != null">
#{channelId,jdbcType=BIGINT},
</if>
<if test="tagId != null" >
#{tagId,jdbcType=BIGINT},
<if test="tag != null">
#{tag,jdbcType=VARCHAR},
</if>
</trim>
</insert>
......@@ -190,15 +193,15 @@
</select>
<update id="updateByExampleSelective" parameterType="map" >
update `r_channel_tag` `channel_tag`
<set >
<if test="record.id != null" >
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.channelId != null" >
<if test="record.channelId != null">
channel_id = #{record.channelId,jdbcType=BIGINT},
</if>
<if test="record.tagId != null" >
tag_id = #{record.tagId,jdbcType=BIGINT},
<if test="record.tag != null">
tag = #{record.tag,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null" >
......@@ -209,19 +212,19 @@
update `r_channel_tag` `channel_tag`
set id = #{record.id,jdbcType=BIGINT},
channel_id = #{record.channelId,jdbcType=BIGINT},
tag_id = #{record.tagId,jdbcType=BIGINT}
tag = #{record.tag,jdbcType=VARCHAR}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.viontech.fanxing.commons.model.ChannelTag" >
update `r_channel_tag`
<set >
<if test="channelId != null" >
<set>
<if test="channelId != null">
channel_id = #{channelId,jdbcType=BIGINT},
</if>
<if test="tagId != null" >
tag_id = #{tagId,jdbcType=BIGINT},
<if test="tag != null">
tag = #{tag,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
......@@ -229,7 +232,7 @@
<update id="updateByPrimaryKey" parameterType="com.viontech.fanxing.commons.model.ChannelTag" >
update `r_channel_tag`
set channel_id = #{channelId,jdbcType=BIGINT},
tag_id = #{tagId,jdbcType=BIGINT}
tag = #{tag,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
......@@ -7,14 +7,17 @@ import com.viontech.fanxing.commons.base.BaseMapper;
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.exception.FanXingException;
import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.vo.ChannelVo;
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.service.adapter.ChannelService;
import com.viontech.fanxing.ops.service.adapter.ChannelTagService;
import com.viontech.fanxing.ops.service.adapter.DictCateService;
import com.viontech.fanxing.ops.service.adapter.DictCodeService;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.ImmutablePair;
......@@ -22,6 +25,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient;
import javax.annotation.Resource;
import java.io.File;
import java.time.Duration;
import java.util.*;
import java.util.stream.Collectors;
......@@ -39,8 +43,11 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
private ChannelTagService channelTagService;
@Resource
private VionConfig vionConfig;
@Resource
private TaskFeignClient taskFeignClient;
@Override
public BaseMapper<Channel> getMapper() {
return channelMapper;
}
......@@ -49,7 +56,7 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
public List<Channel> selectByExample(BaseExample example) {
List<Channel> channels = getMapper().selectByExample(example);
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());
}
}
......@@ -65,6 +72,22 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
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;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.IntSummaryStatistics;
import java.util.DoubleSummaryStatistics;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
/**
......@@ -47,7 +48,7 @@ public class VideoService {
* 上传存储视频文件
*/
@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) {
String originalFilename = file.getOriginalFilename();
String basePath = vionConfig.getImage().getPath() + File.separator + "uploadVideo" + File.separator;
......@@ -57,16 +58,8 @@ public class VideoService {
}
String unid = UUID.randomUUID().toString();
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.setUnid(unid);
channel.setChannelUnid(unid);
......@@ -75,14 +68,28 @@ public class VideoService {
channel.setStreamPath("/uploadVideo/" + filename);
channel.setType(ChannelType.FILE.value);
channel.setStreamType(ChannelType.STREAM_FILE.value);
channel.setPort(Math.toIntExact(mbSize));
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) {
for (Long tagId : tags) {
for (String tagId : tags) {
ChannelTag channelTag = new ChannelTag();
channelTag.setChannelId(channel.getId());
channelTag.setTagId(tagId);
channelTag.setTag(tagId);
channelTagService.insertSelective(channelTag);
}
}
......@@ -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() {
ChannelExample channelExample = new ChannelExample();
channelExample.createCriteria().andTypeEqualTo(ChannelType.FILE.value);
channelExample.createColumns().hasPortColumn();
channelExample.createColumns().hasExpandColumn();
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();
res.put("fileCount", summary.getCount());
res.put("size", summary.getSum());
res.put("unit", "MB");
return res;
}
}
......@@ -3,9 +3,12 @@ package com.viontech.fanxing.ops;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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.ops.feign.TaskFeignClient;
import com.viontech.fanxing.ops.service.adapter.ChannelService;
import com.viontech.fanxing.ops.service.adapter.DictCodeService;
import com.viontech.keliu.util.JsonMessageUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
......@@ -29,6 +32,8 @@ public class MainTest {
@Resource
private ChannelService channelService;
@Resource
private TaskFeignClient taskFeignClient;
@Test
public void nvs3000CodeTest() {
......@@ -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 {
return vaServerService.getRotationStatus(taskUnid);
}
@GetMapping("/getCurrentScene")
public Object getCurrentScene(@RequestParam String taskUnid) {
return vaServerService.getCurrentScene(taskUnid);
}
/**
* @param type 任务的类型 0 交通, 1 客流, 2 安防, 3 违停, 4 人脸
*/
......
package com.viontech.fanxing.task.controller.web;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.base.BaseModel;
import com.viontech.fanxing.commons.model.Task;
......@@ -15,6 +16,8 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static com.viontech.keliu.util.JsonMessageUtil.getSuccessJsonMsg;
@RestController
@RequestMapping("/tasks")
@Slf4j
......@@ -27,6 +30,24 @@ public class TaskController extends TaskBaseController {
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
@Override
......
......@@ -17,14 +17,14 @@ import java.util.UUID;
@Setter
@Accessors(chain = true)
public class Scene {
private String algo_type;
private Integer algo_type;
/** 标定,后端不需要关心 */
private Calibration calibration;
/** 配置信息 */
private Config config;
private String position_name;
private String position_num;
private String scene_unid = UUID.randomUUID().toString();
private String scene_unid;
private String vchan_refid;
private Integer runtime = -1;
private PlayUrls play_urls;
......
......@@ -24,7 +24,7 @@ public class VATask {
private String task_unid;
private String task_name;
private String alg_type;
private Integer alg_type;
private String store_config;
private String channel_unid;
private String stream_path;
......@@ -35,7 +35,7 @@ public class VATask {
Task task = taskData.getTask();
this.task_unid = task.getUnid();
this.task_name = task.getName();
this.alg_type = task.getAlgType();
this.alg_type = Integer.parseInt(task.getAlgType());
this.store_config = taskData.getStoreConfig();
this.channel_unid = task.getChannelUnid();
this.stream_path = task.getStreamPath();
......
package com.viontech.fanxing.task.repository;
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.task.model.vaserver.VaServerInfo;
import org.redisson.api.RBucket;
import org.redisson.api.RLock;
import org.redisson.api.RMap;
import org.springframework.stereotype.Repository;
......@@ -62,5 +63,9 @@ public class VAServerRedisRepository {
return bucket.isExists();
}
public RLock getDevLock(String devId) {
return redisService.getLockMust("lock:vaserver:" + devId);
}
}
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.TaskExample;
import com.viontech.fanxing.task.mapper.TaskMapper;
......@@ -38,7 +39,7 @@ public class TaskInitRunner implements CommandLineRunner {
List<Task> tasks = taskMapper.selectByExampleWithBLOBs(new TaskExample());
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 {
TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(task.getUnid());
if (taskData == null) {
......
......@@ -10,6 +10,7 @@ import com.viontech.fanxing.task.service.TaskDataService;
import com.viontech.fanxing.task.service.VAServerService;
import com.viontech.fanxing.task.service.adapter.TaskService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.redisson.api.RLock;
import org.redisson.api.RMap;
import org.redisson.api.RScoredSortedSet;
......@@ -71,8 +72,14 @@ public class TaskRunner {
if (temp.getStatus() == 0) {
continue;
}
// 指定了VAServer
if (StringUtils.isNotBlank(taskVaType)) {
if (!taskVaType.equals(temp.getServiceName())) {
continue;
}
}
if (temp.getAvailableResources() > resourceNeed) {
devLock = redisService.getLockMust("lock:vaserver:" + devId);
devLock = vaServerService.getVaServerRedisRepository().getDevLock(devId);
temp = vaServerMap.get(devId);
if (temp.getAvailableResources() > resourceNeed) {
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 {
public void updateTask(Task task) {
String taskUnid = task.getUnid();
VaServerInfo vaServerInfo = taskRunOn(taskUnid);
// vaServerId 为空说明任务未执行可以先删除再建立新任务
if (vaServerInfo == null) {
deleteTask(taskUnid);
addTask(task);
} else if (vaServerInfo.getStatus() == 0) {
throw new FanXingException("设备离线");
} else {
TaskData taskData = new TaskData(task);
// 需要更新taskData,并且向vaServer更新任务信息
taskDataRedisRepository.addOrUpdateTaskData(taskData);
......
......@@ -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);
String path = "/api/vaserver/v1/task";
Mono<String> stringMono = WebClient.create(vaServerInfo.getServiceBaseUrl())
......@@ -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";
VATask vaTask = new VATask(taskData);
......@@ -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";
JSONObject jsonObject = new JSONObject();
......@@ -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";
JSONObject jsonObject = new JSONObject();
......@@ -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";
JSONObject jsonObject = new JSONObject();
......@@ -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";
JSONObject jsonObject = new JSONObject();
......@@ -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";
JSONObject jsonObject = new JSONObject();
......@@ -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";
JSONObject jsonObject = new JSONObject();
......@@ -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";
JSONObject jsonObject = new JSONObject();
......@@ -212,7 +212,7 @@ public class VAServerHttpService {
/**
* 运行状态查询
*/
public Object status(VaServerInfo vaServerInfo) {
public JSONObject status(VaServerInfo vaServerInfo) {
String path = "/api/vaserver/v1/status";
Mono<String> stringMono = WebClient.create(vaServerInfo.getServiceBaseUrl())
......@@ -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";
JSONObject jsonObject = new JSONObject();
jsonObject.put("task_algo_type", taskAlgType);
......@@ -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;
import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.constant.RedisKeys;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.Task;
import com.viontech.fanxing.commons.service.RedisService;
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.repository.VAServerRedisRepository;
import org.redisson.api.RBucket;
import org.redisson.api.RLock;
import org.redisson.api.RMap;
......@@ -40,23 +41,25 @@ public class VAServerService {
*/
public void registerVAServer(VaServerInfo vaServerInfo) {
String devId = vaServerInfo.getDevID();
keepalive(devId);
vaServerRedisRepository.addOrUpdate(devId, vaServerInfo);
keepalive(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);
if (vaserverInfo != null) {
vaserverInfo.setStatus(1);
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 {
public boolean terminateTask(String taskUnid) {
TaskData taskData = taskDataService.getRepository().getTaskDataByUnid(taskUnid);
if (taskData == null) {
return false;
return true;
}
Task task = taskData.getTask();
......@@ -180,7 +183,7 @@ public class VAServerService {
/**
* 获取 VAServer 运行状态配置参数等
*/
public Object getStatus(String devId) {
public JSONObject getStatus(String devId) {
VaServerInfo vaServerInfo = vaServerRedisRepository.getVAServerInfoById(devId);
if (vaServerInfo != null) {
return vaServerHttpService.status(vaServerInfo);
......@@ -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) {
RMap<String, VaServerInfo> map = vaServerRedisRepository.getVaServerInfoMap();
VaServerInfo temp = null;
......
......@@ -2,6 +2,10 @@ package com.viontech.fanxing.task.service.impl;
import com.alibaba.fastjson.JSONArray;
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.BaseServiceImpl;
import com.viontech.fanxing.commons.base.LocalCache;
......@@ -27,6 +31,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@Service
public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskService {
......@@ -46,6 +52,28 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
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)
@Override
public TaskVo addTask(Task task) {
......@@ -100,7 +128,8 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
.setPosition_num(String.valueOf(i))
.setPosition_name(String.valueOf(i))
.setVchan_refid(channelUnid)
.setAlgo_type(algType)
.setScene_unid(UUID.randomUUID().toString())
.setAlgo_type(Integer.parseInt(algType))
.setConfig(config)
.setPlay_urls(playUrls);
if (streamPath.contains("http")) {
......@@ -181,7 +210,7 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
}
@Override
@LocalCache(value = "task_overview", duration = 3)
@LocalCache(value = "task_overview", duration = 30, timeunit = TimeUnit.SECONDS)
public JSONObject overview() {
List<Task> tasks = selectByExample(new TaskExample());
int resourceCount = 0;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!