diff --git a/src/main/java/net/mingsoft/cms/action/CategoryAction.java b/src/main/java/net/mingsoft/cms/action/CategoryAction.java index 229b3819..956e2320 100755 --- a/src/main/java/net/mingsoft/cms/action/CategoryAction.java +++ b/src/main/java/net/mingsoft/cms/action/CategoryAction.java @@ -280,7 +280,7 @@ public class CategoryAction extends BaseAction { } CategoryEntity categoryEntity=new CategoryEntity(); categoryEntity.setCategoryPinyin(pingYin); - CategoryEntity categoryBizEntity = (CategoryEntity)categoryBiz.getEntity(categoryEntity); + CategoryEntity categoryBizEntity = categoryBiz.getEntity(categoryEntity); category.setCategoryPinyin(pingYin); //如果存在此拼音栏目则拼接上id if(categoryBizEntity!=null&&!categoryBizEntity.getId().equals(category.getId())){ 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 f6b737c0..5e7a6d72 100755 --- a/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java +++ b/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java @@ -132,7 +132,7 @@ public class CategoryBizImpl extends BaseBizImpl i } } - private void setChildParentId(CategoryEntity categoryEntity) { + private void setChildParentId(CategoryEntity categoryEntity, String topId) { CategoryEntity category=new CategoryEntity(); category.setCategoryId(categoryEntity.getId()); List list = categoryDao.query(category); @@ -142,12 +142,14 @@ public class CategoryBizImpl extends BaseBizImpl i } else { x.setCategoryParentIds(categoryEntity.getCategoryParentIds()+","+categoryEntity.getId()); } + //更新topid + x.setTopId(topId); String path=categoryEntity.getCategoryPath(); //判断是否有parentIds x.setCategoryPath(path+"/"+x.getCategoryPinyin()); //去除多余的/符号 super.updateEntity(x); - setChildParentId(x); + setChildParentId(x, topId); }); } @@ -166,8 +168,21 @@ public class CategoryBizImpl extends BaseBizImpl i } setParentLeaf(entity); setTopId(entity); - super.updateById(entity); - setChildParentId(entity); + //如果父级栏目和父级id为空字符串则转化成null + if (StringUtils.isEmpty(entity.getCategoryId())) { + entity.setCategoryId(null); + } + if (StringUtils.isEmpty(entity.getCategoryParentIds())) { + entity.setCategoryParentIds(null); + } + categoryDao.updateEntity(entity); + //更新子节点所有父节点id和topid + //如果本节点的topid为0(顶级栏目),则把自身的id作为子栏目的topid,非0所有的子栏目和本栏目使用同一个topid + String topId = entity.getTopId(); + if (topId.equals("0")) { + topId = entity.getId(); + } + setChildParentId(entity, topId); } @@ -200,7 +215,6 @@ public class CategoryBizImpl extends BaseBizImpl i * @param entity */ private void setParentLeaf(CategoryEntity entity){ - Assert.notNull(entity); CategoryEntity categoryEntity = getById(entity.getId()); //如果父级不为空并且修改了父级则需要更新父级 if(entity.getCategoryId() != null && !entity.getCategoryId().equals(categoryEntity.getCategoryId())){ diff --git a/src/main/java/net/mingsoft/cms/dao/ICategoryDao.xml b/src/main/java/net/mingsoft/cms/dao/ICategoryDao.xml index d13e711d..5ca1bb0a 100755 --- a/src/main/java/net/mingsoft/cms/dao/ICategoryDao.xml +++ b/src/main/java/net/mingsoft/cms/dao/ICategoryDao.xml @@ -26,61 +26,10 @@ + + - - - insert into cms_category - - category_title, - category_pinyin, - category_id, - category_type, - category_sort, - category_list_url, - category_url, - category_keyword, - category_descrip, - category_img, - category_diy_url, - mdiy_model_id, - category_datetime, - dict_id, - category_flag, - category_path, - category_parent_ids, - create_by, - create_date, - update_by, - update_date, - del, - - - #{categoryTitle}, - #{categoryPinyin}, - #{categoryId}, - #{categoryType}, - #{categorySort}, - #{categoryListUrl}, - #{categoryUrl}, - #{categoryKeyword}, - #{categoryDescrip}, - #{categoryImg}, - #{categoryDiyUrl}, - #{mdiyModelId}, - #{categoryDatetime}, - #{dictId}, - #{categoryFlag}, - #{categoryPath}, - #{categoryParentId}, - #{createBy}, - #{createDate}, - #{updateBy}, - #{updateDate}, - #{del}, - - @@ -88,6 +37,8 @@ category_title=#{categoryTitle}, category_pinyin=#{categoryPinyin}, + top_id=#{topId}, + leaf=#{leaf}, category_id=#{categoryId}, category_parent_ids=#{categoryParentIds}, category_type=#{categoryType}, @@ -143,6 +94,8 @@ and update_by=#{updateBy} and update_date=#{updateDate} and del=#{del} + and top_id=#{topId} + and leaf=#{leaf} @@ -214,6 +167,8 @@ and update_by=#{updateBy} and update_date=#{updateDate} and del=#{del} + and top_id=#{topId} + and leaf=#{leaf}