|
|
@@ -0,0 +1,66 @@
|
|
|
+package com.aijiuyi.admin.controller;
|
|
|
+
|
|
|
+import com.aijiuyi.admin.common.annotation.Log;
|
|
|
+import com.aijiuyi.admin.common.entity.Result;
|
|
|
+import com.aijiuyi.admin.common.enums.OperationType;
|
|
|
+import com.aijiuyi.admin.entity.ContentArticle;
|
|
|
+import com.aijiuyi.admin.service.ContentArticleService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * App端内容(文章)Controller
|
|
|
+ * 仅提供已发布文章的查询接口,供APP用户使用
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("/app/content")
|
|
|
+public class AppContentController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ContentArticleService articleService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 分页查询已发布文章列表(APP端专用)
|
|
|
+ * 只返回状态为 PUBLISHED 的文章,按发布时间倒序
|
|
|
+ *
|
|
|
+ * @param pageNum 当前页码,默认1
|
|
|
+ * @param pageSize 每页条数,默认10
|
|
|
+ * @return 分页结果
|
|
|
+ */
|
|
|
+ @GetMapping("/articles")
|
|
|
+ @Log(value = "App查询已发布文章", module = "App内容", operationType = OperationType.QUERY)
|
|
|
+ public Result<IPage<ContentArticle>> publishedArticles(
|
|
|
+ @RequestParam(defaultValue = "1") Integer pageNum,
|
|
|
+ @RequestParam(defaultValue = "10") Integer pageSize) {
|
|
|
+ Page<ContentArticle> page = new Page<>(pageNum, pageSize);
|
|
|
+ LambdaQueryWrapper<ContentArticle> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ wrapper.eq(ContentArticle::getStatus, "PUBLISHED")
|
|
|
+ .orderByDesc(ContentArticle::getPublishTime);
|
|
|
+ return Result.success(articleService.page(page, wrapper));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取已发布文章详情(APP端专用)
|
|
|
+ *
|
|
|
+ * @param id 文章ID
|
|
|
+ * @return 文章详情(仅PUBLISHED状态可查看)
|
|
|
+ */
|
|
|
+ @GetMapping("/articles/{id}")
|
|
|
+ @Log(value = "App查询文章详情", module = "App内容", operationType = OperationType.QUERY)
|
|
|
+ public Result<ContentArticle> getPublishedArticle(@PathVariable Long id) {
|
|
|
+ ContentArticle article = articleService.getById(id);
|
|
|
+ if (article == null || !"PUBLISHED".equals(article.getStatus())) {
|
|
|
+ return Result.error("文章不存在或未发布");
|
|
|
+ }
|
|
|
+ // 浏览次数+1
|
|
|
+ ContentArticle update = new ContentArticle();
|
|
|
+ update.setId(id);
|
|
|
+ update.setViewCount(article.getViewCount() != null ? article.getViewCount() + 1 : 1);
|
|
|
+ articleService.updateById(update);
|
|
|
+ article.setViewCount(update.getViewCount());
|
|
|
+ return Result.success(article);
|
|
|
+ }
|
|
|
+}
|