Ver Fonte

up:5.4.2

Signed-off-by: mingsoft <killfen@126.com>
mingsoft há 1 ano atrás
pai
commit
3bb395b9f3

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

@@ -32,10 +32,14 @@ import net.mingsoft.base.entity.ResultData;
 import net.mingsoft.basic.bean.EUListBean;
 import net.mingsoft.basic.util.BasicUtil;
 import net.mingsoft.cms.bean.ContentBean;
+import net.mingsoft.cms.biz.ICategoryBiz;
 import net.mingsoft.cms.biz.IContentBiz;
 import net.mingsoft.cms.biz.IHistoryLogBiz;
+import net.mingsoft.cms.entity.CategoryEntity;
 import net.mingsoft.cms.entity.ContentEntity;
 import net.mingsoft.cms.entity.HistoryLogEntity;
+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.stereotype.Controller;
@@ -43,7 +47,10 @@ import org.springframework.web.bind.annotation.*;
 import springfox.documentation.annotations.ApiIgnore;
 
 import java.util.Date;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+
 /**
  * 文章管理控制层
  * @author 铭飞开发团队
@@ -63,6 +70,12 @@ public class ContentAction extends net.mingsoft.cms.action.BaseAction{
 	private IContentBiz contentBiz;
 
 	@Autowired
+	private ICategoryBiz categoryBiz;
+
+	@Autowired
+	private IModelBiz modelBiz;
+
+	@Autowired
 	private IHistoryLogBiz historyLogBiz;
 
 	/**
@@ -114,11 +127,28 @@ public class ContentAction extends net.mingsoft.cms.action.BaseAction{
 	@ResponseBody
 	public ResultData get(@ModelAttribute @ApiIgnore ContentEntity content){
 		if(content.getId()==null) {
-			return ResultData.build().error();
+			return ResultData.build().error(getResString("err.empty",this.getResString("id")));
 		}
 		content.setSqlWhere("");
-		ContentEntity _content = (ContentEntity)contentBiz.getById(content.getId());;
-		return ResultData.build().success(_content);
+		ContentEntity _content = contentBiz.getById(content.getId());
+		if(_content==null) {
+			return ResultData.build().error(getResString("err.error",this.getResString("id")));
+		}
+		// 获取栏目数据
+		CategoryEntity categoryEntity = categoryBiz.getById(_content.getCategoryId());
+		ModelEntity modelEntity = new ModelEntity();
+		if (categoryEntity != null) {
+			modelEntity = modelBiz.getById(categoryEntity.getMdiyModelId());
+		}
+		// 组织map查询数据
+		Map<String, Object> map = new HashMap<>();
+		map.put("dataid", content.getId());
+		// 如果没有自定义模型, 不设置自定义模型
+		if (modelEntity != null && StringUtils.isNotBlank(modelEntity.getModelTableName())) {
+			map.put("tableName", modelEntity.getModelTableName());
+		}
+		Map contentMap = contentBiz.get(map);
+		return ResultData.build().success(contentMap);
 	}
 
 	/**

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

@@ -76,4 +76,11 @@ public interface IContentBiz extends IBaseBiz<ContentEntity> {
      */
     List list(Map map);
 
+    /**
+     * 根据解析标签data的sql获取文章数据,如有自定义模型,则返回则加上自定义模型数据
+     * @param map
+     * @return
+     */
+    Map get(Map map);
+
 }

+ 16 - 15
src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java

@@ -7,10 +7,10 @@
  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  * the Software, and to permit persons to whom the Software is furnished to do so,
  * subject to the following conditions:
-
+ * <p>
  * The above copyright notice and this permission notice shall be included in all
  * copies or substantial portions of the Software.
-
+ * <p>
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
@@ -20,8 +20,6 @@
  */
 
 
-
-
 package net.mingsoft.cms.biz.impl;
 
 import cn.hutool.core.collection.CollUtil;
@@ -29,6 +27,7 @@ import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 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.biz.impl.BaseBizImpl;
 import net.mingsoft.base.dao.IBaseDao;
