swagger 完善 + requestInterceptors 记录访问请求
This commit is contained in:
parent
fb7a911c6f
commit
f5e65eb274
10
api/pom.xml
10
api/pom.xml
@ -43,10 +43,20 @@
|
||||
<artifactId>springdoc-openapi-starter-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>jakarta.servlet</groupId>
|
||||
<artifactId>jakarta.servlet-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -11,6 +11,7 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springdoc.core.annotations.ParameterObject;
|
||||
import org.springdoc.core.models.GroupedOpenApi;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@Tag(name="历史录像")
|
||||
@ -26,7 +27,7 @@ public class RecordController {
|
||||
}
|
||||
|
||||
@GetJson("/getInfo")
|
||||
public JsonResponse<Void> getInfo(@ParameterObject GetInfoDTO dto){
|
||||
public JsonResponse<Void> getInfo(@ParameterObject @Validated GetInfoDTO dto){
|
||||
recordService.requestRecordInfo(dto.getDeviceId());
|
||||
return JsonResponse.success(null);
|
||||
}
|
||||
|
@ -1,11 +1,13 @@
|
||||
package cn.skcks.docking.gb28181.api.record.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import lombok.Data;
|
||||
|
||||
@Schema(title = "查询历史录像")
|
||||
@Data
|
||||
public class GetInfoDTO {
|
||||
@NotBlank
|
||||
@Schema(description = "设备id")
|
||||
private String deviceId;
|
||||
}
|
||||
|
@ -1,13 +1,22 @@
|
||||
package cn.skcks.docking.gb28181.config;
|
||||
|
||||
import cn.skcks.docking.gb28181.interceptor.RequestInterceptor;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
private final RequestInterceptor requestInterceptor;
|
||||
@Override
|
||||
public void addInterceptors(@NotNull InterceptorRegistry registry) {
|
||||
registry.addInterceptor(requestInterceptor)
|
||||
.excludePathPatterns("/swagger-ui/**","/v3/api-docs/**")
|
||||
.addPathPatterns("/**");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package cn.skcks.docking.gb28181.interceptor;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@SuppressWarnings({"unused"})
|
||||
@RequiredArgsConstructor
|
||||
public class RequestInterceptor implements HandlerInterceptor {
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
log.info("{} 访问 {}",request.getRemoteHost(), request.getRequestURI());
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user