wzy
2022-10-20 673231ff8850208a50e6cf4d505cbba8d6b95869
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.xcong.farmer.cms.core.handler;
 
 
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;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * @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) {
//        log.info("######文章解析########");
        String baseUrl = (String) node.getSystemDataValue("baseUrl");
 
        Article tag = (Article) node.getParam();
        ArticleEntity data = articleMapper.selectById(tag.getId());
 
        ArticleData articleData = ArticleConversion.INSTANCE.entityToData(data);
 
        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");
            }
 
            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);
    }
}