feat: 系统模块多语言

This commit is contained in:
TsMask
2023-11-20 18:55:33 +08:00
parent d52945c946
commit 5604bd9b9d
23 changed files with 957 additions and 527 deletions

View File

@@ -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,