添加日志存储与查询功能

登录接口返回用户详细信息
This commit is contained in:
648540858
2021-08-07 14:05:42 +08:00
parent 94ef0d856f
commit 61f5950b4f
15 changed files with 617 additions and 11 deletions

View File

@@ -0,0 +1,93 @@
package com.genersoft.iot.vmp.vmanager.log;
import com.genersoft.iot.vmp.service.ILogService;
import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@Api(tags = "日志管理")
@CrossOrigin
@RestController
@RequestMapping("/api/log")
public class LogController {
@Autowired
private ILogService logService;
private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 分页查询日志
*
* @param query 查询内容
* @param page 当前页
* @param count 每页查询数量
* @param type 类型
* @param startTime 开始时间
* @param endTime 结束时间
* @return
*/
@ApiOperation("分页查询报警")
@GetMapping("/all")
@ApiImplicitParams({
@ApiImplicitParam(name="query", value = "查询内容", dataTypeClass = String.class),
@ApiImplicitParam(name="page", value = "当前页", required = true ,dataTypeClass = Integer.class),
@ApiImplicitParam(name="count", value = "每页查询数量", required = true ,dataTypeClass = Integer.class),
@ApiImplicitParam(name="type", value = "类型" ,dataTypeClass = String.class),
@ApiImplicitParam(name="startTime", value = "查询内容" ,dataTypeClass = String.class),
@ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class),
})
public ResponseEntity<PageInfo<LogDto>> getAll(
@RequestParam int page,
@RequestParam int count,
@RequestParam(required = false) String query,
@RequestParam(required = false) String type,
@RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime
) {
if (StringUtils.isEmpty(query)) query = null;
if (StringUtils.isEmpty(startTime)) startTime = null;
if (StringUtils.isEmpty(endTime)) endTime = null;
try {
if (startTime != null) format.parse(startTime);
if (endTime != null) format.parse(endTime);
} catch (ParseException e) {
return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
}
PageInfo<LogDto> allLog = logService.getAll(page, count, query, type, startTime, endTime);
return new ResponseEntity<>(allLog, HttpStatus.OK);
}
/**
* 清空日志
*
*/
@ApiOperation("清空日志")
@DeleteMapping("/clear")
@ApiImplicitParams({})
public ResponseEntity<WVPResult<String>> clear() {
int count = logService.clear();
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(0);
wvpResult.setMsg("success");
wvpResult.setData(count);
return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
}
}

View File

@@ -17,9 +17,7 @@ import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.*;
import javax.security.sasl.AuthenticationException;
import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Api(tags = "用户管理")
@@ -42,19 +40,25 @@ public class UserController {
@ApiImplicitParam(name = "password", required = true, value = "密码32位md5加密", dataTypeClass = String.class),
})
@GetMapping("/login")
public String login(@RequestParam String username, @RequestParam String password){
LoginUser user;
public WVPResult<LoginUser> login(@RequestParam String username, @RequestParam String password){
LoginUser user = null;
WVPResult<LoginUser> result = new WVPResult<>();
try {
user = SecurityUtils.login(username, password, authenticationManager);
} catch (AuthenticationException e) {
e.printStackTrace();
return "fail";
result.setCode(-1);
result.setMsg("fail");
}
if (user != null) {
return "success";
result.setCode(0);
result.setMsg("success");
result.setData(user);
}else {
return "fail";
result.setCode(-1);
result.setMsg("fail");
}
return result;
}
@ApiOperation("修改密码")