diff --git a/src/main/java/net/mingsoft/cms/action/CategoryAction.java b/src/main/java/net/mingsoft/cms/action/CategoryAction.java index cce498d4..a8dd7bb6 100644 --- a/src/main/java/net/mingsoft/cms/action/CategoryAction.java +++ b/src/main/java/net/mingsoft/cms/action/CategoryAction.java @@ -1,5 +1,6 @@ package net.mingsoft.cms.action; +import cn.hutool.core.util.StrUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; @@ -166,7 +167,15 @@ public class CategoryAction extends BaseAction { if(!StringUtil.checkLength(category.getCategoryParentId()+"", 1, 100)){ return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100")); } - //获取拼音 + //判断拼音是否重复 + if(StrUtil.isNotBlank(category.getCategoryPinyin())) { + CategoryEntity _category = new CategoryEntity(); + _category.setCategoryPinyin(category.getCategoryPinyin()); + List query = categoryBiz.query(_category); + if (query.size() > 0) { + return ResultData.build().error(getResString("err.exist", this.getResString("category.pinyin"))); + } + } categoryBiz.saveEntity(category); return ResultData.build().success(category); @@ -238,7 +247,20 @@ public class CategoryAction extends BaseAction { if(!StringUtil.checkLength(category.getCategoryParentId()+"", 0, 100)){ return ResultData.build().error(getResString("err.length", this.getResString("category.parent.id"), "1", "100")); } + //判断拼音是否重复并且是否和原拼音相同 + if(StrUtil.isNotBlank(category.getCategoryPinyin()) && !categoryBiz.getById(category.getId()).getCategoryPinyin().equals(category.getCategoryPinyin())) { + CategoryEntity _category = new CategoryEntity(); + _category.setCategoryPinyin(category.getCategoryPinyin()); + List query = categoryBiz.query(_category); + if (query.size() > 0) { + return ResultData.build().error(getResString("err.exist", this.getResString("category.pinyin"))); + } + } String pingYin = PinYinUtil.getPingYin(category.getCategoryTitle()); + //如果用户填写了拼音则使用用户填写的 + if (StrUtil.isNotBlank(category.getCategoryPinyin())) { + pingYin = category.getCategoryPinyin(); + } CategoryEntity categoryEntity=new CategoryEntity(); categoryEntity.setCategoryPinyin(pingYin); CategoryEntity categoryBizEntity = (CategoryEntity)categoryBiz.getEntity(categoryEntity); 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 25d484ba..32a32c9a 100644 --- a/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java +++ b/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java @@ -27,7 +27,6 @@ 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; import net.mingsoft.basic.util.PinYinUtil; import net.mingsoft.cms.biz.ICategoryBiz; import net.mingsoft.cms.dao.ICategoryDao; @@ -74,6 +73,10 @@ public class CategoryBizImpl extends BaseBizImpl i public void saveEntity(CategoryEntity categoryEntity) { // TODO Auto-generated method stub String pingYin = PinYinUtil.getPingYin(categoryEntity.getCategoryTitle()); + //如果用户自己填入了拼音则使用用户的 + if (StrUtil.isNotBlank(categoryEntity.getCategoryPinyin())) { + pingYin = categoryEntity.getCategoryPinyin(); + } CategoryEntity category=new CategoryEntity(); category.setCategoryPinyin(pingYin); Object categoryBizEntity = getEntity(category); diff --git a/src/main/java/net/mingsoft/cms/resources/resources_zh_CN.properties b/src/main/java/net/mingsoft/cms/resources/resources_zh_CN.properties index 4bf15c7b..6ebd4bd5 100644 --- a/src/main/java/net/mingsoft/cms/resources/resources_zh_CN.properties +++ b/src/main/java/net/mingsoft/cms/resources/resources_zh_CN.properties @@ -34,3 +34,4 @@ content.sort=\u81EA\u5B9A\u4E49\u987A\u5E8F category.diy.url=\u81EA\u5B9A\u4E49\u94FE\u63A5 content.keyword=\u5173\u952E\u5B57 templet.file=\u672A\u627E\u5230\u6A21\u677F\u6587\u4EF6 +category.pinyin=\u62FC\u97F3 diff --git a/src/main/webapp/WEB-INF/manager/cms/category/form.ftl b/src/main/webapp/WEB-INF/manager/cms/category/form.ftl index c1d0f32a..a46871b2 100644 --- a/src/main/webapp/WEB-INF/manager/cms/category/form.ftl +++ b/src/main/webapp/WEB-INF/manager/cms/category/form.ftl @@ -169,6 +169,24 @@ + + + + + + + + + +