fix: [临时提交]
This commit is contained in:
parent
36b70e9450
commit
52f7f2c1c7
|
@ -0,0 +1,73 @@
|
|||
package com.guwan.backend.aspect;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Before;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class RequestLogAspect {
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
/**
|
||||
* 定义切点,匹配所有controller包下的公共方法
|
||||
*/
|
||||
@Pointcut("execution(public * com.guwan.backend.controller..*.*(..))")
|
||||
public void controllerLog() {}
|
||||
|
||||
/**
|
||||
* 前置通知,在方法执行前打印请求日志
|
||||
*/
|
||||
@Before("controllerLog()")
|
||||
public void doBefore(JoinPoint joinPoint) {
|
||||
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
|
||||
if (attributes == null) {
|
||||
return; // 非HTTP请求上下文,不处理
|
||||
}
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
|
||||
// 记录请求信息
|
||||
log.info("===================== Request Start =====================");
|
||||
log.info("URL : {}", request.getRequestURL().toString());
|
||||
log.info("HTTP Method : {}", request.getMethod());
|
||||
log.info("Class Method : {}.{}", joinPoint.getSignature().getDeclaringTypeName(), joinPoint.getSignature().getName());
|
||||
log.info("IP : {}", request.getRemoteAddr());
|
||||
|
||||
// 记录参数,尝试序列化为JSON
|
||||
Object[] args = joinPoint.getArgs();
|
||||
if (args != null && args.length > 0) {
|
||||
try {
|
||||
// 过滤掉HttpServletRequest和HttpServletResponse类型的参数
|
||||
Object[] loggableArgs = Arrays.stream(args)
|
||||
.filter(arg -> !(arg instanceof HttpServletRequest) && !(arg instanceof jakarta.servlet.http.HttpServletResponse))
|
||||
.toArray();
|
||||
if (loggableArgs.length > 0) {
|
||||
log.info("Request Args : {}", objectMapper.writeValueAsString(loggableArgs));
|
||||
} else {
|
||||
log.info("Request Args : No Loggable Arguments");
|
||||
}
|
||||
} catch (JsonProcessingException e) {
|
||||
log.warn("Failed to serialize request arguments to JSON: {}", e.getMessage());
|
||||
log.info("Request Args : {}", Arrays.toString(args)); // 序列化失败则打印原始toString
|
||||
}
|
||||
} else {
|
||||
log.info("Request Args : No Arguments");
|
||||
}
|
||||
log.info("===================== Request End =======================");
|
||||
}
|
||||
}
|
|
@ -387,8 +387,7 @@ public class CommonController {
|
|||
|
||||
|
||||
@GetMapping("/testQwen")
|
||||
public Result testQwen(
|
||||
@RequestParam(value = "str1", required = false) String message) {
|
||||
public Result testQwen(@RequestParam(value = "str1", required = false) String message) {
|
||||
|
||||
var response = qwenChatModel.chat(message);
|
||||
System.out.println("response = " + response);
|
||||
|
|
|
@ -5,22 +5,15 @@ package com.guwan.backend.controller;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.guwan.backend.common.Result;
|
||||
import com.guwan.backend.mongodb.CategoryService;
|
||||
import com.guwan.backend.pojo.Courses;
|
||||
import com.guwan.backend.pojo.Course;
|
||||
import com.guwan.backend.pojo.dto.BSCategory;
|
||||
import com.guwan.backend.service.BSCategoryService;
|
||||
import com.guwan.backend.service.CoursesService;
|
||||
import com.guwan.backend.service.CourseService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -38,7 +31,7 @@ public class CoursesController {
|
|||
* 服务对象
|
||||
*/
|
||||
|
||||
private final CoursesService coursesService;
|
||||
private final CourseService courseService;
|
||||
|
||||
private final BSCategoryService categoryService;
|
||||
|
||||
|
@ -49,18 +42,15 @@ public class CoursesController {
|
|||
* @param pageRequest 分页对象
|
||||
* @return 查询结果
|
||||
*/
|
||||
@GetMapping("/homePage")
|
||||
@GetMapping("/queryByPage")
|
||||
public Result queryByPage(@RequestParam("page") Integer pageNumber,
|
||||
@RequestParam("size") Integer size) {
|
||||
|
||||
// return Result.success(this.coursesService.queryByPage(courses, pageRequest));
|
||||
Page<Course> page = new Page<>(pageNumber, size);
|
||||
|
||||
log.debug("cscscs");
|
||||
Page<Courses> page = new Page<>(pageNumber, size);
|
||||
LambdaQueryWrapper<Course> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
LambdaQueryWrapper<Courses> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
Page<Courses> resultPage = this.coursesService.page(page, lambdaQueryWrapper);
|
||||
Page<Course> resultPage = this.courseService.page(page, lambdaQueryWrapper);
|
||||
|
||||
return Result.success(resultPage.getRecords().stream()
|
||||
.peek(course -> {
|
||||
|
@ -80,30 +70,30 @@ public class CoursesController {
|
|||
* @return 单条数据
|
||||
*/
|
||||
@GetMapping("{id}")
|
||||
public Result<Courses> queryById(@PathVariable("id") Integer id) {
|
||||
return Result.success(this.coursesService.getById(id));
|
||||
public Result<Course> queryById(@PathVariable("id") Integer id) {
|
||||
return Result.success(courseService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
* @param courses 实体
|
||||
* @param course 实体
|
||||
* @return 新增结果
|
||||
*/
|
||||
@PostMapping
|
||||
public Result<Courses> add(Courses courses) {
|
||||
this.coursesService.save(courses);
|
||||
public Result<Course> add(Course course) {
|
||||
this.courseService.save(course);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑数据
|
||||
*
|
||||
* @param courses 实体
|
||||
* @param course 实体
|
||||
* @return 编辑结果
|
||||
*/
|
||||
@PutMapping
|
||||
public Result<Courses> edit(Courses courses) {
|
||||
public Result<Course> edit(Course course) {
|
||||
//return Result.success(this.coursesService.update(courses));
|
||||
return Result.success();
|
||||
}
|
||||
|
@ -116,7 +106,7 @@ public class CoursesController {
|
|||
*/
|
||||
@DeleteMapping
|
||||
public Result<Boolean> deleteById(Integer id) {
|
||||
return Result.success(this.coursesService.removeById(id));
|
||||
return Result.success(this.courseService.removeById(id));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
package com.guwan.backend.controller;
|
||||
|
||||
public class GPTController {
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package com.guwan.backend.mapper;
|
||||
|
||||
import com.guwan.backend.pojo.Courses;
|
||||
import com.guwan.backend.pojo.Course;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
|
@ -11,7 +11,7 @@ import org.apache.ibatis.annotations.Mapper;
|
|||
* @Entity com.guwan.backend.pojo.Courses
|
||||
*/
|
||||
@Mapper
|
||||
public interface CoursesMapper extends BaseMapper<Courses> {
|
||||
public interface CoursesMapper extends BaseMapper<Course> {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ import lombok.Data;
|
|||
*/
|
||||
@TableName(value ="courses")
|
||||
@Data
|
||||
public class Courses implements Serializable {
|
||||
public class Course implements Serializable {
|
||||
/**
|
||||
* 课程ID
|
||||
*/
|
|
@ -1,6 +1,6 @@
|
|||
package com.guwan.backend.service;
|
||||
|
||||
import com.guwan.backend.pojo.Courses;
|
||||
import com.guwan.backend.pojo.Course;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
/**
|
||||
|
@ -8,6 +8,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||
* @description 针对表【courses(课程表)】的数据库操作Service
|
||||
* @createDate 2025-03-13 22:45:19
|
||||
*/
|
||||
public interface CoursesService extends IService<Courses> {
|
||||
public interface CourseService extends IService<Course> {
|
||||
|
||||
}
|
|
@ -1,8 +1,8 @@
|
|||
package com.guwan.backend.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guwan.backend.pojo.Courses;
|
||||
import com.guwan.backend.service.CoursesService;
|
||||
import com.guwan.backend.pojo.Course;
|
||||
import com.guwan.backend.service.CourseService;
|
||||
import com.guwan.backend.mapper.CoursesMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -12,8 +12,8 @@ import org.springframework.stereotype.Service;
|
|||
* @createDate 2025-03-13 22:45:19
|
||||
*/
|
||||
@Service
|
||||
public class CoursesServiceImpl extends ServiceImpl<CoursesMapper, Courses>
|
||||
implements CoursesService{
|
||||
public class CourseServiceImpl extends ServiceImpl<CoursesMapper, Course>
|
||||
implements CourseService {
|
||||
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.guwan.backend.mapper.CoursesMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.guwan.backend.pojo.Courses">
|
||||
<resultMap id="BaseResultMap" type="com.guwan.backend.pojo.Course">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="title" column="title" jdbcType="VARCHAR"/>
|
||||
<result property="categoryId" column="category_id" jdbcType="VARCHAR"/>
|
||||
|
|
Loading…
Reference in New Issue