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()); 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(cmsProperties.getBaseUrl() + 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(cmsProperties.getBaseUrl() + nextEntity.getPath() + "/" + nextEntity.getId() + ".html"); } articleData.setNext(next); } else { articleData.setNext(new ArticleData()); } node.setData(articleData); } }