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

@@ -59,7 +59,7 @@ func (s *SysUserController) List(c *gin.Context) {
func (s *SysUserController) Info(c *gin.Context) {
userId := c.Param("userId")
if userId == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
// 查询系统角色列表
@@ -95,7 +95,7 @@ func (s *SysUserController) Info(c *gin.Context) {
// 检查用户是否存在
user := s.sysUserService.SelectUserById(userId)
if user.UserID != userId {
c.JSON(200, result.ErrMsg("没有权限访问用户数据!"))
c.JSON(200, result.ErrMsg("There is no accessible user data!"))
return
}
@@ -128,7 +128,7 @@ func (s *SysUserController) Add(c *gin.Context) {
var body model.SysUser
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.UserID != "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
@@ -137,7 +137,7 @@ func (s *SysUserController) Add(c *gin.Context) {
Password string `json:"password" binding:"required"`
}
if err := c.ShouldBindBodyWith(&bodyPassword, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
body.Password = bodyPassword.Password
@@ -145,7 +145,8 @@ func (s *SysUserController) Add(c *gin.Context) {
// 检查用户登录账号是否唯一
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.UserName, "")
if !uniqueUserName {
msg := fmt.Sprintf("新增用户【%s】失败登录账号已存在", body.UserName)
// 新增用户【%s】失败登录账号已存在
msg := fmt.Sprintf("Failed to add user [%s], login account already exists", body.UserName)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -155,12 +156,14 @@ func (s *SysUserController) Add(c *gin.Context) {
if regular.ValidMobile(body.PhoneNumber) {
uniquePhone := s.sysUserService.CheckUniquePhone(body.PhoneNumber, "")
if !uniquePhone {
msg := fmt.Sprintf("新增用户【%s】失败手机号码已存在", body.UserName)
// 新增用户【%s】失败手机号码已存在
msg := fmt.Sprintf("Failed to add user [%s], cell phone number already exists", body.UserName)
c.JSON(200, result.ErrMsg(msg))
return
}
} else {
msg := fmt.Sprintf("新增用户【%s】失败手机号码格式错误", body.UserName)
// 新增用户【%s】失败手机号码格式错误
msg := fmt.Sprintf("Failed to add user [%s], wrong format of cell phone number", body.UserName)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -171,12 +174,14 @@ func (s *SysUserController) Add(c *gin.Context) {
if regular.ValidEmail(body.Email) {
uniqueEmail := s.sysUserService.CheckUniqueEmail(body.Email, "")
if !uniqueEmail {
msg := fmt.Sprintf("新增用户【%s】失败邮箱已存在", body.UserName)
// 新增用户【%s】失败邮箱已存在
msg := fmt.Sprintf("Failed to add user [%s], mailbox already exists", body.UserName)
c.JSON(200, result.ErrMsg(msg))
return
}
} else {
msg := fmt.Sprintf("新增用户【%s】失败邮箱格式错误", body.UserName)
// 新增用户【%s】失败邮箱格式错误
msg := fmt.Sprintf("Failed to add user [%s], mailbox format error", body.UserName)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -198,26 +203,29 @@ func (s *SysUserController) Edit(c *gin.Context) {
var body model.SysUser
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.UserID == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
// 检查是否管理员用户
if config.IsAdmin(body.UserID) {
c.JSON(200, result.ErrMsg("不允许操作管理员用户"))
// 不允许操作管理员用户
c.JSON(200, result.ErrMsg("Administrator users are not allowed to operate"))
return
}
user := s.sysUserService.SelectUserById(body.UserID)
if user.UserID != body.UserID {
c.JSON(200, result.ErrMsg("没有权限访问用户数据!"))
// 没有可访问用户数据!
c.JSON(200, result.ErrMsg("There is no accessible user data!"))
return
}
// 检查用户登录账号是否唯一
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.UserName, body.UserID)
if !uniqueUserName {
msg := fmt.Sprintf("修改用户【%s】失败登录账号已存在", body.UserName)
// 修改用户【%s】失败登录账号已存在
msg := fmt.Sprintf("Failed to modify user [%s], login account already exists", body.UserName)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -227,12 +235,14 @@ func (s *SysUserController) Edit(c *gin.Context) {
if regular.ValidMobile(body.PhoneNumber) {
uniquePhone := s.sysUserService.CheckUniquePhone(body.PhoneNumber, body.UserID)
if !uniquePhone {
msg := fmt.Sprintf("修改用户【%s】失败手机号码已存在", body.UserName)
// 修改用户【%s】失败手机号码已存在
msg := fmt.Sprintf("Failed to modify user [%s], cell phone number already exists", body.UserName)
c.JSON(200, result.ErrMsg(msg))
return
}
} else {
msg := fmt.Sprintf("修改用户【%s】失败手机号码格式错误", body.UserName)
// 修改用户【%s】失败手机号码格式错误
msg := fmt.Sprintf("Failed to modify user [%s], wrong format of cell phone number", body.UserName)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -243,12 +253,14 @@ func (s *SysUserController) Edit(c *gin.Context) {
if regular.ValidEmail(body.Email) {
uniqueEmail := s.sysUserService.CheckUniqueEmail(body.Email, body.UserID)
if !uniqueEmail {
msg := fmt.Sprintf("修改用户【%s】失败邮箱已存在", body.UserName)
// 修改用户【%s】失败邮箱已存在
msg := fmt.Sprintf("Failed to modify user [%s], mailbox already exists", body.UserName)
c.JSON(200, result.ErrMsg(msg))
return
}
} else {
msg := fmt.Sprintf("修改用户【%s】失败邮箱格式错误", body.UserName)
// 修改用户【%s】失败邮箱格式错误
msg := fmt.Sprintf("Failed to modify user [%s], mailbox format error", body.UserName)
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -273,7 +285,7 @@ func (s *SysUserController) Edit(c *gin.Context) {
func (s *SysUserController) Remove(c *gin.Context) {
userIds := c.Param("userIds")
if userIds == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
// 处理字符转id数组后去重
@@ -288,7 +300,8 @@ func (s *SysUserController) Remove(c *gin.Context) {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
msg := fmt.Sprintf("删除成功:%d", rows)
// 删除成功:%d
msg := fmt.Sprintf("Deleted successfully: %d", rows)
c.JSON(200, result.OkMsg(msg))
}
@@ -301,23 +314,26 @@ func (s *SysUserController) ResetPwd(c *gin.Context) {
Password string `json:"password" binding:"required"`
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
// 检查是否管理员用户
if config.IsAdmin(body.UserID) {
c.JSON(200, result.ErrMsg("不允许操作管理员用户"))
// 不允许操作管理员用户
c.JSON(200, result.ErrMsg("Administrator users are not allowed to operate"))
return
}
user := s.sysUserService.SelectUserById(body.UserID)
if user.UserID != body.UserID {
c.JSON(200, result.ErrMsg("没有权限访问用户数据!"))
// 没有可访问用户数据!
c.JSON(200, result.ErrMsg("There is no accessible user data!"))
return
}
if !regular.ValidPassword(body.Password) {
c.JSON(200, result.ErrMsg("登录密码至少包含大小写字母、数字、特殊符号且不少于6位"))
// 登录密码至少包含大小写字母、数字、特殊符号且不少于6位
c.JSON(200, result.ErrMsg("Login password contains at least upper and lower case letters, numbers, special symbols, and not less than 6 digits"))
return
}
@@ -344,20 +360,22 @@ func (s *SysUserController) Status(c *gin.Context) {
Status string `json:"status" binding:"required"`
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}
// 检查是否存在
user := s.sysUserService.SelectUserById(body.UserID)
if user.UserID != body.UserID {
c.JSON(200, result.ErrMsg("没有权限访问用户数据!"))
// 没有可访问用户数据!
c.JSON(200, result.ErrMsg("There is no accessible user data!"))
return
}
// 与旧值相等不变更
if user.Status == body.Status {
c.JSON(200, result.ErrMsg("变更状态与旧值相等!"))
// 变更状态与旧值相等!
c.JSON(200, result.ErrMsg("The change status is equal to the old value!"))
return
}
@@ -384,7 +402,8 @@ func (s *SysUserController) Export(c *gin.Context) {
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "u")
data := s.sysUserService.SelectUserPage(querys, dataScopeSQL)
if data["total"].(int64) == 0 {
c.JSON(200, result.ErrMsg("导出数据记录为空"))
// 导出数据记录为空
c.JSON(200, result.ErrMsg("Export data record is empty"))
return
}
rows := data["rows"].([]model.SysUser)
@@ -393,18 +412,18 @@ func (s *SysUserController) Export(c *gin.Context) {
fileName := fmt.Sprintf("user_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
// 第一行表头标题
headerCells := map[string]string{
"A1": "用户编号",
"B1": "登录名称",
"C1": "用户名称",
"D1": "用户邮箱",
"E1": "手机号码",
"F1": "用户性别",
"G1": "帐号状态",
"H1": "部门编号",
"I1": "部门名称",
"J1": "部门负责人",
"K1": "最后登录IP",
"L1": "最后登录时间",
"A1": "UserID",
"B1": "UserName",
"C1": "NickName",
"D1": "Email",
"E1": "PhoneNumber",
"F1": "UserSex",
"G1": "Status",
"H1": "DeptID",
"I1": "DeptName",
"J1": "DeptLeader",
"K1": "LoginIP",
"L1": "LoginDate",
}
// 读取用户性别字典数据
dictSysUserSex := s.sysDictDataService.SelectDictDataByType("sys_user_sex")
@@ -413,7 +432,7 @@ func (s *SysUserController) Export(c *gin.Context) {
for i, row := range rows {
idx := strconv.Itoa(i + 2)
// 用户性别
sysUserSex := "未知"
sysUserSex := "unknown"
for _, v := range dictSysUserSex {
if row.Sex == v.DictValue {
sysUserSex = v.DictLabel
@@ -421,9 +440,9 @@ func (s *SysUserController) Export(c *gin.Context) {
}
}
// 帐号状态
statusValue := "停用"
statusValue := "deactivate"
if row.Status == "1" {
statusValue = "正常"
statusValue = "normalcy"
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.UserID,
@@ -485,7 +504,7 @@ func (s *SysUserController) ImportData(c *gin.Context) {
// 上传的文件
formFile, err := c.FormFile("file")
if err != nil || updateSupport == "" {
c.JSON(400, result.CodeMsg(400, "参数错误"))
c.JSON(400, result.CodeMsg(400, "parameter error"))
return
}