diff --git a/rpc/user/pb/user.pb.go b/rpc/user/pb/user.pb.go index 6e2ef4a..0174d7f 100644 --- a/rpc/user/pb/user.pb.go +++ b/rpc/user/pb/user.pb.go @@ -1254,6 +1254,66 @@ func (*InfoReq) Descriptor() ([]byte, []int) { return file_user_user_proto_rawDescGZIP(), []int{19} } +type ClientReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"` + SubjectType uint32 `protobuf:"varint,3,opt,name=subject_type,json=subjectType,proto3" json:"subject_type,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ClientReq) Reset() { + *x = ClientReq{} + mi := &file_user_user_proto_msgTypes[20] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ClientReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ClientReq) ProtoMessage() {} + +func (x *ClientReq) ProtoReflect() protoreflect.Message { + mi := &file_user_user_proto_msgTypes[20] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ClientReq.ProtoReflect.Descriptor instead. +func (*ClientReq) Descriptor() ([]byte, []int) { + return file_user_user_proto_rawDescGZIP(), []int{20} +} + +func (x *ClientReq) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *ClientReq) GetType() string { + if x != nil { + return x.Type + } + return "" +} + +func (x *ClientReq) GetSubjectType() uint32 { + if x != nil { + return x.SubjectType + } + return 0 +} + var File_user_user_proto protoreflect.FileDescriptor const file_user_user_proto_rawDesc = "" + @@ -1353,10 +1413,15 @@ const file_user_user_proto_rawDesc = "" + "\auser_id\x18\x01 \x01(\x03R\x06userId\x12\x16\n" + "\x06mobile\x18\x02 \x01(\tR\x06mobile\x12\x12\n" + "\x04name\x18\x03 \x01(\tR\x04name\"\t\n" + - "\aInfoReq2\xef\x06\n" + + "\aInfoReq\"V\n" + + "\tClientReq\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\x12\x12\n" + + "\x04type\x18\x02 \x01(\tR\x04type\x12!\n" + + "\fsubject_type\x18\x03 \x01(\rR\vsubjectType2\xbc\a\n" + "\x04User\x12A\n" + "\x05Login\x12\x0e.user.LoginReq\x1a\x0e.user.Response\"\x18\x82\xd3\xe4\x93\x02\x12:\x01*\"\r/api/v3/login\x12C\n" + - "\x04Info\x12\r.user.InfoReq\x1a\x0e.user.Response\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\x12\x11/api/v3/user/info\x12P\n" + + "\x04Info\x12\r.user.InfoReq\x1a\x0e.user.Response\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\x12\x11/api/v3/user/info\x12K\n" + + "\x06Client\x12\x0f.user.ClientReq\x1a\x0e.user.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\x12\x15/admin/v3/user/client\x12P\n" + "\tUserItems\x12\x12.user.UserItemsReq\x1a\x0e.user.Response\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\x12\x14/admin/v3/user/items\x12S\n" + "\n" + "UserStatus\x12\x13.user.UserStatusReq\x1a\x0e.user.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\x1a\x15/admin/v3/user/status\x12C\n" + @@ -1380,7 +1445,7 @@ func file_user_user_proto_rawDescGZIP() []byte { return file_user_user_proto_rawDescData } -var file_user_user_proto_msgTypes = make([]protoimpl.MessageInfo, 20) +var file_user_user_proto_msgTypes = make([]protoimpl.MessageInfo, 21) var file_user_user_proto_goTypes = []any{ (*Response)(nil), // 0: user.Response (*LoginReq)(nil), // 1: user.LoginReq @@ -1402,33 +1467,36 @@ var file_user_user_proto_goTypes = []any{ (*InternalUpdateReq)(nil), // 17: user.InternalUpdateReq (*InternalUpdateData)(nil), // 18: user.InternalUpdateData (*InfoReq)(nil), // 19: user.InfoReq + (*ClientReq)(nil), // 20: user.ClientReq } var file_user_user_proto_depIdxs = []int32{ 7, // 0: user.InternalUsersByIdsData.items:type_name -> user.UserBriefItem 1, // 1: user.User.Login:input_type -> user.LoginReq 19, // 2: user.User.Info:input_type -> user.InfoReq - 2, // 3: user.User.UserItems:input_type -> user.UserItemsReq - 3, // 4: user.User.UserStatus:input_type -> user.UserStatusReq - 4, // 5: user.User.InternalCreate:input_type -> user.InternalCreateReq - 13, // 6: user.User.InternalCheckCreate:input_type -> user.InternalCheckCreateReq - 15, // 7: user.User.InternalCheckUpdate:input_type -> user.InternalCheckUpdateReq - 17, // 8: user.User.InternalUpdate:input_type -> user.InternalUpdateReq - 6, // 9: user.User.InternalUsersByIds:input_type -> user.InternalUsersByIdsReq - 9, // 10: user.User.InternalUpdateMobile:input_type -> user.InternalUpdateMobileReq - 11, // 11: user.User.InternalRevokeBizClient:input_type -> user.InternalRevokeBizClientReq - 0, // 12: user.User.Login:output_type -> user.Response - 0, // 13: user.User.Info:output_type -> user.Response - 0, // 14: user.User.UserItems:output_type -> user.Response - 0, // 15: user.User.UserStatus:output_type -> user.Response - 5, // 16: user.User.InternalCreate:output_type -> user.InternalCreateData - 14, // 17: user.User.InternalCheckCreate:output_type -> user.InternalCheckCreateData - 16, // 18: user.User.InternalCheckUpdate:output_type -> user.InternalCheckUpdateData - 18, // 19: user.User.InternalUpdate:output_type -> user.InternalUpdateData - 8, // 20: user.User.InternalUsersByIds:output_type -> user.InternalUsersByIdsData - 10, // 21: user.User.InternalUpdateMobile:output_type -> user.InternalUpdateMobileData - 12, // 22: user.User.InternalRevokeBizClient:output_type -> user.InternalRevokeBizClientData - 12, // [12:23] is the sub-list for method output_type - 1, // [1:12] is the sub-list for method input_type + 20, // 3: user.User.Client:input_type -> user.ClientReq + 2, // 4: user.User.UserItems:input_type -> user.UserItemsReq + 3, // 5: user.User.UserStatus:input_type -> user.UserStatusReq + 4, // 6: user.User.InternalCreate:input_type -> user.InternalCreateReq + 13, // 7: user.User.InternalCheckCreate:input_type -> user.InternalCheckCreateReq + 15, // 8: user.User.InternalCheckUpdate:input_type -> user.InternalCheckUpdateReq + 17, // 9: user.User.InternalUpdate:input_type -> user.InternalUpdateReq + 6, // 10: user.User.InternalUsersByIds:input_type -> user.InternalUsersByIdsReq + 9, // 11: user.User.InternalUpdateMobile:input_type -> user.InternalUpdateMobileReq + 11, // 12: user.User.InternalRevokeBizClient:input_type -> user.InternalRevokeBizClientReq + 0, // 13: user.User.Login:output_type -> user.Response + 0, // 14: user.User.Info:output_type -> user.Response + 0, // 15: user.User.Client:output_type -> user.Response + 0, // 16: user.User.UserItems:output_type -> user.Response + 0, // 17: user.User.UserStatus:output_type -> user.Response + 5, // 18: user.User.InternalCreate:output_type -> user.InternalCreateData + 14, // 19: user.User.InternalCheckCreate:output_type -> user.InternalCheckCreateData + 16, // 20: user.User.InternalCheckUpdate:output_type -> user.InternalCheckUpdateData + 18, // 21: user.User.InternalUpdate:output_type -> user.InternalUpdateData + 8, // 22: user.User.InternalUsersByIds:output_type -> user.InternalUsersByIdsData + 10, // 23: user.User.InternalUpdateMobile:output_type -> user.InternalUpdateMobileData + 12, // 24: user.User.InternalRevokeBizClient:output_type -> user.InternalRevokeBizClientData + 13, // [13:25] is the sub-list for method output_type + 1, // [1:13] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name 1, // [1:1] is the sub-list for extension extendee 0, // [0:1] is the sub-list for field type_name @@ -1445,7 +1513,7 @@ func file_user_user_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_user_user_proto_rawDesc), len(file_user_user_proto_rawDesc)), NumEnums: 0, - NumMessages: 20, + NumMessages: 21, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/user/pb/user_grpc.pb.go b/rpc/user/pb/user_grpc.pb.go index f87c4ac..88e2424 100644 --- a/rpc/user/pb/user_grpc.pb.go +++ b/rpc/user/pb/user_grpc.pb.go @@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion9 const ( User_Login_FullMethodName = "/user.User/Login" User_Info_FullMethodName = "/user.User/Info" + User_Client_FullMethodName = "/user.User/Client" User_UserItems_FullMethodName = "/user.User/UserItems" User_UserStatus_FullMethodName = "/user.User/UserStatus" User_InternalCreate_FullMethodName = "/user.User/InternalCreate" @@ -38,6 +39,7 @@ const ( type UserClient interface { Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*Response, error) Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*Response, error) + Client(ctx context.Context, in *ClientReq, opts ...grpc.CallOption) (*Response, error) UserItems(ctx context.Context, in *UserItemsReq, opts ...grpc.CallOption) (*Response, error) UserStatus(ctx context.Context, in *UserStatusReq, opts ...grpc.CallOption) (*Response, error) InternalCreate(ctx context.Context, in *InternalCreateReq, opts ...grpc.CallOption) (*InternalCreateData, error) @@ -77,6 +79,16 @@ func (c *userClient) Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOpt return out, nil } +func (c *userClient) Client(ctx context.Context, in *ClientReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, User_Client_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *userClient) UserItems(ctx context.Context, in *UserItemsReq, opts ...grpc.CallOption) (*Response, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(Response) @@ -173,6 +185,7 @@ func (c *userClient) InternalRevokeBizClient(ctx context.Context, in *InternalRe type UserServer interface { Login(context.Context, *LoginReq) (*Response, error) Info(context.Context, *InfoReq) (*Response, error) + Client(context.Context, *ClientReq) (*Response, error) UserItems(context.Context, *UserItemsReq) (*Response, error) UserStatus(context.Context, *UserStatusReq) (*Response, error) InternalCreate(context.Context, *InternalCreateReq) (*InternalCreateData, error) @@ -198,6 +211,9 @@ func (UnimplementedUserServer) Login(context.Context, *LoginReq) (*Response, err func (UnimplementedUserServer) Info(context.Context, *InfoReq) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method Info not implemented") } +func (UnimplementedUserServer) Client(context.Context, *ClientReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Client not implemented") +} func (UnimplementedUserServer) UserItems(context.Context, *UserItemsReq) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method UserItems not implemented") } @@ -282,6 +298,24 @@ func _User_Info_Handler(srv interface{}, ctx context.Context, dec func(interface return interceptor(ctx, in, info, handler) } +func _User_Client_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ClientReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(UserServer).Client(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: User_Client_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(UserServer).Client(ctx, req.(*ClientReq)) + } + return interceptor(ctx, in, info, handler) +} + func _User_UserItems_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(UserItemsReq) if err := dec(in); err != nil { @@ -459,6 +493,10 @@ var User_ServiceDesc = grpc.ServiceDesc{ MethodName: "Info", Handler: _User_Info_Handler, }, + { + MethodName: "Client", + Handler: _User_Client_Handler, + }, { MethodName: "UserItems", Handler: _User_UserItems_Handler, diff --git a/rpc/user/user.pb b/rpc/user/user.pb index a838d70..bbcaa4b 100644 Binary files a/rpc/user/user.pb and b/rpc/user/user.pb differ diff --git a/rpc/user/user.proto b/rpc/user/user.proto index 81c251c..5e18e15 100644 --- a/rpc/user/user.proto +++ b/rpc/user/user.proto @@ -128,6 +128,12 @@ message InternalUpdateData { message InfoReq {} +message ClientReq { + string name = 1; + string type = 2; + uint32 subject_type = 3; +} + service User { rpc Login(LoginReq) returns (Response) { option (google.api.http) = { @@ -141,6 +147,12 @@ service User { body: "*" }; } + rpc Client(ClientReq) returns (Response) { + option (google.api.http) = { + get: "/admin/v3/user/client" + body: "*" + }; + } rpc UserItems(UserItemsReq) returns (Response) { option (google.api.http) = { get: "/admin/v3/user/items" diff --git a/services/user/internal/logic/clientLogic.go b/services/user/internal/logic/clientLogic.go new file mode 100644 index 0000000..a5f8471 --- /dev/null +++ b/services/user/internal/logic/clientLogic.go @@ -0,0 +1,58 @@ +package logic + +import ( + "context" + "strconv" + + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + user "lone-services/rpc/user/pb" + "lone-services/services/user/internal/dao" + "lone-services/services/user/internal/model" + "lone-services/services/user/internal/svc" + "lone-services/services/user/validator" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ClientLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewClientLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClientLogic { + return &ClientLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ClientLogic) Client(in *user.ClientReq) (*user.Response, error) { + var req validator.ClientValidator + if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty { + return outResponse(utils.ErrorParams, msg), nil + } + + w := modelbase.Params{} + + if req.Name != utils.StringEmpty { + w.Eq["name"] = req.Name + } + if req.Type != utils.StringEmpty { + w.Eq["type"] = req.Type + } + if req.SubjectType != utils.NumberZero { + w.Eq["subject_type"] = strconv.FormatUint(uint64(req.SubjectType), utils.NumberTen) + } + var items []dao.Client + err := model.ClientModel{}.Init().Items(w, &items) + if err != nil { + l.Errorf("client items: %v", err) + return outResponse(utils.ErrorInternalServer, utils.Fail.Msg), nil + } + + return okResponse(items), nil +} diff --git a/services/user/internal/server/userServer.go b/services/user/internal/server/userServer.go index 2937c2c..e41578c 100644 --- a/services/user/internal/server/userServer.go +++ b/services/user/internal/server/userServer.go @@ -33,6 +33,11 @@ func (s *UserServer) Info(ctx context.Context, in *user.InfoReq) (*user.Response return l.Info(in) } +func (s *UserServer) Client(ctx context.Context, in *user.ClientReq) (*user.Response, error) { + l := logic.NewClientLogic(ctx, s.svcCtx) + return l.Client(in) +} + func (s *UserServer) UserItems(ctx context.Context, in *user.UserItemsReq) (*user.Response, error) { l := logic.NewUserItemsLogic(ctx, s.svcCtx) return l.UserItems(in) diff --git a/services/user/userClient/user.go b/services/user/userClient/user.go index 9d21399..be13d6d 100644 --- a/services/user/userClient/user.go +++ b/services/user/userClient/user.go @@ -14,6 +14,7 @@ import ( ) type ( + ClientReq = user.ClientReq InfoReq = user.InfoReq InternalCheckCreateData = user.InternalCheckCreateData InternalCheckCreateReq = user.InternalCheckCreateReq @@ -38,6 +39,7 @@ type ( User interface { Login(ctx context.Context, in *LoginReq, opts ...grpc.CallOption) (*Response, error) Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*Response, error) + Client(ctx context.Context, in *ClientReq, opts ...grpc.CallOption) (*Response, error) UserItems(ctx context.Context, in *UserItemsReq, opts ...grpc.CallOption) (*Response, error) UserStatus(ctx context.Context, in *UserStatusReq, opts ...grpc.CallOption) (*Response, error) InternalCreate(ctx context.Context, in *InternalCreateReq, opts ...grpc.CallOption) (*InternalCreateData, error) @@ -70,6 +72,11 @@ func (m *defaultUser) Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOp return client.Info(ctx, in, opts...) } +func (m *defaultUser) Client(ctx context.Context, in *ClientReq, opts ...grpc.CallOption) (*Response, error) { + client := user.NewUserClient(m.cli.Conn()) + return client.Client(ctx, in, opts...) +} + func (m *defaultUser) UserItems(ctx context.Context, in *UserItemsReq, opts ...grpc.CallOption) (*Response, error) { client := user.NewUserClient(m.cli.Conn()) return client.UserItems(ctx, in, opts...) diff --git a/services/user/validator/client.go b/services/user/validator/client.go new file mode 100644 index 0000000..2c85f16 --- /dev/null +++ b/services/user/validator/client.go @@ -0,0 +1,17 @@ +package validator + +import "lone-services/pkg/validate" + +type ClientValidator struct { + Name string `validate:"omitempty,max=64"` + Type string `validate:"omitempty,oneof=user sale store"` + SubjectType uint32 `validate:"omitempty,oneof=1 2 3"` +} + +func (p ClientValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Name.max": "名称过长", + "Type.oneof": "类型不正确", + "SubjectType.oneof": "主体类型不正确", + } +}