生成的栏目名为拼音
This commit is contained in:
parent
dd1c671c40
commit
851c2744dd
|
@ -1,5 +1,7 @@
|
||||||
package net.mingsoft.cms.action;
|
package net.mingsoft.cms.action;
|
||||||
|
|
||||||
|
import com.github.stuxuhai.jpinyin.PinyinFormat;
|
||||||
|
import com.github.stuxuhai.jpinyin.PinyinHelper;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParam;
|
||||||
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiImplicitParams;
|
||||||
|
@ -13,6 +15,7 @@ import net.mingsoft.basic.util.BasicUtil;
|
||||||
import net.mingsoft.basic.util.StringUtil;
|
import net.mingsoft.basic.util.StringUtil;
|
||||||
import net.mingsoft.cms.biz.ICategoryBiz;
|
import net.mingsoft.cms.biz.ICategoryBiz;
|
||||||
import net.mingsoft.cms.entity.CategoryEntity;
|
import net.mingsoft.cms.entity.CategoryEntity;
|
||||||
|
import net.mingsoft.cms.util.PinYinUtil;
|
||||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
|
@ -171,6 +174,8 @@ public class CategoryAction extends BaseAction{
|
||||||
if(!StringUtil.checkLength(category.getCategoryParentId()+"", 1, 100)){
|
if(!StringUtil.checkLength(category.getCategoryParentId()+"", 1, 100)){
|
||||||
return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100"));
|
return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100"));
|
||||||
}
|
}
|
||||||
|
//获取拼音
|
||||||
|
|
||||||
category.setAppId(BasicUtil.getAppId());
|
category.setAppId(BasicUtil.getAppId());
|
||||||
categoryBiz.saveEntity(category);
|
categoryBiz.saveEntity(category);
|
||||||
return ResultData.build().success(category);
|
return ResultData.build().success(category);
|
||||||
|
@ -242,6 +247,16 @@ public class CategoryAction extends BaseAction{
|
||||||
if(!StringUtil.checkLength(category.getCategoryParentId()+"", 0, 100)){
|
if(!StringUtil.checkLength(category.getCategoryParentId()+"", 0, 100)){
|
||||||
return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100"));
|
return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100"));
|
||||||
}
|
}
|
||||||
|
String pingYin = PinYinUtil.getPingYin(category.getCategoryTitle());
|
||||||
|
CategoryEntity categoryEntity=new CategoryEntity();
|
||||||
|
categoryEntity.setCategoryPinyin(pingYin);
|
||||||
|
categoryEntity.setAppId(BasicUtil.getAppId());
|
||||||
|
Object categoryBizEntity = categoryBiz.getEntity(categoryEntity);
|
||||||
|
category.setCategoryPinyin(pingYin);
|
||||||
|
//如果存在此拼音栏目则拼接上id
|
||||||
|
if(categoryBizEntity!=null){
|
||||||
|
category.setCategoryPinyin(pingYin+category.getId());
|
||||||
|
}
|
||||||
//判断是否选择子级为所属栏目
|
//判断是否选择子级为所属栏目
|
||||||
CategoryEntity _category = new CategoryEntity();
|
CategoryEntity _category = new CategoryEntity();
|
||||||
_category.setCategoryParentId(category.getId());
|
_category.setCategoryParentId(category.getId());
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
<resultMap id="resultMap" type="net.mingsoft.cms.entity.CategoryEntity">
|
<resultMap id="resultMap" type="net.mingsoft.cms.entity.CategoryEntity">
|
||||||
<id column="id" property="id" /><!--编号 -->
|
<id column="id" property="id" /><!--编号 -->
|
||||||
<result column="category_title" property="categoryTitle" /><!--栏目管理名称 -->
|
<result column="category_title" property="categoryTitle" /><!--栏目管理名称 -->
|
||||||
|
<result column="category_pinyin" property="categoryPinyin" /><!--栏目管理名称 -->
|
||||||
<result column="category_id" property="categoryId" /><!--所属栏目 -->
|
<result column="category_id" property="categoryId" /><!--所属栏目 -->
|
||||||
<result column="category_type" property="categoryType" /><!--栏目管理属性 -->
|
<result column="category_type" property="categoryType" /><!--栏目管理属性 -->
|
||||||
<result column="category_sort" property="categorySort" /><!--自定义顺序 -->
|
<result column="category_sort" property="categorySort" /><!--自定义顺序 -->
|
||||||
|
@ -35,6 +36,7 @@
|
||||||
insert into cms_category
|
insert into cms_category
|
||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<if test="categoryTitle != null and categoryTitle != ''">category_title,</if>
|
<if test="categoryTitle != null and categoryTitle != ''">category_title,</if>
|
||||||
|
<if test="categoryPinyin != null and categoryPinyin != ''">category_pinyin,</if>
|
||||||
<if test="categoryId != null and categoryId != ''">category_id,</if>
|
<if test="categoryId != null and categoryId != ''">category_id,</if>
|
||||||
<if test="categoryType != null and categoryType != ''">category_type,</if>
|
<if test="categoryType != null and categoryType != ''">category_type,</if>
|
||||||
<if test="categorySort != null">category_sort,</if>
|
<if test="categorySort != null">category_sort,</if>
|
||||||
|
@ -60,6 +62,7 @@
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="categoryTitle != null and categoryTitle != ''">#{categoryTitle},</if>
|
<if test="categoryTitle != null and categoryTitle != ''">#{categoryTitle},</if>
|
||||||
|
<if test="categoryPinyin != null and categoryPinyin != ''">#{categoryPinyin},</if>
|
||||||
<if test="categoryId != null and categoryId != ''">#{categoryId},</if>
|
<if test="categoryId != null and categoryId != ''">#{categoryId},</if>
|
||||||
<if test="categoryType != null and categoryType != ''">#{categoryType},</if>
|
<if test="categoryType != null and categoryType != ''">#{categoryType},</if>
|
||||||
<if test="categorySort != null">#{categorySort},</if>
|
<if test="categorySort != null">#{categorySort},</if>
|
||||||
|
@ -90,6 +93,7 @@
|
||||||
update cms_category
|
update cms_category
|
||||||
<set>
|
<set>
|
||||||
<if test="categoryTitle != null and categoryTitle != ''">category_title=#{categoryTitle},</if>
|
<if test="categoryTitle != null and categoryTitle != ''">category_title=#{categoryTitle},</if>
|
||||||
|
<if test="categoryPinyin != null and categoryPinyin != ''">category_pinyin=#{categoryPinyin},</if>
|
||||||
category_id=#{categoryId},
|
category_id=#{categoryId},
|
||||||
category_parent_id=#{categoryParentId},
|
category_parent_id=#{categoryParentId},
|
||||||
<if test="categoryType != null and categoryType != ''">category_type=#{categoryType},</if>
|
<if test="categoryType != null and categoryType != ''">category_type=#{categoryType},</if>
|
||||||
|
@ -126,6 +130,7 @@
|
||||||
select * from cms_category
|
select * from cms_category
|
||||||
<where>
|
<where>
|
||||||
<if test="categoryTitle != null and categoryTitle != ''">and category_title=#{categoryTitle}</if>
|
<if test="categoryTitle != null and categoryTitle != ''">and category_title=#{categoryTitle}</if>
|
||||||
|
<if test="categoryPinyin != null and categoryPinyin != ''">and category_pinyin=#{categoryPinyin}</if>
|
||||||
<if test="categoryId != null and categoryId != ''">and category_id=#{categoryId}</if>
|
<if test="categoryId != null and categoryId != ''">and category_id=#{categoryId}</if>
|
||||||
<if test="categoryType != null and categoryType != ''">and category_type=#{categoryType}</if>
|
<if test="categoryType != null and categoryType != ''">and category_type=#{categoryType}</if>
|
||||||
<if test="categorySort != null"> and category_sort=#{categorySort} </if>
|
<if test="categorySort != null"> and category_sort=#{categorySort} </if>
|
||||||
|
@ -210,6 +215,7 @@
|
||||||
select * from cms_category
|
select * from cms_category
|
||||||
<where>
|
<where>
|
||||||
<if test="categoryTitle != null and categoryTitle != ''"> and category_title=#{categoryTitle}</if>
|
<if test="categoryTitle != null and categoryTitle != ''"> and category_title=#{categoryTitle}</if>
|
||||||
|
<if test="categoryPinyin != null and categoryPinyin != ''">and category_pinyin=#{categoryPinyin}</if>
|
||||||
<if test="categoryId != null and categoryId != ''"> and category_id=#{categoryId}</if>
|
<if test="categoryId != null and categoryId != ''"> and category_id=#{categoryId}</if>
|
||||||
<if test="categoryType != null and categoryType != ''"> and category_type=#{categoryType}</if>
|
<if test="categoryType != null and categoryType != ''"> and category_type=#{categoryType}</if>
|
||||||
<if test="categorySort != null"> and category_sort=#{categorySort} </if>
|
<if test="categorySort != null"> and category_sort=#{categorySort} </if>
|
||||||
|
|
|
@ -20,6 +20,10 @@ private static final long serialVersionUID = 1574925152750L;
|
||||||
*/
|
*/
|
||||||
private String categoryTitle;
|
private String categoryTitle;
|
||||||
/**
|
/**
|
||||||
|
* 栏目别名
|
||||||
|
*/
|
||||||
|
private String categoryPinyin;
|
||||||
|
/**
|
||||||
* 所属栏目
|
* 所属栏目
|
||||||
*/
|
*/
|
||||||
private String categoryId;
|
private String categoryId;
|
||||||
|
@ -112,6 +116,14 @@ private static final long serialVersionUID = 1574925152750L;
|
||||||
this.categoryId = categoryId;
|
this.categoryId = categoryId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getCategoryPinyin() {
|
||||||
|
return categoryPinyin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategoryPinyin(String categoryPinyin) {
|
||||||
|
this.categoryPinyin = categoryPinyin;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取所属栏目
|
* 获取所属栏目
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
package net.mingsoft.cms.util;
|
||||||
|
|
||||||
|
import com.github.stuxuhai.jpinyin.PinyinException;
|
||||||
|
import com.github.stuxuhai.jpinyin.PinyinFormat;
|
||||||
|
import com.github.stuxuhai.jpinyin.PinyinHelper;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author by 铭飞开源团队
|
||||||
|
* @Description TODO
|
||||||
|
* @date 2020/6/16 14:40
|
||||||
|
*/
|
||||||
|
public class PinYinUtil {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将字符串中的中文转化为拼音,其他字符不变
|
||||||
|
*
|
||||||
|
* @param inputString
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getPingYin(String inputString) {
|
||||||
|
if (!StringUtils.isBlank(inputString)) {
|
||||||
|
try {
|
||||||
|
return PinyinHelper.convertToPinyinString(inputString,"", PinyinFormat.WITHOUT_TONE);
|
||||||
|
} catch (PinyinException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws PinyinException {
|
||||||
|
System.out.println(getPingYin("哈哈6666"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue