Browse Source

fix:5.4.3 业务代码更新

msgroup 10 tháng trước cách đây
mục cha
commit
4e8fd1fdd4

+ 5 - 0
src/main/java/net/mingsoft/cms/action/CategoryAction.java

@@ -93,6 +93,11 @@ public class CategoryAction extends BaseAction {
     @RequestMapping(value = "/list", method = {RequestMethod.GET, RequestMethod.POST})
     @ResponseBody
     public ResultData list(@ModelAttribute @ApiIgnore CategoryEntity category) {
+        // TODO: 2024/12/2 为了拓展栏目使用方法,增加isChild字段处理
+        // 这里根据外部传值,如果没有则默认查询cms下栏目
+        if (StrUtil.isBlank(category.getIsChild())) {
+            category.setIsChild("cms");
+        }
         List categoryList = categoryBiz.list(new LambdaQueryWrapper<CategoryEntity>(category));
         return ResultData.build().success(new EUListBean(categoryList, categoryList.size()));
     }

+ 5 - 4
src/main/java/net/mingsoft/cms/action/ContentAction.java

@@ -22,6 +22,7 @@
 
 package net.mingsoft.cms.action;
 
+import cn.hutool.core.util.StrUtil;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -121,7 +122,7 @@ public class ContentAction extends BaseAction {
         // 检查SQL注入
         SqlInjectionUtil.filterContent(content.getCategoryId());
         BasicUtil.startPage();
-        List contentList = contentBiz.queryContent(content);
+        List<ContentBean> contentList = contentBiz.queryContent(content);
         return ResultData.build().success(new EUListBean(contentList, (int) BasicUtil.endPage(contentList).getTotal()));
     }
 
@@ -269,10 +270,10 @@ public class ContentAction extends BaseAction {
             }
             //获取到配置模型实体
             ModelEntity modelEntity = modelBiz.getById(categoryEntity.getMdiyModelId());
+            // 过滤表名
+            SqlInjectionUtil.filterContent(modelEntity.getModelTableName());
             //删除模型表的数据
-            Map<String, String> map = new HashMap<>();
-            map.put("link_id", contents.get(i).getId());
-            modelBiz.deleteBySQL(modelEntity.getModelTableName(), map);
+            modelBiz.update(StrUtil.format("delete from {} where link_id = ?", modelEntity.getModelTableName()), contents.get(i).getId());
         }
 
         contentBiz.removeByIds(ids);

+ 96 - 6
src/main/java/net/mingsoft/cms/action/GeneraterAction.java

@@ -26,14 +26,19 @@ package net.mingsoft.cms.action;
 
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.bean.copier.CopyOptions;
+import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.date.DateException;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import net.mingsoft.base.entity.ResultData;
 import net.mingsoft.basic.annotation.LogAnn;
+import net.mingsoft.basic.bean.EUListBean;
 import net.mingsoft.basic.constant.e.BusinessTypeEnum;
 import net.mingsoft.basic.entity.AppEntity;
 import net.mingsoft.basic.util.BasicUtil;
