Helius
2022-11-12 067546725a07d08e0346ebf3a410d481e97e5730
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.xcong.farmer.cms.core.handler;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.Articles;
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 java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * @author wzy
 * @date 2022-06-24
 **/
@Slf4j
public class ArticlesDataParserHandler implements DataParserHandler  {
 
    private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class);
 
    @Override
    public void dataParser(AttrNode node) {
//        log.info("文章列表解析");
        Long companyId = (Long) node.getSystemDataValue("companyId");
        String companyCode = (String) node.getSystemDataValue("companyCode");
        String baseUrl = (String) node.getSystemDataValue("baseUrl");
        Object pageNo = node.getSystemDataValue("page");
 
        Articles param = (Articles) node.getParam();
        if (pageNo != null) {
            param.setPage(pageNo.toString());
        }
 
        ArticleEntity article = new ArticleEntity();
        Page<ArticleEntity> page = new Page<>(Integer.parseInt(param.getPage()), Integer.parseInt(param.getLimit()));
        if (StrUtil.isEmpty(param.getColId())) {
            article.setColumnCode(param.getCode());
        } else {
            List<String> colIdsStr = StrUtil.split(param.getColId(), ',');
            List<Long> colIds = new ArrayList<>();
            colIdsStr.forEach(item -> {
                colIds.add(Long.parseLong(item));
            });
 
            article.setColumnIds(colIds);
        }
        article.setCompanyId(companyId);
        article.setDelStatus(ArticleEntity.DELETE_STATUS_NO);
        article.setDraftState(2);
 
        if (StrUtil.isNotBlank(param.getType())) {
            if ("hot".equals(param.getType())) {
                article.setIsTop(1);
            }
        }
 
        IPage<ArticleEntity> listPage = articleMapper.selectArticleInPage(page, article);
 
        List<ArticleData> list = new ArrayList<>();
        for (ArticleEntity record : listPage.getRecords()) {
            ArticleData articleData = entityToData(record, baseUrl);
            list.add(articleData);
        }
 
        node.setData(list);
    }
 
    public ArticleData entityToData(ArticleEntity article, String baseUrl) {
        ArticleData articleData = ArticleConversion.INSTANCE.entityToData(article);
 
        if (article.getType() == 2) {
            articleData.setUrl(article.getArticleUrl());
        } else {
            articleData.setUrl(baseUrl + article.getPath() + "/" + article.getId() + ".html");
        }
 
 
        return articleData;
    }
}