u
This commit is contained in:
1 parent
4dcac7b5a0
commit
59d3be2299
25 files changed
+380
-125
No files matched your search
@@ -44,8 +44,8 @@ func LoginDefault(ctx context.Context, c *app.RequestContext) {
|
||||
|
||||
// 异步更新登录事件
|
||||
go func(userID int64) {
|
||||
time, err := db.Queries.UpdateUserLoginLastTime(ctx, userID)
|
||||
if err != nil || time == 0 {
|
||||
err = db.Queries.UpdateUserLoginLastTime(ctx, userID)
|
||||
if err != nil {
|
||||
logx.CtxError(ctx, "更新用户登录时间失败,UserID=%d, err=%v", loginUser.ID, err)
|
||||
}
|
||||
}(loginUser.ID)
|
||||
|
||||
@@ -6,8 +6,10 @@ import (
|
||||
auth "cn/oneao/base-go/biz/model/auth"
|
||||
"cn/oneao/base-go/db"
|
||||
"cn/oneao/base-go/db/repo"
|
||||
"cn/oneao/base-go/utils"
|
||||
"cn/oneao/base-go/utils/errorx"
|
||||
"cn/oneao/base-go/utils/idgen"
|
||||
"cn/oneao/base-go/utils/pgtypex"
|
||||
"cn/oneao/base-go/utils/response"
|
||||
"context"
|
||||
|
||||
@@ -64,11 +66,18 @@ func RegisterDefault(ctx context.Context, c *app.RequestContext) {
|
||||
}
|
||||
}()
|
||||
|
||||
generateCode, err := utils.GenerateCode(8)
|
||||
if err != nil {
|
||||
errorx.AddError(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
// 插入用户
|
||||
params := repo.InsertUserParams{
|
||||
ID: idgen.NextId(),
|
||||
Account: account,
|
||||
Password: password,
|
||||
Username: pgtypex.StringToText("a_" + generateCode),
|
||||
}
|
||||
|
||||
insert, err := db.Queries.WithTx(tx).InsertUser(ctx, params)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"cn/oneao/base-go/db/repo"
|
||||
"cn/oneao/base-go/utils/errorx"
|
||||
"cn/oneao/base-go/utils/idgen"
|
||||
"cn/oneao/base-go/utils/pgtypex"
|
||||
"cn/oneao/base-go/utils/response"
|
||||
"context"
|
||||
|
||||
@@ -78,9 +79,10 @@ func ListSpaceUsers(ctx context.Context, c *app.RequestContext) {
|
||||
// 填充用户列表
|
||||
for _, u := range users {
|
||||
resp.Users = append(resp.Users, &space.SpaceUser{
|
||||
UserId: u.UserID,
|
||||
Username: u.Username.String,
|
||||
SpaceRole: u.Role,
|
||||
UserId: u.UserID,
|
||||
Username: u.Username.String,
|
||||
SpaceRole: u.Role,
|
||||
ActiveTime: pgtypex.TimestampToDateTimeString(u.ActiveTime),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v6.33.1
|
||||
// protoc v4.25.3
|
||||
// source: api.proto
|
||||
|
||||
package api
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v6.33.1
|
||||
// protoc v4.25.3
|
||||
// source: space.proto
|
||||
|
||||
package space
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v6.33.1
|
||||
// protoc v4.25.3
|
||||
// source: space/space_types.proto
|
||||
|
||||
package space
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Code generated by protoc-gen-go. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go v1.28.0
|
||||
// protoc v6.33.1
|
||||
// protoc v4.25.3
|
||||
// source: space/space_user_types.proto
|
||||
|
||||
package space
|
||||
@@ -65,9 +65,10 @@ type SpaceUser struct {
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
UserId int64 `protobuf:"varint,1,opt,name=UserId,proto3" form:"user_id" json:"user_id"`
|
||||
Username string `protobuf:"bytes,2,opt,name=Username,proto3" form:"username" json:"username"`
|
||||
SpaceRole int32 `protobuf:"varint,4,opt,name=SpaceRole,proto3" form:"space_role" json:"space_role"`
|
||||
UserId int64 `protobuf:"varint,1,opt,name=UserId,proto3" form:"user_id" json:"user_id"`
|
||||
Username string `protobuf:"bytes,2,opt,name=Username,proto3" form:"username" json:"username"`
|
||||
SpaceRole int32 `protobuf:"varint,3,opt,name=SpaceRole,proto3" form:"space_role" json:"space_role"`
|
||||
ActiveTime string `protobuf:"bytes,4,opt,name=ActiveTime,proto3" form:"active_time" json:"active_time"`
|
||||
}
|
||||
|
||||
func (x *SpaceUser) Reset() {
|
||||
@@ -123,6 +124,13 @@ func (x *SpaceUser) GetSpaceRole() int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *SpaceUser) GetActiveTime() string {
|
||||
if x != nil {
|
||||
return x.ActiveTime
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type ListSpaceUsersResult struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -646,66 +654,69 @@ var file_space_space_user_types_proto_rawDesc = []byte{
|
||||
0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x05,
|
||||
0x73, 0x70, 0x61, 0x63, 0x65, 0x1a, 0x09, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x22, 0x16, 0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65,
|
||||
0x72, 0x73, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x88, 0x01, 0x0a, 0x09, 0x53, 0x70, 0x61,
|
||||
0x72, 0x73, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0xb9, 0x01, 0x0a, 0x09, 0x53, 0x70, 0x61,
|
||||
0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x12, 0x23, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0b, 0xca, 0xbb, 0x18, 0x07, 0x75, 0x73, 0x65, 0x72,
|
||||
0x5f, 0x69, 0x64, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x08, 0x55,
|
||||
0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0c, 0xca,
|
||||
0xbb, 0x18, 0x08, 0x75, 0x73, 0x65, 0x72, 0x6e, 0x61, 0x6d, 0x65, 0x52, 0x08, 0x55, 0x73, 0x65,
|
||||
0x72, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2c, 0x0a, 0x09, 0x53, 0x70, 0x61, 0x63, 0x65, 0x52, 0x6f,
|
||||
0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x42, 0x0e, 0xca, 0xbb, 0x18, 0x0a, 0x73, 0x70,
|
||||
0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x42, 0x0e, 0xca, 0xbb, 0x18, 0x0a, 0x73, 0x70,
|
||||
0x61, 0x63, 0x65, 0x5f, 0x72, 0x6f, 0x6c, 0x65, 0x52, 0x09, 0x53, 0x70, 0x61, 0x63, 0x65, 0x52,
|
||||
0x6f, 0x6c, 0x65, 0x22, 0x3e, 0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x70, 0x61, 0x63, 0x65,
|
||||
0x55, 0x73, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x26, 0x0a, 0x05, 0x75,
|
||||
0x73, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x70, 0x61,
|
||||
0x63, 0x65, 0x2e, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x05, 0x75, 0x73,
|
||||
0x65, 0x72, 0x73, 0x22, 0x4d, 0x0a, 0x0f, 0x4a, 0x6f, 0x69, 0x6e, 0x53, 0x70, 0x61, 0x63, 0x65,
|
||||
0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x3a, 0x0a, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65,
|
||||
0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x1a, 0xca, 0xbb, 0x18, 0x0b,
|
||||
0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0xda, 0xbb, 0x18, 0x07, 0x24,
|
||||
0x20, 0x21, 0x3d, 0x20, 0x27, 0x27, 0x52, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f,
|
||||
0x64, 0x65, 0x22, 0x11, 0x0a, 0x0f, 0x4a, 0x6f, 0x69, 0x6e, 0x53, 0x70, 0x61, 0x63, 0x65, 0x52,
|
||||
0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x11, 0x0a, 0x0f, 0x45, 0x78, 0x69, 0x74, 0x53, 0x70, 0x61,
|
||||
0x63, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x11, 0x0a, 0x0f, 0x45, 0x78, 0x69, 0x74,
|
||||
0x53, 0x70, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x78, 0x0a, 0x15, 0x52,
|
||||
0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x50, 0x61,
|
||||
0x72, 0x61, 0x6d, 0x73, 0x12, 0x30, 0x0a, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x18,
|
||||
0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x16, 0xca, 0xbb, 0x18, 0x08, 0x73, 0x70, 0x61, 0x63, 0x65,
|
||||
0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x06, 0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x07, 0x53,
|
||||
0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12, 0x2d, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64,
|
||||
0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x42, 0x15, 0xca, 0xbb, 0x18, 0x07, 0x75, 0x73, 0x65, 0x72,
|
||||
0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x06, 0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x06, 0x55,
|
||||
0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x17, 0x0a, 0x15, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53,
|
||||
0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0xae,
|
||||
0x01, 0x0a, 0x19, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73,
|
||||
0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x30, 0x0a, 0x07,
|
||||
0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x16, 0xca,
|
||||
0xbb, 0x18, 0x08, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x06, 0x24,
|
||||
0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12, 0x2d,
|
||||
0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x42, 0x15,
|
||||
0xca, 0xbb, 0x18, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x06, 0x24,
|
||||
0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x30, 0x0a,
|
||||
0x04, 0x52, 0x6f, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x42, 0x1c, 0xca, 0xbb, 0x18,
|
||||
0x04, 0x72, 0x6f, 0x6c, 0x65, 0xda, 0xbb, 0x18, 0x10, 0x24, 0x20, 0x3d, 0x3d, 0x20, 0x31, 0x20,
|
||||
0x7c, 0x7c, 0x20, 0x24, 0x20, 0x3d, 0x3d, 0x20, 0x32, 0x52, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x22,
|
||||
0x1b, 0x0a, 0x19, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73,
|
||||
0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x14, 0x0a, 0x12,
|
||||
0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x53, 0x70, 0x61, 0x63, 0x65, 0x50, 0x61, 0x72, 0x61,
|
||||
0x6d, 0x73, 0x22, 0xb9, 0x01, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x53, 0x70,
|
||||
0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x26, 0x0a, 0x07, 0x53, 0x70, 0x61,
|
||||
0x63, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0c, 0xca, 0xbb, 0x18, 0x08,
|
||||
0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x52, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49,
|
||||
0x64, 0x12, 0x2c, 0x0a, 0x09, 0x53, 0x70, 0x61, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x02,
|
||||
0x20, 0x01, 0x28, 0x09, 0x42, 0x0e, 0xca, 0xbb, 0x18, 0x0a, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f,
|
||||
0x6e, 0x61, 0x6d, 0x65, 0x52, 0x09, 0x53, 0x70, 0x61, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12,
|
||||
0x2f, 0x0a, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20,
|
||||
0x01, 0x28, 0x09, 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x5f,
|
||||
0x63, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65,
|
||||
0x12, 0x1c, 0x0a, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x42, 0x08,
|
||||
0xca, 0xbb, 0x18, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x52, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x42, 0x22,
|
||||
0x5a, 0x20, 0x63, 0x6e, 0x2f, 0x6f, 0x6e, 0x65, 0x61, 0x6f, 0x2f, 0x62, 0x61, 0x73, 0x65, 0x2d,
|
||||
0x67, 0x6f, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x73, 0x70, 0x61,
|
||||
0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x6f, 0x6c, 0x65, 0x12, 0x2f, 0x0a, 0x0a, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x54, 0x69, 0x6d,
|
||||
0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x61, 0x63, 0x74,
|
||||
0x69, 0x76, 0x65, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x52, 0x0a, 0x41, 0x63, 0x74, 0x69, 0x76, 0x65,
|
||||
0x54, 0x69, 0x6d, 0x65, 0x22, 0x3e, 0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, 0x53, 0x70, 0x61, 0x63,
|
||||
0x65, 0x55, 0x73, 0x65, 0x72, 0x73, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x26, 0x0a, 0x05,
|
||||
0x75, 0x73, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x73, 0x70,
|
||||
0x61, 0x63, 0x65, 0x2e, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x05, 0x75,
|
||||
0x73, 0x65, 0x72, 0x73, 0x22, 0x4d, 0x0a, 0x0f, 0x4a, 0x6f, 0x69, 0x6e, 0x53, 0x70, 0x61, 0x63,
|
||||
0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x3a, 0x0a, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74,
|
||||
0x65, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x42, 0x1a, 0xca, 0xbb, 0x18,
|
||||
0x0b, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0xda, 0xbb, 0x18, 0x07,
|
||||
0x24, 0x20, 0x21, 0x3d, 0x20, 0x27, 0x27, 0x52, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43,
|
||||
0x6f, 0x64, 0x65, 0x22, 0x11, 0x0a, 0x0f, 0x4a, 0x6f, 0x69, 0x6e, 0x53, 0x70, 0x61, 0x63, 0x65,
|
||||
0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x11, 0x0a, 0x0f, 0x45, 0x78, 0x69, 0x74, 0x53, 0x70,
|
||||
0x61, 0x63, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0x11, 0x0a, 0x0f, 0x45, 0x78, 0x69,
|
||||
0x74, 0x53, 0x70, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x78, 0x0a, 0x15,
|
||||
0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x50,
|
||||
0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x30, 0x0a, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64,
|
||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x16, 0xca, 0xbb, 0x18, 0x08, 0x73, 0x70, 0x61, 0x63,
|
||||
0x65, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x06, 0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x07,
|
||||
0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12, 0x2d, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49,
|
||||
0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x42, 0x15, 0xca, 0xbb, 0x18, 0x07, 0x75, 0x73, 0x65,
|
||||
0x72, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x06, 0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x06,
|
||||
0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x22, 0x17, 0x0a, 0x15, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65,
|
||||
0x53, 0x70, 0x61, 0x63, 0x65, 0x55, 0x73, 0x65, 0x72, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22,
|
||||
0xae, 0x01, 0x0a, 0x19, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55,
|
||||
0x73, 0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65, 0x50, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x12, 0x30, 0x0a,
|
||||
0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x16,
|
||||
0xca, 0xbb, 0x18, 0x08, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x06,
|
||||
0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65, 0x49, 0x64, 0x12,
|
||||
0x2d, 0x0a, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x42,
|
||||
0x15, 0xca, 0xbb, 0x18, 0x07, 0x75, 0x73, 0x65, 0x72, 0x5f, 0x69, 0x64, 0xda, 0xbb, 0x18, 0x06,
|
||||
0x24, 0x20, 0x21, 0x3d, 0x20, 0x30, 0x52, 0x06, 0x55, 0x73, 0x65, 0x72, 0x49, 0x64, 0x12, 0x30,
|
||||
0x0a, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x42, 0x1c, 0xca, 0xbb,
|
||||
0x18, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0xda, 0xbb, 0x18, 0x10, 0x24, 0x20, 0x3d, 0x3d, 0x20, 0x31,
|
||||
0x20, 0x7c, 0x7c, 0x20, 0x24, 0x20, 0x3d, 0x3d, 0x20, 0x32, 0x52, 0x04, 0x52, 0x6f, 0x6c, 0x65,
|
||||
0x22, 0x1b, 0x0a, 0x19, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x53, 0x70, 0x61, 0x63, 0x65, 0x55,
|
||||
0x73, 0x65, 0x72, 0x52, 0x6f, 0x6c, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x22, 0x14, 0x0a,
|
||||
0x12, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x53, 0x70, 0x61, 0x63, 0x65, 0x50, 0x61, 0x72,
|
||||
0x61, 0x6d, 0x73, 0x22, 0xb9, 0x01, 0x0a, 0x12, 0x47, 0x65, 0x74, 0x55, 0x73, 0x65, 0x72, 0x53,
|
||||
0x70, 0x61, 0x63, 0x65, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x26, 0x0a, 0x07, 0x53, 0x70,
|
||||
0x61, 0x63, 0x65, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x42, 0x0c, 0xca, 0xbb, 0x18,
|
||||
0x08, 0x73, 0x70, 0x61, 0x63, 0x65, 0x5f, 0x69, 0x64, 0x52, 0x07, 0x53, 0x70, 0x61, 0x63, 0x65,
|
||||
0x49, 0x64, 0x12, 0x2c, 0x0a, 0x09, 0x53, 0x70, 0x61, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18,
|
||||
0x02, 0x20, 0x01, 0x28, 0x09, 0x42, 0x0e, 0xca, 0xbb, 0x18, 0x0a, 0x73, 0x70, 0x61, 0x63, 0x65,
|
||||
0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x52, 0x09, 0x53, 0x70, 0x61, 0x63, 0x65, 0x4e, 0x61, 0x6d, 0x65,
|
||||
0x12, 0x2f, 0x0a, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x03,
|
||||
0x20, 0x01, 0x28, 0x09, 0x42, 0x0f, 0xca, 0xbb, 0x18, 0x0b, 0x69, 0x6e, 0x76, 0x69, 0x74, 0x65,
|
||||
0x5f, 0x63, 0x6f, 0x64, 0x65, 0x52, 0x0a, 0x49, 0x6e, 0x76, 0x69, 0x74, 0x65, 0x43, 0x6f, 0x64,
|
||||
0x65, 0x12, 0x1c, 0x0a, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, 0x42,
|
||||
0x08, 0xca, 0xbb, 0x18, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x52, 0x04, 0x52, 0x6f, 0x6c, 0x65, 0x42,
|
||||
0x22, 0x5a, 0x20, 0x63, 0x6e, 0x2f, 0x6f, 0x6e, 0x65, 0x61, 0x6f, 0x2f, 0x62, 0x61, 0x73, 0x65,
|
||||
0x2d, 0x67, 0x6f, 0x2f, 0x62, 0x69, 0x7a, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x73, 0x70,
|
||||
0x61, 0x63, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"cn/oneao/base-go/db"
|
||||
"cn/oneao/base-go/logx"
|
||||
"context"
|
||||
"github.com/cloudwego/hertz/pkg/app"
|
||||
)
|
||||
|
||||
func RefreshActive() app.HandlerFunc {
|
||||
return func(c context.Context, ctx *app.RequestContext) {
|
||||
// 先执行后续 handler
|
||||
ctx.Next(c)
|
||||
|
||||
userID := GetUserID(c)
|
||||
if userID == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
// 异步刷新活跃时间
|
||||
go func() {
|
||||
if err := db.Queries.UpdateUserActiveTime(c, userID); err != nil {
|
||||
logx.CtxError(c, "刷新用户活跃时间失败, userID=%d, err=%v", userID, err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,21 @@ SET role = $1
|
||||
WHERE user_id = $2
|
||||
AND space_id = $3;
|
||||
|
||||
-- 获取空间下的所有用户信息
|
||||
-- 获取空间下的所有用户信息(按 role, active_time, username 排序)
|
||||
-- name: ListSpaceUsers :many
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
u.id AS user_id,
|
||||
u.username,
|
||||
u.active_time,
|
||||
su.role,
|
||||
su.join_time
|
||||
FROM space_user su
|
||||
JOIN space s ON su.space_id = s.id
|
||||
JOIN user_info u ON su.user_id = u.id
|
||||
WHERE s.id = $1
|
||||
ORDER BY su.join_time ASC;
|
||||
|
||||
ORDER BY su.role ASC,
|
||||
u.active_time DESC,
|
||||
u.username ASC;
|
||||
|
||||
-- name: GetSpaceUserByUserId :one
|
||||
SELECT * FROM space_user WHERE user_id = $1;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- 插入用户并返回刚创建的记录
|
||||
-- name: InsertUser :execrows
|
||||
INSERT INTO user_info (id, account, password)
|
||||
VALUES ($1, $2, $3);
|
||||
INSERT INTO user_info (id, account, password,username)
|
||||
VALUES ($1, $2, $3,$4);
|
||||
|
||||
-- 根据 ID 查询单条用户记录
|
||||
-- name: GetUserById :one
|
||||
@@ -23,8 +23,13 @@ WHERE account = $1
|
||||
AND password = $2;
|
||||
|
||||
-- 更新用户最后登录时间,并返回更新后的记录
|
||||
-- name: UpdateUserLoginLastTime :execrows
|
||||
-- name: UpdateUserLoginLastTime :exec
|
||||
UPDATE user_info
|
||||
SET last_login_time = now()
|
||||
WHERE id = $1;
|
||||
|
||||
-- 更新用户活跃时间
|
||||
-- name: UpdateUserActiveTime :exec
|
||||
UPDATE user_info
|
||||
SET active_time = now()
|
||||
WHERE id = $1;
|
||||
@@ -76,5 +76,6 @@ type UserInfo struct {
|
||||
Gender pgtype.Int4
|
||||
CreateTime pgtype.Timestamp
|
||||
UpdateTime pgtype.Timestamp
|
||||
ActiveTime pgtype.Timestamp
|
||||
LastLoginTime pgtype.Timestamp
|
||||
}
|
||||
@@ -109,25 +109,29 @@ func (q *Queries) InsertSpaceUser(ctx context.Context, arg InsertSpaceUserParams
|
||||
|
||||
const listSpaceUsers = `-- name: ListSpaceUsers :many
|
||||
SELECT
|
||||
u.id as user_id,
|
||||
u.id AS user_id,
|
||||
u.username,
|
||||
u.active_time,
|
||||
su.role,
|
||||
su.join_time
|
||||
FROM space_user su
|
||||
JOIN space s ON su.space_id = s.id
|
||||
JOIN user_info u ON su.user_id = u.id
|
||||
WHERE s.id = $1
|
||||
ORDER BY su.join_time ASC
|
||||
ORDER BY su.role ASC,
|
||||
u.active_time DESC,
|
||||
u.username ASC
|
||||
`
|
||||
|
||||
type ListSpaceUsersRow struct {
|
||||
UserID int64
|
||||
Username pgtype.Text
|
||||
Role int32
|
||||
JoinTime pgtype.Timestamp
|
||||
UserID int64
|
||||
Username pgtype.Text
|
||||
ActiveTime pgtype.Timestamp
|
||||
Role int32
|
||||
JoinTime pgtype.Timestamp
|
||||
}
|
||||
|
||||
// 获取空间下的所有用户信息
|
||||
// 获取空间下的所有用户信息(按 role, active_time, username 排序)
|
||||
func (q *Queries) ListSpaceUsers(ctx context.Context, id int64) ([]ListSpaceUsersRow, error) {
|
||||
rows, err := q.db.Query(ctx, listSpaceUsers, id)
|
||||
if err != nil {
|
||||
@@ -140,6 +144,7 @@ func (q *Queries) ListSpaceUsers(ctx context.Context, id int64) ([]ListSpaceUser
|
||||
if err := rows.Scan(
|
||||
&i.UserID,
|
||||
&i.Username,
|
||||
&i.ActiveTime,
|
||||
&i.Role,
|
||||
&i.JoinTime,
|
||||
); err != nil {
|
||||
|
||||
@@ -7,10 +7,12 @@ package repo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/jackc/pgx/v5/pgtype"
|
||||
)
|
||||
|
||||
const getUserByAccount = `-- name: GetUserByAccount :one
|
||||
SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, last_login_time
|
||||
SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, active_time, last_login_time
|
||||
FROM user_info
|
||||
WHERE account = $1
|
||||
`
|
||||
@@ -29,13 +31,14 @@ func (q *Queries) GetUserByAccount(ctx context.Context, account string) (UserInf
|
||||
&i.Gender,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
&i.ActiveTime,
|
||||
&i.LastLoginTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserById = `-- name: GetUserById :one
|
||||
SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, last_login_time
|
||||
SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, active_time, last_login_time
|
||||
FROM user_info
|
||||
WHERE id = $1
|
||||
`
|
||||
@@ -54,13 +57,14 @@ func (q *Queries) GetUserById(ctx context.Context, id int64) (UserInfo, error) {
|
||||
&i.Gender,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
&i.ActiveTime,
|
||||
&i.LastLoginTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getUserForLogin = `-- name: GetUserForLogin :one
|
||||
SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, last_login_time
|
||||
SELECT id, seq_no, account, password, email, username, gender, create_time, update_time, active_time, last_login_time
|
||||
FROM user_info
|
||||
WHERE account = $1
|
||||
AND password = $2
|
||||
@@ -85,42 +89,58 @@ func (q *Queries) GetUserForLogin(ctx context.Context, arg GetUserForLoginParams
|
||||
&i.Gender,
|
||||
&i.CreateTime,
|
||||
&i.UpdateTime,
|
||||
&i.ActiveTime,
|
||||
&i.LastLoginTime,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertUser = `-- name: InsertUser :execrows
|
||||
INSERT INTO user_info (id, account, password)
|
||||
VALUES ($1, $2, $3)
|
||||
INSERT INTO user_info (id, account, password,username)
|
||||
VALUES ($1, $2, $3,$4)
|
||||
`
|
||||
|
||||
type InsertUserParams struct {
|
||||
ID int64
|
||||
Account string
|
||||
Password string
|
||||
Username pgtype.Text
|
||||
}
|
||||
|
||||
// 插入用户并返回刚创建的记录
|
||||
func (q *Queries) InsertUser(ctx context.Context, arg InsertUserParams) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, insertUser, arg.ID, arg.Account, arg.Password)
|
||||
result, err := q.db.Exec(ctx, insertUser,
|
||||
arg.ID,
|
||||
arg.Account,
|
||||
arg.Password,
|
||||
arg.Username,
|
||||
)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
}
|
||||
|
||||
const updateUserLoginLastTime = `-- name: UpdateUserLoginLastTime :execrows
|
||||
const updateUserActiveTime = `-- name: UpdateUserActiveTime :exec
|
||||
UPDATE user_info
|
||||
SET active_time = now()
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
// 更新用户活跃时间
|
||||
func (q *Queries) UpdateUserActiveTime(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, updateUserActiveTime, id)
|
||||
return err
|
||||
}
|
||||
|
||||
const updateUserLoginLastTime = `-- name: UpdateUserLoginLastTime :exec
|
||||
UPDATE user_info
|
||||
SET last_login_time = now()
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
// 更新用户最后登录时间,并返回更新后的记录
|
||||
func (q *Queries) UpdateUserLoginLastTime(ctx context.Context, id int64) (int64, error) {
|
||||
result, err := q.db.Exec(ctx, updateUserLoginLastTime, id)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return result.RowsAffected(), nil
|
||||
func (q *Queries) UpdateUserLoginLastTime(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, updateUserLoginLastTime, id)
|
||||
return err
|
||||
}
|
||||
@@ -8,6 +8,7 @@ CREATE TABLE user_info (
|
||||
gender INT DEFAULT 0,
|
||||
create_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
active_time TIMESTAMP,
|
||||
last_login_time TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
@@ -12,7 +12,8 @@ message ListSpaceUsersParams {
|
||||
message SpaceUser {
|
||||
int64 UserId = 1 [(api.body)="user_id"];
|
||||
string Username = 2 [(api.body)="username"];
|
||||
int32 SpaceRole = 4 [(api.body)="space_role"];
|
||||
int32 SpaceRole = 3 [(api.body)="space_role"];
|
||||
string ActiveTime = 4 [(api.body)="active_time"];
|
||||
}
|
||||
|
||||
message ListSpaceUsersResult {
|
||||
|
||||
@@ -34,6 +34,7 @@ func main() {
|
||||
h.Use(middleware.Log())
|
||||
h.Use(middleware.Error())
|
||||
h.Use(middleware.Auth())
|
||||
h.Use(middleware.RefreshActive())
|
||||
|
||||
register(h)
|
||||
h.Spin()
|
||||
|
||||
Reference in new issue
Block a user