refactor(log): consolidate logging models and update related logic for improved clarity and functionality

This commit is contained in:
Chang lue Tsen
2025-08-20 13:36:06 -04:00
parent 4f32d67113
commit 87c771bbd4
41 changed files with 1082 additions and 707 deletions
+16 -4
View File
@@ -9,6 +9,7 @@ import (
"github.com/perfect-panel/server/internal/config"
"github.com/perfect-panel/server/internal/logic/common"
"github.com/perfect-panel/server/internal/model/log"
"github.com/perfect-panel/server/internal/model/user"
"github.com/perfect-panel/server/internal/svc"
"github.com/perfect-panel/server/internal/types"
@@ -51,13 +52,24 @@ func (l *TelephoneLoginLogic) TelephoneLogin(req *types.TelephoneLoginRequest, r
// Record login status
defer func(svcCtx *svc.ServiceContext) {
if userInfo.Id != 0 {
if err := svcCtx.UserModel.InsertLoginLog(l.ctx, &user.LoginLog{
UserId: userInfo.Id,
loginLog := log.Login{
LoginIP: ip,
UserAgent: r.UserAgent(),
Success: &loginStatus,
Success: loginStatus,
}
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.Logger.Error("[UserLogin] insert login log error", logger.Field("error", err.Error()))
l.Errorw("failed to insert login log",
logger.Field("user_id", userInfo.Id),
logger.Field("ip", req.IP),
logger.Field("error", err.Error()),
)
}
}
}(l.svcCtx)