package org.nl.system.controller.redis;

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.redis.RedisService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: lyd
 * @Description: Redis监控管理
 * @Date: 2022-08-04
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "系统表格管理")
@RequestMapping("/api/redis")
@Slf4j
public class RedisController {

    private final RedisService redisService;

    @GetMapping("/get-monitor-info")
    @Log("查询redis的信息")
    @ApiOperation("查询redis的信息")
    public ResponseEntity<Object> getRedisMonitorInfo() {
        return new ResponseEntity<>(redisService.getRedisMonitorInfo(),HttpStatus.OK);
    }

    @GetMapping("/get-key-define-list")
    @Log("获得 Redis Key 模板列表")
    @ApiOperation("获得 Redis Key 模板列表")
    public ResponseEntity<Object> getKeyDefineList() {
        return new ResponseEntity<>(redisService.getKeyDefineList(),HttpStatus.OK);
    }

    @GetMapping("/get-key-value-list")
    @Log("获得 Redis Key Value列表")
    @ApiOperation("获得 Redis Key Value列表")
    public ResponseEntity<Object> getKeyValueList() {
        return new ResponseEntity<>( redisService.getKeyValueList(),HttpStatus.OK);
    }

    @Log("根据key删除Redis数据")
    @ApiOperation("根据key删除Redis数据")
    @DeleteMapping
    public ResponseEntity<Object> deleteByKey(@RequestBody String[] ids) {
        redisService.deleteByKey(ids);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }


}
