diff --git a/src/main/java/net/mingsoft/cms/action/CategoryAction.java b/src/main/java/net/mingsoft/cms/action/CategoryAction.java index e8b1861d..1552d5cc 100644 --- a/src/main/java/net/mingsoft/cms/action/CategoryAction.java +++ b/src/main/java/net/mingsoft/cms/action/CategoryAction.java @@ -1,10 +1,12 @@ package net.mingsoft.cms.action; import cn.hutool.core.util.StrUtil; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; +import net.mingsoft.base.entity.BaseEntity; import net.mingsoft.base.entity.ResultData; import net.mingsoft.basic.annotation.LogAnn; import net.mingsoft.basic.bean.EUListBean; @@ -282,6 +284,18 @@ public class CategoryAction extends BaseAction { return ResultData.build().success(category); } + @ApiOperation(value = "验证拼音") + @GetMapping("/verifyPingYin") + @ResponseBody + public ResultData verifyPingYin(@ModelAttribute @ApiIgnore CategoryEntity category, HttpServletResponse response, HttpServletRequest request, @ApiIgnore ModelMap model){ + int count = categoryBiz.count(Wrappers.lambdaQuery() + .ne(StrUtil.isNotBlank(category.getId()), CategoryEntity::getId, category.getId()) + .eq(CategoryEntity::getCategoryPinyin, category.getCategoryPinyin())); + if(count>0){ + return ResultData.build().error("存在相同拼音的栏目"); + } + return ResultData.build().success(); + } } 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 32a32c9a..0f6bca5e 100644 --- a/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java +++ b/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java @@ -108,6 +108,7 @@ public class CategoryBizImpl extends BaseBizImpl i //保存链接地址 String path=ObjectUtil.isNotNull(parentCategory)?parentCategory.getCategoryPath():""; categoryEntity.setCategoryPath( path+"/" + categoryEntity.getCategoryPinyin()); + removeVirgule(categoryEntity); setTopId(categoryEntity); super.updateById(categoryEntity); } @@ -144,6 +145,8 @@ public class CategoryBizImpl extends BaseBizImpl i String path=categoryEntity.getCategoryPath(); //判断是否有parentIds x.setCategoryPath(path+"/"+x.getCategoryPinyin()); + //去除多余的/符号 + removeVirgule(x); super.updateEntity(x); setChildParentId(x); }); @@ -152,7 +155,8 @@ public class CategoryBizImpl extends BaseBizImpl i @Override public void updateEntity(CategoryEntity entity) { setParentId(entity); - String pingYin = PinYinUtil.getPingYin(entity.getCategoryTitle()); + String pingYin =entity.getCategoryPinyin(); + if(StrUtil.isNotBlank(pingYin)){ CategoryEntity category=new CategoryEntity(); category.setCategoryPinyin(pingYin); CategoryEntity categoryBizEntity = (CategoryEntity)getEntity(category); @@ -160,12 +164,24 @@ public class CategoryBizImpl extends BaseBizImpl i if(categoryBizEntity!=null&&!categoryBizEntity.getId().equals(entity.getId())){ entity.setCategoryPinyin(pingYin+entity.getId()); } + } setParentLeaf(entity); setTopId(entity); + removeVirgule(entity); super.updateById(entity); setChildParentId(entity); } + /**去除多余的/符号 + * @param entity + */ + private void removeVirgule(CategoryEntity entity) { + + if (entity.getCategoryPath().startsWith("/")) { + entity.setCategoryPath(entity.getCategoryPath().substring(1)); + } + } + @Override public void update(CategoryEntity entity) { super.updateEntity(entity); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 9e57c903..654f82c6 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -84,7 +84,6 @@ spring: mybatis-plus: global-config: db-config: - column-format: "\"%s\"" #增加这个需要增加 ms-db id-type: assign_id configuration: database-id: mysql \ No newline at end of file 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 a46871b2..fecae319 100644 --- a/src/main/webapp/WEB-INF/manager/cms/category/form.ftl +++ b/src/main/webapp/WEB-INF/manager/cms/category/form.ftl @@ -253,6 +253,21 @@ var form = new Vue({ el: '#form', data: function () { + var that = this + //验证拼音是否存在 + var validatorCategoryPinyin = function (rule, value, callback) { + // + ms.http.get(ms.manager+'/cms/category/verifyPingYin.do',{ + id:that.form.id, + categoryPinyin:that.form.categoryPinyin, + }).then(function (res) { + if(!res.result){ + callback(new Error(res.msg)); + }else { + return callback(); + } + }) + } return { treeList: [{ id: '0', @@ -318,6 +333,11 @@ "required": true, "message": "请选择列表模板" }], + categoryPinyin:[ + { + validator: validatorCategoryPinyin, trigger: 'blur' + } + ], // 内容模板 categoryUrl: [{ "required": true,