fix
Helius
2022-07-12 c331c21472fa85fd7b6c7847c82722b6e35cb533
src/main/java/com/xcong/farmer/cms/core/handler/ArticleDataParserHandler.java
@@ -2,11 +2,15 @@
import com.alibaba.fastjson.JSONObject;
import com.xcong.farmer.cms.configurations.properties.CmsProperties;
import com.xcong.farmer.cms.conversion.ArticleConversion;
import com.xcong.farmer.cms.core.node.AttrNode;
import com.xcong.farmer.cms.core.tag.data.ArticleData;
import com.xcong.farmer.cms.core.tag.model.Article;
import com.xcong.farmer.cms.modules.system.entity.ArticleEntity;
import com.xcong.farmer.cms.modules.system.mapper.ArticleMapper;
import com.xcong.farmer.cms.utils.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -17,25 +21,48 @@
 * @author wzy
 * @date 2022-06-24
 **/
@Slf4j
public class ArticleDataParserHandler implements DataParserHandler {
    private final ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class);
    @Override
    public void dataParser(AttrNode node) {
        System.out.println("ArticleDataParserHandler");
        log.info("######文章解析########");
        String baseUrl = (String) node.getSystemDataValue("baseUrl");
        Article tag = (Article) node.getParam();
        ArticleEntity data = articleMapper.selectById(tag.getId());
        ArticleEntity prev = articleMapper.selectPrevOrNextArticle(data.getId(), data.getColumnId(), 1);
        ArticleEntity next = articleMapper.selectPrevOrNextArticle(data.getId(), data.getColumnId(), 2);
        ArticleData articleData = ArticleConversion.INSTANCE.entityToData(data);
        Map map = JSONObject.parseObject(JSONObject.toJSONString(data), Map.class);
//        Map<String, Object> map = new HashMap<>();
//        map.put("title", "这是单个文章标题");
        ArticleEntity prevEntity = articleMapper.selectPrevOrNextArticle(data.getId(), data.getColumnId(), 1);
        if (prevEntity != null) {
            ArticleData prev = ArticleConversion.INSTANCE.entityToData(prevEntity);
            if (prevEntity.getType() == 2) {
                prev.setUrl(prevEntity.getArticleUrl());
            } else {
                prev.setUrl(baseUrl + prevEntity.getPath() + "/" + prevEntity.getId() + ".html");
            }
        map.put("prev", prev);
        map.put("next", next);
        node.setData(map);
            articleData.setPrev(prev);
        } else {
            articleData.setPrev(new ArticleData());
        }
        ArticleEntity nextEntity = articleMapper.selectPrevOrNextArticle(data.getId(), data.getColumnId(), 2);
        if (nextEntity != null) {
            ArticleData next = ArticleConversion.INSTANCE.entityToData(nextEntity);
            if (nextEntity.getType() == 2) {
                next.setUrl(nextEntity.getArticleUrl());
            } else {
                next.setUrl(baseUrl + nextEntity.getPath() + "/" + nextEntity.getId() + ".html");
            }
            articleData.setNext(next);
        } else {
            articleData.setNext(new ArticleData());
        }
        node.setData(articleData);
    }
}