Helius
2022-07-08 cd906c6c82dd28dbf1c53b03d382a5b14d67bb4a
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
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);
    private final CmsProperties cmsProperties = SpringContextHolder.getBean(CmsProperties.class);
    @Override
    public void dataParser(AttrNode node) {
        log.info("文章解析");
        Article tag = (Article) node.getParam();
        ArticleEntity data = articleMapper.selectById(tag.getId());
 
        ArticleEntity prevEntity = articleMapper.selectPrevOrNextArticle(data.getId(), data.getColumnId(), 1);
        ArticleData prev = ArticleConversion.INSTANCE.entityToData(prevEntity);
        if (prevEntity.getType() == 2) {
            prev.setUrl(prevEntity.getArticleUrl());
        } else {
            prev.setUrl(cmsProperties.getBaseUrl() + prevEntity.getPath() + "/" + prevEntity.getId() + ".html");
        }
 
        ArticleEntity nextEntity = articleMapper.selectPrevOrNextArticle(data.getId(), data.getColumnId(), 2);
        ArticleData next = ArticleConversion.INSTANCE.entityToData(nextEntity);
        if (nextEntity.getType() == 2) {
            next.setUrl(prevEntity.getArticleUrl());
        } else {
            next.setUrl(cmsProperties.getBaseUrl() + nextEntity.getPath() + "/" + nextEntity.getId() + ".html");
        }
 
        ArticleData articleData = ArticleConversion.INSTANCE.entityToData(data);
        articleData.setNext(next);
        articleData.setPrev(prev);
        node.setData(articleData);
    }
}