diff --git a/src/main/java/net/mingsoft/cms/action/CategoryAction.java b/src/main/java/net/mingsoft/cms/action/CategoryAction.java index 43e5addd..cce498d4 100644 --- a/src/main/java/net/mingsoft/cms/action/CategoryAction.java +++ b/src/main/java/net/mingsoft/cms/action/CategoryAction.java @@ -182,7 +182,7 @@ public class CategoryAction extends BaseAction { @RequiresPermissions("cms:category:del") public ResultData delete(@RequestBody List categorys, HttpServletResponse response, HttpServletRequest request) { for(int i = 0;i { */ void update(CategoryEntity entity); - void delete(int categoryId); + void delete(String categoryId); } diff --git a/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java b/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java index 9f0d8852..a9658150 100644 --- a/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java +++ b/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java @@ -37,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.ArrayList; import java.util.List; /** @@ -163,21 +164,21 @@ public class CategoryBizImpl extends BaseBizImpl i } @Override - public void delete(int categoryId) { + public void delete(String categoryId) { // TODO Auto-generated method stub - CategoryEntity category = (CategoryEntity) categoryDao.getEntity(categoryId); + CategoryEntity category = (CategoryEntity) categoryDao.selectById(categoryId); //删除父类 if(category != null){ category.setCategoryParentId(null); List childrenList = categoryDao.queryChildren(category); - int[] ids = new int[childrenList.size()]; + List ids = new ArrayList<>(); for(int i = 0; i < childrenList.size(); i++){ //删除子类 - ids[i] = Integer.parseInt(childrenList.get(i).getId()); + ids.add(childrenList.get(i).getId()); } - categoryDao.delete(ids); + categoryDao.deleteBatchIds(ids); // 删除文章 - contentDao.deleteEntityByCategoryIds(ids); + contentDao.deleteEntityByCategoryIds(ids.toArray(new String[ids.size()])); } } diff --git a/src/main/java/net/mingsoft/cms/dao/IContentDao.java b/src/main/java/net/mingsoft/cms/dao/IContentDao.java index f82e909f..2578771e 100644 --- a/src/main/java/net/mingsoft/cms/dao/IContentDao.java +++ b/src/main/java/net/mingsoft/cms/dao/IContentDao.java @@ -41,5 +41,5 @@ public interface IContentDao extends IBaseDao { * 分类编号删除文章 * @param ids */ - void deleteEntityByCategoryIds(@Param("ids") int[] ids); + void deleteEntityByCategoryIds(@Param("ids") String[] ids); } \ No newline at end of file diff --git a/src/main/java/net/mingsoft/cms/upgrade/Upgrade.java b/src/main/java/net/mingsoft/cms/upgrade/Upgrade.java index 67aa2424..dcd8b2a5 100644 --- a/src/main/java/net/mingsoft/cms/upgrade/Upgrade.java +++ b/src/main/java/net/mingsoft/cms/upgrade/Upgrade.java @@ -1,13 +1,16 @@ package net.mingsoft.cms.upgrade; import cn.hutool.core.util.StrUtil; +import io.swagger.models.auth.In; import net.mingsoft.basic.util.BasicUtil; import net.mingsoft.basic.util.SpringUtil; import net.mingsoft.cms.biz.ICategoryBiz; import net.mingsoft.cms.entity.CategoryEntity; import net.mingsoft.basic.util.PinYinUtil; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * @author by 铭飞开源团队 @@ -17,29 +20,44 @@ import java.util.List; public class Upgrade { /** - * 菜单拼音升级 + * 更新栏目分类的顶级节点和叶子节点 */ public void upgrade(){ ICategoryBiz categoryBiz = SpringUtil.getBean(ICategoryBiz.class); List list = categoryBiz.queryAll(); - //先更新所有栏目的拼音 + list.forEach(x->{ - String pingYin = PinYinUtil.getPingYin(x.getCategoryTitle()); - CategoryEntity category=new CategoryEntity(); - category.setCategoryPinyin(pingYin); - CategoryEntity categoryBizEntity = (CategoryEntity)categoryBiz.getEntity(category); - x.setCategoryPinyin(pingYin); - //拼音存在则拼接id - if(categoryBizEntity!=null&&!categoryBizEntity.getId().equals(x.getId())){ - x.setCategoryPinyin(pingYin+x.getId()); + + //将parentId第一行设为顶级节点 + String topId = "0"; + String parentId = x.getParentid(); + if (parentId != null) { + topId = parentId.split(",")[0]; } - categoryBiz.update(x); - }); - //再更新路径 - list.forEach(x->{ - if(StrUtil.isBlank(x.getCategoryId())||x.getCategoryId().equals("0")){ - categoryBiz.updateEntity(x); + x.setTopId(topId); + + String id = x.getId(); + boolean leaf = true; + //判断是否叶子,循环查找,如果有节点的父节点中包含该节点的id则判断为否跳出循环 + for (int i = 0; i< list.size(); i++) { + String pId = list.get(i).getParentid(); + if (pId == null) { + continue; + } + leaf = !pId.contains(id); + //如果不是叶子就跳出循环,不需要再判断了 + if (!leaf) { + break; + } } + x.setLeaf(leaf); + //更新 + Map fields = new HashMap<>(); + fields.put("leaf", x.getLeaf()?"1":"0"); + fields.put("top_id", x.getTopId()); + Map where = new HashMap<>(); + where.put("id", x.getId()); + categoryBiz.updateBySQL("cms_category", fields, where); }); } diff --git a/src/main/java/net/mingsoft/handler/AppHandler.java b/src/main/java/net/mingsoft/handler/AppHandler.java index b94b3713..dff9516a 100644 --- a/src/main/java/net/mingsoft/handler/AppHandler.java +++ b/src/main/java/net/mingsoft/handler/AppHandler.java @@ -24,12 +24,12 @@ public class AppHandler implements TenantLineHandler { if(localPage!=null&&localPage.getTotal()==0){ PageHelper.clearPage(); } - int appId = BasicUtil.getAppId(); + //int appId = BasicUtil.getAppId(); if(localPage!=null&&localPage.getTotal()==0){ PageHelper.startPage(localPage.getPageNum(),localPage.getPageSize(),localPage.isCount()); PageHelper.orderBy(localPage.getOrderBy()); } - return new LongValue(appId); + return new LongValue(1); } @Override