✨ 增加文章下架功能
This commit is contained in:
parent
ff292b89c4
commit
5d505eec6a
@ -0,0 +1,21 @@
|
|||||||
|
package com.rymcu.forest.dto;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2023/7/26 10:20.
|
||||||
|
*
|
||||||
|
* @author ronger
|
||||||
|
* @email ronger-x@outlook.com
|
||||||
|
* @desc : com.rymcu.forest.dto
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ArticleUpdateStatusDTO {
|
||||||
|
|
||||||
|
private Long idArticle;
|
||||||
|
|
||||||
|
private String articleStatus;
|
||||||
|
|
||||||
|
private String remarks;
|
||||||
|
|
||||||
|
}
|
@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.rymcu.forest.core.constant.NotificationConstant;
|
import com.rymcu.forest.core.constant.NotificationConstant;
|
||||||
import com.rymcu.forest.handler.event.ArticleDeleteEvent;
|
import com.rymcu.forest.handler.event.ArticleDeleteEvent;
|
||||||
import com.rymcu.forest.handler.event.ArticleEvent;
|
import com.rymcu.forest.handler.event.ArticleEvent;
|
||||||
|
import com.rymcu.forest.handler.event.ArticleStatusEvent;
|
||||||
import com.rymcu.forest.lucene.service.LuceneService;
|
import com.rymcu.forest.lucene.service.LuceneService;
|
||||||
import com.rymcu.forest.util.NotificationUtils;
|
import com.rymcu.forest.util.NotificationUtils;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -11,6 +12,7 @@ import org.springframework.stereotype.Component;
|
|||||||
import org.springframework.transaction.event.TransactionalEventListener;
|
import org.springframework.transaction.event.TransactionalEventListener;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.mail.MessagingException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created on 2022/8/16 20:42.
|
* Created on 2022/8/16 20:42.
|
||||||
@ -58,4 +60,10 @@ public class ArticleHandler {
|
|||||||
luceneService.deleteArticle(articleDeleteEvent.getIdArticle());
|
luceneService.deleteArticle(articleDeleteEvent.getIdArticle());
|
||||||
log.info("执行完成文章删除相关事件...id={}", articleDeleteEvent.getIdArticle());
|
log.info("执行完成文章删除相关事件...id={}", articleDeleteEvent.getIdArticle());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TransactionalEventListener
|
||||||
|
public void processArticleStatusEvent(ArticleStatusEvent articleStatusEvent) throws MessagingException {
|
||||||
|
log.info(String.format("执行文章删除相关事件:[%s]", JSON.toJSONString(articleStatusEvent)));
|
||||||
|
NotificationUtils.saveNotification(articleStatusEvent.getArticleAuthor(), articleStatusEvent.getIdArticle(), NotificationConstant.UpdateArticleStatus, articleStatusEvent.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.rymcu.forest.handler.event;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created on 2022/8/20 18:51.
|
||||||
|
*
|
||||||
|
* @author ronger
|
||||||
|
* @email ronger-x@outlook.com
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ArticleStatusEvent {
|
||||||
|
|
||||||
|
private Long idArticle;
|
||||||
|
|
||||||
|
private Long articleAuthor;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
}
|
@ -220,4 +220,6 @@ public interface ArticleMapper extends Mapper<Article> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<ArticleDTO> selectAnnouncements();
|
List<ArticleDTO> selectAnnouncements();
|
||||||
|
|
||||||
|
int updateStatus(@Param("idArticle") Long idArticle, @Param("articleStatus") String articleStatus);
|
||||||
}
|
}
|
||||||
|
@ -140,4 +140,14 @@ public interface ArticleService extends Service<Article> {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<ArticleDTO> findAnnouncements();
|
List<ArticleDTO> findAnnouncements();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 变更文章状态
|
||||||
|
*
|
||||||
|
* @param idArticle
|
||||||
|
* @param articleStatus
|
||||||
|
* @param remarks
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Boolean updateStatus(Long idArticle, String articleStatus, String remarks);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import com.rymcu.forest.entity.Tag;
|
|||||||
import com.rymcu.forest.entity.User;
|
import com.rymcu.forest.entity.User;
|
||||||
import com.rymcu.forest.handler.event.ArticleDeleteEvent;
|
import com.rymcu.forest.handler.event.ArticleDeleteEvent;
|
||||||
import com.rymcu.forest.handler.event.ArticleEvent;
|
import com.rymcu.forest.handler.event.ArticleEvent;
|
||||||
|
import com.rymcu.forest.handler.event.ArticleStatusEvent;
|
||||||
import com.rymcu.forest.mapper.ArticleMapper;
|
import com.rymcu.forest.mapper.ArticleMapper;
|
||||||
import com.rymcu.forest.service.*;
|
import com.rymcu.forest.service.*;
|
||||||
import com.rymcu.forest.util.Html2TextUtil;
|
import com.rymcu.forest.util.Html2TextUtil;
|
||||||
@ -60,6 +61,9 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
private static final String DEFAULT_TOPIC_URI = "news";
|
private static final String DEFAULT_TOPIC_URI = "news";
|
||||||
private static final int ADMIN_ROLE_WEIGHTS = 2;
|
private static final int ADMIN_ROLE_WEIGHTS = 2;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ApplicationEventPublisher applicationEventPublisher;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ArticleDTO> findArticles(ArticleSearchDTO searchDTO) {
|
public List<ArticleDTO> findArticles(ArticleSearchDTO searchDTO) {
|
||||||
List<ArticleDTO> list;
|
List<ArticleDTO> list;
|
||||||
@ -250,6 +254,7 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public Boolean updatePerfect(Long idArticle, String articlePerfect) {
|
public Boolean updatePerfect(Long idArticle, String articlePerfect) {
|
||||||
if (articleMapper.updatePerfect(idArticle, articlePerfect) == 0) {
|
if (articleMapper.updatePerfect(idArticle, articlePerfect) == 0) {
|
||||||
throw new ContentNotExistException("设置优选文章失败!");
|
throw new ContentNotExistException("设置优选文章失败!");
|
||||||
@ -264,6 +269,23 @@ public class ArticleServiceImpl extends AbstractService<Article> implements Arti
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Boolean updateStatus(Long idArticle, String articleStatus, String remarks) {
|
||||||
|
if (articleMapper.updateStatus(idArticle, articleStatus) == 0) {
|
||||||
|
throw new ContentNotExistException("设置文章状态失败!");
|
||||||
|
}
|
||||||
|
Article article = articleMapper.selectByPrimaryKey(idArticle);
|
||||||
|
String message = "你的文章《"+article.getArticleTitle()+"》";
|
||||||
|
if ("1".equals(articleStatus)) {
|
||||||
|
message += "已下架, 下架原因: " + remarks;
|
||||||
|
} else {
|
||||||
|
message += "已上架!";
|
||||||
|
}
|
||||||
|
applicationEventPublisher.publishEvent(new ArticleStatusEvent(idArticle, article.getArticleAuthorId(), message));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private ArticleDTO genArticle(ArticleDTO article, Integer type) {
|
private ArticleDTO genArticle(ArticleDTO article, Integer type) {
|
||||||
Integer articleList = 0;
|
Integer articleList = 0;
|
||||||
Integer articleView = 1;
|
Integer articleView = 1;
|
||||||
|
@ -41,7 +41,7 @@ public class NotificationUtils {
|
|||||||
|
|
||||||
public static void saveNotification(Long idUser, Long dataId, String dataType, String dataSummary) throws MessagingException {
|
public static void saveNotification(Long idUser, Long dataId, String dataType, String dataSummary) throws MessagingException {
|
||||||
Notification notification = notificationService.findNotification(idUser, dataId, dataType);
|
Notification notification = notificationService.findNotification(idUser, dataId, dataType);
|
||||||
if (notification == null || NotificationConstant.UpdateArticle.equals(dataType)) {
|
if (notification == null || NotificationConstant.UpdateArticle.equals(dataType) || NotificationConstant.UpdateArticleStatus.equals(dataType)) {
|
||||||
System.out.println("------------------- 开始执行消息通知 ------------------");
|
System.out.println("------------------- 开始执行消息通知 ------------------");
|
||||||
Integer result = notificationService.save(idUser, dataId, dataType, dataSummary);
|
Integer result = notificationService.save(idUser, dataId, dataType, dataSummary);
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
|
@ -2,6 +2,7 @@ package com.rymcu.forest.web.api.admin;
|
|||||||
|
|
||||||
import com.rymcu.forest.core.result.GlobalResult;
|
import com.rymcu.forest.core.result.GlobalResult;
|
||||||
import com.rymcu.forest.core.result.GlobalResultGenerator;
|
import com.rymcu.forest.core.result.GlobalResultGenerator;
|
||||||
|
import com.rymcu.forest.dto.ArticleUpdateStatusDTO;
|
||||||
import com.rymcu.forest.entity.Article;
|
import com.rymcu.forest.entity.Article;
|
||||||
import com.rymcu.forest.service.ArticleService;
|
import com.rymcu.forest.service.ArticleService;
|
||||||
import org.springframework.web.bind.annotation.PatchMapping;
|
import org.springframework.web.bind.annotation.PatchMapping;
|
||||||
@ -30,4 +31,12 @@ public class AdminArticleController {
|
|||||||
String articlePerfect = article.getArticlePerfect();
|
String articlePerfect = article.getArticlePerfect();
|
||||||
return GlobalResultGenerator.genSuccessResult(articleService.updatePerfect(idArticle, articlePerfect));
|
return GlobalResultGenerator.genSuccessResult(articleService.updatePerfect(idArticle, articlePerfect));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PatchMapping("/update-status")
|
||||||
|
public GlobalResult<Boolean> updateArticleStatus(@RequestBody ArticleUpdateStatusDTO article) {
|
||||||
|
Long idArticle = article.getIdArticle();;
|
||||||
|
String articleStatus = article.getArticleStatus();
|
||||||
|
String remarks = article.getRemarks();
|
||||||
|
return GlobalResultGenerator.genSuccessResult(articleService.updateStatus(idArticle, articleStatus, remarks));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,6 +88,9 @@
|
|||||||
<update id="updatePerfect">
|
<update id="updatePerfect">
|
||||||
update forest_article set article_perfect = #{articlePerfect} where id = #{idArticle}
|
update forest_article set article_perfect = #{articlePerfect} where id = #{idArticle}
|
||||||
</update>
|
</update>
|
||||||
|
<update id="updateStatus">
|
||||||
|
update forest_article set article_status = #{articleStatus} where id = #{idArticle}
|
||||||
|
</update>
|
||||||
<delete id="deleteTagArticle">
|
<delete id="deleteTagArticle">
|
||||||
delete from forest_tag_article where id_article = #{id}
|
delete from forest_tag_article where id_article = #{id}
|
||||||
</delete>
|
</delete>
|
||||||
|
Loading…
Reference in New Issue
Block a user