|
|
@@ -550,4 +550,78 @@ public class ArticleService {
|
|
|
result.put("pointsEarned", pointsEarned);
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户发布文章(成长记录)
|
|
|
+ * @param visibility private=仅家庭(直接发布), public=公开(需审核)
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public Article publishByUser(String title, String content, String coverImage, String visibility,
|
|
|
+ String relatedDimensions, Long userId, String userRole) {
|
|
|
+ Article article = new Article();
|
|
|
+ article.setTitle(title);
|
|
|
+ article.setContent(content);
|
|
|
+ article.setCoverImage(coverImage);
|
|
|
+ article.setAuthorType("parent");
|
|
|
+ article.setCreatedBy(userId);
|
|
|
+ article.setWordCount(calculateWordCount(content));
|
|
|
+
|
|
|
+ // 可见范围
|
|
|
+ article.setVisibility(visibility != null ? visibility : "private");
|
|
|
+
|
|
|
+ // 关联维度
|
|
|
+ article.setRelatedDimensions(relatedDimensions);
|
|
|
+
|
|
|
+ // 公开文章需要审核,家庭内部可见直接发布
|
|
|
+ if ("public".equals(visibility)) {
|
|
|
+ article.setStatus("draft");
|
|
|
+ article.setAuditStatus("pending");
|
|
|
+ } else {
|
|
|
+ article.setStatus("published");
|
|
|
+ article.setAuditStatus("approved");
|
|
|
+ article.setPublishedAt(new Date());
|
|
|
+ }
|
|
|
+
|
|
|
+ article.setArticleType("original");
|
|
|
+ article.setViewCount(0);
|
|
|
+ article.setCreatedAt(new Date());
|
|
|
+ article.setUpdatedAt(new Date());
|
|
|
+ articleMapper.insert(article);
|
|
|
+ return article;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取我的发布列表
|
|
|
+ */
|
|
|
+ public Page<Article> getMyPosts(Long userId, int page, int size) {
|
|
|
+ LambdaQueryWrapper<Article> wrapper = new LambdaQueryWrapper<Article>()
|
|
|
+ .eq(Article::getCreatedBy, userId)
|
|
|
+ .in(Article::getAuthorType, "parent", "child")
|
|
|
+ .orderByDesc(Article::getCreatedAt);
|
|
|
+ return articleMapper.selectPage(new Page<>(page, size), wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 管理员审核文章
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void auditArticle(Long articleId, String auditStatus, String auditReason, Long auditorId) {
|
|
|
+ Article article = articleMapper.selectById(articleId);
|
|
|
+ if (article == null) {
|
|
|
+ throw new RuntimeException("文章不存在");
|
|
|
+ }
|
|
|
+ article.setAuditStatus(auditStatus);
|
|
|
+ article.setAuditorId(auditorId);
|
|
|
+ article.setAuditedAt(new Date());
|
|
|
+ if ("approved".equals(auditStatus)) {
|
|
|
+ article.setStatus("published");
|
|
|
+ article.setPublishedAt(new Date());
|
|
|
+ article.setAuditReason(null);
|
|
|
+ } else if ("rejected".equals(auditStatus)) {
|
|
|
+ article.setStatus("draft");
|
|
|
+ article.setAuditReason(auditReason);
|
|
|
+ }
|
|
|
+ article.setUpdatedAt(new Date());
|
|
|
+ articleMapper.updateById(article);
|
|
|
+ }
|
|
|
}
|