浏览代码

栏目分类新增拼音

xierz 5 年之前
父节点
当前提交
1a95a6978e

+ 23 - 1
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<CategoryEntity> 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<CategoryEntity> 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);

+ 4 - 1
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<ICategoryDao, CategoryEntity> 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);

+ 1 - 0
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

+ 20 - 0
src/main/webapp/WEB-INF/manager/cms/category/form.ftl

@@ -169,6 +169,24 @@
                         </el-form-item>
                     </el-col>
                 </el-row>
+                <el-row
+                        :gutter="0"
+                        justify="start" align="top">
+                    <el-col :span="12">
+                        <el-form-item  label="栏目拼音" prop="categoryPinyin">
+                            <el-input
+                                    v-model="form.categoryPinyin"
+                                    :disabled="false"
+                                    :readonly="false"
+                                    :style="{width:  '100%'}"
+                                    :clearable="true"
+                                    placeholder="默认拼音根据名称生成">
+                            </el-input>
+                        </el-form-item>
+                    </el-col>
+                    <el-col :span="12">
+                    </el-col>
+                </el-row>
                 <el-form-item label="栏目管理关键字" prop="categoryKeyword" >
                     <template slot='label'>栏目关键字
                         <el-popover slot="label" placement="top-start" title="提示" trigger="hover">
@@ -258,6 +276,8 @@
                     categoryListUrl: '',
                     // 内容模板
                     categoryUrl: '',
+                    // 栏目拼音
+                    categoryPinyin: '',
                     // 栏目管理关键字
                     categoryKeyword: '',
                     // 栏目管理描述