style: 错误信息英文返回-system 模块路由

This commit is contained in:
TsMask
2023-11-08 14:56:36 +08:00
parent ae7f2d050c
commit a102f772cb
21 changed files with 460 additions and 342 deletions

View File

@@ -1,7 +1,7 @@
package service
import (
"errors"
"fmt"
"ems.agt/src/framework/constants/cachekey"
"ems.agt/src/framework/redis"
@@ -93,12 +93,13 @@ func (r *SysConfigImpl) DeleteConfigByIds(configIds []string) (int64, error) {
// 检查是否存在
configs := r.sysConfigRepository.SelectConfigByIds(configIds)
if len(configs) <= 0 {
return 0, errors.New("没有权限访问参数配置数据!")
return 0, fmt.Errorf("there is no accessible parameter configuration data")
}
for _, config := range configs {
// 检查是否为内置参数
if config.ConfigType == "Y" {
return 0, errors.New(config.ConfigID + " 配置参数属于内置参数,禁止删除!")
// 【%s】 配置参数属于内置参数,禁止删除!
return 0, fmt.Errorf("[%s] Configuration parameters are built-in parameters and their deletion is prohibited", config.ConfigID)
}
// 清除缓存
r.clearConfigCache(config.ConfigKey)
@@ -107,7 +108,8 @@ func (r *SysConfigImpl) DeleteConfigByIds(configIds []string) (int64, error) {
rows := r.sysConfigRepository.DeleteConfigByIds(configIds)
return rows, nil
}
return 0, errors.New("删除参数配置信息失败!")
// 删除参数配置信息失败!
return 0, fmt.Errorf("failed to delete parameter configuration information")
}
// ResetConfigCache 重置参数缓存数据

View File

@@ -1,7 +1,7 @@
package service
import (
"errors"
"fmt"
"ems.agt/src/modules/system/model"
"ems.agt/src/modules/system/repository"
@@ -77,7 +77,8 @@ func (r *SysDictDataImpl) DeleteDictDataByCodes(dictCodes []string) (int64, erro
// 检查是否存在
dictDatas := r.sysDictDataRepository.SelectDictDataByCodes(dictCodes)
if len(dictDatas) <= 0 {
return 0, errors.New("没有权限访问字典编码数据!")
// 没有可访问字典编码数据!
return 0, fmt.Errorf("there is no accessible dictionary-encoded data")
}
if len(dictDatas) == len(dictCodes) {
for _, v := range dictDatas {
@@ -88,7 +89,8 @@ func (r *SysDictDataImpl) DeleteDictDataByCodes(dictCodes []string) (int64, erro
rows := r.sysDictDataRepository.DeleteDictDataByCodes(dictCodes)
return rows, nil
}
return 0, errors.New("删除字典数据信息失败!")
// 删除字典数据信息失败!
return 0, fmt.Errorf("failed to delete dictionary data information")
}
// InsertDictData 新增字典数据信息

View File

@@ -2,7 +2,6 @@ package service
import (
"encoding/json"
"errors"
"fmt"
"ems.agt/src/framework/constants/cachekey"
@@ -107,14 +106,15 @@ func (r *SysDictTypeImpl) DeleteDictTypeByIDs(dictIDs []string) (int64, error) {
// 检查是否存在
dictTypes := r.sysDictTypeRepository.SelectDictTypeByIDs(dictIDs)
if len(dictTypes) <= 0 {
return 0, errors.New("没有权限访问字典类型数据!")
// 没有可访问字典类型数据!
return 0, fmt.Errorf("there is no accessible dictionary type data")
}
for _, v := range dictTypes {
// 字典类型下级含有数据
useCount := r.sysDictDataRepository.CountDictDataByType(v.DictType)
if useCount > 0 {
msg := fmt.Sprintf("【%s】存在字典数据,不能删除", v.DictName)
return 0, errors.New(msg)
// 【%s】存在字典数据,不能删除
return 0, fmt.Errorf("[%s] dictionary data exists and cannot be deleted", v.DictName)
}
// 清除缓存
r.ClearDictCache(v.DictType)
@@ -123,7 +123,8 @@ func (r *SysDictTypeImpl) DeleteDictTypeByIDs(dictIDs []string) (int64, error) {
rows := r.sysDictTypeRepository.DeleteDictTypeByIDs(dictIDs)
return rows, nil
}
return 0, errors.New("删除字典数据信息失败!")
// 删除字典数据信息失败!
return 0, fmt.Errorf("failed to delete dictionary data information")
}
// ResetDictCache 重置字典缓存数据

View File

@@ -1,7 +1,7 @@
package service
import (
"errors"
"fmt"
"ems.agt/src/modules/system/model"
"ems.agt/src/modules/system/repository"
@@ -55,17 +55,19 @@ func (r *SysNoticeImpl) DeleteNoticeByIds(noticeIds []string) (int64, error) {
// 检查是否存在
notices := r.sysNoticeRepository.SelectNoticeByIds(noticeIds)
if len(notices) <= 0 {
return 0, errors.New("没有权限访问公告信息数据!")
return 0, fmt.Errorf("there is no accessible bulletin information data")
}
for _, notice := range notices {
// 检查是否为已删除
if notice.DelFlag == "1" {
return 0, errors.New(notice.NoticeID + " 公告信息已经删除!")
// 【%s】公告信息已经删除!
return 0, fmt.Errorf("the [%s] announcement message has been deleted", notice.NoticeID)
}
}
if len(notices) == len(noticeIds) {
rows := r.sysNoticeRepository.DeleteNoticeByIds(noticeIds)
return rows, nil
}
return 0, errors.New("删除公告信息失败!")
// 删除公告信息失败!
return 0, fmt.Errorf("failed to delete the announcement message")
}

View File

@@ -1,7 +1,6 @@
package service
import (
"errors"
"fmt"
"ems.agt/src/modules/system/model"
@@ -54,20 +53,22 @@ func (r *SysPostImpl) DeletePostByIds(postIds []string) (int64, error) {
// 检查是否存在
posts := r.sysPostRepository.SelectPostByIds(postIds)
if len(posts) <= 0 {
return 0, errors.New("没有权限访问岗位数据!")
// 没有可访问岗位数据!
return 0, fmt.Errorf("there is no accessible post data")
}
for _, post := range posts {
useCount := r.sysUserPostRepository.CountUserPostByPostId(post.PostID)
if useCount > 0 {
msg := fmt.Sprintf("【%s】已分配给用户,不能删除", post.PostName)
return 0, errors.New(msg)
// 【%s】已分配给用户,不能删除
return 0, fmt.Errorf("[%s] has been assigned to a user and cannot be deleted", post.PostName)
}
}
if len(posts) == len(postIds) {
rows := r.sysPostRepository.DeletePostByIds(postIds)
return rows, nil
}
return 0, errors.New("删除岗位信息失败!")
// 删除岗位信息失败!
return 0, fmt.Errorf("failed to delete post information")
}
// UpdatePost 修改岗位信息

View File

@@ -1,7 +1,6 @@
package service
import (
"errors"
"fmt"
"ems.agt/src/modules/system/model"
@@ -99,18 +98,20 @@ func (r *SysRoleImpl) DeleteRoleByIds(roleIds []string) (int64, error) {
// 检查是否存在
roles := r.sysRoleRepository.SelectRoleByIds(roleIds)
if len(roles) <= 0 {
return 0, errors.New("没有权限访问角色数据!")
// 没有可访问角色数据!
return 0, fmt.Errorf("there is no accessible role data")
}
for _, role := range roles {
// 检查是否为已删除
if role.DelFlag == "1" {
return 0, errors.New(role.RoleID + " 角色信息已经删除!")
// 【%s】角色信息已经删除!
return 0, fmt.Errorf("[%s] Role information has been deleted", role.RoleID)
}
// 检查分配用户
userCount := r.sysUserRoleRepository.CountUserRoleByRoleId(role.RoleID)
if userCount > 0 {
msg := fmt.Sprintf("【%s】已分配给用户,不能删除", role.RoleName)
return 0, errors.New(msg)
// 【%s】已分配给用户,不能删除
return 0, fmt.Errorf("[%s] has been assigned to a user and cannot be deleted", role.RoleName)
}
}
if len(roles) == len(roleIds) {
@@ -121,7 +122,8 @@ func (r *SysRoleImpl) DeleteRoleByIds(roleIds []string) (int64, error) {
rows := r.sysRoleRepository.DeleteRoleByIds(roleIds)
return rows, nil
}
return 0, errors.New("删除角色信息失败!")
// 删除角色信息失败!
return 0, fmt.Errorf("failed to delete role information")
}
// CheckUniqueRoleName 校验角色名称是否唯一

View File

@@ -1,7 +1,6 @@
package service
import (
"errors"
"fmt"
"strings"
@@ -138,7 +137,8 @@ func (r *SysUserImpl) DeleteUserByIds(userIds []string) (int64, error) {
// 检查是否存在
users := r.sysUserRepository.SelectUserByIds(userIds)
if len(users) <= 0 {
return 0, errors.New("没有权限访问用户数据!")
// 没有可访问用户数据!
return 0, fmt.Errorf("there is no accessible user data")
}
if len(users) == len(userIds) {
// 删除用户与角色关联
@@ -150,7 +150,7 @@ func (r *SysUserImpl) DeleteUserByIds(userIds []string) (int64, error) {
rows := r.sysUserRepository.DeleteUserByIds(userIds)
return rows, nil
}
return 0, errors.New("删除用户信息失败!")
return 0, fmt.Errorf("failed to delete user information")
}
// CheckUniqueUserName 校验用户名称是否唯一
@@ -211,7 +211,8 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
if !ownItem {
mustItemArrStr := strings.Join(mustItemArr, "、")
failureNum++
failureMsgArr = append(failureMsgArr, fmt.Sprintf("表格中必填列表项,%s}", mustItemArrStr))
// 表格中必填列表项,
failureMsgArr = append(failureMsgArr, fmt.Sprintf("Required list items in the form, %s}", mustItemArrStr))
continue
}
@@ -224,7 +225,7 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
}
}
sysUserStatus := common.STATUS_NO
if row["G"] == "正常" {
if row["G"] == "Normal" {
sysUserStatus = common.STATUS_YES
}
@@ -246,13 +247,15 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
if regular.ValidMobile(newSysUser.PhoneNumber) {
uniquePhone := r.CheckUniquePhone(newSysUser.PhoneNumber, "")
if !uniquePhone {
msg := fmt.Sprintf("用户编号:%s 手机号码 %s 已存在", row["A"], row["E"])
// 用户编号:%s 手机号码 %s 已存在
msg := fmt.Sprintf("UserID: %s PhoneNumber: %s pre-existing", row["A"], row["E"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
}
} else {
msg := fmt.Sprintf("用户编号:%s 手机号码 %s 格式错误", row["A"], row["E"])
// 用户编号:%s 手机号码 %s 格式错误
msg := fmt.Sprintf("UserID: %s PhoneNumber: %s formatting error", row["A"], row["E"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
@@ -264,13 +267,15 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
if regular.ValidEmail(newSysUser.Email) {
uniqueEmail := r.CheckUniqueEmail(newSysUser.Email, "")
if !uniqueEmail {
msg := fmt.Sprintf("用户编号:%s 用户邮箱 %s 已存在", row["A"], row["D"])
// 用户编号:%s 用户邮箱 %s 已存在
msg := fmt.Sprintf("UserID: %s Email: %s pre-existing", row["A"], row["D"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
}
} else {
msg := fmt.Sprintf("用户编号:%s 用户邮箱 %s 格式错误", row["A"], row["D"])
// 用户编号:%s 用户邮箱 %s 格式错误
msg := fmt.Sprintf("UserID: %s Email: %s formatting error", row["A"], row["D"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
continue
@@ -283,11 +288,13 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
newSysUser.CreateBy = operName
insertId := r.InsertUser(newSysUser)
if insertId != "" {
msg := fmt.Sprintf("用户编号:%s 登录名称 %s 导入成功", row["A"], row["B"])
// 用户编号:%s 登录名称 %s 导入成功
msg := fmt.Sprintf("UserID: %s UserName: %s import successfully", row["A"], row["B"])
successNum++
successMsgArr = append(successMsgArr, msg)
} else {
msg := fmt.Sprintf("用户编号:%s 登录名称 %s 导入失败", row["A"], row["B"])
// 用户编号:%s 登录名称 %s 导入失败
msg := fmt.Sprintf("UserID: %s UserName: %s import failure", row["A"], row["B"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
}
@@ -300,11 +307,13 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
newSysUser.UpdateBy = operName
rows := r.UpdateUser(newSysUser)
if rows > 0 {
msg := fmt.Sprintf("用户编号:%s 登录名称 %s 更新成功", row["A"], row["B"])
// 用户编号:%s 登录名称 %s 更新成功
msg := fmt.Sprintf("UserID: %s UserName: %s Update Successful", row["A"], row["B"])
successNum++
successMsgArr = append(successMsgArr, msg)
} else {
msg := fmt.Sprintf("用户编号:%s 登录名称 %s 更新失败", row["A"], row["B"])
// 用户编号:%s 登录名称 %s 更新失败
msg := fmt.Sprintf("UserID: %s UserName: %s Update Failed", row["A"], row["B"])
failureNum++
failureMsgArr = append(failureMsgArr, msg)
}
@@ -313,10 +322,12 @@ func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool,
}
if failureNum > 0 {
failureMsgArr = append([]string{fmt.Sprintf("很抱歉,导入失败!共 %d 条数据格式不正确,错误如下:", failureNum)}, failureMsgArr...)
// 很抱歉,导入失败!共 %d 条数据格式不正确,错误如下:
failureMsgArr = append([]string{fmt.Sprintf("Sorry, the import failed! A total of %d entries were formatted incorrectly with the following error:", failureNum)}, failureMsgArr...)
return strings.Join(failureMsgArr, "<br/>")
}
successMsgArr = append([]string{fmt.Sprintf("恭喜您,数据已全部导入成功!共 %d 条,数据如下:", successNum)}, successMsgArr...)
// 恭喜您,数据已全部导入成功!共 %d 条,数据如下:
successMsgArr = append([]string{fmt.Sprintf("Congratulations, the data has been imported successfully! Total %d entries, data below:", successNum)}, successMsgArr...)
return strings.Join(successMsgArr, "<br/>")
}