浏览代码

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

LuTong 1 月之前
父节点
当前提交
cf13069dcf

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

@@ -10,7 +10,9 @@ import shop.alien.entity.store.LawyerCommonQuestion;
 import shop.alien.store.service.LawyerCommonQuestionService;
 import shop.alien.util.myBaticsPlus.QueryBuilder;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 常见问题 前端控制器
@@ -113,5 +115,17 @@ public class LawyerCommonQuestionController {
                 .page(commonQuestionService);
         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);
+    }
+
 }
 

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

@@ -6,6 +6,7 @@ import shop.alien.entity.result.R;
 import shop.alien.entity.store.LawyerCommonQuestion;
 
 import java.util.List;
+import java.util.Map;
 
 /**
  * 常见问题 服务类
@@ -60,5 +61,14 @@ public interface LawyerCommonQuestionService extends IService<LawyerCommonQuesti
      * @return R<Boolean>
      */
     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);
+    }
 }