feat: 更新多个模块以支持新的数据结构和日志格式
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/modules/monitor/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -29,39 +29,39 @@ type MonitorController struct {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param type query string true "Data Type" Enums(all,load,cpu,memory,io,network) default(all)
|
||||
// @Param startTime query number true "StartTime, timestamp milliseconds" default(1738771200000)
|
||||
// @Param beginTime query number true "BeginTime, timestamp milliseconds" default(1738771200000)
|
||||
// @Param endTime query number true "EndTime, timestamp milliseconds" default(1738810051253)
|
||||
// @Param neType query string false "NE Type, Currently none Default #" default(#)
|
||||
// @Param neId query string false "NE ID, Currently none Default #" default(#)
|
||||
// @Param name query string false "Name, Data Type valid for networ and io"
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Security TokenAuth
|
||||
// @Summary Resource monitoring information loading
|
||||
// @Description Resource monitoring information loading
|
||||
// @Summary Load Resource Utilization Information
|
||||
// @Description Load Resource Utilization Information
|
||||
// @Router /monitor/load [get]
|
||||
func (s *MonitorController) Load(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
var querys struct {
|
||||
Type string `form:"type" binding:"required,oneof=all load cpu memory io network"` // 数据类型all/load/cpu/memory/io/network
|
||||
StartTime int64 `form:"startTime" binding:"required"` // 开始时间
|
||||
BeginTime int64 `form:"beginTime" binding:"required"` // 开始时间
|
||||
EndTime int64 `form:"endTime" binding:"required"` // 结束时间
|
||||
NeType string `form:"neType"` // 网元类型
|
||||
NeID string `form:"neId"` // 网元ID
|
||||
Name string `form:"name"` // 名称,networ和io时有效
|
||||
}
|
||||
if err := c.ShouldBindQuery(&querys); err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
// 查询数据
|
||||
data := s.monitorService.SelectMonitorInfo(map[string]any{
|
||||
data := s.monitorService.FindInfo(map[string]any{
|
||||
"type": querys.Type,
|
||||
"startTime": querys.StartTime,
|
||||
"beginTime": querys.BeginTime,
|
||||
"endTime": querys.EndTime,
|
||||
"neType": querys.NeType,
|
||||
"neId": querys.NeID,
|
||||
"name": querys.Name,
|
||||
})
|
||||
c.JSON(200, result.OkData(data))
|
||||
c.JSON(200, resp.OkData(data))
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"be.ems/src/framework/constants/cachekey"
|
||||
"fmt"
|
||||
|
||||
"be.ems/src/framework/constants"
|
||||
"be.ems/src/framework/database/redis"
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/redis"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/reqctx"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/modules/monitor/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -32,138 +34,148 @@ type SysCacheController struct{}
|
||||
// @Description Cache Service Information
|
||||
// @Router /monitor/cache [get]
|
||||
func (s *SysCacheController) Info(c *gin.Context) {
|
||||
c.JSON(200, result.OkData(map[string]any{
|
||||
c.JSON(200, resp.OkData(map[string]any{
|
||||
"info": redis.Info(""),
|
||||
"dbSize": redis.KeySize(""),
|
||||
"commandStats": redis.CommandStats(""),
|
||||
}))
|
||||
}
|
||||
|
||||
// 缓存名称列表
|
||||
// Names 缓存名称列表
|
||||
//
|
||||
// GET /getNames
|
||||
func (s *SysCacheController) Names(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
// GET /names
|
||||
func (s SysCacheController) Names(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
caches := []model.SysCache{
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.user"), cachekey.LOGIN_TOKEN_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.sys_config"), cachekey.SYS_CONFIG_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.sys_dict"), cachekey.SYS_DICT_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.captcha_codes"), cachekey.CAPTCHA_CODE_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.repeat_submit"), cachekey.REPEAT_SUBMIT_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.rate_limit"), cachekey.RATE_LIMIT_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.pwd_err_cnt"), cachekey.PWD_ERR_CNT_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.ne_info"), cachekey.NE_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.ne_data"), cachekey.NE_DATA_KEY),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.user"), constants.CACHE_LOGIN_TOKEN),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.sys_config"), constants.CACHE_SYS_CONFIG),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.sys_dict"), constants.CACHE_SYS_DICT),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.captcha_codes"), constants.CACHE_CAPTCHA_CODE),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.repeat_submit"), constants.CACHE_REPEAT_SUBMIT),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.rate_limit"), constants.CACHE_RATE_LIMIT),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.pwd_err_cnt"), constants.CACHE_PWD_ERR_COUNT),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.ne_info"), constants.CACHE_NE_INFO),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.ne_data"), constants.CACHE_NE_DATA),
|
||||
}
|
||||
c.JSON(200, result.OkData(caches))
|
||||
c.JSON(200, resp.OkData(caches))
|
||||
}
|
||||
|
||||
// 缓存名称下键名列表
|
||||
// Keys 缓存名称下键名列表
|
||||
//
|
||||
// GET /getKeys/:cacheName
|
||||
func (s *SysCacheController) Keys(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
cacheName := c.Param("cacheName")
|
||||
if cacheName == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
// GET /keys?cacheName=xxx
|
||||
func (s SysCacheController) Keys(c *gin.Context) {
|
||||
var query struct {
|
||||
CacheName string `form:"cacheName" binding:"required"` // 键名列表中得到的缓存名称
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
caches := []model.SysCache{}
|
||||
|
||||
// 遍历组装
|
||||
cacheKeys, _ := redis.GetKeys("", cacheName+":*")
|
||||
cacheKeys, _ := redis.GetKeys("", query.CacheName+":*")
|
||||
for _, key := range cacheKeys {
|
||||
caches = append(caches, model.NewSysCacheKeys(cacheName, key))
|
||||
caches = append(caches, model.NewKeys(query.CacheName, key))
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(caches))
|
||||
c.JSON(200, resp.OkData(caches))
|
||||
}
|
||||
|
||||
// 缓存内容
|
||||
// Value 缓存内容信息
|
||||
//
|
||||
// GET /getValue/:cacheName/:cacheKey
|
||||
func (s *SysCacheController) Value(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
cacheName := c.Param("cacheName")
|
||||
cacheKey := c.Param("cacheKey")
|
||||
if cacheName == "" || cacheKey == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
// GET /value?cacheName=xxx&cacheKey=xxx
|
||||
func (s SysCacheController) Value(c *gin.Context) {
|
||||
var query struct {
|
||||
CacheName string `form:"cacheName" binding:"required"` // 键名列表中得到的缓存名称
|
||||
CacheKey string `form:"cacheKey" binding:"required"` // 键名列表中得到的缓存键名
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
cacheValue, err := redis.Get("", cacheName+":"+cacheKey)
|
||||
cacheValue, err := redis.Get("", query.CacheName+":"+query.CacheKey)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
sysCache := model.NewSysCacheValue(cacheName, cacheKey, cacheValue)
|
||||
c.JSON(200, result.OkData(sysCache))
|
||||
sysCache := model.NewValue(query.CacheName, query.CacheKey, cacheValue)
|
||||
c.JSON(200, resp.OkData(sysCache))
|
||||
}
|
||||
|
||||
// 删除缓存名称下键名列表
|
||||
// CleanNames 缓存名称列表安全删除
|
||||
//
|
||||
// DELETE /clearCacheName/:cacheName
|
||||
func (s *SysCacheController) ClearCacheName(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
cacheName := c.Param("cacheName")
|
||||
if cacheName == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
cacheKeys, err := redis.GetKeys("", cacheName+":*")
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
ok, _ := redis.DelKeys("", cacheKeys)
|
||||
if ok {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 删除缓存键名
|
||||
//
|
||||
// DELETE /clearCacheKey/:cacheName/:cacheKey
|
||||
func (s *SysCacheController) ClearCacheKey(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
cacheName := c.Param("cacheName")
|
||||
cacheKey := c.Param("cacheKey")
|
||||
if cacheName == "" || cacheKey == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
return
|
||||
}
|
||||
|
||||
ok, _ := redis.Del("", cacheName+":"+cacheKey)
|
||||
if ok {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 安全清理缓存名称
|
||||
//
|
||||
// DELETE /clearCacheSafe
|
||||
func (s *SysCacheController) ClearCacheSafe(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
// DELETE /names
|
||||
func (s SysCacheController) CleanNames(c *gin.Context) {
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
caches := []model.SysCache{
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.sys_config"), cachekey.SYS_CONFIG_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.sys_dict"), cachekey.SYS_DICT_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.repeat_submit"), cachekey.REPEAT_SUBMIT_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.rate_limit"), cachekey.RATE_LIMIT_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.pwd_err_cnt"), cachekey.PWD_ERR_CNT_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.ne_info"), cachekey.NE_KEY),
|
||||
model.NewSysCacheNames(i18n.TKey(language, "cache.name.ne_data"), cachekey.NE_DATA_KEY),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.sys_config"), constants.CACHE_SYS_CONFIG),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.sys_dict"), constants.CACHE_SYS_DICT),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.repeat_submit"), constants.CACHE_REPEAT_SUBMIT),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.rate_limit"), constants.CACHE_RATE_LIMIT),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.pwd_err_cnt"), constants.CACHE_PWD_ERR_COUNT),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.ne_info"), constants.CACHE_NE_INFO),
|
||||
model.NewNames(i18n.TKey(language, "cache.name.ne_data"), constants.CACHE_NE_DATA),
|
||||
}
|
||||
for _, v := range caches {
|
||||
cacheKeys, err := redis.GetKeys("", v.CacheName+":*")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
redis.DelKeys("", cacheKeys)
|
||||
_ = redis.DelKeys("", cacheKeys)
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// CleanKeys 缓存名称下键名删除
|
||||
//
|
||||
// DELETE /keys?cacheName=xxx
|
||||
func (s SysCacheController) CleanKeys(c *gin.Context) {
|
||||
var query struct {
|
||||
CacheName string `form:"cacheName" binding:"required"` // 键名列表中得到的缓存名称
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
if constants.CACHE_LOGIN_TOKEN == query.CacheName {
|
||||
c.JSON(200, resp.ErrMsg("Cannot delete user information cache"))
|
||||
return
|
||||
}
|
||||
|
||||
cacheKeys, err := redis.GetKeys("", query.CacheName+":*")
|
||||
if err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
if err = redis.DelKeys("", cacheKeys); err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// CleanValue 缓存内容删除
|
||||
//
|
||||
// DELETE /value?cacheName=xxx&cacheKey=xxx
|
||||
func (s SysCacheController) CleanValue(c *gin.Context) {
|
||||
var query struct {
|
||||
CacheName string `form:"cacheName" binding:"required"` // 键名列表中得到的缓存名称
|
||||
CacheKey string `form:"cacheKey" binding:"required"` // 键名列表中得到的缓存键名
|
||||
}
|
||||
if err := c.ShouldBindQuery(&query); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
if err := redis.Del("", query.CacheName+":"+query.CacheKey); err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
@@ -4,20 +4,18 @@ import (
|
||||
"encoding/json"
|
||||
"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/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"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 SysJobLogController 结构体
|
||||
@@ -38,15 +36,14 @@ type SysJobController struct {
|
||||
//
|
||||
// GET /list
|
||||
func (s *SysJobController) List(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
querys := ctx.QueryMap(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
query := reqctx.QueryMap(c)
|
||||
// 多语言值转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.sysJobService.SelectJobPage(querys)
|
||||
rows := data["rows"].([]model.SysJob)
|
||||
rows, total := s.sysJobService.FindByPage(query)
|
||||
|
||||
// 闭包函数处理多语言
|
||||
converI18n := func(language string, arr *[]model.SysJob) {
|
||||
@@ -57,40 +54,44 @@ func (s *SysJobController) 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 /:jobId
|
||||
func (s *SysJobController) Info(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
jobId := c.Param("jobId")
|
||||
if jobId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
jobId := parse.Number(c.Param("jobId"))
|
||||
if jobId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: jobId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
data := s.sysJobService.SelectJobById(jobId)
|
||||
if data.JobID == jobId {
|
||||
data := s.sysJobService.FindById(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, resp.OkData(data))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务新增
|
||||
//
|
||||
// POST /
|
||||
func (s *SysJobController) Add(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body model.SysJob
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.JobID != "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.JobId > 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: jobId not is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -98,7 +99,7 @@ func (s *SysJobController) Add(c *gin.Context) {
|
||||
if parse.CronExpression(body.CronExpression) == 0 {
|
||||
// 调度任务新增【%s】失败,Cron表达式不正确
|
||||
msg := i18n.TTemplate(language, "job.errCronExpression", map[string]any{"name": body.JobName})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
c.JSON(200, resp.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -107,42 +108,46 @@ func (s *SysJobController) Add(c *gin.Context) {
|
||||
// 调度任务新增【%s】失败,任务传入参数json字符串不正确
|
||||
msg := i18n.TTemplate(language, "job.errTargetParams", map[string]any{"name": body.JobName})
|
||||
if len(body.TargetParams) < 7 {
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
c.JSON(200, resp.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
if !json.Valid([]byte(body.TargetParams)) {
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
c.JSON(200, resp.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueJob := s.sysJobService.CheckUniqueJobName(body.JobName, body.JobGroup, "")
|
||||
uniqueJob := s.sysJobService.CheckUniqueByJobName(body.JobName, body.JobGroup, 0)
|
||||
if !uniqueJob {
|
||||
// 调度任务新增【%s】失败,同任务组内有相同任务名称
|
||||
msg := i18n.TTemplate(language, "job.errJobExists", map[string]any{"name": body.JobName})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
c.JSON(200, resp.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
insertId := s.sysJobService.InsertJob(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
body.CreateBy = reqctx.LoginUserToUserName(c)
|
||||
insertId := s.sysJobService.Insert(body)
|
||||
if insertId > 0 {
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *SysJobController) Edit(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body model.SysJob
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.JobID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
if body.JobId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: jobId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -150,7 +155,7 @@ func (s *SysJobController) Edit(c *gin.Context) {
|
||||
if parse.CronExpression(body.CronExpression) == 0 {
|
||||
// 调度任务修改【%s】失败,Cron表达式不正确
|
||||
msg := i18n.TTemplate(language, "job.errCronExpression", map[string]any{"name": body.JobName})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
c.JSON(200, resp.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -159,179 +164,188 @@ func (s *SysJobController) Edit(c *gin.Context) {
|
||||
// 调度任务修改【%s】失败,任务传入参数json字符串不正确
|
||||
msg := i18n.TTemplate(language, "job.errTargetParams", map[string]any{"name": body.JobName})
|
||||
if len(body.TargetParams) < 7 {
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
c.JSON(200, resp.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
if !json.Valid([]byte(body.TargetParams)) {
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
c.JSON(200, resp.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
job := s.sysJobService.SelectJobById(body.JobID)
|
||||
if job.JobID != body.JobID {
|
||||
jobInfo := s.sysJobService.FindById(body.JobId)
|
||||
if jobInfo.JobId != body.JobId {
|
||||
// 没有可访问调度任务数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "job.noData")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "job.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueJob := s.sysJobService.CheckUniqueJobName(body.JobName, body.JobGroup, body.JobID)
|
||||
uniqueJob := s.sysJobService.CheckUniqueByJobName(body.JobName, body.JobGroup, body.JobId)
|
||||
if !uniqueJob {
|
||||
// 调度任务修改【%s】失败,同任务组内有相同任务名称
|
||||
msg := i18n.TTemplate(language, "job.errJobExists", map[string]any{"name": body.JobName})
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
c.JSON(200, resp.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 多语言非原始值
|
||||
i18nValue := i18n.TKey(language, job.JobName)
|
||||
if i18nValue != job.JobName {
|
||||
i18n.UpdateKeyValue(language, job.JobName, body.JobName)
|
||||
body.JobName = job.JobName
|
||||
i18nValue := i18n.TKey(language, jobInfo.JobName)
|
||||
if i18nValue != jobInfo.JobName {
|
||||
systemService.NewSysI18n.UpdateKeyValue(language, jobInfo.JobName, body.JobName)
|
||||
body.JobName = jobInfo.JobName
|
||||
}
|
||||
// 多语言非原始值
|
||||
i18nValue2 := i18n.TKey(language, job.Remark)
|
||||
if i18nValue2 != job.Remark {
|
||||
i18n.UpdateKeyValue(language, job.Remark, body.Remark)
|
||||
body.Remark = job.Remark
|
||||
i18nValue2 := i18n.TKey(language, jobInfo.Remark)
|
||||
if i18nValue2 != jobInfo.Remark {
|
||||
systemService.NewSysI18n.UpdateKeyValue(language, jobInfo.Remark, body.Remark)
|
||||
body.Remark = jobInfo.Remark
|
||||
}
|
||||
|
||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.sysJobService.UpdateJob(body)
|
||||
jobInfo.JobName = body.JobName
|
||||
jobInfo.JobGroup = body.JobGroup
|
||||
jobInfo.InvokeTarget = body.InvokeTarget
|
||||
jobInfo.TargetParams = body.TargetParams
|
||||
jobInfo.CronExpression = body.CronExpression
|
||||
jobInfo.MisfirePolicy = body.MisfirePolicy
|
||||
jobInfo.Concurrent = body.Concurrent
|
||||
jobInfo.StatusFlag = body.StatusFlag
|
||||
jobInfo.SaveLog = body.SaveLog
|
||||
jobInfo.Remark = body.Remark
|
||||
jobInfo.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
rows := s.sysJobService.Update(jobInfo)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务删除
|
||||
//
|
||||
// DELETE /:jobIds
|
||||
// DELETE /:jobId
|
||||
func (s *SysJobController) Remove(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
jobIds := c.Param("jobIds")
|
||||
if jobIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
jobId := c.Param("jobId")
|
||||
if jobId == "" {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: jobId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(jobIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
uniqueIDs := parse.RemoveDuplicatesToArray(jobId, ",")
|
||||
// 转换成int64数组类型
|
||||
ids := make([]int64, 0)
|
||||
for _, v := range uniqueIDs {
|
||||
ids = append(ids, parse.Number(v))
|
||||
}
|
||||
rows, err := s.sysJobService.DeleteJobByIds(uniqueIDs)
|
||||
|
||||
rows, err := s.sysJobService.DeleteByIds(ids)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
msg := i18n.TTemplate(language, "app.common.deleteSuccess", map[string]any{"num": rows})
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
c.JSON(200, resp.OkMsg(msg))
|
||||
}
|
||||
|
||||
// 调度任务修改状态
|
||||
//
|
||||
// PUT /changeStatus
|
||||
func (s *SysJobController) Status(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
var body struct {
|
||||
// 任务ID
|
||||
JobId string `json:"jobId" binding:"required"`
|
||||
// 状态
|
||||
Status string `json:"status" binding:"required"`
|
||||
JobId int64 `json:"jobId" binding:"required"`
|
||||
StatusFlag string `json:"statusFlag" binding:"required,oneof=0 1 2"`
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
if err := c.ShouldBindBodyWithJSON(&body); err != nil {
|
||||
errMsgs := fmt.Sprintf("bind err: %s", resp.FormatBindError(err))
|
||||
c.JSON(422, resp.CodeMsg(40422, errMsgs))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
job := s.sysJobService.SelectJobById(body.JobId)
|
||||
if job.JobID != body.JobId {
|
||||
// 检查是否存在
|
||||
jobInfo := s.sysJobService.FindById(body.JobId)
|
||||
if jobInfo.JobId != body.JobId {
|
||||
// 没有可访问调度任务数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "job.noData")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "job.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
// 与旧值相等不变更
|
||||
if job.Status == body.Status {
|
||||
if jobInfo.StatusFlag == body.StatusFlag {
|
||||
// 变更状态与旧值相等!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "job.statusEq")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "job.statusEq")))
|
||||
return
|
||||
}
|
||||
|
||||
// 更新状态
|
||||
job.Status = body.Status
|
||||
job.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.sysJobService.UpdateJob(job)
|
||||
jobInfo.StatusFlag = body.StatusFlag
|
||||
jobInfo.UpdateBy = reqctx.LoginUserToUserName(c)
|
||||
rows := s.sysJobService.Update(jobInfo)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务立即执行一次
|
||||
//
|
||||
// PUT /run/:jobId
|
||||
func (s *SysJobController) Run(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
jobId := c.Param("jobId")
|
||||
if jobId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
jobId := parse.Number(c.Param("jobId"))
|
||||
if jobId <= 0 {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: jobId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
job := s.sysJobService.SelectJobById(jobId)
|
||||
if job.JobID != jobId {
|
||||
job := s.sysJobService.FindById(jobId)
|
||||
if job.JobId != jobId {
|
||||
// 没有可访问调度任务数据!
|
||||
c.JSON(200, result.ErrMsg(i18n.TKey(language, "job.noData")))
|
||||
c.JSON(200, resp.ErrMsg(i18n.TKey(language, "job.noData")))
|
||||
return
|
||||
}
|
||||
|
||||
ok := s.sysJobService.RunQueueJob(job)
|
||||
ok := s.sysJobService.Run(job)
|
||||
if ok {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
c.JSON(200, resp.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务重置刷新队列
|
||||
//
|
||||
// PUT /resetQueueJob
|
||||
func (s *SysJobController) ResetQueueJob(c *gin.Context) {
|
||||
s.sysJobService.ResetQueueJob()
|
||||
c.JSON(200, result.Ok(nil))
|
||||
s.sysJobService.Reset()
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
// 导出调度任务信息
|
||||
// Export 导出调度任务信息
|
||||
//
|
||||
// POST /export
|
||||
// GET /export
|
||||
func (s *SysJobController) Export(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
language := reqctx.AcceptLanguage(c)
|
||||
// 查询结果,根据查询条件结果,单页最大值限制
|
||||
querys := ctx.BodyJSONMap(c)
|
||||
querys["pageNum"] = 1
|
||||
querys["pageSize"] = 10000
|
||||
data := s.sysJobService.SelectJobPage(querys)
|
||||
if parse.Number(data["total"]) == 0 {
|
||||
query := reqctx.QueryMap(c)
|
||||
rows, total := s.sysJobService.FindByPage(query)
|
||||
if total == 0 {
|
||||
// c.JSON(200, resp.CodeMsg(40016, "export data record as empty"))
|
||||
// 导出数据记录为空
|
||||
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.SysJob)
|
||||
|
||||
// rows := s.sysJobService.SelectJobList(model.SysJob{})
|
||||
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
|
||||
}
|
||||
|
||||
@@ -358,7 +372,7 @@ func (s *SysJobController) Export(c *gin.Context) {
|
||||
// "E1": i18n.TKey(language, "job.export.targetParams"),
|
||||
}
|
||||
// 读取任务组名字典数据
|
||||
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 {
|
||||
@@ -366,19 +380,19 @@ func (s *SysJobController) 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.JobID,
|
||||
"A" + idx: row.JobId,
|
||||
"B" + idx: row.JobName,
|
||||
"C" + idx: sysJobGroup,
|
||||
"D" + idx: row.InvokeTarget,
|
||||
@@ -392,7 +406,7 @@ func (s *SysJobController) 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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,15 @@ package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"be.ems/src/framework/constants/cachekey"
|
||||
"be.ems/src/framework/i18n"
|
||||
"be.ems/src/framework/redis"
|
||||
"be.ems/src/framework/utils/ctx"
|
||||
"be.ems/src/framework/vo"
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/constants"
|
||||
"be.ems/src/framework/database/redis"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/framework/token"
|
||||
"be.ems/src/framework/utils/parse"
|
||||
"be.ems/src/modules/monitor/model"
|
||||
"be.ems/src/modules/monitor/service"
|
||||
|
||||
@@ -42,12 +42,11 @@ type SysUserOnlineController struct {
|
||||
// @Description System Online User List
|
||||
// @Router /monitor/online/list [get]
|
||||
func (s *SysUserOnlineController) List(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
ipaddr := c.Query("ipaddr")
|
||||
loginIp := c.Query("loginIp")
|
||||
userName := c.Query("userName")
|
||||
|
||||
// 获取所有在线用户key
|
||||
keys, _ := redis.GetKeys("", cachekey.LOGIN_TOKEN_KEY+"*")
|
||||
keys, _ := redis.GetKeys("", constants.CACHE_LOGIN_TOKEN+":*")
|
||||
|
||||
// 分批获取
|
||||
arr := make([]string, 0)
|
||||
@@ -59,81 +58,84 @@ func (s *SysUserOnlineController) List(c *gin.Context) {
|
||||
chunk := keys[i:end]
|
||||
values, _ := redis.GetBatch("", chunk)
|
||||
for _, v := range values {
|
||||
arr = append(arr, v.(string))
|
||||
arr = append(arr, fmt.Sprint(v))
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历字符串信息解析组合可用对象
|
||||
userOnlines := make([]model.SysUserOnline, 0)
|
||||
var userOnlines []model.SysUserOnline
|
||||
for _, str := range arr {
|
||||
if str == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
var loginUser vo.LoginUser
|
||||
err := json.Unmarshal([]byte(str), &loginUser)
|
||||
var tokenInfo token.TokenInfo
|
||||
err := json.Unmarshal([]byte(str), &tokenInfo)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
onlineUser := s.sysUserOnlineService.LoginUserToUserOnline(loginUser)
|
||||
onlineUser := s.sysUserOnlineService.TokenInfoToUserOnline(tokenInfo)
|
||||
if onlineUser.TokenID != "" {
|
||||
onlineUser.LoginLocation = i18n.TKey(language, onlineUser.LoginLocation)
|
||||
userOnlines = append(userOnlines, onlineUser)
|
||||
}
|
||||
}
|
||||
|
||||
// 根据查询条件过滤
|
||||
filteredUserOnlines := make([]model.SysUserOnline, 0)
|
||||
if ipaddr != "" && userName != "" {
|
||||
filteredUserOnline := make([]model.SysUserOnline, 0)
|
||||
if loginIp != "" && userName != "" {
|
||||
for _, o := range userOnlines {
|
||||
if strings.Contains(o.IPAddr, ipaddr) && strings.Contains(o.UserName, userName) {
|
||||
filteredUserOnlines = append(filteredUserOnlines, o)
|
||||
if strings.Contains(o.LoginIp, loginIp) && strings.Contains(o.UserName, userName) {
|
||||
filteredUserOnline = append(filteredUserOnline, o)
|
||||
}
|
||||
}
|
||||
} else if ipaddr != "" {
|
||||
} else if loginIp != "" {
|
||||
for _, o := range userOnlines {
|
||||
if strings.Contains(o.IPAddr, ipaddr) {
|
||||
filteredUserOnlines = append(filteredUserOnlines, o)
|
||||
if strings.Contains(o.LoginIp, loginIp) {
|
||||
filteredUserOnline = append(filteredUserOnline, o)
|
||||
}
|
||||
}
|
||||
} else if userName != "" {
|
||||
for _, o := range userOnlines {
|
||||
if strings.Contains(o.UserName, userName) {
|
||||
filteredUserOnlines = append(filteredUserOnlines, o)
|
||||
filteredUserOnline = append(filteredUserOnline, o)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filteredUserOnlines = userOnlines
|
||||
filteredUserOnline = userOnlines
|
||||
}
|
||||
|
||||
// 按登录时间排序
|
||||
sort.Slice(filteredUserOnlines, func(i, j int) bool {
|
||||
return filteredUserOnlines[j].LoginTime > filteredUserOnlines[i].LoginTime
|
||||
sort.Slice(filteredUserOnline, func(i, j int) bool {
|
||||
return filteredUserOnline[j].LoginTime > filteredUserOnline[i].LoginTime
|
||||
})
|
||||
|
||||
c.JSON(200, result.Ok(map[string]any{
|
||||
"total": len(filteredUserOnlines),
|
||||
"rows": filteredUserOnlines,
|
||||
c.JSON(200, resp.OkData(map[string]any{
|
||||
"total": len(filteredUserOnline),
|
||||
"rows": filteredUserOnline,
|
||||
}))
|
||||
}
|
||||
|
||||
// 在线用户强制退出
|
||||
// Logout 在线用户强制退出
|
||||
//
|
||||
// DELETE /:tokenId
|
||||
func (s *SysUserOnlineController) ForceLogout(c *gin.Context) {
|
||||
language := ctx.AcceptLanguage(c)
|
||||
tokenId := c.Param("tokenId")
|
||||
if tokenId == "" || tokenId == "*" {
|
||||
c.JSON(400, result.CodeMsg(400, i18n.TKey(language, "app.common.err400")))
|
||||
// DELETE /logout/:tokenId
|
||||
func (s SysUserOnlineController) Logout(c *gin.Context) {
|
||||
tokenIdStr := c.Param("tokenId")
|
||||
if tokenIdStr == "" || strings.Contains(tokenIdStr, "*") {
|
||||
c.JSON(400, resp.CodeMsg(40010, "bind err: tokenId is empty"))
|
||||
return
|
||||
}
|
||||
|
||||
// 删除token
|
||||
ok, _ := redis.Del("", cachekey.LOGIN_TOKEN_KEY+tokenId)
|
||||
if ok {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(tokenIdStr, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
for _, v := range uniqueIDs {
|
||||
key := constants.CACHE_LOGIN_TOKEN + ":" + v
|
||||
if err := redis.Del("", key); err != nil {
|
||||
c.JSON(200, resp.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
|
||||
c.JSON(200, resp.Ok(nil))
|
||||
}
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"be.ems/src/framework/vo/result"
|
||||
"be.ems/src/framework/resp"
|
||||
"be.ems/src/modules/monitor/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 实例化控制层 SystemInfoController 结构体
|
||||
var NewSystemInfo = &SystemInfoController{
|
||||
systemInfogService: service.NewSystemInfo,
|
||||
// NewSystem 实例化控制层
|
||||
var NewSystem = &SystemController{
|
||||
systemInfoService: service.NewSystemInfo,
|
||||
}
|
||||
|
||||
// 服务器监控信息
|
||||
// SystemController 服务器监控信息 控制层处理
|
||||
//
|
||||
// PATH /monitor/system-info
|
||||
type SystemInfoController struct {
|
||||
systemInfogService *service.SystemInfo // 服务器系统相关信息服务
|
||||
// PATH /monitor/system
|
||||
type SystemController struct {
|
||||
// 服务器系统相关信息服务
|
||||
systemInfoService *service.SystemInfo
|
||||
}
|
||||
|
||||
// 服务器信息
|
||||
@@ -28,17 +29,17 @@ type SystemInfoController struct {
|
||||
// @Produce json
|
||||
// @Success 200 {object} object "Response Results"
|
||||
// @Security TokenAuth
|
||||
// @Summary Server Information
|
||||
// @Description Server Information
|
||||
// @Summary System Server Information
|
||||
// @Description System Server Information
|
||||
// @Router /monitor/system-info [get]
|
||||
func (s *SystemInfoController) Info(c *gin.Context) {
|
||||
func (s SystemController) Info(c *gin.Context) {
|
||||
data := map[string]any{
|
||||
"cpu": s.systemInfogService.CPUInfo(),
|
||||
"memory": s.systemInfogService.MemoryInfo(),
|
||||
"network": s.systemInfogService.NetworkInfo(),
|
||||
"time": s.systemInfogService.TimeInfo(),
|
||||
"system": s.systemInfogService.SystemInfo(),
|
||||
"disk": s.systemInfogService.DiskInfo(),
|
||||
"cpu": s.systemInfoService.CPUInfo(),
|
||||
"memory": s.systemInfoService.MemoryInfo(),
|
||||
"network": s.systemInfoService.NetworkInfo(),
|
||||
"time": s.systemInfoService.TimeInfo(),
|
||||
"system": s.systemInfoService.SystemInfo(),
|
||||
"disk": s.systemInfoService.DiskInfo(),
|
||||
}
|
||||
c.JSON(200, result.OkData(data))
|
||||
c.JSON(200, resp.OkData(data))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user