feat: 合并Gin_Vue
This commit is contained in:
149
src/modules/monitor/controller/sys_cache.go
Normal file
149
src/modules/monitor/controller/sys_cache.go
Normal file
@@ -0,0 +1,149 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"ems.agt/src/framework/constants/cachekey"
|
||||
"ems.agt/src/framework/redis"
|
||||
"ems.agt/src/framework/vo/result"
|
||||
"ems.agt/src/modules/monitor/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 实例化控制层 SysCacheController 结构体
|
||||
var NewSysCache = &SysCacheController{}
|
||||
|
||||
// 缓存监控信息
|
||||
//
|
||||
// PATH /monitor/cache
|
||||
type SysCacheController struct{}
|
||||
|
||||
// Redis信息
|
||||
//
|
||||
// GET /
|
||||
func (s *SysCacheController) Info(c *gin.Context) {
|
||||
c.JSON(200, result.OkData(map[string]any{
|
||||
"info": redis.Info(""),
|
||||
"dbSize": redis.KeySize(""),
|
||||
"commandStats": redis.CommandStats(""),
|
||||
}))
|
||||
}
|
||||
|
||||
// 缓存名称列表
|
||||
//
|
||||
// GET /getNames
|
||||
func (s *SysCacheController) Names(c *gin.Context) {
|
||||
caches := []model.SysCache{
|
||||
model.NewSysCacheNames("用户信息", cachekey.LOGIN_TOKEN_KEY),
|
||||
model.NewSysCacheNames("配置信息", cachekey.SYS_CONFIG_KEY),
|
||||
model.NewSysCacheNames("数据字典", cachekey.SYS_DICT_KEY),
|
||||
model.NewSysCacheNames("验证码", cachekey.CAPTCHA_CODE_KEY),
|
||||
model.NewSysCacheNames("防重提交", cachekey.REPEAT_SUBMIT_KEY),
|
||||
model.NewSysCacheNames("限流处理", cachekey.RATE_LIMIT_KEY),
|
||||
model.NewSysCacheNames("密码错误次数", cachekey.PWD_ERR_CNT_KEY),
|
||||
}
|
||||
c.JSON(200, result.OkData(caches))
|
||||
}
|
||||
|
||||
// 缓存名称下键名列表
|
||||
//
|
||||
// GET /getKeys/:cacheName
|
||||
func (s *SysCacheController) Keys(c *gin.Context) {
|
||||
cacheName := c.Param("cacheName")
|
||||
if cacheName == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
caches := []model.SysCache{}
|
||||
|
||||
// 遍历组装
|
||||
cacheKeys, _ := redis.GetKeys("", cacheName+":*")
|
||||
for _, key := range cacheKeys {
|
||||
caches = append(caches, model.NewSysCacheKeys(cacheName, key))
|
||||
}
|
||||
|
||||
c.JSON(200, result.OkData(caches))
|
||||
}
|
||||
|
||||
// 缓存内容
|
||||
//
|
||||
// GET /getValue/:cacheName/:cacheKey
|
||||
func (s *SysCacheController) Value(c *gin.Context) {
|
||||
cacheName := c.Param("cacheName")
|
||||
cacheKey := c.Param("cacheKey")
|
||||
if cacheName == "" || cacheKey == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
|
||||
cacheValue, err := redis.Get("", cacheName+":"+cacheKey)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
sysCache := model.NewSysCacheValue(cacheName, cacheKey, cacheValue)
|
||||
c.JSON(200, result.OkData(sysCache))
|
||||
}
|
||||
|
||||
// 删除缓存名称下键名列表
|
||||
//
|
||||
// DELETE /clearCacheName/:cacheName
|
||||
func (s *SysCacheController) ClearCacheName(c *gin.Context) {
|
||||
cacheName := c.Param("cacheName")
|
||||
if cacheName == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
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) {
|
||||
cacheName := c.Param("cacheName")
|
||||
cacheKey := c.Param("cacheKey")
|
||||
if cacheName == "" || cacheKey == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
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) {
|
||||
caches := []model.SysCache{
|
||||
model.NewSysCacheNames("配置信息", cachekey.SYS_CONFIG_KEY),
|
||||
model.NewSysCacheNames("数据字典", cachekey.SYS_DICT_KEY),
|
||||
model.NewSysCacheNames("验证码", cachekey.CAPTCHA_CODE_KEY),
|
||||
model.NewSysCacheNames("防重提交", cachekey.REPEAT_SUBMIT_KEY),
|
||||
model.NewSysCacheNames("限流处理", cachekey.RATE_LIMIT_KEY),
|
||||
model.NewSysCacheNames("密码错误次数", cachekey.PWD_ERR_CNT_KEY),
|
||||
}
|
||||
for _, v := range caches {
|
||||
cacheKeys, err := redis.GetKeys("", v.CacheName+":*")
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
redis.DelKeys("", cacheKeys)
|
||||
}
|
||||
c.JSON(200, result.Ok(nil))
|
||||
}
|
||||
338
src/modules/monitor/controller/sys_job.go
Normal file
338
src/modules/monitor/controller/sys_job.go
Normal file
@@ -0,0 +1,338 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ems.agt/src/framework/utils/ctx"
|
||||
"ems.agt/src/framework/utils/file"
|
||||
"ems.agt/src/framework/utils/parse"
|
||||
"ems.agt/src/framework/vo/result"
|
||||
"ems.agt/src/modules/monitor/model"
|
||||
"ems.agt/src/modules/monitor/service"
|
||||
systemService "ems.agt/src/modules/system/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/gin-gonic/gin/binding"
|
||||
)
|
||||
|
||||
// 实例化控制层 SysJobLogController 结构体
|
||||
var NewSysJob = &SysJobController{
|
||||
sysJobService: service.NewSysJobImpl,
|
||||
sysDictDataService: systemService.NewSysDictDataImpl,
|
||||
}
|
||||
|
||||
// 调度任务信息
|
||||
//
|
||||
// PATH /monitor/job
|
||||
type SysJobController struct {
|
||||
// 调度任务服务
|
||||
sysJobService service.ISysJob
|
||||
// 字典数据服务
|
||||
sysDictDataService systemService.ISysDictData
|
||||
}
|
||||
|
||||
// 调度任务列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *SysJobController) List(c *gin.Context) {
|
||||
querys := ctx.QueryMap(c)
|
||||
data := s.sysJobService.SelectJobPage(querys)
|
||||
c.JSON(200, result.Ok(data))
|
||||
}
|
||||
|
||||
// 调度任务信息
|
||||
//
|
||||
// GET /:jobId
|
||||
func (s *SysJobController) Info(c *gin.Context) {
|
||||
jobId := c.Param("jobId")
|
||||
if jobId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
|
||||
data := s.sysJobService.SelectJobById(jobId)
|
||||
if data.JobID == jobId {
|
||||
c.JSON(200, result.OkData(data))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务新增
|
||||
//
|
||||
// POST /
|
||||
func (s *SysJobController) Add(c *gin.Context) {
|
||||
var body model.SysJob
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.JobID != "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查cron表达式格式
|
||||
if parse.CronExpression(body.CronExpression) == 0 {
|
||||
msg := fmt.Sprintf("调度任务新增【%s】失败,Cron表达式不正确", body.JobName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查任务调用传入参数是否json格式
|
||||
if body.TargetParams != "" {
|
||||
msg := fmt.Sprintf("调度任务新增【%s】失败,任务传入参数json字符串不正确", body.JobName)
|
||||
if len(body.TargetParams) < 7 {
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
if !json.Valid([]byte(body.TargetParams)) {
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueJob := s.sysJobService.CheckUniqueJobName(body.JobName, body.JobGroup, "")
|
||||
if !uniqueJob {
|
||||
msg := fmt.Sprintf("调度任务新增【%s】失败,同任务组内有相同任务名称", body.JobName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
body.CreateBy = ctx.LoginUserToUserName(c)
|
||||
insertId := s.sysJobService.InsertJob(body)
|
||||
if insertId != "" {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务修改
|
||||
//
|
||||
// PUT /
|
||||
func (s *SysJobController) Edit(c *gin.Context) {
|
||||
var body model.SysJob
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil || body.JobID == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查cron表达式格式
|
||||
if parse.CronExpression(body.CronExpression) == 0 {
|
||||
msg := fmt.Sprintf("调度任务修改【%s】失败,Cron表达式不正确", body.JobName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查任务调用传入参数是否json格式
|
||||
if body.TargetParams != "" {
|
||||
msg := fmt.Sprintf("调度任务修改【%s】失败,任务传入参数json字符串不正确", body.JobName)
|
||||
if len(body.TargetParams) < 7 {
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
if !json.Valid([]byte(body.TargetParams)) {
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// 检查属性值唯一
|
||||
uniqueJob := s.sysJobService.CheckUniqueJobName(body.JobName, body.JobGroup, body.JobID)
|
||||
if !uniqueJob {
|
||||
msg := fmt.Sprintf("调度任务修改【%s】失败,同任务组内有相同任务名称", body.JobName)
|
||||
c.JSON(200, result.ErrMsg(msg))
|
||||
return
|
||||
}
|
||||
|
||||
body.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
rows := s.sysJobService.UpdateJob(body)
|
||||
if rows > 0 {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务删除
|
||||
//
|
||||
// DELETE /:jobIds
|
||||
func (s *SysJobController) Remove(c *gin.Context) {
|
||||
jobIds := c.Param("jobIds")
|
||||
if jobIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(jobIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows, err := s.sysJobService.DeleteJobByIds(uniqueIDs)
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
msg := fmt.Sprintf("删除成功:%d", rows)
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
}
|
||||
|
||||
// 调度任务修改状态
|
||||
//
|
||||
// PUT /changeStatus
|
||||
func (s *SysJobController) Status(c *gin.Context) {
|
||||
var body struct {
|
||||
// 任务ID
|
||||
JobId string `json:"jobId" binding:"required"`
|
||||
// 状态
|
||||
Status string `json:"status" binding:"required"`
|
||||
}
|
||||
err := c.ShouldBindBodyWith(&body, binding.JSON)
|
||||
if err != nil {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
job := s.sysJobService.SelectJobById(body.JobId)
|
||||
if job.JobID != body.JobId {
|
||||
c.JSON(200, result.ErrMsg("没有权限访问调度任务数据!"))
|
||||
return
|
||||
}
|
||||
|
||||
// 与旧值相等不变更
|
||||
if job.Status == body.Status {
|
||||
c.JSON(200, result.ErrMsg("变更状态与旧值相等!"))
|
||||
return
|
||||
}
|
||||
|
||||
// 更新状态
|
||||
job.Status = body.Status
|
||||
job.UpdateBy = ctx.LoginUserToUserName(c)
|
||||
ok := s.sysJobService.ChangeStatus(job)
|
||||
if ok {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务立即执行一次
|
||||
//
|
||||
// PUT /run/:jobId
|
||||
func (s *SysJobController) Run(c *gin.Context) {
|
||||
jobId := c.Param("jobId")
|
||||
if jobId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
|
||||
// 检查是否存在
|
||||
job := s.sysJobService.SelectJobById(jobId)
|
||||
if job.JobID != jobId {
|
||||
c.JSON(200, result.ErrMsg("没有权限访问调度任务数据!"))
|
||||
return
|
||||
}
|
||||
|
||||
ok := s.sysJobService.RunQueueJob(job)
|
||||
if ok {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务重置刷新队列
|
||||
//
|
||||
// PUT /resetQueueJob
|
||||
func (s *SysJobController) ResetQueueJob(c *gin.Context) {
|
||||
s.sysJobService.ResetQueueJob()
|
||||
c.JSON(200, result.Ok(nil))
|
||||
}
|
||||
|
||||
// 导出调度任务信息
|
||||
//
|
||||
// POST /export
|
||||
func (s *SysJobController) Export(c *gin.Context) {
|
||||
// 查询结果,根据查询条件结果,单页最大值限制
|
||||
querys := ctx.BodyJSONMap(c)
|
||||
data := s.sysJobService.SelectJobPage(querys)
|
||||
if data["total"].(int64) == 0 {
|
||||
c.JSON(200, result.ErrMsg("导出数据记录为空"))
|
||||
return
|
||||
}
|
||||
rows := data["rows"].([]model.SysJob)
|
||||
|
||||
// 导出文件名称
|
||||
fileName := fmt.Sprintf("job_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
|
||||
// 第一行表头标题
|
||||
headerCells := map[string]string{
|
||||
"A1": "任务编号",
|
||||
"B1": "任务名称",
|
||||
"C1": "任务组名",
|
||||
"D1": "调用目标",
|
||||
"E1": "传入参数",
|
||||
"F1": "执行表达式",
|
||||
"G1": "出错策略",
|
||||
"H1": "并发执行",
|
||||
"I1": "任务状态",
|
||||
"J1": "备注说明",
|
||||
}
|
||||
// 读取任务组名字典数据
|
||||
dictSysJobGroup := s.sysDictDataService.SelectDictDataByType("sys_job_group")
|
||||
// 从第二行开始的数据
|
||||
dataCells := make([]map[string]any, 0)
|
||||
for i, row := range rows {
|
||||
idx := strconv.Itoa(i + 2)
|
||||
// 任务组名
|
||||
sysJobGroup := ""
|
||||
for _, v := range dictSysJobGroup {
|
||||
if row.JobGroup == v.DictValue {
|
||||
sysJobGroup = v.DictLabel
|
||||
break
|
||||
}
|
||||
}
|
||||
misfirePolicy := "放弃执行"
|
||||
if row.MisfirePolicy == "1" {
|
||||
misfirePolicy = "立即执行"
|
||||
} else if row.MisfirePolicy == "2" {
|
||||
misfirePolicy = "执行一次"
|
||||
}
|
||||
concurrent := "禁止"
|
||||
if row.Concurrent == "1" {
|
||||
concurrent = "允许"
|
||||
}
|
||||
// 状态
|
||||
statusValue := "失败"
|
||||
if row.Status == "1" {
|
||||
statusValue = "成功"
|
||||
}
|
||||
dataCells = append(dataCells, map[string]any{
|
||||
"A" + idx: row.JobID,
|
||||
"B" + idx: row.JobName,
|
||||
"C" + idx: sysJobGroup,
|
||||
"D" + idx: row.InvokeTarget,
|
||||
"E" + idx: row.TargetParams,
|
||||
"F" + idx: row.CronExpression,
|
||||
"G" + idx: misfirePolicy,
|
||||
"H" + idx: concurrent,
|
||||
"I" + idx: statusValue,
|
||||
"J" + idx: row.Remark,
|
||||
})
|
||||
}
|
||||
|
||||
// 导出数据表格
|
||||
saveFilePath, err := file.WriteSheet(headerCells, dataCells, fileName, "")
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.FileAttachment(saveFilePath, fileName)
|
||||
}
|
||||
167
src/modules/monitor/controller/sys_job_log.go
Normal file
167
src/modules/monitor/controller/sys_job_log.go
Normal file
@@ -0,0 +1,167 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"ems.agt/src/framework/utils/ctx"
|
||||
"ems.agt/src/framework/utils/date"
|
||||
"ems.agt/src/framework/utils/file"
|
||||
"ems.agt/src/framework/utils/parse"
|
||||
"ems.agt/src/framework/vo/result"
|
||||
"ems.agt/src/modules/monitor/model"
|
||||
"ems.agt/src/modules/monitor/service"
|
||||
systemService "ems.agt/src/modules/system/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 实例化控制层 SysJobLogController 结构体
|
||||
var NewSysJobLog = &SysJobLogController{
|
||||
sysJobLogService: service.NewSysJobLogImpl,
|
||||
sysDictDataService: systemService.NewSysDictDataImpl,
|
||||
}
|
||||
|
||||
// 调度任务日志信息
|
||||
//
|
||||
// PATH /monitor/jobLog
|
||||
type SysJobLogController struct {
|
||||
// 调度任务日志服务
|
||||
sysJobLogService service.ISysJobLog
|
||||
// 字典数据服务
|
||||
sysDictDataService systemService.ISysDictData
|
||||
}
|
||||
|
||||
// 调度任务日志列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *SysJobLogController) List(c *gin.Context) {
|
||||
// 查询参数转换map
|
||||
querys := ctx.QueryMap(c)
|
||||
list := s.sysJobLogService.SelectJobLogPage(querys)
|
||||
c.JSON(200, result.Ok(list))
|
||||
}
|
||||
|
||||
// 调度任务日志信息
|
||||
//
|
||||
// GET /:jobLogId
|
||||
func (s *SysJobLogController) Info(c *gin.Context) {
|
||||
jobLogId := c.Param("jobLogId")
|
||||
if jobLogId == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
data := s.sysJobLogService.SelectJobLogById(jobLogId)
|
||||
if data.JobLogID == jobLogId {
|
||||
c.JSON(200, result.OkData(data))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
|
||||
// 调度任务日志删除
|
||||
//
|
||||
// DELETE /:jobLogIds
|
||||
func (s *SysJobLogController) Remove(c *gin.Context) {
|
||||
jobLogIds := c.Param("jobLogIds")
|
||||
if jobLogIds == "" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
|
||||
// 处理字符转id数组后去重
|
||||
ids := strings.Split(jobLogIds, ",")
|
||||
uniqueIDs := parse.RemoveDuplicates(ids)
|
||||
if len(uniqueIDs) <= 0 {
|
||||
c.JSON(200, result.Err(nil))
|
||||
return
|
||||
}
|
||||
rows := s.sysJobLogService.DeleteJobLogByIds(uniqueIDs)
|
||||
if rows > 0 {
|
||||
msg := fmt.Sprintf("删除成功:%d", rows)
|
||||
c.JSON(200, result.OkMsg(msg))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.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))
|
||||
}
|
||||
|
||||
// 导出调度任务日志信息
|
||||
//
|
||||
// POST /export
|
||||
func (s *SysJobLogController) Export(c *gin.Context) {
|
||||
// 查询结果,根据查询条件结果,单页最大值限制
|
||||
querys := ctx.BodyJSONMap(c)
|
||||
data := s.sysJobLogService.SelectJobLogPage(querys)
|
||||
if data["total"].(int64) == 0 {
|
||||
c.JSON(200, result.ErrMsg("导出数据记录为空"))
|
||||
return
|
||||
}
|
||||
rows := data["rows"].([]model.SysJobLog)
|
||||
|
||||
// 导出文件名称
|
||||
fileName := fmt.Sprintf("jobLog_export_%d_%d.xlsx", len(rows), time.Now().UnixMilli())
|
||||
// 第一行表头标题
|
||||
headerCells := map[string]string{
|
||||
"A1": "日志序号",
|
||||
"B1": "任务名称",
|
||||
"C1": "任务组名",
|
||||
"D1": "调用目标",
|
||||
"E1": "传入参数",
|
||||
"F1": "日志信息",
|
||||
"G1": "执行状态",
|
||||
"H1": "记录时间",
|
||||
}
|
||||
// 读取任务组名字典数据
|
||||
dictSysJobGroup := s.sysDictDataService.SelectDictDataByType("sys_job_group")
|
||||
// 从第二行开始的数据
|
||||
dataCells := make([]map[string]any, 0)
|
||||
for i, row := range rows {
|
||||
idx := strconv.Itoa(i + 2)
|
||||
// 任务组名
|
||||
sysJobGroup := ""
|
||||
for _, v := range dictSysJobGroup {
|
||||
if row.JobGroup == v.DictValue {
|
||||
sysJobGroup = v.DictLabel
|
||||
break
|
||||
}
|
||||
}
|
||||
// 状态
|
||||
statusValue := "失败"
|
||||
if row.Status == "1" {
|
||||
statusValue = "成功"
|
||||
}
|
||||
dataCells = append(dataCells, map[string]any{
|
||||
"A" + idx: row.JobLogID,
|
||||
"B" + idx: row.JobName,
|
||||
"C" + idx: sysJobGroup,
|
||||
"D" + idx: row.InvokeTarget,
|
||||
"E" + idx: row.TargetParams,
|
||||
"F" + idx: row.JobMsg,
|
||||
"G" + idx: statusValue,
|
||||
"H" + idx: date.ParseDateToStr(row.CreateTime, date.YYYY_MM_DD_HH_MM_SS),
|
||||
})
|
||||
}
|
||||
|
||||
// 导出数据表格
|
||||
saveFilePath, err := file.WriteSheet(headerCells, dataCells, fileName, "")
|
||||
if err != nil {
|
||||
c.JSON(200, result.ErrMsg(err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
c.FileAttachment(saveFilePath, fileName)
|
||||
}
|
||||
126
src/modules/monitor/controller/sys_user_online.go
Normal file
126
src/modules/monitor/controller/sys_user_online.go
Normal file
@@ -0,0 +1,126 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"ems.agt/src/framework/constants/cachekey"
|
||||
"ems.agt/src/framework/redis"
|
||||
"ems.agt/src/framework/vo"
|
||||
"ems.agt/src/framework/vo/result"
|
||||
"ems.agt/src/modules/monitor/model"
|
||||
"ems.agt/src/modules/monitor/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 实例化控制层 SysUserOnlineController 结构体
|
||||
var NewSysUserOnline = &SysUserOnlineController{
|
||||
sysUserOnlineService: service.NewSysUserOnlineImpl,
|
||||
}
|
||||
|
||||
// 在线用户监控
|
||||
//
|
||||
// PATH /monitor/online
|
||||
type SysUserOnlineController struct {
|
||||
// 在线用户服务
|
||||
sysUserOnlineService service.ISysUserOnline
|
||||
}
|
||||
|
||||
// 在线用户列表
|
||||
//
|
||||
// GET /list
|
||||
func (s *SysUserOnlineController) List(c *gin.Context) {
|
||||
ipaddr := c.Query("ipaddr")
|
||||
userName := c.Query("userName")
|
||||
|
||||
// 获取所有在线用户key
|
||||
keys, _ := redis.GetKeys("", cachekey.LOGIN_TOKEN_KEY+"*")
|
||||
|
||||
// 分批获取
|
||||
arr := make([]string, 0)
|
||||
for i := 0; i < len(keys); i += 20 {
|
||||
end := i + 20
|
||||
if end > len(keys) {
|
||||
end = len(keys)
|
||||
}
|
||||
chunk := keys[i:end]
|
||||
values, _ := redis.GetBatch("", chunk)
|
||||
for _, v := range values {
|
||||
arr = append(arr, v.(string))
|
||||
}
|
||||
}
|
||||
|
||||
// 遍历字符串信息解析组合可用对象
|
||||
userOnlines := make([]model.SysUserOnline, 0)
|
||||
for _, str := range arr {
|
||||
if str == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
var loginUser vo.LoginUser
|
||||
err := json.Unmarshal([]byte(str), &loginUser)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
onlineUser := s.sysUserOnlineService.LoginUserToUserOnline(loginUser)
|
||||
if onlineUser.TokenID != "" {
|
||||
userOnlines = append(userOnlines, onlineUser)
|
||||
}
|
||||
}
|
||||
|
||||
// 根据查询条件过滤
|
||||
filteredUserOnlines := make([]model.SysUserOnline, 0)
|
||||
if ipaddr != "" && userName != "" {
|
||||
for _, o := range userOnlines {
|
||||
if strings.Contains(o.IPAddr, ipaddr) && strings.Contains(o.UserName, userName) {
|
||||
filteredUserOnlines = append(filteredUserOnlines, o)
|
||||
}
|
||||
}
|
||||
} else if ipaddr != "" {
|
||||
for _, o := range userOnlines {
|
||||
if strings.Contains(o.IPAddr, ipaddr) {
|
||||
filteredUserOnlines = append(filteredUserOnlines, o)
|
||||
}
|
||||
}
|
||||
} else if userName != "" {
|
||||
for _, o := range userOnlines {
|
||||
if strings.Contains(o.UserName, userName) {
|
||||
filteredUserOnlines = append(filteredUserOnlines, o)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filteredUserOnlines = userOnlines
|
||||
}
|
||||
|
||||
// 按登录时间排序
|
||||
sort.Slice(filteredUserOnlines, func(i, j int) bool {
|
||||
return filteredUserOnlines[j].LoginTime > filteredUserOnlines[i].LoginTime
|
||||
})
|
||||
|
||||
c.JSON(200, result.Ok(map[string]any{
|
||||
"total": len(filteredUserOnlines),
|
||||
"rows": filteredUserOnlines,
|
||||
}))
|
||||
}
|
||||
|
||||
// 在线用户强制退出
|
||||
//
|
||||
// DELETE /:tokenId
|
||||
func (s *SysUserOnlineController) ForceLogout(c *gin.Context) {
|
||||
tokenId := c.Param("tokenId")
|
||||
if tokenId == "" || tokenId == "*" {
|
||||
c.JSON(400, result.CodeMsg(400, "参数错误"))
|
||||
return
|
||||
}
|
||||
|
||||
// 删除token
|
||||
ok, _ := redis.Del("", cachekey.LOGIN_TOKEN_KEY+tokenId)
|
||||
if ok {
|
||||
c.JSON(200, result.Ok(nil))
|
||||
return
|
||||
}
|
||||
c.JSON(200, result.Err(nil))
|
||||
}
|
||||
36
src/modules/monitor/controller/system_info.go
Normal file
36
src/modules/monitor/controller/system_info.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"ems.agt/src/framework/vo/result"
|
||||
"ems.agt/src/modules/monitor/service"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// 实例化控制层 SystemInfoController 结构体
|
||||
var NewSystemInfo = &SystemInfoController{
|
||||
systemInfogService: service.NewSystemInfoImpl,
|
||||
}
|
||||
|
||||
// 服务器监控信息
|
||||
//
|
||||
// PATH /monitor/system-info
|
||||
type SystemInfoController struct {
|
||||
// 服务器系统相关信息服务
|
||||
systemInfogService service.ISystemInfo
|
||||
}
|
||||
|
||||
// 服务器信息
|
||||
//
|
||||
// GET /
|
||||
func (s *SystemInfoController) Info(c *gin.Context) {
|
||||
c.JSON(200, result.OkData(map[string]any{
|
||||
"project": s.systemInfogService.ProjectInfo(),
|
||||
"cpu": s.systemInfogService.CPUInfo(),
|
||||
"memory": s.systemInfogService.MemoryInfo(),
|
||||
"network": s.systemInfogService.NetworkInfo(),
|
||||
"time": s.systemInfogService.TimeInfo(),
|
||||
"system": s.systemInfogService.SystemInfo(),
|
||||
"disk": s.systemInfogService.DiskInfo(),
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user