Merge branch 'master' of http://120.27.238.55:7000/r/farmer-cms
4 files deleted
38 files modified
10 files added
| | |
| | | |
| | | public static String path(String path, String fileName) { |
| | | File file = new File(path); |
| | | if (!file.isDirectory()){ |
| | | if (file.exists() && !file.isDirectory()){ |
| | | return ""; |
| | | } |
| | | |
| | | if (!file.exists()) { |
| | | file.mkdirs(); |
| | | } |
| | | |
| | | String dir = path(path); |
| | | return dir + fileName; |
| | | } |
| | |
| | | import com.xcong.farmer.cms.configurations.properties.CmsProperties; |
| | | import com.xcong.farmer.cms.core.template.TemplateConfiguration; |
| | | import com.xcong.farmer.cms.core.template.TemplateLoader; |
| | | import com.xcong.farmer.cms.modules.system.entity.DataDictionaryCustom; |
| | | import com.xcong.farmer.cms.modules.system.mapper.DataDictionaryCustomMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.context.annotation.Bean; |
| | | import org.springframework.context.annotation.Configuration; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * @author wzy |
| | |
| | | @Bean |
| | | public TemplateConfiguration templateConfiguration() { |
| | | log.info("CMS管理系统"); |
| | | TemplateConfiguration cfg = new TemplateConfiguration(cmsProperties.getTemplatePath(), cmsProperties.getStaticPath(), cmsProperties.getOutputPath(), cmsProperties.getBaseUrl(), cmsProperties.getStaticUrl()); |
| | | |
| | | TemplateConfiguration cfg = new TemplateConfiguration(cmsProperties.getTemplatePath(), cmsProperties.getStaticPath(), cmsProperties.getOutputPath(), cmsProperties.getApiUrl(), cmsProperties.getStaticUrl()); |
| | | TemplateLoader loader = new TemplateLoader(cfg); |
| | | cfg.templateLoader(loader); |
| | | return cfg; |
| | |
| | | import lombok.Data; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.context.annotation.Configuration; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Data |
| | | @Configuration |
| | | @ConfigurationProperties(prefix = "cms") |
| | | public class CmsProperties { |
| | | |
| | | /** |
| | | * 模板保存地址 |
| | | */ |
| | | private String templatePath; |
| | | |
| | | /** |
| | | * 静态文件保存地址 |
| | | */ |
| | | private String staticPath; |
| | | |
| | | /** |
| | | * html输出地址 |
| | | */ |
| | | private String outputPath; |
| | | |
| | | /** |
| | | * 静态文件访问地址 |
| | | */ |
| | | private String staticUrl; |
| | | |
| | | private String baseUrl; |
| | | /** |
| | | * api请求地址 |
| | | */ |
| | | private String apiUrl; |
| | | } |
| | |
| | | @Mapping(source = "visits", target = "views") |
| | | @Mapping(source = "mainDiagram", target = "thumb") |
| | | @Mapping(source = "releaseTime", target = "createTime") |
| | | @Mapping(source = "authorBelong", target = "company") |
| | | @Mapping(source = "articleDetails", target = "content") |
| | | @Mapping(source = "uploadFile", target = "filePath") |
| | | @Mapping(source = "remark", target = "description") |
| | | public abstract ArticleData entityToData(ArticleEntity article); |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.conversion; |
| | | |
| | | import com.xcong.farmer.cms.modules.system.dto.SetWebSettingDto; |
| | | import com.xcong.farmer.cms.modules.system.entity.WebSettingEntity; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeWebSetInfoVo; |
| | | import org.mapstruct.Mapper; |
| | | import org.mapstruct.factory.Mappers; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-11 |
| | | **/ |
| | | @Mapper |
| | | public abstract class WebSettingConversion { |
| | | public static WebSettingConversion INSTANCE = Mappers.getMapper(WebSettingConversion.class); |
| | | |
| | | public abstract WebSettingEntity dtoToEntity(SetWebSettingDto setWebSettingDto); |
| | | |
| | | public abstract AdminSeeWebSetInfoVo entityToVo(WebSettingEntity webSettingEntity); |
| | | } |
| | |
| | | |
| | | |
| | | 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); |
| | | |
| | | @Override |
| | | public void dataParser(AttrNode node) { |
| | | System.out.println("ArticleDataParserHandler"); |
| | | log.info("######文章解析########"); |
| | | String baseUrl = (String) node.getSystemDataValue("baseUrl"); |
| | | |
| | | 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(baseUrl + 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(baseUrl + nextEntity.getPath() + "/" + nextEntity.getId() + ".html"); |
| | | } |
| | | |
| | | articleData.setNext(next); |
| | | } else { |
| | | articleData.setNext(new ArticleData()); |
| | | } |
| | | |
| | | node.setData(articleData); |
| | | } |
| | | } |
| | |
| | | public class ArticlesDataParserHandler implements DataParserHandler { |
| | | |
| | | private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class); |
| | | private CmsProperties cmsProperties = SpringContextHolder.getBean(CmsProperties.class); |
| | | |
| | | @Override |
| | | public void dataParser(AttrNode node) { |
| | | log.info("文章列表解析"); |
| | | Long companyId = (Long) node.getSystemDataValue("companyId"); |
| | | Articles param = (Articles) node.getParam(); |
| | | String companyCode = (String) node.getSystemDataValue("companyCode"); |
| | | String baseUrl = (String) node.getSystemDataValue("baseUrl"); |
| | | |
| | | Articles param = (Articles) node.getParam(); |
| | | ArticleEntity article = new ArticleEntity(); |
| | | Page<ArticleEntity> page = new Page<>(Integer.parseInt(param.getPage()), Integer.parseInt(param.getLimit())); |
| | | if (StrUtil.isEmpty(param.getColId())) { |
| | | |
| | | article.setColumnCode(param.getCode()); |
| | | |
| | | } else { |
| | | List<String> colIdsStr = StrUtil.split(param.getColId(), ','); |
| | | List<Long> colIds = new ArrayList<>(); |
| | |
| | | article.setColumnIds(colIds); |
| | | } |
| | | article.setCompanyId(companyId); |
| | | |
| | | if (StrUtil.isNotBlank(param.getType())) { |
| | | if ("hot".equals(param.getType())) { |
| | | article.setIsTop(1); |
| | | } |
| | | } |
| | | |
| | | IPage<ArticleEntity> listPage = articleMapper.selectArticleInPage(page, article); |
| | | |
| | | List<ArticleData> list = new ArrayList<>(); |
| | | for (ArticleEntity record : listPage.getRecords()) { |
| | | ArticleData articleData = entityToData(record); |
| | | ArticleData articleData = entityToData(record, baseUrl); |
| | | list.add(articleData); |
| | | } |
| | | |
| | | node.setData(list); |
| | | } |
| | | |
| | | public ArticleData entityToData(ArticleEntity article) { |
| | | public ArticleData entityToData(ArticleEntity article, String baseUrl) { |
| | | ArticleData articleData = ArticleConversion.INSTANCE.entityToData(article); |
| | | |
| | | if (article.getType() == 2) { |
| | | articleData.setUrl(article.getArticleUrl()); |
| | | } else { |
| | | articleData.setUrl(cmsProperties.getBaseUrl() + article.getPath() + "/" + article.getId() + ".html"); |
| | | articleData.setUrl(baseUrl + article.getPath() + "/" + article.getId() + ".html"); |
| | | } |
| | | |
| | | |
| | |
| | | String obj = param.getObj(); |
| | | |
| | | Object o = parserData.get(obj); |
| | | if (o == null) { |
| | | return; |
| | | } |
| | | Object state = JSONObject.parseObject(JSONObject.toJSONString(o)).get("state"); |
| | | List children = JSONObject.parseObject(JSONObject.toJSONString(state)).getObject("children", List.class); |
| | | attrNode.setData(children); |
| | |
| | | |
| | | private ColumnMapper columnMapper = SpringContextHolder.getBean(ColumnMapper.class); |
| | | private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class); |
| | | private CmsProperties cmsProperties = SpringContextHolder.getBean(CmsProperties.class); |
| | | |
| | | private String baseUrl = ""; |
| | | @Override |
| | | public void dataParser(AttrNode attrNode) { |
| | | log.info("栏目解析"); |
| | | Long companyId = (Long) attrNode.getSystemDataValue("companyId"); |
| | | baseUrl = (String) attrNode.getSystemDataValue("baseUrl"); |
| | | |
| | | Column param = (Column) attrNode.getParam(); |
| | | |
| | |
| | | } |
| | | ColumnData columnData = columnToData(columnEntity); |
| | | if (columnEntity.getParentId() == 0L) { |
| | | List<ColumnEntity> child = columnMapper.selectColumnByParentId(columnEntity.getId(), companyId); |
| | | List<ColumnEntity> child = columnMapper.selectColumnByParentId(columnEntity.getId(), companyId, 1); |
| | | if (CollUtil.isNotEmpty(child)) { |
| | | List<ColumnData> list = new ArrayList<>(); |
| | | for (ColumnEntity entity : child) { |
| | |
| | | public ColumnData columnToData(ColumnEntity column) { |
| | | ColumnData columnData = ColumnConversion.INSTANCE.entityToData(column); |
| | | |
| | | columnData.setUrl(cmsProperties.getBaseUrl() + column.getPath()); |
| | | columnData.setUrl(baseUrl + column.getPath()); |
| | | if (column.getType() == 2) { |
| | | if (column.getTargetType() == 1) { |
| | | ArticleEntity article = this.articleMapper.selectArticleById(Long.parseLong(column.getTargetUrl())); |
| | | columnData.setUrl(cmsProperties.getBaseUrl() + article.getPath() + "/" + article.getId() + ".html"); |
| | | columnData.setUrl(baseUrl + article.getPath() + "/" + article.getId() + ".html"); |
| | | } else if (column.getTargetType() == 2) { |
| | | ColumnEntity columnEntity = this.columnMapper.selectByCodeAndCompanyId(column.getTargetUrl(), column.getCompanyId()); |
| | | columnData.setUrl(cmsProperties.getBaseUrl() + columnEntity.getPath()); |
| | | columnData.setUrl(baseUrl + columnEntity.getPath()); |
| | | } else { |
| | | columnData.setUrl(column.getTargetUrl()); |
| | | } |
| | |
| | | |
| | | private ColumnMapper columnMapper = SpringContextHolder.getBean(ColumnMapper.class); |
| | | private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class); |
| | | private CmsProperties cmsProperties = SpringContextHolder.getBean(CmsProperties.class); |
| | | |
| | | private String baseUrl = ""; |
| | | @Override |
| | | public void dataParser(AttrNode node) { |
| | | 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; |
| | |
| | | |
| | | NavData index = new NavData(); |
| | | index.setTitle("首页"); |
| | | index.setUrl(cmsProperties.getBaseUrl()); |
| | | 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); |
| | |
| | | public NavData columnToNav(ColumnEntity column) { |
| | | NavData navData = ColumnConversion.INSTANCE.columnToNav(column); |
| | | |
| | | navData.setUrl(cmsProperties.getBaseUrl() + column.getPath()); |
| | | navData.setUrl(baseUrl + 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"); |
| | | navData.setUrl(baseUrl + 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()); |
| | | navData.setUrl(baseUrl + columnEntity.getPath()); |
| | | } else { |
| | | navData.setUrl(column.getTargetUrl()); |
| | | } |
| | |
| | | public class PageDataParserHandler implements DataParserHandler { |
| | | |
| | | private ArticleMapper articleMapper = SpringContextHolder.getBean(ArticleMapper.class); |
| | | private CmsProperties cmsProperties = SpringContextHolder.getBean(CmsProperties.class); |
| | | @Override |
| | | public void dataParser(AttrNode attrNode) { |
| | | log.info("分页解析"); |
| | | Template.HAS_PAGING = true; |
| | | synchronized (this) { |
| | | Template.HAS_PAGING = true; |
| | | String baseUrl = (String) attrNode.getSystemDataValue("baseUrl"); |
| | | |
| | | Long companyId = (Long) attrNode.getSystemDataValue("companyId"); |
| | | Pagination param = (Pagination) attrNode.getParam(); |
| | | Long companyId = (Long) attrNode.getSystemDataValue("companyId"); |
| | | Pagination param = (Pagination) attrNode.getParam(); |
| | | |
| | | Page<ArticleEntity> page = new Page<>(Integer.parseInt(param.getPage()), Integer.parseInt(param.getLimit())); |
| | | ArticleEntity article = new ArticleEntity(); |
| | | article.setColumnCode(param.getCode()); |
| | | article.setCompanyId(companyId); |
| | | IPage<ArticleEntity> pageList = articleMapper.selectArticleInPage(page, article); |
| | | Page<ArticleEntity> page = new Page<>(Integer.parseInt(param.getPage()), Integer.parseInt(param.getLimit())); |
| | | ArticleEntity article = new ArticleEntity(); |
| | | article.setColumnCode(param.getCode()); |
| | | article.setCompanyId(companyId); |
| | | IPage<ArticleEntity> pageList = articleMapper.selectArticleInPage(page, article); |
| | | |
| | | PageData pageData = new PageData(); |
| | | pageData.setTotalPage((int) pageList.getPages()); |
| | | pageData.setIndex(Integer.parseInt(param.getPage())); |
| | | pageData.setTotalCnt((int) pageList.getSize()); |
| | | PageData pageData = new PageData(); |
| | | pageData.setTotalPage((int) pageList.getPages()); |
| | | pageData.setIndex(Integer.parseInt(param.getPage())); |
| | | pageData.setTotalCnt((int) pageList.getSize()); |
| | | |
| | | if (CollUtil.isNotEmpty(pageList.getRecords())) { |
| | | String path = cmsProperties.getBaseUrl() + "/" + param.getCode(); |
| | | String filename = "index_{}.html"; |
| | | if (CollUtil.isNotEmpty(pageList.getRecords())) { |
| | | String path = baseUrl + "/" + param.getCode(); |
| | | String filename = "index_{}.html"; |
| | | |
| | | List<PageChildData> list = new ArrayList<>(); |
| | | int pageNo = Integer.parseInt(param.getPage()); |
| | | List<PageChildData> list = new ArrayList<>(); |
| | | int pageNo = Integer.parseInt(param.getPage()); |
| | | |
| | | // 计算出页面显示分页的最大和最小值 |
| | | int[] startAndEnd = pageStartAndEnd(pageNo, (int) pageList.getPages(), Integer.parseInt(param.getSize())); |
| | | for (int i = startAndEnd[0]; i <= startAndEnd[1] ; i++) { |
| | | PageChildData child = new PageChildData(); |
| | | child.setIndex(i); |
| | | if (pageNo == 1) { |
| | | child.setPath(path + "/index.html"); |
| | | } else { |
| | | child.setPath(path + "/" + StrUtil.format(filename, i)); |
| | | // 计算出页面显示分页的最大和最小值 |
| | | int[] startAndEnd = pageStartAndEnd(pageNo, (int) pageList.getPages(), Integer.parseInt(param.getSize())); |
| | | for (int i = startAndEnd[0]; i <= startAndEnd[1]; i++) { |
| | | PageChildData child = new PageChildData(); |
| | | child.setIndex(i); |
| | | if (pageNo == 1) { |
| | | child.setPath(path + "/index.html"); |
| | | } else { |
| | | child.setPath(path + "/" + StrUtil.format(filename, i)); |
| | | } |
| | | list.add(child); |
| | | } |
| | | list.add(child); |
| | | |
| | | pageData.setChildren(list); |
| | | } else { |
| | | pageData.setNext("javascript:void(0)"); |
| | | pageData.setPrev("javascript:void(0)"); |
| | | } |
| | | |
| | | pageData.setChildren(list); |
| | | } else { |
| | | pageData.setNext("javascript:void(0)"); |
| | | pageData.setPrev("javascript:void(0)"); |
| | | } |
| | | if (Integer.parseInt(param.getPage()) >= pageList.getPages()) { |
| | | Template.HAS_PAGING = false; |
| | | } |
| | | |
| | | if (Integer.parseInt(param.getPage()) == pageList.getPages()) { |
| | | Template.HAS_PAGING = false; |
| | | attrNode.setData(pageData); |
| | | } |
| | | |
| | | attrNode.setData(pageData); |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.farmer.cms.core.handler.DataParserHandler; |
| | | import com.xcong.farmer.cms.core.tag.TagsEnum; |
| | | import com.xcong.farmer.cms.core.tag.model.TimeTag; |
| | | import com.xcong.farmer.cms.core.template.Configuration; |
| | | import com.xcong.farmer.cms.core.template.TemplateConfiguration; |
| | | import com.xcong.farmer.cms.utils.GroovySingleton; |
| | | import groovy.lang.Binding; |
| | | import groovy.lang.GroovyShell; |
| | | import groovy.lang.Script; |
| | | 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.time.format.DateTimeFormatter; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.regex.Matcher; |
| | |
| | | return false; |
| | | } |
| | | |
| | | public void staticPath() { |
| | | // 设置img的链接访问 |
| | | if ("img".equals(this.element.tagName())) { |
| | | String src = this.element.attr("src"); |
| | | if (StrUtil.isNotBlank(STATIC_URL)) { |
| | | this.element.attr("src", STATIC_URL + src); |
| | | } |
| | | } |
| | | |
| | | if ("link".equals(this.element.tagName())) { |
| | | String src = this.element.attr("href"); |
| | | if (StrUtil.isNotBlank(STATIC_URL)) { |
| | | this.element.attr("href", STATIC_URL + src); |
| | | } |
| | | } |
| | | |
| | | if ("script".equals(this.element.tagName())) { |
| | | String src = this.element.attr("src"); |
| | | if (StrUtil.isNotBlank(STATIC_URL)) { |
| | | this.element.attr("src", STATIC_URL + src); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void parser() { |
| | | staticPath(); |
| | | // 判断是否为最小节点,如果是且没有特殊标签,则跳过清空 |
| | | if (!isNeedEmpty()) { |
| | | return; |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | runDataInject(); |
| | | } |
| | | |
| | |
| | | String key = attribute.getKey().replaceAll("\\$", ""); |
| | | String value = attribute.getValue(); |
| | | |
| | | String result = attrValueFormat(value); |
| | | // @{} 为java表达式; ${}为需要注入的数据项 |
| | | if (value.startsWith("@{")) { |
| | | value = value.replaceAll("\\@\\{", "").replaceAll("}", ""); |
| | | value = result.replaceAll("\\@\\{", "").replaceAll("}", ""); |
| | | 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(); |
| | | binding.setProperty(fieldKey, data); |
| | | binding.setVariable(fieldKey + ".index", 1); |
| | | binding.setProperty(fieldKey, data.get("state")); |
| | | int index = (int) data.get("index"); |
| | | binding.setVariable( "index", index); |
| | | } |
| | | GroovyShell shell = new GroovyShell(binding); |
| | | String evaluate = (String) shell.evaluate(value); |
| | |
| | | this.element.removeAttr("class"); |
| | | this.element.attr("class", evaluate); |
| | | } else if (value.contains( "${")) { |
| | | String result = attrValueFormat(value); |
| | | if ("text".equals(key)) { |
| | | this.element.text(result); |
| | | } else if ("html".equals(key)) { |
| | | this.element.html(result); |
| | | } else if ("time".equals(key)) { |
| | | TimeTag time = parserTag(result, TimeTag.class); |
| | | String timeStr = DateUtil.format(DateUtil.parse(time.getDate(), DatePattern.NORM_DATETIME_PATTERN), time.getFormat()); |
| | | this.element.text(timeStr); |
| | | } else { |
| | | this.element.attr(key, result); |
| | | } |
| | |
| | | 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; |
| | | // } |
| | | // |
| | | // 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()); |
| | | // } |
| | | // } |
| | | // } |
| | | |
| | | GroovyShell groovyShell = GroovySingleton.getSingleton(); |
| | | Binding binding = new Binding(); |
| | | for (Map.Entry<String, Object> entry : this.parserData.entrySet()) { |
| | | String fieldKey = entry.getKey(); |
| | |
| | | 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()); |
| | | synchronized (this) { |
| | | Script parse = groovyShell.parse(group); |
| | | parse.setBinding(binding); |
| | | Object evaluate = parse.run(); |
| | | if (evaluate instanceof Date) { |
| | | evaluate = DateUtil.format((Date) evaluate, DatePattern.NORM_DATETIME_PATTERN); |
| | | } |
| | | |
| | | if (evaluate == null) { |
| | | targetData.put(group, ""); |
| | | } else { |
| | | targetData.put(group, evaluate.toString()); |
| | | } |
| | | groovyShell.getClassLoader().clearCache(); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | // 页面中包含的标签 |
| | | public static Set<String> TAGS; |
| | | public static boolean HAS_PAGING = false; |
| | | public volatile static boolean HAS_PAGING = false; |
| | | |
| | | public Template() { |
| | | TAGS = new HashSet<>(); |
| | |
| | | if (!new Integer(1).equals(page)) { |
| | | this.name = name + "_" + page; |
| | | } |
| | | } else { |
| | | |
| | | } else if ("search".equals(templateType)){ |
| | | Object templateName = system.get("templateName"); |
| | | if (templateName != null) { |
| | | this.name = String.valueOf(templateName); |
| | | } else { |
| | | this.name = "search"; |
| | | } |
| | | } else if ("message".equals(templateType)) { |
| | | Object templateName = system.get("templateName"); |
| | | if (templateName != null) { |
| | | this.name = String.valueOf(templateName); |
| | | } else { |
| | | this.name = "message"; |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | sb.append(partNode.getHtml()); |
| | | } |
| | | document = Jsoup.parse(sb.toString()); |
| | | String outPath = path(outputPath); |
| | | String outPath = path(outputPath) + system.get("companyCode"); |
| | | |
| | | String html = document.html(); |
| | | try { |
| | |
| | | file.mkdirs(); |
| | | } |
| | | |
| | | FileOutputStream outputStream = new FileOutputStream(path +this.name + suffix); |
| | | FileOutputStream outputStream = new FileOutputStream(path + this.name + suffix); |
| | | outputStream.write(html.getBytes()); |
| | | outputStream.close(); |
| | | } catch (IOException e) { |
| | |
| | | |
| | | private String views; |
| | | |
| | | private String company; |
| | | |
| | | private String filePath; |
| | | |
| | | private List<String> images; |
| | | |
| | | private String url; |
| | | |
| | | private String description; |
| | | |
| | | private ArticleData next; |
| | | |
| | | private ArticleData prev; |
| | | |
| | | public String getCompany() { |
| | | return company; |
| | | } |
| | | |
| | | public void setCompany(String company) { |
| | | this.company = company; |
| | | } |
| | | |
| | | public ArticleData getNext() { |
| | | return next; |
| | | } |
| | | |
| | | public void setNext(ArticleData next) { |
| | | this.next = next; |
| | | } |
| | | |
| | | public ArticleData getPrev() { |
| | | return prev; |
| | | } |
| | | |
| | | public void setPrev(ArticleData prev) { |
| | | this.prev = prev; |
| | | } |
| | | |
| | | public String getFilePath() { |
| | | return filePath; |
| | |
| | | public void setViews(String views) { |
| | | this.views = views; |
| | | } |
| | | |
| | | public String getDescription() { |
| | | return description; |
| | | } |
| | | |
| | | public void setDescription(String description) { |
| | | this.description = description; |
| | | } |
| | | } |
| | |
| | | |
| | | private String field; |
| | | |
| | | /** |
| | | * hot-热点 |
| | | */ |
| | | private String type; |
| | | |
| | | public String getColId() { |
| | | return colId; |
| | | } |
| | |
| | | public void setField(String field) { |
| | | this.field = field; |
| | | } |
| | | |
| | | public String getType() { |
| | | return type; |
| | | } |
| | | |
| | | public void setType(String type) { |
| | | this.type = type; |
| | | } |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.core.tag.model; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-09 |
| | | **/ |
| | | public class TimeTag { |
| | | |
| | | private String date; |
| | | |
| | | private String format; |
| | | |
| | | public String getDate() { |
| | | return date; |
| | | } |
| | | |
| | | public void setDate(String date) { |
| | | this.date = date; |
| | | } |
| | | |
| | | public String getFormat() { |
| | | return format; |
| | | } |
| | | |
| | | public void setFormat(String format) { |
| | | this.format = format; |
| | | } |
| | | } |
| | |
| | | |
| | | public abstract class Configuration { |
| | | |
| | | protected static String BASE_URL; |
| | | protected static String API_URL; |
| | | protected static String STATIC_URL; |
| | | protected static String staticPath; |
| | | protected static String templatePath; |
| | |
| | | public Configuration() { |
| | | } |
| | | |
| | | public Configuration(String templatePath, String staticPath, String outputPath, String baseUrl, String staticUrl) { |
| | | public Configuration(String templatePath, String staticPath, String outputPath, String apiUrl, String staticUrl) { |
| | | Configuration.staticPath = staticPath; |
| | | Configuration.templatePath = templatePath; |
| | | Configuration.outputPath = outputPath; |
| | | Configuration.BASE_URL = baseUrl; |
| | | Configuration.API_URL = apiUrl; |
| | | Configuration.STATIC_URL = staticUrl; |
| | | } |
| | | |
| | |
| | | package com.xcong.farmer.cms.core.template; |
| | | |
| | | import com.xcong.farmer.cms.common.utils.FileUtils; |
| | | import com.xcong.farmer.cms.core.node.PartNode; |
| | | import com.xcong.farmer.cms.core.node.Template; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jsoup.nodes.Document; |
| | | |
| | | import java.io.File; |
| | |
| | | * @author wzy |
| | | * @date 2022-07-01 |
| | | **/ |
| | | @Slf4j |
| | | public class TemplateConfiguration extends Configuration{ |
| | | |
| | | private TemplateLoader templateLoader; |
| | |
| | | if (this.templateLoader == null) { |
| | | throw new RuntimeException("TemplateLoader do not able to be null"); |
| | | } |
| | | map.put("apiUrl", API_URL); |
| | | |
| | | String companyCode = (String) map.get("companyCode"); |
| | | |
| | | log.info("解析开始执行--#类型:{}#--#模板名称:{}#--#ID:{}#", map.get("templateType"), templateName, map.get("id")); |
| | | this.templateLoader.data(map); |
| | | Template template = template(templateName); |
| | | Template template = template(FileUtils.path(templatePath, companyCode), templateName); |
| | | template.output(outputPath); |
| | | |
| | | // 判断是否有分页,有则执行。从第二页开始 |
| | |
| | | while(Template.HAS_PAGING) { |
| | | map.put("page", i); |
| | | this.templateLoader.data(map); |
| | | Template pageTemplate = template(templateName); |
| | | Template pageTemplate = template(FileUtils.path(templatePath, companyCode), templateName); |
| | | pageTemplate.output(outputPath); |
| | | i++; |
| | | } |
| | | } |
| | | |
| | | public Template template(String templateName) { |
| | | public Template template(String templatePath, String templateName) { |
| | | return template(new File(path(templatePath) + templateName)); |
| | | } |
| | | |
| | |
| | | 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 com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | **/ |
| | | @Slf4j |
| | | @RestController |
| | | @RequestMapping(value = "/cms") |
| | | @RequestMapping(value = "/api") |
| | | @Api(value = "CmsCoreController", tags = "CMS核心类") |
| | | public class CmsCoreController { |
| | | |
| | |
| | | @ApiOperation(value = "发布文章", notes = "发布文章") |
| | | @PostMapping(value = "releaseArticle/{id}") |
| | | public Result releaseArticle(@PathVariable("id") Long id) { |
| | | releaseService.releaseArticle(id); |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | releaseService.releaseArticle(id, companyId); |
| | | return Result.ok("success"); |
| | | } |
| | | |
| | | @ApiOperation(value = "发布栏目", notes = "发布栏目") |
| | | @PostMapping(value = "releaseColumn/{type}/{id}") |
| | | public Result releaseColumn(@PathVariable("id") Long id, @PathVariable("type") Integer type) { |
| | | releaseService.releaseColumn(id, type); |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | releaseService.releaseColumn(id, type, companyId); |
| | | return Result.ok("success"); |
| | | } |
| | | |
| | | @ApiOperation(value = "发布首页", notes = "发布首页") |
| | | @PostMapping(value = "/releaseIndex") |
| | | public Result releaseIndex() { |
| | | releaseService.releaseIndex(); |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | releaseService.releaseIndex(companyId, true); |
| | | return Result.ok("success"); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | void indexProcess(Map<String, Object> map, String templateName); |
| | | |
| | | void process(Map<String, Object> map, String templateType, String templateName); |
| | | |
| | | } |
| | |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.xcong.farmer.cms.core.template.TemplateConfiguration; |
| | | import com.xcong.farmer.cms.modules.core.service.ICmsCoreService; |
| | | import com.xcong.farmer.cms.modules.system.mapper.WebSetMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | @Autowired |
| | | private TemplateConfiguration cfg; |
| | | |
| | | @Autowired |
| | | private WebSetMapper webSetMapper; |
| | | |
| | | |
| | | @Override |
| | | public void articleProcess(Map<String, Object> data, String templateName, String templatePath) { |
| | | data.put("templateType", "article"); |
| | | data.put("templatePath", templatePath); |
| | | data.put("templateName", data.get("id")); |
| | | globalData(data); |
| | | if (StrUtil.isEmpty(templateName)) { |
| | | templateName = "defualt.article.html"; |
| | | } |
| | | |
| | | cfg.process(data, templateName); |
| | | try { |
| | | cfg.process(data, templateName); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("发布文章出错", e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | public void columnProcess(Map<String, Object> data, String templateName) { |
| | | data.put("templateType", "column"); |
| | | data.put("page", 1); |
| | | globalData(data); |
| | | if (StrUtil.isEmpty(templateName)) { |
| | | templateName = "defualt.list.html"; |
| | | } |
| | | |
| | | cfg.process(data, templateName); |
| | | try { |
| | | cfg.process(data, templateName); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("发布栏目错误", e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void indexProcess(@NotNull Map<String, Object> data, String templateName) { |
| | | data.put("templateType", "index"); |
| | | globalData(data); |
| | | if (StrUtil.isEmpty(templateName)) { |
| | | templateName = "index.html"; |
| | | } |
| | | |
| | | cfg.process(data, templateName); |
| | | try { |
| | | cfg.process(data, templateName); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("发布首页错误", e); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void process(Map<String, Object> data, String templateType, String templateName) { |
| | | data.put("templateType", templateType); |
| | | globalData(data); |
| | | |
| | | if ("search".equals(templateType) && StrUtil.isBlank(templateName)) { |
| | | templateName = "search.html"; |
| | | } |
| | | |
| | | if ("message".equals(templateType) && StrUtil.isBlank(templateName)) { |
| | | templateName = "message.html"; |
| | | } |
| | | |
| | | try { |
| | | cfg.process(data, templateName); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("发布错误", e); |
| | | } |
| | | } |
| | | |
| | | private void globalData(Map<String, Object> data) { |
| | | Long companyId = (Long) data.get("companyId"); |
| | | Map<String, String> globalSetting = webSetMapper.selectSiteGlobalSetting(companyId); |
| | | |
| | | data.putAll(globalSetting); |
| | | } |
| | | } |
| | |
| | | import com.xcong.farmer.cms.modules.system.dto.*; |
| | | import com.xcong.farmer.cms.modules.system.service.IColumnService; |
| | | import com.xcong.farmer.cms.modules.system.service.IReleaseService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminColumnVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeColumnInfoVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.WebColumnVo; |
| | |
| | | @ApiOperation(value = "发布栏目", notes = "发布栏目") |
| | | @PostMapping(value = "/release") |
| | | public Result release(@RequestBody @Valid ReleaseColumnDto releaseColumnDto) { |
| | | releaseService.releaseColumn(releaseColumnDto.getId(), releaseColumnDto.getType()); |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | releaseService.releaseColumn(releaseColumnDto.getId(), releaseColumnDto.getType(), companyId); |
| | | return Result.ok("发布成功"); |
| | | } |
| | | |
| | |
| | | package com.xcong.farmer.cms.modules.system.controller; |
| | | |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminUpdateWebSetDto; |
| | | import com.xcong.farmer.cms.modules.system.service.IWebSetService; |
| | | import com.xcong.farmer.cms.modules.system.dto.SetWebSettingDto; |
| | | import com.xcong.farmer.cms.modules.system.service.IReleaseService; |
| | | import com.xcong.farmer.cms.modules.system.service.IWebSettingService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeWebSetInfoVo; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import io.swagger.annotations.ApiResponse; |
| | | import io.swagger.annotations.ApiResponses; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | public class AdminWebSetController { |
| | | |
| | | @Resource |
| | | private IWebSetService iWebSetService; |
| | | private IWebSettingService iWebSetService; |
| | | |
| | | @Resource |
| | | private IReleaseService releaseService; |
| | | |
| | | @ApiOperation(value = "查看网页设置", notes = "查看网页设置") |
| | | @ApiResponses({ |
| | | @ApiResponse(code = 200, message = "success", response = AdminSeeWebSetInfoVo.class) |
| | | }) |
| | | @GetMapping(value = "/seeWebSetInfo") |
| | | public Result seeWebSetInfo() { |
| | | return iWebSetService.seeWebSetInfo(); |
| | | return iWebSetService.getWebSetting(); |
| | | } |
| | | |
| | | @ApiOperation(value = "更新网页设置", notes = "更新网页设置") |
| | | @PostMapping(value = "/updateWebSet") |
| | | public Result updateWebSet(@RequestBody @Valid AdminUpdateWebSetDto adminUpdateWebSetDto) { |
| | | return iWebSetService.updateWebSet(adminUpdateWebSetDto); |
| | | public Result updateWebSet(@RequestBody @Valid SetWebSettingDto setWebSettingDto) { |
| | | return iWebSetService.setWebSetting(setWebSettingDto); |
| | | } |
| | | |
| | | @ApiOperation(value = "发布全站", notes = "发布全站") |
| | | @PostMapping(value = "/releaseAll") |
| | | public Result releaseAll() { |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | releaseService.releaseAll(companyId); |
| | | return Result.ok("发布成功"); |
| | | } |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.system.dto; |
| | | |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import javax.validation.constraints.NotBlank; |
| | | |
| | | @Data |
| | | @ApiModel(value = "AdminUpdateWebSetDto", description = "参数接收类") |
| | | public class SetWebSettingDto { |
| | | |
| | | @ApiModelProperty(value = "ID") |
| | | private Long id; |
| | | |
| | | @ApiModelProperty(value = "网页标题") |
| | | @NotBlank(message = "请输入网页标题") |
| | | private String title; |
| | | |
| | | @ApiModelProperty(value = "网页关键字") |
| | | private String seoTitle; |
| | | |
| | | @ApiModelProperty(value = "网页描述") |
| | | private String seoDescription; |
| | | |
| | | @ApiModelProperty(value = "网页描述") |
| | | private String seoKeyword; |
| | | |
| | | @ApiModelProperty(value = "网页LOGO") |
| | | private String logoUrl; |
| | | |
| | | @ApiModelProperty(value = "首页模板") |
| | | private String indexTemplate; |
| | | |
| | | @ApiModelProperty(value = "搜索模板") |
| | | private String searchTemplate; |
| | | |
| | | @ApiModelProperty(value = "在线留言模板") |
| | | private String msgTemplate; |
| | | } |
| | |
| | | //内容类型 1:文章 2:图片 3:文件 4:音频" |
| | | private Integer contentType; |
| | | |
| | | /** |
| | | * 更新前栏目编码 |
| | | */ |
| | | private Long beforeColumnId; |
| | | |
| | | @TableField(exist = false) |
| | | private String columnCode; |
| | | |
| | |
| | | @TableField(exist = false) |
| | | private String timeType; |
| | | |
| | | @TableField(exist = false) |
| | | private Integer releaseType; |
| | | |
| | | } |
| | |
| | | |
| | | @TableField(exist = false) |
| | | private List<Long> ids; |
| | | |
| | | /** |
| | | * 更新前栏目ID |
| | | */ |
| | | private Long beforeParentId; |
| | | |
| | | /** |
| | | * 更新前栏目编码 |
| | | */ |
| | | private String beforeColumnCode; |
| | | |
| | | /** |
| | | * 发布状态 1-已发布 2-未发布 |
| | | */ |
| | | private Integer releaseState; |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.system.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import lombok.Data; |
| | | |
| | | /** |
| | | * 网页配置表 |
| | | */ |
| | | @Data |
| | | @TableName("t_web_setting") |
| | | public class WebSettingEntity { |
| | | //ID |
| | | |
| | | @TableId(value = "id",type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | /** |
| | | * 网站标题 |
| | | */ |
| | | private String title; |
| | | |
| | | /** |
| | | * seo标题 |
| | | */ |
| | | private String seoTitle; |
| | | |
| | | /** |
| | | * seo关键词 |
| | | */ |
| | | private String seoKeyword; |
| | | |
| | | /** |
| | | * seo描述 |
| | | */ |
| | | private String seoDescription; |
| | | |
| | | /** |
| | | * logo地址 |
| | | */ |
| | | private String logoUrl; |
| | | |
| | | /** |
| | | * 首页模板 |
| | | */ |
| | | private String indexTemplate; |
| | | |
| | | /** |
| | | * 搜索模板 |
| | | */ |
| | | private String searchTemplate; |
| | | |
| | | /** |
| | | * 在线留言模板 |
| | | */ |
| | | private String msgTemplate; |
| | | |
| | | private Long companyId; |
| | | |
| | | @TableField(exist = false) |
| | | private String companyCode; |
| | | |
| | | @TableField(exist = false) |
| | | private String companyUrl; |
| | | } |
| | |
| | | IPage<WebArticleVo> selectWebArticleInPage(Page<WebArticleVo> page, @Param("record") ArticleEntity articleEntity); |
| | | |
| | | List<Long> selectArticleIdsByColumnId(@Param("columnId") Long columnId, @Param("companyId") Long companyId, @Param("type") Integer type); |
| | | |
| | | List<ArticleEntity> selectArticleByColumnId(@Param("columnId") Long columnId, @Param("companyId") Long companyId, @Param("type") Integer type); |
| | | } |
| | |
| | | |
| | | ColumnEntity selectByCodeAndCompanyId(@Param("code") String code, @Param("companyId") Long companyId); |
| | | |
| | | List<ColumnEntity> selectColumnByParentId(@Param("parentId") Long parentId, @Param("companyId") Long companyId); |
| | | List<ColumnEntity> selectColumnByParentId(@Param("parentId") Long parentId, @Param("companyId") Long companyId, @Param("isNav") Integer isNav); |
| | | |
| | | IPage<ColumnEntity> selectColumnInPage(Page<ColumnEntity> page, @Param("record") ColumnEntity column); |
| | | |
| | |
| | | package com.xcong.farmer.cms.modules.system.mapper; |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.xcong.farmer.cms.modules.system.entity.WebSetEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.WebSettingEntity; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | public interface WebSetMapper extends BaseMapper<WebSetEntity> { |
| | | import java.util.Map; |
| | | |
| | | public interface WebSetMapper extends BaseMapper<WebSettingEntity> { |
| | | |
| | | WebSettingEntity selectByCompanyId(@Param("companyId") Long companyId); |
| | | |
| | | Map<String, String> selectSiteGlobalSetting(@Param("companyId") Long companyId); |
| | | } |
| | |
| | | public interface IReleaseService { |
| | | |
| | | |
| | | void releaseArticle(Long id); |
| | | void releaseArticle(Long id, Long companyId); |
| | | |
| | | void releaseColumn(Long id, int type); |
| | | void releaseColumn(Long id, int type, Long companyId); |
| | | |
| | | void releaseIndex(); |
| | | void releaseColumns(int type, Long companyId); |
| | | |
| | | void releaseIndex(Long companyId, boolean hasSearch); |
| | | |
| | | void releaseAll(Long companyId); |
| | | |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.system.service; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.modules.system.dto.SetWebSettingDto; |
| | | import com.xcong.farmer.cms.modules.system.entity.WebSettingEntity; |
| | | |
| | | public interface IWebSettingService extends IService<WebSettingEntity> { |
| | | Result getWebSetting(); |
| | | |
| | | Result setWebSetting(SetWebSettingDto adminUpdateWebSetDto); |
| | | } |
| | |
| | | String atlas = adminAddArticleDto.getAtlas(); |
| | | articleEntity.setAtlas(atlas); |
| | | Date releaseTime = adminAddArticleDto.getReleaseTime(); |
| | | if (releaseTime == null) { |
| | | releaseTime = new Date(); |
| | | } |
| | | articleEntity.setReleaseTime(releaseTime); |
| | | Integer isTop = adminAddArticleDto.getIsTop(); |
| | | articleEntity.setIsTop(isTop); |
| | |
| | | if(ObjectUtil.isEmpty(columnEntity)){ |
| | | return Result.fail("请选择文章栏目"); |
| | | } |
| | | |
| | | if (!articleEntity.getColumnId().equals(columnId) && articleEntity.getBeforeColumnId() == -1) { |
| | | articleEntity.setBeforeColumnId(articleEntity.getColumnId()); |
| | | } |
| | | articleEntity.setColumnId(columnId); |
| | | |
| | | Integer visits = adminUpdateArticleDto.getVisits() == null ? 0 : adminUpdateArticleDto.getVisits(); |
| | | articleEntity.setVisits(visits); |
| | | String mainDiagram = adminUpdateArticleDto.getMainDiagram(); |
| | |
| | | articleEntity.setArticleUrl(adminUpdateArticleDto.getArticleUrl()); |
| | | articleEntity.setType(adminUpdateArticleDto.getType()); |
| | | articleEntity.setContentType(adminUpdateArticleDto.getContentType()); |
| | | |
| | | String authorBelong = adminUpdateArticleDto.getAuthorBelong(); |
| | | articleEntity.setAuthorBelong(authorBelong); |
| | | this.baseMapper.updateById(articleEntity); |
| | |
| | | } |
| | | articleEntity.setReleaseStatus(ArticleEntity.RELEASE_STATUS_NO); |
| | | this.baseMapper.updateById(articleEntity); |
| | | |
| | | releaseService.releaseColumn(articleEntity.getColumnId(), 2, articleEntity.getCompanyId()); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | public Result updateStatusOn(Long id) { |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | ArticleEntity articleEntity = this.baseMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(articleEntity)){ |
| | | return Result.fail("文章不存在"); |
| | |
| | | articleEntity.setReleaseStatus(ArticleEntity.RELEASE_STATUS_YES); |
| | | this.baseMapper.updateById(articleEntity); |
| | | |
| | | releaseService.releaseArticle(articleEntity.getId()); |
| | | releaseService.releaseArticle(articleEntity.getId(), companyId); |
| | | return Result.ok("操作成功"); |
| | | } |
| | | |
| | |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminSaveTemplateInfoDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.TemplateListDto; |
| | | import com.xcong.farmer.cms.modules.system.entity.CmsTemplateEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.CompanyEntity; |
| | | import com.xcong.farmer.cms.modules.system.mapper.CmsTemplateMapper; |
| | | import com.xcong.farmer.cms.modules.system.mapper.CompanyMapper; |
| | | import com.xcong.farmer.cms.modules.system.service.ICmsTemplateService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | | import org.jsoup.nodes.Element; |
| | | import org.jsoup.select.Elements; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.nio.file.Files; |
| | |
| | | @Autowired |
| | | private CmsProperties properties; |
| | | |
| | | @Autowired |
| | | private CompanyMapper companyMapper; |
| | | |
| | | |
| | | private List<String> fileSuffix = Arrays.asList(".zip", ".html"); |
| | | |
| | | @Override |
| | |
| | | String templatePath = properties.getTemplatePath(); |
| | | String staticPath = properties.getStaticPath(); |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | CompanyEntity company = companyMapper.selectById(companyId); |
| | | |
| | | String companyCode = company.getCode(); |
| | | templatePath = FileUtils.path(templatePath, companyCode); |
| | | staticPath = FileUtils.path(staticPath, companyCode); |
| | | |
| | | String filename = upload.getOriginalFilename(); |
| | | String suffix = filename.substring(filename.lastIndexOf(".")); |
| | |
| | | continue; |
| | | } |
| | | |
| | | Document parse = Jsoup.parse(templateFile, null); |
| | | String attr = parse.head().attr("name"); |
| | | CmsTemplateEntity cmsTemplate = new CmsTemplateEntity(); |
| | | cmsTemplate.setCompanyId(companyId); |
| | | if (name.endsWith(".list.html")) { |
| | | cmsTemplate.setType(2); |
| | | } else if (name.endsWith(".article.html")) { |
| | | cmsTemplate.setType(3); |
| | | } else { |
| | | cmsTemplate.setType(1); |
| | | } |
| | | cmsTemplate.setName(StrUtil.isNotBlank(attr) ? attr : templateFile.getName()); |
| | | cmsTemplate.setPath(templateFile.getName()); |
| | | |
| | | this.baseMapper.insert(cmsTemplate); |
| | | insertTemplate(templateFile, companyId, companyCode); |
| | | } |
| | | |
| | | } |
| | | |
| | | if (".html".equals(suffix)) { |
| | | FileUtil.touch(file); |
| | | |
| | | Document parse = Jsoup.parse(file, null); |
| | | String attr = parse.head().attr("name"); |
| | | CmsTemplateEntity cmsTemplate = new CmsTemplateEntity(); |
| | | cmsTemplate.setCompanyId(companyId); |
| | | if (file.getName().endsWith(".list.html")) { |
| | | cmsTemplate.setType(2); |
| | | } else if (file.getName().endsWith(".article.html")) { |
| | | cmsTemplate.setType(3); |
| | | } else { |
| | | cmsTemplate.setType(1); |
| | | } |
| | | cmsTemplate.setName(StrUtil.isNotBlank(attr) ? attr : file.getName()); |
| | | cmsTemplate.setPath(file.getName()); |
| | | |
| | | this.baseMapper.insert(cmsTemplate); |
| | | insertTemplate(file, companyId, companyCode); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | throw new GlobalException("模板上传失败"); |
| | | } |
| | | } |
| | | |
| | | private void insertTemplate(File file, Long companyId, String companyCode) throws IOException { |
| | | Document parse = Jsoup.parse(file, null); |
| | | String attr = parse.head().attr("name"); |
| | | |
| | | staticPathParser(parse, "img", "src", companyCode); |
| | | staticPathParser(parse, "link", "href", companyCode); |
| | | staticPathParser(parse, "script", "src", companyCode); |
| | | |
| | | FileOutputStream outputStream = new FileOutputStream(file); |
| | | outputStream.write(parse.html().getBytes()); |
| | | outputStream.close(); |
| | | |
| | | CmsTemplateEntity cmsTemplate = new CmsTemplateEntity(); |
| | | cmsTemplate.setCompanyId(companyId); |
| | | if (file.getName().endsWith(".list.html")) { |
| | | cmsTemplate.setType(2); |
| | | } else if (file.getName().endsWith(".article.html")) { |
| | | cmsTemplate.setType(3); |
| | | } else { |
| | | cmsTemplate.setType(1); |
| | | } |
| | | cmsTemplate.setName(StrUtil.isNotBlank(attr) ? attr : file.getName()); |
| | | cmsTemplate.setPath(file.getName()); |
| | | |
| | | this.baseMapper.insert(cmsTemplate); |
| | | } |
| | | |
| | | private void staticPathParser(Document document, String tagName, String attrKey, String companyCode) { |
| | | Elements elements = document.getElementsByTag(tagName); |
| | | if (elements.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | for (Element element : elements) { |
| | | String attr = element.attr(attrKey); |
| | | if (StrUtil.isNotBlank(attr) && !attr.contains("http://") && !attr.contains("https://")) { |
| | | element.attr(attrKey, cmsProperties.getStaticUrl() + companyCode + "/" + attr); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | @Override |
| | | public Result viewTemplateInfo(Long id) { |
| | | Result result = new Result(); |
| | | |
| | | CompanyEntity companyEntity = companyMapper.selectById(LoginUserUtil.getCompanyId()); |
| | | CmsTemplateEntity cmsTemplateEntity = this.baseMapper.selectById(id); |
| | | String templatePath = cmsProperties.getTemplatePath(); |
| | | String templatePath = FileUtils.path(cmsProperties.getTemplatePath(), companyEntity.getCode()); |
| | | String pathName = FileUtils.path(templatePath, cmsTemplateEntity.getPath()); |
| | | |
| | | byte[] bytes = new byte[0]; |
| | |
| | | adminSeeColumnInfoVo.setType(columnEntity.getType()); |
| | | adminSeeColumnInfoVo.setTargetType(columnEntity.getTargetType()); |
| | | adminSeeColumnInfoVo.setContentType(columnEntity.getContentType()); |
| | | |
| | | CompanyEntity companyEntity = companyMapper.selectById(LoginUserUtil.getCompanyId()); |
| | | |
| | | if (columnEntity.getType() == 2) { |
| | | if (columnEntity.getTargetType() == 1) { |
| | | ArticleEntity articleEntity = articleMapper.selectById(Long.parseLong(columnEntity.getTargetUrl())); |
| | | adminSeeColumnInfoVo.setTargetName(articleEntity.getTitle()); |
| | | adminSeeColumnInfoVo.setUrl(companyEntity.getWebAddress() + columnEntity.getPath() + "/" + columnEntity.getTargetUrl() + ".html"); |
| | | } else if (columnEntity.getTargetType() == 2) { |
| | | ColumnEntity column = this.baseMapper.selectByCodeAndCompanyId(columnEntity.getTargetUrl(), LoginUserUtil.getCompanyId()); |
| | | adminSeeColumnInfoVo.setTargetName(column.getColumnName()); |
| | | adminSeeColumnInfoVo.setUrl(companyEntity.getWebAddress() + column.getPath()); |
| | | } |
| | | } else { |
| | | adminSeeColumnInfoVo.setUrl(companyEntity.getWebAddress() + columnEntity.getPath()); |
| | | } |
| | | adminSeeColumnInfoVo.setTargetUrl(columnEntity.getTargetUrl()); |
| | | return Result.ok(adminSeeColumnInfoVo); |
| | |
| | | if(CollUtil.isNotEmpty(columnEntities) && columnEntities.size() > 1){ |
| | | return Result.fail("栏目编码不能重复"); |
| | | } |
| | | |
| | | // 判断是否编辑了栏目编码且此时栏目处于已发布的状态,然后保存之前的编码。因为如果是未发布状态,多次保存的话,容易覆盖真正的最开始的栏目编码 |
| | | if (!columnEntity.getColumnCode().equals(columnCode) && columnEntity.getReleaseState() == 1) { |
| | | columnEntity.setBeforeColumnCode(columnCode); |
| | | } |
| | | columnEntity.setColumnCode(columnCode); |
| | | |
| | | String remark = adminUpdateColumnDto.getRemark(); |
| | | columnEntity.setRemark(remark); |
| | | String pic = adminUpdateColumnDto.getPic(); |
| | |
| | | columnEntity.setOrderNum(orderNum); |
| | | } |
| | | Long parentId = adminUpdateColumnDto.getParentId(); |
| | | // 同栏目编码 |
| | | if (!columnEntity.getParentId().equals(parentId) && columnEntity.getReleaseState() == 1) { |
| | | columnEntity.setBeforeParentId(columnEntity.getParentId()); |
| | | } |
| | | |
| | | if(ObjectUtil.isEmpty(parentId)){ |
| | | columnEntity.setParentId(ColumnEntity.PARENTID_DEFAULT); |
| | | columnEntity.setPath("/" + columnEntity.getColumnCode()); |
| | |
| | | columnEntity.setTargetUrl(adminUpdateColumnDto.getTargetUrl()); |
| | | columnEntity.setIsNav(adminUpdateColumnDto.getIsNav()); |
| | | columnEntity.setContentType(adminUpdateColumnDto.getContentType()); |
| | | columnEntity.setReleaseState(2); |
| | | this.baseMapper.updateById(columnEntity); |
| | | return Result.ok("更新成功"); |
| | | } |
| | |
| | | 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.entity.WebSettingEntity; |
| | | 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.mapper.CompanyMapper; |
| | | import com.xcong.farmer.cms.modules.system.mapper.WebSetMapper; |
| | | import com.xcong.farmer.cms.modules.system.service.IReleaseService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Hashtable; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.Executor; |
| | |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @TODO 发布时,index存在重复发布的情况,可优化。用线程notify唤醒。 |
| | | * @date 2022-07-05 |
| | | **/ |
| | | @Slf4j |
| | |
| | | @Autowired |
| | | private ICmsCoreService cmsCoreService; |
| | | |
| | | private final Executor executor = new ThreadPoolExecutor(5, 10, 600, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); |
| | | @Autowired |
| | | private WebSetMapper webSetMapper; |
| | | |
| | | private final Executor executor = new ThreadPoolExecutor(5, 20, 600, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()); |
| | | |
| | | @Override |
| | | public void releaseArticle(Long id) { |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | public void releaseArticle(Long id, Long companyId) { |
| | | ArticleEntity article = articleMapper.selectById(id); |
| | | ColumnEntity column = columnMapper.selectById(article.getColumnId()); |
| | | |
| | | Map<String, Object> data = new HashMap<>(); |
| | | Long beforeColumnId = article.getBeforeColumnId(); |
| | | article.setBeforeColumnId(-1L); |
| | | articleMapper.updateById(article); |
| | | |
| | | Map<String, Object> data = new Hashtable<>(); |
| | | data.put("id", article.getId()); |
| | | data.put("companyId", companyId); |
| | | |
| | | executor.execute(()->{ |
| | | executor.execute(() -> { |
| | | log.info("执行文章发布"); |
| | | cmsCoreService.articleProcess(data, column.getArticleTemplate(), column.getPath()); |
| | | this.releaseColumn(column.getId(), 1); |
| | | this.releaseColumn(column.getId(), 1, companyId); |
| | | if (column.getParentId() != 0L) { |
| | | releaseColumn(column.getParentId(), 1); |
| | | releaseColumn(column.getParentId(), 1, companyId); |
| | | } |
| | | this.releaseIndex(); |
| | | |
| | | if (beforeColumnId != null && !article.getColumnId().equals(beforeColumnId)) { |
| | | ColumnEntity beforeColumn = columnMapper.selectById(beforeColumnId); |
| | | this.releaseColumn(beforeColumnId, 1, companyId); |
| | | if (beforeColumn.getParentId() != 0L) { |
| | | this.releaseColumn(beforeColumn.getParentId(), 1, companyId); |
| | | } |
| | | } |
| | | |
| | | this.releaseIndex(companyId, false); |
| | | }); |
| | | } |
| | | |
| | | @Override |
| | | public void releaseColumn(Long id, int type) { |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | public void releaseColumn(Long id, int type, Long companyId) { |
| | | ColumnEntity columnEntity = columnMapper.selectById(id); |
| | | Map<String, Object> map = new HashMap<>(); |
| | | Map<String, Object> map = buildColumnData(columnEntity); |
| | | |
| | | executor.execute(() -> { |
| | | List<ArticleEntity> articles = articleMapper.selectArticleByColumnId(columnEntity.getId(), companyId, type); |
| | | if (CollUtil.isNotEmpty(articles)) { |
| | | for (ArticleEntity article : articles) { |
| | | if (article.getReleaseStatus() == 0) { |
| | | article.setReleaseStatus(1); |
| | | articleMapper.updateById(article); |
| | | } |
| | | |
| | | if (article.getType() == 1) { |
| | | map.put("id", article.getId()); |
| | | cmsCoreService.articleProcess(map, columnEntity.getArticleTemplate(), columnEntity.getPath()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | map.put("id", columnEntity.getId()); |
| | | cmsCoreService.columnProcess(map, columnEntity.getListTemplate()); |
| | | if (columnEntity.getParentId() != 0L) { |
| | | ColumnEntity parentColumn = columnMapper.selectById(columnEntity.getParentId()); |
| | | Map<String, Object> parentMap = buildColumnData(parentColumn); |
| | | parentMap.put("id", parentColumn.getId()); |
| | | cmsCoreService.columnProcess(parentMap, parentColumn.getListTemplate()); |
| | | } |
| | | |
| | | releaseIndex(companyId, false); |
| | | }); |
| | | |
| | | if (type != 1) { |
| | | executor.execute(() -> { |
| | | if (columnEntity.getParentId() == 0L) { |
| | | List<ColumnEntity> columns = columnMapper.selectColumnByParentId(columnEntity.getId(), companyId, 2); |
| | | if (CollUtil.isNotEmpty(columns)) { |
| | | for (ColumnEntity column : columns) { |
| | | List<ArticleEntity> articles = articleMapper.selectArticleByColumnId(column.getId(), companyId, type); |
| | | if (CollUtil.isNotEmpty(articles)) { |
| | | for (ArticleEntity article : articles) { |
| | | if (article.getReleaseStatus() == 0) { |
| | | article.setReleaseStatus(1); |
| | | articleMapper.updateById(article); |
| | | } |
| | | |
| | | if (article.getType() == 1) { |
| | | map.put("id", article.getId()); |
| | | cmsCoreService.articleProcess(map, column.getArticleTemplate(), column.getPath()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Map<String, Object> data = buildColumnData(column); |
| | | cmsCoreService.columnProcess(data, column.getListTemplate()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | releaseIndex(companyId, false); |
| | | }); |
| | | |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void releaseColumns(int type, Long companyId) { |
| | | List<ColumnEntity> columns = columnMapper.selectColumnByParentId(0L, companyId, 2); |
| | | |
| | | if (CollUtil.isEmpty(columns)) { |
| | | return; |
| | | } |
| | | |
| | | for (ColumnEntity column : columns) { |
| | | releaseColumn(column.getId(), type, companyId); |
| | | } |
| | | } |
| | | |
| | | private Map<String, Object> buildColumnData(ColumnEntity columnEntity) { |
| | | Map<String, Object> map = new Hashtable<>(); |
| | | map.put("id", columnEntity.getId()); |
| | | map.put("code", columnEntity.getColumnCode()); |
| | | if (columnEntity.getParentId() == 0L) { |
| | |
| | | ColumnEntity parent = columnMapper.selectById(columnEntity.getParentId()); |
| | | map.put("parentCode", parent.getColumnCode()); |
| | | } |
| | | map.put("columnTitle", columnEntity.getColumnName()); |
| | | map.put("templatePath", columnEntity.getPath()); |
| | | map.put("companyId", columnEntity.getCompanyId()); |
| | | return map; |
| | | } |
| | | |
| | | @Override |
| | | public void releaseIndex(Long companyId, boolean hasSearch) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("companyId", companyId); |
| | | |
| | | if (type != 1) { |
| | | WebSettingEntity webSetting = webSetMapper.selectByCompanyId(companyId); |
| | | |
| | | cmsCoreService.indexProcess(map, webSetting.getIndexTemplate()); |
| | | if (hasSearch) { |
| | | executor.execute(() -> { |
| | | if (columnEntity.getParentId() == 0L) { |
| | | List<ColumnEntity> columns = columnMapper.selectColumnByParentId(columnEntity.getParentId(), companyId); |
| | | if (CollUtil.isNotEmpty(columns)) { |
| | | for (ColumnEntity column : columns) { |
| | | map.put("id", column.getId()); |
| | | cmsCoreService.columnProcess(map, column.getListTemplate()); |
| | | |
| | | List<Long> ids = articleMapper.selectArticleIdsByColumnId(column.getId(), companyId,type); |
| | | cmsCoreService.articlesProcess(map, ids, column.getArticleTemplate(), column.getPath()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | List<Long> ids = articleMapper.selectArticleIdsByColumnId(columnEntity.getId(), companyId, type); |
| | | cmsCoreService.articlesProcess(map, ids, columnEntity.getArticleTemplate(), columnEntity.getPath()); |
| | | |
| | | releaseIndex(); |
| | | }); |
| | | |
| | | executor.execute(() -> { |
| | | cmsCoreService.columnProcess(map, columnEntity.getListTemplate()); |
| | | releaseIndex(); |
| | | cmsCoreService.process(map, "search", webSetting.getSearchTemplate()); |
| | | cmsCoreService.process(map, "message", webSetting.getMsgTemplate()); |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void releaseIndex() { |
| | | public void releaseAll(Long companyId) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | map.put("companyId", companyId); |
| | | |
| | | cmsCoreService.indexProcess(map, null); |
| | | releaseColumns(4, companyId); |
| | | releaseIndex(companyId, true); |
| | | } |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.modules.system.service.Impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.conversion.WebSettingConversion; |
| | | import com.xcong.farmer.cms.modules.system.dto.SetWebSettingDto; |
| | | import com.xcong.farmer.cms.modules.system.entity.UserEntity; |
| | | import com.xcong.farmer.cms.modules.system.entity.WebSettingEntity; |
| | | import com.xcong.farmer.cms.modules.system.mapper.WebSetMapper; |
| | | import com.xcong.farmer.cms.modules.system.service.IWebSettingService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeWebSetInfoVo; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | @Service |
| | | @Slf4j |
| | | public class WebSettingServiceImpl extends ServiceImpl<WebSetMapper, WebSettingEntity> implements IWebSettingService { |
| | | @Override |
| | | public Result getWebSetting() { |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | WebSettingEntity webSetting = this.baseMapper.selectByCompanyId(companyId); |
| | | if (webSetting == null) { |
| | | webSetting = new WebSettingEntity(); |
| | | } |
| | | |
| | | AdminSeeWebSetInfoVo adminSeeWebSetInfoVo = WebSettingConversion.INSTANCE.entityToVo(webSetting); |
| | | return Result.ok(adminSeeWebSetInfoVo); |
| | | } |
| | | |
| | | @Override |
| | | public Result setWebSetting(SetWebSettingDto setWebSettingDto) { |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | |
| | | WebSettingEntity webSetting = WebSettingConversion.INSTANCE.dtoToEntity(setWebSettingDto); |
| | | webSetting.setCompanyId(companyId); |
| | | if (setWebSettingDto.getId() == null) { |
| | | WebSettingEntity hasExist = this.baseMapper.selectByCompanyId(companyId); |
| | | if (hasExist != null) { |
| | | webSetting.setId(hasExist.getId()); |
| | | this.baseMapper.updateById(webSetting); |
| | | } else { |
| | | this.baseMapper.insert(webSetting); |
| | | } |
| | | } else { |
| | | this.baseMapper.updateById(webSetting); |
| | | } |
| | | return Result.ok("保存成功"); |
| | | } |
| | | } |
| | |
| | | @ApiModelProperty(value = "内容类型 1:文章 2:图片 3:文件 4:音频") |
| | | private Integer contentType; |
| | | |
| | | @ApiModelProperty(value = "栏目地址") |
| | | private String url; |
| | | |
| | | } |
| | |
| | | package com.xcong.farmer.cms.modules.system.vo; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | |
| | | private Long id; |
| | | |
| | | @ApiModelProperty(value = "网页标题") |
| | | private String webTitle; |
| | | private String title; |
| | | |
| | | @ApiModelProperty(value = "网页关键字") |
| | | private String webKeyword; |
| | | @ApiModelProperty(value = "seo关键字") |
| | | private String seoKeyword; |
| | | |
| | | @ApiModelProperty(value = "网页描述") |
| | | private String webRemark; |
| | | @ApiModelProperty(value = "seo描述") |
| | | private String seoRemark; |
| | | |
| | | @ApiModelProperty(value = "seo描述") |
| | | private String seoDescription; |
| | | |
| | | @ApiModelProperty(value = "网页LOGO") |
| | | private String webPic; |
| | | private String logoUrl; |
| | | |
| | | @ApiModelProperty(value = "首页模板") |
| | | private String indexTemplate; |
| | | |
| | | @ApiModelProperty(value = "搜索模板") |
| | | private String searchTemplate; |
| | | |
| | | @ApiModelProperty(value = "在线留言模板") |
| | | private String msgTemplate; |
| | | |
| | | @ApiModelProperty(value = "公司编码") |
| | | private String companyCode; |
| | | |
| | | @ApiModelProperty(value = "公司URL") |
| | | private String companyUrl; |
| | | } |
New file |
| | |
| | | package com.xcong.farmer.cms.utils; |
| | | |
| | | import groovy.lang.Binding; |
| | | import groovy.lang.GroovyShell; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-08 |
| | | **/ |
| | | public class GroovySingleton { |
| | | private volatile static GroovyShell groovyShell; |
| | | |
| | | private GroovySingleton (){} |
| | | |
| | | public static GroovyShell getSingleton() { |
| | | if (groovyShell == null) { |
| | | synchronized (GroovySingleton.class) { |
| | | if (groovyShell == null) { |
| | | Binding binding = new Binding(); |
| | | groovyShell = new GroovyShell(binding); |
| | | } |
| | | } |
| | | } |
| | | return groovyShell; |
| | | } |
| | | |
| | | } |
| | |
| | | path: /home/javaweb/webresource/uploadeFile/image/ |
| | | |
| | | cms: |
| | | base-url: http://120.27.238.55:8000/cms/output |
| | | api-url: http://120.27.238.55:8878 |
| | | static-url: http://120.27.238.55:8000/cms/static/ |
| | | template-path: /home/javaweb/webresource/cms/template |
| | | static-path: /home/javaweb/webresource/cms/static |
| | |
| | | max-request-size: 100MB |
| | | mybatis-plus: |
| | | mapper-locations: classpath:mapper/*.xml |
| | | # configuration: |
| | | # log-impl: org.apache.ibatis.logging.stdout.StdOutImpl |
| | | |
| | | |
| | | app: |
| | |
| | | path: /image/ |
| | | |
| | | cms: |
| | | base-url: http://localhost |
| | | static-url: http://localhost/ |
| | | template-path: /Users/helius/Desktop/template |
| | | static-path: /Users/helius/Desktop/static |
| | | output-path: /Users/helius/Desktop/web/output |
| | | api-url: http://120.27.238.55:8878 |
| | | static-url: http://120.27.238.55:8000/cms/static/ |
| | | template-path: /Users/helius/Desktop/template-online/template |
| | | static-path: /Users/helius/Desktop/template-online/static |
| | | output-path: /Users/helius/Desktop/template-online/output |
| | | |
| | |
| | | <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} |
| | | where (a.column_id=b.id or a.column_id=b.parent_id) and a.column_id=#{columnId} and release_status=1 |
| | | and del_status = 1 |
| | | <!--上一篇--> |
| | | <if test="type == 1"> |
| | | order by a.id |
| | | and #{id} > a.id |
| | | order by a.id desc |
| | | </if> |
| | | <!--下一篇--> |
| | | <if test="type == 2"> |
| | | order by a.id desc |
| | | and a.id > #{id} |
| | | order by a.id |
| | | </if> |
| | | limit 1 |
| | | </select> |
| | |
| | | inner join t_column b on a.column_id=b.id |
| | | inner join t_column c on b.parent_id=c.id or c.id=b.id |
| | | <where> |
| | | a.company_id=#{record.companyId} and a.del_status = 1 |
| | | a.company_id=#{record.companyId} and a.del_status = 1 and release_status = 1 |
| | | <if test="record.columnCode != null and record.columnCode != ''"> |
| | | and c.column_code=#{record.columnCode} |
| | | </if> |
| | |
| | | ${item} |
| | | </foreach> |
| | | </if> |
| | | <if test="record.isTop != null and record.isTop != ''"> |
| | | and a.is_top=#{record.isTop} |
| | | </if> |
| | | </where> |
| | | order by release_time desc |
| | | </select> |
| | | |
| | | <select id="selectWebArticleInPage" resultType="com.xcong.farmer.cms.modules.system.vo.WebArticleVo"> |
| | |
| | | </select> |
| | | |
| | | <select id="selectArticleIdsByColumnId" resultType="java.lang.Long"> |
| | | select a.id from t_article a |
| | | where a.column_id=#{columnId} and a.company_id=#{companyId} and a.del_status = 1 |
| | | <if test="type != 4"> |
| | | <if test="type == 2"> |
| | | and release_status=1 |
| | | </if> |
| | | <if test="type == 3"> |
| | | and release_status=0 |
| | | </if> |
| | | </if> |
| | | </select> |
| | | |
| | | <select id="selectArticleByColumnId" resultType="com.xcong.farmer.cms.modules.system.entity.ArticleEntity"> |
| | | select * from t_article a |
| | | where a.column_id=#{columnId} and a.company_id=#{companyId} |
| | | where a.column_id=#{columnId} and a.company_id=#{companyId} and a.del_status = 1 |
| | | <if test="type != 4"> |
| | | <if test="type == 2"> |
| | | and release_status=1 |
| | |
| | | <select id="selectColumnByParentId" resultType="com.xcong.farmer.cms.modules.system.entity.ColumnEntity"> |
| | | select * from t_column |
| | | where parent_id=#{parentId} and company_id=#{companyId} |
| | | <if test="isNav == 1"> |
| | | and is_nav=1 |
| | | </if> |
| | | </select> |
| | | |
| | | <select id="selectColumnInPage" resultType="com.xcong.farmer.cms.modules.system.entity.ColumnEntity"> |
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.WebSetMapper"> |
| | | |
| | | <select id="selectByCompanyId" resultType="com.xcong.farmer.cms.modules.system.entity.WebSettingEntity"> |
| | | select |
| | | a.*, |
| | | b.web_address companyUrl, |
| | | b.code companyCode |
| | | from t_web_setting a, t_company b |
| | | where a.company_id=#{companyId} and a.company_id=b.id |
| | | </select> |
| | | |
| | | <select id="selectSiteGlobalSetting" resultType="java.util.Map"> |
| | | select |
| | | a.title title, |
| | | a.seo_title seoTitle, |
| | | a.seo_keyword seoKeyword, |
| | | a.seo_description seoDescription, |
| | | a.logo_url logo, |
| | | b.web_address baseUrl, |
| | | b.code companyCode |
| | | from t_web_setting a, t_company b |
| | | where a.company_id=#{companyId} and a.company_id=b.id |
| | | </select> |
| | | |
| | | </mapper> |
New file |
| | |
| | | package com.xcong.farmer.cms; |
| | | |
| | | import com.xcong.farmer.cms.modules.system.entity.ArticleEntity; |
| | | import com.xcong.farmer.cms.modules.system.mapper.ArticleMapper; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-11 |
| | | **/ |
| | | @SpringBootTest |
| | | public class ArticleTest { |
| | | |
| | | @Autowired |
| | | private ArticleMapper articleMapper; |
| | | |
| | | @Test |
| | | public void articleColumnIdUpdateTest() { |
| | | Long columnId = 83L; |
| | | ArticleEntity article = articleMapper.selectById(88L); |
| | | |
| | | article.setBeforeColumnId(-1L); |
| | | articleMapper.updateById(article); |
| | | } |
| | | |
| | | } |
| | |
| | | public void viewTemplateInfo() { |
| | | Long id = 4L; |
| | | CmsTemplateEntity cmsTemplateEntity = cmsTemplateMapper.selectById(id); |
| | | String htmlUrl = cmsProperties.getBaseUrl() + cmsProperties.getTemplatePath(); |
| | | String htmlUrl = "" + cmsProperties.getTemplatePath(); |
| | | File uploadDir = new File(htmlUrl); |
| | | if (!uploadDir.isDirectory()) { |
| | | uploadDir.mkdir(); |
New file |
| | |
| | | package com.xcong.farmer.cms; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import org.jsoup.Jsoup; |
| | | import org.jsoup.nodes.Document; |
| | | import org.jsoup.nodes.Element; |
| | | import org.jsoup.select.Elements; |
| | | import org.junit.jupiter.api.Test; |
| | | import org.springframework.boot.test.context.SpringBootTest; |
| | | |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | |
| | | /** |
| | | * @author wzy |
| | | * @date 2022-07-09 |
| | | **/ |
| | | @SpringBootTest |
| | | public class TemplateTest { |
| | | |
| | | String baseUrl = "http://120.27.238.55:8000/cms/static/"; |
| | | |
| | | @Test |
| | | public void staticFileTest() throws IOException { |
| | | File file = new File("/Users/helius/Desktop/template-online/index-test.html"); |
| | | Document parse = Jsoup.parse(file, "utf-8"); |
| | | |
| | | staticPathParser(parse, "img", "src"); |
| | | staticPathParser(parse, "href", "link"); |
| | | staticPathParser(parse, "script", "src"); |
| | | |
| | | FileOutputStream outputStream = new FileOutputStream(file); |
| | | outputStream.write(parse.html().getBytes()); |
| | | outputStream.close(); |
| | | } |
| | | |
| | | public void staticPathParser(Document document, String tagName, String attrKey) { |
| | | Elements elements = document.getElementsByTag(tagName); |
| | | if (elements.isEmpty()) { |
| | | return; |
| | | } |
| | | |
| | | for (Element element : elements) { |
| | | String attr = element.attr(attrKey); |
| | | if (StrUtil.isNotBlank(attr) && !attr.contains("http://") && !attr.contains("https://")) { |
| | | element.attr(attrKey, baseUrl + attr); |
| | | } |
| | | } |
| | | } |
| | | } |