| | |
| | | |
| | | |
| | | 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; |
| | | |
| | |
| | | * @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) { |
| | | System.out.println("ArticleDataParserHandler"); |
| | | log.info("文章解析"); |
| | | Article tag = (Article) node.getParam(); |
| | | ArticleEntity data = articleMapper.selectById(tag.getId()); |
| | | |
| | | ArticleEntity prev = articleMapper.selectPrevOrNextArticle(data.getId(), data.getColumnId(), 1); |
| | | ArticleEntity next = articleMapper.selectPrevOrNextArticle(data.getId(), data.getColumnId(), 2); |
| | | ArticleData articleData = ArticleConversion.INSTANCE.entityToData(data); |
| | | |
| | | Map map = JSONObject.parseObject(JSONObject.toJSONString(data), Map.class); |
| | | // Map<String, Object> map = new HashMap<>(); |
| | | // map.put("title", "这是单个文章标题"); |
| | | 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"); |
| | | } |
| | | |
| | | map.put("prev", prev); |
| | | map.put("next", next); |
| | | node.setData(map); |
| | | 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); |
| | | } |
| | | } |