/*
 * Copyright (c) 2023 codvision.com All Rights Reserved.
 */

package com.codvision.monitor.controller.manager;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.codvision.authcore.annotation.RequiresPermissions;
import com.codvision.commoncore.common.ResponseEntity;
import com.codvision.commoncore.utils.DateUtil;
import com.codvision.monitor.entity.SysLog;
import com.codvision.monitor.entity.vo.SysLogVO;
import com.codvision.monitor.service.ISysLogService;
import com.codvision.webcore.bean.QueryPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 系统日志 管理模块
 *
 * @author lingee
 * @date 2023-11-20
 */
@RestController
@RequestMapping("/v1/manager/sysLog")
@Api(tags = "平台管理端-系统日志模块")
public class ManagerSysLogController {

    @Autowired
    private ISysLogService sysLogService;

    @ApiOperation(value = "获取系统日志分页列表", notes = "获取系统日志分页列表接口")
    @PostMapping("/all")
    @RequiresPermissions("sys_log_list")
    public ResponseEntity<IPage<SysLogVO>> getPageList(@ApiParam(value = "类型") @RequestParam(value = "type", required = false, defaultValue = "") String type,
                                                       @ApiParam(value = "开始时间") @RequestParam(value = "beginTime", required = false, defaultValue = "") String beginTime,
                                                       @ApiParam(value = "结束时间") @RequestParam(value = "endTime", required = false, defaultValue = "") String endTime,
                                                       @ApiParam(value = "关键字（内容）") @RequestParam(required = false) String keyword,
                                                       @RequestParam(value = "page", required = false, defaultValue = "1") int page,
                                                       @RequestParam(value = "size", required = false, defaultValue = "10") int size) {
        SysLog queryBean = new SysLog();
        queryBean.setType(type);
        if (StrUtil.isNotBlank(beginTime)) {
            queryBean.setBeginTime(DateUtil.toDate(beginTime));
        }
        if (StrUtil.isNotBlank(endTime)) {
            queryBean.setEndTime(DateUtil.toDate(endTime));
        }
        queryBean.setContent(keyword);
        IPage<SysLogVO> pageResult = sysLogService.getPageResult(new QueryPage<>(queryBean, page, size));
        return new ResponseEntity<IPage<SysLogVO>>().ok().data(pageResult);
    }
}
