feat(traffic): add traffic statistics logging and scheduling

This commit is contained in:
Chang lue Tsen
2025-08-21 14:11:03 -04:00
parent 6b1b365734
commit d33f4cd1ce
11 changed files with 363 additions and 13 deletions
@@ -6,6 +6,7 @@ import (
"time"
"github.com/perfect-panel/server/internal/config"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
"github.com/perfect-panel/server/pkg/constant"
@@ -100,6 +101,29 @@ func (l *TelephoneResetPasswordLogic) TelephoneResetPassword(req *types.Telephon
if err = l.svcCtx.Redis.Set(l.ctx, sessionIdCacheKey, userInfo.Id, time.Duration(l.svcCtx.Config.JwtAuth.AccessExpire)*time.Second).Err(); err != nil {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.ERROR), "set session id error: %v", err.Error())
}
defer func() {
if token != "" && userInfo.Id != 0 {
loginLog := log.Login{
LoginIP: req.IP,
UserAgent: req.UserAgent,
Success: token != "",
}
content, _ := loginLog.Marshal()
if err = l.svcCtx.LogModel.Insert(l.ctx, &log.SystemLog{
Id: 0,
Type: log.TypeLogin.Uint8(),
Date: time.Now().Format("2006-01-02"),
ObjectID: userInfo.Id,
Content: string(content),
}); err != nil {
l.Errorw("failed to insert login log",
logger.Field("user_id", userInfo.Id),
logger.Field("ip", req.IP),
logger.Field("error", err.Error()),
)
}
}
}()
return &types.LoginResponse{
Token: token,
}, nil