feat: 系统模块多语言
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user