fix: 用户登录记录模块完成

main
NoahLan 1 year ago
parent 4e070c8156
commit e7af733d58

@ -2,6 +2,9 @@ package login_record
import ( import (
"context" "context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/loginrecord"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/user"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -21,7 +24,11 @@ func NewGetRecordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetReco
// Login Record management // Login Record management
func (l *GetRecordLogic) GetRecord(in *core.RecordReq) (*core.LoginRecordInfo, error) { func (l *GetRecordLogic) GetRecord(in *core.RecordReq) (*core.LoginRecordInfo, error) {
// todo: add your logic here and delete this line dbData, err := l.svcCtx.DB.LoginRecord.Query().
Where(loginrecord.HasUserWith(user.IDEQ(in.UserId))).
return &core.LoginRecordInfo{}, nil First(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
return l.svcCtx.Convert.ConvertLoginRecordRpc(l.ctx, dbData), nil
} }

@ -2,6 +2,13 @@ package login_record
import ( import (
"context" "context"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/ent/loginrecord"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/utils/hander"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/code"
"git.noahlan.cn/noahlan/ntool-biz/core/nstatus/msg"
"git.noahlan.cn/noahlan/ntool/ntime"
"time"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/internal/svc"
"git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core" "git.noahlan.cn/n-admin/n-admin-server/rpc/core/types/core"
@ -20,7 +27,29 @@ func NewRecordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RecordLogi
} }
func (l *RecordLogic) Record(in *core.LoginRecordInfo) (*core.BaseResp, error) { func (l *RecordLogic) Record(in *core.LoginRecordInfo) (*core.BaseResp, error) {
// todo: add your logic here and delete this line err := l.svcCtx.DB.LoginRecord.Create().
SetUserID(in.UserId).
return &core.BaseResp{}, nil SetLastLoginAt(ntime.MustParseTimeD(in.LastLoginAt, time.Now(), time.DateTime)).
SetLastLoginIpv4(in.LastLoginIpv4).
SetLastLoginDevice(in.LastLoginDevice).
SetLastLoginUA(in.LastLoginUa).
// upsert
OnConflictColumns(loginrecord.UserColumn).
Update(func(upsert *ent.LoginRecordUpsert) {
upsert.UpdateLastLoginAt().
UpdateLastLoginIpv4().
UpdateLastLoginDevice().
UpdateLastLoginUA().
SetUpdatedAt(time.Now()).
AddLoginCount(1).
AddVersion(1)
}).
Exec(l.ctx)
if err != nil {
return nil, hander.HandleEntErr(err, in)
}
return &core.BaseResp{
Code: code.StatusOK,
Msg: msg.Success,
}, nil
} }

Loading…
Cancel
Save