Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
cms_sys
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
西魏
cms_sys
Commits
bf363bda
Commit
bf363bda
authored
Apr 29, 2021
by
msgroup
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复子栏目删除是,父栏目leaf标识不对bug
parent
954b380a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
51 additions
and
49 deletions
+51
-49
CategoryBizImpl.java
src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java
+51
-49
No files found.
src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java
View file @
bf363bda
...
...
@@ -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
...
...
@@ -48,8 +48,8 @@ import java.util.List;
* 创建日期:2019-11-28 15:12:32<br/>
* 历史修订:<br/>
*/
@Service
(
"cmscategoryBizImpl"
)
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
@Service
(
"cmscategoryBizImpl"
)
@Transactional
(
rollbackFor
=
RuntimeException
.
class
)
public
class
CategoryBizImpl
extends
BaseBizImpl
<
ICategoryDao
,
CategoryEntity
>
implements
ICategoryBiz
{
...
...
@@ -71,6 +71,7 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
// TODO Auto-generated method stub
return
categoryDao
.
queryChildren
(
category
);
}
@Override
public
void
saveEntity
(
CategoryEntity
categoryEntity
)
{
// TODO Auto-generated method stub
...
...
@@ -79,16 +80,16 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
if
(
StrUtil
.
isNotBlank
(
categoryEntity
.
getCategoryPinyin
()))
{
pingYin
=
categoryEntity
.
getCategoryPinyin
();
}
CategoryEntity
category
=
new
CategoryEntity
();
CategoryEntity
category
=
new
CategoryEntity
();
category
.
setCategoryPinyin
(
pingYin
);
Object
categoryBizEntity
=
getEntity
(
category
);
setParentId
(
categoryEntity
);
categoryEntity
.
setCategoryPinyin
(
pingYin
);
//更新新的父级
if
(
StrUtil
.
isNotBlank
(
categoryEntity
.
getCategoryId
())&&!
"0"
.
equals
(
categoryEntity
.
getCategoryId
()))
{
if
(
StrUtil
.
isNotBlank
(
categoryEntity
.
getCategoryId
())
&&
!
"0"
.
equals
(
categoryEntity
.
getCategoryId
()))
{
CategoryEntity
parent
=
getById
(
categoryEntity
.
getCategoryId
());
//如果之前是叶子节点就更新
if
(
parent
.
getLeaf
())
{
if
(
parent
.
getLeaf
())
{
parent
.
setLeaf
(
false
);
updateById
(
parent
);
}
...
...
@@ -100,54 +101,55 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
}
super
.
save
(
categoryEntity
);
//拼音存在则拼接id
if
(
categoryBizEntity
!=
null
)
{
categoryEntity
.
setCategoryPinyin
(
pingYin
+
categoryEntity
.
getId
());
if
(
categoryBizEntity
!=
null
)
{
categoryEntity
.
setCategoryPinyin
(
pingYin
+
categoryEntity
.
getId
());
}
CategoryEntity
parentCategory
=
null
;
if
(
StringUtils
.
isNotBlank
(
categoryEntity
.
getCategoryId
()))
{
parentCategory
=
(
CategoryEntity
)
getById
(
categoryEntity
.
getCategoryId
());
parentCategory
=
(
CategoryEntity
)
getById
(
categoryEntity
.
getCategoryId
());
}
//保存链接地址
String
path
=
ObjectUtil
.
isNotNull
(
parentCategory
)?
parentCategory
.
getCategoryPath
():
""
;
categoryEntity
.
setCategoryPath
(
path
+
"/"
+
categoryEntity
.
getCategoryPinyin
());
String
path
=
ObjectUtil
.
isNotNull
(
parentCategory
)
?
parentCategory
.
getCategoryPath
()
:
""
;
categoryEntity
.
setCategoryPath
(
path
+
"/"
+
categoryEntity
.
getCategoryPinyin
());
setTopId
(
categoryEntity
);
super
.
updateById
(
categoryEntity
);
}
private
void
setParentId
(
CategoryEntity
categoryEntity
)
{
String
path
=
""
;
if
(
StringUtils
.
isNotEmpty
(
categoryEntity
.
getCategoryId
())&&
Long
.
parseLong
(
categoryEntity
.
getCategoryId
())>
0
)
{
CategoryEntity
category
=
(
CategoryEntity
)
getById
(
categoryEntity
.
getCategoryId
());
if
(
StringUtils
.
isNotEmpty
(
categoryEntity
.
getCategoryId
())
&&
Long
.
parseLong
(
categoryEntity
.
getCategoryId
())
>
0
)
{
CategoryEntity
category
=
(
CategoryEntity
)
getById
(
categoryEntity
.
getCategoryId
());
path
=
category
.
getCategoryPath
();
if
(
StringUtils
.
isEmpty
(
category
.
getCategoryParentIds
()))
{
if
(
StringUtils
.
isEmpty
(
category
.
getCategoryParentIds
()))
{
categoryEntity
.
setCategoryParentIds
(
category
.
getId
());
}
else
{
categoryEntity
.
setCategoryParentIds
(
category
.
getCategoryParentIds
()+
","
+
category
.
getId
());
categoryEntity
.
setCategoryParentIds
(
category
.
getCategoryParentIds
()
+
","
+
category
.
getId
());
}
}
else
{
}
else
{
categoryEntity
.
setCategoryParentIds
(
null
);
}
//保存时先保存再修改链接地址,修改时直接修改
if
(
StringUtils
.
isNotBlank
(
categoryEntity
.
getId
()))
{
categoryEntity
.
setCategoryPath
(
path
+
"/"
+
categoryEntity
.
getCategoryPinyin
());
if
(
StringUtils
.
isNotBlank
(
categoryEntity
.
getId
()))
{
categoryEntity
.
setCategoryPath
(
path
+
"/"
+
categoryEntity
.
getCategoryPinyin
());
}
}
private
void
setChildParentId
(
CategoryEntity
categoryEntity
,
String
topId
)
{
CategoryEntity
category
=
new
CategoryEntity
();
CategoryEntity
category
=
new
CategoryEntity
();
category
.
setCategoryId
(
categoryEntity
.
getId
());
List
<
CategoryEntity
>
list
=
categoryDao
.
query
(
category
);
list
.
forEach
(
x
->
{
if
(
StringUtils
.
isEmpty
(
categoryEntity
.
getCategoryParentIds
()))
{
list
.
forEach
(
x
->
{
if
(
StringUtils
.
isEmpty
(
categoryEntity
.
getCategoryParentIds
()))
{
x
.
setCategoryParentIds
(
categoryEntity
.
getId
());
}
else
{
x
.
setCategoryParentIds
(
categoryEntity
.
getCategoryParentIds
()+
","
+
categoryEntity
.
getId
());
x
.
setCategoryParentIds
(
categoryEntity
.
getCategoryParentIds
()
+
","
+
categoryEntity
.
getId
());
}
//更新topid
x
.
setTopId
(
topId
);
String
path
=
categoryEntity
.
getCategoryPath
();
String
path
=
categoryEntity
.
getCategoryPath
();
//判断是否有parentIds
x
.
setCategoryPath
(
path
+
"/"
+
x
.
getCategoryPinyin
());
x
.
setCategoryPath
(
path
+
"/"
+
x
.
getCategoryPinyin
());
//去除多余的/符号
super
.
updateEntity
(
x
);
setChildParentId
(
x
,
topId
);
...
...
@@ -157,14 +159,14 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
@Override
public
void
updateEntity
(
CategoryEntity
entity
)
{
setParentId
(
entity
);
String
pingYin
=
entity
.
getCategoryPinyin
();
if
(
StrUtil
.
isNotBlank
(
pingYin
))
{
CategoryEntity
category
=
new
CategoryEntity
();
String
pingYin
=
entity
.
getCategoryPinyin
();
if
(
StrUtil
.
isNotBlank
(
pingYin
))
{
CategoryEntity
category
=
new
CategoryEntity
();
category
.
setCategoryPinyin
(
pingYin
);
CategoryEntity
categoryBizEntity
=
(
CategoryEntity
)
getEntity
(
category
);
CategoryEntity
categoryBizEntity
=
(
CategoryEntity
)
getEntity
(
category
);
//拼音存在则拼接id
if
(
categoryBizEntity
!=
null
&&!
categoryBizEntity
.
getId
().
equals
(
entity
.
getId
()))
{
entity
.
setCategoryPinyin
(
pingYin
+
entity
.
getId
());
if
(
categoryBizEntity
!=
null
&&
!
categoryBizEntity
.
getId
().
equals
(
entity
.
getId
()))
{
entity
.
setCategoryPinyin
(
pingYin
+
entity
.
getId
());
}
}
setParentLeaf
(
entity
);
...
...
@@ -197,11 +199,11 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
// TODO Auto-generated method stub
CategoryEntity
category
=
(
CategoryEntity
)
categoryDao
.
selectById
(
categoryId
);
//删除父类
if
(
category
!=
null
)
{
if
(
category
!=
null
)
{
category
.
setCategoryParentIds
(
null
);
List
<
CategoryEntity
>
childrenList
=
categoryDao
.
queryChildren
(
category
);
List
<
String
>
ids
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
childrenList
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
childrenList
.
size
();
i
++)
{
//删除子类
ids
.
add
(
childrenList
.
get
(
i
).
getId
());
}
...
...
@@ -211,50 +213,50 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
//获取被删节点的父节点
CategoryEntity
parentNode
=
categoryDao
.
selectById
(
category
.
getCategoryId
());
//清空CategoryParentIds,避免查找不必要的数据,只需要当前的父级栏目
parentNode
.
setCategoryParentIds
(
null
);
//获取被删节点的所属栏目的其他节点
List
<
CategoryEntity
>
childNode
=
categoryDao
.
queryChildren
(
parentNode
);
//判断删除的是否为主节点
if
(
parentNode
!=
null
)
{
UpdateWrapper
<
CategoryEntity
>
updateWrapper
=
new
UpdateWrapper
<>();
//是否还有子节点
if
(
childNode
.
size
()
>
1
)
updateWrapper
.
eq
(
"id"
,
parentNode
.
getId
()).
set
(
"leaf"
,
0
);
else
//如果没有子节点进行更新代码
if
(
childNode
.
size
()
==
1
)
{
updateWrapper
.
eq
(
"id"
,
parentNode
.
getId
()).
set
(
"leaf"
,
1
);
categoryDao
.
update
(
null
,
updateWrapper
);
}
}
}
}
/**
* 设置父级叶子节点
* @param entity
*/
private
void
setParentLeaf
(
CategoryEntity
entity
)
{
private
void
setParentLeaf
(
CategoryEntity
entity
)
{
CategoryEntity
categoryEntity
=
getById
(
entity
.
getId
());
//如果父级不为空并且修改了父级则需要更新父级
if
(
entity
.
getCategoryId
()
!=
null
&&
!
entity
.
getCategoryId
().
equals
(
categoryEntity
.
getCategoryId
()))
{
if
(
entity
.
getCategoryId
()
!=
null
&&
!
entity
.
getCategoryId
().
equals
(
categoryEntity
.
getCategoryId
()))
{
//更新旧的父级
if
(
StrUtil
.
isNotBlank
(
categoryEntity
.
getCategoryId
())&&!
"0"
.
equals
(
categoryEntity
.
getCategoryId
()))
{
if
(
StrUtil
.
isNotBlank
(
categoryEntity
.
getCategoryId
())
&&
!
"0"
.
equals
(
categoryEntity
.
getCategoryId
()))
{
CategoryEntity
parent
=
getById
(
categoryEntity
.
getCategoryId
());
//如果修改了父级则需要判断父级是否还有子节点
boolean
leaf
=
parent
.
getLeaf
();
//查找不等于当前更新的分类子集,有则不是叶子节点
QueryWrapper
<
CategoryEntity
>
queryWrapper
=
new
QueryWrapper
<>();
parent
.
setLeaf
(
count
(
queryWrapper
.
eq
(
"category_id"
,
parent
.
getId
()).
ne
(
"id"
,
entity
.
getId
()))==
0
);
if
(
leaf
!=
parent
.
getLeaf
())
{
parent
.
setLeaf
(
count
(
queryWrapper
.
eq
(
"category_id"
,
parent
.
getId
()).
ne
(
"id"
,
entity
.
getId
()))
==
0
);
if
(
leaf
!=
parent
.
getLeaf
())
{
updateById
(
parent
);
}
}
//更新新的父级
if
(
StrUtil
.
isNotBlank
(
entity
.
getCategoryId
())&&!
"0"
.
equals
(
entity
.
getCategoryId
()))
{
if
(
StrUtil
.
isNotBlank
(
entity
.
getCategoryId
())
&&
!
"0"
.
equals
(
entity
.
getCategoryId
()))
{
CategoryEntity
parent
=
getById
(
entity
.
getCategoryId
());
//如果之前是叶子节点就更新
if
(
parent
.
getLeaf
())
{
if
(
parent
.
getLeaf
())
{
parent
.
setLeaf
(
false
);
updateById
(
parent
);
}
...
...
@@ -266,12 +268,12 @@ public class CategoryBizImpl extends BaseBizImpl<ICategoryDao, CategoryEntity> i
* 设置顶级id
* @param entity
*/
private
void
setTopId
(
CategoryEntity
entity
)
{
private
void
setTopId
(
CategoryEntity
entity
)
{
String
categoryParentId
=
entity
.
getCategoryParentIds
();
if
(
StrUtil
.
isNotBlank
(
categoryParentId
))
{
if
(
StrUtil
.
isNotBlank
(
categoryParentId
))
{
String
[]
ids
=
categoryParentId
.
split
(
","
);
//如果有ParentId就取第一个
if
(
ids
.
length
>
0
)
{
if
(
ids
.
length
>
0
)
{
entity
.
setTopId
(
ids
[
0
]);
return
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment