Commit 2737dc87 by xmh

Channel 增加字段 deviceType

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

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

任务服务整体调整
1 parent f7e3280c
Showing 31 changed files with 986 additions and 577 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) {
videoService.uploadVideo(files, 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')" >
......@@ -145,20 +150,20 @@
</if>
</delete>
<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,
`type`, stream_type, stream_path,
username, `password`, brand,
direction, address_unid, `name`,
ip, port, expand, longitude,
latitude, `status`, create_time
)
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}
)
insert into `s_channel` (unid, channel_unid, device_unid,
`type`, stream_type, stream_path,
username, `password`, brand,
direction, address_unid, `name`,
ip, port, expand, longitude,
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},
#{deviceType,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.viontech.fanxing.commons.model.Channel" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `s_channel`
......@@ -209,17 +214,20 @@
expand,
</if>
<if test="longitude != null" >
longitude,
</if>
<if test="latitude != null" >
latitude,
</if>
<if test="status != null" >
`status`,
</if>
<if test="createTime != null" >
create_time,
longitude,
</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 prefix="values (" suffix=")" suffixOverrides="," >
<if test="unid != null" >
......@@ -270,15 +278,18 @@
<if test="longitude != null" >
#{longitude,jdbcType=REAL},
</if>
<if test="latitude != null" >
#{latitude,jdbcType=REAL},
</if>
<if test="status != null" >
#{status,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="latitude != null">
#{latitude,jdbcType=REAL},
</if>
<if test="status != null">
#{status,jdbcType=INTEGER},
</if>
<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" >
......@@ -339,17 +350,20 @@
expand = #{record.expand,jdbcType=VARCHAR},
</if>
<if test="record.longitude != null" >
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},
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 test="record.deviceType != null">
device_type = #{record.deviceType,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
......@@ -376,8 +390,9 @@
longitude = #{record.longitude,jdbcType=REAL},
latitude = #{record.latitude,jdbcType=REAL},
`status` = #{record.status,jdbcType=INTEGER},
create_time = #{record.createTime,jdbcType=TIMESTAMP}
<if test="_parameter != null" >
create_time = #{record.createTime,jdbcType=TIMESTAMP},
device_type = #{record.deviceType,jdbcType=VARCHAR}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
......@@ -432,15 +447,18 @@
<if test="longitude != null" >
longitude = #{longitude,jdbcType=REAL},
</if>
<if test="latitude != null" >
latitude = #{latitude,jdbcType=REAL},
</if>
<if test="status != null" >
`status` = #{status,jdbcType=INTEGER},
</if>
<if test="createTime != null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="latitude != null">
latitude = #{latitude,jdbcType=REAL},
</if>
<if test="status != null">
`status` = #{status,jdbcType=INTEGER},
</if>
<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}
where id = #{id,jdbcType=BIGINT}
create_time = #{createTime,jdbcType=TIMESTAMP},
device_type = #{deviceType,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
......@@ -4,28 +4,30 @@
<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" />
</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" />
<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_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" >
<choose >
......@@ -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,27 +162,27 @@
</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" >
channel_id,
</if>
<if test="tagId != null" >
tag_id,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="channelId != null" >
#{channelId,jdbcType=BIGINT},
</if>
<if test="tagId != null" >
#{tagId,jdbcType=BIGINT},
</if>
</trim>
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="channelId != null">
channel_id,
</if>
<if test="tag != null">
tag,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="channelId != null">
#{channelId,jdbcType=BIGINT},
</if>
<if test="tag != null">
#{tag,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.viontech.fanxing.commons.model.ChannelTagExample" resultType="java.lang.Integer" >
select count(*) from `r_channel_tag` `channel_tag`
......@@ -190,46 +193,46 @@
</select>
<update id="updateByExampleSelective" parameterType="map" >
update `r_channel_tag` `channel_tag`
<set >
<if test="record.id != null" >
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.channelId != null" >
channel_id = #{record.channelId,jdbcType=BIGINT},
</if>
<if test="record.tagId != null" >
tag_id = #{record.tagId,jdbcType=BIGINT},
</if>
</set>
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.channelId != null">
channel_id = #{record.channelId,jdbcType=BIGINT},
</if>
<if test="record.tag != null">
tag = #{record.tag,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map" >
update `r_channel_tag` `channel_tag`
set id = #{record.id,jdbcType=BIGINT},
update `r_channel_tag` `channel_tag`
set id = #{record.id,jdbcType=BIGINT},
channel_id = #{record.channelId,jdbcType=BIGINT},
tag_id = #{record.tagId,jdbcType=BIGINT}
<if test="_parameter != null" >
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" >
channel_id = #{channelId,jdbcType=BIGINT},
</if>
<if test="tagId != null" >
tag_id = #{tagId,jdbcType=BIGINT},
</if>
</set>
<set>
<if test="channelId != null">
channel_id = #{channelId,jdbcType=BIGINT},
</if>
<if test="tag != null">
tag = #{tag,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<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}
where id = #{id,jdbcType=BIGINT}
update `r_channel_tag`
set channel_id = #{channelId,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;
......
-- s_task 任务信息表
CREATE TABLE IF NOT EXISTS s_task(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
name VARCHAR(128) NOT NULL COMMENT '任务名称',
alg_type VARCHAR(36) NOT NULL COMMENT '算法类型',
alg_enabled VARCHAR(32) COMMENT '已启用的算法类型',
resource_need FLOAT NOT NULL COMMENT '任务所需资源数量',
priority INT NOT NULL DEFAULT 0 COMMENT '任务优先级',
store_config_id BIGINT NOT NULL COMMENT '存储配置id',
va_type VARCHAR(36) COMMENT '算法分析设备类型',
runtime_type INT NOT NULL DEFAULT 0 COMMENT '任务执行时间类型,全天分时段等',
runtime_conf TEXT COMMENT '任务执行时间段的配置',
device_unid VARCHAR(36) COMMENT '相机设备unid',
channel_unid VARCHAR(36) COMMENT '相机通道unid',
stream_path VARCHAR(1024) COMMENT '视频流地址',
stream_type INT COMMENT '视频流类型',
scene TEXT COMMENT '场景配置,包含画线预置位等',
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
status INT NOT NULL DEFAULT 0 COMMENT '任务状态',
INDEX s_task_unid_idx(unid)
CREATE TABLE IF NOT EXISTS s_task
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
name VARCHAR(128) NOT NULL COMMENT '任务名称',
alg_type VARCHAR(36) NOT NULL COMMENT '算法类型',
alg_enabled VARCHAR(128) COMMENT '已启用的算法类型',
resource_need FLOAT NOT NULL COMMENT '任务所需资源数量',
priority INT NOT NULL DEFAULT 0 COMMENT '任务优先级',
store_config_id BIGINT NOT NULL COMMENT '存储配置id',
va_type VARCHAR(36) COMMENT '算法分析设备类型',
runtime_type INT NOT NULL DEFAULT 0 COMMENT '任务执行时间类型,全天分时段等',
runtime_conf TEXT COMMENT '任务执行时间段的配置',
device_unid VARCHAR(36) COMMENT '相机设备unid',
channel_unid VARCHAR(36) COMMENT '相机通道unid',
stream_path VARCHAR(1024) COMMENT '视频流地址',
stream_type INT COMMENT '视频流类型',
scene TEXT COMMENT '场景配置,包含画线预置位等',
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
status INT NOT NULL DEFAULT 0 COMMENT '任务状态',
INDEX s_task_unid_idx (unid)
);
-- s_store_config 存储配置表
CREATE TABLE IF NOT EXISTS s_store_config(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
name VARCHAR(256) NOT NULL COMMENT '存储配置名称',
content_format INT NOT NULL COMMENT '配置内容格式,如xml',
content TEXT NOT NULL COMMENT '配置内容',
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
status INT NOT NULL DEFAULT 0 COMMENT '状态',
INDEX s_store_config_unid_idx(unid)
CREATE TABLE IF NOT EXISTS s_store_config
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
name VARCHAR(256) NOT NULL COMMENT '存储配置名称',
content_format INT NOT NULL COMMENT '配置内容格式,如xml',
content TEXT NOT NULL COMMENT '配置内容',
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
status INT NOT NULL DEFAULT 0 COMMENT '状态',
INDEX s_store_config_unid_idx (unid)
);
-- s_forward 转发信息表
CREATE TABLE IF NOT EXISTS s_forward(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
name VARCHAR(256) NOT NULL COMMENT '转发名称',
url VARCHAR(1024) NOT NULL COMMENT '转发地址',
total BIGINT NOT NULL DEFAULT 0 COMMENT '转发数据总量',
failed BIGINT NOT NULL DEFAULT 0 COMMENT '失败数量',
last_send_time TIMESTAMP COMMENT '最后发送时间',
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
status INT NOT NULL DEFAULT 0 COMMENT '状态'
CREATE TABLE IF NOT EXISTS s_forward
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
name VARCHAR(256) NOT NULL COMMENT '转发名称',
url VARCHAR(1024) NOT NULL COMMENT '转发地址',
total BIGINT NOT NULL DEFAULT 0 COMMENT '转发数据总量',
failed BIGINT NOT NULL DEFAULT 0 COMMENT '失败数量',
last_send_time TIMESTAMP COMMENT '最后发送时间',
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
status INT NOT NULL DEFAULT 0 COMMENT '状态'
);
-- s_forward_config 转发配置表
CREATE TABLE IF NOT EXISTS s_forward_config(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
forward_id BIGINT NOT NULL COMMENT '转发信息id',
event_cate VARCHAR(36) NOT NULL,
event_type VARCHAR(36) NOT NULL,
INDEX s_forward_config_forward_id_idx(forward_id)
CREATE TABLE IF NOT EXISTS s_forward_config
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
forward_id BIGINT NOT NULL COMMENT '转发信息id',
event_cate VARCHAR(36) NOT NULL,
event_type VARCHAR(36) NOT NULL,
INDEX s_forward_config_forward_id_idx (forward_id)
);
-- d_traffic
CREATE TABLE IF NOT EXISTS d_traffic(
id BIGINT NOT NULL AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
task_id BIGINT COMMENT '任务id',
event_cate VARCHAR(36),
event_type VARCHAR(36),
event_time TIMESTAMP NOT NULL COMMENT '事件时间',
channel_unid VARCHAR(36) COMMENT '通道unid',
plate_color VARCHAR(36) COMMENT '车牌颜色',
plate_number VARCHAR(36) COMMENT '车牌号码',
location_code VARCHAR(36) COMMENT '位置编码',
location_name VARCHAR(500) COMMENT '位置名称',
lane_code VARCHAR(36) COMMENT '车道编码',
direction_code VARCHAR(36) COMMENT '卡口方向',
vehicle_type VARCHAR(36) COMMENT '车辆类型',
vehicle_color VARCHAR(36) COMMENT '车身颜色',
vehicle_logo VARCHAR(36) COMMENT '车标编码',
illegal_code VARCHAR(36) COMMENT '违法行为',
illegal_state INT COMMENT '违法行为是否可用',
feature_annual_inspection_mark SMALLINT DEFAULT 0 COMMENT '年检标',
feature_pendant SMALLINT DEFAULT 0 COMMENT '吊坠',
feature_decoration SMALLINT DEFAULT 0 COMMENT '摆件',
feature_sun_shield SMALLINT DEFAULT 0 COMMENT '遮阳板',
xcycle_type VARCHAR(36) COMMENT '非机动车类型',
event_id VARCHAR(64) COMMENT '事件唯一id' ,
special_type VARCHAR(36),
with_helmet INT COMMENT '是否戴头盔0不带',
json_data TEXT COMMENT '原始数据',
pics VARCHAR(2048),
video_name VARCHAR(256),
status INT NOT NULL DEFAULT 0 COMMENT '状态',
PRIMARY KEY(id,event_time),
INDEX d_traffic_unid_idx(unid),
INDEX d_traffic_select_idx(event_time,event_type,vehicle_type)
CREATE TABLE IF NOT EXISTS d_traffic
(
id BIGINT NOT NULL AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
task_id BIGINT COMMENT '任务id',
event_cate VARCHAR(36),
event_type VARCHAR(36),
event_time TIMESTAMP NOT NULL COMMENT '事件时间',
channel_unid VARCHAR(36) COMMENT '通道unid',
plate_color VARCHAR(36) COMMENT '车牌颜色',
plate_number VARCHAR(36) COMMENT '车牌号码',
location_code VARCHAR(36) COMMENT '位置编码',
location_name VARCHAR(500) COMMENT '位置名称',
lane_code VARCHAR(36) COMMENT '车道编码',
direction_code VARCHAR(36) COMMENT '卡口方向',
vehicle_type VARCHAR(36) COMMENT '车辆类型',
vehicle_color VARCHAR(36) COMMENT '车身颜色',
vehicle_logo VARCHAR(36) COMMENT '车标编码',
illegal_code VARCHAR(36) COMMENT '违法行为',
illegal_state INT COMMENT '违法行为是否可用',
feature_annual_inspection_mark SMALLINT DEFAULT 0 COMMENT '年检标',
feature_pendant SMALLINT DEFAULT 0 COMMENT '吊坠',
feature_decoration SMALLINT DEFAULT 0 COMMENT '摆件',
feature_sun_shield SMALLINT DEFAULT 0 COMMENT '遮阳板',
xcycle_type VARCHAR(36) COMMENT '非机动车类型',
event_id VARCHAR(64) COMMENT '事件唯一id',
special_type VARCHAR(36),
with_helmet INT COMMENT '是否戴头盔0不带',
json_data TEXT COMMENT '原始数据',
pics VARCHAR(2048),
video_name VARCHAR(256),
status INT NOT NULL DEFAULT 0 COMMENT '状态',
PRIMARY KEY (id, event_time),
INDEX d_traffic_unid_idx (unid),
INDEX d_traffic_select_idx (event_time, event_type, vehicle_type)
);
-- d_traffic_face
CREATE TABLE IF NOT EXISTS d_traffic_face(
id BIGINT NOT NULL AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
traffic_id BIGINT NOT NULL COMMENT 'trafficId',
event_time TIMESTAMP NOT NULL COMMENT '事件时间',
state SMALLINT NOT NULL DEFAULT 1,
sex SMALLINT NOT NULL DEFAULT 0,
upper_color VARCHAR(36),
lower_color VARCHAR(36),
INDEX traffic_face_traffic_id_idx(traffic_id),
PRIMARY KEY(id,event_time)
CREATE TABLE IF NOT EXISTS d_traffic_face
(
id BIGINT NOT NULL AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
traffic_id BIGINT NOT NULL COMMENT 'trafficId',
event_time TIMESTAMP NOT NULL COMMENT '事件时间',
state SMALLINT NOT NULL DEFAULT 1,
sex SMALLINT NOT NULL DEFAULT 0,
upper_color VARCHAR(36),
lower_color VARCHAR(36),
INDEX traffic_face_traffic_id_idx (traffic_id),
PRIMARY KEY (id, event_time)
);
-- d_flow_data
CREATE TABLE IF NOT EXISTS d_flow_data(
id BIGINT NOT NULL AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
flow_event_id BIGINT COMMENT 'eventId',
task_id BIGINT,
detection_type VARCHAR(36) COMMENT '检测类型(bus,big_vehicle,xcycle等)',
road_code VARCHAR(36) COMMENT '道路编码',
direction_code VARCHAR(36) COMMENT '方向编码',
sample_dura BIGINT,
sample_num FLOAT,
velocity FLOAT COMMENT '速率',
velocity_unit VARCHAR(16) COMMENT '速率单位',
occupy FLOAT COMMENT '车道占有率',
distance FLOAT COMMENT '车头间距',
queue_length FLOAT COMMENT '车辆排队长度',
region_id VARCHAR(36),
region_name VARCHAR(128),
position_content TEXT,
head_content TEXT,
area FLOAT,
density FLOAT,
sample_num_in FLOAT,
sample_num_out FLOAT,
event_time TIMESTAMP,
dist_time FLOAT,
time_occupy FLOAT,
status INT NOT NULL DEFAULT 0 COMMENT '状态',
PRIMARY KEY(id,event_time),
INDEX flow_data_select_idx(flow_event_id)
CREATE TABLE IF NOT EXISTS d_flow_data
(
id BIGINT NOT NULL AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
flow_event_id BIGINT COMMENT 'eventId',
task_id BIGINT,
detection_type VARCHAR(36) COMMENT '检测类型(bus,big_vehicle,xcycle等)',
road_code VARCHAR(36) COMMENT '道路编码',
direction_code VARCHAR(36) COMMENT '方向编码',
sample_dura BIGINT,
sample_num FLOAT,
velocity FLOAT COMMENT '速率',
velocity_unit VARCHAR(16) COMMENT '速率单位',
occupy FLOAT COMMENT '车道占有率',
distance FLOAT COMMENT '车头间距',
queue_length FLOAT COMMENT '车辆排队长度',
region_id VARCHAR(36),
region_name VARCHAR(128),
position_content TEXT,
head_content TEXT,
area FLOAT,
density FLOAT,
sample_num_in FLOAT,
sample_num_out FLOAT,
event_time TIMESTAMP,
dist_time FLOAT,
time_occupy FLOAT,
status INT NOT NULL DEFAULT 0 COMMENT '状态',
PRIMARY KEY (id, event_time),
INDEX flow_data_select_idx (flow_event_id)
);
-- d_flow_event
CREATE TABLE IF NOT EXISTS d_flow_event(
id BIGINT NOT NULL AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
task_id BIGINT COMMENT '任务id',
event_type VARCHAR(36),
event_time TIMESTAMP COMMENT '事件时间',
event_id VARCHAR(64) COMMENT '事件唯一id',
device_code VARCHAR(36),
device_name VARCHAR(64),
location_code VARCHAR(36),
location_name VARCHAR(64),
json_data TEXT,
pics VARCHAR(2048),
video_name VARCHAR(256),
PRIMARY KEY(id,event_time),
INDEX flow_event_select_idx(event_time,event_type)
CREATE TABLE IF NOT EXISTS d_flow_event
(
id BIGINT NOT NULL AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
task_id BIGINT COMMENT '任务id',
event_type VARCHAR(36),
event_time TIMESTAMP COMMENT '事件时间',
event_id VARCHAR(64) COMMENT '事件唯一id',
device_code VARCHAR(36),
device_name VARCHAR(64),
location_code VARCHAR(36),
location_name VARCHAR(64),
json_data TEXT,
pics VARCHAR(2048),
video_name VARCHAR(256),
PRIMARY KEY (id, event_time),
INDEX flow_event_select_idx (event_time, event_type)
);
-- d_behavior
CREATE TABLE IF NOT EXISTS d_behavior(
id BIGINT NOT NULL AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
task_id BIGINT,
event_type VARCHAR(36),
event_cate VARCHAR(36),
event_refid VARCHAR(64),
event_time TIMESTAMP,
event_data TEXT,
pics VARCHAR(2048),
video TEXT,
channel_unid VARCHAR(36),
task_name VARCHAR(128),
event_data_num VARCHAR(36),
PRIMARY KEY(id,event_time),
INDEX behavior_select_idx(event_time,event_type,event_cate)
CREATE TABLE IF NOT EXISTS d_behavior
(
id BIGINT NOT NULL AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
task_id BIGINT,
event_type VARCHAR(36),
event_cate VARCHAR(36),
event_refid VARCHAR(64),
event_time TIMESTAMP,
event_data TEXT,
pics VARCHAR(2048),
video TEXT,
channel_unid VARCHAR(36),
task_name VARCHAR(128),
event_data_num VARCHAR(36),
PRIMARY KEY (id, event_time),
INDEX behavior_select_idx (event_time, event_type, event_cate)
);
-- s_dict_cate
CREATE TABLE IF NOT EXISTS s_dict_cate(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
type VARCHAR(36) COMMENT '分类',
code VARCHAR(36) COMMENT 'cate编码',
name VARCHAR(36) NOT NULL COMMENT 'cate名称',
note VARCHAR(36) COMMENT '注释',
INDEX s_dict_cate_type_idx(type)
CREATE TABLE IF NOT EXISTS s_dict_cate
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
type VARCHAR(36) COMMENT '分类',
code VARCHAR(36) COMMENT 'cate编码',
name VARCHAR(36) NOT NULL COMMENT 'cate名称',
note VARCHAR(36) COMMENT '注释',
INDEX s_dict_cate_type_idx (type)
);
-- s_dict_code
CREATE TABLE IF NOT EXISTS s_dict_code(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
cate_id BIGINT NOT NULL,
parent_id BIGINT COMMENT '上级code的id',
code VARCHAR(36) COMMENT 'code编码',
name VARCHAR(36) NOT NULL COMMENT 'code名称',
note VARCHAR(36) COMMENT '注释',
CONSTRAINT `s_dict_code_cate_id_frk` FOREIGN KEY (`cate_id`) REFERENCES `fanxing3`.`s_dict_cate` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
INDEX s_dict_code_idx(cate_id)
CREATE TABLE IF NOT EXISTS s_dict_code
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
cate_id BIGINT NOT NULL,
parent_id BIGINT COMMENT '上级code的id',
code VARCHAR(36) COMMENT 'code编码',
name VARCHAR(36) NOT NULL COMMENT 'code名称',
note VARCHAR(36) COMMENT '注释',
CONSTRAINT `s_dict_code_cate_id_frk` FOREIGN KEY (`cate_id`) REFERENCES `fanxing3`.`s_dict_cate` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
INDEX s_dict_code_idx (cate_id)
);
-- s_channel
CREATE TABLE IF NOT EXISTS s_channel(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
channel_unid VARCHAR(64) NOT NULL COMMENT '设备中每一路视频通道本身的编码',
device_unid VARCHAR(64) COMMENT '设备自身的编码',
type INT NOT NULL default 0 COMMENT '设备信息来源类型,0手动添加,1平台拉取,2视频资源上传',
stream_type INT COMMENT '视频流类型,例如rtsp,http,rtmp等',
stream_path VARCHAR(1024) COMMENT '视频流地址',
username VARCHAR(36) COMMENT '获取视频流所需的用户名',
password VARCHAR(64) COMMENT '获取视频流所需的密码',
brand varchar(64) COMMENT '品牌/厂家',
direction varchar(64) COMMENT '方向',
address_unid VARCHAR(36) COMMENT '绑定的组织结构,组织结构在字典表中',
name VARCHAR(128) COMMENT '名称',
ip VARCHAR(36) COMMENT 'ip地址',
port INT COMMENT '端口号',
expand VARCHAR(128) COMMENT '扩展字段,保存一些不重要的信息',
longitude FLOAT,
latitude FLOAT,
status INT NOT NULL DEFAULT 0,
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
INDEX s_channel_channel_unid_idx(channel_unid),
INDEX s_cahnnel_unid_idx(unid)
CREATE TABLE IF NOT EXISTS s_channel
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
channel_unid VARCHAR(64) NOT NULL UNIQUE COMMENT '设备中每一路视频通道本身的编码',
device_unid VARCHAR(64) COMMENT '设备自身的编码',
type INT NOT NULL default 0 COMMENT '设备信息来源类型,0手动添加,1平台拉取,2视频资源上传',
device_type VARCHAR(36) COMMENT '设备类型,对应字典表中device_type',
stream_type INT COMMENT '视频流类型,例如rtsp,http,rtmp等',
stream_path VARCHAR(1024) COMMENT '视频流地址',
username VARCHAR(36) COMMENT '获取视频流所需的用户名',
password VARCHAR(64) COMMENT '获取视频流所需的密码',
brand varchar(64) COMMENT '品牌/厂家',
direction varchar(64) COMMENT '方向',
address_unid VARCHAR(36) COMMENT '绑定的组织结构,组织结构在字典表中',
name VARCHAR(128) UNIQUE COMMENT '名称',
ip VARCHAR(36) COMMENT 'ip地址',
port INT COMMENT '端口号',
expand VARCHAR(128) COMMENT '扩展字段,保存一些不重要的信息',
longitude FLOAT,
latitude FLOAT,
status INT NOT NULL DEFAULT 0,
create_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
INDEX s_channel_unid_idx (unid)
);
-- r_channel_tag
CREATE TABLE IF NOT EXISTS r_channel_tag (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
channel_id BIGINT NOT NULL COMMENT '对应channel表的id',
tag_id BIGINT NOT NULL COMMENT 'tag也在字典表中',
CONSTRAINT `r_channel_tag_channel_id_frk` FOREIGN KEY (`channel_id`) REFERENCES `fanxing3`.`s_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
INDEX r_channel_tag_channel_id_idx(channel_id),
INDEX r_channel_tag_tag_id_idx(tag_id)
CREATE TABLE IF NOT EXISTS r_channel_tag
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
channel_id BIGINT NOT NULL COMMENT '对应channel表的id',
tag VARCHAR(36) NOT NULL COMMENT 'tag也在字典表中',
CONSTRAINT `r_channel_tag_channel_id_frk` FOREIGN KEY (`channel_id`) REFERENCES `fanxing3`.`s_channel` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
INDEX r_channel_tag_channel_id_idx (channel_id),
INDEX r_channel_tag_tag_id_idx (tag)
);
-- s_content
CREATE TABLE IF NOT EXISTS s_content (
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
name VARCHAR(64) NOT NULL COMMENT '名称',
type VARCHAR(32) COMMENT '分组',
content TEXT COMMENT '内容'
CREATE TABLE IF NOT EXISTS s_content
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
unid VARCHAR(36) NOT NULL DEFAULT (UUID()),
name VARCHAR(64) NOT NULL COMMENT '名称',
type VARCHAR(32) COMMENT '分组',
content TEXT COMMENT '内容'
);
insert into s_content(name, content ,type)
insert into s_content(name, content, type)
values ('defaultConfig',
'<?xml version="1.0" encoding="GBK"?><root><算法参数设置><车牌识别><车牌缩放比率>0.8000</车牌缩放比率><本地车牌首字母>1</本地车牌首字母><车牌最小宽度>60</车牌最小宽度><车牌最大宽度>180</车牌最大宽度><本地汉字>20</本地汉字><是否识别新能源车牌>0</是否识别新能源车牌></车牌识别><是否启用高速模式>0</是否启用高速模式><调试信息><字体大小>20</字体大小><是否显示Scale>0</是否显示Scale><是否显示耗时>0</是否显示耗时><是否显示版本>0</是否显示版本></调试信息><车牌宽度范围设定方法>1</车牌宽度范围设定方法></算法参数设置><短时录像设置><启用>1</启用><是否画框>1</是否画框><向前录像时间>10</向前录像时间><向后录像时间>10</向后录像时间><录像最大缓存时间>100</录像最大缓存时间></短时录像设置><功能配置><抓拍参数配置><路口电警><卡口><输出卡口图片>1</输出卡口图片><卡口抓两张图>0</卡口抓两张图><上行物体不输出卡口结果>0</上行物体不输出卡口结果><下行物体不输出卡口结果>0</下行物体不输出卡口结果><无牌车辆不输出卡口结果>0</无牌车辆不输出卡口结果><行人非机动车不输出卡口结果>0</行人非机动车不输出卡口结果></卡口></路口电警></抓拍参数配置></功能配置><车辆属性识别><识别车辆类型>1</识别车辆类型><识别车标>1</识别车标><识别车身颜色>1</识别车身颜色><识别驾驶员>1</识别驾驶员><识别危险品标识>1</识别危险品标识></车辆属性识别></root>',
'defaultConfig');
insert into s_content(name, content ,type)
'defaultConfig');
insert into s_content(name, content, type)
values ('defaultConfigTemplate',
'<?xml version="1.0" encoding="GBK"?><root><短时录像设置><启用><AttribType>4</AttribType><AttribInfo>是否开启录像</AttribInfo><AttribDefault>0</AttribDefault><AttribRange /></启用><是否画框><AttribType>4</AttribType><AttribInfo>是否画框</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></是否画框><向前录像时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>5</AttribDefault><AttribRange>0-1000</AttribRange></向前录像时间><向后录像时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>5</AttribDefault><AttribRange>0-1000</AttribRange></向后录像时间><录像最大缓存时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>60</AttribDefault><AttribRange>0-1000</AttribRange></录像最大缓存时间></短时录像设置><车辆属性识别><识别车辆类型><AttribType>4</AttribType><AttribInfo>识别车辆类型</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车辆类型><识别车标><AttribType>4</AttribType><AttribInfo>识别车标</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车标><识别车身颜色><AttribType>4</AttribType><AttribInfo>识别车身颜色</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车身颜色><识别驾驶员><AttribType>4</AttribType><AttribInfo>识别驾驶员</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别驾驶员><识别危险品标识><AttribType>4</AttribType><AttribInfo>识别危险品标识</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别危险品标识></车辆属性识别><功能配置><抓拍参数配置><路口电警><卡口><输出卡口图片><AttribType>4</AttribType><AttribInfo/><AttribDefault>1</AttribDefault><AttribRange /></输出卡口图片><卡口抓两张图><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></卡口抓两张图><上行物体不输出卡口结果><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></上行物体不输出卡口结果><下行物体不输出卡口结果><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></下行物体不输出卡口结果><无牌车辆不输出卡口结果><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></无牌车辆不输出卡口结果><行人非机动车不输出卡口结果><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></行人非机动车不输出卡口结果></卡口></路口电警></抓拍参数配置></功能配置><算法参数设置><是否启用高速模式><AttribType>4</AttribType><AttribInfo>应用于车辆通常速度较高且视频卡顿场景</AttribInfo><AttribDefault>0</AttribDefault><AttribRange /></是否启用高速模式><车牌识别><车牌缩放比率><AttribType>1</AttribType><AttribInfo>适用非机动车和摩托车,车牌宽目标40-80像素</AttribInfo><AttribDefault>0.800000</AttribDefault><AttribRange>0.300000-3.000000</AttribRange></车牌缩放比率><本地车牌首字母><AttribType>3</AttribType><AttribInfo>只摩托车</AttribInfo><AttribDefault>0</AttribDefault><AttribRange>26:0-A&amp;1-B&amp;2-C&amp;3-D&amp;4-E&amp;5-F&amp;6-G&amp;7-H&amp;8-I&amp;9-J&amp;10-K&amp;11-L&amp;12-M&amp;13-N&amp;14-O&amp;15-P&amp;16-Q&amp;17-R&amp;18-S&amp;19-T&amp;20-U&amp;21-V&amp;22-W&amp;23-X&amp;24-Y&amp;25-Z</AttribRange></本地车牌首字母><车牌最小宽度><AttribType>0</AttribType><AttribInfo/><AttribDefault>90</AttribDefault><AttribRange>60-230</AttribRange></车牌最小宽度><车牌最大宽度><AttribType>0</AttribType><AttribInfo/><AttribDefault>130</AttribDefault><AttribRange>60-230</AttribRange></车牌最大宽度><本地汉字><AttribType>3</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange>31:0-京&amp;1-沪&amp;2-津&amp;3-渝&amp;4-冀&amp;5-晋&amp;6-蒙&amp;7-辽&amp;8-吉&amp;9-黑&amp;10-苏&amp;11-浙&amp;12-皖&amp;13-闽&amp;14-赣&amp;15-鲁&amp;16-豫&amp;17-鄂&amp;18-湘&amp;19-粤&amp;20-桂&amp;21-琼&amp;22-川&amp;23-贵&amp;24-云&amp;25-藏&amp;26-陕&amp;27-甘&amp;28-青&amp;29-宁&amp;30-新</AttribRange></本地汉字><是否识别新能源车牌><AttribType>4</AttribType><AttribInfo/><AttribDefault>1</AttribDefault><AttribRange /></是否识别新能源车牌></车牌识别><调试信息><字体大小><AttribType>0</AttribType><AttribInfo>root\算法参数设置\调试信息\字体大小</AttribInfo><AttribDefault>20</AttribDefault><AttribRange>10-100</AttribRange></字体大小><是否显示Scale><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示Scale><是否显示耗时><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示耗时><是否显示版本><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示版本></调试信息></算法参数设置><车牌宽度范围设定方法><AttribType>3</AttribType><AttribInfo/><AttribDefault>1</AttribDefault><AttribRange>2:0-手动设置&amp;1-自动计算</AttribRange></车牌宽度范围设定方法></root>',
'defaultConfig');
'defaultConfig');
insert into s_content(name, content ,type)
insert into s_content(name, content, type)
values ('illegalStopDefaultConfig',
'<?xml version="1.0" encoding="GBK"?><root><短时录像设置><录像最大缓存时间>200</录像最大缓存时间><向前录像时间>180</向前录像时间><向后录像时间>20</向后录像时间><启用>0</启用><是否画框>0</是否画框></短时录像设置><算法参数设置><是否输出无牌结果>1</是否输出无牌结果><车牌识别><本地汉字>0</本地汉字><车牌最小宽度>60</车牌最小宽度><车牌最大宽度>150</车牌最大宽度><是否识别新能源车牌>0</是否识别新能源车牌></车牌识别><车头检测分数阈值>50</车头检测分数阈值><车尾检测分数阈值>50</车尾检测分数阈值><是否画检测区域>0</是否画检测区域><同时计时抓拍>0</同时计时抓拍><违法图片间隔时间-秒><时间1>10</时间1><时间2>160</时间2><时间3>10</时间3></违法图片间隔时间-秒></算法参数设置><动态跟踪参数><使用球机3D定位-重启生效>0</使用球机3D定位-重启生效></动态跟踪参数><车辆属性识别><识别车辆类型>0</识别车辆类型><识别车标>0</识别车标><识别车身颜色>0</识别车身颜色><识别驾驶员>0</识别驾驶员><识别危险品标识>0</识别危险品标识></车辆属性识别></root>',
'defaultConfig');
insert into s_content(name, content ,type)
'defaultConfig');
insert into s_content(name, content, type)
values ('illegalStopDefaultConfigTemplate',
'<?xml version="1.0" encoding="GBK"?><root><短时录像设置><启用><AttribType>4</AttribType><AttribInfo>是否开启录像</AttribInfo><AttribDefault>0</AttribDefault><AttribRange /></启用><是否画框><AttribType>4</AttribType><AttribInfo>是否画框</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></是否画框><向前录像时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>5</AttribDefault><AttribRange>0-1000</AttribRange></向前录像时间><向后录像时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>5</AttribDefault><AttribRange>0-1000</AttribRange></向后录像时间><录像最大缓存时间><AttribType>0</AttribType><AttribInfo>秒</AttribInfo><AttribDefault>60</AttribDefault><AttribRange>0-1000</AttribRange></录像最大缓存时间></短时录像设置><车辆属性识别><识别车辆类型><AttribType>4</AttribType><AttribInfo>识别车辆类型</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车辆类型><识别车标><AttribType>4</AttribType><AttribInfo>识别车标</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车标><识别车身颜色><AttribType>4</AttribType><AttribInfo>识别车身颜色</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别车身颜色><识别驾驶员><AttribType>4</AttribType><AttribInfo>识别驾驶员</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别驾驶员><识别危险品标识><AttribType>4</AttribType><AttribInfo>识别危险品标识</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></识别危险品标识></车辆属性识别><算法功能><是否开启车牌验证同一辆车><AttribType>4</AttribType><AttribInfo>是否开启车牌验证同一辆车</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></是否开启车牌验证同一辆车></算法功能><算法参数设置><抓拍前等待时间-秒><AttribType>0</AttribType><AttribInfo>抓拍前等待时间</AttribInfo><AttribDefault>2</AttribDefault><AttribRange>0-600</AttribRange></抓拍前等待时间-秒><违法图片间隔时间-秒><时间1><AttribType>0</AttribType><AttribInfo>图1图2间隔时间</AttribInfo><AttribDefault>10</AttribDefault><AttribRange>0-1000</AttribRange></时间1><时间2><AttribType>0</AttribType><AttribInfo>图2图3间隔时间</AttribInfo><AttribDefault>10</AttribDefault><AttribRange>0-1000</AttribRange></时间2><时间3><AttribType>0</AttribType><AttribInfo>图3图4间隔时间</AttribInfo><AttribDefault>10</AttribDefault><AttribRange>0-1000</AttribRange></时间3></违法图片间隔时间-秒><同时计时抓拍><AttribType>4</AttribType><AttribInfo>同时计时抓拍</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></同时计时抓拍><车头检测分数阈值><AttribType>0</AttribType><AttribInfo>车检分数阈值</AttribInfo><AttribDefault>50</AttribDefault><AttribRange>10-100</AttribRange></车头检测分数阈值><车尾检测分数阈值><AttribType>0</AttribType><AttribInfo>车检分数阈值</AttribInfo><AttribDefault>50</AttribDefault><AttribRange>10-100</AttribRange></车尾检测分数阈值><是否画检测区域><AttribType>4</AttribType><AttribInfo>是否画检测区域</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></是否画检测区域><是否输出无牌结果><AttribType>4</AttribType><AttribInfo>是否输出无牌结果</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></是否输出无牌结果><调试信息><字体大小><AttribType>0</AttribType><AttribInfo/><AttribDefault>20</AttribDefault><AttribRange>10-100</AttribRange></字体大小><是否显示Scale><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示Scale><是否显示耗时><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示耗时><是否显示版本><AttribType>4</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange /></是否显示版本></调试信息><车牌识别><本地汉字><AttribType>3</AttribType><AttribInfo/><AttribDefault>0</AttribDefault><AttribRange>31:0-京&amp;1-沪&amp;2-津&amp;3-渝&amp;4-冀&amp;5-晋&amp;6-蒙&amp;7-辽&amp;8-吉&amp;9-黑&amp;10-苏&amp;11-浙&amp;12-皖&amp;13-闽&amp;14-赣&amp;15-鲁&amp;16-豫&amp;17-鄂&amp;18-湘&amp;19-粤&amp;20-桂&amp;21-琼&amp;22-川&amp;23-贵&amp;24-云&amp;25-藏&amp;26-陕&amp;27-甘&amp;28-青&amp;29-宁&amp;30-新</AttribRange></本地汉字><车牌最小宽度><AttribType>0</AttribType><AttribInfo/><AttribDefault>90</AttribDefault><AttribRange>60-230</AttribRange></车牌最小宽度><车牌最大宽度><AttribType>0</AttribType><AttribInfo/><AttribDefault>130</AttribDefault><AttribRange>60-230</AttribRange></车牌最大宽度><是否识别新能源车牌><AttribType>4</AttribType><AttribInfo/><AttribDefault>1</AttribDefault><AttribRange /></是否识别新能源车牌></车牌识别></算法参数设置><动态跟踪参数><使用球机3D定位-重启生效><AttribType>4</AttribType><AttribInfo>使用球机3D定位</AttribInfo><AttribDefault>1</AttribDefault><AttribRange /></使用球机3D定位-重启生效></动态跟踪参数></root>',
'defaultConfig');
'defaultConfig');
-- 分表
alter TABLE d_traffic PARTITION by RANGE(UNIX_TIMESTAMP(event_time))(
PARTITION d_traffic20210701 VALUES less than (UNIX_TIMESTAMP('2021-07-02'))
);
alter TABLE d_traffic_face PARTITION by RANGE(UNIX_TIMESTAMP(event_time))(
PARTITION d_traffic_face20210701 VALUES less than (UNIX_TIMESTAMP('2021-07-02'))
);
alter TABLE d_flow_event PARTITION by RANGE(UNIX_TIMESTAMP(event_time))(
PARTITION d_flow_event20210701 VALUES less than (UNIX_TIMESTAMP('2021-07-02'))
);
alter TABLE d_flow_data PARTITION by RANGE(UNIX_TIMESTAMP(event_time))(
PARTITION d_flow_data20210701 VALUES less than (UNIX_TIMESTAMP('2021-07-02'))
);
alter TABLE d_behavior PARTITION by RANGE(UNIX_TIMESTAMP(event_time))(
PARTITION d_behavior20210701 VALUES less than (UNIX_TIMESTAMP('2021-07-02'))
);
alter TABLE d_traffic PARTITION by RANGE (UNIX_TIMESTAMP(event_time))(
PARTITION d_traffic20210701 VALUES less than (UNIX_TIMESTAMP('2021-07-02'))
);
alter TABLE d_traffic_face PARTITION by RANGE (UNIX_TIMESTAMP(event_time))(
PARTITION d_traffic_face20210701 VALUES less than (UNIX_TIMESTAMP('2021-07-02'))
);
alter TABLE d_flow_event PARTITION by RANGE (UNIX_TIMESTAMP(event_time))(
PARTITION d_flow_event20210701 VALUES less than (UNIX_TIMESTAMP('2021-07-02'))
);
alter TABLE d_flow_data PARTITION by RANGE (UNIX_TIMESTAMP(event_time))(
PARTITION d_flow_data20210701 VALUES less than (UNIX_TIMESTAMP('2021-07-02'))
);
alter TABLE d_behavior PARTITION by RANGE (UNIX_TIMESTAMP(event_time))(
PARTITION d_behavior20210701 VALUES less than (UNIX_TIMESTAMP('2021-07-02'))
);
delimiter $$
DROP PROCEDURE IF EXISTS timestamp_partition
DROP PROCEDURE IF EXISTS timestamp_partition
$$
CREATE PROCEDURE timestamp_partition(v_table_name VARCHAR(128),v_schema VARCHAR(128))
CREATE PROCEDURE timestamp_partition(v_table_name VARCHAR(128), v_schema VARCHAR(128))
BEGIN
DECLARE v_sysdate date; # 声明 当前时间
DECLARE v_mindate date; # 声明 目前分区的最小值
DECLARE v_maxdate date; # 声明 目前分区值中的最大值
DECLARE v_pt varchar(20); # 声明 分区名称 数字部分
DECLARE v_maxval varchar(20); # 声明 最大值
DECLARE i int; # 声明 ??
-- 增加新分区
SELECT max(CAST(FROM_UNIXTIME(partition_description) as date)) AS val
INTO v_maxdate
FROM INFORMATION_SCHEMA.PARTITIONS
WHERE TABLE_NAME = v_table_name AND TABLE_SCHEMA = v_schema;
set v_sysdate = sysdate(); # 赋值v_sysdate为当前时间
-- INTERVAL 时间计算的关键字
WHILE v_maxdate <= (v_sysdate + INTERVAL 7 DAY) DO
SET v_pt = date_format(v_maxdate ,'%Y%m%d');
SET v_maxval = date_format(v_maxdate + INTERVAL 1 DAY, '%Y-%m-%d');
SET @sql = concat('alter table ',v_table_name,' add partition (partition ',v_table_name, v_pt, ' values less than(UNIX_TIMESTAMP(''', v_maxval , ''')))');
PREPARE stmt FROM @sql;
EXECUTE stmt;
-- 删除预处理
DEALLOCATE PREPARE stmt;
SET v_maxdate = v_maxdate + INTERVAL 1 DAY; # 最大值 加一操作
END WHILE;
-- 删除旧分区
SELECT min(CAST(FROM_UNIXTIME(partition_description) as date)) AS val
INTO v_mindate
FROM INFORMATION_SCHEMA.PARTITIONS
WHERE TABLE_NAME = v_table_name AND TABLE_SCHEMA = v_schema;
-- 删除7天前的旧分区
WHILE v_mindate <= (v_sysdate - INTERVAL 7 DAY) DO
SET v_pt = date_format(v_mindate - INTERVAL 1 DAY,'%Y%m%d');
SET @sql = concat('alter table ',v_table_name,' drop partition ',v_table_name, v_pt);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET v_mindate = v_mindate + INTERVAL 1 DAY;
END WHILE;
DECLARE v_sysdate date; # 声明 当前时间
DECLARE v_mindate date; # 声明 目前分区的最小值
DECLARE v_maxdate date; # 声明 目前分区值中的最大值
DECLARE v_pt varchar(20); # 声明 分区名称 数字部分
DECLARE v_maxval varchar(20);
# 声明 最大值
-- 增加新分区
SELECT max(CAST(FROM_UNIXTIME(partition_description) as date)) AS val
INTO v_maxdate
FROM INFORMATION_SCHEMA.PARTITIONS
WHERE TABLE_NAME = v_table_name
AND TABLE_SCHEMA = v_schema;
set v_sysdate = sysdate();
# 赋值v_sysdate为当前时间
-- INTERVAL 时间计算的关键字
WHILE v_maxdate <= (v_sysdate + INTERVAL 7 DAY)
DO
SET v_pt = date_format(v_maxdate, '%Y%m%d');
SET v_maxval = date_format(v_maxdate + INTERVAL 1 DAY, '%Y-%m-%d');
SET @sql = concat('alter table ', v_table_name, ' add partition (partition ', v_table_name, v_pt,
' values less than(UNIX_TIMESTAMP(''', v_maxval, ''')))');
PREPARE stmt FROM @sql;
EXECUTE stmt;
-- 删除预处理
DEALLOCATE PREPARE stmt;
SET v_maxdate = v_maxdate + INTERVAL 1 DAY; # 最大值 加一操作
END WHILE;
-- 删除旧分区
SELECT min(CAST(FROM_UNIXTIME(partition_description) as date)) AS val
INTO v_mindate
FROM INFORMATION_SCHEMA.PARTITIONS
WHERE TABLE_NAME = v_table_name
AND TABLE_SCHEMA = v_schema;
-- 删除7天前的旧分区
WHILE v_mindate <= (v_sysdate - INTERVAL 7 DAY)
DO
SET v_pt = date_format(v_mindate - INTERVAL 1 DAY, '%Y%m%d');
SET @sql = concat('alter table ', v_table_name, ' drop partition ', v_table_name, v_pt);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET v_mindate = v_mindate + INTERVAL 1 DAY;
END WHILE;
END$$
delimiter ;
......@@ -363,14 +381,14 @@ delimiter ;
delimiter $$
drop event if exists auto_pt $$
create event auto_pt
on schedule
every 1 day
do
BEGIN
call timestamp_partition('d_traffic','{schema}');
call timestamp_partition('d_behavior','{schema}');
call timestamp_partition('d_flow_event','{schema}');
call timestamp_partition('d_flow_data','{schema}');
call timestamp_partition('d_traffic_face','{schema}');
END$$
on schedule
every 1 day
do
BEGIN
call timestamp_partition('d_traffic', '{schema}');
call timestamp_partition('d_behavior', '{schema}');
call timestamp_partition('d_flow_event', '{schema}');
call timestamp_partition('d_flow_data', '{schema}');
call timestamp_partition('d_traffic_face', '{schema}');
END$$
delimiter ;
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!