移除后台首页错误引用标签,访问统计接口添加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; 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.baomidou.mybatisplus.extension.service.IService;
import com.chestnut.contentcore.domain.CmsSite; import com.chestnut.contentcore.domain.CmsSite;
import com.chestnut.contentcore.domain.CmsTemplate; import com.chestnut.contentcore.domain.CmsTemplate;
import com.chestnut.contentcore.domain.dto.TemplateAddDTO; 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.domain.dto.TemplateUpdateDTO;
import com.chestnut.contentcore.template.ITemplateType; import com.chestnut.contentcore.template.ITemplateType;
import java.io.File;
import java.io.IOException;
import java.util.List;
public interface ITemplateService extends IService<CmsTemplate> { 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 * @param typeid 模板类型唯一标识
* @return
*/ */
ITemplateType getTemplateType(String typeid); ITemplateType getTemplateType(String typeid);
/** /**
* 获取模板静态化内容缓存主要区块模板使用 * 获取模板静态化内容缓存主要区块模板使用
* *
* @param templateId * @param templateKey 相对resourceRoot路径
* @return
*/ */
String getTemplateStaticContentCache(String templateId); String getTemplateStaticContentCache(String templateKey);
/** /**
* 缓存模板静态化内容 * 缓存模板静态化内容
* *
* @param templateId 相对resourceRoot路径 * @param templateKey 相对resourceRoot路径
* @param staticContent
*/ */
void setTemplateStaticContentCache(String templateId, String staticContent); void setTemplateStaticContentCache(String templateKey, String staticContent);
/** /**
* 扫描模板目录创建模板数据库记录 * 扫描模板目录创建模板数据库记录
* *
* @param site * @param site 站点数据
*/ */
void scanTemplates(CmsSite site); void scanTemplates(CmsSite site);
/** /**
* 保存模板内容 * 保存模板内容
*
* @throws IOException
*/ */
void saveTemplate(CmsTemplate template, TemplateUpdateDTO dto) throws IOException; void saveTemplate(CmsTemplate template, TemplateUpdateDTO dto) throws IOException;
/** /**
* 模板文件重命名 * 模板文件重命名
* *
* @param template * @param template 模板信息
* @param path * @param path 路径
* @param remark * @param remark 备注
* @param operator * @param operator 操作人
* @throws IOException
*/ */
void renameTemplate(CmsTemplate template, String path, String remark, String operator) throws IOException; void renameTemplate(CmsTemplate template, String path, String remark, String operator) throws IOException;
/** /**
* 获取模板文件 * 获取模板文件
* *
* @param template * @param template 模板信息
* @return
*/ */
File getTemplateFile(CmsTemplate template); File getTemplateFile(CmsTemplate template);
/** /**
* 查找模板文件 * 查找模板文件
* *
* @param site * @param site 站点信息
* @param templatePath * @param templatePath 模板路径
* @param publishPipeCode * @param publishPipeCode 发布通道编码
* @return
* @throws FileNotFoundException
*/ */
File findTemplateFile(CmsSite site, String templatePath, String publishPipeCode); File findTemplateFile(CmsSite site, String templatePath, String publishPipeCode);
/** /**
* 新建模板文件 * 新建模板文件
* *
* @param dto * @param dto 模板数据
* @throws IOException
*/ */
void addTemplate(TemplateAddDTO dto) throws IOException; void addTemplate(TemplateAddDTO dto) throws IOException;
/** /**
* 删除模板 * 删除模板
* @param templateIds * @param templateIds 模板ID列表
* @throws IOException
*/ */
void deleteTemplates(CmsSite site, List<Long> templateIds) throws IOException; 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 com.chestnut.system.fixed.dict.YesOrNo;
import freemarker.template.TemplateException; import freemarker.template.TemplateException;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FileUtils;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -130,15 +129,8 @@ public class PublishServiceImpl implements IPublishService, ApplicationContextAw
@Override @Override
public void run0() throws InterruptedException { public void run0() throws InterruptedException {
List<CmsPublishPipe> publishPipes = publishPipeService.getPublishPipes(site.getSiteId()); // 发布全站先清理所有模板缓存
publishPipes.forEach(pp -> { templateService.clearSiteAllTemplateStaticContentCache(site);
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);
}
});
List<CmsCatalog> catalogList = catalogService List<CmsCatalog> catalogList = catalogService
.list(new LambdaQueryWrapper<CmsCatalog>().eq(CmsCatalog::getSiteId, site.getSiteId())); .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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chestnut.common.redis.RedisCache; import com.chestnut.common.redis.RedisCache;
import com.chestnut.common.utils.Assert;
import com.chestnut.common.utils.IdUtils; import com.chestnut.common.utils.IdUtils;
import com.chestnut.common.utils.StringUtils; import com.chestnut.common.utils.StringUtils;
import com.chestnut.common.utils.file.FileExUtils; import com.chestnut.common.utils.file.FileExUtils;
@ -44,8 +43,6 @@ import org.springframework.stereotype.Service;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -67,19 +64,28 @@ public class TemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTempl
private final ISiteService siteService; private final ISiteService siteService;
@Override @Override
public String getTemplateStaticContentCache(String templateId) { public String getTemplateStaticContentCache(String templateKey) {
return this.redisCache.getCacheObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateId); return this.redisCache.getCacheObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateKey);
} }
@Override @Override
public void setTemplateStaticContentCache(String templateId, String staticContent) { public void setTemplateStaticContentCache(String templateKey, String staticContent) {
this.redisCache.setCacheObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateId, staticContent, 24, this.redisCache.setCacheObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateKey, staticContent, 24,
TimeUnit.HOURS); TimeUnit.HOURS);
} }
@Override @Override
public void clearTemplateStaticContentCache(String templateId) { public void clearTemplateStaticContentCache(String templateKey) {
this.redisCache.deleteObject(TEMPLATE_STATIC_CONTENT_CACHE_KEY_PREFIX + templateId); 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 @Override
@ -153,14 +159,6 @@ public class TemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTempl
}); });
} }
/**
* 模板文件重命名
*
* @param template
* @param path
* @param remark
* @param operator
*/
@Override @Override
public void renameTemplate(CmsTemplate template, String path, String remark, String operator) throws IOException { public void renameTemplate(CmsTemplate template, String path, String remark, String operator) throws IOException {
String newPath = FileExUtils.normalizePath(path); String newPath = FileExUtils.normalizePath(path);
@ -198,11 +196,6 @@ public class TemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTempl
this.clearTemplateStaticContentCache(template); this.clearTemplateStaticContentCache(template);
} }
/**
* 新建模板文件
*
* @param dto
*/
@Override @Override
public void addTemplate(TemplateAddDTO dto) throws IOException { public void addTemplate(TemplateAddDTO dto) throws IOException {
CmsTemplate template = new CmsTemplate(); CmsTemplate template = new CmsTemplate();
@ -248,12 +241,6 @@ public class TemplateServiceImpl extends ServiceImpl<CmsTemplateMapper, CmsTempl
this.clearTemplateStaticContentCache(templateKey); this.clearTemplateStaticContentCache(templateKey);
} }
/**
* 获取模板文件
*
* @param template
* @return
*/
@Override @Override
public File getTemplateFile(CmsTemplate template) { public File getTemplateFile(CmsTemplate template) {
CmsSite site = this.siteService.getSite(template.getSiteId()); CmsSite site = this.siteService.getSite(template.getSiteId());

View File

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

View File

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