fix(RoleController.java): 添加角色时名称重复页面报错

Closes I3ZONS
This commit is contained in:
haoxr 2021-07-08 23:03:49 +08:00
parent c53ba2864e
commit 3c75c1b85a
15 changed files with 26 additions and 19 deletions

View File

@ -157,10 +157,14 @@ youlai-mall
| ------------------------------------------------------------ | ------------------------------------------------------------ |
| ![image-20210622000304570](https://gitee.com/haoxr/image/raw/master/image-20210622000304570.png) | ![image-20210622000046029](https://gitee.com/haoxr/image/raw/master/image-20210622000046029.png) |
## 项目文档
[项目文档地址](https://www.cnblogs.com/haoxianrui/)
## Stargazers over time
## Star趋势
- Github
[![Github](https://starchart.cc/hxrui/youlai-mall.svg)](https://starchart.cc/hxrui/youlai-mall)
- Gitee
[![Gitee](https://whnb.wang/stars/youlaitech/youlai-mall)](https://whnb.wang/stars/youlaitech/youlai-mall)
## contributors
@ -168,7 +172,7 @@ youlai-mall
## 联系信息
因为微信交流群超过200人了只能通过邀请进入群聊添加开发人员PS:日常上班时间建议选择没有头像的)后由其拉进群,相互交流学习,备注“**有来**”即可
因为微信交流群满200人只能通过邀请进入如果想进入交流群学习可添加以下开发人员备注“**有来**“由其拉进群
| ![](https://gitee.com/haoxr/image/raw/master/default/113__6c5ed5b1b73ea9cd4cf32848ed350c07_b9b214638a2a406e52dbf51e9bf9a2ef.png) | ![](https://gitee.com/haoxr/image/raw/master/hxr.jpg) | ![](https://gitee.com/haoxr/image/raw/master/huawei.jpg) | ![](https://gitee.com/haoxr/image/raw/master/default/1625149769(1).png) |
| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |

View File

@ -23,7 +23,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.lang.Assert;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import cn.hutool.core.util.IdUtil;
import com.youlai.admin.service.impl.MinioService;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil;
@ -90,9 +90,11 @@ public class RoleController {
@PostMapping
public Result add(@RequestBody SysRole role) {
int count = iSysRoleService.count(new LambdaQueryWrapper<SysRole>()
.eq(SysRole::getCode, role.getCode())
.eq(SysRole::getCode, role.getCode() )
.or()
.eq(SysRole::getName,role.getName())
);
Assert.isTrue(count == 0, "角色编码已存在");
Assert.isTrue(count == 0, "角色名称或角色编码重复,请检查!");
boolean result = iSysRoleService.save(role);
return Result.judge(result);
}
@ -108,9 +110,11 @@ public class RoleController {
@RequestBody SysRole role) {
int count = iSysRoleService.count(new LambdaQueryWrapper<SysRole>()
.eq(SysRole::getCode, role.getCode())
.or()
.eq(SysRole::getName,role.getName())
.ne(SysRole::getId, id)
);
Assert.isTrue(count == 0, "角色编码已存在");
Assert.isTrue(count == 0, "角色名称或角色编码重复,请检查!");
boolean result = iSysRoleService.updateById(role);
if (result) {
iSysPermissionService.refreshPermRolesRules();

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import com.youlai.admin.pojo.vo.RouteVO;
import com.youlai.admin.service.ISysMenuService;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import com.youlai.admin.service.ITokenService;
import com.youlai.common.result.Result;

View File

@ -1,4 +1,4 @@
package com.youlai.admin.controller.v1;
package com.youlai.admin.controller;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

View File

@ -6,7 +6,6 @@ import cn.hutool.core.util.StrUtil;
import com.youlai.common.constant.AuthConstants;
import com.youlai.common.constant.GlobalConstants;
import com.youlai.gateway.component.UrlPermRolesLocalCache;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;