2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-07 07:03:12 +08:00

refactor: 重构 tools.Exec 函数

This commit is contained in:
耗子
2023-11-14 01:54:26 +08:00
parent 1c5b32a7a9
commit 2b1b58ea2b
39 changed files with 1843 additions and 1332 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/goravel/framework/facades"
"github.com/goravel/framework/support/carbon"
"github.com/spf13/cast"
"panel/app/models"
"panel/app/services"
)
@@ -26,7 +27,10 @@ func (r *MonitorController) Switch(ctx http.Context) http.Response {
value := ctx.Request().InputBool("monitor")
err := r.setting.Set(models.SettingKeyMonitor, cast.ToString(value))
if err != nil {
facades.Log().Info("[面板][MonitorController] 更新监控开关失败 ", err)
facades.Log().Request(ctx.Request()).Tags("面板", "资源监控").With(map[string]any{
"monitor": value,
"error": err.Error(),
}).Info("更新监控开关失败")
return ErrorSystem(ctx)
}
@@ -38,7 +42,10 @@ func (r *MonitorController) SaveDays(ctx http.Context) http.Response {
days := ctx.Request().Input("days")
err := r.setting.Set(models.SettingKeyMonitorDays, days)
if err != nil {
facades.Log().Info("[面板][MonitorController] 更新监控天数失败 ", err)
facades.Log().Request(ctx.Request()).Tags("面板", "资源监控").With(map[string]any{
"days": days,
"error": err.Error(),
}).Info("更新监控开关失败")
return ErrorSystem(ctx)
}
@@ -60,7 +67,9 @@ func (r *MonitorController) SwitchAndDays(ctx http.Context) http.Response {
func (r *MonitorController) Clear(ctx http.Context) http.Response {
_, err := facades.Orm().Query().Where("1 = 1").Delete(&models.Monitor{})
if err != nil {
facades.Log().Info("[面板][MonitorController] 清空监控数据失败 ", err)
facades.Log().Request(ctx.Request()).Tags("面板", "资源监控").With(map[string]any{
"error": err.Error(),
}).Info("清空监控数据失败")
return ErrorSystem(ctx)
}
@@ -77,7 +86,11 @@ func (r *MonitorController) List(ctx http.Context) http.Response {
var monitors []models.Monitor
err := facades.Orm().Query().Where("created_at >= ?", startTime.ToDateTimeString()).Where("created_at <= ?", endTime.ToDateTimeString()).Get(&monitors)
if err != nil {
facades.Log().Info("[面板][MonitorController] 查询监控数据失败 ", err)
facades.Log().Request(ctx.Request()).Tags("面板", "资源监控").With(map[string]any{
"start": startTime.ToDateTimeString(),
"end": endTime.ToDateTimeString(),
"error": err.Error(),
}).Info("获取监控数据失败")
return ErrorSystem(ctx)
}