feat: 调度任务多语言

This commit is contained in:
TsMask
2023-11-20 18:54:15 +08:00
parent 506866e082
commit 084a7b3c93
3 changed files with 120 additions and 62 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"
@@ -40,17 +41,42 @@ type SysJobLogController struct {
func (s *SysJobLogController) List(c *gin.Context) {
// 查询参数转换map
querys := ctx.QueryMap(c)
list := s.sysJobLogService.SelectJobLogPage(querys)
c.JSON(200, result.Ok(list))
data := s.sysJobLogService.SelectJobLogPage(querys)
language := ctx.AcceptLanguage(c)
// 反查多语言key
querys["jobName"] = i18n.ValueKey(language, querys["jobName"].(string))
dataI18n := s.sysJobLogService.SelectJobLogPage(querys)
totalI18n := parse.Number(dataI18n["total"])
if totalI18n != 0 {
rows := data["rows"].([]model.SysJobLog)
total := parse.Number(data["total"])
rowsI18n := dataI18n["rows"].([]model.SysJobLog)
data["rows"] = append(rows, rowsI18n...)
data["total"] = total + totalI18n
}
rows := data["rows"].([]model.SysJobLog)
// 闭包函数处理多语言
converI18n := func(language string, arr *[]model.SysJobLog) {
for i := range *arr {
(*arr)[i].JobName = i18n.TKey(language, (*arr)[i].JobName)
}
}
converI18n(language, &rows)
c.JSON(200, result.Ok(data))
}
// 调度任务日志信息
//
// GET /:jobLogId
func (s *SysJobLogController) Info(c *gin.Context) {
language := ctx.AcceptLanguage(c)
jobLogId := c.Param("jobLogId")
if jobLogId == "" {
c.JSON(400, result.CodeMsg(400, "parameter error"))
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
data := s.sysJobLogService.SelectJobLogById(jobLogId)
@@ -65,9 +91,10 @@ func (s *SysJobLogController) Info(c *gin.Context) {
//
// DELETE /:jobLogIds
func (s *SysJobLogController) Remove(c *gin.Context) {
language := ctx.AcceptLanguage(c)
jobLogIds := c.Param("jobLogIds")
if jobLogIds == "" {
c.JSON(400, result.CodeMsg(400, "parameter error"))
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
return
}
@@ -81,7 +108,7 @@ func (s *SysJobLogController) Remove(c *gin.Context) {
rows := s.sysJobLogService.DeleteJobLogByIds(uniqueIDs)
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
}
@@ -113,18 +140,27 @@ func (s *SysJobLogController) Export(c *gin.Context) {
}
rows := data["rows"].([]model.SysJobLog)
// 闭包函数处理多语言
language := ctx.AcceptLanguage(c)
converI18n := func(language string, arr *[]model.SysJobLog) {
for i := range *arr {
(*arr)[i].JobName = i18n.TKey(language, (*arr)[i].JobName)
}
}
converI18n(language, &rows)
// 导出文件名称
fileName := fmt.Sprintf("jobLog_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
// 第一行表头标题
headerCells := map[string]string{
"A1": "JobLogID",
"B1": "JobName",
"C1": "JobGroupName",
"D1": "InvokeTarget",
"E1": "TargetParams",
"F1": "JobMsg",
"G1": "Status",
"H1": "Time",
"A1": i18n.TKey(language, "job.export.jobLogID"),
"B1": i18n.TKey(language, "job.export.jobName"),
"C1": i18n.TKey(language, "job.export.jobGroupName"),
"D1": i18n.TKey(language, "job.export.invokeTarget"),
"E1": i18n.TKey(language, "job.export.targetParams"),
"F1": i18n.TKey(language, "job.export.jobID"),
"G1": i18n.TKey(language, "job.export.jobLogStatus"),
"H1": i18n.TKey(language, "job.export.jobLogTime"),
}
// 读取任务组名字典数据
dictSysJobGroup := s.sysDictDataService.SelectDictDataByType("sys_job_group")
@@ -136,14 +172,14 @@ func (s *SysJobLogController) Export(c *gin.Context) {
sysJobGroup := ""
for _, v := range dictSysJobGroup {
if row.JobGroup == v.DictValue {
sysJobGroup = v.DictLabel
sysJobGroup = i18n.TKey(language, v.DictLabel)
break
}
}
// 状态
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.JobLogID,