@@ -56,6 +61,7 @@ import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.*;
+import springfox.documentation.annotations.ApiIgnore;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -111,6 +117,25 @@ public class GeneraterAction extends BaseAction {
     }
 
     /**
+     * 获取所有栏目数据
+     * 重写接口说明:
+     * 处理静态化生成页无法获取所有分类信息问题
+     * 目前栏目作为一个公共数据,方便以后拓展其他业务
+     * @param category 分类实体
+     */
+    @ApiOperation(value = "查询分类列表接口")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "categoryTitle", value = "栏目管理名称", required = false, paramType = "query"),
+            @ApiImplicitParam(name = "categoryParentId", value = "父类型编号", required = false, paramType = "query"),
+    })
+    @RequestMapping(value = "/list", method = {RequestMethod.GET, RequestMethod.POST})
+    @ResponseBody
+    public ResultData list(@ModelAttribute @ApiIgnore CategoryEntity category) {
+        List categoryList = categoryBiz.list(new LambdaQueryWrapper<CategoryEntity>(category));
+        return ResultData.build().success(new EUListBean(categoryList, categoryList.size()));
+    }
+
+    /**
      * 生成主页
      *
      * @param request
@@ -220,6 +245,16 @@ public class GeneraterAction extends BaseAction {
                     }
                     CmsParserUtil.generateBasic(articleIdList, htmlDir,null);
                     break;
+                default:
+                    // 为了方面拓展其他静态化栏目,都默认走这个业务
+                    // 判断模板文件是否存在
+                    if (StringUtils.isEmpty(column.getCategoryUrl()) || !FileUtil.exist(ParserUtil.buildTemplatePath(column.getCategoryUrl()))) {
+                        LOG.error("{} 模板不存在:{}", column.getCategoryTitle(), column.getCategoryUrl());
+                        continue;
+                    }
+                    // TODO: 2024/11/26 目前只根据内容模版生成静态文件 
+                    CmsParserUtil.generate(column.getCategoryUrl(), column.getCategoryPinyin(), htmlDir);
+                    break;
             }
         }
 
@@ -279,6 +314,11 @@ public class GeneraterAction extends BaseAction {
             if (category.getCategoryType().equals(CategoryTypeEnum.LINK.toString())) {
                 continue;
             }
+
+            // 如果是单篇文章跳过生成
+            if (category.getCategoryType().equals(CategoryTypeEnum.COVER.toString())) {
+                continue;
+            }
             contentBean.setCategoryId(category.getId());
             contentBean.setCategoryType(category.getCategoryType());
             contentBean.setOrderBy("date");
@@ -291,13 +331,12 @@ public class GeneraterAction extends BaseAction {
                     LOG.error("{} 模板不存在:{}", category.getCategoryTitle(), category.getCategoryListUrl());
                     continue;
                 }
-            } else if (category.getCategoryType().equals(CategoryTypeEnum.COVER.toString())) {
-                continue;
-            }
-            // 有符合条件的就更新
-            if (articleIdList.size() > 0) {
-                CmsParserUtil.generateBasic(articleIdList, htmlDir,contentUpdateTime);
+                // 有符合条件的就更新
+                if (articleIdList.size() > 0) {
+                    CmsParserUtil.generateBasic(articleIdList, htmlDir,contentUpdateTime);
+                }
             }
+
         }
 
 
@@ -321,5 +360,56 @@ public class GeneraterAction extends BaseAction {
         return "redirect:" + indexPosition;
     }
 
+    /**
+     * 删除页面
+     * <p>
+     * 页面名称
+     *
+     * @param request 响应
+     */
+    @ApiOperation(value = "删除页面")
+    @ApiImplicitParam(name = "fileName", value = "主页名称", required = true, paramType = "query")
+    @LogAnn(title = "删除页面", businessType = BusinessTypeEnum.DELETE)
+    @PostMapping("/delete")
+    @ResponseBody
+    @RequiresPermissions("cms:generate:del")
+    public ResultData delete(HttpServletRequest request) {
+        String deletePath = BasicUtil.getString("deletePath");
+        if (StrUtil.isBlank(deletePath)) {
+            return ResultData.build().error("请先输入要删除的文件路径");
+        }
+        // 确定以html开头
+        if (!deletePath.startsWith(htmlDir) && !deletePath.startsWith("/" + htmlDir)) {
+            return ResultData.build().error("删除路径请以" + htmlDir + "开头");
+        }
+        if (deletePath.contains("..") || deletePath.contains("../") || deletePath.contains("..\\")) {
+            return ResultData.build().error("非法路径");
+        }
+        String appDir = BasicUtil.getApp().getAppDir();
+        // 用户输入的实际路径
+        String realPath = BasicUtil.getRealPath(deletePath);
+        //站点的真实路径 html/web(站点id)
+        String webRealPath = BasicUtil.getRealPath(htmlDir + "/" + appDir + "/");
+
+        String htmlRealPath = BasicUtil.getRealPath(htmlDir);
+        // 取html下的文件
+        List<String> paths = FileUtil.listFileNames(htmlRealPath);
+        // 暂不考虑 html/web/index 与  html/index短链 同时存在; 只处理html/web/index 与  html/index短链 单独存在的场景
+        if (CollUtil.isEmpty(paths)) {
+            // 为空则说为目录  就有web;
+            // 判断传入的路径是否以 (html+/+站点+/ yaml配置中) 开头;是则为同一个站,不是则跨站
+            if (!realPath.startsWith(webRealPath)) {
+                return ResultData.build().error("不允许跨站删除");
+            }
+        }
+        //  只剩下情况  文件 html/web(本站)/index  和 html/index  判断直接删除文件
+        if (FileUtil.exist(realPath)) {
+            FileUtil.del(realPath);
+            return ResultData.build().success();
+        } else {
+            return ResultData.build().error("文件不存在");
+        }
+    }
+
 
 }

