Skip to content

Commit

Permalink
up:5.4.1
Browse files Browse the repository at this point in the history
Signed-off-by: mingsoft <[email protected]>
  • Loading branch information
msgroup authored and killfen committed Jul 29, 2024
1 parent 91fb207 commit 50d9a34
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 44 deletions.
1 change: 0 additions & 1 deletion src/main/java/net/mingsoft/cms/action/BaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public class BaseAction extends net.mingsoft.basic.action.BaseAction{
@Override
protected String getResString(String key) {

// TODO Auto-generated method stub
String str = "";
try {
str = super.getResString(key);
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/net/mingsoft/cms/action/GeneraterAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import io.swagger.annotations.ApiOperation;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.basic.annotation.LogAnn;
import net.mingsoft.basic.biz.IModelBiz;
import net.mingsoft.basic.constant.e.BusinessTypeEnum;
import net.mingsoft.basic.entity.AppEntity;
import net.mingsoft.basic.util.BasicUtil;
Expand Down Expand Up @@ -97,15 +96,6 @@ public class GeneraterAction extends BaseAction {
@Autowired
private ICategoryBiz categoryBiz;

/**
* 模块管理业务层
*/
@Autowired
private IModelBiz modelBiz;

@Value("${ms.manager.path}")
private String managerPath;

@Value("${ms.diy.html-dir:html}")
private String htmlDir;

Expand Down
27 changes: 13 additions & 14 deletions src/main/java/net/mingsoft/cms/aop/CategoryAop.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import net.mingsoft.base.constant.Const;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.basic.exception.BusinessException;
import net.mingsoft.base.exception.BusinessException;
import net.mingsoft.base.util.BundleUtil;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.cms.constant.e.CategoryDisplayEnum;
import net.mingsoft.cms.constant.e.CategoryIsSearchEnum;
Expand All @@ -52,7 +53,6 @@
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -175,32 +175,31 @@ public ResultData move(ProceedingJoinPoint pjp) throws Throwable {
@After("delete()")
public void delete(JoinPoint jp) {
List<CategoryEntity> categoryEntities = (List<CategoryEntity>) getJsonParam(jp);
// appDir
String appDir = BasicUtil.getApp().getAppDir() + File.separator;
for (CategoryEntity categoryEntity : categoryEntities) {
// 删除静态文件
deleteCategoryHtml(categoryEntity.getCategoryPath());
deleteCategoryHtml(appDir + categoryEntity.getTypelink());
}
}


/**
* @param categoryPath 栏目目录
* @param categoryLink 栏目链接
* 删除栏目静态文件
*/
public void deleteCategoryHtml(String categoryPath) {
public void deleteCategoryHtml(String categoryLink) {
// 过滤非法路径
if (StringUtils.isEmpty(categoryPath) || categoryPath.contains("../") || categoryPath.contains("..\\")) {
LOG.error("非法路径:{}", categoryPath);
throw new BusinessException("非法路径");
if (StringUtils.isEmpty(categoryLink) || categoryLink.contains("../") || categoryLink.contains("..\\")) {
LOG.error("非法路径:{}", categoryLink);
throw new BusinessException(BundleUtil.getString(Const.RESOURCES,"err.error",BundleUtil.getString(net.mingsoft.basic.constant.Const.RESOURCES,"file.path")));
}
// html真实路径
String htmlPath = BasicUtil.getRealPath(htmlDir);
// appDir
String appDir = BasicUtil.getApp().getAppDir();
// 删除静态文件
// 文件夹路径组成 html真实路径 + appdir + 栏目路径
// 文件夹路径组成 html真实路径 + 栏目路径
boolean flag = FileUtil.del(htmlPath
+ File.separator + appDir
+ categoryPath
+ File.separator + categoryLink
);
if (flag) {
LOG.info("删除静态文件夹成功!");
Expand Down
71 changes: 53 additions & 18 deletions src/main/java/net/mingsoft/cms/aop/ContentAop.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@

import cn.hutool.core.io.FileUtil;
import net.mingsoft.base.constant.Const;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.base.exception.BusinessException;
import net.mingsoft.base.util.BundleUtil;
import net.mingsoft.basic.aop.BaseAop;
import net.mingsoft.basic.util.BasicUtil;
import net.mingsoft.cms.biz.ICategoryBiz;
import net.mingsoft.cms.biz.IContentBiz;
import net.mingsoft.cms.biz.IHistoryLogBiz;
import net.mingsoft.cms.constant.e.CategoryTypeEnum;
import net.mingsoft.cms.constant.e.ContentEnum;
import net.mingsoft.cms.entity.CategoryEntity;
import net.mingsoft.cms.entity.ContentEntity;
import net.mingsoft.cms.entity.HistoryLogEntity;
import net.mingsoft.mdiy.util.ParserUtil;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
Expand Down Expand Up @@ -84,6 +85,7 @@ public class ContentAop extends BaseAop {
/**
* 文章浏览记录,
* 如果该文章该ip已经记录过,则不在重复记录
*
* @param pjp
* @return
* @throws Throwable
Expand Down Expand Up @@ -130,10 +132,12 @@ public void delete() {
*
* @param jp
*/
@After("delete()")
@AfterReturning("delete()")
public void delete(JoinPoint jp) {
List<ContentEntity> contents = (List<ContentEntity>) getJsonParam(jp);

// 获取appDir
String appDir = BasicUtil.getApp().getAppDir();
// 获取栏目ID对应文章ID数组 map
Map<String, List<String>> categoryIdByContentIds = contents.stream()
.collect(Collectors.groupingBy(ContentEntity::getCategoryId, Collectors.mapping(ContentEntity::getId, Collectors.toList())));
Expand All @@ -143,31 +147,62 @@ public void delete(JoinPoint jp) {
// 获取栏目
CategoryEntity category = categoryBiz.getById(categoryId);
// 获取栏目路径
String categoryPath = category.getCategoryPath();
String contentPath = appDir
+ File.separator + category.getCategoryPath();
for (String contentId : categoryIdByContentIds.get(categoryId)) {
// 组装静态文件地址
contentPath = contentPath + File.separator + contentId;
// 删除静态文件
deleteHtml(categoryPath, contentId);
deleteHtml(contentPath);
}
}
}

@Pointcut("execution(* net.mingsoft.cms.action.ContentAction.update(..))")
public void update() {
}

/**
* @param categoryPath 栏目目录
* @param contentId 文章ID
* 根据文章实体删除静态文件
* 更新文章后,如果该文章不显示,则删除文章对应的静态化文件
* @param jp
*/
private void deleteHtml(String categoryPath, String contentId) {
// html真实路径
String htmlPath = BasicUtil.getRealPath(htmlDir);
@AfterReturning("update()")
public void update(JoinPoint jp) {
// 更新文章只会一篇一篇更新
ContentEntity contentEntity = getType(jp, ContentEntity.class);
// appDir
String appDir = BasicUtil.getApp().getAppDir();
// 文件路径组成 html真实路径 + appdir + 栏目路径 + 文章ID + .html
String path = htmlPath
+ File.separator + appDir
+ categoryPath
+ File.separator + contentId
+ ParserUtil.HTML_SUFFIX;
// 判断文章是否存在且判断是否显示,如果不显示则把相关文章删除
if (contentEntity != null && contentEntity.getContentDisplay().equals(ContentEnum.HIDE.toString())) {
// 判断单篇文章类型
// 获取栏目
CategoryEntity category = categoryBiz.getById(contentEntity.getCategoryId());
if (category != null) {
String contentPath = appDir
+ File.separator + category.getCategoryPath();
if (category.getCategoryType().equals(CategoryTypeEnum.COVER.toString())) {
// 如何是单篇文章则拼接index,不传id值
contentPath = contentPath + File.separator + "index";
deleteHtml(contentPath);
} else {
contentPath = contentPath + File.separator + contentEntity.getId();
deleteHtml(contentPath);
}
}
}
}


/**
* 根据文章路径删除静态文件
*
* @param contentPath 文章文件路径
*/
private void deleteHtml(String contentPath) {
// html真实路径
String htmlPath = BasicUtil.getRealPath(htmlDir);
// 文件路径组成 html真实路径 + 文章路径 + .html
String path = htmlPath + File.separator + contentPath + ParserUtil.HTML_SUFFIX;
// 校验路径是否合法
if (path.contains("..") || path.contains("../") || path.contains("..\\")) {
LOG.error("非法路径:"+path);
Expand All @@ -178,7 +213,7 @@ private void deleteHtml(String categoryPath, String contentId) {
if (flag) {
LOG.info("删除静态文件成功!");
} else {
LOG.info("删除失败!");
LOG.error("删除失败!");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/


package net.mingsoft.cms.constant.e;

import net.mingsoft.base.constant.e.BaseEnum;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/mingsoft/cms/util/CmsParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import net.mingsoft.mdiy.biz.IModelBiz;
import net.mingsoft.mdiy.biz.impl.ModelBizImpl;
import net.mingsoft.mdiy.entity.ModelEntity;
import net.mingsoft.mdiy.util.ConfigUtil;
import net.mingsoft.mdiy.util.ParserUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down

0 comments on commit 50d9a34

Please sign in to comment.