Commit 9b5333df by 春觉晓

修改我的课程查询逻辑,过滤未分组课程

1 parent d9230835
......@@ -217,7 +217,8 @@ public class LearningCenterCourseService {
if (StringUtils.isNotBlank(cache)) {
throw new RpcServiceException(DefaultErrorEnum.SERVER_ERROR, "操作频繁,请稍后再试");
}
redisTemplate.opsForValue().set(COURSE_CACHE_KEY, COURSE_CACHE_KEY, 30, TimeUnit.MINUTES);
Integer interval = environment.getProperty("course.sync.interval", Integer.class, 30);
redisTemplate.opsForValue().set(COURSE_CACHE_KEY, COURSE_CACHE_KEY, interval, TimeUnit.MINUTES);
//使用线程异步调用数据同步
new Thread(() -> {
sync.sync();
......
......@@ -144,19 +144,12 @@
left join dj_beisen_course bc on cpc.course_id = bc.id and bc.deleted_flag = 'N'
left join dj_car_life_learning_center_course_category_rel ccr on bc.id = ccr.course_id and ccr.deleted_flag = 'N'
<where>
cpc.deleted_flag = 'N'
cpc.deleted_flag = 'N' and ccr.id is not null and ccr.id <![CDATA[<>]]> 1
<if test="userId != null">
and cpc.person_id = #{userId}
</if>
<if test="courseCategoryId != null">
<choose>
<when test="courseCategoryId == 1">
and (ccr.course_id = #{courseCategoryId} or ccr.id is null)
</when>
<otherwise>
and ccr.category_id = #{courseCategoryId}
</otherwise>
</choose>
and ccr.category_id = #{courseCategoryId}
</if>
<if test="title != null and title != ''">
and bc.title like concat('%', #{title}, '%')
......
......@@ -41,7 +41,7 @@ public class LearningCenterCourseServiceTest extends BaseServiceTest {
CourseDetailSearchDTO request = new CourseDetailSearchDTO();
pagination.setCondition(request);
//request.setPassFlag(1);
request.setPhone("13476670746");
//request.setPhone("13476670746");
request.setOrderByType(0);
request.setCourseId("9aa2244a-3072-4db1-beac-f89735946c55");
Page<CourseDetailPageInfo> res1 = learningCenterCourseService.pageCourseDetail(pagination);
......@@ -64,7 +64,9 @@ public class LearningCenterCourseServiceTest extends BaseServiceTest {
CourseSearchDTO request = new CourseSearchDTO();
pagination.setCondition(request);
request.setStaffPhone("13476670746");
request.setCourseCategoryId(4);
request.setSortType(0);
request.setSortOrder("desc");
request.setCourseCategoryId(9);
Page<CoursePageInfo> res1 = learningCenterCourseService.pageRecommendedCourse(pagination);
System.out.println(res1);
}
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    LearningCenterCourseService.java

    1. 问题:在设置 Redis 缓存时,redisTemplate.opsForValue().set(COURSE_CACHE_KEY, COURSE_CACHE_KEY, interval, TimeUnit.MINUTES); 第二个参数应该是缓存的值,而不是 COURSE_CACHE_KEY。

      • 影响:这会导致缓存的值不正确,可能引发后续业务逻辑错误。
      • 优化建议:将第二个参数替换为实际需要缓存的数据。 java redisTemplate.opsForValue().set(COURSE_CACHE_KEY, "some_actual_value", interval, TimeUnit.MINUTES);
    2. 问题:创建线程的方式存在潜在问题。

      • 影响:直接创建线程可能会导致线程泄漏或资源耗尽。
      • 优化建议:使用线程池来管理线程。 java ExecutorService executorService = Executors.newFixedThreadPool(10); executorService.submit(() -> { sync.sync(); }); 或者可以考虑使用 Spring 的 @Async 注解。

    LearningCenterCourseServiceTest.java

    1. 问题:测试方法中硬编码了电话号码和课程类别ID。

      • 影响:这使得测试不够灵活,如果这些值发生变化,测试会失败。
      • 优化建议:使用测试数据工厂或者配置文件来管理测试数据。 java String testPhone = "13476670746"; int testCourseCategoryId = 9; request.setPhone(testPhone); request.setCourseCategoryId(testCourseCategoryId);
    2. 问题:打印日志的方式不规范。

      • 影响:使用 System.out.println 不利于日志管理和调试。
      • 优化建议:使用日志框架(如 SLF4J)来记录日志。 java private static final Logger logger = LoggerFactory.getLogger(LearningCenterCourseServiceTest.class); logger.info("Result: {}", res1);

    评分明细

    1. 功能实现的正确性与健壮性(40分)

      • 问题1:未正确设置 Redis 缓存值,扣 10 分。
      • 问题2:直接创建线程,扣 5 分。
      • 测试方法中的硬编码问题,扣 5 分。
      • 打印日志的方式不规范,扣 5 分。
      • 得分:15 分。
    2. 安全性与潜在风险(30分)

      • 未发现明显的安全漏洞。
      • 得分:30 分。
    3. 是否符合最佳实践(20分)

      • 创建线程的方式不符合最佳实践,扣 5 分。
      • 测试数据硬编码,扣 5 分。
      • 日志记录方式不规范,扣 5 分。
      • 得分:5 分。
    4. 性能与资源利用效率(5分)

      • 直接创建线程可能导致性能问题,扣 5 分。
      • 得分:0 分。
    5. Commits信息的清晰性与准确性(5分)

      • 提交信息不够清晰,仅提到“过滤未分组课程”,但没有说明具体的变更内容。
      • 得分:2 分。

    总分: 52分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!