From e7af733d586a8f3f28de4d5c96741571139849c6 Mon Sep 17 00:00:00 2001 From: NoahLan <6995syu@163.com> Date: Sun, 3 Sep 2023 20:44:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=94=A8=E6=88=B7=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=A8=A1=E5=9D=97=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/login_record/get_record_logic.go | 13 +++++-- .../logic/login_record/record_logic.go | 35 +++++++++++++++++-- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/rpc/core/internal/logic/login_record/get_record_logic.go b/rpc/core/internal/logic/login_record/get_record_logic.go index 28e2391..d6e0373 100644 --- a/rpc/core/internal/logic/login_record/get_record_logic.go +++ b/rpc/core/internal/logic/login_record/get_record_logic.go @@ -2,6 +2,9 @@ package login_record import ( "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/types/core" @@ -21,7 +24,11 @@ func NewGetRecordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetReco // Login Record management func (l *GetRecordLogic) GetRecord(in *core.RecordReq) (*core.LoginRecordInfo, error) { - // todo: add your logic here and delete this line - - return &core.LoginRecordInfo{}, nil + dbData, err := l.svcCtx.DB.LoginRecord.Query(). + Where(loginrecord.HasUserWith(user.IDEQ(in.UserId))). + First(l.ctx) + if err != nil { + return nil, hander.HandleEntErr(err, in) + } + return l.svcCtx.Convert.ConvertLoginRecordRpc(l.ctx, dbData), nil } diff --git a/rpc/core/internal/logic/login_record/record_logic.go b/rpc/core/internal/logic/login_record/record_logic.go index ca5fca3..70909b7 100644 --- a/rpc/core/internal/logic/login_record/record_logic.go +++ b/rpc/core/internal/logic/login_record/record_logic.go @@ -2,6 +2,13 @@ package login_record import ( "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/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) { - // todo: add your logic here and delete this line - - return &core.BaseResp{}, nil + err := l.svcCtx.DB.LoginRecord.Create(). + SetUserID(in.UserId). + 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 }