| | |
| | | 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; |
| | |
| | | * @author wzy |
| | | * @date 2022-06-24 |
| | | **/ |
| | | @Slf4j |
| | | public class ArticlesDataParserHandler implements DataParserHandler { |
| | | |
| | | private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class); |
| | | private CmsProperties cmsProperties = SpringContextHolder.getBean(CmsProperties.class); |
| | | |
| | | @Override |
| | | public void dataParser(AttrNode node) { |
| | | System.out.println("ArticlesDataParserHandler"); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("path", "这是链接1"); |
| | | map.put("title", "这是标题1"); |
| | | list.add(map); |
| | | log.info("文章列表解析"); |
| | | Long companyId = (Long) node.getSystemDataValue("companyId"); |
| | | Articles param = (Articles) node.getParam(); |
| | | |
| | | Map<String, Object> map2 = new HashMap<>(); |
| | | map2.put("path", "这是链接2"); |
| | | map2.put("title", "这是标题2"); |
| | | list.add(map2); |
| | | 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); |
| | | IPage<ArticleEntity> listPage = articleMapper.selectArticleInPage(page, article); |
| | | |
| | | List<ArticleData> list = new ArrayList<>(); |
| | | for (ArticleEntity record : listPage.getRecords()) { |
| | | ArticleData articleData = entityToData(record); |
| | | list.add(articleData); |
| | | } |
| | | |
| | | node.setData(list); |
| | | } |
| | | |
| | | public ArticleData entityToData(ArticleEntity article) { |
| | | ArticleData articleData = ArticleConversion.INSTANCE.entityToData(article); |
| | | |
| | | if (article.getType() == 2) { |
| | | articleData.setUrl(article.getArticleUrl()); |
| | | } else { |
| | | articleData.setUrl(cmsProperties.getBaseUrl() + article.getPath() + "/" + article.getId() + ".html"); |
| | | } |
| | | |
| | | |
| | | return articleData; |
| | | } |
| | | } |