Commit 1139fb92 by xmh

<feat> 添加日志表 s_log,添加生成代码

<feat> VionConfig 修改,添加 sip28181 对接配置
<feat> 视频操作添加日志
<feat> 任务操作添加日志
<feat> gateway 鉴权后添加 username 到 header 中
1 parent c9b6a2fb
Showing 28 changed files with 1022 additions and 40 deletions
......@@ -23,18 +23,21 @@ import java.util.List;
@Slf4j
public class VionConfig {
/** 视频和图片存储配置 */
private Image image;
/** 是否启用转发 */
private boolean enableForward;
/** auth 服务地址 */
private Boolean authEnabled;
private Gateway gateway;
private String receiveResultPrefixPath;
/** 支持的视频格式列表 */
private List<String> supportedVideoFormats;
/** 需要跳过 token 验证的 url 的正则表达式列表 */
private List<String> skipAuth;
/** 平台srs的配置 */
private Srs srs;
/** sip28181 对接的配置 */
private Sip sip;
public @Getter
@Setter
......@@ -49,15 +52,6 @@ public class VionConfig {
public @Getter
@Setter
static class Gateway {
/** 网关 ip,以后可能改为 nginx */
private String ip;
/** 网关端口 */
private String port;
}
public @Getter
@Setter
static class Srs {
private String ip;
private String rtmpPort = "1935";
......@@ -70,6 +64,7 @@ public class VionConfig {
}
public String getHttpUrl(String taskUnid) {
// todo
String url = "http://36.112.68.214:30010/srs/live/" + taskUnid + ".flv";
// String url = "http://" + ip + ":" + httpPort + "/srs/live/" + taskUnid + ".flv";
log.debug(url);
......@@ -77,5 +72,11 @@ public class VionConfig {
}
}
public @Getter
@Setter
static class Sip {
private String id;
private String url;
}
}
package com.viontech.fanxing.commons.constant;
/**
* .
*
* @author 谢明辉
* @date 2021/11/10
*/
public enum LogType {
/** 登录日志 */
LOGIN(0),
/** 任务管理 */
TASK(1),
/** 用户管理 */
USER_MANAGER(2),
/** 数据查询 */
QUERY(3),
/** 视频资源管理 */
VIDEO_RESOURCE(4),
;
public int value;
LogType(int value) {
this.value = value;
}
}
package com.viontech.fanxing.commons.model;
import com.viontech.fanxing.commons.base.BaseModel;
import java.util.Date;
public class Log extends BaseModel {
private Long id;
private Date dateTime;
private String username;
private Integer logType;
private String content;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getDateTime() {
return dateTime;
}
public void setDateTime(Date dateTime) {
this.dateTime = dateTime;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username == null ? null : username.trim();
}
public Integer getLogType() {
return logType;
}
public void setLogType(Integer logType) {
this.logType = logType;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content == null ? null : content.trim();
}
}
\ No newline at end of file
package com.viontech.fanxing.commons.vo;
import com.viontech.fanxing.commons.model.Log;
import com.viontech.fanxing.commons.vobase.LogVoBase;
public class LogVo extends LogVoBase {
public LogVo() {
super();
}
public LogVo(Log log) {
super(log);
}
}
\ No newline at end of file
package com.viontech.fanxing.commons.vobase;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.viontech.fanxing.commons.base.VoInterface;
import com.viontech.fanxing.commons.model.Log;
import java.util.ArrayList;
import java.util.Date;
public class LogVoBase extends Log implements VoInterface<Log> {
private Log log;
@JsonIgnore
private ArrayList<Long> id_arr;
@JsonIgnore
private Long id_gt;
@JsonIgnore
private Long id_lt;
@JsonIgnore
private Long id_gte;
@JsonIgnore
private Long id_lte;
@JsonIgnore
private ArrayList<Date> dateTime_arr;
@JsonIgnore
private Date dateTime_gt;
@JsonIgnore
private Date dateTime_lt;
@JsonIgnore
private Date dateTime_gte;
@JsonIgnore
private Date dateTime_lte;
@JsonIgnore
private Boolean username_null;
@JsonIgnore
private ArrayList<String> username_arr;
@JsonIgnore
private String username_like;
@JsonIgnore
private ArrayList<Integer> logType_arr;
@JsonIgnore
private Integer logType_gt;
@JsonIgnore
private Integer logType_lt;
@JsonIgnore
private Integer logType_gte;
@JsonIgnore
private Integer logType_lte;
@JsonIgnore
private Boolean content_null;
@JsonIgnore
private ArrayList<String> content_arr;
@JsonIgnore
private String content_like;
public LogVoBase() {
this(null);
}
public LogVoBase(Log log) {
if(log == null) {
log = new Log();
}
this.log = log;
}
@JsonIgnore
public Log getModel() {
return log;
}
public void setModel(Log log) {
this.log = log;
}
public ArrayList<Long> getId_arr() {
return id_arr;
}
public void setId_arr(ArrayList<Long> id_arr) {
this.id_arr = id_arr;
}
public Long getId_gt() {
return id_gt;
}
public void setId_gt(Long id_gt) {
this.id_gt = id_gt;
}
public Long getId_lt() {
return id_lt;
}
public void setId_lt(Long id_lt) {
this.id_lt = id_lt;
}
public Long getId_gte() {
return id_gte;
}
public void setId_gte(Long id_gte) {
this.id_gte = id_gte;
}
public Long getId_lte() {
return id_lte;
}
public void setId_lte(Long id_lte) {
this.id_lte = id_lte;
}
public Long getId() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getId();
}
public void setId(Long id) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setId(id);
}
public ArrayList<Date> getDateTime_arr() {
return dateTime_arr;
}
public void setDateTime_arr(ArrayList<Date> dateTime_arr) {
this.dateTime_arr = dateTime_arr;
}
public Date getDateTime_gt() {
return dateTime_gt;
}
public void setDateTime_gt(Date dateTime_gt) {
this.dateTime_gt = dateTime_gt;
}
public Date getDateTime_lt() {
return dateTime_lt;
}
public void setDateTime_lt(Date dateTime_lt) {
this.dateTime_lt = dateTime_lt;
}
public Date getDateTime_gte() {
return dateTime_gte;
}
public void setDateTime_gte(Date dateTime_gte) {
this.dateTime_gte = dateTime_gte;
}
public Date getDateTime_lte() {
return dateTime_lte;
}
public void setDateTime_lte(Date dateTime_lte) {
this.dateTime_lte = dateTime_lte;
}
public Date getDateTime() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getDateTime();
}
public void setDateTime(Date dateTime) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setDateTime(dateTime);
}
public Boolean getUsername_null() {
return username_null;
}
public void setUsername_null(Boolean username_null) {
this.username_null = username_null;
}
public ArrayList<String> getUsername_arr() {
return username_arr;
}
public void setUsername_arr(ArrayList<String> username_arr) {
this.username_arr = username_arr;
}
public String getUsername_like() {
return username_like;
}
public void setUsername_like(String username_like) {
this.username_like = username_like;
}
public String getUsername() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getUsername();
}
public void setUsername(String username) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setUsername(username);
}
public ArrayList<Integer> getLogType_arr() {
return logType_arr;
}
public void setLogType_arr(ArrayList<Integer> logType_arr) {
this.logType_arr = logType_arr;
}
public Integer getLogType_gt() {
return logType_gt;
}
public void setLogType_gt(Integer logType_gt) {
this.logType_gt = logType_gt;
}
public Integer getLogType_lt() {
return logType_lt;
}
public void setLogType_lt(Integer logType_lt) {
this.logType_lt = logType_lt;
}
public Integer getLogType_gte() {
return logType_gte;
}
public void setLogType_gte(Integer logType_gte) {
this.logType_gte = logType_gte;
}
public Integer getLogType_lte() {
return logType_lte;
}
public void setLogType_lte(Integer logType_lte) {
this.logType_lte = logType_lte;
}
public Integer getLogType() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getLogType();
}
public void setLogType(Integer logType) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setLogType(logType);
}
public Boolean getContent_null() {
return content_null;
}
public void setContent_null(Boolean content_null) {
this.content_null = content_null;
}
public ArrayList<String> getContent_arr() {
return content_arr;
}
public void setContent_arr(ArrayList<String> content_arr) {
this.content_arr = content_arr;
}
public String getContent_like() {
return content_like;
}
public void setContent_like(String content_like) {
this.content_like = content_like;
}
public String getContent() {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
return this.getModel().getContent();
}
public void setContent(String content) {
if(getModel() == null ){
throw new RuntimeException("model is null");
}
this.getModel().setContent(content);
}
}
\ No newline at end of file
......@@ -24,6 +24,10 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
/**
* .
......@@ -36,6 +40,7 @@ import java.util.Map;
@Component
public class AuthorizationFilter implements GlobalFilter {
ExecutorService executorService = Executors.newCachedThreadPool();
@Resource
private VionConfig vionConfig;
@Resource
......@@ -49,12 +54,18 @@ public class AuthorizationFilter implements GlobalFilter {
if (token == null) {
return unAuthorized(exchange.getResponse(), "authorization failed");
}
// 鉴权
ImmutablePair<Boolean, String> checkResult = checkToken(token);
Boolean success = checkResult.left;
if (!success) {
log.info("token校验未通过:[{}][{}]", checkResult.right, request.getPath());
return unAuthorized(exchange.getResponse(), checkResult.right);
}
// 添加 username 到 header 中, 供之后的服务使用
ServerHttpRequest req = request.mutate().headers(headers -> headers.add("username", checkResult.right)).build();
exchange.mutate().request(req).build();
log.info("token 校验成功:{}", token);
}
return chain.filter(exchange);
......@@ -62,6 +73,7 @@ public class AuthorizationFilter implements GlobalFilter {
private ImmutablePair<Boolean, String> checkToken(String token) {
// todo authorize
String username;
try {
Map<String, String> api = new HashMap<>(2);
api.put("verb", HttpMethod.POST.name());
......@@ -69,13 +81,15 @@ public class AuthorizationFilter implements GlobalFilter {
Map<String, Object> perm = new HashMap<>(2);
perm.put("type", "api");
perm.put("api", api);
JSONObject jsonObject = authClient.checkToken(token, Collections.singletonMap("perm", perm));
// webFlux 是异步的,这里不能直接用 feign 调用
Future<JSONObject> perm1 = executorService.submit(() -> authClient.checkToken(token, Collections.singletonMap("perm", perm)));
JSONObject jsonObject = perm1.get();
username = jsonObject.getString("username");
} catch (Exception e) {
log.info("token 校验失败:{}", e.getMessage());
log.info("token 校验失败:", e);
return ImmutablePair.of(false, e.getLocalizedMessage());
}
return ImmutablePair.of(true, null);
return ImmutablePair.of(true, username);
}
......
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.BaseService;
import com.viontech.fanxing.commons.model.Log;
import com.viontech.fanxing.commons.model.LogExample;
import com.viontech.fanxing.commons.vo.LogVo;
import com.viontech.fanxing.ops.service.adapter.LogService;
import javax.annotation.Resource;
public abstract class LogBaseController extends BaseController<Log, LogVo> {
@Resource
protected LogService logService;
@Override
protected BaseExample getExample(LogVo logVo, int type) {
LogExample logExample = new LogExample();
LogExample.Criteria criteria = logExample.createCriteria();
if (logVo.getId() != null) {
criteria.andIdEqualTo(logVo.getId());
}
if (logVo.getId_arr() != null) {
criteria.andIdIn(logVo.getId_arr());
}
if (logVo.getId_gt() != null) {
criteria.andIdGreaterThan(logVo.getId_gt());
}
if (logVo.getId_lt() != null) {
criteria.andIdLessThan(logVo.getId_lt());
}
if (logVo.getId_gte() != null) {
criteria.andIdGreaterThanOrEqualTo(logVo.getId_gte());
}
if (logVo.getId_lte() != null) {
criteria.andIdLessThanOrEqualTo(logVo.getId_lte());
}
if (logVo.getDateTime() != null) {
criteria.andDateTimeEqualTo(logVo.getDateTime());
}
if (logVo.getDateTime_arr() != null) {
criteria.andDateTimeIn(logVo.getDateTime_arr());
}
if (logVo.getDateTime_gt() != null) {
criteria.andDateTimeGreaterThan(logVo.getDateTime_gt());
}
if (logVo.getDateTime_lt() != null) {
criteria.andDateTimeLessThan(logVo.getDateTime_lt());
}
if (logVo.getDateTime_gte() != null) {
criteria.andDateTimeGreaterThanOrEqualTo(logVo.getDateTime_gte());
}
if (logVo.getDateTime_lte() != null) {
criteria.andDateTimeLessThanOrEqualTo(logVo.getDateTime_lte());
}
if (logVo.getUsername() != null) {
criteria.andUsernameEqualTo(logVo.getUsername());
}
if (logVo.getUsername_null() != null) {
if (logVo.getUsername_null().booleanValue()) {
criteria.andUsernameIsNull();
} else {
criteria.andUsernameIsNotNull();
}
}
if (logVo.getUsername_arr() != null) {
criteria.andUsernameIn(logVo.getUsername_arr());
}
if (logVo.getUsername_like() != null) {
criteria.andUsernameLike(logVo.getUsername_like());
}
if (logVo.getLogType() != null) {
criteria.andLogTypeEqualTo(logVo.getLogType());
}
if (logVo.getLogType_arr() != null) {
criteria.andLogTypeIn(logVo.getLogType_arr());
}
if (logVo.getLogType_gt() != null) {
criteria.andLogTypeGreaterThan(logVo.getLogType_gt());
}
if (logVo.getLogType_lt() != null) {
criteria.andLogTypeLessThan(logVo.getLogType_lt());
}
if (logVo.getLogType_gte() != null) {
criteria.andLogTypeGreaterThanOrEqualTo(logVo.getLogType_gte());
}
if (logVo.getLogType_lte() != null) {
criteria.andLogTypeLessThanOrEqualTo(logVo.getLogType_lte());
}
if (logVo.getContent() != null) {
criteria.andContentEqualTo(logVo.getContent());
}
if (logVo.getContent_null() != null) {
if (logVo.getContent_null().booleanValue()) {
criteria.andContentIsNull();
} else {
criteria.andContentIsNotNull();
}
}
if (logVo.getContent_arr() != null) {
criteria.andContentIn(logVo.getContent_arr());
}
if (logVo.getContent_like() != null) {
criteria.andContentLike(logVo.getContent_like());
}
return logExample;
}
@Override
protected BaseService<Log> getService() {
return logService;
}
}
\ No newline at end of file
......@@ -52,7 +52,6 @@ public class ChannelController extends ChannelBaseController {
Assert.notNull(channelVo.getUsername(), "用户名不能为空");
Assert.notNull(channelVo.getPassword(), "密码不能为空");
Assert.notNull(channelVo.getStreamPath(), "视频流地址不能为空");
Assert.notNull(channelVo.getType(), "类型不能为空");
ChannelVo update = channelService.update(id, channelVo);
return JsonMessageUtil.getSuccessJsonMsg(MESSAGE_UPDATE_SUCCESS, update);
}
......@@ -137,7 +136,7 @@ public class ChannelController extends ChannelBaseController {
Assert.notNull(channelVo.getType(), "类型不能为空");
try {
return super.add(channelVo);
return channelService.add(channelVo);
} catch (DuplicateKeyException e) {
log.error("", e);
return JsonMessageUtil.getErrorJsonMsg("设备编号或名称重复");
......
package com.viontech.fanxing.ops.controller.web;
import com.viontech.fanxing.commons.base.BaseExample;
import com.viontech.fanxing.commons.model.LogExample;
import com.viontech.fanxing.commons.vo.LogVo;
import com.viontech.fanxing.ops.controller.base.LogBaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/logs")
public class LogController extends LogBaseController {
@Override
protected BaseExample getExample(LogVo logVo, int type) {
LogExample logExample = (LogExample) super.getExample(logVo, type);
return logExample;
}
}
\ No newline at end of file
package com.viontech.fanxing.ops.mapper;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.model.Log;
import com.viontech.fanxing.commons.model.LogExample;
import java.util.List;
import org.apache.ibatis.annotations.Param;
public interface LogMapper extends BaseMapper {
int countByExample(LogExample example);
int deleteByExample(LogExample example);
int deleteByPrimaryKey(Long id);
int insert(Log record);
int insertSelective(Log record);
List<Log> selectByExample(LogExample example);
Log selectByPrimaryKey(Long id);
int updateByExampleSelective(@Param("record") Log record, @Param("example") LogExample example);
int updateByExample(@Param("record") Log record, @Param("example") LogExample example);
int updateByPrimaryKeySelective(Log record);
int updateByPrimaryKey(Log record);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.viontech.fanxing.ops.mapper.LogMapper" >
<resultMap id="BaseResultMapRoot" type="com.viontech.fanxing.commons.model.Log" >
<id column="log_id" property="id" />
<result column="log_date_time" property="dateTime" />
<result column="log_username" property="username" />
<result column="log_log_type" property="logType" />
<result column="log_content" property="content" />
</resultMap>
<resultMap id="BaseResultMap" type="com.viontech.fanxing.commons.model.Log" extends="BaseResultMapRoot" />
<sql id="Example_Where_Clause" >
<where >
<foreach collection="oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause" >
<where >
<foreach collection="example.oredCriteria" item="criteria" separator="or" >
<if test="criteria.valid" >
<trim prefix="(" suffix=")" prefixOverrides="and" >
<foreach collection="criteria.criteria" item="criterion" >
<choose >
<when test="criterion.noValue" >
and ${criterion.condition}
</when>
<when test="criterion.singleValue" >
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue" >
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue" >
and ${criterion.condition}
<foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List_Root" >
`log`.id as log_id, `log`.date_time as log_date_time, `log`.username as log_username,
`log`.log_type as log_log_type, `log`.content as log_content
</sql>
<sql id="Base_Column_List" >
<if test="!(_parameter.getClass().getSimpleName() == 'LogExample')" >
<include refid="com.viontech.fanxing.ops.mapper.LogMapper.Base_Column_List_Root" />
</if>
<if test="_parameter.getClass().getSimpleName() == 'LogExample'" >
<foreach collection="columnContainerSet" item="columns" separator="," >
<choose >
<when test="columns.tableName == 's_log'.toString()" >
<if test="columns.valid" >
${columns.columnContainerStr}
</if>
<if test="!columns.valid" >
<include refid="com.viontech.fanxing.ops.mapper.LogMapper.Base_Column_List_Root" />
</if>
</when>
</choose>
</foreach>
</if>
</sql>
<select id="selectByExample" resultMap="BaseResultMap" parameterType="com.viontech.fanxing.commons.model.LogExample" >
select
<if test="distinct" >
distinct
</if>
<include refid="Base_Column_List" />
from `s_log` `log`
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
<if test="groupByClause != null" >
group by ${groupByClause}
</if>
<if test="orderByClause != null" >
order by ${orderByClause}
</if>
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long" >
select
<include refid="Base_Column_List" />
from `s_log` `log`
where `log`.id = #{id,jdbcType=BIGINT}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.Long" >
delete from `s_log` `log`
where id = #{id,jdbcType=BIGINT}
</delete>
<delete id="deleteByExample" parameterType="com.viontech.fanxing.commons.model.LogExample" >
delete from `s_log` `log`
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.viontech.fanxing.commons.model.Log" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `s_log` (date_time, username, log_type,
content)
values (#{dateTime,jdbcType=TIMESTAMP}, #{username,jdbcType=VARCHAR}, #{logType,jdbcType=INTEGER},
#{content,jdbcType=VARCHAR})
</insert>
<insert id="insertSelective" parameterType="com.viontech.fanxing.commons.model.Log" useGeneratedKeys="true" keyProperty="id" keyColumn="id" >
insert into `s_log`
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="dateTime != null" >
date_time,
</if>
<if test="username != null" >
username,
</if>
<if test="logType != null" >
log_type,
</if>
<if test="content != null" >
content,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="dateTime != null" >
#{dateTime,jdbcType=TIMESTAMP},
</if>
<if test="username != null" >
#{username,jdbcType=VARCHAR},
</if>
<if test="logType != null" >
#{logType,jdbcType=INTEGER},
</if>
<if test="content != null" >
#{content,jdbcType=VARCHAR},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.viontech.fanxing.commons.model.LogExample" resultType="java.lang.Integer" >
select count(*) from `s_log` `log`
<if test="_parameter != null" >
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map" >
update `s_log` `log`
<set >
<if test="record.id != null" >
id = #{record.id,jdbcType=BIGINT},
</if>
<if test="record.dateTime != null" >
date_time = #{record.dateTime,jdbcType=TIMESTAMP},
</if>
<if test="record.username != null" >
username = #{record.username,jdbcType=VARCHAR},
</if>
<if test="record.logType != null" >
log_type = #{record.logType,jdbcType=INTEGER},
</if>
<if test="record.content != null" >
content = #{record.content,jdbcType=VARCHAR},
</if>
</set>
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map" >
update `s_log` `log`
set id = #{record.id,jdbcType=BIGINT},
date_time = #{record.dateTime,jdbcType=TIMESTAMP},
username = #{record.username,jdbcType=VARCHAR},
log_type = #{record.logType,jdbcType=INTEGER},
content = #{record.content,jdbcType=VARCHAR}
<if test="_parameter != null" >
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.viontech.fanxing.commons.model.Log" >
update `s_log`
<set >
<if test="dateTime != null" >
date_time = #{dateTime,jdbcType=TIMESTAMP},
</if>
<if test="username != null" >
username = #{username,jdbcType=VARCHAR},
</if>
<if test="logType != null" >
log_type = #{logType,jdbcType=INTEGER},
</if>
<if test="content != null" >
content = #{content,jdbcType=VARCHAR},
</if>
</set>
where id = #{id,jdbcType=BIGINT}
</update>
<update id="updateByPrimaryKey" parameterType="com.viontech.fanxing.commons.model.Log" >
update `s_log`
set date_time = #{dateTime,jdbcType=TIMESTAMP},
username = #{username,jdbcType=VARCHAR},
log_type = #{logType,jdbcType=INTEGER},
content = #{content,jdbcType=VARCHAR}
where id = #{id,jdbcType=BIGINT}
</update>
</mapper>
\ No newline at end of file
......@@ -14,6 +14,8 @@ public interface ChannelService extends BaseService<Channel> {
List<DictCodeVo> channelOrg(List<Channel> channels);
Channel add(ChannelVo channelVo);
ChannelVo update(long id, ChannelVo vo);
}
\ No newline at end of file
package com.viontech.fanxing.ops.service.adapter;
import com.viontech.fanxing.commons.base.BaseService;
import com.viontech.fanxing.commons.model.Log;
import java.util.Date;
public interface LogService extends BaseService<Log> {
void addLog(int type, Date date, String content);
}
\ No newline at end of file
......@@ -7,6 +7,7 @@ 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.constant.LogType;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.vo.ChannelVo;
......@@ -14,10 +15,7 @@ import com.viontech.fanxing.commons.vo.DictCodeVo;
import com.viontech.fanxing.commons.vo.TaskVo;
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.fanxing.ops.service.adapter.*;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -47,6 +45,8 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
private VionConfig vionConfig;
@Resource
private TaskFeignClient taskFeignClient;
@Resource
private LogService logService;
@Override
......@@ -65,6 +65,12 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
return channels;
}
@Override
public Channel add(ChannelVo channelVo) {
logService.addLog(LogType.VIDEO_RESOURCE.value, null, "添加视频资源:" + channelVo.getName());
return insertSelective(channelVo);
}
@Transactional(rollbackFor = Exception.class)
@Override
public ChannelVo update(long id, ChannelVo vo) {
......@@ -73,6 +79,8 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
throw new RuntimeException("资源不存在");
}
vo.setId(id);
vo.setUnid(channel.getUnid());
vo.setType(channel.getType());
updateByPrimaryKey(vo);
// 如果对 streamPath 进行更新,需要同时更新任务信息
......@@ -94,6 +102,8 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
}
}
}
logService.addLog(LogType.VIDEO_RESOURCE.value, null, "更新视频信息:" + vo.getName());
return vo;
}
......@@ -109,6 +119,9 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
@Override
public int deleteByPrimaryKey(Object id) {
Channel channel = super.selectByPrimaryKey(id);
if (channel == null) {
return 0;
}
JsonMessageUtil.JsonMessage<List<Task>> res = taskFeignClient.getTaskByChannelUnid(channel.getChannelUnid());
if (res.getData().size() > 0) {
throw new FanXingException("设备或文件使用中");
......@@ -119,7 +132,10 @@ public class ChannelServiceImpl extends BaseServiceImpl<Channel> implements Chan
file.delete();
file.deleteOnExit();
}
return super.deleteByPrimaryKey(id);
int i = super.deleteByPrimaryKey(id);
logService.addLog(LogType.VIDEO_RESOURCE.value, null, "删除视频资源:" + channel.getName());
return i;
}
/**
......
package com.viontech.fanxing.ops.service.impl;
import com.viontech.fanxing.commons.base.BaseMapper;
import com.viontech.fanxing.commons.base.BaseServiceImpl;
import com.viontech.fanxing.commons.model.Log;
import com.viontech.fanxing.ops.mapper.LogMapper;
import com.viontech.fanxing.ops.service.adapter.LogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
@Service
@Slf4j
public class LogServiceImpl extends BaseServiceImpl<Log> implements LogService {
@Resource
private LogMapper logMapper;
@Override
public BaseMapper<Log> getMapper() {
return logMapper;
}
@Override
public void addLog(int type, Date date, String content) {
try {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
String username = null;
if (requestAttributes != null) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
username = request.getHeader("username");
}
Log log = new Log();
log.setUsername(username);
log.setLogType(type);
log.setDateTime(date);
log.setContent(content);
this.insertSelective(log);
} catch (Exception e) {
log.error("添加日志失败", e);
}
}
}
\ No newline at end of file
......@@ -4,12 +4,14 @@ import com.alibaba.fastjson.JSONObject;
import com.viontech.fanxing.commons.base.LocalCache;
import com.viontech.fanxing.commons.config.VionConfig;
import com.viontech.fanxing.commons.constant.ChannelType;
import com.viontech.fanxing.commons.constant.LogType;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.ChannelExample;
import com.viontech.fanxing.commons.model.ChannelTag;
import com.viontech.fanxing.ops.service.adapter.ChannelService;
import com.viontech.fanxing.ops.service.adapter.ChannelTagService;
import com.viontech.fanxing.ops.service.adapter.LogService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
......@@ -22,9 +24,7 @@ import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.DoubleSummaryStatistics;
import java.util.List;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
......@@ -44,6 +44,8 @@ public class VideoService {
private VionConfig vionConfig;
@Resource
private ChannelTagService channelTagService;
@Resource
private LogService logService;
/**
* 上传存储视频文件
......@@ -51,8 +53,10 @@ public class VideoService {
@Transactional(rollbackFor = Exception.class)
public void uploadVideo(List<MultipartFile> files, List<String> tags) {
DecimalFormat decimalFormat = new DecimalFormat("0.00");
HashSet<String> fileNames = new HashSet<>();
for (MultipartFile file : files) {
String originalFilename = file.getOriginalFilename();
fileNames.add(originalFilename);
String basePath = vionConfig.getImage().getPath() + File.separator + "uploadVideo" + File.separator;
String extension = FilenameUtils.getExtension(originalFilename);
if (StringUtils.isBlank(extension) || !vionConfig.getSupportedVideoFormats().contains(extension.toLowerCase())) {
......@@ -96,6 +100,14 @@ public class VideoService {
}
}
}
if (fileNames.size() > 0) {
StringBuilder sb = new StringBuilder("上传视频:");
for (String fileName : fileNames) {
sb.append("[").append(fileName).append("]");
}
logService.addLog(LogType.VIDEO_RESOURCE.value, new Date(), sb.toString());
}
}
/**
......
......@@ -57,6 +57,9 @@ vion:
url-prefix: http://192.168.9.233:30007/images
redisson:
path: F:\myIDEAworkspace\jt\fanxing3\fanxing-commons\src\main\resources\redisson.yml
sip:
id: 800d8652-d1f5-442e-9f34-4d70a6d000a8
url: http://192.168.9.233:8888
supported-video-formats:
- mp4
- avi
......
......@@ -34,15 +34,13 @@ public class VAServerController {
*/
@PostMapping("/register")
public Object register(@RequestBody VaServerInfo vaServerInfo) {
String ip = vionConfig.getGateway().getIp();
String port = vionConfig.getGateway().getPort();
log.info("收到注册消息:{}", JSON.toJSONString(vaServerInfo));
vaServerService.registerVAServer(vaServerInfo);
HashMap<String, Object> result = new HashMap<>();
result.put("code", 200);
result.put("msg", "success");
result.put("resultRecvUrl", "http://" + ip + ":" + port + "/fanxing-forward/result");
result.put("videoUploadUrl", "http://" + ip + ":" + port + "/fanxing-forward/result/video");
result.put("resultRecvUrl", vionConfig.getReceiveResultPrefixPath() + "/fanxing-forward/result");
result.put("videoUploadUrl", vionConfig.getReceiveResultPrefixPath() + "/fanxing-forward/result/video");
return result;
}
......
......@@ -76,6 +76,7 @@ public class TaskController extends TaskBaseController {
public Object add(@RequestBody TaskVo taskVo) {
try {
taskVo = taskService.addTask(taskVo.getModel());
opsClientService.addLog("添加任务:" + taskVo.getName());
} catch (DuplicateKeyException e) {
return JsonMessageUtil.getErrorJsonMsg("任务名称重复:" + taskVo.getName());
}
......@@ -87,14 +88,22 @@ public class TaskController extends TaskBaseController {
public Object update(@PathVariable(value = "id") Long id, @RequestBody TaskVo taskVo) {
taskVo.setId(id);
taskVo = taskService.updateTask(taskVo);
opsClientService.addLog("修改任务:" + taskVo.getName());
return JsonMessageUtil.getSuccessJsonMsg("success", taskVo);
}
@Override
@DeleteMapping("/{id}")
public Object del(@PathVariable(value = "id") Long id) {
taskService.removeTask(id);
return JsonMessageUtil.getSuccessJsonMsg();
Task task = taskService.selectByPrimaryKey(id);
if (task != null) {
taskService.removeTask(id);
opsClientService.addLog("删除任务:" + task.getName());
return JsonMessageUtil.getSuccessJsonMsg();
} else {
return JsonMessageUtil.getErrorJsonMsg("任务不存在");
}
}
@GetMapping("/{id}/start")
......
package com.viontech.fanxing.task.feign;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.Content;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.StoreConfig;
import com.viontech.fanxing.commons.model.*;
import com.viontech.fanxing.commons.vo.LogVo;
import com.viontech.keliu.util.JsonMessageUtil;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -36,5 +32,7 @@ public interface OpsClient {
@GetMapping("/dictCodes")
JsonMessageUtil.JsonMessage<List<DictCode>> getDictCodeByUnid(@RequestParam("unid") String unid);
@PostMapping("/logs")
JsonMessageUtil.JsonMessage<Log> addLog(@RequestBody LogVo logVo);
}
package com.viontech.fanxing.task.service;
import com.viontech.fanxing.commons.constant.LogType;
import com.viontech.fanxing.commons.exception.FanXingException;
import com.viontech.fanxing.commons.model.Channel;
import com.viontech.fanxing.commons.model.Content;
import com.viontech.fanxing.commons.model.DictCode;
import com.viontech.fanxing.commons.model.StoreConfig;
import com.viontech.fanxing.commons.vo.LogVo;
import com.viontech.fanxing.task.feign.OpsClient;
import com.viontech.keliu.util.JsonMessageUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
......@@ -20,6 +27,7 @@ import java.util.List;
*/
@Service
@Slf4j
public class OpsClientService {
@Resource
......@@ -65,4 +73,23 @@ public class OpsClientService {
}
}
public void addLog(String content) {
try {
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
String username = null;
if (requestAttributes != null) {
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
username = request.getHeader("username");
}
LogVo logVo = new LogVo();
logVo.setUsername(username);
logVo.setLogType(LogType.TASK.value);
logVo.setContent(content);
opsClient.addLog(logVo);
} catch (Exception e) {
log.error("添加日志失败:", e);
}
}
}
......@@ -208,6 +208,7 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
}
updateStatus(id, TaskStatus.PAUSE.val);
taskDataService.addTask(task);
opsClientService.addLog("启动任务:" + task.getName());
}
/**
......@@ -219,6 +220,7 @@ public class TaskServiceImpl extends BaseServiceImpl<Task> implements TaskServic
Task task = selectByPrimaryKey(id);
taskDataService.deleteTask(task.getUnid());
updateStatus(id, TaskStatus.PAUSE.val);
opsClientService.addLog("停止任务:" + task.getName());
}
@Override
......
......@@ -58,6 +58,4 @@ vion:
ip: 192.168.9.233
rtmp-port: 1935
http-port: 30010
gateway:
ip: 192.168.9.233
port: 30000
\ No newline at end of file
receive-result-prefix-path: http://192.168.9.116:30010/api
\ No newline at end of file
......@@ -81,4 +81,9 @@ public class MainTest {
vaServerHttpService.rmTask(taskUnid, vaServerInfo);
}
@Test
public void LogTest() {
opsClientService.addLog("task test test test");
}
}
......@@ -65,5 +65,8 @@
<table delimitIdentifiers="true" tableName="s_content" alias="content" domainObjectName="Content">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
<table delimitIdentifiers="true" tableName="s_log" alias="log" domainObjectName="Log">
<generatedKey column="id" sqlStatement="JDBC"/>
</table>
</context>
</generatorConfiguration>
......@@ -5,6 +5,8 @@ upstream gateway {
}
server {
listen 30010;
server_name localhost;
location / {
alias /xmh/fanxing3/page/;
index index.html;
......
......@@ -303,6 +303,17 @@ 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');
-- 日志表
CREATE TABLE IF NOT EXISTS s_log
(
id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT,
date_time timestamp NOT NULL default CURRENT_TIMESTAMP COMMENT '名称',
username VARCHAR(32) COMMENT '用户名',
log_type int not null default -1 comment '操作类型',
content varchar(256) COMMENT '内容',
INDEX s_log_date_time_idx (date_time)
);
-- 分表
alter TABLE d_traffic PARTITION by RANGE (UNIX_TIMESTAMP(event_time))(
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!