移除后台首页错误引用标签,访问统计接口添加host和path参数,全站发布优化

This commit is contained in:
liweiyi 2024-03-28 10:11:36 +08:00
parent 0e19d56afd
commit b8b9ab9b63
5 changed files with 55 additions and 74 deletions

View File

@ -15,103 +15,102 @@
*/
package com.chestnut.contentcore.service;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import com.chestnut.contentcore.domain.CmsSite;
import com.chestnut.contentcore.domain.CmsTemplate;
import com.chestnut.contentcore.domain.dto.TemplateAddDTO;
import com.chestnut.contentcore.domain.dto.TemplateRenameDTO;
import com.chestnut.contentcore.domain.dto.TemplateUpdateDTO;
import com.chestnut.contentcore.template.ITemplateType;
import java.io.File;
import java.io.IOException;
import java.util.List;
public interface ITemplateService extends IService<CmsTemplate> {
void clearTemplateStaticContentCache(String templateId);
/**
* 清理站点指定模板静态化缓存
*
* @param templateKey 唯一标识相对resourceRoot路径
*/
void clearTemplateStaticContentCache(String templateKey);
/**
* 清理站点所有模板静态化缓存
*
* @param site 站点信息
*/
void clearSiteAllTemplateStaticContentCache(CmsSite site);
/**
* 获取模板类型
*
* @param typeid
* @return
* @param typeid 模板类型唯一标识
*/
ITemplateType getTemplateType(String typeid);
/**
* 获取模板静态化内容缓存主要区块模板使用
*
* @param templateId
* @return
* @param templateKey 相对resourceRoot路径
*/
String getTemplateStaticContentCache(String templateId);
String getTemplateStaticContentCache(String templateKey);
/**
* 缓存模板静态化内容
*
* @param templateId 相对resourceRoot路径
* @param staticContent
* @param templateKey 相对resourceRoot路径
*/
void setTemplateStaticContentCache(String templateId, String staticContent);
void setTemplateStaticContentCache(String templateKey, String staticContent);
/**
* 扫描模板目录创建模板数据库记录
*
* @param site
* @param site 站点数据
*/
void scanTemplates(CmsSite site);
/**
* 保存模板内容
*
* @throws IOException
*/
void saveTemplate(CmsTemplate template, TemplateUpdateDTO dto) throws IOException;
/**
* 模板文件重命名
*
* @param template
* @param path
* @param remark
* @param operator
* @throws IOException
* @param template 模板信息
* @param path 路径
* @param remark 备注
* @param operator 操作人
*/
void renameTemplate(CmsTemplate template, String path, String remark, String operator) throws IOException;
/**
* 获取模板文件
*
* @param template
* @return
* @param template 模板信息
*/
File getTemplateFile(CmsTemplate template);
/**
* 查找模板文件
*
* @param site
* @param templatePath
* @param publishPipeCode
* @return
* @throws FileNotFoundException
* @param site 站点信息
* @param templatePath 模板路径
* @param publishPipeCode 发布通道编码
*/
File findTemplateFile(CmsSite site, String templatePath, String publishPipeCode);
/**
* 新建模板文件
*
* @param dto
* @throws IOException
* @param dto 模板数据
*/
void addTemplate(TemplateAddDTO dto) throws IOException;
/**
* 删除模板
* @param templateIds
* @throws IOException
* @param templateIds 模板ID列表
*/
void deleteTemplates(CmsSite site, List<Long> templateIds) throws IOException;
}

View File

