From 14b2d5db6b0a76e2afa346d52d2ceb3c9db67199 Mon Sep 17 00:00:00 2001 From: xierz Date: Tue, 3 Nov 2020 12:08:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=8F=E7=9B=AE-=E7=88=B6?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E5=88=A4=E6=96=AD=20=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=A0=8F=E7=9B=AE-=E6=9B=B4=E6=96=B0=E7=88=B6=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=8F=B6=E5=AD=90=E7=8A=B6=E6=80=81=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9E=E6=A0=8F=E7=9B=AE-=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=A0=8F=E7=9B=AE=E4=B8=80=E5=AE=9A=E6=98=AF=E5=8F=B6=E5=AD=90?= =?UTF-8?q?=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/mingsoft/cms/biz/impl/CategoryBizImpl.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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 a9658150..25d484ba 100644 --- a/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java +++ b/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java @@ -24,6 +24,7 @@ package net.mingsoft.cms.biz.impl; import cn.hutool.core.lang.Assert; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import net.mingsoft.base.biz.impl.BaseBizImpl; import net.mingsoft.base.dao.IBaseDao; import net.mingsoft.basic.util.BasicUtil; @@ -88,6 +89,10 @@ public class CategoryBizImpl extends BaseBizImpl i } } categoryEntity.setLeaf(false); + //如果是新增栏目一定是叶子节点 + if (StrUtil.isEmpty(categoryEntity.getId())) { + categoryEntity.setLeaf(true); + } super.save(categoryEntity); //拼音存在则拼接id if(categoryBizEntity!=null){ @@ -190,14 +195,15 @@ public class CategoryBizImpl extends BaseBizImpl i Assert.notNull(entity); CategoryEntity categoryEntity = getById(entity.getId()); //如果父级不为空并且修改了父级则需要更新父级 - if(!entity.getCategoryId().equals(categoryEntity.getId())){ + if(!entity.getCategoryId().equals(categoryEntity.getCategoryId())){ //更新旧的父级 if(StrUtil.isNotBlank(categoryEntity.getCategoryId())&&!"0".equals(categoryEntity.getCategoryId())){ CategoryEntity parent = getById(categoryEntity.getCategoryId()); //如果修改了父级则需要判断父级是否还有子节点 boolean leaf = parent.getLeaf(); //查找不等于当前更新的分类子集,有则不是叶子节点 - parent.setLeaf(count(lambdaQuery().eq(CategoryEntity::getCategoryId,parent.getId()).ne(CategoryEntity::getId,entity.getId()))==0); + QueryWrapper queryWrapper = new QueryWrapper<>(); + parent.setLeaf(count(queryWrapper.eq("category_id",parent.getId()).ne("id",entity.getId()))==0); if(leaf!=parent.getLeaf()){ updateById(parent); }