| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 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);
- }
- }
|