@ -48,7 +48,6 @@ import com.chestnut.contentcore.util.*;
import com.chestnut.system.fixed.dict.YesOrNo;
import freemarker.template.TemplateException;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -130,15 +129,8 @@ public class PublishServiceImpl implements IPublishService, ApplicationContextAw
@Override
public void run0() throws InterruptedException {
List<CmsPublishPipe> publishPipes = publishPipeService.getPublishPipes(site.getSiteId());
publishPipes.forEach(pp -> {
try {
String siteRoot = SiteUtils.getSiteRoot(site, pp.getCode());
FileUtils.deleteDirectory(new File(siteRoot + "include/"));
} catch (IOException e) {
logger.error("Delete site publish pipe include directory failed: {}", pp.getCode(), e);
}
});
// 发布全站先清理所有模板缓存
templateService.clearSiteAllTemplateStaticContentCache(site);
List<CmsCatalog> catalogList = catalogService
.list(new LambdaQueryWrapper<CmsCatalog>().eq(CmsCatalog::getSiteId, site.getSiteId()));

View File

@ -17,7 +17,6 @@ package com.chestnut.contentcore.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chestnut.common.redis.RedisCache;
import com.chestnut.common.utils.Assert;
import com.chestnut.common.utils.IdUtils;
import com.chestnut.common.utils.StringUtils;
import com.chestnut.common.utils.file.FileExUtils;
@ -44,8 +43,6 @@ import org.springframework.stereotype.Service;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@ -67,19 +64,28 @@ public class TemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTempl
private final ISiteService siteService;
@Override
public String getTemplateStaticContentCache(String templateId) {
return this.redisCache.getCacheObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateId);
public String getTemplateStaticContentCache(String templateKey) {
return this.redisCache.getCacheObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateKey);
}
@Override
public void setTemplateStaticContentCache(String templateId, String staticContent) {
this.redisCache.setCacheObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateId, staticContent, 24,
public void setTemplateStaticContentCache(String templateKey, String staticContent) {
this.redisCache.setCacheObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateKey, staticContent, 24,
TimeUnit.HOURS);
}
@Override
public void clearTemplateStaticContentCache(String templateId) {
this.redisCache.deleteObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateId);
public void clearTemplateStaticContentCache(String templateKey) {
this.redisCache.deleteObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateKey);
}
@Override
public void clearSiteAllTemplateStaticContentCache(CmsSite site) {
List<CmsTemplate> dbTemplates = this.lambdaQuery().eq(CmsTemplate::getSiteId, site.getSiteId()).list();
dbTemplates.forEach(template -> {
String templateKey = SiteUtils.getTemplateKey(site, template.getPublishPipeCode(), template.getPath());
clearTemplateStaticContentCache(templateKey);
});
}
@Override
@ -153,14 +159,6 @@ public class TemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTempl
});
}
/**
* 模板文件重命名
*
* @param template
* @param path
* @param remark
* @param operator
*/
@Override
public void renameTemplate(CmsTemplate template, String path, String remark, String operator) throws IOException {
String newPath = FileExUtils.normalizePath(path);
@ -198,11 +196,6 @@ public class TemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTempl
this.clearTemplateStaticContentCache(template);
}
/**
* 新建模板文件
*
* @param dto
*/
@Override
public void addTemplate(TemplateAddDTO dto) throws IOException {
CmsTemplate template = new CmsTemplate();
@ -248,12 +241,6 @@ public class TemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTempl
this.clearTemplateStaticContentCache(templateKey);
}
/**
* 获取模板文件
*
* @param template
* @return
*/
@Override
public File getTemplateFile(CmsTemplate template) {
CmsSite site = this.siteService.getSite(template.getSiteId());

View File

@ -48,7 +48,9 @@ public class CmsStatApiController extends BaseRestController {
public void visitSite(
@RequestParam("sid") Long siteId,
@RequestParam(value = "cid", required = false, defaultValue = "0") Long catalogId,
@RequestParam(value = "id", required = false, defaultValue = "0") Long contentId) {
@RequestParam(value = "id", required = false, defaultValue = "0") Long contentId,
@RequestParam(value = "h", required = false) String host,
@RequestParam(value = "p", required = false) String path) {
StatEvent evt = new StatEvent();
evt.setType(PageViewStatEventHandler.TYPE);
ObjectNode objectNode = JacksonUtils.objectNode();
@ -58,6 +60,8 @@ public class CmsStatApiController extends BaseRestController {
evt.setData(objectNode);
evt.setEvtTime(LocalDateTime.now());
evt.fillRequestData(ServletUtils.getRequest());
evt.getRequestData().setHost(host);
evt.getRequestData().setUri(path);
statEventService.dealStatEvent(evt);
}
}

View File

@ -12,7 +12,6 @@
<el-col :span="12">
<shortcut></shortcut>
<cms-site-data-stat></cms-site-data-stat>
<qi-gua></qi-gua>
<server-info></server-info>
</el-col>
</el-row>