Commit 61f5950b4fbc0c9d59ac755314c0d1a9efb702bc

Authored by 648540858
1 parent 94ef0d85

添加日志存储与查询功能

登录接口返回用户详细信息
sql/mysql.sql
... ... @@ -74,7 +74,19 @@ create table device_alarm
74 74 alarmType varchar(50)
75 75 );
76 76  
77   -
  77 +create table log
  78 +(
  79 + id int auto_increment
  80 + primary key,
  81 + name varchar(50) not null,
  82 + type varchar(50) not null,
  83 + uri varchar(200) not null,
  84 + address varchar(50) not null,
  85 + result varchar(50) not null,
  86 + timing bigint not null,
  87 + username varchar(50) not null,
  88 + createTime varchar(50) not null
  89 +);
78 90  
79 91 create table device_mobile_position
80 92 (
... ...
src/main/java/com/genersoft/iot/vmp/VManageBootstrap.java
... ... @@ -4,6 +4,7 @@ import java.util.logging.LogManager;
4 4  
5 5 import org.springframework.boot.SpringApplication;
6 6 import org.springframework.boot.autoconfigure.SpringBootApplication;
  7 +import org.springframework.boot.web.servlet.ServletComponentScan;
7 8 import org.springframework.context.ConfigurableApplicationContext;
8 9 import org.springframework.scheduling.annotation.EnableScheduling;
9 10 import springfox.documentation.oas.annotations.EnableOpenApi;
... ... @@ -11,6 +12,7 @@ import springfox.documentation.oas.annotations.EnableOpenApi;
11 12 /**
12 13 *
13 14 */
  15 +@ServletComponentScan("com.genersoft.iot.vmp.conf")
14 16 @SpringBootApplication
15 17 @EnableScheduling
16 18 @EnableOpenApi
... ...
src/main/java/com/genersoft/iot/vmp/common/ApiSaveConstant.java 0 → 100644
  1 +package com.genersoft.iot.vmp.common;
  2 +
  3 +public class ApiSaveConstant {
  4 +
  5 + public static String getVal(String key) {
  6 + String[] keyItemArray = key.split("/");
  7 + if (keyItemArray.length <= 1 || !"api".equals(keyItemArray[1])) {
  8 + return null;
  9 + }
  10 + if (keyItemArray.length >= 4) {
  11 + switch (keyItemArray[2]) {
  12 + case "alarm":
  13 + if ("delete".equals(keyItemArray[3])) {
  14 + return "删除报警";
  15 + }
  16 + break;
  17 + case "device":
  18 + switch (keyItemArray[3]) {
  19 + case "config":
  20 + if (keyItemArray.length >= 5 && "basicParam".equals(keyItemArray[4])) {
  21 + return "[设备配置] 基本配置设置命令";
  22 + }
  23 + break;
  24 + case "control":
  25 + switch (keyItemArray[4]) {
  26 + case "teleboot":
  27 + return "[设备控制] 远程启动";
  28 + case "record":
  29 + return "[设备控制] 录像控制";
  30 + case "guard":
  31 + return "[设备控制] 布防/撤防命令";
  32 + case "reset_alarm":
  33 + return "[设备控制] 报警复位";
  34 + case "i_frame":
  35 + return "[设备控制] 强制关键帧";
  36 + case "home_position":
  37 + return "[设备控制] 看守位控制";
  38 + }
  39 + break;
  40 + case "query":
  41 + if (keyItemArray.length <= 5) return null;
  42 + switch (keyItemArray[4]) {
  43 + case "devices":
  44 + if (keyItemArray.length < 7) return null;
  45 + switch (keyItemArray[6]) {
  46 + case "sync":
  47 + return "[设备查询] 同步设备通道";
  48 + case "delete":
  49 + return "[设备查询] 移除设备";
  50 + }
  51 + break;
  52 + case "channel":
  53 + return "[设备查询] 更新通道信息";
  54 + case "transport":
  55 + return "[设备查询] 修改数据流传输模式";
  56 + }
  57 + break;
  58 + }
  59 + case "gbStream":
  60 + switch (keyItemArray[3]) {
  61 + case "del":
  62 + return "移除通道与国标的关联";
  63 + case "add":
  64 + return "添加通道与国标的关联";
  65 + }
  66 + break;
  67 + case "media":
  68 + break;
  69 + case "position":
  70 + if ("subscribe".equals(keyItemArray[3])) {
  71 + return "订阅位置信息";
  72 + }
  73 + break;
  74 + case "platform":
  75 + switch (keyItemArray[3]) {
  76 + case "save":
  77 + return "添加上级平台";
  78 + case "delete":
  79 + return "移除上级平台";
  80 + case "update_channel_for_gb":
  81 + return "向上级平台添加国标通道";
  82 + case "del_channel_for_gb":
  83 + return "从上级平台移除国标通道";
  84 + }
  85 + break;
  86 + case "platform_gb_stream":
  87 + break;
  88 + case "play":
  89 + switch (keyItemArray[3]) {
  90 + case "start":
  91 + return "开始点播";
  92 + case "stop":
  93 + return "停止点播";
  94 + case "convert":
  95 + return "转码";
  96 + case "convertStop":
  97 + return "结束转码";
  98 + case "broadcast":
  99 + return "语音广播";
  100 + }
  101 + break;
  102 + case "download":
  103 + switch (keyItemArray[3]) {
  104 + case "start":
  105 + return "开始历史媒体下载";
  106 + case "stop":
  107 + return "停止历史媒体下载";
  108 + }
  109 + break;
  110 + case "playback":
  111 + switch (keyItemArray[3]) {
  112 + case "start":
  113 + return "开始视频回放";
  114 + case "stop":
  115 + return "停止视频回放";
  116 + }
  117 + break;
  118 + case "ptz":
  119 + switch (keyItemArray[3]) {
  120 + case "control":
  121 + return "云台控制";
  122 + case "front_end_command":
  123 + return "通用前端控制命令";
  124 + }
  125 + break;
  126 + case "gb_record":
  127 + break;
  128 + case "onvif":
  129 + break;
  130 + case "server":
  131 + if ("restart".equals(keyItemArray[3])) {
  132 + return "重启流媒体服务";
  133 + }
  134 + break;
  135 + case "proxy":
  136 + switch (keyItemArray[3]) {
  137 + case "save":
  138 + return "保存代理";
  139 + case "del":
  140 + return "移除代理";
  141 + case "start":
  142 + return "启用代理";
  143 + case "stop":
  144 + return "停用代理";
  145 + }
  146 + break;
  147 + case "push":
  148 + switch (keyItemArray[3]) {
  149 + case "save_to_gb":
  150 + return "将推流添加到国标";
  151 + case "remove_form_gb":
  152 + return "将推流移出到国标";
  153 + }
  154 + break;
  155 + case "user":
  156 + switch (keyItemArray[3]) {
  157 + case "login":
  158 + return "登录";
  159 + case "changePassword":
  160 + return "修改密码";
  161 + case "add":
  162 + return "添加用户";
  163 + case "delete":
  164 + return "删除用户";
  165 + }
  166 + break;
  167 + }
  168 + }
  169 + return null;
  170 + }
  171 +}
  172 +
... ...
src/main/java/com/genersoft/iot/vmp/conf/ApiAccessFilter.java 0 → 100644
  1 +package com.genersoft.iot.vmp.conf;
  2 +
  3 +import com.genersoft.iot.vmp.common.ApiSaveConstant;
  4 +import com.genersoft.iot.vmp.conf.security.SecurityUtils;
  5 +import com.genersoft.iot.vmp.service.ILogService;
  6 +import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
  7 +import org.apache.commons.lang3.StringUtils;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.http.HttpStatus;
  12 +import org.springframework.web.filter.OncePerRequestFilter;
  13 +
  14 +import javax.servlet.*;
  15 +import javax.servlet.annotation.WebFilter;
  16 +import javax.servlet.http.HttpServletRequest;
  17 +import javax.servlet.http.HttpServletResponse;
  18 +import java.io.IOException;
  19 +import java.text.SimpleDateFormat;
  20 +
  21 +@WebFilter(filterName = "ApiAccessFilter", urlPatterns = "/api/*", asyncSupported=true)
  22 +public class ApiAccessFilter extends OncePerRequestFilter {
  23 +
  24 + private final static Logger logger = LoggerFactory.getLogger(ApiAccessFilter.class);
  25 +
  26 + private final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  27 +
  28 + @Autowired
  29 + private UserSetup userSetup;
  30 +
  31 + @Autowired
  32 + private ILogService logService;
  33 +
  34 +
  35 + @Override
  36 + protected void doFilterInternal(HttpServletRequest servletRequest, HttpServletResponse servletResponse, FilterChain filterChain) throws ServletException, IOException {
  37 + String username = null;
  38 + if (SecurityUtils.getUserInfo() == null) {
  39 + username = servletRequest.getParameter("username");
  40 + }else {
  41 + username = SecurityUtils.getUserInfo().getUsername();
  42 + }
  43 + long start = System.currentTimeMillis(); // 请求进入时间
  44 + String uriName = ApiSaveConstant.getVal(servletRequest.getRequestURI());
  45 +
  46 + filterChain.doFilter(servletRequest, servletResponse);
  47 +
  48 + if (uriName != null && userSetup.getLogInDatebase()) {
  49 +
  50 + LogDto logDto = new LogDto();
  51 + logDto.setName(uriName);
  52 + logDto.setUsername(username);
  53 + logDto.setAddress(servletRequest.getRemoteAddr());
  54 + logDto.setResult(HttpStatus.valueOf(servletResponse.getStatus()).toString());
  55 + logDto.setTiming(System.currentTimeMillis() - start);
  56 + logDto.setType(servletRequest.getMethod());
  57 + logDto.setUri(servletRequest.getRequestURI());
  58 + logDto.setCreateTime(format.format(System.currentTimeMillis()));
  59 + logService.add(logDto);
  60 +// logger.warn("[Api Access] [{}] [{}] [{}] [{}] [{}] {}ms",
  61 +// uriName, servletRequest.getMethod(), servletRequest.getRequestURI(), servletRequest.getRemoteAddr(), HttpStatus.valueOf(servletResponse.getStatus()),
  62 +// System.currentTimeMillis() - start);
  63 +
  64 + }
  65 + }
  66 +
  67 + /**
  68 + * 获取IP地址
  69 + *
  70 + * @param request 请求
  71 + * @return request发起客户端的IP地址
  72 + */
  73 + private String getIP(HttpServletRequest request) {
  74 + if (request == null) {
  75 + return "0.0.0.0";
  76 + }
  77 +
  78 + String Xip = request.getHeader("X-Real-IP");
  79 + String XFor = request.getHeader("X-Forwarded-For");
  80 +
  81 + String UNKNOWN_IP = "unknown";
  82 + if (StringUtils.isNotEmpty(XFor) && !UNKNOWN_IP.equalsIgnoreCase(XFor)) {
  83 + //多次反向代理后会有多个ip值,第一个ip才是真实ip
  84 + int index = XFor.indexOf(",");
  85 + if (index != -1) {
  86 + return XFor.substring(0, index);
  87 + } else {
  88 + return XFor;
  89 + }
  90 + }
  91 +
  92 + XFor = Xip;
  93 + if (StringUtils.isNotEmpty(XFor) && !UNKNOWN_IP.equalsIgnoreCase(XFor)) {
  94 + return XFor;
  95 + }
  96 +
  97 + if (StringUtils.isBlank(XFor) || UNKNOWN_IP.equalsIgnoreCase(XFor)) {
  98 + XFor = request.getHeader("Proxy-Client-IP");
  99 + }
  100 + if (StringUtils.isBlank(XFor) || UNKNOWN_IP.equalsIgnoreCase(XFor)) {
  101 + XFor = request.getHeader("WL-Proxy-Client-IP");
  102 + }
  103 + if (StringUtils.isBlank(XFor) || UNKNOWN_IP.equalsIgnoreCase(XFor)) {
  104 + XFor = request.getHeader("HTTP_CLIENT_IP");
  105 + }
  106 + if (StringUtils.isBlank(XFor) || UNKNOWN_IP.equalsIgnoreCase(XFor)) {
  107 + XFor = request.getHeader("HTTP_X_FORWARDED_FOR");
  108 + }
  109 + if (StringUtils.isBlank(XFor) || UNKNOWN_IP.equalsIgnoreCase(XFor)) {
  110 + XFor = request.getRemoteAddr();
  111 + }
  112 + return XFor;
  113 + }
  114 +}
... ...
src/main/java/com/genersoft/iot/vmp/conf/UserSetup.java
... ... @@ -25,6 +25,8 @@ public class UserSetup {
25 25  
26 26 private Boolean recordPushLive = Boolean.FALSE;
27 27  
  28 + private Boolean logInDatebase = Boolean.TRUE;
  29 +
28 30 private List<String> interfaceAuthenticationExcludes = new ArrayList<>();
29 31  
30 32 public Boolean getSavePositionHistory() {
... ... @@ -94,4 +96,12 @@ public class UserSetup {
94 96 public void setInterfaceAuthenticationExcludes(List<String> interfaceAuthenticationExcludes) {
95 97 this.interfaceAuthenticationExcludes = interfaceAuthenticationExcludes;
96 98 }
  99 +
  100 + public Boolean getLogInDatebase() {
  101 + return logInDatebase;
  102 + }
  103 +
  104 + public void setLogInDatebase(Boolean logInDatebase) {
  105 + this.logInDatebase = logInDatebase;
  106 + }
97 107 }
... ...
src/main/java/com/genersoft/iot/vmp/conf/security/SecurityUtils.java
... ... @@ -48,7 +48,7 @@ public class SecurityUtils {
48 48 Authentication authentication = getAuthentication();
49 49 if(authentication!=null){
50 50 Object principal = authentication.getPrincipal();
51   - if(principal!=null){
  51 + if(principal!=null && !"anonymousUser".equals(principal)){
52 52 LoginUser user = (LoginUser) authentication.getPrincipal();
53 53 return user;
54 54 }
... ...
src/main/java/com/genersoft/iot/vmp/service/ILogService.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service;
  2 +
  3 +import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
  4 +import com.github.pagehelper.PageInfo;
  5 +
  6 +/**
  7 + * 系统日志
  8 + */
  9 +public interface ILogService {
  10 +
  11 + /**
  12 + * 查询日志
  13 + * @param page 当前页
  14 + * @param count 每页数量
  15 + * @param query 搜索内容
  16 + * @param type 类型
  17 + * @param startTime 开始时间
  18 + * @param endTime 结束时间
  19 + * @return 日志列表
  20 + */
  21 + PageInfo<LogDto> getAll(int page, int count, String query, String type, String startTime, String endTime);
  22 +
  23 + /**
  24 + * 添加日志
  25 + * @param logDto 日志
  26 + */
  27 + void add(LogDto logDto);
  28 +
  29 + /**
  30 + * 清空
  31 + */
  32 + int clear();
  33 +
  34 +}
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/LogServiceImpl.java 0 → 100644
  1 +package com.genersoft.iot.vmp.service.impl;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
  4 +import com.genersoft.iot.vmp.service.ILogService;
  5 +import com.genersoft.iot.vmp.storager.dao.LogMapper;
  6 +import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
  7 +import com.github.pagehelper.PageHelper;
  8 +import com.github.pagehelper.PageInfo;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +import java.util.List;
  13 +
  14 +@Service
  15 +public class LogServiceImpl implements ILogService {
  16 +
  17 + @Autowired
  18 + private LogMapper logMapper;
  19 +
  20 + @Override
  21 + public PageInfo<LogDto> getAll(int page, int count, String query, String type, String startTime, String endTime) {
  22 + PageHelper.startPage(page, count);
  23 + List<LogDto> all = logMapper.query(query, type, startTime, endTime);
  24 + return new PageInfo<>(all);
  25 + }
  26 +
  27 + @Override
  28 + public void add(LogDto logDto) {
  29 + logMapper.add(logDto);
  30 + }
  31 +
  32 + @Override
  33 + public int clear() {
  34 + return logMapper.clear();
  35 + }
  36 +}
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
... ... @@ -342,12 +342,14 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR
342 342  
343 343 if (redisUtil.zSize(key) == null || redisUtil.zSize(key) == 0) {
344 344 logger.info("获取负载最低的节点时无在线节点");
  345 + return null;
345 346 }
346 347  
347 348 // 获取分数最低的,及并发最低的
348 349 Set<Object> objects = redisUtil.ZRange(key, 0, -1);
349   - ArrayList<Object> MediaServerObjectS = new ArrayList<>(objects);
350   - String mediaServerId = (String)MediaServerObjectS.get(0);
  350 + ArrayList<Object> mediaServerObjectS = new ArrayList<>(objects);
  351 +
  352 + String mediaServerId = (String)mediaServerObjectS.get(0);
351 353 return getOne(mediaServerId);
352 354 }
353 355  
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/LogMapper.java 0 → 100644
  1 +package com.genersoft.iot.vmp.storager.dao;
  2 +
  3 +import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
  4 +import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
  5 +import org.apache.ibatis.annotations.Delete;
  6 +import org.apache.ibatis.annotations.Insert;
  7 +import org.apache.ibatis.annotations.Mapper;
  8 +import org.apache.ibatis.annotations.Select;
  9 +import org.springframework.stereotype.Repository;
  10 +
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * 用于存储设服务的日志
  15 + */
  16 +@Mapper
  17 +@Repository
  18 +public interface LogMapper {
  19 +
  20 + @Insert("insert into log ( name, type, uri, address, result, timing, username, createTime) " +
  21 + "values ('${name}', '${type}', '${uri}', '${address}', '${result}', ${timing}, '${username}', '${createTime}')")
  22 + int add(LogDto logDto);
  23 +
  24 +
  25 + @Select(value = {"<script>" +
  26 + " SELECT * FROM log " +
  27 + " WHERE 1=1 " +
  28 + " <if test=\"query != null\"> AND (name LIKE '%${query}%')</if> " +
  29 + " <if test=\"type != null\" > AND type = '${type}'</if>" +
  30 + " <if test=\"startTime != null\" > AND createTime &gt;= '${startTime}' </if>" +
  31 + " <if test=\"endTime != null\" > AND createTime &lt;= '${endTime}' </if>" +
  32 + " ORDER BY createTime DESC " +
  33 + " </script>"})
  34 + List<LogDto> query(String query, String type, String startTime, String endTime);
  35 +
  36 +
  37 + @Delete("DELETE FROM log")
  38 + int clear();
  39 +}
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/dto/LogDto.java 0 → 100644
  1 +package com.genersoft.iot.vmp.storager.dao.dto;
  2 +
  3 +public class LogDto {
  4 +
  5 + private int id;
  6 + private String name;
  7 + private String type;
  8 + private String uri;
  9 + private String address;
  10 + private String result;
  11 + private long timing;
  12 + private String username;
  13 + private String createTime;
  14 +
  15 + public int getId() {
  16 + return id;
  17 + }
  18 +
  19 + public void setId(int id) {
  20 + this.id = id;
  21 + }
  22 +
  23 + public String getName() {
  24 + return name;
  25 + }
  26 +
  27 + public void setName(String name) {
  28 + this.name = name;
  29 + }
  30 +
  31 + public String getType() {
  32 + return type;
  33 + }
  34 +
  35 + public void setType(String type) {
  36 + this.type = type;
  37 + }
  38 +
  39 + public String getUri() {
  40 + return uri;
  41 + }
  42 +
  43 + public void setUri(String uri) {
  44 + this.uri = uri;
  45 + }
  46 +
  47 + public String getAddress() {
  48 + return address;
  49 + }
  50 +
  51 + public void setAddress(String address) {
  52 + this.address = address;
  53 + }
  54 +
  55 + public String getResult() {
  56 + return result;
  57 + }
  58 +
  59 + public void setResult(String result) {
  60 + this.result = result;
  61 + }
  62 +
  63 + public long getTiming() {
  64 + return timing;
  65 + }
  66 +
  67 + public void setTiming(long timing) {
  68 + this.timing = timing;
  69 + }
  70 +
  71 + public String getUsername() {
  72 + return username;
  73 + }
  74 +
  75 + public void setUsername(String username) {
  76 + this.username = username;
  77 + }
  78 +
  79 + public String getCreateTime() {
  80 + return createTime;
  81 + }
  82 +
  83 + public void setCreateTime(String createTime) {
  84 + this.createTime = createTime;
  85 + }
  86 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/log/LogController.java 0 → 100644
  1 +package com.genersoft.iot.vmp.vmanager.log;
  2 +
  3 +import com.genersoft.iot.vmp.service.ILogService;
  4 +import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
  5 +import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
  6 +import com.github.pagehelper.PageInfo;
  7 +import io.swagger.annotations.Api;
  8 +import io.swagger.annotations.ApiImplicitParam;
  9 +import io.swagger.annotations.ApiImplicitParams;
  10 +import io.swagger.annotations.ApiOperation;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.http.HttpStatus;
  13 +import org.springframework.http.ResponseEntity;
  14 +import org.springframework.util.StringUtils;
  15 +import org.springframework.web.bind.annotation.*;
  16 +
  17 +import java.text.ParseException;
  18 +import java.text.SimpleDateFormat;
  19 +
  20 +@Api(tags = "日志管理")
  21 +@CrossOrigin
  22 +@RestController
  23 +@RequestMapping("/api/log")
  24 +public class LogController {
  25 +
  26 + @Autowired
  27 + private ILogService logService;
  28 +
  29 + private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  30 +
  31 + /**
  32 + * 分页查询日志
  33 + *
  34 + * @param query 查询内容
  35 + * @param page 当前页
  36 + * @param count 每页查询数量
  37 + * @param type 类型
  38 + * @param startTime 开始时间
  39 + * @param endTime 结束时间
  40 + * @return
  41 + */
  42 + @ApiOperation("分页查询报警")
  43 + @GetMapping("/all")
  44 + @ApiImplicitParams({
  45 + @ApiImplicitParam(name="query", value = "查询内容", dataTypeClass = String.class),
  46 + @ApiImplicitParam(name="page", value = "当前页", required = true ,dataTypeClass = Integer.class),
  47 + @ApiImplicitParam(name="count", value = "每页查询数量", required = true ,dataTypeClass = Integer.class),
  48 + @ApiImplicitParam(name="type", value = "类型" ,dataTypeClass = String.class),
  49 + @ApiImplicitParam(name="startTime", value = "查询内容" ,dataTypeClass = String.class),
  50 + @ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class),
  51 + })
  52 + public ResponseEntity<PageInfo<LogDto>> getAll(
  53 + @RequestParam int page,
  54 + @RequestParam int count,
  55 + @RequestParam(required = false) String query,
  56 + @RequestParam(required = false) String type,
  57 + @RequestParam(required = false) String startTime,
  58 + @RequestParam(required = false) String endTime
  59 + ) {
  60 + if (StringUtils.isEmpty(query)) query = null;
  61 + if (StringUtils.isEmpty(startTime)) startTime = null;
  62 + if (StringUtils.isEmpty(endTime)) endTime = null;
  63 +
  64 +
  65 + try {
  66 + if (startTime != null) format.parse(startTime);
  67 + if (endTime != null) format.parse(endTime);
  68 + } catch (ParseException e) {
  69 + return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
  70 + }
  71 +
  72 + PageInfo<LogDto> allLog = logService.getAll(page, count, query, type, startTime, endTime);
  73 + return new ResponseEntity<>(allLog, HttpStatus.OK);
  74 + }
  75 +
  76 + /**
  77 + * 清空日志
  78 + *
  79 + */
  80 + @ApiOperation("清空日志")
  81 + @DeleteMapping("/clear")
  82 + @ApiImplicitParams({})
  83 + public ResponseEntity<WVPResult<String>> clear() {
  84 +
  85 + int count = logService.clear();
  86 + WVPResult wvpResult = new WVPResult();
  87 + wvpResult.setCode(0);
  88 + wvpResult.setMsg("success");
  89 + wvpResult.setData(count);
  90 + return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
  91 + }
  92 +
  93 +}
... ...
src/main/java/com/genersoft/iot/vmp/vmanager/user/UserController.java
... ... @@ -17,9 +17,7 @@ import org.springframework.util.DigestUtils;
17 17 import org.springframework.web.bind.annotation.*;
18 18  
19 19 import javax.security.sasl.AuthenticationException;
20   -import javax.xml.crypto.Data;
21 20 import java.text.SimpleDateFormat;
22   -import java.util.Date;
23 21 import java.util.List;
24 22  
25 23 @Api(tags = "用户管理")
... ... @@ -42,19 +40,25 @@ public class UserController {
42 40 @ApiImplicitParam(name = "password", required = true, value = "密码(32位md5加密)", dataTypeClass = String.class),
43 41 })
44 42 @GetMapping("/login")
45   - public String login(@RequestParam String username, @RequestParam String password){
46   - LoginUser user;
  43 + public WVPResult<LoginUser> login(@RequestParam String username, @RequestParam String password){
  44 + LoginUser user = null;
  45 + WVPResult<LoginUser> result = new WVPResult<>();
47 46 try {
48 47 user = SecurityUtils.login(username, password, authenticationManager);
49 48 } catch (AuthenticationException e) {
50 49 e.printStackTrace();
51   - return "fail";
  50 + result.setCode(-1);
  51 + result.setMsg("fail");
52 52 }
53 53 if (user != null) {
54   - return "success";
  54 + result.setCode(0);
  55 + result.setMsg("success");
  56 + result.setData(user);
55 57 }else {
56   - return "fail";
  58 + result.setCode(-1);
  59 + result.setMsg("fail");
57 60 }
  61 + return result;
58 62 }
59 63  
60 64 @ApiOperation("修改密码")
... ...
src/main/resources/all-application.yml
... ... @@ -150,6 +150,8 @@ user-settings:
150 150 - /api/v1/**
151 151 # 推流直播是否录制
152 152 record-push-live: true
  153 + # 是否将日志存储进数据库
  154 + logInDatebase: true
153 155  
154 156 # 在线文档: swagger-ui(生产环境建议关闭)
155 157 swagger-ui:
... ...
src/main/resources/wvp.sqlite
No preview for this file type