diff --git a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/ErrorCodes.java b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/ErrorCodes.java index 2a4a7ca9..36696ec2 100644 --- a/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/ErrorCodes.java +++ b/pig-common/pig-common-core/src/main/java/com/pig4cloud/pig/common/core/exception/ErrorCodes.java @@ -13,9 +13,79 @@ public interface ErrorCodes { */ String SYS_PARAM_CONFIG_ERROR = "sys.param.config.error"; + /** + * 系统内置参数不能删除 + */ + String SYS_PARAM_DELETE_SYSTEM = "sys.param.delete.system"; + /** * 用户已存在 */ String SYS_USER_USERNAME_EXISTING = "sys.user.username.existing"; + /** + * 用户原密码错误,修改失败 + */ + String SYS_USER_UPDATE_PASSWORDERROR = "sys.user.update.passwordError"; + + /** + * 用户信息为空 + */ + String SYS_USER_USERINFO_EMPTY = "sys.user.userInfo.empty"; + + /** + * 获取当前用户信息失败 + */ + String SYS_USER_QUERY_ERROR = "sys.user.query.error"; + + /** + * 部门名称不存在 + */ + String SYS_DEPT_DEPTNAME_INEXISTENCE = "sys.dept.deptName.inexistence"; + + /** + * 岗位名称不存在 + */ + String SYS_POST_POSTNAME_INEXISTENCE = "sys.post.postName.inexistence"; + + /** + * 岗位名称或编码已经存在 + */ + String SYS_POST_NAMEORCODE_EXISTING = "sys.post.nameOrCode.existing"; + + /** + * 角色名称不存在 + */ + String SYS_ROLE_ROLENAME_INEXISTENCE = "sys.role.roleName.inexistence"; + + /** + * 角色名或角色编码已经存在 + */ + String SYS_ROLE_NAMEORCODE_EXISTING = "sys.role.nameOrCode.existing"; + + /** + * 菜单存在下级节点 删除失败 + */ + String SYS_MENU_DELETE_EXISTING = "sys.menu.delete.existing"; + + /** + * 系统内置字典不允许删除 + */ + String SYS_DICT_DELETE_SYSTEM = "sys.dict.delete.system"; + + /** + * 系统内置字典不能修改 + */ + String SYS_DICT_UPDATE_SYSTEM = "sys.dict.update.system"; + + /** + * 验证码发送频繁 + */ + String SYS_APP_SMS_OFTEN = "sys.app.sms.often"; + + /** + * 手机号未注册 + */ + String SYS_APP_PHONE_UNREGISTERED = "sys.app.phone.unregistered"; + } diff --git a/pig-common/pig-common-core/src/main/resources/i18n/messages_zh_CN.properties b/pig-common/pig-common-core/src/main/resources/i18n/messages_zh_CN.properties index 5011630f..4f8556ab 100644 --- a/pig-common/pig-common-core/src/main/resources/i18n/messages_zh_CN.properties +++ b/pig-common/pig-common-core/src/main/resources/i18n/messages_zh_CN.properties @@ -1,2 +1,23 @@ +sys.user.update.passwordError=\u539f\u5bc6\u7801\u9519\u8bef\uff0c\u4fee\u6539\u5931\u8d25 +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.dept.deptName.inexistence={0} \u90e8\u95e8\u540d\u79f0\u4e0d\u5b58\u5728 + +sys.post.postName.inexistence={0} \u5c97\u4f4d\u540d\u79f0\u4e0d\u5b58\u5728 +sys.post.nameOrCode.existing={0} {1} \u5c97\u4f4d\u540d\u6216\u5c97\u4f4d\u7f16\u7801\u5df2\u7ecf\u5b58\u5728 + +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.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.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 diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/AppController.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/AppController.java index a80c1615..8fda57b8 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/AppController.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/AppController.java @@ -5,6 +5,8 @@ import com.pig4cloud.pig.admin.api.dto.UserInfo; import com.pig4cloud.pig.admin.api.entity.SysUser; import com.pig4cloud.pig.admin.service.AppService; import com.pig4cloud.pig.admin.service.SysUserService; +import com.pig4cloud.pig.common.core.exception.ErrorCodes; +import com.pig4cloud.pig.common.core.util.MsgUtils; import com.pig4cloud.pig.common.core.util.R; import com.pig4cloud.pig.common.security.annotation.Inner; import io.swagger.v3.oas.annotations.security.SecurityRequirement; @@ -47,7 +49,7 @@ public class AppController { public R infoByMobile(@PathVariable String phone) { SysUser user = userService.getOne(Wrappers.query().lambda().eq(SysUser::getPhone, phone)); if (user == null) { - return R.failed(String.format("用户信息为空 %s", phone)); + return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERINFO_EMPTY, phone)); } return R.ok(userService.getUserInfo(user)); } diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/UserController.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/UserController.java index 080e976c..bc5aa24d 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/UserController.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/controller/UserController.java @@ -27,6 +27,8 @@ import com.pig4cloud.pig.admin.api.vo.UserExcelVO; import com.pig4cloud.pig.admin.api.vo.UserInfoVO; import com.pig4cloud.pig.admin.api.vo.UserVO; import com.pig4cloud.pig.admin.service.SysUserService; +import com.pig4cloud.pig.common.core.exception.ErrorCodes; +import com.pig4cloud.pig.common.core.util.MsgUtils; import com.pig4cloud.pig.common.core.util.R; import com.pig4cloud.pig.common.log.annotation.SysLog; import com.pig4cloud.pig.common.security.annotation.Inner; @@ -67,7 +69,7 @@ public class UserController { String username = SecurityUtils.getUser().getUsername(); SysUser user = userService.getOne(Wrappers.query().lambda().eq(SysUser::getUsername, username)); if (user == null) { - return R.failed("获取当前用户信息失败"); + return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_USER_QUERY_ERROR)); } UserInfo userInfo = userService.getUserInfo(user); UserInfoVO vo = new UserInfoVO(); @@ -86,7 +88,7 @@ public class UserController { public R info(@PathVariable String username) { SysUser user = userService.getOne(Wrappers.query().lambda().eq(SysUser::getUsername, username)); if (user == null) { - return R.failed(String.format("用户信息为空 %s", username)); + return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERINFO_EMPTY, username)); } return R.ok(userService.getUserInfo(user)); } diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/AppServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/AppServiceImpl.java index 148d6433..a121a9ae 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/AppServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/AppServiceImpl.java @@ -25,6 +25,8 @@ import com.pig4cloud.pig.admin.mapper.SysUserMapper; import com.pig4cloud.pig.admin.service.AppService; import com.pig4cloud.pig.common.core.constant.CacheConstants; import com.pig4cloud.pig.common.core.constant.SecurityConstants; +import com.pig4cloud.pig.common.core.exception.ErrorCodes; +import com.pig4cloud.pig.common.core.util.MsgUtils; import com.pig4cloud.pig.common.core.util.R; import io.springboot.sms.core.SmsClient; import lombok.AllArgsConstructor; @@ -63,14 +65,14 @@ public class AppServiceImpl implements AppService { if (CollUtil.isEmpty(userList)) { log.info("手机号未注册:{}", phone); - return R.ok(Boolean.FALSE, "手机号未注册"); + return R.ok(Boolean.FALSE, MsgUtils.getMessage(ErrorCodes.SYS_APP_PHONE_UNREGISTERED, phone)); } Object codeObj = redisTemplate.opsForValue().get(CacheConstants.DEFAULT_CODE_KEY + phone); if (codeObj != null) { log.info("手机号验证码未过期:{},{}", phone, codeObj); - return R.ok(Boolean.FALSE, "验证码发送过频繁"); + return R.ok(Boolean.FALSE, MsgUtils.getMessage(ErrorCodes.SYS_APP_SMS_OFTEN)); } String code = RandomUtil.randomNumbers(Integer.parseInt(SecurityConstants.CODE_SIZE)); diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysDictItemServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysDictItemServiceImpl.java index 4bbe27b0..65c729f2 100755 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysDictItemServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysDictItemServiceImpl.java @@ -23,6 +23,8 @@ import com.pig4cloud.pig.admin.service.SysDictItemService; import com.pig4cloud.pig.admin.service.SysDictService; import com.pig4cloud.pig.common.core.constant.CacheConstants; import com.pig4cloud.pig.common.core.constant.enums.DictTypeEnum; +import com.pig4cloud.pig.common.core.exception.ErrorCodes; +import com.pig4cloud.pig.common.core.util.MsgUtils; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; import org.springframework.stereotype.Service; @@ -52,7 +54,8 @@ public class SysDictItemServiceImpl extends ServiceImpl impl public void removeDict(Long id) { SysDict dict = this.getById(id); // 系统内置 - Assert.state(!DictTypeEnum.SYSTEM.getType().equals(dict.getSystemFlag()), "系统内置字典项目不能删除"); + Assert.state(!DictTypeEnum.SYSTEM.getType().equals(dict.getSystemFlag()), + MsgUtils.getMessage(ErrorCodes.SYS_DICT_DELETE_SYSTEM)); baseMapper.deleteById(id); dictItemMapper.delete(Wrappers.lambdaQuery().eq(SysDictItem::getDictId, id)); } @@ -68,7 +71,8 @@ public class SysDictServiceImpl extends ServiceImpl impl public void updateDict(SysDict dict) { SysDict sysDict = this.getById(dict.getId()); // 系统内置 - Assert.state(!DictTypeEnum.SYSTEM.getType().equals(sysDict.getSystemFlag()), "系统内置字典项目不能修改"); + Assert.state(!DictTypeEnum.SYSTEM.getType().equals(sysDict.getSystemFlag()), + MsgUtils.getMessage(ErrorCodes.SYS_DICT_UPDATE_SYSTEM)); this.updateById(dict); } diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysMenuServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysMenuServiceImpl.java index d34b6fb3..3a6883e7 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysMenuServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysMenuServiceImpl.java @@ -31,6 +31,8 @@ import com.pig4cloud.pig.admin.service.SysMenuService; import com.pig4cloud.pig.common.core.constant.CacheConstants; import com.pig4cloud.pig.common.core.constant.CommonConstants; import com.pig4cloud.pig.common.core.constant.enums.MenuTypeEnum; +import com.pig4cloud.pig.common.core.exception.ErrorCodes; +import com.pig4cloud.pig.common.core.util.MsgUtils; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; @@ -39,10 +41,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; import javax.validation.constraints.NotNull; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.function.Function; import java.util.stream.Collectors; @@ -78,7 +77,7 @@ public class SysMenuServiceImpl extends ServiceImpl impl // 查询父节点为当前节点的节点 List menuList = this.list(Wrappers.query().lambda().eq(SysMenu::getParentId, id)); - Assert.isTrue(CollUtil.isEmpty(menuList), "菜单含有下级不能删除"); + Assert.isTrue(CollUtil.isEmpty(menuList), MsgUtils.getMessage(ErrorCodes.SYS_MENU_DELETE_EXISTING)); sysRoleMenuMapper.delete(Wrappers.query().lambda().eq(SysRoleMenu::getMenuId, id)); // 删除当前菜单及其子菜单 diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysPostServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysPostServiceImpl.java index 63756ea0..a9974d2c 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysPostServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysPostServiceImpl.java @@ -21,10 +21,11 @@ import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.pig4cloud.pig.admin.api.entity.SysPost; -import com.pig4cloud.pig.admin.api.entity.SysRole; import com.pig4cloud.pig.admin.api.vo.PostExcelVO; import com.pig4cloud.pig.admin.mapper.SysPostMapper; import com.pig4cloud.pig.admin.service.SysPostService; +import com.pig4cloud.pig.common.core.exception.ErrorCodes; +import com.pig4cloud.pig.common.core.util.MsgUtils; import com.pig4cloud.pig.common.core.util.R; import com.pig4cloud.plugin.excel.vo.ErrorMessage; import org.springframework.stereotype.Service; @@ -67,7 +68,8 @@ public class SysPostServiceImpl extends ServiceImpl impl || excel.getPostCode().equals(post.getPostCode())); if (existPost) { - errorMsg.add(String.format("%s %s 岗位名或岗位编码已经存在", excel.getPostName(), excel.getPostCode())); + errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_POST_NAMEORCODE_EXISTING, excel.getPostName(), + excel.getPostCode())); } // 数据合法情况 diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysPublicParamServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysPublicParamServiceImpl.java index 8b564172..7f9a3736 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysPublicParamServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysPublicParamServiceImpl.java @@ -24,6 +24,8 @@ import com.pig4cloud.pig.admin.mapper.SysPublicParamMapper; import com.pig4cloud.pig.admin.service.SysPublicParamService; import com.pig4cloud.pig.common.core.constant.CacheConstants; import com.pig4cloud.pig.common.core.constant.enums.DictTypeEnum; +import com.pig4cloud.pig.common.core.exception.ErrorCodes; +import com.pig4cloud.pig.common.core.util.MsgUtils; import com.pig4cloud.pig.common.core.util.R; import lombok.AllArgsConstructor; import org.springframework.cache.annotation.CacheEvict; @@ -64,7 +66,7 @@ public class SysPublicParamServiceImpl extends ServiceImpl impl || excel.getRoleCode().equals(sysRole.getRoleCode())); if (existRole) { - errorMsg.add(String.format("%s %s 角色名或角色编码已经存在", excel.getRoleName(), excel.getRoleDesc())); + errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_ROLE_NAMEORCODE_EXISTING, excel.getRoleName(), + excel.getRoleCode())); } // 数据合法情况 diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java index bd013472..b652fbaa 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java @@ -174,7 +174,8 @@ public class SysUserServiceImpl extends ServiceImpl impl public Boolean updateUserInfo(UserDTO userDto) { UserVO userVO = baseMapper.getUserVoByUsername(userDto.getUsername()); - Assert.isTrue(ENCODER.matches(userDto.getPassword(), userVO.getPassword()), "原密码错误,修改失败"); + Assert.isTrue(ENCODER.matches(userDto.getPassword(), userVO.getPassword()), + MsgUtils.getMessage(ErrorCodes.SYS_USER_UPDATE_PASSWORDERROR)); SysUser sysUser = new SysUser(); if (StrUtil.isNotBlank(userDto.getNewpassword1())) { @@ -284,14 +285,14 @@ public class SysUserServiceImpl extends ServiceImpl impl .anyMatch(sysUser -> excel.getUsername().equals(sysUser.getUsername())); if (exsitUserName) { - errorMsg.add(String.format("%s 用户名已存在", excel.getUsername())); + errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, excel.getUsername())); } // 判断输入的部门名称列表是否合法 Optional deptOptional = deptList.stream() .filter(dept -> excel.getDeptName().equals(dept.getName())).findFirst(); if (!deptOptional.isPresent()) { - errorMsg.add(String.format("%s 部门名称不存在", excel.getDeptName())); + errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_DEPT_DEPTNAME_INEXISTENCE, excel.getDeptName())); } // 判断输入的角色名称列表是否合法 @@ -301,7 +302,7 @@ public class SysUserServiceImpl extends ServiceImpl impl .collect(Collectors.toList()); if (roleCollList.size() != roleNameList.size()) { - errorMsg.add(String.format("%s 角色名称不存在", excel.getRoleNameList())); + errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_ROLE_ROLENAME_INEXISTENCE, excel.getRoleNameList())); } // 判断输入的岗位名称列表是否合法 @@ -311,7 +312,7 @@ public class SysUserServiceImpl extends ServiceImpl impl .collect(Collectors.toList()); if (postCollList.size() != postNameList.size()) { - errorMsg.add(String.format("%s 岗位名称不存在", excel.getPostNameList())); + errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_POST_POSTNAME_INEXISTENCE, excel.getPostNameList())); } // 数据合法情况