+ 3 - 2
src/main/java/net/mingsoft/cms/action/web/ContentAction.java

@@ -23,7 +23,6 @@
 package net.mingsoft.cms.action.web;
 
 import cn.hutool.core.util.ObjectUtil;
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
@@ -42,6 +41,7 @@ import net.mingsoft.mdiy.biz.IModelBiz;
 import net.mingsoft.mdiy.entity.ModelEntity;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.MediaType;
 import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 import springfox.documentation.annotations.ApiIgnore;
@@ -158,7 +158,8 @@ public class ContentAction extends net.mingsoft.cms.action.BaseAction{
 	 */
 	@ApiOperation(value = "查看文章点击数")
 	@ApiImplicitParam(name = "contentId", value = "文章编号", required = true,paramType="path")
-	@GetMapping(value = "/{contentId}/hit")
+	// 由于适配增加了对clob序列化处理,此处需要指定响应头
+	@GetMapping(value = "/{contentId}/hit", produces = MediaType.TEXT_HTML_VALUE)
 	@ResponseBody
 	public String hit(@PathVariable @ApiIgnore String contentId) {
 		if(StringUtils.isEmpty(contentId)){

+ 1 - 1
src/main/java/net/mingsoft/cms/biz/IContentBiz.java

@@ -52,7 +52,7 @@ public interface IContentBiz extends IBaseBiz<ContentEntity> {
      * @param contentBean
      * @return
      */
-    List<CategoryBean> queryContent(ContentBean contentBean);
+    List<ContentBean> queryContent(ContentBean contentBean);
 
     /**
      * 文章搜索结果总数,提供搜索使用

+ 1 - 1
src/main/java/net/mingsoft/cms/biz/impl/ContentBizImpl.java

@@ -88,7 +88,7 @@ public class ContentBizImpl  extends BaseBizImpl<IContentDao, ContentEntity> imp
 	}
 
 	@Override
-	public List<CategoryBean> queryContent(ContentBean contentBean) {
+	public List<ContentBean> queryContent(ContentBean contentBean) {
 		return this.contentDao.queryContent(contentBean);
 
 	}

+ 4 - 0
src/main/java/net/mingsoft/cms/constant/e/CategoryTypeEnum.java

@@ -44,6 +44,10 @@ public enum CategoryTypeEnum implements BaseEnum {
      * 链接
      */
     LINK("3"),
+    /**
+     * 专题专栏
+     */
+    TOPIC("topic"),
 
     /**
      * 未知类型

+ 4 - 0
src/main/java/net/mingsoft/cms/dao/ICategoryDao.xml

@@ -25,6 +25,7 @@
 		<result column="category_flag" property="categoryFlag" /><!--栏目属性 -->
 		<result column="category_path" property="categoryPath" /><!--栏目路径 -->
 		<result column="category_parent_ids" property="categoryParentIds" /><!--父类型编号 -->
+		<result column="is_child" property="isChild" /><!--扩展业务标记 -->
 		<result column="create_by" property="createBy" /><!--创建人 -->
 		<result column="create_date" property="createDate" /><!--创建时间 -->
 		<result column="update_by" property="updateBy" /><!--修改人 -->
@@ -62,6 +63,7 @@
 			<if test="dictId != null">dict_id=#{dictId},</if>
 			<if test="categoryFlag != null ">category_flag=#{categoryFlag},</if>
 			<if test="categoryPath != null and categoryPath != ''">category_path=#{categoryPath},</if>
+			<if test="isChild != null and isChild != ''">is_child=#{isChild},</if>
 			<if test="createBy &gt; 0">create_by=#{createBy},</if>
 			<if test="createDate != null">create_date=#{createDate},</if>
 			<if test="updateBy &gt; 0">update_by=#{updateBy},</if>
@@ -107,6 +109,7 @@
 			<if test="del != null"> and del=#{del} </if>
 			<if test="topId != null and topId != ''"> and top_id=#{topId}</if>
 			<if test="leaf != null"> and leaf=#{leaf}</if>
+			<if test="isChild != null and isChild != ''"> and is_child=#{isChild}</if>
 		</where>
 	</select>
 
@@ -180,6 +183,7 @@
 			<if test="del != null"> and del=#{del} </if>
 			<if test="topId != null and topId != ''"> and top_id=#{topId}</if>
 			<if test="leaf != null"> and leaf=#{leaf}</if>
+			<if test="isChild != null and isChild != ''"> and is_child=#{isChild}</if>
 			<include refid="net.mingsoft.base.dao.IBaseDao.sqlWhere"></include>
 		</where>
 	</select>

+ 1 - 1
src/main/java/net/mingsoft/cms/dao/IContentDao.java

@@ -60,7 +60,7 @@ public interface IContentDao extends IBaseDao<ContentEntity> {
      * @contentBean
      * @return
      */
-    public List<CategoryBean> queryContent(ContentBean contentBean);
+    public List<ContentBean> queryContent(ContentBean contentBean);
 
     /**
      * 根据查询文章实体总数

+ 7 - 6
src/main/java/net/mingsoft/cms/dao/IContentDao.xml

@@ -234,7 +234,7 @@
 			<if test="contentTitle != null and contentTitle != ''"> and  content_title like CONCAT(CONCAT('%',#{contentTitle}),'%')</if>
 			<if test="contentShortTitle != null and contentShortTitle != ''"> and  content_short_title like CONCAT(CONCAT('%',#{contentShortTitle}),'%')</if>
 			<if test="categoryId != null and categoryId != ''"> 	and (ct.category_id=#{categoryId} or ct.category_id in
-				(select id FROM cms_category where find_in_set(#{categoryId},CATEGORY_PARENT_IDS)>0 and cms_category.category_type != 2))</if>
+				(select id FROM cms_category where find_in_set(#{categoryId},CATEGORY_PARENT_IDS)>0 and cms_category.category_type != '2'))</if>
 			<if test="contentType != null and contentType != ''">
 				and
 				<foreach item="item" index="index" collection="contentType.split(',')" open="(" separator="or"
@@ -258,6 +258,7 @@
 			<if test="createDate != null"> and ct.create_date=#{createDate} </if>
 			<if test="updateBy &gt; 0"> and ct.update_by=#{updateBy} </if>
 			<if test="updateDate != null"> and update_date=#{updateDate} </if>
+
 			<include refid="net.mingsoft.base.dao.IBaseDao.sqlWhere"></include>
 		</where>
 		)ct ORDER BY ct.content_datetime desc,content_sort desc
@@ -324,11 +325,11 @@
 			where ct.del=0 and ct.content_display=0 and c.category_display='enable'
 
 			<!-- 查询子栏目数据 -->
-			<if test="categoryId!=null and  categoryId!='' and categoryType==1">
+			<if test="categoryId!=null and  categoryId!='' and categoryType== '1'.toString()">
 				and (ct.category_id=#{categoryId} or ct.category_id in
 				(select id FROM cms_category where find_in_set(#{categoryId},CATEGORY_PARENT_IDS)>0))
 			</if>
-			<if test="categoryId!=null and  categoryId!='' and categoryType==2">
+			<if test="categoryId!=null and  categoryId!='' and categoryType== '2'.toString()">
 				and ct.category_id=#{categoryId}
 			</if>
 
@@ -375,11 +376,11 @@
 		where ct.del=0 and ct.content_display=0 and c.category_display='enable'
 
 		<!-- 查询子栏目数据 -->
-		<if test="categoryId!=null and  categoryId!='' and categoryType==1">
+		<if test="categoryId!=null and  categoryId!='' and categoryType== '1'.toString()">
 			and (ct.category_id=#{categoryId} or ct.category_id in
-			(select id FROM cms_category where find_in_set(#{categoryId},CATEGORY_PARENT_IDS)>0 and category_type!=2))
+			(select id FROM cms_category where find_in_set(#{categoryId},CATEGORY_PARENT_IDS)>0 and category_type!='2'))
 		</if>
-		<if test="categoryId!=null and  categoryId!='' and categoryType==2">
+		<if test="categoryId!=null and  categoryId!='' and categoryType== '2'.toString()">
 			and ct.category_id=#{categoryId}
 		</if>
 		<if test="beginTime!=null and beginTime!=''">

+ 18 - 0
src/main/java/net/mingsoft/cms/entity/CategoryEntity.java

@@ -164,6 +164,11 @@ public class CategoryEntity extends BaseEntity {
      */
     private String topId;
 
+    /**
+     * 子业务关联
+     */
+    private String isChild;
+
     public Boolean getLeaf() {
         return leaf;
     }
@@ -568,4 +573,17 @@ public class CategoryEntity extends BaseEntity {
     public String getUrl() {
         return "/" + MSProperties.diy.htmlDir + "/" + BasicUtil.getApp().getAppDir() + "/" +this.getCategoryPath() + "/index.html";
     }
+
+    /**
+     * 获取子业务关联
+     */
+    public String getIsChild() {
+        return isChild;
+    }
+    /**
+     * 设置子业务关联
+     */
+    public void setIsChild(String isChild) {
+        this.isChild = isChild;
+    }
 }

+ 8 - 4
src/main/java/net/mingsoft/config/WebConfig.java

@@ -29,8 +29,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import net.mingsoft.basic.filter.XSSEscapeFilter;
 import net.mingsoft.basic.interceptor.ActionInterceptor;
 import net.mingsoft.mdiy.biz.IConfigBiz;
+import net.mingsoft.mdiy.constant.e.ModelCustomTypeEnum;
 import net.mingsoft.mdiy.entity.ConfigEntity;
 import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.web.servlet.FilterRegistrationBean;
 import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
@@ -62,9 +64,11 @@ public class WebConfig implements WebMvcConfigurer {
     @Resource
     private IConfigBiz configBiz;
 
-    @Resource
+
+    @Autowired(required = false)
     private MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter;
 
+
     @Bean
     public ActionInterceptor actionInterceptor() {
         return new ActionInterceptor();
@@ -88,7 +92,7 @@ public class WebConfig implements WebMvcConfigurer {
      */
     @Override
     public void addInterceptors(InterceptorRegistry registry) {
-        // 排除配置
+          // 排除配置
         registry.addInterceptor(actionInterceptor()).excludePathPatterns("/static/**", "/app/**", "/webjars/**",
                 "/*.html", "/*.htm");
     }
@@ -178,13 +182,11 @@ public class WebConfig implements WebMvcConfigurer {
         WebMvcConfigurer.super.addViewControllers(registry);
     }
 
-
     /**
      * 解决com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException 问题,提交实体不存在的字段异常
      */
     @Override
     public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
-        
         converters.add(mappingJackson2HttpMessageConverter);
         WebMvcConfigurer.super.configureMessageConverters(converters);
 
@@ -205,6 +207,8 @@ public class WebConfig implements WebMvcConfigurer {
         if (!StringUtils.isEmpty(configName) && !StringUtils.isEmpty(configName)) {
             ConfigEntity configEntity = new ConfigEntity();
             configEntity.setConfigName(configName);
+            // 防止查询到重复的数据
+            configEntity.setConfigType(ModelCustomTypeEnum.CONFIG.getLabel());
             configEntity = (ConfigEntity)this.configBiz.getOne(new QueryWrapper(configEntity));
             return configEntity != null && !StringUtils.isEmpty(configEntity.getConfigData()) ? (Map) JSONUtil.toBean(configEntity.getConfigData(), HashMap.class) : null;
         } else {