Commit 526e05aa authored by fangxinjiang's avatar fangxinjiang

代码优化

parent e0dbda54
......@@ -128,6 +128,4 @@ public interface CommonConstants {
* hgw 2022-6-9 17:36:35
*/
String DOWN_LINE = "_";
String EXIST_ENTITY = "已存在唯一性的数据";
}
......@@ -127,4 +127,18 @@ public interface ErrorCodes {
* 系统内置用户不允许修改
*/
String SYS_USER_UPDATE_SYSTEM = "sys.user.update.system";
/**
* 已存在对应标识的角色
*/
String SYS_ROLE_UPDATE_ERROR_CODE_EXIST= "sys.role.update.error.code.exist";
/**
* 已存在对应名称的菜单
*/
String SYS_MENU_ADD_NAME_EXIST = "sys_menu_add_name_exist";
/**
* 已存在对应名称的角色
*/
String SYS_ROLE_UPDATE_ERROR_NAME_EXIST ="sys.role.update.error.name.exist";
}
......@@ -2,6 +2,8 @@ sys.user.update.passwordError=\u539F\u5BC6\u7801\u9519\u8BEF\uFF0C\u4FEE\u6539\u
sys.user.query.error=\u83B7\u53D6\u5F53\u524D\u7528\u6237\u4FE1\u606F\u5931\u8D25
sys.user.username.existing={0} \u7528\u6237\u540D\u5DF2\u5B58\u5728
sys.user.userInfo.empty={0} \u7528\u6237\u4FE1\u606F\u4E3A\u7A7A
sys.user.update.system=\u7CFB\u7EDF\u5185\u7F6E\u7528\u6237\u4E0D\u80FD\u4FEE\u6539
sys.user.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u7528\u6237\u4E0D\u80FD\u5220\u9664
sys.dept.deptName.inexistence={0} \u90E8\u95E8\u540D\u79F0\u4E0D\u5B58\u5728
......@@ -10,27 +12,29 @@ sys.post.nameOrCode.existing={0} {1} \u5C97\u4F4D\u540D\u6216\u5C97\u4F4D\u7F16\
sys.role.roleName.inexistence={0} \u89D2\u8272\u540D\u79F0\u4E0D\u5B58\u5728
sys.role.nameOrCode.existing={0} {1} \u89D2\u8272\u540D\u6216\u89D2\u8272\u7F16\u7801\u5DF2\u7ECF\u5B58\u5728
sys.role.update.error.name.exist=\u5DF2\u5B58\u5728\u5BF9\u5E94\u540D\u79F0\u7684\u89D2\u8272
sys.param.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u53C2\u6570\u4E0D\u80FD\u5220\u9664
sys.param.config.error={0} \u7CFB\u7EDF\u53C2\u6570\u914D\u7F6E\u9519\u8BEF
sys.menu.delete.existing=\u83DC\u5355\u542B\u6709\u4E0B\u7EA7\u4E0D\u80FD\u5220\u9664
sys.menu.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u83DC\u5355\u4E0D\u80FD\u5220\u9664
sys.menu.add.parent.error=\u83DC\u5355\u4E0A\u7EA7\u83DC\u5355\u4E0D\u53EF\u4E3A\u6570\u636E\u6743\u9650\u914D\u7F6E\u7C7B\u83DC\u5355
sys_menu_add_name_exist="\u5DF2\u5B58\u5728\u5BF9\u5E94\u540D\u79F0\u7684\u83DC\u5355"
sys.app.sms.often=\u9A8C\u8BC1\u7801\u53D1\u9001\u8FC7\u9891\u7E41
sys.app.phone.unregistered={0} \u624B\u673A\u53F7\u672A\u6CE8\u518C
sys.dict.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u5B57\u5178\u9879\u76EE\u4E0D\u80FD\u5220\u9664
sys.dict.update.system=\u7CFB\u7EDF\u5185\u7F6E\u5B57\u5178\u9879\u76EE\u4E0D\u80FD\u4FEE\u6539
sys.dict.delete.existing=\u5B57\u5178\u5B58\u5728\u4E0B\u7EA7\u8282\u70B9\u4E0D\u80FD\u5220\u9664
sys.role.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u89D2\u8272\u4E0D\u80FD\u5220\u9664
sys.role.update.system=\u7CFB\u7EDF\u5185\u7F6E\u89D2\u8272\u4E0D\u80FD\u4FEE\u6539
sys.role.update.error.code.exist="\u5DF2\u5B58\u5728\u5BF9\u5E94\u6807\u8BC6\u7684\u89D2\u8272"
sys.role.delete.existing.user=\u8BE5\u89D2\u8272\u4E0B\u8FD8\u6709\u5173\u8054\u7684\u7528\u6237\uFF0C\u8BF7\u5148\u5C06\u7528\u6237\u8F6C\u79FB\u5230\u5176\u4ED6\u89D2\u8272!
sys.user.update.system=\u7CFB\u7EDF\u5185\u7F6E\u7528\u6237\u4E0D\u80FD\u4FEE\u6539
sys.user.delete.system=\u7CFB\u7EDF\u5185\u7F6E\u7528\u6237\u4E0D\u80FD\u5220\u9664
......@@ -18,9 +18,14 @@ package com.yifu.cloud.plus.v1.yifu.admin.controller;
import cn.hutool.core.lang.tree.Tree;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yifu.cloud.plus.v1.yifu.admin.api.entity.SysMenu;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysMenuService;
import com.yifu.cloud.plus.v1.yifu.common.core.constant.CommonConstants;
import com.yifu.cloud.plus.v1.yifu.common.core.exception.ErrorCodes;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.MsgUtils;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import com.yifu.cloud.plus.v1.yifu.common.security.util.SecurityUtils;
......@@ -33,6 +38,7 @@ import javax.validation.Valid;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.WeakHashMap;
import java.util.stream.Collectors;
/**
......@@ -124,6 +130,14 @@ public class MenuController {
@PostMapping
@PreAuthorize("@pms.hasPermission('sys_menu_add')")
public R<SysMenu> save(@Valid @RequestBody SysMenu sysMenu) {
if (CommonConstants.ZERO_STRING.equals(sysMenu.getType())){
SysMenu sm = sysMenuService.getOne(Wrappers.<SysMenu>query().lambda()
.eq(SysMenu::getName,sysMenu.getName())
.eq(SysMenu::getDelFlag,CommonConstants.ZERO_STRING));
if (Common.isNotNull(sm)){
return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_MENU_ADD_NAME_EXIST));
}
}
SysMenu menu = sysMenuService.saveAsso(sysMenu);
return R.ok(menu);
}
......@@ -149,6 +163,15 @@ public class MenuController {
@PutMapping
@PreAuthorize("@pms.hasPermission('sys_menu_edit')")
public R<Boolean> update(@Valid @RequestBody SysMenu sysMenu) {
if (CommonConstants.ZERO_STRING.equals(sysMenu.getType())){
SysMenu sm = sysMenuService.getOne(Wrappers.<SysMenu>query().lambda()
.eq(SysMenu::getName,sysMenu.getName())
.eq(SysMenu::getDelFlag,CommonConstants.ZERO_STRING)
.ne(SysMenu::getMenuId,sysMenu.getMenuId()));
if (Common.isNotNull(sm)){
return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_MENU_ADD_NAME_EXIST));
}
}
return R.ok(sysMenuService.updateMenuById(sysMenu));
}
......
......@@ -26,6 +26,7 @@ import com.yifu.cloud.plus.v1.yifu.admin.api.vo.RoleExcelVO;
import com.yifu.cloud.plus.v1.yifu.admin.api.vo.RoleVo;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysRoleMenuService;
import com.yifu.cloud.plus.v1.yifu.admin.service.SysRoleService;
import com.yifu.cloud.plus.v1.yifu.common.core.util.Common;
import com.yifu.cloud.plus.v1.yifu.common.core.util.R;
import com.yifu.cloud.plus.v1.yifu.common.log.annotation.SysLog;
import io.swagger.v3.oas.annotations.tags.Tag;
......@@ -70,9 +71,16 @@ public class RoleController {
@PostMapping
@PreAuthorize("@pms.hasPermission('sys_role_add')")
public R<Boolean> save(@Valid @RequestBody SysRole sysRole) {
R<Boolean> check = sysRoleService.getBooleanR(sysRole);
if ( Common.isNotNull(check)) {
return check;
}
return R.ok(sysRoleService.save(sysRole));
}
/**
* 修改角色
* @param sysRole 角色信息
......@@ -81,7 +89,11 @@ public class RoleController {
@SysLog("修改角色")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys_role_edit')")
public R update(@Valid @RequestBody SysRole sysRole) {
public R<Boolean> update(@Valid @RequestBody SysRole sysRole) {
R<Boolean> check = sysRoleService.getBooleanR(sysRole);
if ( Common.isNotNull(check)) {
return check;
}
sysRoleService.updateRoleById(sysRole);
return R.ok();
}
......
......@@ -64,4 +64,12 @@ public interface SysRoleService extends IService<SysRole> {
*/
void updateRoleById(SysRole sysRole);
/**
* @Author fxj
* @Description 验证角色名称和角色编码
* @Date 17:23 2022/6/14
* @Param
* @return
**/
R<Boolean> getBooleanR(SysRole sysRole);
}
......@@ -239,6 +239,7 @@ public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> impl
extra.put("sortOrder", menu.getSortOrder());
extra.put("keepAlive", menu.getKeepAlive());
extra.put("systemFlag",menu.getSystemFlag());
extra.put("flag",menu.getFlag());
node.setExtra(extra);
return node;
};
......
......@@ -183,5 +183,42 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
MsgUtils.getMessage(ErrorCodes.SYS_ROLE_UPDATE_SYSTEM));
this.updateById(sysRole);
}
/**
* @Author fxj
* @Description 验证角色名称和角色编码
* @Date 17:23 2022/6/14
* @Param type 0 名称 1 编码
* @return
**/
@Override
public R<Boolean> getBooleanR(SysRole sysRole) {
SysRole role = baseMapper.selectOne(buildCheckQueryWrapper(sysRole,CommonConstants.ONE_STRING));
if (Common.isNotNull(role) && Common.isNotNull(sysRole.getRoleCode())){
return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_ROLE_UPDATE_ERROR_CODE_EXIST));
}
role = baseMapper.selectOne(buildCheckQueryWrapper(sysRole,CommonConstants.ZERO_STRING));
if (Common.isNotNull(role) && Common.isNotNull(sysRole.getRoleName())){
return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_ROLE_UPDATE_ERROR_NAME_EXIST));
}
return null;
}
private LambdaQueryWrapper buildCheckQueryWrapper(SysRole sysRole, String type) {
LambdaQueryWrapper<SysRole> wrapper = Wrappers.lambdaQuery();
if (Common.isNotNull(sysRole.getRoleId())){
wrapper.ne(SysRole::getRoleId,sysRole.getRoleId());
}
if (CommonConstants.ZERO_STRING.equals(type)){
if (StrUtil.isNotBlank(sysRole.getRoleName())){
wrapper.likeRight(SysRole::getRoleName,sysRole.getRoleName());
}
}
if (CommonConstants.ONE_STRING.equals(type)){
if (StrUtil.isNotBlank(sysRole.getRoleCode())){
wrapper.likeRight(SysRole::getRoleCode,sysRole.getRoleCode());
}
}
wrapper.last(CommonConstants.LAST_ONE_SQL);
return wrapper;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment