| | |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.ObjectUtil; |
| | | 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.CmsTemplateEntity; |
| | | 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.CmsTemplateMapper; |
| | | 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; |
| | |
| | | |
| | | private ColumnMapper columnMapper = SpringContextHolder.getBean(ColumnMapper.class); |
| | | private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class); |
| | | private String BASE_URL = "http://192.168.0.1/"; |
| | | private CmsTemplateMapper cmsTemplateMapper = SpringContextHolder.getBean(CmsTemplateMapper.class); |
| | | |
| | | private String baseUrl = ""; |
| | | @Override |
| | | public void dataParser(AttrNode node) { |
| | | log.info("导航栏解析"); |
| | | // log.info("导航栏解析"); |
| | | Long companyId = (Long) node.getSystemDataValue("companyId"); |
| | | baseUrl = (String) node.getSystemDataValue("baseUrl"); |
| | | |
| | | List<ColumnEntity> columns = columnMapper.selectColumnByParentId(0L, companyId); |
| | | List<ColumnEntity> columns = columnMapper.selectColumnByParentId(0L, companyId, 1); |
| | | |
| | | if (CollUtil.isEmpty(columns)) { |
| | | return; |
| | | } |
| | | |
| | | List<NavData> list = new ArrayList<>(); |
| | | |
| | | NavData index = new NavData(); |
| | | //首页是否设置,设置了从内容模版表中取名称 |
| | | CmsTemplateEntity cmsTemplateEntity = cmsTemplateMapper.selectByPathAndCompanyId("index.html", companyId); |
| | | if(ObjectUtil.isNotEmpty(cmsTemplateEntity)){ |
| | | index.setTitle(cmsTemplateEntity.getName()); |
| | | }else{ |
| | | index.setTitle("首页"); |
| | | } |
| | | index.setUrl(baseUrl); |
| | | index.setCode("index"); |
| | | list.add(index); |
| | | |
| | | for (ColumnEntity column : columns) { |
| | | NavData navData = columnToNav(column); |
| | | |
| | | List<ColumnEntity> child = columnMapper.selectColumnByParentId(column.getId(), companyId); |
| | | List<ColumnEntity> child = columnMapper.selectColumnByParentId(column.getId(), companyId, 1); |
| | | if (CollUtil.isNotEmpty(child)) { |
| | | List<NavData> childNavData = columnsToNavs(child); |
| | | navData.setChildren(childNavData); |
| | | } |
| | | list.add(navData); |
| | | } |
| | | |
| | | node.setData(list); |
| | | } |
| | | |
| | |
| | | public NavData columnToNav(ColumnEntity column) { |
| | | NavData navData = ColumnConversion.INSTANCE.columnToNav(column); |
| | | |
| | | navData.setUrl(BASE_URL + navData.getCode()); |
| | | navData.setUrl(baseUrl + column.getPath()); |
| | | if (column.getType() == 2) { |
| | | if (column.getTargetType() == 1) { |
| | | ArticleEntity article = this.articleMapper.selectArticleById(Long.parseLong(column.getTargetUrl())); |
| | | navData.setUrl(BASE_URL + article.getColumnCode() + "/" + article.getId() + ".html"); |
| | | navData.setUrl(baseUrl + article.getPath() + "/" + article.getId() + ".html"); |
| | | } else if (column.getTargetType() == 2) { |
| | | navData.setUrl(BASE_URL + column.getTargetUrl()); |
| | | ColumnEntity columnEntity = this.columnMapper.selectByCodeAndCompanyId(column.getTargetUrl(), column.getCompanyId()); |
| | | navData.setUrl(baseUrl + columnEntity.getPath()); |
| | | } else { |
| | | navData.setUrl(column.getTargetUrl()); |
| | | } |