All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rexsheng.springboot.faster.system.log.adapter.LogController Maven / Gradle / Ivy

The newest version!
package com.github.rexsheng.springboot.faster.system.log.adapter;

import com.github.rexsheng.springboot.faster.common.domain.Result;
import com.github.rexsheng.springboot.faster.system.log.application.LogService;
import com.github.rexsheng.springboot.faster.system.log.application.dto.QueryLogRequest;
import com.github.rexsheng.springboot.faster.system.utils.AuthenticationUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/log")
@Tag(name = "LogController",description = "日志管理")
@ConditionalOnProperty(prefix = "app.module.management",name = "controller",havingValue = "true",matchIfMissing = true)
@ConditionalOnClass({Authentication.class,SqlSessionFactoryBean.class})
public class LogController {

    @Resource
    private LogService logService;

    @PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).LOG_LIST)")
    @GetMapping
    public Result queryLogList(@RequestParam(required = false) String keyword,
                               @RequestParam(required = true) String startTime,
                               @RequestParam(required = true) String endTime,
                               @RequestParam(required = false) Long operateUser,
                               @RequestParam(required = false) Boolean error,
                               @RequestParam(required = false) String requestMethod,
                               @RequestParam(required = false) String requestUrl,
                               @RequestParam(required = false) String module,
                               @RequestParam Long pageIndex,
                               @RequestParam Long pageSize){
        QueryLogRequest request=new QueryLogRequest();
        request.setStartTime(startTime);
        request.setEndTime(endTime);
        request.setPageIndex(pageIndex);
        request.setPageSize(pageSize);
        request.setOperateUser(operateUser);
        request.setKeyword(keyword);
        request.setError(error);
        request.setRequestMethod(requestMethod);
        request.setRequestUrl(requestUrl);
        request.setModule(module);
        return Result.success(logService.queryLogList(request));
    }

    @GetMapping("/personal")
    @PreAuthorize("@ss.denyApi()")
    public Result queryUserLogList(Authentication authentication,
                                   @RequestParam(required = true) String startTime,
                                   @RequestParam(required = true) String endTime,
                                   @RequestParam Long pageIndex){
        QueryLogRequest request=new QueryLogRequest();
        request.setStartTime(startTime);
        request.setEndTime(endTime);
        request.setPageIndex(pageIndex);
        request.setPageSize(10L);
        request.setOperateUser(AuthenticationUtil.getUserIdFromAuthentication(authentication));
        request.setSearchNullableMethodNote(false);
        return Result.success(logService.queryLogList(request));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy