package org.nl.system.controller.lucence;

import cn.dev33.satoken.annotation.SaIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.common.logging.annotation.Log;
import org.nl.system.service.lucene.LuceneService;
import org.nl.system.service.lucene.dto.LogQuery;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequiredArgsConstructor
@Api(tags = "日志检索")
@RequestMapping("/api/esLog")
@Slf4j
public class LuceneController {

    private final LuceneService luceneService;

    @GetMapping("/getAll")
    @Log("日志检索")
    @ApiOperation("日志检索")
    //@PreAuthorize("@el.check('task:list')")
    public ResponseEntity<Object> get(@RequestParam Map whereJson, Pageable page) {
        return new ResponseEntity<>(luceneService.getAll(whereJson, page), HttpStatus.OK);
    }

    @PostMapping("/query")
    //("日志查询")
    public ResponseEntity<Object> query(@RequestBody LogQuery query) {
        return new ResponseEntity<>(luceneService.query(query), HttpStatus.OK);
    }
    @GetMapping("/labels/{type}")
    //("获取标签")
    public ResponseEntity<Object> labelsValues(@PathVariable String type) {
        return new ResponseEntity<>(luceneService.getLabelsValues(type), HttpStatus.OK);
    }


    @DeleteMapping("/clearLogs")
    //("清空日志")
    public ResponseEntity<Object> clearLogs(@RequestBody LogQuery query) {
        luceneService.clearLogs(query);
        return new ResponseEntity<>(HttpStatus.OK);
    }



}
