Ver código fonte

开发“根据数量获取常见问题列表” /lawyer/commonQuestion/getListByNum

LuTong 1 mês atrás
pai
commit
2c770f9158

+ 11 - 0
alien-store/src/main/java/shop/alien/store/controller/LawyerCommonQuestionController.java

@@ -116,5 +116,16 @@ public class LawyerCommonQuestionController {
         return R.data(pageResult);
     }
 
+    @ApiOperation("根据数量获取常见问题列表")
+    @ApiOperationSupport(order = 7)
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "num", value = "获取数量", dataType = "Integer", paramType = "query", required = true)
+    })
+    @GetMapping("/getListByNum")
+    public R<List<LawyerCommonQuestion>> getListByNum(@RequestParam Integer num) {
+        log.info("LawyerCommonQuestionController.getListByNum?num={}", num);
+        return commonQuestionService.getCommonQuestionListByNum(num);
+    }
+
 }
 

+ 8 - 0
alien-store/src/main/java/shop/alien/store/service/LawyerCommonQuestionService.java

@@ -62,5 +62,13 @@ public interface LawyerCommonQuestionService extends IService<LawyerCommonQuesti
      */
     R<Boolean> deleteCommonQuestion(Integer id);
 
+    /**
+     * 根据数量获取常见问题列表
+     *
+     * @param num 获取数量
+     * @return R<List<LawyerCommonQuestion>>
+     */
+    R<List<LawyerCommonQuestion>> getCommonQuestionListByNum(Integer num);
+
 }
 

+ 18 - 0
alien-store/src/main/java/shop/alien/store/service/impl/LawyerCommonQuestionServiceImpl.java

@@ -95,5 +95,23 @@ public class LawyerCommonQuestionServiceImpl extends ServiceImpl<LawyerCommonQue
         }
         return R.fail("删除失败");
     }
+
+    @Override
+    public R<List<LawyerCommonQuestion>> getCommonQuestionListByNum(Integer num) {
+        log.info("LawyerCommonQuestionServiceImpl.getCommonQuestionListByNum?num={}", num);
+        
+        // 参数校验:如果 num 小于等于0,返回空列表
+        if (num == null || num <= 0) {
+            return R.data(new java.util.ArrayList<>());
+        }
+        
+        // 构建查询条件:只查询未删除的记录,随机排序
+        LambdaQueryWrapper<LawyerCommonQuestion> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(LawyerCommonQuestion::getDeleteFlag, 0)
+                .last("ORDER BY RAND() LIMIT " + num);
+        
+        List<LawyerCommonQuestion> list = this.list(queryWrapper);
+        return R.data(list);
+    }
 }