| | |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.xcong.farmer.cms.configurations.properties.CmsProperties; |
| | | import com.xcong.farmer.cms.conversion.ColumnConversion; |
| | | import com.xcong.farmer.cms.core.node.AttrNode; |
| | | import com.xcong.farmer.cms.core.tag.data.NavData; |
| | | import com.xcong.farmer.cms.core.tag.model.Nav; |
| | | import com.xcong.farmer.cms.modules.system.entity.ArticleEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.ColumnEntity; |
| | | import com.xcong.farmer.cms.modules.system.mapper.ArticleMapper; |
| | | import com.xcong.farmer.cms.modules.system.mapper.ColumnMapper; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminColumnVo; |
| | | 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-28 |
| | | **/ |
| | | @Slf4j |
| | | public class NavDataParserHandler implements DataParserHandler { |
| | | |
| | | private ColumnMapper columnMapper = SpringContextHolder.getBean(ColumnMapper.class); |
| | | private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class); |
| | | private CmsProperties cmsProperties = SpringContextHolder.getBean(CmsProperties.class); |
| | | |
| | | @Override |
| | | public void dataParser(AttrNode node) { |
| | | System.out.println("NavDataParserHandler"); |
| | | List<Map<String, Object>> list = new ArrayList<>(); |
| | | Map<String, Object> aa = new HashMap<>(); |
| | | aa.put("title", "导航1"); |
| | | list.add(aa); |
| | | log.info("导航栏解析"); |
| | | Long companyId = (Long) node.getSystemDataValue("companyId"); |
| | | |
| | | Map<String, Object> bb = new HashMap<>(); |
| | | bb.put("title", "导航2"); |
| | | List<ColumnEntity> columns = columnMapper.selectColumnByParentId(0L, companyId); |
| | | |
| | | List<Map<String, Object>> sub = new ArrayList<>(); |
| | | Map<String, Object> subBB = new HashMap<>(); |
| | | subBB.put("title", "子导航1"); |
| | | subBB.put("src", "http://1234"); |
| | | sub.add(subBB); |
| | | Map<String, Object> subAA = new HashMap<>(); |
| | | subAA.put("title", "子导航2"); |
| | | subAA.put("src", "http://123455555"); |
| | | sub.add(subAA); |
| | | if (CollUtil.isEmpty(columns)) { |
| | | return; |
| | | } |
| | | |
| | | bb.put("children", sub); |
| | | list.add(bb); |
| | | List<NavData> list = new ArrayList<>(); |
| | | |
| | | NavData index = new NavData(); |
| | | index.setTitle("首页"); |
| | | index.setUrl(cmsProperties.getBaseUrl()); |
| | | index.setCode("index"); |
| | | list.add(index); |
| | | |
| | | for (ColumnEntity column : columns) { |
| | | NavData navData = columnToNav(column); |
| | | |
| | | List<ColumnEntity> child = columnMapper.selectColumnByParentId(column.getId(), companyId); |
| | | if (CollUtil.isNotEmpty(child)) { |
| | | List<NavData> childNavData = columnsToNavs(child); |
| | | navData.setChildren(childNavData); |
| | | } |
| | | list.add(navData); |
| | | } |
| | | |
| | | node.setData(list); |
| | | } |
| | | |
| | | public List<NavData> columnsToNavs(List<ColumnEntity> columns) { |
| | | List<NavData> list = new ArrayList<>(); |
| | | for (ColumnEntity column : columns) { |
| | | list.add(columnToNav(column)); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | public NavData columnToNav(ColumnEntity column) { |
| | | NavData navData = ColumnConversion.INSTANCE.columnToNav(column); |
| | | |
| | | navData.setUrl(cmsProperties.getBaseUrl() + column.getPath()); |
| | | if (column.getType() == 2) { |
| | | if (column.getTargetType() == 1) { |
| | | ArticleEntity article = this.articleMapper.selectArticleById(Long.parseLong(column.getTargetUrl())); |
| | | navData.setUrl(cmsProperties.getBaseUrl() + article.getPath() + "/" + article.getId() + ".html"); |
| | | } else if (column.getTargetType() == 2) { |
| | | ColumnEntity columnEntity = this.columnMapper.selectByCodeAndCompanyId(column.getTargetUrl(), column.getCompanyId()); |
| | | navData.setUrl(cmsProperties.getBaseUrl() + columnEntity.getPath()); |
| | | } else { |
| | | navData.setUrl(column.getTargetUrl()); |
| | | } |
| | | } |
| | | return navData; |
| | | } |
| | | } |