From 5604bd9b9db82ce93f100051d04068f29b05579f Mon Sep 17 00:00:00 2001
From: TsMask <340112800@qq.com>
Date: Mon, 20 Nov 2023 18:55:33 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E7=B3=BB=E7=BB=9F=E6=A8=A1=E5=9D=97?=
=?UTF-8?q?=E5=A4=9A=E8=AF=AD=E8=A8=80?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/modules/system/controller/sys_config.go | 80 +++--
src/modules/system/controller/sys_dept.go | 95 +++--
.../system/controller/sys_dict_data.go | 102 ++++--
.../system/controller/sys_dict_type.go | 66 +++-
.../system/controller/sys_log_login.go | 59 +++-
.../system/controller/sys_log_operate.go | 66 ++--
src/modules/system/controller/sys_menu.go | 101 ++++--
src/modules/system/controller/sys_post.go | 66 +++-
src/modules/system/controller/sys_profile.go | 50 +--
src/modules/system/controller/sys_role.go | 120 +++++--
src/modules/system/controller/sys_user.go | 333 +++++++++++++++---
.../system/repository/sys_config.impl.go | 17 +-
.../system/repository/sys_dept.impl.go | 6 +-
.../system/repository/sys_dict_data.impl.go | 7 +-
.../system/repository/sys_dict_type.impl.go | 7 +-
.../system/repository/sys_menu.impl.go | 6 +-
.../system/repository/sys_post.impl.go | 7 +-
.../system/repository/sys_role.impl.go | 7 +-
.../system/repository/sys_user.impl.go | 7 +-
src/modules/system/service/sys_config.impl.go | 8 +-
src/modules/system/service/sys_user.go | 3 -
src/modules/system/service/sys_user.impl.go | 155 --------
src/modules/system/system.go | 116 +++---
23 files changed, 957 insertions(+), 527 deletions(-)
diff --git a/src/modules/system/controller/sys_config.go b/src/modules/system/controller/sys_config.go
index e5dd936b..190815ab 100644
--- a/src/modules/system/controller/sys_config.go
+++ b/src/modules/system/controller/sys_config.go
@@ -6,6 +6,7 @@ import (
"strings"
"time"
+ "ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/utils/parse"
@@ -36,6 +37,19 @@ type SysConfigController struct {
func (s *SysConfigController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.sysConfigService.SelectConfigPage(querys)
+
+ rows := data["rows"].([]model.SysConfig)
+ // 闭包函数处理多语言
+ language := ctx.AcceptLanguage(c)
+ converI18n := func(language string, arr *[]model.SysConfig) {
+ for i := range *arr {
+ (*arr)[i].ConfigName = i18n.TKey(language, (*arr)[i].ConfigName)
+ (*arr)[i].ConfigValue = i18n.TKey(language, (*arr)[i].ConfigValue)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &rows)
+
c.JSON(200, result.Ok(data))
}
@@ -43,13 +57,19 @@ func (s *SysConfigController) List(c *gin.Context) {
//
// GET /:configId
func (s *SysConfigController) Info(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
configId := c.Param("configId")
if configId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
+
data := s.sysConfigService.SelectConfigById(configId)
if data.ConfigID == configId {
+ // 处理多语言
+ data.ConfigName = i18n.TKey(language, data.ConfigName)
+ data.ConfigValue = i18n.TKey(language, data.ConfigValue)
+ data.Remark = i18n.TKey(language, data.Remark)
c.JSON(200, result.OkData(data))
return
}
@@ -60,10 +80,11 @@ func (s *SysConfigController) Info(c *gin.Context) {
//
// POST /
func (s *SysConfigController) Add(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysConfig
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.ConfigID != "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -71,7 +92,7 @@ func (s *SysConfigController) Add(c *gin.Context) {
uniqueConfigKey := s.sysConfigService.CheckUniqueConfigKey(body.ConfigKey, "")
if !uniqueConfigKey {
// 参数配置新增【%s】失败,参数键名已存在
- msg := fmt.Sprintf("Parameter configuration add [%s] failed, parameter key name already exists", body.ConfigKey)
+ msg := i18n.TTemplate(language, "config.errKeyExists", map[string]any{"name": body.ConfigKey})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -89,10 +110,11 @@ func (s *SysConfigController) Add(c *gin.Context) {
//
// PUT /
func (s *SysConfigController) Edit(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysConfig
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.ConfigID == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -100,7 +122,7 @@ func (s *SysConfigController) Edit(c *gin.Context) {
uniqueConfigKey := s.sysConfigService.CheckUniqueConfigKey(body.ConfigKey, body.ConfigID)
if !uniqueConfigKey {
// 参数配置修改【%s】失败,参数键名已存在
- msg := fmt.Sprintf("Parameter configuration modification [%s] failed, parameter key name already exists", body.ConfigKey)
+ msg := i18n.TTemplate(language, "config.errKeyExists", map[string]any{"name": body.ConfigKey})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -109,7 +131,7 @@ func (s *SysConfigController) Edit(c *gin.Context) {
config := s.sysConfigService.SelectConfigById(body.ConfigID)
if config.ConfigID != body.ConfigID {
// 没有可访问参数配置数据!
- c.JSON(200, result.ErrMsg("There is no accessible parameter configuration data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "config.noData")))
return
}
@@ -126,9 +148,10 @@ func (s *SysConfigController) Edit(c *gin.Context) {
//
// DELETE /:configIds
func (s *SysConfigController) Remove(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
configIds := c.Param("configIds")
if configIds == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 处理字符转id数组后去重
@@ -140,10 +163,10 @@ func (s *SysConfigController) Remove(c *gin.Context) {
}
rows, err := s.sysConfigService.DeleteConfigByIds(uniqueIDs)
if err != nil {
- c.JSON(200, result.ErrMsg(err.Error()))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, err.Error())))
return
}
- msg := fmt.Sprintf("Deleted successfully: %d", rows)
+ msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
}
@@ -159,9 +182,10 @@ func (s *SysConfigController) RefreshCache(c *gin.Context) {
//
// GET /configKey/:configKey
func (s *SysConfigController) ConfigKey(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
configKey := c.Param("configKey")
if configKey == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
key := s.sysConfigService.SelectConfigValueByKey(configKey)
@@ -176,33 +200,45 @@ func (s *SysConfigController) ConfigKey(c *gin.Context) {
//
// POST /export
func (s *SysConfigController) Export(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
data := s.sysConfigService.SelectConfigPage(querys)
if data["total"].(int64) == 0 {
// 导出数据记录为空
- c.JSON(200, result.ErrMsg("Export data record is empty"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.SysConfig)
+ // 闭包函数处理多语言
+ converI18n := func(language string, arr *[]model.SysConfig) {
+ for i := range *arr {
+ (*arr)[i].ConfigName = i18n.TKey(language, (*arr)[i].ConfigName)
+ (*arr)[i].ConfigValue = i18n.TKey(language, (*arr)[i].ConfigValue)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &rows)
+
// 导出文件名称
fileName := fmt.Sprintf("config_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
// 第一行表头标题
headerCells := map[string]string{
- "A1": "ConfigID",
- "B1": "ConfigName",
- "C1": "ConfigKey",
- "D1": "ConfigValue",
- "E1": "Type",
+ "A1": i18n.TKey(language, "config..export.id"),
+ "B1": i18n.TKey(language, "config..export.name"),
+ "C1": i18n.TKey(language, "config..export.key"),
+ "D1": i18n.TKey(language, "config..export.value"),
+ "E1": i18n.TKey(language, "config..export.type"),
+ "F1": i18n.TKey(language, "config..export.remark"),
}
// 从第二行开始的数据
dataCells := make([]map[string]any, 0)
for i, row := range rows {
idx := strconv.Itoa(i + 2)
- typeValue := "clogged"
+ typeValue := i18n.TKey(language, "dictData.no")
if row.ConfigType == "Y" {
- typeValue = "be"
+ typeValue = i18n.TKey(language, "dictData.yes")
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.ConfigID,
@@ -210,6 +246,7 @@ func (s *SysConfigController) Export(c *gin.Context) {
"C" + idx: row.ConfigKey,
"D" + idx: row.ConfigValue,
"E" + idx: typeValue,
+ "F" + idx: row.Remark,
})
}
@@ -227,12 +264,13 @@ func (s *SysConfigController) Export(c *gin.Context) {
//
// PUT /changeConfigValue
func (s *SysConfigController) ConfigValue(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body struct {
Key string `json:"key" binding:"required"`
Value string `json:"value" binding:"required"`
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -240,14 +278,14 @@ func (s *SysConfigController) ConfigValue(c *gin.Context) {
info := s.sysConfigService.SelectConfigByKey(body.Key)
if info.ConfigKey != body.Key {
// 无效 key
- c.JSON(200, result.ErrMsg("Invalid key"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "config.errKey")))
return
}
// 与旧值相等不变更
if info.ConfigValue == body.Value {
// 变更状态与旧值相等!
- c.JSON(200, result.ErrMsg("The change status is equal to the old value!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "config.errValueEq")))
return
}
info.ConfigValue = body.Value
diff --git a/src/modules/system/controller/sys_dept.go b/src/modules/system/controller/sys_dept.go
index db5f0784..dedbddf0 100644
--- a/src/modules/system/controller/sys_dept.go
+++ b/src/modules/system/controller/sys_dept.go
@@ -1,11 +1,12 @@
package controller
import (
- "fmt"
"strings"
"ems.agt/src/framework/constants/common"
+ "ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
+ "ems.agt/src/framework/vo"
"ems.agt/src/framework/vo/result"
"ems.agt/src/modules/system/model"
"ems.agt/src/modules/system/service"
@@ -31,6 +32,7 @@ type SysDeptController struct {
//
// GET /list
func (s *SysDeptController) List(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var querys struct {
// 部门ID
DeptID string `json:"deptId"`
@@ -43,7 +45,7 @@ func (s *SysDeptController) List(c *gin.Context) {
}
err := c.ShouldBindQuery(&querys)
if err != nil {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -55,6 +57,15 @@ func (s *SysDeptController) List(c *gin.Context) {
}
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "")
data := s.sysDeptService.SelectDeptList(SysDeptController, dataScopeSQL)
+
+ // 闭包函数处理多语言
+ converI18n := func(language string, arr *[]model.SysDept) {
+ for i := range *arr {
+ (*arr)[i].DeptName = i18n.TKey(language, (*arr)[i].DeptName)
+ }
+ }
+ converI18n(language, &data)
+
c.JSON(200, result.OkData(data))
}
@@ -62,13 +73,16 @@ func (s *SysDeptController) List(c *gin.Context) {
//
// GET /:deptId
func (s *SysDeptController) Info(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
deptId := c.Param("deptId")
if deptId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.sysDeptService.SelectDeptById(deptId)
if data.DeptID == deptId {
+ // 处理多语言
+ data.DeptName = i18n.TKey(language, data.DeptName)
c.JSON(200, result.OkData(data))
return
}
@@ -79,10 +93,11 @@ func (s *SysDeptController) Info(c *gin.Context) {
//
// POST /
func (s *SysDeptController) Add(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysDept
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.DeptID != "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -91,18 +106,18 @@ func (s *SysDeptController) Add(c *gin.Context) {
deptParent := s.sysDeptService.SelectDeptById(body.ParentID)
if deptParent.DeptID != body.ParentID {
// 没有可访问部门数据!
- c.JSON(200, result.ErrMsg("There is no accessible sectoral data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "dept.noData")))
return
}
if deptParent.Status == common.STATUS_NO {
// 上级部门【%s】停用,不允许新增
- msg := fmt.Sprintf("Upper division [%s] deactivated, no new additions allowed", deptParent.DeptName)
+ msg := i18n.TTemplate(language, "dept.errParentStatus", map[string]any{"name": deptParent.DeptName})
c.JSON(200, result.ErrMsg(msg))
return
}
if deptParent.DelFlag == common.STATUS_YES {
// 上级部门【%s】已删除,不允许新增
- msg := fmt.Sprintf("The parent department [%s] has been deleted and is not allowed to be added", deptParent.DeptName)
+ msg := i18n.TTemplate(language, "dept.errParentDelFlag", map[string]any{"name": deptParent.DeptName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -115,7 +130,7 @@ func (s *SysDeptController) Add(c *gin.Context) {
uniqueDeptName := s.sysDeptService.CheckUniqueDeptName(body.DeptName, body.ParentID, "")
if !uniqueDeptName {
// 部门新增【%s】失败,部门名称已存在
- msg := fmt.Sprintf("Department add [%s] failed, department name already exists", body.DeptName)
+ msg := i18n.TTemplate(language, "dept.errNameExists", map[string]any{"name": body.DeptName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -133,17 +148,18 @@ func (s *SysDeptController) Add(c *gin.Context) {
//
// PUT /
func (s *SysDeptController) Edit(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysDept
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.DeptID == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 上级部门不能选自己
if body.DeptID == body.ParentID {
// 部门修改【%s】失败,上级部门不能是自己
- msg := fmt.Sprintf("Departmental modification [%s] failed, the parent department cannot be itself", body.DeptName)
+ msg := i18n.TTemplate(language, "dept.errParentID", map[string]any{"name": body.DeptName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -152,7 +168,7 @@ func (s *SysDeptController) Edit(c *gin.Context) {
deptInfo := s.sysDeptService.SelectDeptById(body.DeptID)
if deptInfo.DeptID != body.DeptID {
// 没有可访问部门数据!
- c.JSON(200, result.ErrMsg("There is no accessible sectoral data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "dept.noData")))
return
}
// 父级ID不为0是要检查
@@ -160,7 +176,7 @@ func (s *SysDeptController) Edit(c *gin.Context) {
deptParent := s.sysDeptService.SelectDeptById(body.ParentID)
if deptParent.DeptID != body.ParentID {
// 没有可访问部门数据!
- c.JSON(200, result.ErrMsg("There is no accessible sectoral data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "dept.noData")))
return
}
}
@@ -169,7 +185,7 @@ func (s *SysDeptController) Edit(c *gin.Context) {
uniqueDeptName := s.sysDeptService.CheckUniqueDeptName(body.DeptName, body.ParentID, body.DeptID)
if !uniqueDeptName {
// 部门修改【%s】失败,部门名称已存在
- msg := fmt.Sprintf("Department modification [%s] failed, department name already exists", body.DeptName)
+ msg := i18n.TTemplate(language, "dept.errNameExists", map[string]any{"name": body.DeptName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -179,7 +195,7 @@ func (s *SysDeptController) Edit(c *gin.Context) {
hasChild := s.sysDeptService.HasChildByDeptId(body.DeptID)
if hasChild > 0 {
// 该部门包含未停用的子部门数量:%d
- msg := fmt.Sprintf("Number of subsectors not deactivated included in this sector: %d", hasChild)
+ msg := i18n.TTemplate(language, "dept.errHasChildUse", map[string]any{"num": hasChild})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -198,9 +214,10 @@ func (s *SysDeptController) Edit(c *gin.Context) {
//
// DELETE /:deptId
func (s *SysDeptController) Remove(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
deptId := c.Param("deptId")
if deptId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -208,7 +225,7 @@ func (s *SysDeptController) Remove(c *gin.Context) {
dept := s.sysDeptService.SelectDeptById(deptId)
if dept.DeptID != deptId {
// 没有可访问部门数据!
- c.JSON(200, result.ErrMsg("There is no accessible sectoral data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "dept.noData")))
return
}
@@ -216,7 +233,7 @@ func (s *SysDeptController) Remove(c *gin.Context) {
hasChild := s.sysDeptService.HasChildByDeptId(deptId)
if hasChild > 0 {
// 不允许删除,存在子部门数:%d
- msg := fmt.Sprintf("Deletion not allowed, number of subsectors present: %d", hasChild)
+ msg := i18n.TTemplate(language, "dept.errHasChildUse", map[string]any{"num": hasChild})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -225,7 +242,7 @@ func (s *SysDeptController) Remove(c *gin.Context) {
existUser := s.sysDeptService.CheckDeptExistUser(deptId)
if existUser > 0 {
// 不允许删除,部门已分配给用户数:%d
- msg := fmt.Sprintf("Deletions are not allowed and the department has been assigned to the number of users: %d", existUser)
+ msg := i18n.TTemplate(language, "dept.errHasUserUse", map[string]any{"num": existUser})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -233,7 +250,7 @@ func (s *SysDeptController) Remove(c *gin.Context) {
rows := s.sysDeptService.DeleteDeptById(deptId)
if rows > 0 {
// 删除成功:%d
- msg := fmt.Sprintf("Deleted successfully: %d", rows)
+ msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
return
}
@@ -244,9 +261,10 @@ func (s *SysDeptController) Remove(c *gin.Context) {
//
// GET /list/exclude/:deptId
func (s *SysDeptController) ExcludeChild(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
deptId := c.Param("deptId")
if deptId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -265,6 +283,7 @@ func (s *SysDeptController) ExcludeChild(c *gin.Context) {
}
}
if !(dept.DeptID == deptId || hasAncestor) {
+ dept.DeptName = i18n.TKey(language, dept.DeptName)
filtered = append(filtered, dept)
}
}
@@ -275,6 +294,7 @@ func (s *SysDeptController) ExcludeChild(c *gin.Context) {
//
// GET /treeSelect
func (s *SysDeptController) TreeSelect(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var querys struct {
// 部门ID
DeptID string `json:"deptId"`
@@ -287,7 +307,7 @@ func (s *SysDeptController) TreeSelect(c *gin.Context) {
}
err := c.ShouldBindQuery(&querys)
if err != nil {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -298,23 +318,50 @@ func (s *SysDeptController) TreeSelect(c *gin.Context) {
Status: querys.Status,
}
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "")
- data := s.sysDeptService.SelectDeptTreeSelect(SysDeptController, dataScopeSQL)
- c.JSON(200, result.OkData(data))
+ deptTreeSelect := s.sysDeptService.SelectDeptTreeSelect(SysDeptController, dataScopeSQL)
+
+ // 闭包函数处理多语言
+ var converI18n func(language string, arr *[]vo.TreeSelect)
+ converI18n = func(language string, arr *[]vo.TreeSelect) {
+ for i := range *arr {
+ (*arr)[i].Label = i18n.TKey(language, (*arr)[i].Label)
+ if len((*arr)[i].Children) > 0 {
+ converI18n(language, &(*arr)[i].Children)
+ }
+ }
+ }
+ converI18n(language, &deptTreeSelect)
+
+ c.JSON(200, result.OkData(deptTreeSelect))
}
// 部门树结构列表(指定角色)
//
// GET /roleDeptTreeSelect/:roleId
func (s *SysDeptController) RoleDeptTreeSelect(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
roleId := c.Param("roleId")
if roleId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "")
deptTreeSelect := s.sysDeptService.SelectDeptTreeSelect(model.SysDept{}, dataScopeSQL)
checkedKeys := s.sysDeptService.SelectDeptListByRoleId(roleId)
+
+ // 闭包函数处理多语言
+ var converI18n func(language string, arr *[]vo.TreeSelect)
+ converI18n = func(language string, arr *[]vo.TreeSelect) {
+ for i := range *arr {
+ (*arr)[i].Label = i18n.TKey(language, (*arr)[i].Label)
+ if len((*arr)[i].Children) > 0 {
+ converI18n(language, &(*arr)[i].Children)
+ }
+ }
+ }
+ converI18n(language, &deptTreeSelect)
+
c.JSON(200, result.OkData(map[string]any{
"depts": deptTreeSelect,
"checkedKeys": checkedKeys,
diff --git a/src/modules/system/controller/sys_dict_data.go b/src/modules/system/controller/sys_dict_data.go
index f4b391e9..60a8fd4c 100644
--- a/src/modules/system/controller/sys_dict_data.go
+++ b/src/modules/system/controller/sys_dict_data.go
@@ -6,6 +6,7 @@ import (
"strings"
"time"
+ "ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/utils/parse"
@@ -39,6 +40,21 @@ type SysDictDataController struct {
func (s *SysDictDataController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.sysDictDataService.SelectDictDataPage(querys)
+
+ rows := data["rows"].([]model.SysDictData)
+ // 闭包函数处理多语言
+ language := ctx.AcceptLanguage(c)
+ converI18n := func(language string, arr *[]model.SysDictData) {
+ for i := range *arr {
+ if strings.Contains((*arr)[i].DictType, "i18n") {
+ continue
+ }
+ (*arr)[i].DictLabel = i18n.TKey(language, (*arr)[i].DictLabel)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &rows)
+
c.JSON(200, result.Ok(data))
}
@@ -46,13 +62,17 @@ func (s *SysDictDataController) List(c *gin.Context) {
//
// GET /:dictCode
func (s *SysDictDataController) Info(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
dictCode := c.Param("dictCode")
if dictCode == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.sysDictDataService.SelectDictDataByCode(dictCode)
if data.DictCode == dictCode {
+ // 处理多语言
+ data.DictLabel = i18n.TKey(language, data.DictLabel)
+ data.Remark = i18n.TKey(language, data.Remark)
c.JSON(200, result.OkData(data))
return
}
@@ -63,10 +83,11 @@ func (s *SysDictDataController) Info(c *gin.Context) {
//
// POST /
func (s *SysDictDataController) Add(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysDictData
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.DictCode != "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -74,7 +95,7 @@ func (s *SysDictDataController) Add(c *gin.Context) {
sysDictType := s.sysDictTypeService.SelectDictTypeByType(body.DictType)
if sysDictType.DictType != body.DictType {
// 没有可访问字典类型数据!
- c.JSON(200, result.ErrMsg("There is no accessible dictionary type data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "dictType.noData")))
return
}
@@ -82,16 +103,7 @@ func (s *SysDictDataController) Add(c *gin.Context) {
uniqueDictLabel := s.sysDictDataService.CheckUniqueDictLabel(body.DictType, body.DictLabel, "")
if !uniqueDictLabel {
// 数据新增【%s】失败,该字典类型下标签名已存在
- msg := fmt.Sprintf("Data addition [%s] failed, tag name already exists under this dictionary type", body.DictLabel)
- c.JSON(200, result.ErrMsg(msg))
- return
- }
-
- // 检查字典键值唯一
- uniqueDictValue := s.sysDictDataService.CheckUniqueDictValue(body.DictType, body.DictValue, "")
- if !uniqueDictValue {
- // 数据新增【%s】失败,该字典类型下标签值已存在
- msg := fmt.Sprintf("Data addition [%s] failed, tagged value already exists under this dictionary type", body.DictValue)
+ msg := i18n.TTemplate(language, "dictType.errLabelExists", map[string]any{"name": body.DictLabel})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -109,10 +121,11 @@ func (s *SysDictDataController) Add(c *gin.Context) {
//
// PUT /
func (s *SysDictDataController) Edit(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysDictData
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.DictCode == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -120,7 +133,7 @@ func (s *SysDictDataController) Edit(c *gin.Context) {
sysDictType := s.sysDictTypeService.SelectDictTypeByType(body.DictType)
if sysDictType.DictType != body.DictType {
// 没有可访问字典类型数据!
- c.JSON(200, result.ErrMsg("There is no accessible dictionary type data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "dictType.noData")))
return
}
@@ -128,7 +141,7 @@ func (s *SysDictDataController) Edit(c *gin.Context) {
SysDictDataController := s.sysDictDataService.SelectDictDataByCode(body.DictCode)
if SysDictDataController.DictCode != body.DictCode {
// 没有可访问字典编码数据!
- c.JSON(200, result.ErrMsg("There is no accessible dictionary-encoded data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "dictData.noData")))
return
}
@@ -136,16 +149,7 @@ func (s *SysDictDataController) Edit(c *gin.Context) {
uniqueDictLabel := s.sysDictDataService.CheckUniqueDictLabel(body.DictType, body.DictLabel, body.DictCode)
if !uniqueDictLabel {
// 数据修改【%s】失败,该字典类型下标签名已存在
- msg := fmt.Sprintf("Data modification [%s] failed, tag name already exists under this dictionary type", body.DictLabel)
- c.JSON(200, result.ErrMsg(msg))
- return
- }
-
- // 检查字典键值唯一
- uniqueDictValue := s.sysDictDataService.CheckUniqueDictValue(body.DictType, body.DictValue, body.DictCode)
- if !uniqueDictValue {
- // 数据修改【%s】失败,该字典类型下标签值已存在
- msg := fmt.Sprintf("Data modification [%s] failed, tagged value already exists under this dictionary type", body.DictValue)
+ msg := i18n.TTemplate(language, "dictType.errLabelExists", map[string]any{"name": body.DictLabel})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -163,9 +167,10 @@ func (s *SysDictDataController) Edit(c *gin.Context) {
//
// DELETE /:dictCodes
func (s *SysDictDataController) Remove(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
dictCodes := c.Param("dictCodes")
if dictCodes == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 处理字符转id数组后去重
@@ -181,7 +186,7 @@ func (s *SysDictDataController) Remove(c *gin.Context) {
return
}
// 删除成功:%d
- msg := fmt.Sprintf("Deleted successfully: %d", rows)
+ msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
}
@@ -189,13 +194,24 @@ func (s *SysDictDataController) Remove(c *gin.Context) {
//
// GET /type/:dictType
func (s *SysDictDataController) DictType(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
dictType := c.Param("dictType")
if dictType == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.sysDictDataService.SelectDictDataByType(dictType)
+
+ // 闭包函数处理多语言
+ converI18n := func(language string, arr *[]model.SysDictData) {
+ for i := range *arr {
+ (*arr)[i].DictLabel = i18n.TKey(language, (*arr)[i].DictLabel)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &data)
+
c.JSON(200, result.OkData(data))
}
@@ -203,34 +219,44 @@ func (s *SysDictDataController) DictType(c *gin.Context) {
//
// POST /export
func (s *SysDictDataController) Export(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
data := s.sysDictDataService.SelectDictDataPage(querys)
if data["total"].(int64) == 0 {
// 导出数据记录为空
- c.JSON(200, result.ErrMsg("Export data record is empty"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.SysDictData)
+ // 闭包函数处理多语言
+ converI18n := func(language string, arr *[]model.SysDictData) {
+ for i := range *arr {
+ (*arr)[i].DictLabel = i18n.TKey(language, (*arr)[i].DictLabel)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &rows)
+
// 导出文件名称
fileName := fmt.Sprintf("dict_data_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
// 第一行表头标题
headerCells := map[string]string{
- "A1": "DictCode",
- "B1": "DictSort",
- "C1": "DictLabel",
- "D1": "DictValue",
- "E1": "DictType",
- "F1": "Status",
+ "A1": i18n.TKey(language, "dictData.export.code"),
+ "B1": i18n.TKey(language, "dictData.export.sort"),
+ "C1": i18n.TKey(language, "dictData.export.label"),
+ "D1": i18n.TKey(language, "dictData.export.value"),
+ "E1": i18n.TKey(language, "dictData.export.type"),
+ "F1": i18n.TKey(language, "dictData.export.status"),
}
// 从第二行开始的数据
dataCells := make([]map[string]any, 0)
for i, row := range rows {
idx := strconv.Itoa(i + 2)
- statusValue := "deactivate"
+ statusValue := i18n.TKey(language, "dictData.disable")
if row.Status == "1" {
- statusValue = "normalcy"
+ statusValue = i18n.TKey(language, "dictData.normal")
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.DictCode,
diff --git a/src/modules/system/controller/sys_dict_type.go b/src/modules/system/controller/sys_dict_type.go
index 7f3bb3b9..80b83a2b 100644
--- a/src/modules/system/controller/sys_dict_type.go
+++ b/src/modules/system/controller/sys_dict_type.go
@@ -38,6 +38,18 @@ type SysDictTypeController struct {
func (s *SysDictTypeController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.sysDictTypeService.SelectDictTypePage(querys)
+
+ rows := data["rows"].([]model.SysDictType)
+ // 闭包函数处理多语言
+ language := ctx.AcceptLanguage(c)
+ converI18n := func(language string, arr *[]model.SysDictType) {
+ for i := range *arr {
+ (*arr)[i].DictName = i18n.TKey(language, (*arr)[i].DictName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &rows)
+
c.JSON(200, result.Ok(data))
}
@@ -45,13 +57,17 @@ func (s *SysDictTypeController) List(c *gin.Context) {
//
// GET /:dictId
func (s *SysDictTypeController) Info(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
dictId := c.Param("dictId")
if dictId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.sysDictTypeService.SelectDictTypeByID(dictId)
if data.DictID == dictId {
+ // 处理多语言
+ data.DictName = i18n.TKey(language, data.DictName)
+ data.Remark = i18n.TKey(language, data.Remark)
c.JSON(200, result.OkData(data))
return
}
@@ -62,10 +78,11 @@ func (s *SysDictTypeController) Info(c *gin.Context) {
//
// POST /
func (s *SysDictTypeController) Add(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysDictType
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.DictID != "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -73,7 +90,7 @@ func (s *SysDictTypeController) Add(c *gin.Context) {
uniqueDictName := s.sysDictTypeService.CheckUniqueDictName(body.DictName, "")
if !uniqueDictName {
// 字典新增【%s】失败,字典名称已存在
- msg := fmt.Sprintf("Dictionary add [%s] failed, dictionary name already exists", body.DictName)
+ msg := i18n.TTemplate(language, "dictType.errNameExists", map[string]any{"name": body.DictName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -82,7 +99,7 @@ func (s *SysDictTypeController) Add(c *gin.Context) {
uniqueDictType := s.sysDictTypeService.CheckUniqueDictType(body.DictType, "")
if !uniqueDictType {
// 字典新增【%s】失败,字典类型已存在
- msg := fmt.Sprintf("Dictionary add [%s] failed, dictionary type already exists", body.DictType)
+ msg := i18n.TTemplate(language, "dictType.errTypeExists", map[string]any{"name": body.DictName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -100,10 +117,11 @@ func (s *SysDictTypeController) Add(c *gin.Context) {
//
// PUT /
func (s *SysDictTypeController) Edit(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysDictType
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.DictID == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -111,7 +129,7 @@ func (s *SysDictTypeController) Edit(c *gin.Context) {
dictInfo := s.sysDictTypeService.SelectDictTypeByID(body.DictID)
if dictInfo.DictID != body.DictID {
// 没有可访问字典类型数据!
- c.JSON(200, result.ErrMsg("There is no accessible dictionary type data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "dictType.noData")))
return
}
@@ -119,7 +137,7 @@ func (s *SysDictTypeController) Edit(c *gin.Context) {
uniqueDictName := s.sysDictTypeService.CheckUniqueDictName(body.DictName, body.DictID)
if !uniqueDictName {
// 字典修改【%s】失败,字典名称已存在
- msg := fmt.Sprintf("Dictionary modification [%s] failed, dictionary name already exists", body.DictName)
+ msg := i18n.TTemplate(language, "dictType.errNameExists", map[string]any{"name": body.DictName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -128,7 +146,7 @@ func (s *SysDictTypeController) Edit(c *gin.Context) {
uniqueDictType := s.sysDictTypeService.CheckUniqueDictType(body.DictType, body.DictID)
if !uniqueDictType {
// 字典修改【%s】失败,字典类型已存在
- msg := fmt.Sprintf("Dictionary modification [%s] failed, dictionary type already exists", body.DictType)
+ msg := i18n.TTemplate(language, "dictType.errTypeExists", map[string]any{"name": body.DictName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -146,9 +164,10 @@ func (s *SysDictTypeController) Edit(c *gin.Context) {
//
// DELETE /:dictIds
func (s *SysDictTypeController) Remove(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
dictIds := c.Param("dictIds")
if dictIds == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 处理字符转id数组后去重
@@ -163,7 +182,7 @@ func (s *SysDictTypeController) Remove(c *gin.Context) {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
- msg := fmt.Sprintf("Deleted successfully: %d", rows)
+ msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
}
@@ -189,11 +208,12 @@ func (s *SysDictTypeController) DictOptionselect(c *gin.Context) {
Value string `json:"value"`
}
+ language := ctx.AcceptLanguage(c)
// 数据组
arr := []labelValue{}
for _, v := range data {
arr = append(arr, labelValue{
- Label: v.DictName,
+ Label: i18n.TKey(language, v.DictName),
Value: v.DictType,
})
}
@@ -204,32 +224,42 @@ func (s *SysDictTypeController) DictOptionselect(c *gin.Context) {
//
// POST /export
func (s *SysDictTypeController) Export(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
data := s.sysDictTypeService.SelectDictTypePage(querys)
if data["total"].(int64) == 0 {
// 导出数据记录为空
- c.JSON(200, result.ErrMsg("Export data record is empty"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.SysDictType)
+ // 闭包函数处理多语言
+ converI18n := func(language string, arr *[]model.SysDictType) {
+ for i := range *arr {
+ (*arr)[i].DictName = i18n.TKey(language, (*arr)[i].DictName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &rows)
+
// 导出文件名称
fileName := fmt.Sprintf("dict_type_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
// 第一行表头标题
headerCells := map[string]string{
- "A1": "DictID",
- "B1": "DictName",
- "C1": "DictType",
- "D1": "Status",
+ "A1": i18n.TKey(language, "dictType.export.id"),
+ "B1": i18n.TKey(language, "dictType.export.name"),
+ "C1": i18n.TKey(language, "dictType.export.type"),
+ "D1": i18n.TKey(language, "dictType.export.status"),
}
// 从第二行开始的数据
dataCells := make([]map[string]any, 0)
for i, row := range rows {
idx := strconv.Itoa(i + 2)
- statusValue := "deactivate"
+ statusValue := i18n.TKey(language, "dictData.disable")
if row.Status == "1" {
- statusValue = "normalcy"
+ statusValue = i18n.TKey(language, "dictData.normal")
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.DictID,
diff --git a/src/modules/system/controller/sys_log_login.go b/src/modules/system/controller/sys_log_login.go
index ab7b5f17..44941030 100644
--- a/src/modules/system/controller/sys_log_login.go
+++ b/src/modules/system/controller/sys_log_login.go
@@ -6,6 +6,7 @@ import (
"strings"
"time"
+ "ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/date"
"ems.agt/src/framework/utils/file"
@@ -40,6 +41,19 @@ type SysLogLoginController struct {
func (s *SysLogLoginController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.sysLogLoginService.SelectSysLogLoginPage(querys)
+
+ rows := data["rows"].([]model.SysLogLogin)
+ // 闭包函数处理多语言
+ language := ctx.AcceptLanguage(c)
+ converI18n := func(language string, arr *[]model.SysLogLogin) {
+ for i := range *arr {
+ (*arr)[i].LoginLocation = i18n.TKey(language, (*arr)[i].LoginLocation)
+ (*arr)[i].OS = i18n.TKey(language, (*arr)[i].OS)
+ (*arr)[i].Browser = i18n.TKey(language, (*arr)[i].Browser)
+ }
+ }
+ converI18n(language, &rows)
+
c.JSON(200, result.Ok(data))
}
@@ -47,9 +61,10 @@ func (s *SysLogLoginController) List(c *gin.Context) {
//
// DELETE /:infoIds
func (s *SysLogLoginController) Remove(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
infoIds := c.Param("infoIds")
if infoIds == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -62,7 +77,7 @@ func (s *SysLogLoginController) Remove(c *gin.Context) {
}
rows := s.sysLogLoginService.DeleteSysLogLoginByIds(uniqueIDs)
if rows > 0 {
- msg := fmt.Sprintf("Deleted successfully: %d", rows)
+ msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
return
}
@@ -85,9 +100,10 @@ func (s *SysLogLoginController) Clean(c *gin.Context) {
//
// PUT /unlock/:userName
func (s *SysLogLoginController) Unlock(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
userName := c.Param("userName")
if userName == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
ok := s.accountService.ClearLoginRecordCache(userName)
@@ -95,45 +111,56 @@ func (s *SysLogLoginController) Unlock(c *gin.Context) {
c.JSON(200, result.Ok(nil))
return
}
- c.JSON(200, result.ErrMsg("unlatched"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.errUnlock")))
}
// 导出系统登录日志信息
//
// POST /export
func (s *SysLogLoginController) Export(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
data := s.sysLogLoginService.SelectSysLogLoginPage(querys)
if data["total"].(int64) == 0 {
// 导出数据记录为空
- c.JSON(200, result.ErrMsg("Export data record is empty"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.SysLogLogin)
+ // 闭包函数处理多语言
+ converI18n := func(language string, arr *[]model.SysLogLogin) {
+ for i := range *arr {
+ (*arr)[i].LoginLocation = i18n.TKey(language, (*arr)[i].LoginLocation)
+ (*arr)[i].OS = i18n.TKey(language, (*arr)[i].OS)
+ (*arr)[i].Browser = i18n.TKey(language, (*arr)[i].Browser)
+ }
+ }
+ converI18n(language, &rows)
+
// 导出文件名称
fileName := fmt.Sprintf("sys_log_login_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
// 第一行表头标题
headerCells := map[string]string{
- "A1": "ID",
- "B1": "UserName",
- "C1": "Status",
- "D1": "IP",
- "E1": "Location",
- "F1": "Browser",
- "G1": "OS",
- "H1": "Msg",
- "I1": "Time",
+ "A1": i18n.TKey(language, "log.login.export.id"),
+ "B1": i18n.TKey(language, "log.login.export.userName"),
+ "C1": i18n.TKey(language, "log.login.export.status"),
+ "D1": i18n.TKey(language, "log.login.export.ip"),
+ "E1": i18n.TKey(language, "log.login.export.location"),
+ "F1": i18n.TKey(language, "log.login.export.browser"),
+ "G1": i18n.TKey(language, "log.login.export.os"),
+ "H1": i18n.TKey(language, "log.login.export.msg"),
+ "I1": i18n.TKey(language, "log.login.export.time"),
}
// 从第二行开始的数据
dataCells := make([]map[string]any, 0)
for i, row := range rows {
idx := strconv.Itoa(i + 2)
// 状态
- statusValue := "fail"
+ statusValue := i18n.TKey(language, "dictData.fail")
if row.Status == "1" {
- statusValue = "successes"
+ statusValue = i18n.TKey(language, "dictData.success")
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.LoginID,
diff --git a/src/modules/system/controller/sys_log_operate.go b/src/modules/system/controller/sys_log_operate.go
index 37e2e3e9..ffedb366 100644
--- a/src/modules/system/controller/sys_log_operate.go
+++ b/src/modules/system/controller/sys_log_operate.go
@@ -6,6 +6,7 @@ import (
"strings"
"time"
+ "ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/date"
"ems.agt/src/framework/utils/file"
@@ -36,6 +37,18 @@ type SysLogOperateController struct {
func (s *SysLogOperateController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.SysLogOperateService.SelectSysLogOperatePage(querys)
+
+ rows := data["rows"].([]model.SysLogOperate)
+ // 闭包函数处理多语言
+ language := ctx.AcceptLanguage(c)
+ converI18n := func(language string, arr *[]model.SysLogOperate) {
+ for i := range *arr {
+ (*arr)[i].Title = i18n.TKey(language, (*arr)[i].Title)
+ (*arr)[i].OperLocation = i18n.TKey(language, (*arr)[i].OperLocation)
+ }
+ }
+ converI18n(language, &rows)
+
c.JSON(200, result.Ok(data))
}
@@ -43,9 +56,10 @@ func (s *SysLogOperateController) List(c *gin.Context) {
//
// DELETE /:operIds
func (s *SysLogOperateController) Remove(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
operIds := c.Param("operIds")
if operIds == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -58,7 +72,7 @@ func (s *SysLogOperateController) Remove(c *gin.Context) {
}
rows := s.SysLogOperateService.DeleteSysLogOperateByIds(uniqueIDs)
if rows > 0 {
- msg := fmt.Sprintf("Deleted successfully: %d", rows)
+ msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
return
}
@@ -81,36 +95,46 @@ func (s *SysLogOperateController) Clean(c *gin.Context) {
//
// POST /export
func (s *SysLogOperateController) Export(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
data := s.SysLogOperateService.SelectSysLogOperatePage(querys)
if data["total"].(int64) == 0 {
// 导出数据记录为空
- c.JSON(200, result.ErrMsg("Export data record is empty"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.SysLogOperate)
+ // 闭包函数处理多语言
+ converI18n := func(language string, arr *[]model.SysLogOperate) {
+ for i := range *arr {
+ (*arr)[i].Title = i18n.TKey(language, (*arr)[i].Title)
+ (*arr)[i].OperLocation = i18n.TKey(language, (*arr)[i].OperLocation)
+ }
+ }
+ converI18n(language, &rows)
+
// 导出文件名称
fileName := fmt.Sprintf("sys_log_operate_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
// 第一行表头标题
headerCells := map[string]string{
- "A1": "ID",
- "B1": "Title",
- "C1": "BusinessType",
- "D1": "Method",
- "E1": "RequestMethod",
- "F1": "OperatorType",
- "G1": "OperName",
- "H1": "DeptName",
- "I1": "URL",
- "J1": "IP",
- "K1": "Location",
- "L1": "Param",
- "M1": "Msg",
- "N1": "Status",
- "O1": "CostTime (ms)",
- "P1": "OperTime",
+ "A1": i18n.TKey(language, "log.operate.export.id"),
+ "B1": i18n.TKey(language, "log.operate.export.title"),
+ "C1": i18n.TKey(language, "log.operate.export.businessType"),
+ "D1": i18n.TKey(language, "log.operate.export.method"),
+ "E1": i18n.TKey(language, "log.operate.export.requestMethod"),
+ "F1": i18n.TKey(language, "log.operate.export.operatorType"),
+ "G1": i18n.TKey(language, "log.operate.export.operName"),
+ "H1": i18n.TKey(language, "log.operate.export.deptName"),
+ "I1": i18n.TKey(language, "log.operate.export.url"),
+ "J1": i18n.TKey(language, "log.operate.export.ip"),
+ "K1": i18n.TKey(language, "log.operate.export.location"),
+ "L1": i18n.TKey(language, "log.operate.export.param"),
+ "M1": i18n.TKey(language, "log.operate.export.msg"),
+ "N1": i18n.TKey(language, "log.operate.export.status"),
+ "O1": i18n.TKey(language, "log.operate.export.costTime"),
+ "P1": i18n.TKey(language, "log.operate.export.operTime"),
}
// 从第二行开始的数据
dataCells := make([]map[string]any, 0)
@@ -121,9 +145,9 @@ func (s *SysLogOperateController) Export(c *gin.Context) {
// 操作类别
operatorType := ""
// 状态
- statusValue := "fail"
+ statusValue := i18n.TKey(language, "dictData.fail")
if row.Status == "1" {
- statusValue = "success"
+ statusValue = i18n.TKey(language, "dictData.success")
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.OperID,
diff --git a/src/modules/system/controller/sys_menu.go b/src/modules/system/controller/sys_menu.go
index 27427a24..47bacdb5 100644
--- a/src/modules/system/controller/sys_menu.go
+++ b/src/modules/system/controller/sys_menu.go
@@ -1,13 +1,13 @@
package controller
import (
- "fmt"
-
"ems.agt/src/framework/config"
"ems.agt/src/framework/constants/common"
"ems.agt/src/framework/constants/menu"
+ "ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/regular"
+ "ems.agt/src/framework/vo"
"ems.agt/src/framework/vo/result"
"ems.agt/src/modules/system/model"
"ems.agt/src/modules/system/service"
@@ -46,6 +46,21 @@ func (s *SysMenuController) List(c *gin.Context) {
userId = "*"
}
data := s.sysMenuService.SelectMenuList(query, userId)
+
+ // 闭包函数处理多语言
+ language := ctx.AcceptLanguage(c)
+ var converI18n func(language string, arr *[]model.SysMenu)
+ converI18n = func(language string, arr *[]model.SysMenu) {
+ for i := range *arr {
+ (*arr)[i].MenuName = i18n.TKey(language, (*arr)[i].MenuName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ if len((*arr)[i].Children) > 0 {
+ converI18n(language, &(*arr)[i].Children)
+ }
+ }
+ }
+ converI18n(language, &data)
+
c.JSON(200, result.OkData(data))
}
@@ -53,13 +68,17 @@ func (s *SysMenuController) List(c *gin.Context) {
//
// GET /:menuId
func (s *SysMenuController) Info(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
menuId := c.Param("menuId")
if menuId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.sysMenuService.SelectMenuById(menuId)
if data.MenuID == menuId {
+ // 处理多语言
+ data.MenuName = i18n.TKey(language, data.MenuName)
+ data.Remark = i18n.TKey(language, data.Remark)
c.JSON(200, result.OkData(data))
return
}
@@ -70,10 +89,11 @@ func (s *SysMenuController) Info(c *gin.Context) {
//
// POST /
func (s *SysMenuController) Add(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysMenu
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.MenuID != "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -82,7 +102,7 @@ func (s *SysMenuController) Add(c *gin.Context) {
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, body.ParentID, "")
if !uniqueNenuPath {
// 菜单新增【%s】失败,菜单路由地址已存在
- msg := fmt.Sprintf("Menu add [%s] failed, menu routing address already exists", body.MenuName)
+ msg := i18n.TTemplate(language, "menu.errPathExists", map[string]any{"name": body.MenuName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -92,15 +112,15 @@ func (s *SysMenuController) Add(c *gin.Context) {
uniqueNenuName := s.sysMenuService.CheckUniqueMenuName(body.MenuName, body.ParentID, "")
if !uniqueNenuName {
// 菜单新增【%s】失败,菜单名称已存在
- msg := fmt.Sprintf("Menu add [%s] failed, menu name already exists", body.MenuName)
+ msg := i18n.TTemplate(language, "menu.errNameExists", map[string]any{"name": body.MenuName})
c.JSON(200, result.ErrMsg(msg))
return
}
// 外链菜单需要符合网站http(s)开头
if body.IsFrame == common.STATUS_NO && !regular.ValidHttp(body.Path) {
- // 菜单新增【%s】失败,非内部地址必须以http(s)://开头
- msg := fmt.Sprintf("Menu adds [%s] failure, non-internal addresses must start with http(s)://", body.MenuName)
+ // 操作菜单【{name}】失败,非内部地址请以http(s)://开头
+ msg := i18n.TTemplate(language, "menu.errFramePath", map[string]any{"name": body.MenuName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -118,17 +138,18 @@ func (s *SysMenuController) Add(c *gin.Context) {
//
// PUT /
func (s *SysMenuController) Edit(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysMenu
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.MenuID == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 上级菜单不能选自己
if body.MenuID == body.ParentID {
// 菜单修改【%s】失败,上级菜单不能选择自己
- msg := fmt.Sprintf("Menu modification [%s] fails, the parent menu cannot select itself", body.MenuName)
+ msg := i18n.TTemplate(language, "menu.errPathExists", map[string]any{"name": body.MenuName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -136,21 +157,22 @@ func (s *SysMenuController) Edit(c *gin.Context) {
// 检查数据是否存在
menuInfo := s.sysMenuService.SelectMenuById(body.MenuID)
if menuInfo.MenuID != body.MenuID {
- // 没有可访问菜单数据
- c.JSON(200, result.ErrMsg("No accessible menu data"))
+ // 没有可访问菜单数据!
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "menu.noData")))
return
}
// 父级ID不为0是要检查
if body.ParentID != "0" {
menuParent := s.sysMenuService.SelectMenuById(body.ParentID)
if menuParent.MenuID != body.ParentID {
- c.JSON(200, result.ErrMsg("No accessible menu data"))
+ // 没有可访问菜单数据!
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "menu.noData")))
return
}
// 禁用菜单时检查父菜单是否使用
if body.Status == common.STATUS_YES && menuParent.Status == common.STATUS_NO {
// 上级菜单未启用!
- c.JSON(200, result.ErrMsg("The parent menu is not enabled!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "menu.errParentStatus")))
return
}
}
@@ -160,7 +182,7 @@ func (s *SysMenuController) Edit(c *gin.Context) {
uniqueNenuPath := s.sysMenuService.CheckUniqueMenuPath(body.Path, body.ParentID, body.MenuID)
if !uniqueNenuPath {
// 菜单修改【%s】失败,菜单路由地址已存在
- msg := fmt.Sprintf("Menu modification [%s] failed, menu routing address already exists", body.MenuName)
+ msg := i18n.TTemplate(language, "menu.errPathExists", map[string]any{"name": body.MenuName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -170,7 +192,7 @@ func (s *SysMenuController) Edit(c *gin.Context) {
uniqueNenuName := s.sysMenuService.CheckUniqueMenuName(body.MenuName, body.ParentID, body.MenuID)
if !uniqueNenuName {
// 菜单修改【%s】失败,菜单名称已存在
- msg := fmt.Sprintf("Menu modification [%s] failed, menu name already exists", body.MenuName)
+ msg := i18n.TTemplate(language, "menu.errNameExists", map[string]any{"name": body.MenuName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -178,7 +200,7 @@ func (s *SysMenuController) Edit(c *gin.Context) {
// 外链菜单需要符合网站http(s)开头
if body.IsFrame == common.STATUS_NO && !regular.ValidHttp(body.Path) {
// 菜单修改【%s】失败,非内部地址必须以http(s)://开头
- msg := fmt.Sprintf("Menu change [%s] failed, non-internal address must start with http(s)://", body.MenuName)
+ msg := i18n.TTemplate(language, "menu.errFramePath", map[string]any{"name": body.MenuName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -187,8 +209,8 @@ func (s *SysMenuController) Edit(c *gin.Context) {
if body.Status == common.STATUS_NO {
hasStatus := s.sysMenuService.HasChildByMenuIdAndStatus(body.MenuID, common.STATUS_YES)
if hasStatus > 0 {
- // 不允许禁用,存在使用子菜单数:%d
- msg := fmt.Sprintf("Disabling is not allowed, number of submenus present for use: %d", hasStatus)
+ // 操作菜单【%s】失败,存在使用子菜单数:%d
+ msg := i18n.TTemplate(language, "menu.errHasChildUse", map[string]any{"name": body.MenuName, "num": hasStatus})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -207,9 +229,10 @@ func (s *SysMenuController) Edit(c *gin.Context) {
//
// DELETE /:menuId
func (s *SysMenuController) Remove(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
menuId := c.Param("menuId")
if menuId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -217,7 +240,7 @@ func (s *SysMenuController) Remove(c *gin.Context) {
menu := s.sysMenuService.SelectMenuById(menuId)
if menu.MenuID != menuId {
// 没有可访问菜单数据!
- c.JSON(200, result.ErrMsg("There is no accessible menu data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "menu.noData")))
return
}
@@ -225,7 +248,7 @@ func (s *SysMenuController) Remove(c *gin.Context) {
hasChild := s.sysMenuService.HasChildByMenuIdAndStatus(menuId, "")
if hasChild > 0 {
// 不允许删除,存在子菜单数:%d
- msg := fmt.Sprintf("Deletion not allowed, number of submenus present: %d", hasChild)
+ msg := i18n.TTemplate(language, "menu.errHasChildUse", map[string]any{"name": menu.MenuName, "num": hasChild})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -234,14 +257,14 @@ func (s *SysMenuController) Remove(c *gin.Context) {
existRole := s.sysMenuService.CheckMenuExistRole(menuId)
if existRole > 0 {
// 不允许删除,菜单已分配给角色数:%d
- msg := fmt.Sprintf("Deletion not allowed, number of roles assigned to the menu: %d", existRole)
+ msg := i18n.TTemplate(language, "menu.errHasRoleUse", map[string]any{"name": menu.MenuName, "num": existRole})
c.JSON(200, result.ErrMsg(msg))
return
}
rows := s.sysMenuService.DeleteMenuById(menuId)
if rows > 0 {
- msg := fmt.Sprintf("Deleted successfully: %d", rows)
+ msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
return
}
@@ -265,6 +288,20 @@ func (s *SysMenuController) TreeSelect(c *gin.Context) {
userId = "*"
}
data := s.sysMenuService.SelectMenuTreeSelectByUserId(query, userId)
+
+ // 闭包函数处理多语言
+ language := ctx.AcceptLanguage(c)
+ var converI18n func(language string, arr *[]vo.TreeSelect)
+ converI18n = func(language string, arr *[]vo.TreeSelect) {
+ for i := range *arr {
+ (*arr)[i].Label = i18n.TKey(language, (*arr)[i].Label)
+ if len((*arr)[i].Children) > 0 {
+ converI18n(language, &(*arr)[i].Children)
+ }
+ }
+ }
+ converI18n(language, &data)
+
c.JSON(200, result.OkData(data))
}
@@ -273,9 +310,10 @@ func (s *SysMenuController) TreeSelect(c *gin.Context) {
//
// GET /roleMenuTreeSelect/:roleId
func (s *SysMenuController) RoleMenuTreeSelect(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
roleId := c.Param("roleId")
if roleId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -293,6 +331,19 @@ func (s *SysMenuController) RoleMenuTreeSelect(c *gin.Context) {
}
menuTreeSelect := s.sysMenuService.SelectMenuTreeSelectByUserId(query, userId)
checkedKeys := s.sysMenuService.SelectMenuListByRoleId(roleId)
+
+ // 闭包函数处理多语言
+ var converI18n func(language string, arr *[]vo.TreeSelect)
+ converI18n = func(language string, arr *[]vo.TreeSelect) {
+ for i := range *arr {
+ (*arr)[i].Label = i18n.TKey(language, (*arr)[i].Label)
+ if len((*arr)[i].Children) > 0 {
+ converI18n(language, &(*arr)[i].Children)
+ }
+ }
+ }
+ converI18n(language, &menuTreeSelect)
+
c.JSON(200, result.OkData(map[string]any{
"menus": menuTreeSelect,
"checkedKeys": checkedKeys,
diff --git a/src/modules/system/controller/sys_post.go b/src/modules/system/controller/sys_post.go
index fd971212..65ca4089 100644
--- a/src/modules/system/controller/sys_post.go
+++ b/src/modules/system/controller/sys_post.go
@@ -6,6 +6,7 @@ import (
"strings"
"time"
+ "ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/utils/parse"
@@ -36,6 +37,18 @@ type SysPostController struct {
func (s *SysPostController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
data := s.sysPostService.SelectPostPage(querys)
+
+ rows := data["rows"].([]model.SysPost)
+ // 闭包函数处理多语言
+ language := ctx.AcceptLanguage(c)
+ converI18n := func(language string, arr *[]model.SysPost) {
+ for i := range *arr {
+ (*arr)[i].PostName = i18n.TKey(language, (*arr)[i].PostName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &rows)
+
c.JSON(200, result.Ok(data))
}
@@ -43,13 +56,17 @@ func (s *SysPostController) List(c *gin.Context) {
//
// GET /:postId
func (s *SysPostController) Info(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
postId := c.Param("postId")
if postId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.sysPostService.SelectPostById(postId)
if data.PostID == postId {
+ // 处理多语言
+ data.PostName = i18n.TKey(language, data.PostName)
+ data.Remark = i18n.TKey(language, data.Remark)
c.JSON(200, result.OkData(data))
return
}
@@ -60,10 +77,11 @@ func (s *SysPostController) Info(c *gin.Context) {
//
// POST /
func (s *SysPostController) Add(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysPost
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.PostID != "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -71,7 +89,7 @@ func (s *SysPostController) Add(c *gin.Context) {
uniqueuPostName := s.sysPostService.CheckUniquePostName(body.PostName, "")
if !uniqueuPostName {
// 岗位新增【%s】失败,岗位名称已存在
- msg := fmt.Sprintf("Job addition [%s] failed, job name already exists", body.PostName)
+ msg := i18n.TTemplate(language, "post.errNameExists", map[string]any{"name": body.PostName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -80,7 +98,7 @@ func (s *SysPostController) Add(c *gin.Context) {
uniquePostCode := s.sysPostService.CheckUniquePostCode(body.PostCode, "")
if !uniquePostCode {
// 岗位新增【%s】失败,岗位编码已存在
- msg := fmt.Sprintf("Job addition [%s] failed, job code already exists", body.PostCode)
+ msg := i18n.TTemplate(language, "post.errCodeExists", map[string]any{"name": body.PostCode})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -98,10 +116,11 @@ func (s *SysPostController) Add(c *gin.Context) {
//
// PUT /
func (s *SysPostController) Edit(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysPost
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.PostID == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -109,7 +128,7 @@ func (s *SysPostController) Edit(c *gin.Context) {
post := s.sysPostService.SelectPostById(body.PostID)
if post.PostID != body.PostID {
// 没有可访问岗位数据!
- c.JSON(200, result.ErrMsg("There is no accessible post data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "post.noData")))
return
}
@@ -117,7 +136,7 @@ func (s *SysPostController) Edit(c *gin.Context) {
uniqueuPostName := s.sysPostService.CheckUniquePostName(body.PostName, body.PostID)
if !uniqueuPostName {
// 岗位修改【%s】失败,岗位名称已存在
- msg := fmt.Sprintf("Post modification [%s] failed, post name already exists", body.PostName)
+ msg := i18n.TTemplate(language, "post.errNameExists", map[string]any{"name": body.PostName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -126,7 +145,7 @@ func (s *SysPostController) Edit(c *gin.Context) {
uniquePostCode := s.sysPostService.CheckUniquePostCode(body.PostCode, body.PostID)
if !uniquePostCode {
// 岗位修改【%s】失败,岗位编码已存在
- msg := fmt.Sprintf("Post modification [%s] failed, post code already exists", body.PostCode)
+ msg := i18n.TTemplate(language, "post.errCodeExists", map[string]any{"name": body.PostCode})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -144,9 +163,10 @@ func (s *SysPostController) Edit(c *gin.Context) {
//
// DELETE /:postIds
func (s *SysPostController) Remove(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
postIds := c.Param("postIds")
if postIds == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 处理字符转id数组后去重
@@ -161,7 +181,7 @@ func (s *SysPostController) Remove(c *gin.Context) {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
- msg := fmt.Sprintf("Deleted successfully: %d", rows)
+ msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
}
@@ -169,33 +189,43 @@ func (s *SysPostController) Remove(c *gin.Context) {
//
// POST /export
func (s *SysPostController) Export(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
data := s.sysPostService.SelectPostPage(querys)
if data["total"].(int64) == 0 {
// 导出数据记录为空
- c.JSON(200, result.ErrMsg("Export data record is empty"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.SysPost)
+ // 闭包函数处理多语言
+ converI18n := func(language string, arr *[]model.SysPost) {
+ for i := range *arr {
+ (*arr)[i].PostName = i18n.TKey(language, (*arr)[i].PostName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &rows)
+
// 导出文件名称
fileName := fmt.Sprintf("post_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
// 第一行表头标题
headerCells := map[string]string{
- "A1": "PostID",
- "B1": "PostCode",
- "C1": "PostName",
- "D1": "PostSort",
- "E1": "Status",
+ "A1": i18n.TKey(language, "post.export.id"),
+ "B1": i18n.TKey(language, "post.export.code"),
+ "C1": i18n.TKey(language, "post.export.name"),
+ "D1": i18n.TKey(language, "post.export.sort"),
+ "E1": i18n.TKey(language, "post.export.status"),
}
// 从第二行开始的数据
dataCells := make([]map[string]any, 0)
for i, row := range rows {
idx := strconv.Itoa(i + 2)
- statusValue := "deactivate"
+ statusValue := i18n.TKey(language, "dictData.disable")
if row.Status == "1" {
- statusValue = "normalcy"
+ statusValue = i18n.TKey(language, "dictData.normal")
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.PostID,
diff --git a/src/modules/system/controller/sys_profile.go b/src/modules/system/controller/sys_profile.go
index 195c9819..e0941022 100644
--- a/src/modules/system/controller/sys_profile.go
+++ b/src/modules/system/controller/sys_profile.go
@@ -1,11 +1,10 @@
package controller
import (
- "fmt"
-
"ems.agt/src/framework/config"
"ems.agt/src/framework/constants/admin"
"ems.agt/src/framework/constants/uploadsubpath"
+ "ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/crypto"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
@@ -46,9 +45,10 @@ type SysProfileController struct {
//
// GET /
func (s *SysProfileController) Info(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
loginUser, err := ctx.LoginUser(c)
if err != nil {
- c.JSON(401, result.CodeMsg(401, err.Error()))
+ c.JSON(401, result.CodeMsg(401, i18n.TKey(language, err.Error())))
return
}
@@ -56,20 +56,26 @@ func (s *SysProfileController) Info(c *gin.Context) {
roleGroup := []string{}
roles := s.sysRoleService.SelectRoleListByUserId(loginUser.UserID)
for _, role := range roles {
- roleGroup = append(roleGroup, role.RoleName)
+ roleGroup = append(roleGroup, i18n.TKey(language, role.RoleName))
}
isAdmin := config.IsAdmin(loginUser.UserID)
if isAdmin {
- roleGroup = append(roleGroup, "Administrator")
+ roleGroup = append(roleGroup, i18n.TKey(language, "role.admin"))
}
// 查询用户所属岗位组
postGroup := []string{}
posts := s.sysPostService.SelectPostListByUserId(loginUser.UserID)
for _, post := range posts {
- postGroup = append(postGroup, post.PostName)
+ postGroup = append(postGroup, i18n.TKey(language, post.PostName))
}
+ loginUser.User.NickName = i18n.TKey(language, loginUser.User.NickName)
+ loginUser.User.Remark = i18n.TKey(language, loginUser.User.Remark)
+ loginUser.User.Dept.DeptName = i18n.TKey(language, loginUser.User.Dept.DeptName)
+ for ri := range loginUser.User.Roles {
+ loginUser.User.Roles[ri].RoleName = i18n.TKey(language, loginUser.User.Roles[ri].RoleName)
+ }
c.JSON(200, result.OkData(map[string]any{
"user": loginUser.User,
"roleGroup": parse.RemoveDuplicates(roleGroup),
@@ -81,6 +87,7 @@ func (s *SysProfileController) Info(c *gin.Context) {
//
// PUT /
func (s *SysProfileController) UpdateProfile(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body struct {
// 昵称
NickName string `json:"nickName" binding:"required"`
@@ -93,14 +100,14 @@ func (s *SysProfileController) UpdateProfile(c *gin.Context) {
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.Sex == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 登录用户信息
loginUser, err := ctx.LoginUser(c)
if err != nil {
- c.JSON(401, result.CodeMsg(401, err.Error()))
+ c.JSON(401, result.CodeMsg(401, i18n.TKey(language, err.Error())))
return
}
userId := loginUser.UserID
@@ -112,13 +119,13 @@ func (s *SysProfileController) UpdateProfile(c *gin.Context) {
uniquePhone := s.sysUserService.CheckUniquePhone(body.PhoneNumber, userId)
if !uniquePhone {
// 修改用户【%s】失败,手机号码已存在
- msg := fmt.Sprintf("Failed to modify user [%s], cell phone number already exists", userName)
+ msg := i18n.TTemplate(language, "user.errPhoneExists", map[string]any{"name": userName})
c.JSON(200, result.ErrMsg(msg))
return
}
} else {
// 修改用户【%s】失败,手机号码格式错误
- msg := fmt.Sprintf("Failed to modify user [%s], wrong format of cell phone number", userName)
+ msg := i18n.TTemplate(language, "user.errPhoneFormat", map[string]any{"name": userName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -130,13 +137,13 @@ func (s *SysProfileController) UpdateProfile(c *gin.Context) {
uniqueEmail := s.sysUserService.CheckUniqueEmail(body.Email, userId)
if !uniqueEmail {
// 修改用户【%s】失败,邮箱已存在
- msg := fmt.Sprintf("Failed to modify user [%s], mailbox already exists", userName)
+ msg := i18n.TTemplate(language, "user.errEmailExists", map[string]any{"name": userName})
c.JSON(200, result.ErrMsg(msg))
return
}
} else {
// 修改用户【%s】失败,邮箱格式错误
- msg := fmt.Sprintf("Failed to modify user [%s], mailbox format error", userName)
+ msg := i18n.TTemplate(language, "user.errEmailFormat", map[string]any{"name": userName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -169,14 +176,14 @@ func (s *SysProfileController) UpdateProfile(c *gin.Context) {
c.JSON(200, result.Ok(nil))
return
}
- // 上传图片异常
- c.JSON(200, result.ErrMsg("Upload Image Exception"))
+ c.JSON(200, result.Err(nil))
}
// 个人重置密码
//
// PUT /updatePwd
func (s *SysProfileController) UpdatePwd(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body struct {
// 旧密码
OldPassword string `json:"oldPassword" binding:"required"`
@@ -185,14 +192,14 @@ func (s *SysProfileController) UpdatePwd(c *gin.Context) {
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 登录用户信息
loginUser, err := ctx.LoginUser(c)
if err != nil {
- c.JSON(401, result.CodeMsg(401, err.Error()))
+ c.JSON(401, result.CodeMsg(401, i18n.TKey(language, err.Error())))
return
}
userId := loginUser.UserID
@@ -202,7 +209,7 @@ func (s *SysProfileController) UpdatePwd(c *gin.Context) {
user := s.sysUserService.SelectUserById(userId)
if user.UserID != userId {
// 没有可访问用户数据!
- c.JSON(200, result.ErrMsg("There is no accessible user data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "user.noData")))
return
}
@@ -210,13 +217,13 @@ func (s *SysProfileController) UpdatePwd(c *gin.Context) {
oldCompare := crypto.BcryptCompare(body.OldPassword, user.Password)
if !oldCompare {
// 修改密码失败,旧密码错误
- c.JSON(200, result.ErrMsg("Failed to change password, old password is wrong"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "user.errPasswdOld")))
return
}
newCompare := crypto.BcryptCompare(body.NewPassword, user.Password)
if newCompare {
// 新密码不能与旧密码相同
- c.JSON(200, result.ErrMsg("The new password cannot be the same as the old one"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "user.errPasswdEqOld")))
return
}
@@ -238,9 +245,10 @@ func (s *SysProfileController) UpdatePwd(c *gin.Context) {
//
// POST /avatar
func (s *SysProfileController) Avatar(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
formFile, err := c.FormFile("file")
if err != nil {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -254,7 +262,7 @@ func (s *SysProfileController) Avatar(c *gin.Context) {
// 登录用户信息
loginUser, err := ctx.LoginUser(c)
if err != nil {
- c.JSON(401, result.CodeMsg(401, err.Error()))
+ c.JSON(401, result.CodeMsg(401, i18n.TKey(language, err.Error())))
return
}
diff --git a/src/modules/system/controller/sys_role.go b/src/modules/system/controller/sys_role.go
index dc94a1c1..c27e25ae 100644
--- a/src/modules/system/controller/sys_role.go
+++ b/src/modules/system/controller/sys_role.go
@@ -7,7 +7,7 @@ import (
"time"
"ems.agt/src/framework/constants/admin"
- "ems.agt/src/framework/constants/roledatascope"
+ "ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/file"
"ems.agt/src/framework/utils/parse"
@@ -21,8 +21,9 @@ import (
// 实例化控制层 SysRoleController 结构体
var NewSysRole = &SysRoleController{
- sysRoleService: service.NewSysRoleImpl,
- sysUserService: service.NewSysUserImpl,
+ sysRoleService: service.NewSysRoleImpl,
+ sysUserService: service.NewSysUserImpl,
+ sysDictDataService: service.NewSysDictDataImpl,
}
// 角色信息
@@ -33,6 +34,8 @@ type SysRoleController struct {
sysRoleService service.ISysRole
// 用户服务
sysUserService service.ISysUser
+ // 字典数据服务
+ sysDictDataService service.ISysDictData
}
// 角色列表
@@ -42,6 +45,18 @@ func (s *SysRoleController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "")
data := s.sysRoleService.SelectRolePage(querys, dataScopeSQL)
+
+ rows := data["rows"].([]model.SysRole)
+ // 闭包函数处理多语言
+ language := ctx.AcceptLanguage(c)
+ converI18n := func(language string, arr *[]model.SysRole) {
+ for i := range *arr {
+ (*arr)[i].RoleName = i18n.TKey(language, (*arr)[i].RoleName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &rows)
+
c.JSON(200, result.Ok(data))
}
@@ -49,13 +64,16 @@ func (s *SysRoleController) List(c *gin.Context) {
//
// GET /:roleId
func (s *SysRoleController) Info(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
roleId := c.Param("roleId")
if roleId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.sysRoleService.SelectRoleById(roleId)
if data.RoleID == roleId {
+ data.RoleName = i18n.TKey(language, data.RoleName)
+ data.Remark = i18n.TKey(language, data.Remark)
c.JSON(200, result.OkData(data))
return
}
@@ -66,10 +84,11 @@ func (s *SysRoleController) Info(c *gin.Context) {
//
// POST /
func (s *SysRoleController) Add(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysRole
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.RoleID != "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -77,7 +96,7 @@ func (s *SysRoleController) Add(c *gin.Context) {
uniqueRoleName := s.sysRoleService.CheckUniqueRoleName(body.RoleName, "")
if !uniqueRoleName {
// 角色新增【%s】失败,角色名称已存在
- msg := fmt.Sprintf("Character addition [%s] failed, character name already exists", body.RoleName)
+ msg := i18n.TTemplate(language, "role.errNameExists", map[string]any{"name": body.RoleName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -86,7 +105,7 @@ func (s *SysRoleController) Add(c *gin.Context) {
uniqueRoleKey := s.sysRoleService.CheckUniqueRoleKey(body.RoleKey, "")
if !uniqueRoleKey {
// 角色新增【%s】失败,角色键值已存在
- msg := fmt.Sprintf("Character addition [%s] failed, character key already exists", body.RoleName)
+ msg := i18n.TTemplate(language, "role.errKeyExists", map[string]any{"name": body.RoleName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -104,17 +123,18 @@ func (s *SysRoleController) Add(c *gin.Context) {
//
// PUT /
func (s *SysRoleController) Edit(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysRole
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.RoleID == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 检查是否管理员角色
if body.RoleID == admin.ROLE_ID {
// 不允许操作管理员角色
- c.JSON(200, result.ErrMsg("The administrator role is not allowed to operate"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.errOperateRole")))
return
}
@@ -122,15 +142,16 @@ func (s *SysRoleController) Edit(c *gin.Context) {
role := s.sysRoleService.SelectRoleById(body.RoleID)
if role.RoleID != body.RoleID {
// 没有可访问角色数据!
- c.JSON(200, result.ErrMsg("There is no accessible role data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "role.noData")))
return
}
// 判断角色名称是否唯一
uniqueRoleName := s.sysRoleService.CheckUniqueRoleName(body.RoleName, body.RoleID)
if !uniqueRoleName {
- // 角色修改【%s】失败,角色名称已存在
- msg := fmt.Sprintf("Character modification [%s] failed, character name already exists", body.RoleName)
+ // 操作角色【%s】失败,角色名称已存在
+ // msg := fmt.Sprintf("Character modification [%s] failed, character name already exists", body.RoleName)
+ msg := i18n.TTemplate(language, "role.errNameExists", map[string]any{"name": body.RoleName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -139,7 +160,8 @@ func (s *SysRoleController) Edit(c *gin.Context) {
uniqueRoleKey := s.sysRoleService.CheckUniqueRoleKey(body.RoleKey, body.RoleID)
if !uniqueRoleKey {
// 角色修改【%s】失败,角色键值已存在
- msg := fmt.Sprintf("Character modification [%s] failed, character key already exists", body.RoleName)
+ // msg := fmt.Sprintf("Character modification [%s] failed, character key already exists", body.RoleName)
+ msg := i18n.TTemplate(language, "role.errKeyExists", map[string]any{"name": body.RoleName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -157,9 +179,10 @@ func (s *SysRoleController) Edit(c *gin.Context) {
//
// DELETE /:roleIds
func (s *SysRoleController) Remove(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
roleIds := c.Param("roleIds")
if roleIds == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 处理字符转id数组后去重
@@ -173,7 +196,7 @@ func (s *SysRoleController) Remove(c *gin.Context) {
for _, id := range uniqueIDs {
if id == admin.ROLE_ID {
// 不允许操作管理员角色
- c.JSON(200, result.ErrMsg("The administrator role is not allowed to operate"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.errOperateRole")))
return
}
}
@@ -182,7 +205,7 @@ func (s *SysRoleController) Remove(c *gin.Context) {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
- msg := fmt.Sprintf("Deleted successfully: %d", rows)
+ msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
}
@@ -190,6 +213,7 @@ func (s *SysRoleController) Remove(c *gin.Context) {
//
// PUT /changeStatus
func (s *SysRoleController) Status(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body struct {
// 角色ID
RoleID string `json:"roleId" binding:"required"`
@@ -198,14 +222,14 @@ func (s *SysRoleController) Status(c *gin.Context) {
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 检查是否管理员角色
if body.RoleID == admin.ROLE_ID {
// 不允许操作管理员角色
- c.JSON(200, result.ErrMsg("The administrator role is not allowed to operate"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.errOperateRole")))
return
}
@@ -213,14 +237,14 @@ func (s *SysRoleController) Status(c *gin.Context) {
role := s.sysRoleService.SelectRoleById(body.RoleID)
if role.RoleID != body.RoleID {
// 没有可访问角色数据!
- c.JSON(200, result.ErrMsg("There is no accessible role data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "role.noData")))
return
}
// 与旧值相等不变更
if role.Status == body.Status {
// 变更状态与旧值相等!
- c.JSON(200, result.ErrMsg("The change status is equal to the old value!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "role.statusEq")))
return
}
@@ -243,6 +267,7 @@ func (s *SysRoleController) Status(c *gin.Context) {
//
// PUT /dataScope
func (s *SysRoleController) DataScope(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body struct {
// 角色ID
RoleID string `json:"roleId"`
@@ -255,14 +280,14 @@ func (s *SysRoleController) DataScope(c *gin.Context) {
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 检查是否管理员角色
if body.RoleID == admin.ROLE_ID {
// 不允许操作管理员角色
- c.JSON(200, result.ErrMsg("The administrator role is not allowed to operate"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.errOperateRole")))
return
}
@@ -270,7 +295,7 @@ func (s *SysRoleController) DataScope(c *gin.Context) {
role := s.sysRoleService.SelectRoleById(body.RoleID)
if role.RoleID != body.RoleID {
// 没有可访问角色数据!
- c.JSON(200, result.ErrMsg("There is no accessible role data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "role.noData")))
return
}
@@ -295,10 +320,11 @@ func (s *SysRoleController) DataScope(c *gin.Context) {
//
// GET /authUser/allocatedList
func (s *SysRoleController) AuthUserAllocatedList(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
querys := ctx.QueryMap(c)
roleId, ok := querys["roleId"]
if !ok || roleId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -306,7 +332,7 @@ func (s *SysRoleController) AuthUserAllocatedList(c *gin.Context) {
role := s.sysRoleService.SelectRoleById(roleId.(string))
if role.RoleID != roleId {
// 没有可访问角色数据!
- c.JSON(200, result.ErrMsg("There is no accessible role data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "role.noData")))
return
}
@@ -319,6 +345,7 @@ func (s *SysRoleController) AuthUserAllocatedList(c *gin.Context) {
//
// PUT /authUser/checked
func (s *SysRoleController) AuthUserChecked(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body struct {
// 角色ID
RoleID string `json:"roleId" binding:"required"`
@@ -329,7 +356,7 @@ func (s *SysRoleController) AuthUserChecked(c *gin.Context) {
}
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -344,7 +371,7 @@ func (s *SysRoleController) AuthUserChecked(c *gin.Context) {
// 检查是否存在
role := s.sysRoleService.SelectRoleById(body.RoleID)
if role.RoleID != body.RoleID {
- c.JSON(200, result.ErrMsg("There is no accessible role data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "role.noData")))
return
}
@@ -365,41 +392,56 @@ func (s *SysRoleController) AuthUserChecked(c *gin.Context) {
//
// POST /export
func (s *SysRoleController) Export(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "")
data := s.sysRoleService.SelectRolePage(querys, dataScopeSQL)
if data["total"].(int64) == 0 {
// 导出数据记录为空
- c.JSON(200, result.ErrMsg("Export data record is empty"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.SysRole)
+ // 闭包函数处理多语言
+ converI18n := func(language string, arr *[]model.SysRole) {
+ for i := range *arr {
+ (*arr)[i].RoleName = i18n.TKey(language, (*arr)[i].RoleName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18n(language, &rows)
+
// 导出文件名称
fileName := fmt.Sprintf("role_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
// 第一行表头标题
headerCells := map[string]string{
- "A1": "RoleID",
- "B1": "RoleName",
- "C1": "RoleKey",
- "D1": "RoleSort",
- "E1": "DataScope",
- "F1": "Status",
+ "A1": i18n.TKey(language, "role.export.id"),
+ "B1": i18n.TKey(language, "role.export.name"),
+ "C1": i18n.TKey(language, "role.export.key"),
+ "D1": i18n.TKey(language, "role.export.sort"),
+ "E1": i18n.TKey(language, "role.export.dataScope"),
+ "F1": i18n.TKey(language, "role.export.status"),
}
+ // 读取系统角色数据范围字典数据
+ dictSysRoleDatascope := s.sysDictDataService.SelectDictDataByType("sys_role_datascope")
// 从第二行开始的数据
dataCells := make([]map[string]any, 0)
for i, row := range rows {
idx := strconv.Itoa(i + 2)
// 数据范围
- dataScope := "Empty"
- if v, ok := roledatascope.RoleDataScope[row.DataScope]; ok {
- dataScope = v
+ dataScope := row.DataScope
+ for _, v := range dictSysRoleDatascope {
+ if row.DataScope == v.DictValue {
+ dataScope = i18n.TKey(language, v.DictLabel)
+ break
+ }
}
// 角色状态
- statusValue := "deactivate"
+ statusValue := i18n.TKey(language, "dictData.disable")
if row.Status == "1" {
- statusValue = "normalcy"
+ statusValue = i18n.TKey(language, "dictData.normal")
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.RoleID,
diff --git a/src/modules/system/controller/sys_user.go b/src/modules/system/controller/sys_user.go
index c8de6f28..f656f233 100644
--- a/src/modules/system/controller/sys_user.go
+++ b/src/modules/system/controller/sys_user.go
@@ -8,6 +8,8 @@ import (
"ems.agt/src/framework/config"
"ems.agt/src/framework/constants/admin"
+ "ems.agt/src/framework/constants/common"
+ "ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/utils/date"
"ems.agt/src/framework/utils/file"
@@ -27,6 +29,7 @@ var NewSysUser = &SysUserController{
sysRoleService: service.NewSysRoleImpl,
sysPostService: service.NewSysPostImpl,
sysDictDataService: service.NewSysDictDataImpl,
+ sysConfigService: service.NewSysConfigImpl,
}
// 用户信息
@@ -41,6 +44,8 @@ type SysUserController struct {
sysPostService service.ISysPost
// 字典数据服务
sysDictDataService service.ISysDictData
+ // 参数配置服务
+ sysConfigService service.ISysConfig
}
// 用户信息列表
@@ -50,6 +55,22 @@ func (s *SysUserController) List(c *gin.Context) {
querys := ctx.QueryMap(c)
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "u")
data := s.sysUserService.SelectUserPage(querys, dataScopeSQL)
+
+ rows := data["rows"].([]model.SysUser)
+ // 闭包函数处理多语言
+ language := ctx.AcceptLanguage(c)
+ converI18n := func(language string, arr *[]model.SysUser) {
+ for i := range *arr {
+ (*arr)[i].NickName = i18n.TKey(language, (*arr)[i].NickName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ (*arr)[i].Dept.DeptName = i18n.TKey(language, (*arr)[i].Dept.DeptName)
+ for ri := range (*arr)[i].Roles {
+ (*arr)[i].Roles[ri].RoleName = i18n.TKey(language, (*arr)[i].Roles[ri].RoleName)
+ }
+ }
+ }
+ converI18n(language, &rows)
+
c.JSON(200, result.Ok(data))
}
@@ -57,11 +78,13 @@ func (s *SysUserController) List(c *gin.Context) {
//
// GET /:userId
func (s *SysUserController) Info(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
userId := c.Param("userId")
if userId == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
+
// 查询系统角色列表
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "")
roles := s.sysRoleService.SelectRoleList(model.SysRole{}, dataScopeSQL)
@@ -77,9 +100,27 @@ func (s *SysUserController) Info(c *gin.Context) {
roles = rolesFilter
}
+ // 闭包函数处理多语言
+ converI18nRoles := func(language string, arr *[]model.SysRole) {
+ for i := range *arr {
+ (*arr)[i].RoleName = i18n.TKey(language, (*arr)[i].RoleName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18nRoles(language, &roles)
+
// 查询系统岗位列表
posts := s.sysPostService.SelectPostList(model.SysPost{})
+ // 闭包函数处理多语言
+ converI18nPosts := func(language string, arr *[]model.SysPost) {
+ for i := range *arr {
+ (*arr)[i].PostName = i18n.TKey(language, (*arr)[i].PostName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ }
+ }
+ converI18nPosts(language, &posts)
+
// 新增用户时,用户ID为0
if userId == "0" {
c.JSON(200, result.OkData(map[string]any{
@@ -95,10 +136,18 @@ func (s *SysUserController) Info(c *gin.Context) {
// 检查用户是否存在
user := s.sysUserService.SelectUserById(userId)
if user.UserID != userId {
- c.JSON(200, result.ErrMsg("There is no accessible user data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "user.noData")))
return
}
+ // 处理多语言
+ user.NickName = i18n.TKey(language, user.NickName)
+ user.Remark = i18n.TKey(language, user.Remark)
+ user.Dept.DeptName = i18n.TKey(language, user.Dept.DeptName)
+ for ri := range user.Roles {
+ user.Roles[ri].RoleName = i18n.TKey(language, user.Roles[ri].RoleName)
+ }
+
// 角色ID组
roleIds := make([]string, 0)
for _, r := range user.Roles {
@@ -125,10 +174,11 @@ func (s *SysUserController) Info(c *gin.Context) {
//
// POST /
func (s *SysUserController) Add(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysUser
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.UserID != "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -137,7 +187,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, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
body.Password = bodyPassword.Password
@@ -146,7 +196,8 @@ func (s *SysUserController) Add(c *gin.Context) {
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.UserName, "")
if !uniqueUserName {
// 新增用户【%s】失败,登录账号已存在
- msg := fmt.Sprintf("Failed to add user [%s], login account already exists", body.UserName)
+ // msg := fmt.Sprintf("Failed to add user [%s], login account already exists", body.UserName)
+ msg := i18n.TTemplate(language, "user.errNameExists", map[string]any{"name": body.UserName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -157,13 +208,15 @@ func (s *SysUserController) Add(c *gin.Context) {
uniquePhone := s.sysUserService.CheckUniquePhone(body.PhoneNumber, "")
if !uniquePhone {
// 新增用户【%s】失败,手机号码已存在
- msg := fmt.Sprintf("Failed to add user [%s], cell phone number already exists", body.UserName)
+ // msg := fmt.Sprintf("Failed to add user [%s], cell phone number already exists", body.UserName)
+ msg := i18n.TTemplate(language, "user.errPhoneExists", map[string]any{"name": body.UserName})
c.JSON(200, result.ErrMsg(msg))
return
}
} else {
// 新增用户【%s】失败,手机号码格式错误
- msg := fmt.Sprintf("Failed to add user [%s], wrong format of cell phone number", body.UserName)
+ // msg := fmt.Sprintf("Failed to add user [%s], wrong format of cell phone number", body.UserName)
+ msg := i18n.TTemplate(language, "user.errPhoneFormat", map[string]any{"name": body.UserName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -175,13 +228,15 @@ func (s *SysUserController) Add(c *gin.Context) {
uniqueEmail := s.sysUserService.CheckUniqueEmail(body.Email, "")
if !uniqueEmail {
// 新增用户【%s】失败,邮箱已存在
- msg := fmt.Sprintf("Failed to add user [%s], mailbox already exists", body.UserName)
+ // msg := fmt.Sprintf("Failed to add user [%s], mailbox already exists", body.UserName)
+ msg := i18n.TTemplate(language, "user.errEmailExists", map[string]any{"name": body.UserName})
c.JSON(200, result.ErrMsg(msg))
return
}
} else {
// 新增用户【%s】失败,邮箱格式错误
- msg := fmt.Sprintf("Failed to add user [%s], mailbox format error", body.UserName)
+ // msg := fmt.Sprintf("Failed to add user [%s], mailbox format error", body.UserName)
+ msg := i18n.TTemplate(language, "user.errEmailFormat", map[string]any{"name": body.UserName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -200,24 +255,25 @@ func (s *SysUserController) Add(c *gin.Context) {
//
// POST /
func (s *SysUserController) Edit(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body model.SysUser
err := c.ShouldBindBodyWith(&body, binding.JSON)
if err != nil || body.UserID == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 检查是否管理员用户
if config.IsAdmin(body.UserID) {
// 不允许操作管理员用户
- c.JSON(200, result.ErrMsg("Administrator users are not allowed to operate"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.errOperateAdmin")))
return
}
user := s.sysUserService.SelectUserById(body.UserID)
if user.UserID != body.UserID {
// 没有可访问用户数据!
- c.JSON(200, result.ErrMsg("There is no accessible user data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "user.noData")))
return
}
@@ -225,7 +281,8 @@ func (s *SysUserController) Edit(c *gin.Context) {
uniqueUserName := s.sysUserService.CheckUniqueUserName(body.UserName, body.UserID)
if !uniqueUserName {
// 修改用户【%s】失败,登录账号已存在
- msg := fmt.Sprintf("Failed to modify user [%s], login account already exists", body.UserName)
+ // msg := fmt.Sprintf("Failed to modify user [%s], login account already exists", body.UserName)
+ msg := i18n.TTemplate(language, "user.errNameExists", map[string]any{"name": body.UserName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -236,13 +293,15 @@ func (s *SysUserController) Edit(c *gin.Context) {
uniquePhone := s.sysUserService.CheckUniquePhone(body.PhoneNumber, body.UserID)
if !uniquePhone {
// 修改用户【%s】失败,手机号码已存在
- msg := fmt.Sprintf("Failed to modify user [%s], cell phone number already exists", body.UserName)
+ // msg := fmt.Sprintf("Failed to modify user [%s], cell phone number already exists", body.UserName)
+ msg := i18n.TTemplate(language, "user.errPhoneExists", map[string]any{"name": body.UserName})
c.JSON(200, result.ErrMsg(msg))
return
}
} else {
// 修改用户【%s】失败,手机号码格式错误
- msg := fmt.Sprintf("Failed to modify user [%s], wrong format of cell phone number", body.UserName)
+ // msg := fmt.Sprintf("Failed to modify user [%s], wrong format of cell phone number", body.UserName)
+ msg := i18n.TTemplate(language, "user.errPhoneFormat", map[string]any{"name": body.UserName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -254,13 +313,15 @@ func (s *SysUserController) Edit(c *gin.Context) {
uniqueEmail := s.sysUserService.CheckUniqueEmail(body.Email, body.UserID)
if !uniqueEmail {
// 修改用户【%s】失败,邮箱已存在
- msg := fmt.Sprintf("Failed to modify user [%s], mailbox already exists", body.UserName)
+ // msg := fmt.Sprintf("Failed to modify user [%s], mailbox already exists", body.UserName)
+ msg := i18n.TTemplate(language, "user.errEmailExists", map[string]any{"name": body.UserName})
c.JSON(200, result.ErrMsg(msg))
return
}
} else {
// 修改用户【%s】失败,邮箱格式错误
- msg := fmt.Sprintf("Failed to modify user [%s], mailbox format error", body.UserName)
+ // msg := fmt.Sprintf("Failed to modify user [%s], mailbox format error", body.UserName)
+ msg := i18n.TTemplate(language, "user.errEmailFormat", map[string]any{"name": body.UserName})
c.JSON(200, result.ErrMsg(msg))
return
}
@@ -283,9 +344,10 @@ func (s *SysUserController) Edit(c *gin.Context) {
//
// DELETE /:userIds
func (s *SysUserController) Remove(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
userIds := c.Param("userIds")
if userIds == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 处理字符转id数组后去重
@@ -295,13 +357,23 @@ func (s *SysUserController) Remove(c *gin.Context) {
c.JSON(200, result.Err(nil))
return
}
+
+ // 检查是否管理员用户
+ for _, id := range uniqueIDs {
+ if config.IsAdmin(id) {
+ // 不允许操作管理员用户
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.errOperateAdmin")))
+ return
+ }
+ }
+
rows, err := s.sysUserService.DeleteUserByIds(uniqueIDs)
if err != nil {
c.JSON(200, result.ErrMsg(err.Error()))
return
}
// 删除成功:%d
- msg := fmt.Sprintf("Deleted successfully: %d", rows)
+ msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
c.JSON(200, result.OkMsg(msg))
}
@@ -309,31 +381,32 @@ func (s *SysUserController) Remove(c *gin.Context) {
//
// PUT /resetPwd
func (s *SysUserController) ResetPwd(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body struct {
UserID string `json:"userId" binding:"required"`
Password string `json:"password" binding:"required"`
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
// 检查是否管理员用户
if config.IsAdmin(body.UserID) {
- // 不允许操作管理员用户
- c.JSON(200, result.ErrMsg("Administrator users are not allowed to operate"))
+ // 不允许操作内置用户
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.errOperateAdmin")))
return
}
user := s.sysUserService.SelectUserById(body.UserID)
if user.UserID != body.UserID {
// 没有可访问用户数据!
- c.JSON(200, result.ErrMsg("There is no accessible user data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "user.noData")))
return
}
if !regular.ValidPassword(body.Password) {
// 登录密码至少包含大小写字母、数字、特殊符号,且不少于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"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "user.errPasswd")))
return
}
@@ -355,12 +428,13 @@ func (s *SysUserController) ResetPwd(c *gin.Context) {
//
// PUT /changeStatus
func (s *SysUserController) Status(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
var body struct {
UserID string `json:"userId" binding:"required"`
Status string `json:"status" binding:"required"`
}
if err := c.ShouldBindBodyWith(&body, binding.JSON); err != nil {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -368,14 +442,14 @@ func (s *SysUserController) Status(c *gin.Context) {
user := s.sysUserService.SelectUserById(body.UserID)
if user.UserID != body.UserID {
// 没有可访问用户数据!
- c.JSON(200, result.ErrMsg("There is no accessible user data!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "user.noData")))
return
}
// 与旧值相等不变更
if user.Status == body.Status {
// 变更状态与旧值相等!
- c.JSON(200, result.ErrMsg("The change status is equal to the old value!"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "user.statusEq")))
return
}
@@ -397,33 +471,47 @@ func (s *SysUserController) Status(c *gin.Context) {
//
// POST /export
func (s *SysUserController) Export(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
// 查询结果,根据查询条件结果,单页最大值限制
querys := ctx.BodyJSONMap(c)
dataScopeSQL := ctx.LoginUserToDataScopeSQL(c, "d", "u")
data := s.sysUserService.SelectUserPage(querys, dataScopeSQL)
if data["total"].(int64) == 0 {
// 导出数据记录为空
- c.JSON(200, result.ErrMsg("Export data record is empty"))
+ c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
return
}
rows := data["rows"].([]model.SysUser)
+ // 闭包函数处理多语言
+ converI18n := func(language string, arr *[]model.SysUser) {
+ for i := range *arr {
+ (*arr)[i].NickName = i18n.TKey(language, (*arr)[i].NickName)
+ (*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
+ (*arr)[i].Dept.DeptName = i18n.TKey(language, (*arr)[i].Dept.DeptName)
+ for ri := range (*arr)[i].Roles {
+ (*arr)[i].Roles[ri].RoleName = i18n.TKey(language, (*arr)[i].Roles[ri].RoleName)
+ }
+ }
+ }
+ converI18n(language, &rows)
+
// 导出文件名称
fileName := fmt.Sprintf("user_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
// 第一行表头标题
headerCells := map[string]string{
- "A1": "UserID",
- "B1": "UserName",
- "C1": "NickName",
- "D1": "Email",
- "E1": "PhoneNumber",
- "F1": "UserSex",
- "G1": "Status",
- "H1": "DeptID",
- "I1": "DeptName",
- "J1": "DeptLeader",
- "K1": "LoginIP",
- "L1": "LoginDate",
+ "A1": i18n.TKey(language, "user.export.id"),
+ "B1": i18n.TKey(language, "user.export.name"),
+ "C1": i18n.TKey(language, "user.export.nick"),
+ "D1": i18n.TKey(language, "user.export.email"),
+ "E1": i18n.TKey(language, "user.export.phone"),
+ "F1": i18n.TKey(language, "user.export.sex"),
+ "G1": i18n.TKey(language, "user.export.status"),
+ "H1": i18n.TKey(language, "user.export.deptID"),
+ "I1": i18n.TKey(language, "user.export.deptName"),
+ "J1": i18n.TKey(language, "user.export.deptLeader"),
+ "K1": i18n.TKey(language, "user.export.loginIP"),
+ "L1": i18n.TKey(language, "user.export.loginDate"),
}
// 读取用户性别字典数据
dictSysUserSex := s.sysDictDataService.SelectDictDataByType("sys_user_sex")
@@ -432,17 +520,17 @@ func (s *SysUserController) Export(c *gin.Context) {
for i, row := range rows {
idx := strconv.Itoa(i + 2)
// 用户性别
- sysUserSex := "unknown"
+ sysUserSex := row.Sex
for _, v := range dictSysUserSex {
if row.Sex == v.DictValue {
- sysUserSex = v.DictLabel
+ sysUserSex = i18n.TKey(language, v.DictLabel)
break
}
}
// 帐号状态
- statusValue := "deactivate"
+ statusValue := i18n.TKey(language, "dictData.disable")
if row.Status == "1" {
- statusValue = "normalcy"
+ statusValue = i18n.TKey(language, "dictData.normal")
}
dataCells = append(dataCells, map[string]any{
"A" + idx: row.UserID,
@@ -475,11 +563,13 @@ func (s *SysUserController) Export(c *gin.Context) {
// GET /importTemplate
func (s *SysUserController) Template(c *gin.Context) {
fileName := fmt.Sprintf("user_import_template_%d.xlsx", time.Now().UnixMilli())
- asserPath := "assets/template/excel/user_import_template.xlsx"
+
+ // 多语言处理
+ language := ctx.AcceptLanguage(c)
+ asserPath := fmt.Sprintf("assets/template/excel/user_import_template_%s.xlsx", language)
// 从 embed.FS 中读取默认配置文件内容
assetsDir := config.GetAssetsDirFS()
-
// 读取内嵌文件
fileData, err := assetsDir.ReadFile(asserPath)
if err != nil {
@@ -499,12 +589,13 @@ func (s *SysUserController) Template(c *gin.Context) {
//
// POST /importData
func (s *SysUserController) ImportData(c *gin.Context) {
+ language := ctx.AcceptLanguage(c)
// 允许进行更新
updateSupport := c.PostForm("updateSupport")
// 上传的文件
formFile, err := c.FormFile("file")
if err != nil || updateSupport == "" {
- c.JSON(400, result.CodeMsg(400, "parameter error"))
+ c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -525,6 +616,152 @@ func (s *SysUserController) ImportData(c *gin.Context) {
// 获取操作人名称
operName := ctx.LoginUserToUserName(c)
isUpdateSupport := parse.Boolean(updateSupport)
- message := s.sysUserService.ImportUser(rows, isUpdateSupport, operName)
+
+ // 读取默认初始密码
+ initPassword := s.sysConfigService.SelectConfigValueByKey("sys.user.initPassword")
+ // 读取用户性别字典数据
+ dictSysUserSex := s.sysDictDataService.SelectDictDataByType("sys_user_sex")
+
+ // 导入记录
+ successNum := 0
+ failureNum := 0
+ successMsgArr := []string{}
+ failureMsgArr := []string{}
+ mustItemArr := []string{"B", "C"}
+ for _, row := range rows {
+ // 检查必填列
+ ownItem := true
+ for _, item := range mustItemArr {
+ if v, ok := row[item]; !ok || v == "" {
+ ownItem = false
+ break
+ }
+ }
+ if !ownItem {
+ mustItemArrStr := strings.Join(mustItemArr, "、")
+ failureNum++
+ // 表格中必填列表项,
+ msg := i18n.TTemplate(language, "user.import.mustItem", map[string]any{"text": mustItemArrStr})
+ failureMsgArr = append(failureMsgArr, msg)
+ continue
+ }
+
+ // 用户性别转值
+ sysUserSex := "0"
+ for _, v := range dictSysUserSex {
+ label := i18n.TKey(language, v.DictLabel)
+ if row["F"] == label {
+ sysUserSex = v.DictValue
+ break
+ }
+ }
+ sysUserStatus := common.STATUS_NO
+ if row["G"] == "Normal" {
+ sysUserStatus = common.STATUS_YES
+ }
+
+ // 构建用户实体信息
+ newSysUser := model.SysUser{
+ UserType: "sys",
+ Password: initPassword,
+ DeptID: row["H"],
+ UserName: row["B"],
+ NickName: row["C"],
+ PhoneNumber: row["E"],
+ Email: row["D"],
+ Status: sysUserStatus,
+ Sex: sysUserSex,
+ }
+
+ // 检查手机号码格式并判断是否唯一
+ if newSysUser.PhoneNumber != "" {
+ if regular.ValidMobile(newSysUser.PhoneNumber) {
+ uniquePhone := s.sysUserService.CheckUniquePhone(newSysUser.PhoneNumber, "")
+ if !uniquePhone {
+ // 用户编号:%s 手机号码 %s 已存在
+ msg := i18n.TTemplate(language, "user.import.phoneExist", map[string]any{"id": row["A"], "phone": newSysUser.PhoneNumber})
+ failureNum++
+ failureMsgArr = append(failureMsgArr, msg)
+ continue
+ }
+ } else {
+ // 用户编号:%s 手机号码 %s 格式错误
+ msg := i18n.TTemplate(language, "user.import.phoneFormat", map[string]any{"id": row["A"], "phone": newSysUser.PhoneNumber})
+ failureNum++
+ failureMsgArr = append(failureMsgArr, msg)
+ continue
+ }
+ }
+
+ // 检查邮箱格式并判断是否唯一
+ if newSysUser.Email != "" {
+ if regular.ValidEmail(newSysUser.Email) {
+ uniqueEmail := s.sysUserService.CheckUniqueEmail(newSysUser.Email, "")
+ if !uniqueEmail {
+ // 用户编号:%s 用户邮箱 %s 已存在
+ msg := i18n.TTemplate(language, "user.import.emailExist", map[string]any{"id": row["A"], "email": newSysUser.Email})
+ failureNum++
+ failureMsgArr = append(failureMsgArr, msg)
+ continue
+ }
+ } else {
+ // 用户编号:%s 用户邮箱 %s 格式错误
+ msg := i18n.TTemplate(language, "user.import.emailFormat", map[string]any{"id": row["A"], "email": newSysUser.Email})
+ failureNum++
+ failureMsgArr = append(failureMsgArr, msg)
+ continue
+ }
+ }
+
+ // 验证是否存在这个用户
+ userInfo := s.sysUserService.SelectUserByUserName(newSysUser.UserName)
+ if userInfo.UserName != newSysUser.UserName {
+ newSysUser.CreateBy = operName
+ insertId := s.sysUserService.InsertUser(newSysUser)
+ if insertId != "" {
+ // 用户编号:%s 登录名称 %s 导入成功
+ msg := i18n.TTemplate(language, "user.import.success", map[string]any{"id": row["A"], "name": newSysUser.UserName})
+ successNum++
+ successMsgArr = append(successMsgArr, msg)
+ } else {
+ // 用户编号:%s 登录名称 %s 导入失败
+ msg := i18n.TTemplate(language, "user.import.fail", map[string]any{"id": row["A"], "email": newSysUser.UserName})
+ failureNum++
+ failureMsgArr = append(failureMsgArr, msg)
+ }
+ continue
+ }
+
+ // 如果用户已存在 同时 是否更新支持
+ if userInfo.UserName == newSysUser.UserName && isUpdateSupport {
+ newSysUser.UserID = userInfo.UserID
+ newSysUser.UpdateBy = operName
+ rows := s.sysUserService.UpdateUser(newSysUser)
+ if rows > 0 {
+ // 用户编号:%s 登录名称 %s 更新成功
+ msg := i18n.TTemplate(language, "user.import.successUpdate", map[string]any{"id": row["A"], "email": newSysUser.UserName})
+ successNum++
+ successMsgArr = append(successMsgArr, msg)
+ } else {
+ // 用户编号:%s 登录名称 %s 更新失败
+ msg := i18n.TTemplate(language, "user.import.failUpdate", map[string]any{"id": row["A"], "email": newSysUser.UserName})
+ failureNum++
+ failureMsgArr = append(failureMsgArr, msg)
+ }
+ continue
+ }
+ }
+
+ message := ""
+ if failureNum > 0 {
+ // 很抱歉,导入失败!共 %d 条数据格式不正确,错误如下:
+ msg := i18n.TTemplate(language, "user.import.failTip", map[string]any{"num": failureNum})
+ message = strings.Join(append([]string{msg}, failureMsgArr...), "
")
+ } else {
+ // 恭喜您,数据已全部导入成功!共 %d 条,数据如下:
+ msg := i18n.TTemplate(language, "user.import.successTip", map[string]any{"num": failureNum})
+ message = strings.Join(append([]string{msg}, successMsgArr...), "
")
+ }
+
c.JSON(200, result.OkMsg(message))
}
diff --git a/src/modules/system/repository/sys_config.impl.go b/src/modules/system/repository/sys_config.impl.go
index fa5543ee..90d0d3d8 100644
--- a/src/modules/system/repository/sys_config.impl.go
+++ b/src/modules/system/repository/sys_config.impl.go
@@ -1,7 +1,6 @@
package repository
import (
- "fmt"
"strings"
"time"
@@ -186,7 +185,11 @@ func (r *SysConfigImpl) SelectConfigValueByKey(configKey string) string {
return ""
}
if len(results) > 0 {
- return fmt.Sprintf("%v", results[0]["str"])
+ v, ok := results[0]["str"].(string)
+ if ok {
+ return v
+ }
+ return ""
}
return ""
}
@@ -231,7 +234,11 @@ func (r *SysConfigImpl) CheckUniqueConfig(sysConfig model.SysConfig) string {
return ""
}
if len(results) > 0 {
- return fmt.Sprintf("%v", results[0]["str"])
+ v, ok := results[0]["str"].(string)
+ if ok {
+ return v
+ }
+ return ""
}
return ""
}
@@ -303,9 +310,7 @@ func (r *SysConfigImpl) UpdateConfig(sysConfig model.SysConfig) int64 {
if sysConfig.ConfigType != "" {
params["config_type"] = sysConfig.ConfigType
}
- if sysConfig.Remark != "" {
- params["remark"] = sysConfig.Remark
- }
+ params["remark"] = sysConfig.Remark
if sysConfig.UpdateBy != "" {
params["update_by"] = sysConfig.UpdateBy
params["update_time"] = time.Now().UnixMilli()
diff --git a/src/modules/system/repository/sys_dept.impl.go b/src/modules/system/repository/sys_dept.impl.go
index e5698bcd..550d0eb8 100644
--- a/src/modules/system/repository/sys_dept.impl.go
+++ b/src/modules/system/repository/sys_dept.impl.go
@@ -226,7 +226,11 @@ func (r *SysDeptImpl) CheckUniqueDept(sysDept model.SysDept) string {
return ""
}
if len(results) > 0 {
- return fmt.Sprintf("%v", results[0]["str"])
+ v, ok := results[0]["str"].(string)
+ if ok {
+ return v
+ }
+ return ""
}
return ""
}
diff --git a/src/modules/system/repository/sys_dict_data.impl.go b/src/modules/system/repository/sys_dict_data.impl.go
index ab1440d6..055762a2 100644
--- a/src/modules/system/repository/sys_dict_data.impl.go
+++ b/src/modules/system/repository/sys_dict_data.impl.go
@@ -1,7 +1,6 @@
package repository
import (
- "fmt"
"strings"
"time"
@@ -220,7 +219,11 @@ func (r *SysDictDataImpl) CheckUniqueDictData(sysDictData model.SysDictData) str
return ""
}
if len(results) > 0 {
- return fmt.Sprintf("%v", results[0]["str"])
+ v, ok := results[0]["str"].(string)
+ if ok {
+ return v
+ }
+ return ""
}
return ""
}
diff --git a/src/modules/system/repository/sys_dict_type.impl.go b/src/modules/system/repository/sys_dict_type.impl.go
index 3333263f..0dd63b25 100644
--- a/src/modules/system/repository/sys_dict_type.impl.go
+++ b/src/modules/system/repository/sys_dict_type.impl.go
@@ -1,7 +1,6 @@
package repository
import (
- "fmt"
"strings"
"time"
@@ -232,7 +231,11 @@ func (r *SysDictTypeImpl) CheckUniqueDictType(sysDictType model.SysDictType) str
return ""
}
if len(results) > 0 {
- return fmt.Sprintf("%v", results[0]["str"])
+ v, ok := results[0]["str"].(string)
+ if ok {
+ return v
+ }
+ return ""
}
return ""
}
diff --git a/src/modules/system/repository/sys_menu.impl.go b/src/modules/system/repository/sys_menu.impl.go
index 5b62288f..72975c0e 100644
--- a/src/modules/system/repository/sys_menu.impl.go
+++ b/src/modules/system/repository/sys_menu.impl.go
@@ -468,7 +468,11 @@ func (r *SysMenuImpl) CheckUniqueMenu(sysMenu model.SysMenu) string {
return ""
}
if len(results) > 0 {
- return fmt.Sprintf("%v", results[0]["str"])
+ v, ok := results[0]["str"].(string)
+ if ok {
+ return v
+ }
+ return ""
}
return ""
}
diff --git a/src/modules/system/repository/sys_post.impl.go b/src/modules/system/repository/sys_post.impl.go
index 222737c4..184c98b4 100644
--- a/src/modules/system/repository/sys_post.impl.go
+++ b/src/modules/system/repository/sys_post.impl.go
@@ -1,7 +1,6 @@
package repository
import (
- "fmt"
"strings"
"time"
@@ -315,7 +314,11 @@ func (r *SysPostImpl) CheckUniquePost(sysPost model.SysPost) string {
logger.Errorf("query err %v", err)
}
if len(results) > 0 {
- return fmt.Sprintf("%v", results[0]["str"])
+ v, ok := results[0]["str"].(string)
+ if ok {
+ return v
+ }
+ return ""
}
return ""
}
diff --git a/src/modules/system/repository/sys_role.impl.go b/src/modules/system/repository/sys_role.impl.go
index a3d4a5ea..719ee4e0 100644
--- a/src/modules/system/repository/sys_role.impl.go
+++ b/src/modules/system/repository/sys_role.impl.go
@@ -1,7 +1,6 @@
package repository
import (
- "fmt"
"strings"
"time"
@@ -372,7 +371,11 @@ func (r *SysRoleImpl) CheckUniqueRole(sysRole model.SysRole) string {
return ""
}
if len(results) > 0 {
- return fmt.Sprintf("%v", results[0]["str"])
+ v, ok := results[0]["str"].(string)
+ if ok {
+ return v
+ }
+ return ""
}
return ""
}
diff --git a/src/modules/system/repository/sys_user.impl.go b/src/modules/system/repository/sys_user.impl.go
index 0442150c..05d47c94 100644
--- a/src/modules/system/repository/sys_user.impl.go
+++ b/src/modules/system/repository/sys_user.impl.go
@@ -1,7 +1,6 @@
package repository
import (
- "fmt"
"strings"
"time"
@@ -558,7 +557,11 @@ func (r *SysUserImpl) CheckUniqueUser(sysUser model.SysUser) string {
logger.Errorf("query err %v", err)
}
if len(results) > 0 {
- return fmt.Sprintf("%v", results[0]["str"])
+ v, ok := results[0]["str"].(string)
+ if ok {
+ return v
+ }
+ return ""
}
return ""
}
diff --git a/src/modules/system/service/sys_config.impl.go b/src/modules/system/service/sys_config.impl.go
index eff1a2f8..6fbfd19d 100644
--- a/src/modules/system/service/sys_config.impl.go
+++ b/src/modules/system/service/sys_config.impl.go
@@ -93,13 +93,13 @@ func (r *SysConfigImpl) DeleteConfigByIds(configIds []string) (int64, error) {
// 检查是否存在
configs := r.sysConfigRepository.SelectConfigByIds(configIds)
if len(configs) <= 0 {
- return 0, fmt.Errorf("there is no accessible parameter configuration data")
+ return 0, fmt.Errorf("config.noData")
}
for _, config := range configs {
// 检查是否为内置参数
if config.ConfigType == "Y" {
- // 【%s】 配置参数属于内置参数,禁止删除!
- return 0, fmt.Errorf("[%s] Configuration parameters are built-in parameters and their deletion is prohibited", config.ConfigID)
+ // 操作含有内置参数,禁止删除!
+ return 0, fmt.Errorf("config.errType")
}
// 清除缓存
r.clearConfigCache(config.ConfigKey)
@@ -109,7 +109,7 @@ func (r *SysConfigImpl) DeleteConfigByIds(configIds []string) (int64, error) {
return rows, nil
}
// 删除参数配置信息失败!
- return 0, fmt.Errorf("failed to delete parameter configuration information")
+ return 0, fmt.Errorf("config.errDelete")
}
// ResetConfigCache 重置参数缓存数据
diff --git a/src/modules/system/service/sys_user.go b/src/modules/system/service/sys_user.go
index 23fd5fb0..cc38da55 100644
--- a/src/modules/system/service/sys_user.go
+++ b/src/modules/system/service/sys_user.go
@@ -39,7 +39,4 @@ type ISysUser interface {
// CheckUniqueEmail 校验email是否唯一
CheckUniqueEmail(email, userId string) bool
-
- // ImportUser 导入用户数据
- ImportUser(rows []map[string]string, isUpdateSupport bool, operName string) string
}
diff --git a/src/modules/system/service/sys_user.impl.go b/src/modules/system/service/sys_user.impl.go
index b69fd03d..aceeedaf 100644
--- a/src/modules/system/service/sys_user.impl.go
+++ b/src/modules/system/service/sys_user.impl.go
@@ -2,11 +2,8 @@ package service
import (
"fmt"
- "strings"
"ems.agt/src/framework/constants/admin"
- "ems.agt/src/framework/constants/common"
- "ems.agt/src/framework/utils/regular"
"ems.agt/src/modules/system/model"
"ems.agt/src/modules/system/repository"
)
@@ -16,8 +13,6 @@ var NewSysUserImpl = &SysUserImpl{
sysUserRepository: repository.NewSysUserImpl,
sysUserRoleRepository: repository.NewSysUserRoleImpl,
sysUserPostRepository: repository.NewSysUserPostImpl,
- sysDictDataService: NewSysDictDataImpl,
- sysConfigService: NewSysConfigImpl,
}
// SysUserImpl 用户 服务层处理
@@ -28,10 +23,6 @@ type SysUserImpl struct {
sysUserRoleRepository repository.ISysUserRole
// 用户与岗位服务
sysUserPostRepository repository.ISysUserPost
- // 字典数据服务
- sysDictDataService ISysDictData
- // 参数配置服务
- sysConfigService ISysConfig
}
// SelectUserPage 根据条件分页查询用户列表
@@ -185,149 +176,3 @@ func (r *SysUserImpl) CheckUniqueEmail(email, userId string) bool {
}
return uniqueId == ""
}
-
-// ImportUser 导入用户数据
-func (r *SysUserImpl) ImportUser(rows []map[string]string, isUpdateSupport bool, operName string) string {
- // 读取默认初始密码
- initPassword := r.sysConfigService.SelectConfigValueByKey("sys.user.initPassword")
- // 读取用户性别字典数据
- dictSysUserSex := r.sysDictDataService.SelectDictDataByType("sys_user_sex")
-
- // 导入记录
- successNum := 0
- failureNum := 0
- successMsgArr := []string{}
- failureMsgArr := []string{}
- mustItemArr := []string{"B", "C"}
- for _, row := range rows {
- // 检查必填列
- ownItem := true
- for _, item := range mustItemArr {
- if v, ok := row[item]; !ok || v == "" {
- ownItem = false
- break
- }
- }
- if !ownItem {
- mustItemArrStr := strings.Join(mustItemArr, "、")
- failureNum++
- // 表格中必填列表项,
- failureMsgArr = append(failureMsgArr, fmt.Sprintf("Required list items in the form, %s}", mustItemArrStr))
- continue
- }
-
- // 用户性别转值
- sysUserSex := "0"
- for _, v := range dictSysUserSex {
- if row["F"] == v.DictLabel {
- sysUserSex = v.DictValue
- break
- }
- }
- sysUserStatus := common.STATUS_NO
- if row["G"] == "Normal" {
- sysUserStatus = common.STATUS_YES
- }
-
- // 构建用户实体信息
- newSysUser := model.SysUser{
- UserType: "sys",
- Password: initPassword,
- DeptID: row["H"],
- UserName: row["B"],
- NickName: row["C"],
- PhoneNumber: row["E"],
- Email: row["D"],
- Status: sysUserStatus,
- Sex: sysUserSex,
- }
-
- // 检查手机号码格式并判断是否唯一
- if newSysUser.PhoneNumber != "" {
- if regular.ValidMobile(newSysUser.PhoneNumber) {
- uniquePhone := r.CheckUniquePhone(newSysUser.PhoneNumber, "")
- if !uniquePhone {
- // 用户编号:%s 手机号码 %s 已存在
- msg := fmt.Sprintf("UserID: %s PhoneNumber: %s pre-existing", row["A"], row["E"])
- failureNum++
- failureMsgArr = append(failureMsgArr, msg)
- continue
- }
- } else {
- // 用户编号:%s 手机号码 %s 格式错误
- msg := fmt.Sprintf("UserID: %s PhoneNumber: %s formatting error", row["A"], row["E"])
- failureNum++
- failureMsgArr = append(failureMsgArr, msg)
- continue
- }
- }
-
- // 检查邮箱格式并判断是否唯一
- if newSysUser.Email != "" {
- if regular.ValidEmail(newSysUser.Email) {
- uniqueEmail := r.CheckUniqueEmail(newSysUser.Email, "")
- if !uniqueEmail {
- // 用户编号:%s 用户邮箱 %s 已存在
- msg := fmt.Sprintf("UserID: %s Email: %s pre-existing", row["A"], row["D"])
- failureNum++
- failureMsgArr = append(failureMsgArr, msg)
- continue
- }
- } else {
- // 用户编号:%s 用户邮箱 %s 格式错误
- msg := fmt.Sprintf("UserID: %s Email: %s formatting error", row["A"], row["D"])
- failureNum++
- failureMsgArr = append(failureMsgArr, msg)
- continue
- }
- }
-
- // 验证是否存在这个用户
- userInfo := r.sysUserRepository.SelectUserByUserName(newSysUser.UserName)
- if userInfo.UserName != newSysUser.UserName {
- newSysUser.CreateBy = operName
- insertId := r.InsertUser(newSysUser)
- if insertId != "" {
- // 用户编号:%s 登录名称 %s 导入成功
- msg := fmt.Sprintf("UserID: %s UserName: %s import successfully", row["A"], row["B"])
- successNum++
- successMsgArr = append(successMsgArr, msg)
- } else {
- // 用户编号:%s 登录名称 %s 导入失败
- msg := fmt.Sprintf("UserID: %s UserName: %s import failure", row["A"], row["B"])
- failureNum++
- failureMsgArr = append(failureMsgArr, msg)
- }
- continue
- }
-
- // 如果用户已存在 同时 是否更新支持
- if userInfo.UserName == newSysUser.UserName && isUpdateSupport {
- newSysUser.UserID = userInfo.UserID
- newSysUser.UpdateBy = operName
- rows := r.UpdateUser(newSysUser)
- if rows > 0 {
- // 用户编号:%s 登录名称 %s 更新成功
- msg := fmt.Sprintf("UserID: %s UserName: %s Update Successful", row["A"], row["B"])
- successNum++
- successMsgArr = append(successMsgArr, msg)
- } else {
- // 用户编号:%s 登录名称 %s 更新失败
- msg := fmt.Sprintf("UserID: %s UserName: %s Update Failed", row["A"], row["B"])
- failureNum++
- failureMsgArr = append(failureMsgArr, msg)
- }
- continue
- }
- }
-
- if failureNum > 0 {
- // 很抱歉,导入失败!共 %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, "
")
- }
-
- // 恭喜您,数据已全部导入成功!共 %d 条,数据如下:
- successMsgArr = append([]string{fmt.Sprintf("Congratulations, the data has been imported successfully! Total %d entries, data below:", successNum)}, successMsgArr...)
- return strings.Join(successMsgArr, "
")
-}
diff --git a/src/modules/system/system.go b/src/modules/system/system.go
index 71456c21..5838cdb9 100644
--- a/src/modules/system/system.go
+++ b/src/modules/system/system.go
@@ -31,34 +31,34 @@ func Setup(router *gin.Engine) {
)
sysConfigGroup.POST("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:config:add"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Parameter Configuration", collectlogs.BUSINESS_TYPE_INSERT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysConfig", collectlogs.BUSINESS_TYPE_INSERT)),
controller.NewSysConfig.Add,
)
sysConfigGroup.PUT("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:config:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Parameter Configuration", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysConfig", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysConfig.Edit,
)
sysConfigGroup.DELETE("/:configIds",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:config:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Parameter Configuration", collectlogs.BUSINESS_TYPE_DELETE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysConfig", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysConfig.Remove,
)
sysConfigGroup.PUT("/refreshCache",
repeat.RepeatSubmit(5),
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:config:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Parameter Configuration", collectlogs.BUSINESS_TYPE_CLEAN)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysConfig", collectlogs.BUSINESS_TYPE_CLEAN)),
controller.NewSysConfig.RefreshCache,
)
sysConfigGroup.GET("/configKey/:configKey", controller.NewSysConfig.ConfigKey)
sysConfigGroup.POST("/export",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:config:export"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Parameter Configuration", collectlogs.BUSINESS_TYPE_EXPORT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysConfig", collectlogs.BUSINESS_TYPE_EXPORT)),
controller.NewSysConfig.Export,
)
sysConfigGroup.PUT("/changeValue",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:config:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Parameter Configuration", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysConfig", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysConfig.ConfigValue,
)
}
@@ -76,17 +76,17 @@ func Setup(router *gin.Engine) {
)
sysDeptGroup.POST("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dept:add"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Sectoral", collectlogs.BUSINESS_TYPE_INSERT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDept", collectlogs.BUSINESS_TYPE_INSERT)),
controller.NewSysDept.Add,
)
sysDeptGroup.PUT("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dept:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Sectoral", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDept", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysDept.Edit,
)
sysDeptGroup.DELETE("/:deptId",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dept:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Sectoral", collectlogs.BUSINESS_TYPE_DELETE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDept", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysDept.Remove,
)
sysDeptGroup.GET("/list/exclude/:deptId",
@@ -116,17 +116,17 @@ func Setup(router *gin.Engine) {
)
sysDictDataGroup.POST("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dict:add"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Dictionary Data", collectlogs.BUSINESS_TYPE_INSERT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDictData", collectlogs.BUSINESS_TYPE_INSERT)),
controller.NewSysDictData.Add,
)
sysDictDataGroup.PUT("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dict:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Dictionary Data", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDictData", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysDictData.Edit,
)
sysDictDataGroup.DELETE("/:dictCodes",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dict:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Dictionary Data", collectlogs.BUSINESS_TYPE_DELETE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDictData", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysDictData.Remove,
)
sysDictDataGroup.GET("/type/:dictType",
@@ -135,7 +135,7 @@ func Setup(router *gin.Engine) {
)
sysDictDataGroup.POST("/export",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dict:export"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Dictionary Type", collectlogs.BUSINESS_TYPE_EXPORT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDictData", collectlogs.BUSINESS_TYPE_EXPORT)),
controller.NewSysDictData.Export,
)
}
@@ -153,22 +153,22 @@ func Setup(router *gin.Engine) {
)
sysDictTypeGroup.POST("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dict:add"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Dictionary Type", collectlogs.BUSINESS_TYPE_INSERT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDictType", collectlogs.BUSINESS_TYPE_INSERT)),
controller.NewSysDictType.Add,
)
sysDictTypeGroup.PUT("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dict:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Dictionary Type", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDictType", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysDictType.Edit,
)
sysDictTypeGroup.DELETE("/:dictIds",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dict:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Dictionary Type", collectlogs.BUSINESS_TYPE_DELETE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDictType", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysDictType.Remove,
)
sysDictTypeGroup.PUT("/refreshCache",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dict:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Dictionary Type", collectlogs.BUSINESS_TYPE_CLEAN)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDictType", collectlogs.BUSINESS_TYPE_CLEAN)),
controller.NewSysDictType.RefreshCache,
)
sysDictTypeGroup.GET("/getDictOptionselect",
@@ -177,7 +177,7 @@ func Setup(router *gin.Engine) {
)
sysDictTypeGroup.POST("/export",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:dict:export"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Dictionary Type", collectlogs.BUSINESS_TYPE_EXPORT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysDictType", collectlogs.BUSINESS_TYPE_EXPORT)),
controller.NewSysDictType.Export,
)
}
@@ -195,17 +195,17 @@ func Setup(router *gin.Engine) {
)
sysMenuGroup.POST("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:menu:add"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Menu", collectlogs.BUSINESS_TYPE_INSERT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysMenu", collectlogs.BUSINESS_TYPE_INSERT)),
controller.NewSysMenu.Add,
)
sysMenuGroup.PUT("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:menu:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Menu", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysMenu", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysMenu.Edit,
)
sysMenuGroup.DELETE("/:menuId",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:menu:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Menu", collectlogs.BUSINESS_TYPE_DELETE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysMenu", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysMenu.Remove,
)
sysMenuGroup.GET("/treeSelect",
@@ -231,17 +231,17 @@ func Setup(router *gin.Engine) {
)
sysPostGroup.POST("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:post:add"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Post", collectlogs.BUSINESS_TYPE_INSERT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysPost", collectlogs.BUSINESS_TYPE_INSERT)),
controller.NewSysPost.Add,
)
sysPostGroup.PUT("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:post:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Post", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysPost", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysPost.Edit,
)
sysPostGroup.DELETE("/:postIds",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:post:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Post", collectlogs.BUSINESS_TYPE_DELETE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysPost", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysPost.Remove,
)
sysPostGroup.POST("/export",
@@ -263,12 +263,12 @@ func Setup(router *gin.Engine) {
)
sysProfileGroup.PUT("/updatePwd",
middleware.PreAuthorize(nil),
- collectlogs.OperateLog(collectlogs.OptionNew("Personal", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysProfile", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysProfile.UpdatePwd,
)
sysProfileGroup.POST("/avatar",
middleware.PreAuthorize(nil),
- collectlogs.OperateLog(collectlogs.OptionNew("Personal Avatar", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysProfileAvatar", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysProfile.Avatar,
)
}
@@ -286,29 +286,29 @@ func Setup(router *gin.Engine) {
)
sysRoleGroup.POST("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:role:add"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Role", collectlogs.BUSINESS_TYPE_INSERT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysRole", collectlogs.BUSINESS_TYPE_INSERT)),
controller.NewSysRole.Add,
)
sysRoleGroup.PUT("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:role:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Role", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysRole", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysRole.Edit,
)
sysRoleGroup.DELETE("/:roleIds",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:role:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Role", collectlogs.BUSINESS_TYPE_DELETE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysRole", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysRole.Remove,
)
sysRoleGroup.PUT("/changeStatus",
repeat.RepeatSubmit(5),
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:role:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Role", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysRole", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysRole.Status,
)
sysRoleGroup.PUT("/dataScope",
repeat.RepeatSubmit(5),
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:user:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Role", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysRole", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysRole.DataScope,
)
sysRoleGroup.GET("/authUser/allocatedList",
@@ -317,12 +317,12 @@ func Setup(router *gin.Engine) {
)
sysRoleGroup.PUT("/authUser/checked",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:user:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Role", collectlogs.BUSINESS_TYPE_GRANT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysRole", collectlogs.BUSINESS_TYPE_GRANT)),
controller.NewSysRole.AuthUserChecked,
)
sysRoleGroup.POST("/export",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:user:export"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Role", collectlogs.BUSINESS_TYPE_EXPORT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysRole", collectlogs.BUSINESS_TYPE_EXPORT)),
controller.NewSysRole.Export,
)
}
@@ -340,33 +340,33 @@ func Setup(router *gin.Engine) {
)
sysUserGroup.POST("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:user:add"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("User", collectlogs.BUSINESS_TYPE_INSERT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysUser", collectlogs.BUSINESS_TYPE_INSERT)),
controller.NewSysUser.Add,
)
sysUserGroup.PUT("",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:user:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("User", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysUser", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysUser.Edit,
)
sysUserGroup.DELETE("/:userIds",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:user:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("User", collectlogs.BUSINESS_TYPE_DELETE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysUser", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysUser.Remove,
)
sysUserGroup.PUT("/resetPwd",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:user:resetPwd"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("User", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysUser", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysUser.ResetPwd,
)
sysUserGroup.PUT("/changeStatus",
repeat.RepeatSubmit(5),
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:user:edit"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("User", collectlogs.BUSINESS_TYPE_UPDATE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysUser", collectlogs.BUSINESS_TYPE_UPDATE)),
controller.NewSysUser.Status,
)
sysUserGroup.POST("/export",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:user:export"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("User", collectlogs.BUSINESS_TYPE_EXPORT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysUser", collectlogs.BUSINESS_TYPE_EXPORT)),
controller.NewSysUser.Export,
)
sysUserGroup.GET("/importTemplate",
@@ -375,60 +375,60 @@ func Setup(router *gin.Engine) {
)
sysUserGroup.POST("/importData",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:user:import"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("User", collectlogs.BUSINESS_TYPE_INSERT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysUser", collectlogs.BUSINESS_TYPE_INSERT)),
controller.NewSysUser.ImportData,
)
}
// 操作日志记录信息
- sysOperLogGroup := router.Group("/system/log/operate")
+ sysLogOperGroup := router.Group("/system/log/operate")
{
- sysOperLogGroup.GET("/list",
+ sysLogOperGroup.GET("/list",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:log:operate:list"}}),
controller.NewSysLogOperate.List,
)
- sysOperLogGroup.DELETE("/:operIds",
+ sysLogOperGroup.DELETE("/:operIds",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:log:operate:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Operation", collectlogs.BUSINESS_TYPE_DELETE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysLogOper", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysLogOperate.Remove,
)
- sysOperLogGroup.DELETE("/clean",
+ sysLogOperGroup.DELETE("/clean",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:log:operate:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Operation", collectlogs.BUSINESS_TYPE_CLEAN)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysLogOper", collectlogs.BUSINESS_TYPE_CLEAN)),
controller.NewSysLogOperate.Clean,
)
- sysOperLogGroup.POST("/export",
+ sysLogOperGroup.POST("/export",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:log:operate:export"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("Operation", collectlogs.BUSINESS_TYPE_EXPORT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysLogOper", collectlogs.BUSINESS_TYPE_EXPORT)),
controller.NewSysLogOperate.Export,
)
}
// 系统登录日志信息
- sysLogininforGroup := router.Group("/system/log/login")
+ sysLogLoginGroup := router.Group("/system/log/login")
{
- sysLogininforGroup.GET("/list",
+ sysLogLoginGroup.GET("/list",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:log:login:list"}}),
controller.NewSysLogLogin.List,
)
- sysLogininforGroup.DELETE("/:loginIds",
+ sysLogLoginGroup.DELETE("/:loginIds",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:log:login:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("System Login", collectlogs.BUSINESS_TYPE_DELETE)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysLogLogin", collectlogs.BUSINESS_TYPE_DELETE)),
controller.NewSysLogLogin.Remove,
)
- sysLogininforGroup.DELETE("/clean",
+ sysLogLoginGroup.DELETE("/clean",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:log:login:remove"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("System Login", collectlogs.BUSINESS_TYPE_CLEAN)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysLogLogin", collectlogs.BUSINESS_TYPE_CLEAN)),
controller.NewSysLogLogin.Clean,
)
- sysLogininforGroup.PUT("/unlock/:userName",
+ sysLogLoginGroup.PUT("/unlock/:userName",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:log:login:unlock"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("System Login", collectlogs.BUSINESS_TYPE_CLEAN)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysLogLogin", collectlogs.BUSINESS_TYPE_CLEAN)),
controller.NewSysLogLogin.Unlock,
)
- sysLogininforGroup.POST("/export",
+ sysLogLoginGroup.POST("/export",
middleware.PreAuthorize(map[string][]string{"hasPerms": {"system:log:login:export"}}),
- collectlogs.OperateLog(collectlogs.OptionNew("System Login", collectlogs.BUSINESS_TYPE_EXPORT)),
+ collectlogs.OperateLog(collectlogs.OptionNew("log.operate.title.sysLogLogin", collectlogs.BUSINESS_TYPE_EXPORT)),
controller.NewSysLogLogin.Export,
)
}