feat: 调度任务多语言
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"ems.agt/src/framework/i18n"
|
||||||
"ems.agt/src/framework/utils/ctx"
|
"ems.agt/src/framework/utils/ctx"
|
||||||
"ems.agt/src/framework/utils/file"
|
"ems.agt/src/framework/utils/file"
|
||||||
"ems.agt/src/framework/utils/parse"
|
"ems.agt/src/framework/utils/parse"
|
||||||
@@ -41,6 +42,18 @@ type SysJobController struct {
|
|||||||
func (s *SysJobController) List(c *gin.Context) {
|
func (s *SysJobController) List(c *gin.Context) {
|
||||||
querys := ctx.QueryMap(c)
|
querys := ctx.QueryMap(c)
|
||||||
data := s.sysJobService.SelectJobPage(querys)
|
data := s.sysJobService.SelectJobPage(querys)
|
||||||
|
|
||||||
|
rows := data["rows"].([]model.SysJob)
|
||||||
|
// 闭包函数处理多语言
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
|
converI18n := func(language string, arr *[]model.SysJob) {
|
||||||
|
for i := range *arr {
|
||||||
|
(*arr)[i].JobName = i18n.TKey(language, (*arr)[i].JobName)
|
||||||
|
(*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
converI18n(language, &rows)
|
||||||
|
|
||||||
c.JSON(200, result.Ok(data))
|
c.JSON(200, result.Ok(data))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,14 +61,18 @@ func (s *SysJobController) List(c *gin.Context) {
|
|||||||
//
|
//
|
||||||
// GET /:jobId
|
// GET /:jobId
|
||||||
func (s *SysJobController) Info(c *gin.Context) {
|
func (s *SysJobController) Info(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
jobId := c.Param("jobId")
|
jobId := c.Param("jobId")
|
||||||
if jobId == "" {
|
if jobId == "" {
|
||||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data := s.sysJobService.SelectJobById(jobId)
|
data := s.sysJobService.SelectJobById(jobId)
|
||||||
if data.JobID == jobId {
|
if data.JobID == jobId {
|
||||||
|
// 处理多语言
|
||||||
|
data.JobName = i18n.TKey(language, data.JobName)
|
||||||
|
data.Remark = i18n.TKey(language, data.Remark)
|
||||||
c.JSON(200, result.OkData(data))
|
c.JSON(200, result.OkData(data))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -66,17 +83,18 @@ func (s *SysJobController) Info(c *gin.Context) {
|
|||||||
//
|
//
|
||||||
// POST /
|
// POST /
|
||||||
func (s *SysJobController) Add(c *gin.Context) {
|
func (s *SysJobController) Add(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
var body model.SysJob
|
var body model.SysJob
|
||||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||||
if err != nil || body.JobID != "" {
|
if err != nil || body.JobID != "" {
|
||||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查cron表达式格式
|
// 检查cron表达式格式
|
||||||
if parse.CronExpression(body.CronExpression) == 0 {
|
if parse.CronExpression(body.CronExpression) == 0 {
|
||||||
// 调度任务新增【%s】失败,Cron表达式不正确
|
// 调度任务新增【%s】失败,Cron表达式不正确
|
||||||
msg := fmt.Sprintf("Scheduling task add [%s] fails with incorrect Cron expression", body.JobName)
|
msg := i18n.TTemplate(language, "job.errCronExpression", map[string]any{"name": body.JobName})
|
||||||
c.JSON(200, result.ErrMsg(msg))
|
c.JSON(200, result.ErrMsg(msg))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -84,7 +102,7 @@ func (s *SysJobController) Add(c *gin.Context) {
|
|||||||
// 检查任务调用传入参数是否json格式
|
// 检查任务调用传入参数是否json格式
|
||||||
if body.TargetParams != "" {
|
if body.TargetParams != "" {
|
||||||
// 调度任务新增【%s】失败,任务传入参数json字符串不正确
|
// 调度任务新增【%s】失败,任务传入参数json字符串不正确
|
||||||
msg := fmt.Sprintf("Scheduling task add [%s] failed, task incoming parameter json string is incorrect", body.JobName)
|
msg := i18n.TTemplate(language, "job.errTargetParams", map[string]any{"name": body.JobName})
|
||||||
if len(body.TargetParams) < 7 {
|
if len(body.TargetParams) < 7 {
|
||||||
c.JSON(200, result.ErrMsg(msg))
|
c.JSON(200, result.ErrMsg(msg))
|
||||||
return
|
return
|
||||||
@@ -99,7 +117,7 @@ func (s *SysJobController) Add(c *gin.Context) {
|
|||||||
uniqueJob := s.sysJobService.CheckUniqueJobName(body.JobName, body.JobGroup, "")
|
uniqueJob := s.sysJobService.CheckUniqueJobName(body.JobName, body.JobGroup, "")
|
||||||
if !uniqueJob {
|
if !uniqueJob {
|
||||||
// 调度任务新增【%s】失败,同任务组内有相同任务名称
|
// 调度任务新增【%s】失败,同任务组内有相同任务名称
|
||||||
msg := fmt.Sprintf("Scheduling tasks with new [%s] failures, with the same task name in the same task group", body.JobName)
|
msg := i18n.TTemplate(language, "job.errJobExists", map[string]any{"name": body.JobName})
|
||||||
c.JSON(200, result.ErrMsg(msg))
|
c.JSON(200, result.ErrMsg(msg))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -117,17 +135,18 @@ func (s *SysJobController) Add(c *gin.Context) {
|
|||||||
//
|
//
|
||||||
// PUT /
|
// PUT /
|
||||||
func (s *SysJobController) Edit(c *gin.Context) {
|
func (s *SysJobController) Edit(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
var body model.SysJob
|
var body model.SysJob
|
||||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||||
if err != nil || body.JobID == "" {
|
if err != nil || body.JobID == "" {
|
||||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查cron表达式格式
|
// 检查cron表达式格式
|
||||||
if parse.CronExpression(body.CronExpression) == 0 {
|
if parse.CronExpression(body.CronExpression) == 0 {
|
||||||
// 调度任务修改【%s】失败,Cron表达式不正确
|
// 调度任务修改【%s】失败,Cron表达式不正确
|
||||||
msg := fmt.Sprintf("Scheduling task modification [%s] fails with incorrect Cron expression", body.JobName)
|
msg := i18n.TTemplate(language, "job.errCronExpression", map[string]any{"name": body.JobName})
|
||||||
c.JSON(200, result.ErrMsg(msg))
|
c.JSON(200, result.ErrMsg(msg))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -135,7 +154,7 @@ func (s *SysJobController) Edit(c *gin.Context) {
|
|||||||
// 检查任务调用传入参数是否json格式
|
// 检查任务调用传入参数是否json格式
|
||||||
if body.TargetParams != "" {
|
if body.TargetParams != "" {
|
||||||
// 调度任务修改【%s】失败,任务传入参数json字符串不正确
|
// 调度任务修改【%s】失败,任务传入参数json字符串不正确
|
||||||
msg := fmt.Sprintf("Scheduling task modification [%s] failed, task incoming parameter json string is not correct", body.JobName)
|
msg := i18n.TTemplate(language, "job.errTargetParams", map[string]any{"name": body.JobName})
|
||||||
if len(body.TargetParams) < 7 {
|
if len(body.TargetParams) < 7 {
|
||||||
c.JSON(200, result.ErrMsg(msg))
|
c.JSON(200, result.ErrMsg(msg))
|
||||||
return
|
return
|
||||||
@@ -150,7 +169,7 @@ func (s *SysJobController) Edit(c *gin.Context) {
|
|||||||
uniqueJob := s.sysJobService.CheckUniqueJobName(body.JobName, body.JobGroup, body.JobID)
|
uniqueJob := s.sysJobService.CheckUniqueJobName(body.JobName, body.JobGroup, body.JobID)
|
||||||
if !uniqueJob {
|
if !uniqueJob {
|
||||||
// 调度任务修改【%s】失败,同任务组内有相同任务名称
|
// 调度任务修改【%s】失败,同任务组内有相同任务名称
|
||||||
msg := fmt.Sprintf("Scheduling task modification [%s] failed with the same task name in the same task group", body.JobName)
|
msg := i18n.TTemplate(language, "job.errJobExists", map[string]any{"name": body.JobName})
|
||||||
c.JSON(200, result.ErrMsg(msg))
|
c.JSON(200, result.ErrMsg(msg))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -168,9 +187,10 @@ func (s *SysJobController) Edit(c *gin.Context) {
|
|||||||
//
|
//
|
||||||
// DELETE /:jobIds
|
// DELETE /:jobIds
|
||||||
func (s *SysJobController) Remove(c *gin.Context) {
|
func (s *SysJobController) Remove(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
jobIds := c.Param("jobIds")
|
jobIds := c.Param("jobIds")
|
||||||
if jobIds == "" {
|
if jobIds == "" {
|
||||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 处理字符转id数组后去重
|
// 处理字符转id数组后去重
|
||||||
@@ -185,7 +205,7 @@ func (s *SysJobController) Remove(c *gin.Context) {
|
|||||||
c.JSON(200, result.ErrMsg(err.Error()))
|
c.JSON(200, result.ErrMsg(err.Error()))
|
||||||
return
|
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))
|
c.JSON(200, result.OkMsg(msg))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,6 +213,7 @@ func (s *SysJobController) Remove(c *gin.Context) {
|
|||||||
//
|
//
|
||||||
// PUT /changeStatus
|
// PUT /changeStatus
|
||||||
func (s *SysJobController) Status(c *gin.Context) {
|
func (s *SysJobController) Status(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
var body struct {
|
var body struct {
|
||||||
// 任务ID
|
// 任务ID
|
||||||
JobId string `json:"jobId" binding:"required"`
|
JobId string `json:"jobId" binding:"required"`
|
||||||
@@ -201,7 +222,7 @@ func (s *SysJobController) Status(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,14 +230,14 @@ func (s *SysJobController) Status(c *gin.Context) {
|
|||||||
job := s.sysJobService.SelectJobById(body.JobId)
|
job := s.sysJobService.SelectJobById(body.JobId)
|
||||||
if job.JobID != body.JobId {
|
if job.JobID != body.JobId {
|
||||||
// 没有可访问调度任务数据!
|
// 没有可访问调度任务数据!
|
||||||
c.JSON(200, result.ErrMsg("No accessible scheduling task data!"))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "job.noData")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 与旧值相等不变更
|
// 与旧值相等不变更
|
||||||
if job.Status == body.Status {
|
if job.Status == body.Status {
|
||||||
// 变更状态与旧值相等!
|
// 变更状态与旧值相等!
|
||||||
c.JSON(200, result.ErrMsg("Change status equals old value!"))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "job.statusEq")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,9 +256,10 @@ func (s *SysJobController) Status(c *gin.Context) {
|
|||||||
//
|
//
|
||||||
// PUT /run/:jobId
|
// PUT /run/:jobId
|
||||||
func (s *SysJobController) Run(c *gin.Context) {
|
func (s *SysJobController) Run(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
jobId := c.Param("jobId")
|
jobId := c.Param("jobId")
|
||||||
if jobId == "" {
|
if jobId == "" {
|
||||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +267,7 @@ func (s *SysJobController) Run(c *gin.Context) {
|
|||||||
job := s.sysJobService.SelectJobById(jobId)
|
job := s.sysJobService.SelectJobById(jobId)
|
||||||
if job.JobID != jobId {
|
if job.JobID != jobId {
|
||||||
// 没有可访问调度任务数据!
|
// 没有可访问调度任务数据!
|
||||||
c.JSON(200, result.ErrMsg("No accessible scheduling task data!"))
|
c.JSON(200, result.ErrMsg(i18n.TKey(language, "job.noData")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -269,30 +291,38 @@ func (s *SysJobController) ResetQueueJob(c *gin.Context) {
|
|||||||
//
|
//
|
||||||
// POST /export
|
// POST /export
|
||||||
func (s *SysJobController) Export(c *gin.Context) {
|
func (s *SysJobController) Export(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
// 查询结果,根据查询条件结果,单页最大值限制
|
// 查询结果,根据查询条件结果,单页最大值限制
|
||||||
querys := ctx.BodyJSONMap(c)
|
querys := ctx.BodyJSONMap(c)
|
||||||
data := s.sysJobService.SelectJobPage(querys)
|
data := s.sysJobService.SelectJobPage(querys)
|
||||||
if data["total"].(int64) == 0 {
|
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
|
return
|
||||||
}
|
}
|
||||||
rows := data["rows"].([]model.SysJob)
|
rows := data["rows"].([]model.SysJob)
|
||||||
|
|
||||||
|
// 闭包函数处理多语言
|
||||||
|
converI18n := func(language string, arr *[]model.SysJob) {
|
||||||
|
for i := range *arr {
|
||||||
|
(*arr)[i].JobName = i18n.TKey(language, (*arr)[i].JobName)
|
||||||
|
(*arr)[i].Remark = i18n.TKey(language, (*arr)[i].Remark)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
converI18n(language, &rows)
|
||||||
|
|
||||||
// 导出文件名称
|
// 导出文件名称
|
||||||
fileName := fmt.Sprintf("job_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
|
fileName := fmt.Sprintf("job_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
|
||||||
// 第一行表头标题
|
// 第一行表头标题
|
||||||
headerCells := map[string]string{
|
headerCells := map[string]string{
|
||||||
"A1": "JobID",
|
"A1": i18n.TKey(language, "job.export.jobID"),
|
||||||
"B1": "JobName",
|
"B1": i18n.TKey(language, "job.export.jobName"),
|
||||||
"C1": "JobGroupName",
|
"C1": i18n.TKey(language, "job.export.jobGroupName"),
|
||||||
"D1": "InvokeTarget",
|
"D1": i18n.TKey(language, "job.export.invokeTarget"),
|
||||||
"E1": "TargetParams",
|
"E1": i18n.TKey(language, "job.export.targetParams"),
|
||||||
"F1": "CronExpression",
|
"F1": i18n.TKey(language, "job.export.cronExpression"),
|
||||||
"G1": "MisfirePolicy",
|
"G1": i18n.TKey(language, "job.export.status"),
|
||||||
"H1": "Concurrent",
|
"H1": i18n.TKey(language, "job.export.remark"),
|
||||||
"I1": "Status",
|
|
||||||
"J1": "Remark",
|
|
||||||
}
|
}
|
||||||
// 读取任务组名字典数据
|
// 读取任务组名字典数据
|
||||||
dictSysJobGroup := s.sysDictDataService.SelectDictDataByType("sys_job_group")
|
dictSysJobGroup := s.sysDictDataService.SelectDictDataByType("sys_job_group")
|
||||||
@@ -304,24 +334,15 @@ func (s *SysJobController) Export(c *gin.Context) {
|
|||||||
sysJobGroup := ""
|
sysJobGroup := ""
|
||||||
for _, v := range dictSysJobGroup {
|
for _, v := range dictSysJobGroup {
|
||||||
if row.JobGroup == v.DictValue {
|
if row.JobGroup == v.DictValue {
|
||||||
sysJobGroup = v.DictLabel
|
sysJobGroup = i18n.TKey(language, v.DictLabel)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
misfirePolicy := "Abandon execution"
|
|
||||||
if row.MisfirePolicy == "1" {
|
|
||||||
misfirePolicy = "Execute immediately"
|
|
||||||
} else if row.MisfirePolicy == "2" {
|
|
||||||
misfirePolicy = "Execute once"
|
|
||||||
}
|
|
||||||
concurrent := "prohibit"
|
|
||||||
if row.Concurrent == "1" {
|
|
||||||
concurrent = "allow"
|
|
||||||
}
|
|
||||||
// 状态
|
// 状态
|
||||||
statusValue := "fail"
|
statusValue := i18n.TKey(language, "dictData.fail")
|
||||||
if row.Status == "1" {
|
if row.Status == "1" {
|
||||||
statusValue = "successes"
|
statusValue = i18n.TKey(language, "dictData.success")
|
||||||
}
|
}
|
||||||
dataCells = append(dataCells, map[string]any{
|
dataCells = append(dataCells, map[string]any{
|
||||||
"A" + idx: row.JobID,
|
"A" + idx: row.JobID,
|
||||||
@@ -330,10 +351,8 @@ func (s *SysJobController) Export(c *gin.Context) {
|
|||||||
"D" + idx: row.InvokeTarget,
|
"D" + idx: row.InvokeTarget,
|
||||||
"E" + idx: row.TargetParams,
|
"E" + idx: row.TargetParams,
|
||||||
"F" + idx: row.CronExpression,
|
"F" + idx: row.CronExpression,
|
||||||
"G" + idx: misfirePolicy,
|
"G" + idx: statusValue,
|
||||||
"H" + idx: concurrent,
|
"H" + idx: row.Remark,
|
||||||
"I" + idx: statusValue,
|
|
||||||
"J" + idx: row.Remark,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"ems.agt/src/framework/i18n"
|
||||||
"ems.agt/src/framework/utils/ctx"
|
"ems.agt/src/framework/utils/ctx"
|
||||||
"ems.agt/src/framework/utils/date"
|
"ems.agt/src/framework/utils/date"
|
||||||
"ems.agt/src/framework/utils/file"
|
"ems.agt/src/framework/utils/file"
|
||||||
@@ -40,17 +41,42 @@ type SysJobLogController struct {
|
|||||||
func (s *SysJobLogController) List(c *gin.Context) {
|
func (s *SysJobLogController) List(c *gin.Context) {
|
||||||
// 查询参数转换map
|
// 查询参数转换map
|
||||||
querys := ctx.QueryMap(c)
|
querys := ctx.QueryMap(c)
|
||||||
list := s.sysJobLogService.SelectJobLogPage(querys)
|
data := s.sysJobLogService.SelectJobLogPage(querys)
|
||||||
c.JSON(200, result.Ok(list))
|
|
||||||
|
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
|
// GET /:jobLogId
|
||||||
func (s *SysJobLogController) Info(c *gin.Context) {
|
func (s *SysJobLogController) Info(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
jobLogId := c.Param("jobLogId")
|
jobLogId := c.Param("jobLogId")
|
||||||
if jobLogId == "" {
|
if jobLogId == "" {
|
||||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data := s.sysJobLogService.SelectJobLogById(jobLogId)
|
data := s.sysJobLogService.SelectJobLogById(jobLogId)
|
||||||
@@ -65,9 +91,10 @@ func (s *SysJobLogController) Info(c *gin.Context) {
|
|||||||
//
|
//
|
||||||
// DELETE /:jobLogIds
|
// DELETE /:jobLogIds
|
||||||
func (s *SysJobLogController) Remove(c *gin.Context) {
|
func (s *SysJobLogController) Remove(c *gin.Context) {
|
||||||
|
language := ctx.AcceptLanguage(c)
|
||||||
jobLogIds := c.Param("jobLogIds")
|
jobLogIds := c.Param("jobLogIds")
|
||||||
if jobLogIds == "" {
|
if jobLogIds == "" {
|
||||||
c.JSON(400, result.CodeMsg(400, "parameter error"))
|
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +108,7 @@ func (s *SysJobLogController) Remove(c *gin.Context) {
|
|||||||
rows := s.sysJobLogService.DeleteJobLogByIds(uniqueIDs)
|
rows := s.sysJobLogService.DeleteJobLogByIds(uniqueIDs)
|
||||||
if rows > 0 {
|
if rows > 0 {
|
||||||
// 删除成功:%d
|
// 删除成功:%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))
|
c.JSON(200, result.OkMsg(msg))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -113,18 +140,27 @@ func (s *SysJobLogController) Export(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
rows := data["rows"].([]model.SysJobLog)
|
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())
|
fileName := fmt.Sprintf("jobLog_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
|
||||||
// 第一行表头标题
|
// 第一行表头标题
|
||||||
headerCells := map[string]string{
|
headerCells := map[string]string{
|
||||||
"A1": "JobLogID",
|
"A1": i18n.TKey(language, "job.export.jobLogID"),
|
||||||
"B1": "JobName",
|
"B1": i18n.TKey(language, "job.export.jobName"),
|
||||||
"C1": "JobGroupName",
|
"C1": i18n.TKey(language, "job.export.jobGroupName"),
|
||||||
"D1": "InvokeTarget",
|
"D1": i18n.TKey(language, "job.export.invokeTarget"),
|
||||||
"E1": "TargetParams",
|
"E1": i18n.TKey(language, "job.export.targetParams"),
|
||||||
"F1": "JobMsg",
|
"F1": i18n.TKey(language, "job.export.jobID"),
|
||||||
"G1": "Status",
|
"G1": i18n.TKey(language, "job.export.jobLogStatus"),
|
||||||
"H1": "Time",
|
"H1": i18n.TKey(language, "job.export.jobLogTime"),
|
||||||
}
|
}
|
||||||
// 读取任务组名字典数据
|
// 读取任务组名字典数据
|
||||||
dictSysJobGroup := s.sysDictDataService.SelectDictDataByType("sys_job_group")
|
dictSysJobGroup := s.sysDictDataService.SelectDictDataByType("sys_job_group")
|
||||||
@@ -136,14 +172,14 @@ func (s *SysJobLogController) Export(c *gin.Context) {
|
|||||||
sysJobGroup := ""
|
sysJobGroup := ""
|
||||||
for _, v := range dictSysJobGroup {
|
for _, v := range dictSysJobGroup {
|
||||||
if row.JobGroup == v.DictValue {
|
if row.JobGroup == v.DictValue {
|
||||||
sysJobGroup = v.DictLabel
|
sysJobGroup = i18n.TKey(language, v.DictLabel)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 状态
|
// 状态
|
||||||
statusValue := "Fail"
|
statusValue := i18n.TKey(language, "dictData.fail")
|
||||||
if row.Status == "1" {
|
if row.Status == "1" {
|
||||||
statusValue = "Success"
|
statusValue = i18n.TKey(language, "dictData.success")
|
||||||
}
|
}
|
||||||
dataCells = append(dataCells, map[string]any{
|
dataCells = append(dataCells, map[string]any{
|
||||||
"A" + idx: row.JobLogID,
|
"A" + idx: row.JobLogID,
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package repository
|
package repository
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -210,7 +209,11 @@ func (r *SysJobImpl) CheckUniqueJob(sysJob model.SysJob) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
if len(results) > 0 {
|
if len(results) > 0 {
|
||||||
return fmt.Sprintf("%v", results[0]["str"])
|
v, ok := results[0]["str"].(string)
|
||||||
|
if ok {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user