@@ -68,19 +67,19 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
 
     @Override
     protected IBaseDao getDao() {
-        
+
         return categoryDao;
     }
 
     @Override
     public List<CategoryEntity> queryChildren(CategoryEntity category) {
-        
+
         return categoryDao.queryChildren(category);
     }
 
     @Override
     public void saveEntity(CategoryEntity categoryEntity) {
-        
+
         String pingYin = PinYinUtil.getPingYin(categoryEntity.getCategoryTitle());
         //如果用户自己填入了拼音则使用用户的
         if (StrUtil.isNotBlank(categoryEntity.getCategoryPinyin())) {
@@ -138,7 +137,7 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
         //保存时先保存再修改链接地址,修改时直接修改
         if (StringUtils.isNotBlank(categoryEntity.getId())) {
             categoryEntity.setCategoryPath(path + "/" + categoryEntity.getCategoryPinyin());
-            if (StringUtils.isBlank(path)){
+            if (StringUtils.isBlank(path)) {
                 categoryEntity.setCategoryPath(categoryEntity.getCategoryPinyin());
             }
         }
@@ -207,7 +206,7 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
 
     @Override
     public void delete(String categoryId) {
-        
+
         CategoryEntity category = (CategoryEntity) categoryDao.selectById(categoryId);
         //删除父类
         if (category != null) {
@@ -227,10 +226,12 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
             List<CategoryEntity> childNode = categoryDao.queryChildren(parentNode);
             //判断删除的是否为主节点
             if (parentNode != null) {
-                UpdateWrapper<CategoryEntity> updateWrapper = new UpdateWrapper<>();
+                LambdaUpdateWrapper<CategoryEntity> updateWrapper = new LambdaUpdateWrapper<>();
                 //如果没有子节点进行更新代码
                 if (childNode.size() == 1) {
-                    updateWrapper.eq("id", parentNode.getId()).set("leaf", 1);
+                    // 更新父级为叶子节点
+                    updateWrapper.eq(CategoryEntity::getCategoryId, parentNode.getId())
+                            .set(CategoryEntity::getLeaf, true);
                     categoryDao.update(null, updateWrapper);
                 }
 
@@ -327,15 +328,15 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
 
 
     @Override
-    public void changeCategoryType(CategoryEntity categoryEntity,String targetCategoryType) {
+    public void changeCategoryType(CategoryEntity categoryEntity, String targetCategoryType) {
 
         // 转换为单篇
-        if (CategoryTypeEnum.COVER.toString().equalsIgnoreCase(targetCategoryType)){
+        if (CategoryTypeEnum.COVER.toString().equalsIgnoreCase(targetCategoryType)) {
             contentDao.deleteEntityByCategoryIds(new String[]{categoryEntity.getId()});
             categoryEntity.setCategoryUrl(null);
             categoryEntity.setCategoryListUrl(null);
-        // 转换为链接
-        } else if (CategoryTypeEnum.LINK.toString().equalsIgnoreCase(targetCategoryType)){
+            // 转换为链接
+        } else if (CategoryTypeEnum.LINK.toString().equalsIgnoreCase(targetCategoryType)) {
             contentDao.deleteEntityByCategoryIds(new String[]{categoryEntity.getId()});
             categoryEntity.setCategoryUrl(null);
             categoryEntity.setCategoryListUrl(null);

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

@@ -24,6 +24,8 @@
 
 package net.mingsoft.cms.biz.impl;
 
+import cn.hutool.core.collection.CollUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import freemarker.template.TemplateException;
 import net.mingsoft.base.biz.impl.BaseBizImpl;
@@ -125,4 +127,29 @@ public class ContentBizImpl  extends BaseBizImpl<IContentDao, ContentEntity> imp
 		return contentEntities;
 	}
 
+	@Override
+	public Map get(Map map) {
+		//通过tagSqlBiz获取data对应的sql
+		LambdaQueryWrapper<TagEntity> wrapper = new LambdaQueryWrapper<>();
+		wrapper.eq(TagEntity::getTagName, "data");
+		TagEntity tagEntity = tagBiz.getOne(wrapper);
+		if (tagEntity == null) {
+			return null;
+		}
+		String sqlFtl = tagEntity.getTagSql();
+		Map content = null;
+		try {
+			String sql = ParserUtil.rendering(map,sqlFtl);
+			//执行原生的sql
+			List<Map>contentEntities = (List<Map>) tagBiz.excuteSql(sql);
+			if (CollUtil.isEmpty(contentEntities)) {
+				return null;
+			}
+			// 默认取出第一个返回数据
+			content = contentEntities.get(0);
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return content;
+	}
 }