LogController.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package com.genersoft.iot.vmp.vmanager.log;
  2. import com.genersoft.iot.vmp.service.ILogService;
  3. import com.genersoft.iot.vmp.storager.dao.dto.LogDto;
  4. import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
  5. import com.github.pagehelper.PageInfo;
  6. import io.swagger.annotations.Api;
  7. import io.swagger.annotations.ApiImplicitParam;
  8. import io.swagger.annotations.ApiImplicitParams;
  9. import io.swagger.annotations.ApiOperation;
  10. import org.springframework.beans.factory.annotation.Autowired;
  11. import org.springframework.http.HttpStatus;
  12. import org.springframework.http.ResponseEntity;
  13. import org.springframework.util.StringUtils;
  14. import org.springframework.web.bind.annotation.*;
  15. import java.text.ParseException;
  16. import java.text.SimpleDateFormat;
  17. @Api(tags = "日志管理")
  18. @CrossOrigin
  19. @RestController
  20. @RequestMapping("/api/log")
  21. public class LogController {
  22. @Autowired
  23. private ILogService logService;
  24. private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  25. /**
  26. * 分页查询日志
  27. *
  28. * @param query 查询内容
  29. * @param page 当前页
  30. * @param count 每页查询数量
  31. * @param type 类型
  32. * @param startTime 开始时间
  33. * @param endTime 结束时间
  34. * @return
  35. */
  36. @ApiOperation("分页查询报警")
  37. @GetMapping("/all")
  38. @ApiImplicitParams({
  39. @ApiImplicitParam(name="query", value = "查询内容", dataTypeClass = String.class),
  40. @ApiImplicitParam(name="page", value = "当前页", required = true ,dataTypeClass = Integer.class),
  41. @ApiImplicitParam(name="count", value = "每页查询数量", required = true ,dataTypeClass = Integer.class),
  42. @ApiImplicitParam(name="type", value = "类型" ,dataTypeClass = String.class),
  43. @ApiImplicitParam(name="startTime", value = "查询内容" ,dataTypeClass = String.class),
  44. @ApiImplicitParam(name="endTime", value = "查询内容" ,dataTypeClass = String.class),
  45. })
  46. public ResponseEntity<PageInfo<LogDto>> getAll(
  47. @RequestParam int page,
  48. @RequestParam int count,
  49. @RequestParam(required = false) String query,
  50. @RequestParam(required = false) String type,
  51. @RequestParam(required = false) String startTime,
  52. @RequestParam(required = false) String endTime
  53. ) {
  54. if (StringUtils.isEmpty(query)) query = null;
  55. if (StringUtils.isEmpty(startTime)) startTime = null;
  56. if (StringUtils.isEmpty(endTime)) endTime = null;
  57. try {
  58. if (startTime != null) format.parse(startTime);
  59. if (endTime != null) format.parse(endTime);
  60. } catch (ParseException e) {
  61. return new ResponseEntity<>(null, HttpStatus.BAD_REQUEST);
  62. }
  63. PageInfo<LogDto> allLog = logService.getAll(page, count, query, type, startTime, endTime);
  64. return new ResponseEntity<>(allLog, HttpStatus.OK);
  65. }
  66. /**
  67. * 清空日志
  68. *
  69. */
  70. @ApiOperation("清空日志")
  71. @DeleteMapping("/clear")
  72. @ApiImplicitParams({})
  73. public ResponseEntity<WVPResult<String>> clear() {
  74. int count = logService.clear();
  75. WVPResult wvpResult = new WVPResult();
  76. wvpResult.setCode(0);
  77. wvpResult.setMsg("success");
  78. wvpResult.setData(count);
  79. return new ResponseEntity<WVPResult<String>>(wvpResult, HttpStatus.OK);
  80. }
  81. }