feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
1 parent
045a2b6b01
commit
f3c33b31ac
272 files changed
+13153
-15792
No files matched your search
@@ -3,15 +3,14 @@ package controller
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/utils/date"
|
||||
"be.ems/src/framework/utils/file"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/modules/monitor/model"
|
||||
"be.ems/src/modules/monitor/service"
|
||||
systemService "be.ems/src/modules/system/service"
|
||||
@@ -21,6 +20,7 @@ import (
|
||||
|
||||
// 实例化控制层 SysJobLogController 结构体
|
||||
var NewSysJobLog = &SysJobLogController{
|
||||
sysJobService: service.NewSysJob,
|
||||
sysJobLogService: service.NewSysJobLog,
|
||||
sysDictDataService: systemService.NewSysDictData,
|
||||
}
|
||||
@@ -29,6 +29,7 @@ var NewSysJobLog = &SysJobLogController{
|
||||
//
|
||||
// PATH /monitor/jobLog
|
||||
type SysJobLogController struct {
|
||||
sysJobService *service.SysJob // 调度任务服务
|
||||
sysJobLogService *service.SysJobLog // 调度任务日志服务
|
||||
sysDictDataService *systemService.SysDictData // 字典数据服务
|
||||
}
|
||||
@@ -37,22 +38,23 @@ type SysJobLogController struct {
|
||||
//
|
||||
// GET /list
|
||||
func (s *SysJobLogController) List(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
// 查询参数转换map
|
||||
querys := ctx.QueryMap(c)
|
||||
query := reqctx.QueryMap(c)
|
||||
// 任务ID优先级更高
|
||||
if v, ok := querys["jobId"]; ok && v != nil {
|
||||
jobInfo := service.NewSysJob.SelectJobById(v.(string))
|
||||
querys["jobName"] = jobInfo.JobName
|
||||
querys["jobGroup"] = jobInfo.JobGroup
|
||||
if jobIdStr := c.Query("jobId"); jobIdStr != "" {
|
||||
if jobId := parse.Number(jobIdStr); jobId > 0 {
|
||||
job := s.sysJobService.FindById(jobId)
|
||||
query["jobName"] = job.JobName
|
||||
query["jobGroup"] = job.JobGroup
|
||||
}
|
||||
}
|
||||
// 多语言值转key查询
|
||||
if v, ok := querys["jobName"]; ok && v != "" {
|
||||
querys["jobName"] = i18n.TFindKeyPrefix(language, "job", v.(string))
|
||||
if v, ok := query["jobName"]; ok && v != "" {
|
||||
query["jobName"] = i18n.TFindKeyPrefix(language, "job", v)
|
||||
}
|
||||
|
||||
data := s.sysJobLogService.SelectJobLogPage(querys)
|
||||
rows := data["rows"].([]model.SysJobLog)
|
||||
rows, total := s.sysJobLogService.FindByPage(query)
|
||||
|
||||
// 闭包函数处理多语言
|
||||
converI18n := func(language string, arr *[]model.SysJobLog) {
|
||||
@@ -62,88 +64,89 @@ func (s *SysJobLogController) List(c *gin.Context) {
|
||||
}
|
||||
converI18n(language, &rows)
|
||||
|
||||
c.JSON(200, result.Ok(data))
|
||||
c.JSON(200, resp.OkData(map[string]any{"rows": rows, "total": total}))
|
||||
}
|
||||
|
||||
// 调度任务日志信息
|
||||
//
|
||||
// GET /:jobLogId
|
||||
// GET /:logId
|
||||
func (s *SysJobLogController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
jobLogId := c.Param("jobLogId")
|
||||
if jobLogId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
logId := parse.Number(c.Param("logId"))
|
||||
if logId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: logId is empty"))
|
||||
return
|
||||
}
|
||||
data := s.sysJobLogService.SelectJobLogById(jobLogId)
|
||||
if data.JobLogID == jobLogId {
|
||||
c.JSON(200, result.OkData(data))
|
||||
|
||||
jobLogInfo := s.sysJobLogService.FindById(logId)
|
||||
if jobLogInfo.LogId == logId {
|
||||
c.JSON(200, resp.OkData(jobLogInfo))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务日志删除
|
||||
//
|
||||
// DELETE /:jobLogIds
|
||||
// DELETE /:logId
|
||||
func (s *SysJobLogController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
jobLogIds := c.Param("jobLogIds")
|
||||
if jobLogIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
logId := c.Param("logId")
|
||||
if logId == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: logId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(jobLogIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
uniqueIDs := parse.RemoveDuplicatesToArray(logId, ",")
|
||||
// 转换成int64数组类型
|
||||
ids := make([]int64, 0)
|
||||
for _, v := range uniqueIDs {
|
||||
ids = append(ids, parse.Number(v))
|
||||
}
|
||||
rows := s.sysJobLogService.DeleteJobLogByIds(uniqueIDs)
|
||||
|
||||
rows := s.sysJobLogService.DeleteByIds(ids)
|
||||
if rows > 0 {
|
||||
// 删除成功:%d
|
||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
c.JSON(200, resp.OkMsg(msg))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务日志清空
|
||||
//
|
||||
// DELETE /clean
|
||||
func (s *SysJobLogController) Clean(c *gin.Context) {
|
||||
err := s.sysJobLogService.CleanJobLog()
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
rows := s.sysJobLogService.Clean()
|
||||
c.JSON(200, resp.OkData(rows))
|
||||
}
|
||||
|
||||
// 导出调度任务日志信息
|
||||
// Export 导出调度任务日志信息
|
||||
//
|
||||
// POST /export
|
||||
// GET /export
|
||||
func (s *SysJobLogController) Export(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
// 查询结果,根据查询条件结果,单页最大值限制
|
||||
querys := ctx.BodyJSONMap(c)
|
||||
querys["pageNum"] = 1
|
||||
querys["pageSize"] = 10000
|
||||
data := s.sysJobLogService.SelectJobLogPage(querys)
|
||||
if parse.Number(data["total"]) == 0 {
|
||||
query := reqctx.QueryMap(c)
|
||||
if jobIdStr := c.Query("jobId"); jobIdStr != "" {
|
||||
if jobId := parse.Number(jobIdStr); jobId > 0 {
|
||||
job := s.sysJobService.FindById(jobId)
|
||||
query["jobName"] = job.JobName
|
||||
query["jobGroup"] = job.JobGroup
|
||||
}
|
||||
}
|
||||
rows, total := s.sysJobLogService.FindByPage(query)
|
||||
if total == 0 {
|
||||
// 导出数据记录为空
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
return
|
||||
}
|
||||
rows := data["rows"].([]model.SysJobLog)
|
||||
|
||||
// rows := s.sysJobLogService.SelectJobLogList(model.SysJobLog{})
|
||||
if len(rows) <= 0 {
|
||||
// 导出数据记录为空
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "app.common.exportEmpty")))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -170,7 +173,7 @@ func (s *SysJobLogController) Export(c *gin.Context) {
|
||||
"G1": i18n.TKey(language, "log.operate.export.costTime"),
|
||||
}
|
||||
// 读取任务组名字典数据
|
||||
dictSysJobGroup := s.sysDictDataService.SelectDictDataByType("sys_job_group")
|
||||
dictSysJobGroup := s.sysDictDataService.FindByType("sys_job_group")
|
||||
// 从第二行开始的数据
|
||||
dataCells := make([]map[string]any, 0)
|
||||
for i, row := range rows {
|
||||
@@ -178,18 +181,18 @@ func (s *SysJobLogController) Export(c *gin.Context) {
|
||||
// 任务组名
|
||||
sysJobGroup := ""
|
||||
for _, v := range dictSysJobGroup {
|
||||
if row.JobGroup == v.DictValue {
|
||||
sysJobGroup = i18n.TKey(language, v.DictLabel)
|
||||
if row.JobGroup == v.DataValue {
|
||||
sysJobGroup = i18n.TKey(language, v.DataLabel)
|
||||
break
|
||||
}
|
||||
}
|
||||
// 状态
|
||||
statusValue := i18n.TKey(language, "dictData.fail")
|
||||
if row.Status == "1" {
|
||||
if row.StatusFlag == "1" {
|
||||
statusValue = i18n.TKey(language, "dictData.success")
|
||||
}
|
||||
dataCells = append(dataCells, map[string]any{
|
||||
"A" + idx: row.JobLogID,
|
||||
"A" + idx: row.LogId,
|
||||
"B" + idx: row.JobName,
|
||||
"C" + idx: sysJobGroup,
|
||||
"D" + idx: row.InvokeTarget,
|
||||
@@ -204,7 +207,7 @@ func (s *SysJobLogController) Export(c *gin.Context) {
|
||||
// 导出数据表格
|
||||
saveFilePath, err := file.WriteSheet(headerCells, dataCells, fileName, "")
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user