|
|
|
@ -23,7 +23,9 @@ package net.mingsoft.cms.biz.impl; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import cn.hutool.core.util.ObjectUtil; |
|
|
|
import net.mingsoft.base.entity.BaseEntity; |
|
|
|
import net.mingsoft.base.entity.BaseEntity; |
|
|
|
|
|
|
|
import net.mingsoft.basic.util.BasicUtil; |
|
|
|
import net.mingsoft.cms.entity.CategoryEntity; |
|
|
|
import net.mingsoft.cms.entity.CategoryEntity; |
|
|
|
|
|
|
|
import net.mingsoft.cms.util.PinYinUtil; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
@ -64,22 +66,30 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void saveEntity(CategoryEntity categoryEntity) { |
|
|
|
public void saveEntity(CategoryEntity categoryEntity) { |
|
|
|
// TODO Auto-generated method stub
|
|
|
|
// TODO Auto-generated method stub
|
|
|
|
|
|
|
|
String pingYin = PinYinUtil.getPingYin(categoryEntity.getCategoryTitle()); |
|
|
|
|
|
|
|
CategoryEntity category=new CategoryEntity(); |
|
|
|
|
|
|
|
category.setCategoryPinyin(pingYin); |
|
|
|
|
|
|
|
category.setAppId(BasicUtil.getAppId()); |
|
|
|
|
|
|
|
Object categoryBizEntity = getEntity(category); |
|
|
|
setParentId(categoryEntity); |
|
|
|
setParentId(categoryEntity); |
|
|
|
|
|
|
|
categoryEntity.setCategoryPinyin(pingYin); |
|
|
|
super.saveEntity(categoryEntity); |
|
|
|
super.saveEntity(categoryEntity); |
|
|
|
//保存链接地址
|
|
|
|
//拼音存在则拼接id
|
|
|
|
String path=ObjectUtil.isNotNull(categoryEntity.getCategoryParentId())?categoryEntity.getCategoryParentId():""; |
|
|
|
if(categoryBizEntity!=null){ |
|
|
|
//判断是否有parentIds
|
|
|
|
categoryEntity.setCategoryPinyin(pingYin+categoryEntity.getId()); |
|
|
|
if(StringUtils.isNotBlank(path)){ |
|
|
|
|
|
|
|
categoryEntity.setCategoryPath("/" + path.replaceAll(",", "/") + "/" + categoryEntity.getId()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
categoryEntity.setCategoryPath("/" + categoryEntity.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
CategoryEntity parentCategory = (CategoryEntity)categoryDao.getEntity(Integer.parseInt(categoryEntity.getCategoryId())); |
|
|
|
|
|
|
|
//保存链接地址
|
|
|
|
|
|
|
|
String path=ObjectUtil.isNotNull(parentCategory)?categoryEntity.getCategoryPath():""; |
|
|
|
|
|
|
|
categoryEntity.setCategoryPath( path+"/" + categoryEntity.getCategoryPinyin()); |
|
|
|
super.updateEntity(categoryEntity); |
|
|
|
super.updateEntity(categoryEntity); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void setParentId(CategoryEntity categoryEntity) { |
|
|
|
private void setParentId(CategoryEntity categoryEntity) { |
|
|
|
|
|
|
|
String path = ""; |
|
|
|
if(StringUtils.isNotEmpty(categoryEntity.getCategoryId())&&Integer.parseInt(categoryEntity.getCategoryId())>0) { |
|
|
|
if(StringUtils.isNotEmpty(categoryEntity.getCategoryId())&&Integer.parseInt(categoryEntity.getCategoryId())>0) { |
|
|
|
CategoryEntity category = (CategoryEntity)categoryDao.getEntity(Integer.parseInt(categoryEntity.getCategoryId())); |
|
|
|
CategoryEntity category = (CategoryEntity)categoryDao.getEntity(Integer.parseInt(categoryEntity.getCategoryId())); |
|
|
|
|
|
|
|
path = category.getCategoryPath(); |
|
|
|
if(StringUtils.isEmpty(category.getCategoryParentId())) { |
|
|
|
if(StringUtils.isEmpty(category.getCategoryParentId())) { |
|
|
|
categoryEntity.setCategoryParentId(category.getId()); |
|
|
|
categoryEntity.setCategoryParentId(category.getId()); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
@ -90,13 +100,7 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz { |
|
|
|
} |
|
|
|
} |
|
|
|
//保存时先保存再修改链接地址,修改时直接修改
|
|
|
|
//保存时先保存再修改链接地址,修改时直接修改
|
|
|
|
if(StringUtils.isNotBlank(categoryEntity.getId())) { |
|
|
|
if(StringUtils.isNotBlank(categoryEntity.getId())) { |
|
|
|
String path = ObjectUtil.isNotNull(categoryEntity.getCategoryParentId()) ? categoryEntity.getCategoryParentId() : ""; |
|
|
|
categoryEntity.setCategoryPath(path+ "/" + categoryEntity.getCategoryPinyin()); |
|
|
|
//判断是否有parentIds
|
|
|
|
|
|
|
|
if(StringUtils.isNotBlank(path)){ |
|
|
|
|
|
|
|
categoryEntity.setCategoryPath("/" + path.replaceAll(",", "/") + "/" + categoryEntity.getId()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
categoryEntity.setCategoryPath("/" + categoryEntity.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
@ -110,13 +114,9 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz { |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
x.setCategoryParentId(categoryEntity.getCategoryParentId()+","+categoryEntity.getId()); |
|
|
|
x.setCategoryParentId(categoryEntity.getCategoryParentId()+","+categoryEntity.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
String path=ObjectUtil.isNotNull(x.getCategoryParentId())?x.getCategoryParentId():""; |
|
|
|
String path=categoryEntity.getCategoryPath(); |
|
|
|
//判断是否有parentIds
|
|
|
|
//判断是否有parentIds
|
|
|
|
if(StringUtils.isNotBlank(path)){ |
|
|
|
x.setCategoryPath(path+"/"+x.getCategoryPinyin()); |
|
|
|
x.setCategoryPath("/"+path.replaceAll(",","/")+"/"+x.getId()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
x.setCategoryPath("/"+x.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
super.updateEntity(x); |
|
|
|
super.updateEntity(x); |
|
|
|
setChildParentId(x); |
|
|
|
setChildParentId(x); |
|
|
|
}); |
|
|
|
}); |
|
|
|
@ -125,6 +125,15 @@ public class CategoryBizImpl extends BaseBizImpl implements ICategoryBiz { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void updateEntity(CategoryEntity entity) { |
|
|
|
public void updateEntity(CategoryEntity entity) { |
|
|
|
setParentId(entity); |
|
|
|
setParentId(entity); |
|
|
|
|
|
|
|
String pingYin = PinYinUtil.getPingYin(entity.getCategoryTitle()); |
|
|
|
|
|
|
|
CategoryEntity category=new CategoryEntity(); |
|
|
|
|
|
|
|
category.setCategoryPinyin(pingYin); |
|
|
|
|
|
|
|
category.setAppId(BasicUtil.getAppId()); |
|
|
|
|
|
|
|
CategoryEntity categoryBizEntity = (CategoryEntity)getEntity(category); |
|
|
|
|
|
|
|
//拼音存在则拼接id
|
|
|
|
|
|
|
|
if(categoryBizEntity!=null&&!categoryBizEntity.getId().equals(entity.getId())){ |
|
|
|
|
|
|
|
entity.setCategoryPinyin(pingYin+entity.getId()); |
|
|
|
|
|
|
|
} |
|
|
|
super.updateEntity(entity); |
|
|
|
super.updateEntity(entity); |
|
|
|
setChildParentId(entity); |
|
|
|
setChildParentId(entity); |
|
|
|
} |
|
|
|
} |
|
|
|
|