6 files added
11 files modified
| | |
| | | package com.xcong.farmer.cms.conversion; |
| | | |
| | | import com.xcong.farmer.cms.core.tag.data.ColumnData; |
| | | import com.xcong.farmer.cms.core.tag.data.NavData; |
| | | import com.xcong.farmer.cms.core.tag.model.Column; |
| | | import com.xcong.farmer.cms.modules.system.entity.ColumnEntity; |
| | | import com.xcong.farmer.cms.modules.test.mapper.TestUserEntityMapper; |
| | | import org.mapstruct.Mapper; |
| | |
| | | public abstract NavData columnToNav(ColumnEntity column); |
| | | |
| | | public abstract List<NavData> columnsToNavs(List<ColumnEntity> column); |
| | | |
| | | @Mapping(target = "title", source = "columnName") |
| | | @Mapping(target = "code", source = "columnCode") |
| | | @Mapping(target = "image", source = "pic") |
| | | public abstract ColumnData entityToData(ColumnEntity column); |
| | | |
| | | public abstract List<ColumnData> entitiesToDatas(List<ColumnEntity> list); |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.xcong.farmer.cms.conversion.ColumnConversion; |
| | | import com.xcong.farmer.cms.core.node.AttrNode; |
| | | import com.xcong.farmer.cms.core.tag.data.ColumnData; |
| | | import com.xcong.farmer.cms.core.tag.data.NavData; |
| | | import com.xcong.farmer.cms.core.tag.model.Column; |
| | | 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.utils.SpringContextHolder; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-05 |
| | | **/ |
| | | @Slf4j |
| | | public class ColumnDataParserHandler implements DataParserHandler { |
| | | |
| | | private ColumnMapper columnMapper = SpringContextHolder.getBean(ColumnMapper.class); |
| | | private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class); |
| | | private String BASE_URL = "http://192.168.0.1/"; |
| | | |
| | | @Override |
| | | public void dataParser(AttrNode attrNode) { |
| | | log.info("栏目解析"); |
| | | Long companyId = (Long) attrNode.getSystemDataValue("companyId"); |
| | | |
| | | Column param = (Column) attrNode.getParam(); |
| | | |
| | | ColumnEntity columnEntity = columnMapper.selectByCodeAndCompanyId(param.getCode(), companyId); |
| | | |
| | | ColumnData columnData = columnToData(columnEntity); |
| | | if (columnEntity.getParentId() == 0L) { |
| | | List<ColumnEntity> child = columnMapper.selectColumnByParentId(columnEntity.getId(), companyId); |
| | | if (CollUtil.isNotEmpty(child)) { |
| | | List<ColumnData> list = new ArrayList<>(); |
| | | for (ColumnEntity entity : child) { |
| | | ColumnData childData = columnToData(entity); |
| | | list.add(childData); |
| | | } |
| | | columnData.setChildren(list); |
| | | } |
| | | } |
| | | |
| | | attrNode.setData(columnData); |
| | | } |
| | | |
| | | public ColumnData columnToData(ColumnEntity column) { |
| | | ColumnData columnData = ColumnConversion.INSTANCE.entityToData(column); |
| | | |
| | | columnData.setUrl(BASE_URL + columnData.getCode()); |
| | | if (column.getType() == 2) { |
| | | if (column.getTargetType() == 1) { |
| | | ArticleEntity article = this.articleMapper.selectArticleById(Long.parseLong(column.getTargetUrl())); |
| | | columnData.setUrl(BASE_URL + article.getColumnCode() + "/" + article.getId() + ".html"); |
| | | } else if (column.getTargetType() == 2) { |
| | | columnData.setUrl(BASE_URL + column.getTargetUrl()); |
| | | } else { |
| | | columnData.setUrl(column.getTargetUrl()); |
| | | } |
| | | } |
| | | return columnData; |
| | | } |
| | | } |
| | |
| | | } |
| | | list.add(navData); |
| | | } |
| | | // List<Map<String, Object>> list = new ArrayList<>(); |
| | | // Map<String, Object> aa = new HashMap<>(); |
| | | // aa.put("title", "导航1"); |
| | | // list.add(aa); |
| | | // |
| | | // Map<String, Object> bb = new HashMap<>(); |
| | | // bb.put("title", "导航2"); |
| | | // |
| | | // 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); |
| | | // |
| | | // bb.put("children", sub); |
| | | // list.add(bb); |
| | | node.setData(list); |
| | | } |
| | | |
New file |
| | |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | import com.xcong.farmer.cms.core.node.AttrNode; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-05 |
| | | **/ |
| | | public class PageDataParserHandler implements DataParserHandler { |
| | | |
| | | @Override |
| | | public void dataParser(AttrNode attrNode) { |
| | | |
| | | } |
| | | } |
| | |
| | | i++; |
| | | } |
| | | |
| | | } else if (parseData instanceof Map) { |
| | | } else if (parseData instanceof Object) { |
| | | if (StrUtil.isNotBlank(attrNode.getField())) { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("index", 1); |
| | |
| | | private Map<String, Object> system; |
| | | private List<PartNode> partNodes = new ArrayList<>(); |
| | | |
| | | private static boolean hasPaging = false; |
| | | private static boolean HAS_PAGING = false; |
| | | |
| | | public void parser() { |
| | | Elements children = document.body().children(); |
| | |
| | | ARTICLES("@articles", "com.xcong.farmer.cms.core.tag.model.Articles", "com.xcong.farmer.cms.core.handler.ArticlesDataParserHandler",2), |
| | | ARTICLE("@article", "com.xcong.farmer.cms.core.tag.model.Article", "com.xcong.farmer.cms.core.handler.ArticleDataParserHandler",2), |
| | | CHILD("@child", "com.xcong.farmer.cms.core.tag.model.Child", "com.xcong.farmer.cms.core.handler.ChildDataParserHandler",2), |
| | | PAGE("@page", "com.xcong.farmer.cms.core.tag.model.Page", "com.xcong.farmer.cms.core.handler.PageDataParserHandler",2), |
| | | // AD("@ad", "com.xcong.farmer.cms.core.tag.model.Ad", "",2), |
| | | // COLUMNS("@columns", "com.xcong.farmer.cms.core.tag.model.Columns", "",2), |
| | | COLUMN("@column", "com.xcong.farmer.cms.core.tag.model.Column", "",2); |
| | | COLUMN("@column", "com.xcong.farmer.cms.core.tag.model.Column", "com.xcong.farmer.cms.core.handler.ColumnDataParserHandler",2); |
| | | |
| | | private String name; |
| | | |
New file |
| | |
| | | package com.xcong.farmer.cms.core.tag.data; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-05 |
| | | **/ |
| | | public class ColumnData { |
| | | |
| | | private Long id; |
| | | |
| | | private String title; |
| | | |
| | | private String code; |
| | | |
| | | private String url; |
| | | |
| | | private String image; |
| | | |
| | | private List<ColumnData> children; |
| | | |
| | | public Long getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(Long id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getTitle() { |
| | | return title; |
| | | } |
| | | |
| | | public void setTitle(String title) { |
| | | this.title = title; |
| | | } |
| | | |
| | | public String getCode() { |
| | | return code; |
| | | } |
| | | |
| | | public void setCode(String code) { |
| | | this.code = code; |
| | | } |
| | | |
| | | public String getUrl() { |
| | | return url; |
| | | } |
| | | |
| | | public void setUrl(String url) { |
| | | this.url = url; |
| | | } |
| | | |
| | | public String getImage() { |
| | | return image; |
| | | } |
| | | |
| | | public void setImage(String image) { |
| | | this.image = image; |
| | | } |
| | | |
| | | public List<ColumnData> getChildren() { |
| | | return children; |
| | | } |
| | | |
| | | public void setChildren(List<ColumnData> children) { |
| | | this.children = children; |
| | | } |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.core.tag.model; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-05 |
| | | **/ |
| | | public class Page { |
| | | |
| | | /** |
| | | * 栏目ID |
| | | */ |
| | | private String colId; |
| | | |
| | | /** |
| | | * 分页数字显示几个 |
| | | */ |
| | | private String size; |
| | | |
| | | /** |
| | | * 对象名称 |
| | | */ |
| | | private String field; |
| | | |
| | | public String getColId() { |
| | | return colId; |
| | | } |
| | | |
| | | public void setColId(String colId) { |
| | | this.colId = colId; |
| | | } |
| | | |
| | | public String getSize() { |
| | | return size; |
| | | } |
| | | |
| | | public void setSize(String size) { |
| | | this.size = size; |
| | | } |
| | | |
| | | public String getField() { |
| | | return field; |
| | | } |
| | | |
| | | public void setField(String field) { |
| | | this.field = field; |
| | | } |
| | | } |
| | |
| | | public class TemplateLoader { |
| | | |
| | | private Configuration cfg; |
| | | private List<Template> templates = new ArrayList<>(); |
| | | private Map<String, Object> systemData; |
| | | |
| | | public TemplateLoader() {} |
| | |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.modules.core.service.ICmsCoreService; |
| | | import com.xcong.farmer.cms.modules.system.service.IArticleService; |
| | | import com.xcong.farmer.cms.modules.system.service.IReleaseService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | public class CmsCoreController { |
| | | |
| | | @Autowired |
| | | private IArticleService articleService; |
| | | private IReleaseService releaseService; |
| | | |
| | | @ApiOperation(value = "发布文章", notes = "发布文章") |
| | | @PostMapping(value = "releaseArticle/{id}") |
| | | public Result releaseArticle(@PathVariable("id") Long id) { |
| | | articleService.releaseArticle(id); |
| | | releaseService.releaseArticle(id); |
| | | return Result.ok("success"); |
| | | } |
| | | |
| | | @ApiOperation(value = "发布栏目", notes = "发布栏目") |
| | | @PostMapping(value = "releaseColumn/{type}/{id}") |
| | | public Result releaseColumn(@PathVariable("id") Long id, @PathVariable("type") Integer type) { |
| | | boolean article = false; |
| | | if (type == 1) { |
| | | article = true; |
| | | } |
| | | releaseService.releaseColumn(id, article); |
| | | return Result.ok("success"); |
| | | } |
| | | } |
| | |
| | | package com.xcong.farmer.cms.modules.core.service; |
| | | |
| | | import java.util.Map; |
| | | |
| | | public interface ICmsCoreService { |
| | | |
| | | /** |
| | |
| | | |
| | | /** |
| | | * 栏目编译 |
| | | * @param code 栏目代码 |
| | | * @param map 栏目页面参数(如: 栏目ID/CODE) |
| | | * @param templateName 模板名称 |
| | | * @param columnOnly 是否只编译当前栏目列表页(如果false,则会编译栏目下所有子栏目或者所有文章) |
| | | */ |
| | | void columnProcess(String code, String templateName, boolean columnOnly); |
| | | void columnProcess(Map<String, Object> map, String templateName, boolean columnOnly); |
| | | |
| | | /** |
| | | * 栏目编译 |
| | | * @param id 栏目ID |
| | | * @param templateName 模板名称 |
| | | * @param columnOnly 是否只编译当前栏目列表页(如果false,则会编译栏目下所有子栏目或者所有文章) |
| | | */ |
| | | void columnProcess(Long id, String templateName, boolean columnOnly); |
| | | } |
| | |
| | | public void articleProcess(Long id, String templateName) { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("id", id); |
| | | data.put("companyId", 0L); |
| | | data.put("companyId", 23L); |
| | | if (StrUtil.isEmpty(templateName)) { |
| | | templateName = "artile.defualt.html"; |
| | | templateName = "defualt.artile.html"; |
| | | } |
| | | cfg.process(data, templateName); |
| | | } |
| | | |
| | | @Override |
| | | public void columnProcess(String code, String templateName, boolean article) { |
| | | |
| | | public void columnProcess(Map<String, Object> data, String templateName, boolean article) { |
| | | data.put("companyId", 23L); |
| | | if (StrUtil.isEmpty(templateName)) { |
| | | templateName = "defualt.list.html"; |
| | | } |
| | | |
| | | @Override |
| | | public void columnProcess(Long id, String templateName, boolean article) { |
| | | |
| | | cfg.process(data, templateName); |
| | | } |
| | | } |
| | |
| | | |
| | | Result updateIstopOff(Long id); |
| | | |
| | | void releaseArticle(Long id); |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.system.service; |
| | | |
| | | public interface IReleaseService { |
| | | |
| | | |
| | | void releaseArticle(Long id); |
| | | |
| | | void releaseColumn(Long id, boolean article); |
| | | } |
| | |
| | | this.baseMapper.updateById(articleEntity); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | | @Override |
| | | public void releaseArticle(Long id) { |
| | | ArticleEntity article = this.baseMapper.selectById(id); |
| | | |
| | | ColumnEntity column = columnMapper.selectById(article.getColumnId()); |
| | | cmsCoreService.articleProcess(article.getId(), column.getArticleTemplate()); |
| | | } |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.system.service.Impl; |
| | | |
| | | import com.xcong.farmer.cms.modules.core.service.ICmsCoreService; |
| | | 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.service.IReleaseService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-05 |
| | | **/ |
| | | @Slf4j |
| | | @Service |
| | | public class ReleaseServiceImpl implements IReleaseService { |
| | | |
| | | @Autowired |
| | | private ArticleMapper articleMapper; |
| | | |
| | | @Autowired |
| | | private ColumnMapper columnMapper; |
| | | |
| | | @Autowired |
| | | private ICmsCoreService cmsCoreService; |
| | | |
| | | @Override |
| | | public void releaseArticle(Long id) { |
| | | ArticleEntity article = articleMapper.selectById(id); |
| | | |
| | | ColumnEntity column = columnMapper.selectById(article.getColumnId()); |
| | | cmsCoreService.articleProcess(article.getId(), column.getArticleTemplate()); |
| | | } |
| | | |
| | | @Override |
| | | public void releaseColumn(Long id, boolean article) { |
| | | ColumnEntity columnEntity = columnMapper.selectById(id); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("id", columnEntity.getId()); |
| | | map.put("code", columnEntity.getColumnCode()); |
| | | |
| | | cmsCoreService.columnProcess(map, columnEntity.getListTemplate(), article); |
| | | } |
| | | } |