diff --git a/README.md b/README.md index 393cc34..64d2972 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ rpc/scripts/gen-rpc.sh order 4.增加 etc/order.yaml 配置文件 5.Dockerfile 文件 6.changes 里的 SERVICES="..." - docker.strategy.matrix.include 加一行 { name: xxx, dockerfile: services/xxx/Dockerfile } + matrix.name 加一行 order ``` diff --git a/rpc/wecom/pb/wecom.pb.go b/rpc/wecom/pb/wecom.pb.go index 0d93a88..493c450 100644 --- a/rpc/wecom/pb/wecom.pb.go +++ b/rpc/wecom/pb/wecom.pb.go @@ -82,20 +82,56 @@ func (x *Response) GetData() string { return "" } +type EmptyReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EmptyReq) Reset() { + *x = EmptyReq{} + mi := &file_wecom_wecom_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EmptyReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EmptyReq) ProtoMessage() {} + +func (x *EmptyReq) ProtoReflect() protoreflect.Message { + mi := &file_wecom_wecom_proto_msgTypes[1] + 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 EmptyReq.ProtoReflect.Descriptor instead. +func (*EmptyReq) Descriptor() ([]byte, []int) { + return file_wecom_wecom_proto_rawDescGZIP(), []int{1} +} + type ItemsUserReq struct { state protoimpl.MessageState `protogen:"open.v1"` Page uint32 `protobuf:"varint,1,opt,name=page,proto3" json:"page,omitempty"` PageSize uint32 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"` Name string `protobuf:"bytes,3,opt,name=name,proto3" json:"name,omitempty"` - Type uint32 `protobuf:"varint,4,opt,name=type,proto3" json:"type,omitempty"` // 1: 管理员,2: 销售 - Status uint32 `protobuf:"varint,5,opt,name=status,proto3" json:"status,omitempty"` // 1: 启用,2: 禁用 + Type uint32 `protobuf:"varint,4,opt,name=type,proto3" json:"type,omitempty"` + Status uint32 `protobuf:"varint,5,opt,name=status,proto3" json:"status,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } func (x *ItemsUserReq) Reset() { *x = ItemsUserReq{} - mi := &file_wecom_wecom_proto_msgTypes[1] + mi := &file_wecom_wecom_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -107,7 +143,7 @@ func (x *ItemsUserReq) String() string { func (*ItemsUserReq) ProtoMessage() {} func (x *ItemsUserReq) ProtoReflect() protoreflect.Message { - mi := &file_wecom_wecom_proto_msgTypes[1] + mi := &file_wecom_wecom_proto_msgTypes[2] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -120,7 +156,7 @@ func (x *ItemsUserReq) ProtoReflect() protoreflect.Message { // Deprecated: Use ItemsUserReq.ProtoReflect.Descriptor instead. func (*ItemsUserReq) Descriptor() ([]byte, []int) { - return file_wecom_wecom_proto_rawDescGZIP(), []int{1} + return file_wecom_wecom_proto_rawDescGZIP(), []int{2} } func (x *ItemsUserReq) GetPage() uint32 { @@ -172,7 +208,7 @@ type CreateUserReq struct { func (x *CreateUserReq) Reset() { *x = CreateUserReq{} - mi := &file_wecom_wecom_proto_msgTypes[2] + mi := &file_wecom_wecom_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -184,7 +220,7 @@ func (x *CreateUserReq) String() string { func (*CreateUserReq) ProtoMessage() {} func (x *CreateUserReq) ProtoReflect() protoreflect.Message { - mi := &file_wecom_wecom_proto_msgTypes[2] + mi := &file_wecom_wecom_proto_msgTypes[3] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -197,7 +233,7 @@ func (x *CreateUserReq) ProtoReflect() protoreflect.Message { // Deprecated: Use CreateUserReq.ProtoReflect.Descriptor instead. func (*CreateUserReq) Descriptor() ([]byte, []int) { - return file_wecom_wecom_proto_rawDescGZIP(), []int{2} + return file_wecom_wecom_proto_rawDescGZIP(), []int{3} } func (x *CreateUserReq) GetUserId() int64 { @@ -257,7 +293,7 @@ type UpdateUserReq struct { func (x *UpdateUserReq) Reset() { *x = UpdateUserReq{} - mi := &file_wecom_wecom_proto_msgTypes[3] + mi := &file_wecom_wecom_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -269,7 +305,7 @@ func (x *UpdateUserReq) String() string { func (*UpdateUserReq) ProtoMessage() {} func (x *UpdateUserReq) ProtoReflect() protoreflect.Message { - mi := &file_wecom_wecom_proto_msgTypes[3] + mi := &file_wecom_wecom_proto_msgTypes[4] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -282,7 +318,7 @@ func (x *UpdateUserReq) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateUserReq.ProtoReflect.Descriptor instead. func (*UpdateUserReq) Descriptor() ([]byte, []int) { - return file_wecom_wecom_proto_rawDescGZIP(), []int{3} + return file_wecom_wecom_proto_rawDescGZIP(), []int{4} } func (x *UpdateUserReq) GetId() int64 { @@ -344,7 +380,7 @@ type StatusUserReq struct { func (x *StatusUserReq) Reset() { *x = StatusUserReq{} - mi := &file_wecom_wecom_proto_msgTypes[4] + mi := &file_wecom_wecom_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -356,7 +392,7 @@ func (x *StatusUserReq) String() string { func (*StatusUserReq) ProtoMessage() {} func (x *StatusUserReq) ProtoReflect() protoreflect.Message { - mi := &file_wecom_wecom_proto_msgTypes[4] + mi := &file_wecom_wecom_proto_msgTypes[5] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -369,7 +405,7 @@ func (x *StatusUserReq) ProtoReflect() protoreflect.Message { // Deprecated: Use StatusUserReq.ProtoReflect.Descriptor instead. func (*StatusUserReq) Descriptor() ([]byte, []int) { - return file_wecom_wecom_proto_rawDescGZIP(), []int{4} + return file_wecom_wecom_proto_rawDescGZIP(), []int{5} } func (x *StatusUserReq) GetId() int64 { @@ -395,7 +431,7 @@ type DeleteUserReq struct { func (x *DeleteUserReq) Reset() { *x = DeleteUserReq{} - mi := &file_wecom_wecom_proto_msgTypes[5] + mi := &file_wecom_wecom_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -407,7 +443,7 @@ func (x *DeleteUserReq) String() string { func (*DeleteUserReq) ProtoMessage() {} func (x *DeleteUserReq) ProtoReflect() protoreflect.Message { - mi := &file_wecom_wecom_proto_msgTypes[5] + mi := &file_wecom_wecom_proto_msgTypes[6] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -420,7 +456,7 @@ func (x *DeleteUserReq) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteUserReq.ProtoReflect.Descriptor instead. func (*DeleteUserReq) Descriptor() ([]byte, []int) { - return file_wecom_wecom_proto_rawDescGZIP(), []int{5} + return file_wecom_wecom_proto_rawDescGZIP(), []int{6} } func (x *DeleteUserReq) GetId() int64 { @@ -438,7 +474,9 @@ const file_wecom_wecom_proto_rawDesc = "" + "\bResponse\x12\x12\n" + "\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" + "\x03msg\x18\x02 \x01(\tR\x03msg\x12\x12\n" + - "\x04data\x18\x03 \x01(\tR\x04data\"\x7f\n" + + "\x04data\x18\x03 \x01(\tR\x04data\"\n" + + "\n" + + "\bEmptyReq\"\x7f\n" + "\fItemsUserReq\x12\x12\n" + "\x04page\x18\x01 \x01(\rR\x04page\x12\x1b\n" + "\tpage_size\x18\x02 \x01(\rR\bpageSize\x12\x12\n" + @@ -464,7 +502,7 @@ const file_wecom_wecom_proto_rawDesc = "" + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + "\x06status\x18\x02 \x01(\rR\x06status\"\x1f\n" + "\rDeleteUserReq\x12\x0e\n" + - "\x02id\x18\x01 \x01(\x03R\x02id2\xc2\x03\n" + + "\x02id\x18\x01 \x01(\x03R\x02id2\xe2\x04\n" + "\x05Wecom\x12S\n" + "\n" + "ItemsUsers\x12\x13.wecom.ItemsUserReq\x1a\x0f.wecom.Response\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\x12\x14/admin/v3/wecom/user\x12T\n" + @@ -475,7 +513,9 @@ const file_wecom_wecom_proto_rawDesc = "" + "\n" + "StatusUser\x12\x14.wecom.StatusUserReq\x1a\x0f.wecom.Response\"&\x82\xd3\xe4\x93\x02 :\x01*\x1a\x1b/admin/v3/wecom/user/status\x12[\n" + "\n" + - "DeleteUser\x12\x14.wecom.DeleteUserReq\x1a\x0f.wecom.Response\"&\x82\xd3\xe4\x93\x02 :\x01*\x1a\x1b/admin/v3/wecom/user/deleteB\x19Z\x17lone-services/rpc/wecomb\x06proto3" + "DeleteUser\x12\x14.wecom.DeleteUserReq\x1a\x0f.wecom.Response\"&\x82\xd3\xe4\x93\x02 :\x01*\x1a\x1b/admin/v3/wecom/user/delete\x12Q\n" + + "\vItemsAgents\x12\x0f.wecom.EmptyReq\x1a\x0f.wecom.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\x12\x15/admin/v3/wecom/agent\x12K\n" + + "\x05Types\x12\x0f.wecom.EmptyReq\x1a\x0f.wecom.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\x12\x15/admin/v3/wecom/typesB\x19Z\x17lone-services/rpc/wecomb\x06proto3" var ( file_wecom_wecom_proto_rawDescOnce sync.Once @@ -489,28 +529,33 @@ func file_wecom_wecom_proto_rawDescGZIP() []byte { return file_wecom_wecom_proto_rawDescData } -var file_wecom_wecom_proto_msgTypes = make([]protoimpl.MessageInfo, 6) +var file_wecom_wecom_proto_msgTypes = make([]protoimpl.MessageInfo, 7) var file_wecom_wecom_proto_goTypes = []any{ (*Response)(nil), // 0: wecom.Response - (*ItemsUserReq)(nil), // 1: wecom.ItemsUserReq - (*CreateUserReq)(nil), // 2: wecom.CreateUserReq - (*UpdateUserReq)(nil), // 3: wecom.UpdateUserReq - (*StatusUserReq)(nil), // 4: wecom.StatusUserReq - (*DeleteUserReq)(nil), // 5: wecom.DeleteUserReq + (*EmptyReq)(nil), // 1: wecom.EmptyReq + (*ItemsUserReq)(nil), // 2: wecom.ItemsUserReq + (*CreateUserReq)(nil), // 3: wecom.CreateUserReq + (*UpdateUserReq)(nil), // 4: wecom.UpdateUserReq + (*StatusUserReq)(nil), // 5: wecom.StatusUserReq + (*DeleteUserReq)(nil), // 6: wecom.DeleteUserReq } var file_wecom_wecom_proto_depIdxs = []int32{ - 1, // 0: wecom.Wecom.ItemsUsers:input_type -> wecom.ItemsUserReq - 2, // 1: wecom.Wecom.CreateUser:input_type -> wecom.CreateUserReq - 3, // 2: wecom.Wecom.UpdateUser:input_type -> wecom.UpdateUserReq - 4, // 3: wecom.Wecom.StatusUser:input_type -> wecom.StatusUserReq - 5, // 4: wecom.Wecom.DeleteUser:input_type -> wecom.DeleteUserReq - 0, // 5: wecom.Wecom.ItemsUsers:output_type -> wecom.Response - 0, // 6: wecom.Wecom.CreateUser:output_type -> wecom.Response - 0, // 7: wecom.Wecom.UpdateUser:output_type -> wecom.Response - 0, // 8: wecom.Wecom.StatusUser:output_type -> wecom.Response - 0, // 9: wecom.Wecom.DeleteUser:output_type -> wecom.Response - 5, // [5:10] is the sub-list for method output_type - 0, // [0:5] is the sub-list for method input_type + 2, // 0: wecom.Wecom.ItemsUsers:input_type -> wecom.ItemsUserReq + 3, // 1: wecom.Wecom.CreateUser:input_type -> wecom.CreateUserReq + 4, // 2: wecom.Wecom.UpdateUser:input_type -> wecom.UpdateUserReq + 5, // 3: wecom.Wecom.StatusUser:input_type -> wecom.StatusUserReq + 6, // 4: wecom.Wecom.DeleteUser:input_type -> wecom.DeleteUserReq + 1, // 5: wecom.Wecom.ItemsAgents:input_type -> wecom.EmptyReq + 1, // 6: wecom.Wecom.Types:input_type -> wecom.EmptyReq + 0, // 7: wecom.Wecom.ItemsUsers:output_type -> wecom.Response + 0, // 8: wecom.Wecom.CreateUser:output_type -> wecom.Response + 0, // 9: wecom.Wecom.UpdateUser:output_type -> wecom.Response + 0, // 10: wecom.Wecom.StatusUser:output_type -> wecom.Response + 0, // 11: wecom.Wecom.DeleteUser:output_type -> wecom.Response + 0, // 12: wecom.Wecom.ItemsAgents:output_type -> wecom.Response + 0, // 13: wecom.Wecom.Types:output_type -> wecom.Response + 7, // [7:14] is the sub-list for method output_type + 0, // [0:7] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -527,7 +572,7 @@ func file_wecom_wecom_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_wecom_wecom_proto_rawDesc), len(file_wecom_wecom_proto_rawDesc)), NumEnums: 0, - NumMessages: 6, + NumMessages: 7, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/wecom/pb/wecom_grpc.pb.go b/rpc/wecom/pb/wecom_grpc.pb.go index 195536d..b995686 100644 --- a/rpc/wecom/pb/wecom_grpc.pb.go +++ b/rpc/wecom/pb/wecom_grpc.pb.go @@ -19,11 +19,13 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - Wecom_ItemsUsers_FullMethodName = "/wecom.Wecom/ItemsUsers" - Wecom_CreateUser_FullMethodName = "/wecom.Wecom/CreateUser" - Wecom_UpdateUser_FullMethodName = "/wecom.Wecom/UpdateUser" - Wecom_StatusUser_FullMethodName = "/wecom.Wecom/StatusUser" - Wecom_DeleteUser_FullMethodName = "/wecom.Wecom/DeleteUser" + Wecom_ItemsUsers_FullMethodName = "/wecom.Wecom/ItemsUsers" + Wecom_CreateUser_FullMethodName = "/wecom.Wecom/CreateUser" + Wecom_UpdateUser_FullMethodName = "/wecom.Wecom/UpdateUser" + Wecom_StatusUser_FullMethodName = "/wecom.Wecom/StatusUser" + Wecom_DeleteUser_FullMethodName = "/wecom.Wecom/DeleteUser" + Wecom_ItemsAgents_FullMethodName = "/wecom.Wecom/ItemsAgents" + Wecom_Types_FullMethodName = "/wecom.Wecom/Types" ) // WecomClient is the client API for Wecom service. @@ -35,6 +37,8 @@ type WecomClient interface { UpdateUser(ctx context.Context, in *UpdateUserReq, opts ...grpc.CallOption) (*Response, error) StatusUser(ctx context.Context, in *StatusUserReq, opts ...grpc.CallOption) (*Response, error) DeleteUser(ctx context.Context, in *DeleteUserReq, opts ...grpc.CallOption) (*Response, error) + ItemsAgents(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) + Types(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) } type wecomClient struct { @@ -95,6 +99,26 @@ func (c *wecomClient) DeleteUser(ctx context.Context, in *DeleteUserReq, opts .. return out, nil } +func (c *wecomClient) ItemsAgents(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Wecom_ItemsAgents_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *wecomClient) Types(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Wecom_Types_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // WecomServer is the server API for Wecom service. // All implementations must embed UnimplementedWecomServer // for forward compatibility. @@ -104,6 +128,8 @@ type WecomServer interface { UpdateUser(context.Context, *UpdateUserReq) (*Response, error) StatusUser(context.Context, *StatusUserReq) (*Response, error) DeleteUser(context.Context, *DeleteUserReq) (*Response, error) + ItemsAgents(context.Context, *EmptyReq) (*Response, error) + Types(context.Context, *EmptyReq) (*Response, error) mustEmbedUnimplementedWecomServer() } @@ -129,6 +155,12 @@ func (UnimplementedWecomServer) StatusUser(context.Context, *StatusUserReq) (*Re func (UnimplementedWecomServer) DeleteUser(context.Context, *DeleteUserReq) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method DeleteUser not implemented") } +func (UnimplementedWecomServer) ItemsAgents(context.Context, *EmptyReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ItemsAgents not implemented") +} +func (UnimplementedWecomServer) Types(context.Context, *EmptyReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Types not implemented") +} func (UnimplementedWecomServer) mustEmbedUnimplementedWecomServer() {} func (UnimplementedWecomServer) testEmbeddedByValue() {} @@ -240,6 +272,42 @@ func _Wecom_DeleteUser_Handler(srv interface{}, ctx context.Context, dec func(in return interceptor(ctx, in, info, handler) } +func _Wecom_ItemsAgents_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WecomServer).ItemsAgents(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Wecom_ItemsAgents_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WecomServer).ItemsAgents(ctx, req.(*EmptyReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Wecom_Types_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(EmptyReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WecomServer).Types(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Wecom_Types_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WecomServer).Types(ctx, req.(*EmptyReq)) + } + return interceptor(ctx, in, info, handler) +} + // Wecom_ServiceDesc is the grpc.ServiceDesc for Wecom service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -267,6 +335,14 @@ var Wecom_ServiceDesc = grpc.ServiceDesc{ MethodName: "DeleteUser", Handler: _Wecom_DeleteUser_Handler, }, + { + MethodName: "ItemsAgents", + Handler: _Wecom_ItemsAgents_Handler, + }, + { + MethodName: "Types", + Handler: _Wecom_Types_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "wecom/wecom.proto", diff --git a/rpc/wecom/wecom.pb b/rpc/wecom/wecom.pb index 0beb3dc..3948e86 100644 Binary files a/rpc/wecom/wecom.pb and b/rpc/wecom/wecom.pb differ diff --git a/rpc/wecom/wecom.proto b/rpc/wecom/wecom.proto index f087596..77f08eb 100644 --- a/rpc/wecom/wecom.proto +++ b/rpc/wecom/wecom.proto @@ -35,6 +35,20 @@ service Wecom { body: "*" }; } + + rpc ItemsAgents(EmptyReq) returns (Response) { + option (google.api.http) = { + get: "/admin/v3/wecom/agent" + body: "*" + }; + } + + rpc Types(EmptyReq) returns (Response) { + option (google.api.http) = { + get: "/admin/v3/wecom/types" + body: "*" + }; + } } message Response { @@ -43,12 +57,14 @@ message Response { string data = 3; } +message EmptyReq {} + message ItemsUserReq { uint32 page = 1; uint32 page_size = 2; string name = 3; - uint32 type = 4; // 1: 管理员,2: 销售 - uint32 status = 5; // 1: 启用,2: 禁用 + uint32 type = 4; + uint32 status = 5; } message CreateUserReq { diff --git a/services/wecom/internal/dao/agent.go b/services/wecom/internal/dao/agent.go new file mode 100644 index 0000000..b2e1f33 --- /dev/null +++ b/services/wecom/internal/dao/agent.go @@ -0,0 +1,19 @@ +package dao + +import "lone-services/pkg/utils" + +// WecomAgent 企业微信应用 +type WecomAgent struct { + Id int64 `gorm:"column:id;primaryKey;autoIncrement" json:"id"` + Name string `gorm:"column:name" json:"name"` + AgentId int64 `gorm:"column:agent_id" json:"agent_id"` + CreatedAt utils.CustomTime `gorm:"column:created_at" json:"created_at"` +} + +// AgentListItem 应用列表项 +type AgentListItem struct { + Id int64 `json:"id"` + Name string `json:"name"` + AgentId int64 `json:"agent_id"` + CreatedAt string `json:"created_at"` +} diff --git a/services/wecom/internal/dao/user.go b/services/wecom/internal/dao/user.go index d5dc3f8..2b3a79f 100644 --- a/services/wecom/internal/dao/user.go +++ b/services/wecom/internal/dao/user.go @@ -39,3 +39,9 @@ type UserListItem struct { CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` } + +// UserTypeOption 用户类型选项(前端下拉) +type UserTypeOption struct { + Value uint8 `json:"value"` + Label string `json:"label"` +} diff --git a/services/wecom/internal/logic/helper.go b/services/wecom/internal/logic/helper.go index b64d07a..0739ee4 100644 --- a/services/wecom/internal/logic/helper.go +++ b/services/wecom/internal/logic/helper.go @@ -31,6 +31,13 @@ func typeText(t uint8) string { } } +func userTypeOptions() []dao.UserTypeOption { + return []dao.UserTypeOption{ + {Value: dao.UserTypeAdmin, Label: "管理员"}, + {Value: dao.UserTypeSale, Label: "销售"}, + } +} + func resolveStatus(reqStatus uint32, current uint8) uint8 { if reqStatus == uint32(dao.StatusEnabled) || reqStatus == uint32(dao.StatusDisabled) { return uint8(reqStatus) diff --git a/services/wecom/internal/logic/itemsAgentsLogic.go b/services/wecom/internal/logic/itemsAgentsLogic.go new file mode 100644 index 0000000..682248f --- /dev/null +++ b/services/wecom/internal/logic/itemsAgentsLogic.go @@ -0,0 +1,49 @@ +package logic + +import ( + "context" + + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + wecom "lone-services/rpc/wecom/pb" + "lone-services/services/wecom/internal/dao" + "lone-services/services/wecom/internal/model" + "lone-services/services/wecom/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type ItemsAgentsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewItemsAgentsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsAgentsLogic { + return &ItemsAgentsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// ItemsAgents 企业微信应用列表 +func (l *ItemsAgentsLogic) ItemsAgents(_ *wecom.EmptyReq) (*wecom.Response, error) { + var rows []dao.WecomAgent + m := model.AgentModel{}.Init() + if err := m.Items(modelbase.Params{Order: "id desc"}, &rows); err != nil { + l.Errorf("wecom items agents: %v", err) + return failResponse(utils.Fail), nil + } + + items := make([]dao.AgentListItem, 0, len(rows)) + for _, row := range rows { + items = append(items, dao.AgentListItem{ + Id: row.Id, + Name: row.Name, + AgentId: row.AgentId, + CreatedAt: row.CreatedAt.Format(), + }) + } + return okResponse(items), nil +} diff --git a/services/wecom/internal/logic/itemsUsersLogic.go b/services/wecom/internal/logic/itemsUsersLogic.go index cc13ea6..1546a5a 100644 --- a/services/wecom/internal/logic/itemsUsersLogic.go +++ b/services/wecom/internal/logic/itemsUsersLogic.go @@ -57,7 +57,7 @@ func (l *ItemsUsersLogic) ItemsUsers(in *wecom.ItemsUserReq) (*wecom.Response, e if req.Type > utils.NumberZero { w.Eq["type"] = strconv.FormatUint(uint64(req.Type), utils.NumberTen) } - w.Eq["status"] = strconv.FormatUint(uint64(dao.StatusEnabled), utils.NumberTen) + // w.Eq["status"] = strconv.FormatUint(uint64(dao.StatusEnabled), utils.NumberTen) if req.Name != utils.StringEmpty { w.Like["name LIKE ?"] = "%" + req.Name + "%" } diff --git a/services/wecom/internal/logic/typesLogic.go b/services/wecom/internal/logic/typesLogic.go new file mode 100644 index 0000000..deaed26 --- /dev/null +++ b/services/wecom/internal/logic/typesLogic.go @@ -0,0 +1,29 @@ +package logic + +import ( + "context" + + wecom "lone-services/rpc/wecom/pb" + "lone-services/services/wecom/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type TypesLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewTypesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TypesLogic { + return &TypesLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// Types 用户类型选项(管理员 / 销售) +func (l *TypesLogic) Types(_ *wecom.EmptyReq) (*wecom.Response, error) { + return okResponse(userTypeOptions()), nil +} diff --git a/services/wecom/internal/model/agent.go b/services/wecom/internal/model/agent.go new file mode 100644 index 0000000..3a29464 --- /dev/null +++ b/services/wecom/internal/model/agent.go @@ -0,0 +1,18 @@ +package model + +import ( + "lone-services/pkg/modelbase" +) + +type AgentModel struct { + modelbase.Base +} + +func (m AgentModel) TableName() string { + return modelbase.Prefix() + "agents" +} + +func (m AgentModel) Init() AgentModel { + m.Table = m.TableName() + return m +} diff --git a/services/wecom/internal/server/wecomServer.go b/services/wecom/internal/server/wecomServer.go index 166a519..d957134 100644 --- a/services/wecom/internal/server/wecomServer.go +++ b/services/wecom/internal/server/wecomServer.go @@ -47,3 +47,13 @@ func (s *WecomServer) DeleteUser(ctx context.Context, in *wecom.DeleteUserReq) ( l := logic.NewDeleteUserLogic(ctx, s.svcCtx) return l.DeleteUser(in) } + +func (s *WecomServer) ItemsAgents(ctx context.Context, in *wecom.EmptyReq) (*wecom.Response, error) { + l := logic.NewItemsAgentsLogic(ctx, s.svcCtx) + return l.ItemsAgents(in) +} + +func (s *WecomServer) Types(ctx context.Context, in *wecom.EmptyReq) (*wecom.Response, error) { + l := logic.NewTypesLogic(ctx, s.svcCtx) + return l.Types(in) +} diff --git a/services/wecom/sql/agents.sql b/services/wecom/sql/agents.sql new file mode 100644 index 0000000..61cad2e --- /dev/null +++ b/services/wecom/sql/agents.sql @@ -0,0 +1,13 @@ +-- 企业微信应用表(库:dms-wecom,前缀为空时表名为 agents) +CREATE TABLE IF NOT EXISTS `agents` ( + `id` bigint unsigned NOT NULL AUTO_INCREMENT, + `name` varchar(64) NOT NULL DEFAULT '' COMMENT '应用名称', + `agent_id` bigint NOT NULL DEFAULT 0 COMMENT '企业微信 AgentId', + `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`id`), + UNIQUE KEY `uk_agent_id` (`agent_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='企业微信应用'; + +INSERT INTO `agents` (`id`, `name`, `agent_id`, `created_at`) VALUES + (1, '审核通知', 100003, '2026-05-22 16:14:31'), + (2, '消息通知', 100004, '2026-05-22 16:14:33'); diff --git a/services/wecom/wecomClient/wecom.go b/services/wecom/wecomClient/wecom.go index 81dc97c..b67e424 100644 --- a/services/wecom/wecomClient/wecom.go +++ b/services/wecom/wecomClient/wecom.go @@ -16,6 +16,7 @@ import ( type ( CreateUserReq = wecom.CreateUserReq DeleteUserReq = wecom.DeleteUserReq + EmptyReq = wecom.EmptyReq ItemsUserReq = wecom.ItemsUserReq Response = wecom.Response StatusUserReq = wecom.StatusUserReq @@ -27,6 +28,8 @@ type ( UpdateUser(ctx context.Context, in *UpdateUserReq, opts ...grpc.CallOption) (*Response, error) StatusUser(ctx context.Context, in *StatusUserReq, opts ...grpc.CallOption) (*Response, error) DeleteUser(ctx context.Context, in *DeleteUserReq, opts ...grpc.CallOption) (*Response, error) + ItemsAgents(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) + Types(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) } defaultWecom struct { @@ -64,3 +67,13 @@ func (m *defaultWecom) DeleteUser(ctx context.Context, in *DeleteUserReq, opts . client := wecom.NewWecomClient(m.cli.Conn()) return client.DeleteUser(ctx, in, opts...) } + +func (m *defaultWecom) ItemsAgents(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { + client := wecom.NewWecomClient(m.cli.Conn()) + return client.ItemsAgents(ctx, in, opts...) +} + +func (m *defaultWecom) Types(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) { + client := wecom.NewWecomClient(m.cli.Conn()) + return client.Types(ctx, in, opts...) +}