15 files added
17 files renamed
4 files deleted
6 files modified
New file |
| | |
| | | package com.xcong.farmer.cms.configurations; |
| | | |
| | | import com.xcong.farmer.cms.core.template.TemplateConfiguration; |
| | | import com.xcong.farmer.cms.core.template.TemplateLoader; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-03 |
| | | **/ |
| | | @Slf4j |
| | | @Configuration |
| | | public class CmsConfig { |
| | | |
| | | @Bean |
| | | public TemplateConfiguration templateConfiguration() { |
| | | log.info("CMS管理系统"); |
| | | TemplateConfiguration cfg = new TemplateConfiguration("/Users/helius/Desktop/court-web", "", "/Users/helius/Desktop/web/output"); |
| | | TemplateLoader loader = new TemplateLoader(cfg); |
| | | cfg.templateLoader(loader); |
| | | return cfg; |
| | | } |
| | | } |
| | |
| | | .authorizeRequests() |
| | | .antMatchers(HttpMethod.OPTIONS, "/**").permitAll() |
| | | .antMatchers("/login").permitAll() |
| | | .antMatchers("/cms/**").permitAll() |
| | | .antMatchers("/html").permitAll() |
| | | .antMatchers("/swagger**/**").permitAll() |
| | | .antMatchers("/webjars/**").permitAll() |
New file |
| | |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.farmer.cms.core.node.AttrNode; |
| | | 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 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 |
| | | **/ |
| | | public class ArticleDataParserHandler implements DataParserHandler { |
| | | |
| | | private final ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class); |
| | | |
| | | @Override |
| | | public void dataParser(AttrNode node) { |
| | | System.out.println("ArticleDataParserHandler"); |
| | | 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); |
| | | |
| | | Map map = JSONObject.parseObject(JSONObject.toJSONString(data), Map.class); |
| | | // Map<String, Object> map = new HashMap<>(); |
| | | // map.put("title", "这是单个文章标题"); |
| | | |
| | | map.put("prev", prev); |
| | | map.put("next", next); |
| | | node.setData(map); |
| | | } |
| | | } |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/handler/ArticlesDataParserHandler.java |
| | |
| | | package com.xcong.farmer.cms.cms.handler; |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | import com.xcong.farmer.cms.cms.node.AttrNode; |
| | | import com.xcong.farmer.cms.core.node.AttrNode; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/handler/ChildDataParserHandler.java |
| | |
| | | package com.xcong.farmer.cms.cms.handler; |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.farmer.cms.cms.node.AttrNode; |
| | | import com.xcong.farmer.cms.core.node.AttrNode; |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
New file |
| | |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | |
| | | import com.xcong.farmer.cms.core.node.AttrNode; |
| | | |
| | | public interface DataParserHandler { |
| | | |
| | | void dataParser(AttrNode attrNode); |
| | | |
| | | } |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/handler/NavDataParserHandler.java |
| | |
| | | package com.xcong.farmer.cms.cms.handler; |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | import com.xcong.farmer.cms.cms.node.AttrNode; |
| | | import com.xcong.farmer.cms.core.node.AttrNode; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/handler/TemplateCodeDataParserHandler.java |
| | |
| | | package com.xcong.farmer.cms.cms.handler; |
| | | package com.xcong.farmer.cms.core.handler; |
| | | |
| | | import com.xcong.farmer.cms.cms.node.AttrNode; |
| | | import com.xcong.farmer.cms.core.node.AttrNode; |
| | | |
| | | /** |
| | | * @author wzy |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/node/AttrNode.java |
| | |
| | | package com.xcong.farmer.cms.cms.node; |
| | | package com.xcong.farmer.cms.core.node; |
| | | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.farmer.cms.cms.handler.DataParserHandler; |
| | | import com.xcong.farmer.cms.cms.tag.TagsEnum; |
| | | import com.xcong.farmer.cms.cms.tag.model.Articles; |
| | | import com.xcong.farmer.cms.cms.template.Configuration; |
| | | import com.xcong.farmer.cms.core.handler.DataParserHandler; |
| | | import com.xcong.farmer.cms.core.tag.TagsEnum; |
| | | import com.xcong.farmer.cms.core.template.Configuration; |
| | | import groovy.lang.Binding; |
| | | import groovy.lang.GroovyShell; |
| | | import org.apache.commons.text.StringSubstitutor; |
| | | import org.jsoup.nodes.Attribute; |
| | | import org.jsoup.nodes.Attributes; |
| | | import org.jsoup.nodes.Element; |
| | | import org.jsoup.select.Elements; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | private Object data; |
| | | // 用于给这个标签attr注入的数据 |
| | | private Map<String, Object> parserData; |
| | | private Map<String, Object> systemData; |
| | | |
| | | // Tag参数 {id=[1,2,3], page=1, limit=5, field=art} |
| | | private Object param; |
| | | |
| | | private Element element; |
| | | private Element originalElement; |
| | | private boolean processContinue = true; |
| | | |
| | | public AttrNode() { |
| | | } |
| | |
| | | System.out.println(1); |
| | | } |
| | | |
| | | private boolean isNeedEmpty() { |
| | | Elements children = this.element.children(); |
| | | if (CollUtil.isNotEmpty(children)) { |
| | | return true; |
| | | } |
| | | Attributes attributes = this.element.attributes(); |
| | | if (CollUtil.isEmpty(attributes)) { |
| | | return false; |
| | | } |
| | | |
| | | for (Attribute attribute : attributes) { |
| | | if (attribute.getKey().contains("@") || attribute.getKey().contains("$")) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | public void parser() { |
| | | // 判断是否为最小节点,如果是且没有特殊标签,则跳过清空 |
| | | if (!isNeedEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | this.element.empty(); |
| | | Attributes attributes = this.element.attributes(); |
| | | if (attributes.isEmpty()) { |
| | |
| | | } |
| | | |
| | | this.tag = tagsEnum.getName(); |
| | | if (this.data == null) { |
| | | this.processContinue = false; |
| | | } |
| | | } |
| | | |
| | | runDataInject(); |
| | |
| | | |
| | | this.element.removeAttr("class"); |
| | | this.element.attr("class", evaluate); |
| | | } else if (value.startsWith("${")) { |
| | | } else if (value.contains( "${")) { |
| | | |
| | | String result = attrValueFormat(value); |
| | | System.out.println(result); |
| | | if ("text".equals(key)) { |
| | | this.element.text(result); |
| | | } else { |
| | |
| | | Map<String, String> targetData = new HashMap<>(); |
| | | while (matcher.find()) { |
| | | String group = matcher.group(); |
| | | String splitValue = group.replaceAll("\\$\\{", "").replaceAll("}", ""); |
| | | String[] split = splitValue.split("\\."); |
| | | if (split.length == 0) { |
| | | continue; |
| | | } |
| | | // String splitValue = group.replaceAll("\\$\\{", "").replaceAll("}", ""); |
| | | // String[] split = splitValue.split("\\."); |
| | | // if (split.length == 0) { |
| | | // continue; |
| | | // } |
| | | // |
| | | // for (Map.Entry<String, Object> entry : this.parserData.entrySet()) { |
| | | // String fieldKey = entry.getKey(); |
| | | // Map<String, Object> data = (Map<String, Object>) entry.getValue(); |
| | | // JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(data.get("state"))); |
| | | // |
| | | // for (Map.Entry<String, Object> map : jsonObject.entrySet()) { |
| | | // if (map.getValue() instanceof String) { |
| | | // targetData.put(fieldKey + "." + map.getKey(), (String) map.getValue()); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | Binding binding = new Binding(); |
| | | for (Map.Entry<String, Object> entry : this.parserData.entrySet()) { |
| | | String fieldKey = entry.getKey(); |
| | | Map<String, Object> data = (Map<String, Object>) entry.getValue(); |
| | | JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(data.get("state"))); |
| | | binding.setProperty(fieldKey, data.get("state")); |
| | | } |
| | | |
| | | for (Map.Entry<String, Object> map : jsonObject.entrySet()) { |
| | | if (map.getValue() instanceof String) { |
| | | targetData.put(fieldKey + "." + map.getKey(), (String) map.getValue()); |
| | | if (systemData != null) { |
| | | binding.setProperty("system", systemData); |
| | | } |
| | | } |
| | | |
| | | GroovyShell shell = new GroovyShell(binding); |
| | | Object evaluate = shell.evaluate(group); |
| | | if (evaluate == null) { |
| | | targetData.put(group, ""); |
| | | } else { |
| | | targetData.put(group, evaluate.toString()); |
| | | } |
| | | } |
| | | |
| | |
| | | public String getTag() { |
| | | return tag; |
| | | } |
| | | |
| | | public boolean processContinue() { |
| | | return processContinue; |
| | | } |
| | | |
| | | public void systemData(Map<String, Object> systemData) { |
| | | this.systemData = systemData; |
| | | } |
| | | } |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/node/PartNode.java |
| | |
| | | package com.xcong.farmer.cms.cms.node; |
| | | package com.xcong.farmer.cms.core.node; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.farmer.cms.cms.template.Configuration; |
| | | import com.xcong.farmer.cms.core.template.Configuration; |
| | | import org.jsoup.nodes.Element; |
| | | |
| | | import java.util.HashMap; |
| | |
| | | private Element element; |
| | | private Element originalElement; |
| | | private String html; |
| | | private Map<String, Object> system; |
| | | |
| | | public PartNode(Element element) { |
| | | public PartNode(Element element, Map<String, Object> data) { |
| | | this.element = element.clone(); |
| | | this.originalElement = element; |
| | | this.system = data; |
| | | } |
| | | |
| | | public void parser() { |
| | |
| | | |
| | | public String parser(Element element, Map<String, Object> tagDataMap) { |
| | | AttrNode attrNode = new AttrNode(element, tagDataMap); |
| | | attrNode.systemData(this.system); |
| | | attrNode.parser(); |
| | | // attrNode.runDataInject(); |
| | | |
| | |
| | | |
| | | if (parseData == null) { |
| | | // 特殊处理。 如果有子节点标签@child,但数据中没有子节点数据,则将该子节点直接删除即直接返回空字符串 |
| | | if (!"@child".equals(attrNode.getTag())) { |
| | | if (attrNode.processContinue()) { |
| | | for (Element children : element.children()) { |
| | | String html = parser(children, tagDataMap); |
| | | result.append(html); |
New file |
| | |
| | | package com.xcong.farmer.cms.core.tag; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-06-20 |
| | | **/ |
| | | public enum TagsEnum { |
| | | // INCLUDE("@include", "com.xcong.farmer.cms.core.tag.model.Include", "com.xcong.farmer.cms.core.handler.TemplateCodeDataParserHandler", 1), |
| | | NAV("@nav", "com.xcong.farmer.cms.core.tag.model.Nav", "com.xcong.farmer.cms.core.handler.NavDataParserHandler", 2), |
| | | 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), |
| | | // 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); |
| | | |
| | | private String name; |
| | | |
| | | private String className; |
| | | |
| | | private String handler; |
| | | |
| | | // 标签类型 1-模板标签 2-数据标签 |
| | | // 模板标签 : 该标签可以变为通用模板,在各个页面引入 |
| | | // 数据模板 : 该标签需要注入数据 |
| | | private int type; |
| | | |
| | | TagsEnum(String name, String className, String handler, int type) { |
| | | this.name = name; |
| | | this.className = className; |
| | | this.type = type; |
| | | this.handler = handler; |
| | | } |
| | | |
| | | public String getName() { |
| | | return name; |
| | | } |
| | | |
| | | public String getClassName() { |
| | | return className; |
| | | } |
| | | |
| | | public int getType() { |
| | | return type; |
| | | } |
| | | |
| | | public String getHandler() { |
| | | return handler; |
| | | } |
| | | |
| | | public static TagsEnum getEnumByName(String name) { |
| | | for (TagsEnum value : values()) { |
| | | if (name.equals(value.getName())) { |
| | | return value; |
| | | } |
| | | } |
| | | |
| | | return null; |
| | | } |
| | | } |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/tag/model/Ad.java |
| | |
| | | package com.xcong.farmer.cms.cms.tag.model; |
| | | package com.xcong.farmer.cms.core.tag.model; |
| | | |
| | | /** |
| | | * @author wzy |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/tag/model/Article.java |
| | |
| | | package com.xcong.farmer.cms.cms.tag.model; |
| | | package com.xcong.farmer.cms.core.tag.model; |
| | | |
| | | /** |
| | | * @author wzy |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/tag/model/Articles.java |
| | |
| | | package com.xcong.farmer.cms.cms.tag.model; |
| | | package com.xcong.farmer.cms.core.tag.model; |
| | | |
| | | /** |
| | | * @author wzy |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/tag/model/Child.java |
| | |
| | | package com.xcong.farmer.cms.cms.tag.model; |
| | | package com.xcong.farmer.cms.core.tag.model; |
| | | |
| | | /** |
| | | * @author wzy |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/tag/model/Column.java |
| | |
| | | package com.xcong.farmer.cms.cms.tag.model; |
| | | package com.xcong.farmer.cms.core.tag.model; |
| | | |
| | | /** |
| | | * @author wzy |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/tag/model/Columns.java |
| | |
| | | package com.xcong.farmer.cms.cms.tag.model; |
| | | package com.xcong.farmer.cms.core.tag.model; |
| | | |
| | | /** |
| | | * @author wzy |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/tag/model/Include.java |
| | |
| | | package com.xcong.farmer.cms.cms.tag.model; |
| | | package com.xcong.farmer.cms.core.tag.model; |
| | | |
| | | /** |
| | | * @author wzy |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/tag/model/Nav.java |
| | |
| | | package com.xcong.farmer.cms.cms.tag.model; |
| | | package com.xcong.farmer.cms.core.tag.model; |
| | | |
| | | /** |
| | | * @author wzy |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/template/Configuration.java |
| | |
| | | package com.xcong.farmer.cms.cms.template; |
| | | |
| | | import com.xcong.farmer.cms.cms.node.AttrNode; |
| | | package com.xcong.farmer.cms.core.template; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.util.HashMap; |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/template/Template.java |
| | |
| | | package com.xcong.farmer.cms.cms.template; |
| | | package com.xcong.farmer.cms.core.template; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.xcong.farmer.cms.cms.node.PartNode; |
| | | import com.xcong.farmer.cms.core.node.PartNode; |
| | | import org.jsoup.nodes.Document; |
| | | import org.jsoup.nodes.Element; |
| | | import org.jsoup.select.Elements; |
| | |
| | | private Document document; |
| | | |
| | | private Map<String, Map<String, Object>> params = new HashMap<>(); |
| | | private Map<String, Object> system; |
| | | |
| | | private List<PartNode> partNodes = new ArrayList<>(); |
| | | |
| | |
| | | Elements children = document.body().children(); |
| | | if (CollUtil.isNotEmpty(children)) { |
| | | for (Element child : children) { |
| | | PartNode partNode = new PartNode(child); |
| | | PartNode partNode = new PartNode(child, this.system); |
| | | partNode.parser(); |
| | | |
| | | this.add(partNode); |
| | |
| | | public void putParams(String key, Map<String, Object> value) { |
| | | this.params.put(key, value); |
| | | } |
| | | |
| | | public void systemData(Map<String, Object> data) { |
| | | this.system = data; |
| | | } |
| | | } |
File was renamed from src/main/java/com/xcong/farmer/cms/cms/template/TemplateConfiguration.java |
| | |
| | | package com.xcong.farmer.cms.cms.template; |
| | | package com.xcong.farmer.cms.core.template; |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import com.xcong.farmer.cms.cms.node.PartNode; |
| | | import com.xcong.farmer.cms.cms.tag.TagsEnum; |
| | | import com.xcong.farmer.cms.core.node.PartNode; |
| | | import com.xcong.farmer.cms.core.tag.TagsEnum; |
| | | import org.jsoup.nodes.Document; |
| | | |
| | | import java.io.File; |
| | |
| | | this.templateLoader = templateLoader; |
| | | } |
| | | |
| | | public void process() { |
| | | public void process(Map<String, Object> map, String templateName) { |
| | | if (this.templateLoader == null) { |
| | | throw new RuntimeException("TemplateLoader do not able to be null"); |
| | | } |
| | | |
| | | List<Template> templates = templateLoader.templates(); |
| | | |
| | | if (CollUtil.isEmpty(templates)) { |
| | | return; |
| | | this.templateLoader.data(map); |
| | | output(template(templateName)); |
| | | } |
| | | |
| | | for (Template template : templates) { |
| | | output(template); |
| | | } |
| | | } |
| | | |
| | | public List<Template> templates() { |
| | | return this.templateLoader.templates(); |
| | | } |
| | | |
| | | public Template template(String templateName) { |
| | | return template(new File(path(this.templatePath) + templateName)); |
| | |
| | | return this.templateLoader.template(file); |
| | | } |
| | | |
| | | public void columnProcess(Long id, String templateName) { |
| | | Template template = template(templateName); |
| | | } |
| | | |
| | | public void columnProcess(String code, String templateName) { |
| | | |
| | | } |
| | | |
| | | public void articleProcess(Long id, String templateName) { |
| | | Map<String, Map<String, Object>> map = new HashMap<>(); |
| | | |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("id", id); |
| | | map.put(TagsEnum.ARTICLE.getName(), data); |
| | | } |
| | | // public void columnProcess(Map<String, Object> data, String templateName) { |
| | | // process; |
| | | // } |
| | | // |
| | | // |
| | | // public void articleProcess(Map<String, Object> data, String templateName) { |
| | | // process(data, templateName); |
| | | // } |
| | | |
| | | public void output(Template template) { |
| | | Document document = template.getDocument(); |
New file |
| | |
| | | package com.xcong.farmer.cms.core.template; |
| | | |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | public class TemplateLoader { |
| | | |
| | | private Configuration cfg; |
| | | private List<Template> templates = new ArrayList<>(); |
| | | private Map<String, Object> systemData; |
| | | |
| | | public TemplateLoader() {} |
| | | |
| | | public TemplateLoader(Configuration cfg) { |
| | | this.cfg = cfg; |
| | | } |
| | | |
| | | public Template template(File file) { |
| | | Document document = null; |
| | | try { |
| | | document = Jsoup.parse(file, "utf-8"); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | if (document == null) { |
| | | throw new NullPointerException(); |
| | | } |
| | | |
| | | Template template = new Template(); |
| | | template.setDocument(document); |
| | | template.setName(file.getName()); |
| | | template.systemData(this.systemData); |
| | | |
| | | template.parser(); |
| | | return template; |
| | | } |
| | | |
| | | public void data(Map<String, Object> systemData) { |
| | | this.systemData = systemData; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.core; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-03 |
| | | **/ |
| | | public class Test { |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.core.controller; |
| | | |
| | | 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 io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-03 |
| | | **/ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping(value = "/cms") |
| | | @Api(value = "CmsCoreController", tags = "CMS核心类") |
| | | public class CmsCoreController { |
| | | |
| | | @Autowired |
| | | private IArticleService articleService; |
| | | |
| | | @ApiOperation(value = "发布文章", notes = "发布文章") |
| | | @PostMapping(value = "releaseArticle/{id}") |
| | | public Result releaseArticle(@PathVariable("id") Long id) { |
| | | articleService.releaseArticle(id); |
| | | return Result.ok("success"); |
| | | } |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.core.service; |
| | | |
| | | public interface ICmsCoreService { |
| | | |
| | | /** |
| | | * 文章编译 |
| | | * |
| | | * @param id |
| | | * @param templateName |
| | | */ |
| | | void articleProcess(Long id, String templateName); |
| | | |
| | | /** |
| | | * 栏目编译 |
| | | * @param code 栏目代码 |
| | | * @param templateName 模板名称 |
| | | * @param columnOnly 是否只编译当前栏目列表页(如果false,则会编译栏目下所有子栏目或者所有文章) |
| | | */ |
| | | void columnProcess(String code, String templateName, boolean columnOnly); |
| | | |
| | | /** |
| | | * 栏目编译 |
| | | * @param id 栏目ID |
| | | * @param templateName 模板名称 |
| | | * @param columnOnly 是否只编译当前栏目列表页(如果false,则会编译栏目下所有子栏目或者所有文章) |
| | | */ |
| | | void columnProcess(Long id, String templateName, boolean columnOnly); |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.core.service.impl; |
| | | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.farmer.cms.core.template.TemplateConfiguration; |
| | | import com.xcong.farmer.cms.modules.core.service.ICmsCoreService; |
| | | 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-03 |
| | | **/ |
| | | @Slf4j |
| | | @Service |
| | | public class CmsCoreServiceImpl implements ICmsCoreService { |
| | | |
| | | @Autowired |
| | | private TemplateConfiguration cfg; |
| | | |
| | | @Override |
| | | public void articleProcess(Long id, String templateName) { |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("id", id); |
| | | |
| | | if (StrUtil.isEmpty(templateName)) { |
| | | templateName = "artile.defualt.html"; |
| | | } |
| | | cfg.process(data, templateName); |
| | | } |
| | | |
| | | @Override |
| | | public void columnProcess(String code, String templateName, boolean article) { |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public void columnProcess(Long id, String templateName, boolean article) { |
| | | |
| | | } |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.system.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.xcong.farmer.cms.common.system.base.BaseEntity; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-03 |
| | | **/ |
| | | @Data |
| | | @TableName("cms_template") |
| | | public class CmsTemplateEntity extends BaseEntity { |
| | | |
| | | private String name; |
| | | |
| | | private String path; |
| | | |
| | | private String code; |
| | | |
| | | /** |
| | | * 类型 1-文件 2-代码 |
| | | */ |
| | | private Integer type; |
| | | } |
| | |
| | | private Long parentId; |
| | | //所属ID |
| | | private Long companyId; |
| | | |
| | | // 列表页模板 |
| | | private String listTemplate; |
| | | |
| | | // 文章页模板 |
| | | private String articleTemplate; |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.system.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.xcong.farmer.cms.common.system.base.BaseEntity; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2021-09-25 |
| | | **/ |
| | | @Data |
| | | @TableName("data_dictionary_custom") |
| | | public class DataDictionaryCustom extends BaseEntity { |
| | | |
| | | private String type; |
| | | |
| | | private String code; |
| | | |
| | | private String value; |
| | | |
| | | private String description; |
| | | } |
| | |
| | | import com.xcong.farmer.cms.modules.system.entity.ArticleEntity; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminArticleVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeArticleInfoVo; |
| | | import io.swagger.models.auth.In; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | public interface ArticleMapper extends BaseMapper<ArticleEntity> { |
| | |
| | | IPage<AdminArticleVo> selectAdminArticleInPage(Page<AdminArticleVo> page, @Param("record")ArticleEntity articleEntity); |
| | | |
| | | AdminSeeArticleInfoVo selectAdminArticleByid(@Param("id")Long id); |
| | | |
| | | ArticleEntity selectPrevOrNextArticle(@Param("id") Long id, @Param("columnId") Long columnId, @Param("type") Integer type); |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.system.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity; |
| | | |
| | | public interface CmsTemplateMapper extends BaseMapper<CmsTemplateEntity> { |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.system.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xcong.farmer.cms.modules.system.entity.DataDictionaryCustom; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface DataDictionaryCustomMapper extends BaseMapper<DataDictionaryCustom> { |
| | | |
| | | List<DataDictionaryCustom> selectDicByType(String type); |
| | | |
| | | DataDictionaryCustom selectDicDataByTypeAndCode(@Param("type") String type, @Param("code") String code); |
| | | |
| | | int updateDicValueByTypeAndCode(@Param("type") String type, @Param("code") String code, @Param("value") String value); |
| | | } |
| | |
| | | Result updateIstop(Long id); |
| | | |
| | | Result updateIstopOff(Long id); |
| | | |
| | | void releaseArticle(Long id); |
| | | } |
| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.modules.core.service.ICmsCoreService; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminAddArticleDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminArticleDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminDeleteDto; |
| | |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminArticleVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeArticleInfoVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.ArrayList; |
| | |
| | | |
| | | @Resource |
| | | private ColumnMapper columnMapper; |
| | | |
| | | @Autowired |
| | | private ICmsCoreService cmsCoreService; |
| | | |
| | | @Override |
| | | public Result getArticleInPage(AdminArticleDto adminArticleDto) { |
| | |
| | | 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()); |
| | | } |
| | | } |
| | |
| | | t_article a where id = #{id} |
| | | </select> |
| | | |
| | | <select id="selectPrevOrNextArticle" resultType="com.xcong.farmer.cms.modules.system.entity.ArticleEntity"> |
| | | select * |
| | | from t_article a, t_column b |
| | | where a.id!=#{id} and (a.column_id=b.id or a.column_id=b.parent_id) and a.column_id=#{columnId} |
| | | <!--上一篇--> |
| | | <if test="type == 1"> |
| | | order by a.id |
| | | </if> |
| | | <!--下一篇--> |
| | | <if test="type == 2"> |
| | | order by a.id desc |
| | | </if> |
| | | limit 1 |
| | | </select> |
| | | </mapper> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.xcong.farmer.cms.modules.system.mapper.CmsTemplateMapper"> |
| | | |
| | | </mapper> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.xcong.farmer.cms.modules.system.mapper.DataDictionaryCustomMapper"> |
| | | |
| | | <select id="selectDicByType" resultType="com.xcong.farmer.cms.modules.system.entity.DataDictionaryCustom"> |
| | | select * from data_dictionary_custom where type=#{type} |
| | | </select> |
| | | |
| | | <select id="selectDicDataByTypeAndCode" resultType="com.xcong.farmer.cms.modules.system.entity.DataDictionaryCustom"> |
| | | select * from data_dictionary_custom a |
| | | where a.type=#{type} and a.code=#{code} |
| | | </select> |
| | | |
| | | <update id="updateDicValueByTypeAndCode"> |
| | | update data_dictionary_custom |
| | | set value=#{value} |
| | | <where> |
| | | 1=1 |
| | | <if test="code != null and code != ''"> |
| | | and code = #{code} |
| | | </if> |
| | | <if test="type != null and type != ''"> |
| | | and type = #{type} |
| | | </if> |
| | | </where> |
| | | </update> |
| | | </mapper> |