From 44c4aed22ec7070ee87fc24b63ac73e3a8705f28 Mon Sep 17 00:00:00 2001 From: gjs Date: Tue, 11 Aug 2026 10:35:29 +0800 Subject: [PATCH] service apis edit, info, items, status, names --- admin/admin/admin.pb.go | 302 ++++++++++++++++++--- admin/admin/admin_grpc.pb.go | 208 +++++++++++++- admin/adminclient/admin.go | 52 +++- admin/internal/dao/servers.go | 41 ++- admin/internal/logic/adminitemslogic.go | 4 +- admin/internal/logic/serviceeditlogic.go | 74 +++++ admin/internal/logic/serviceinfologic.go | 47 ++++ admin/internal/logic/serviceitemslogic.go | 51 ++++ admin/internal/logic/servicenameslogic.go | 46 ++++ admin/internal/logic/servicestatuslogic.go | 65 +++++ admin/internal/model/services.go | 2 +- admin/internal/server/adminserver.go | 25 ++ admin/proto/admin.proto | 49 ++++ admin/validator/{validator.go => admin.go} | 0 admin/validator/service.go | 46 ++++ bff/etc/admin.pb | Bin 14896 -> 15635 bytes 16 files changed, 930 insertions(+), 82 deletions(-) create mode 100644 admin/internal/logic/serviceeditlogic.go create mode 100644 admin/internal/logic/serviceinfologic.go create mode 100644 admin/internal/logic/serviceitemslogic.go create mode 100644 admin/internal/logic/servicenameslogic.go create mode 100644 admin/internal/logic/servicestatuslogic.go rename admin/validator/{validator.go => admin.go} (100%) create mode 100644 admin/validator/service.go diff --git a/admin/admin/admin.pb.go b/admin/admin/admin.pb.go index 6d503f1..2586f49 100644 --- a/admin/admin/admin.pb.go +++ b/admin/admin/admin.pb.go @@ -546,6 +546,206 @@ func (*AdminEmptyRequest) Descriptor() ([]byte, []int) { return file_proto_admin_proto_rawDescGZIP(), []int{8} } +type InfoRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *InfoRequest) Reset() { + *x = InfoRequest{} + mi := &file_proto_admin_proto_msgTypes[9] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *InfoRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InfoRequest) ProtoMessage() {} + +func (x *InfoRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_admin_proto_msgTypes[9] + 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 InfoRequest.ProtoReflect.Descriptor instead. +func (*InfoRequest) Descriptor() ([]byte, []int) { + return file_proto_admin_proto_rawDescGZIP(), []int{9} +} + +func (x *InfoRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type ServiceEditRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Description string `protobuf:"bytes,3,opt,name=description,proto3" json:"description,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ServiceEditRequest) Reset() { + *x = ServiceEditRequest{} + mi := &file_proto_admin_proto_msgTypes[10] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ServiceEditRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ServiceEditRequest) ProtoMessage() {} + +func (x *ServiceEditRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_admin_proto_msgTypes[10] + 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 ServiceEditRequest.ProtoReflect.Descriptor instead. +func (*ServiceEditRequest) Descriptor() ([]byte, []int) { + return file_proto_admin_proto_rawDescGZIP(), []int{10} +} + +func (x *ServiceEditRequest) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *ServiceEditRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *ServiceEditRequest) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +type ServiceItemsRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ServiceItemsRequest) Reset() { + *x = ServiceItemsRequest{} + mi := &file_proto_admin_proto_msgTypes[11] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ServiceItemsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ServiceItemsRequest) ProtoMessage() {} + +func (x *ServiceItemsRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_admin_proto_msgTypes[11] + 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 ServiceItemsRequest.ProtoReflect.Descriptor instead. +func (*ServiceItemsRequest) Descriptor() ([]byte, []int) { + return file_proto_admin_proto_rawDescGZIP(), []int{11} +} + +func (x *ServiceItemsRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *ServiceItemsRequest) GetStatus() int32 { + if x != nil { + return x.Status + } + return 0 +} + +type ServiceNameRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ServiceNameRequest) Reset() { + *x = ServiceNameRequest{} + mi := &file_proto_admin_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ServiceNameRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ServiceNameRequest) ProtoMessage() {} + +func (x *ServiceNameRequest) ProtoReflect() protoreflect.Message { + mi := &file_proto_admin_proto_msgTypes[12] + 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 ServiceNameRequest.ProtoReflect.Descriptor instead. +func (*ServiceNameRequest) Descriptor() ([]byte, []int) { + return file_proto_admin_proto_rawDescGZIP(), []int{12} +} + +func (x *ServiceNameRequest) GetName() string { + if x != nil { + return x.Name + } + return "" +} + var File_proto_admin_proto protoreflect.FileDescriptor const file_proto_admin_proto_rawDesc = "" + @@ -584,7 +784,18 @@ const file_proto_admin_proto_rawDesc = "" + "\x11AdminLoginRequest\x12\x1a\n" + "\busername\x18\x01 \x01(\tR\busername\x12\x1a\n" + "\bpassword\x18\x02 \x01(\tR\bpassword\"\x13\n" + - "\x11AdminEmptyRequest2\xaa\x06\n" + + "\x11AdminEmptyRequest\"\x1d\n" + + "\vInfoRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"Z\n" + + "\x12ServiceEditRequest\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x12\n" + + "\x04name\x18\x02 \x01(\tR\x04name\x12 \n" + + "\vdescription\x18\x03 \x01(\tR\vdescription\"A\n" + + "\x13ServiceItemsRequest\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name\x12\x16\n" + + "\x06status\x18\x02 \x01(\x05R\x06status\"(\n" + + "\x12ServiceNameRequest\x12\x12\n" + + "\x04name\x18\x01 \x01(\tR\x04name2\xfd\t\n" + "\x05Admin\x12V\n" + "\tAdminEdit\x12\x17.admin.AdminEditRequest\x1a\x0f.admin.Response\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\"\x14/admin/v3/admin/edit\x12W\n" + "\vAdminStatus\x12\x14.admin.StatusRequest\x1a\x0f.admin.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/admin/v3/admin/status\x12X\n" + @@ -596,7 +807,12 @@ const file_proto_admin_proto_rawDesc = "" + "\n" + "AdminLogin\x12\x18.admin.AdminLoginRequest\x1a\x0f.admin.Response\"\x1a\x82\xd3\xe4\x93\x02\x14:\x01*\"\x0f/admin/v3/login\x12W\n" + "\fAdminRefresh\x12\x18.admin.AdminEmptyRequest\x1a\x0f.admin.Response\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\"\x11/admin/v3/refresh\x12Q\n" + - "\tLoginInfo\x12\x18.admin.AdminEmptyRequest\x1a\x0f.admin.Response\"\x19\x82\xd3\xe4\x93\x02\x13:\x01*\"\x0e/admin/v3/infoB\tZ\a./adminb\x06proto3" + "\tLoginInfo\x12\x18.admin.AdminEmptyRequest\x1a\x0f.admin.Response\"\x19\x82\xd3\xe4\x93\x02\x13:\x01*\"\x0e/admin/v3/info\x12U\n" + + "\vServiceInfo\x12\x12.admin.InfoRequest\x1a\x0f.admin.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/admin/v3/service/info\x12\\\n" + + "\vServiceEdit\x12\x19.admin.ServiceEditRequest\x1a\x0f.admin.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\"\x16/admin/v3/service/edit\x12_\n" + + "\fServiceItems\x12\x1a.admin.ServiceItemsRequest\x1a\x0f.admin.Response\"\"\x82\xd3\xe4\x93\x02\x1c:\x01*\"\x17/admin/v3/service/items\x12[\n" + + "\rServiceStatus\x12\x14.admin.StatusRequest\x1a\x0f.admin.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\"\x18/admin/v3/service/status\x12^\n" + + "\fServiceNames\x12\x19.admin.ServiceNameRequest\x1a\x0f.admin.Response\"\"\x82\xd3\xe4\x93\x02\x1c:\x01*\"\x17/admin/v3/service/namesB\tZ\a./adminb\x06proto3" var ( file_proto_admin_proto_rawDescOnce sync.Once @@ -610,42 +826,56 @@ func file_proto_admin_proto_rawDescGZIP() []byte { return file_proto_admin_proto_rawDescData } -var file_proto_admin_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_proto_admin_proto_msgTypes = make([]protoimpl.MessageInfo, 13) var file_proto_admin_proto_goTypes = []any{ - (*AdminEditRequest)(nil), // 0: admin.AdminEditRequest - (*StatusRequest)(nil), // 1: admin.StatusRequest - (*Response)(nil), // 2: admin.Response - (*PasswordRequest)(nil), // 3: admin.PasswordRequest - (*OwnPasswordRequest)(nil), // 4: admin.OwnPasswordRequest - (*AdminInfoRequest)(nil), // 5: admin.AdminInfoRequest - (*AdminItemsRequest)(nil), // 6: admin.AdminItemsRequest - (*AdminLoginRequest)(nil), // 7: admin.AdminLoginRequest - (*AdminEmptyRequest)(nil), // 8: admin.AdminEmptyRequest + (*AdminEditRequest)(nil), // 0: admin.AdminEditRequest + (*StatusRequest)(nil), // 1: admin.StatusRequest + (*Response)(nil), // 2: admin.Response + (*PasswordRequest)(nil), // 3: admin.PasswordRequest + (*OwnPasswordRequest)(nil), // 4: admin.OwnPasswordRequest + (*AdminInfoRequest)(nil), // 5: admin.AdminInfoRequest + (*AdminItemsRequest)(nil), // 6: admin.AdminItemsRequest + (*AdminLoginRequest)(nil), // 7: admin.AdminLoginRequest + (*AdminEmptyRequest)(nil), // 8: admin.AdminEmptyRequest + (*InfoRequest)(nil), // 9: admin.InfoRequest + (*ServiceEditRequest)(nil), // 10: admin.ServiceEditRequest + (*ServiceItemsRequest)(nil), // 11: admin.ServiceItemsRequest + (*ServiceNameRequest)(nil), // 12: admin.ServiceNameRequest } var file_proto_admin_proto_depIdxs = []int32{ - 0, // 0: admin.Admin.AdminEdit:input_type -> admin.AdminEditRequest - 1, // 1: admin.Admin.AdminStatus:input_type -> admin.StatusRequest - 3, // 2: admin.Admin.Password:input_type -> admin.PasswordRequest - 4, // 3: admin.Admin.OwnPassword:input_type -> admin.OwnPasswordRequest - 5, // 4: admin.Admin.AdminInfo:input_type -> admin.AdminInfoRequest - 6, // 5: admin.Admin.AdminItems:input_type -> admin.AdminItemsRequest - 7, // 6: admin.Admin.AdminLogin:input_type -> admin.AdminLoginRequest - 8, // 7: admin.Admin.AdminRefresh:input_type -> admin.AdminEmptyRequest - 8, // 8: admin.Admin.LoginInfo:input_type -> admin.AdminEmptyRequest - 2, // 9: admin.Admin.AdminEdit:output_type -> admin.Response - 2, // 10: admin.Admin.AdminStatus:output_type -> admin.Response - 2, // 11: admin.Admin.Password:output_type -> admin.Response - 2, // 12: admin.Admin.OwnPassword:output_type -> admin.Response - 2, // 13: admin.Admin.AdminInfo:output_type -> admin.Response - 2, // 14: admin.Admin.AdminItems:output_type -> admin.Response - 2, // 15: admin.Admin.AdminLogin:output_type -> admin.Response - 2, // 16: admin.Admin.AdminRefresh:output_type -> admin.Response - 2, // 17: admin.Admin.LoginInfo:output_type -> admin.Response - 9, // [9:18] is the sub-list for method output_type - 0, // [0:9] 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 + 0, // 0: admin.Admin.AdminEdit:input_type -> admin.AdminEditRequest + 1, // 1: admin.Admin.AdminStatus:input_type -> admin.StatusRequest + 3, // 2: admin.Admin.Password:input_type -> admin.PasswordRequest + 4, // 3: admin.Admin.OwnPassword:input_type -> admin.OwnPasswordRequest + 5, // 4: admin.Admin.AdminInfo:input_type -> admin.AdminInfoRequest + 6, // 5: admin.Admin.AdminItems:input_type -> admin.AdminItemsRequest + 7, // 6: admin.Admin.AdminLogin:input_type -> admin.AdminLoginRequest + 8, // 7: admin.Admin.AdminRefresh:input_type -> admin.AdminEmptyRequest + 8, // 8: admin.Admin.LoginInfo:input_type -> admin.AdminEmptyRequest + 9, // 9: admin.Admin.ServiceInfo:input_type -> admin.InfoRequest + 10, // 10: admin.Admin.ServiceEdit:input_type -> admin.ServiceEditRequest + 11, // 11: admin.Admin.ServiceItems:input_type -> admin.ServiceItemsRequest + 1, // 12: admin.Admin.ServiceStatus:input_type -> admin.StatusRequest + 12, // 13: admin.Admin.ServiceNames:input_type -> admin.ServiceNameRequest + 2, // 14: admin.Admin.AdminEdit:output_type -> admin.Response + 2, // 15: admin.Admin.AdminStatus:output_type -> admin.Response + 2, // 16: admin.Admin.Password:output_type -> admin.Response + 2, // 17: admin.Admin.OwnPassword:output_type -> admin.Response + 2, // 18: admin.Admin.AdminInfo:output_type -> admin.Response + 2, // 19: admin.Admin.AdminItems:output_type -> admin.Response + 2, // 20: admin.Admin.AdminLogin:output_type -> admin.Response + 2, // 21: admin.Admin.AdminRefresh:output_type -> admin.Response + 2, // 22: admin.Admin.LoginInfo:output_type -> admin.Response + 2, // 23: admin.Admin.ServiceInfo:output_type -> admin.Response + 2, // 24: admin.Admin.ServiceEdit:output_type -> admin.Response + 2, // 25: admin.Admin.ServiceItems:output_type -> admin.Response + 2, // 26: admin.Admin.ServiceStatus:output_type -> admin.Response + 2, // 27: admin.Admin.ServiceNames:output_type -> admin.Response + 14, // [14:28] is the sub-list for method output_type + 0, // [0:14] 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 } func init() { file_proto_admin_proto_init() } @@ -659,7 +889,7 @@ func file_proto_admin_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_proto_admin_proto_rawDesc), len(file_proto_admin_proto_rawDesc)), NumEnums: 0, - NumMessages: 9, + NumMessages: 13, NumExtensions: 0, NumServices: 1, }, diff --git a/admin/admin/admin_grpc.pb.go b/admin/admin/admin_grpc.pb.go index 0aab2b9..0225ed9 100644 --- a/admin/admin/admin_grpc.pb.go +++ b/admin/admin/admin_grpc.pb.go @@ -19,15 +19,20 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - Admin_AdminEdit_FullMethodName = "/admin.Admin/AdminEdit" - Admin_AdminStatus_FullMethodName = "/admin.Admin/AdminStatus" - Admin_Password_FullMethodName = "/admin.Admin/Password" - Admin_OwnPassword_FullMethodName = "/admin.Admin/OwnPassword" - Admin_AdminInfo_FullMethodName = "/admin.Admin/AdminInfo" - Admin_AdminItems_FullMethodName = "/admin.Admin/AdminItems" - Admin_AdminLogin_FullMethodName = "/admin.Admin/AdminLogin" - Admin_AdminRefresh_FullMethodName = "/admin.Admin/AdminRefresh" - Admin_LoginInfo_FullMethodName = "/admin.Admin/LoginInfo" + Admin_AdminEdit_FullMethodName = "/admin.Admin/AdminEdit" + Admin_AdminStatus_FullMethodName = "/admin.Admin/AdminStatus" + Admin_Password_FullMethodName = "/admin.Admin/Password" + Admin_OwnPassword_FullMethodName = "/admin.Admin/OwnPassword" + Admin_AdminInfo_FullMethodName = "/admin.Admin/AdminInfo" + Admin_AdminItems_FullMethodName = "/admin.Admin/AdminItems" + Admin_AdminLogin_FullMethodName = "/admin.Admin/AdminLogin" + Admin_AdminRefresh_FullMethodName = "/admin.Admin/AdminRefresh" + Admin_LoginInfo_FullMethodName = "/admin.Admin/LoginInfo" + Admin_ServiceInfo_FullMethodName = "/admin.Admin/ServiceInfo" + Admin_ServiceEdit_FullMethodName = "/admin.Admin/ServiceEdit" + Admin_ServiceItems_FullMethodName = "/admin.Admin/ServiceItems" + Admin_ServiceStatus_FullMethodName = "/admin.Admin/ServiceStatus" + Admin_ServiceNames_FullMethodName = "/admin.Admin/ServiceNames" ) // AdminClient is the client API for Admin service. @@ -43,6 +48,11 @@ type AdminClient interface { AdminLogin(ctx context.Context, in *AdminLoginRequest, opts ...grpc.CallOption) (*Response, error) AdminRefresh(ctx context.Context, in *AdminEmptyRequest, opts ...grpc.CallOption) (*Response, error) LoginInfo(ctx context.Context, in *AdminEmptyRequest, opts ...grpc.CallOption) (*Response, error) + ServiceInfo(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*Response, error) + ServiceEdit(ctx context.Context, in *ServiceEditRequest, opts ...grpc.CallOption) (*Response, error) + ServiceItems(ctx context.Context, in *ServiceItemsRequest, opts ...grpc.CallOption) (*Response, error) + ServiceStatus(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) + ServiceNames(ctx context.Context, in *ServiceNameRequest, opts ...grpc.CallOption) (*Response, error) } type adminClient struct { @@ -143,6 +153,56 @@ func (c *adminClient) LoginInfo(ctx context.Context, in *AdminEmptyRequest, opts return out, nil } +func (c *adminClient) ServiceInfo(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Admin_ServiceInfo_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *adminClient) ServiceEdit(ctx context.Context, in *ServiceEditRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Admin_ServiceEdit_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *adminClient) ServiceItems(ctx context.Context, in *ServiceItemsRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Admin_ServiceItems_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *adminClient) ServiceStatus(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Admin_ServiceStatus_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *adminClient) ServiceNames(ctx context.Context, in *ServiceNameRequest, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Admin_ServiceNames_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // AdminServer is the server API for Admin service. // All implementations must embed UnimplementedAdminServer // for forward compatibility. @@ -156,6 +216,11 @@ type AdminServer interface { AdminLogin(context.Context, *AdminLoginRequest) (*Response, error) AdminRefresh(context.Context, *AdminEmptyRequest) (*Response, error) LoginInfo(context.Context, *AdminEmptyRequest) (*Response, error) + ServiceInfo(context.Context, *InfoRequest) (*Response, error) + ServiceEdit(context.Context, *ServiceEditRequest) (*Response, error) + ServiceItems(context.Context, *ServiceItemsRequest) (*Response, error) + ServiceStatus(context.Context, *StatusRequest) (*Response, error) + ServiceNames(context.Context, *ServiceNameRequest) (*Response, error) mustEmbedUnimplementedAdminServer() } @@ -193,6 +258,21 @@ func (UnimplementedAdminServer) AdminRefresh(context.Context, *AdminEmptyRequest func (UnimplementedAdminServer) LoginInfo(context.Context, *AdminEmptyRequest) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method LoginInfo not implemented") } +func (UnimplementedAdminServer) ServiceInfo(context.Context, *InfoRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ServiceInfo not implemented") +} +func (UnimplementedAdminServer) ServiceEdit(context.Context, *ServiceEditRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ServiceEdit not implemented") +} +func (UnimplementedAdminServer) ServiceItems(context.Context, *ServiceItemsRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ServiceItems not implemented") +} +func (UnimplementedAdminServer) ServiceStatus(context.Context, *StatusRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ServiceStatus not implemented") +} +func (UnimplementedAdminServer) ServiceNames(context.Context, *ServiceNameRequest) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method ServiceNames not implemented") +} func (UnimplementedAdminServer) mustEmbedUnimplementedAdminServer() {} func (UnimplementedAdminServer) testEmbeddedByValue() {} @@ -376,6 +456,96 @@ func _Admin_LoginInfo_Handler(srv interface{}, ctx context.Context, dec func(int return interceptor(ctx, in, info, handler) } +func _Admin_ServiceInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InfoRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServer).ServiceInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Admin_ServiceInfo_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServer).ServiceInfo(ctx, req.(*InfoRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Admin_ServiceEdit_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ServiceEditRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServer).ServiceEdit(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Admin_ServiceEdit_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServer).ServiceEdit(ctx, req.(*ServiceEditRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Admin_ServiceItems_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ServiceItemsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServer).ServiceItems(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Admin_ServiceItems_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServer).ServiceItems(ctx, req.(*ServiceItemsRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Admin_ServiceStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(StatusRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServer).ServiceStatus(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Admin_ServiceStatus_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServer).ServiceStatus(ctx, req.(*StatusRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Admin_ServiceNames_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ServiceNameRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(AdminServer).ServiceNames(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Admin_ServiceNames_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(AdminServer).ServiceNames(ctx, req.(*ServiceNameRequest)) + } + return interceptor(ctx, in, info, handler) +} + // Admin_ServiceDesc is the grpc.ServiceDesc for Admin service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -419,6 +589,26 @@ var Admin_ServiceDesc = grpc.ServiceDesc{ MethodName: "LoginInfo", Handler: _Admin_LoginInfo_Handler, }, + { + MethodName: "ServiceInfo", + Handler: _Admin_ServiceInfo_Handler, + }, + { + MethodName: "ServiceEdit", + Handler: _Admin_ServiceEdit_Handler, + }, + { + MethodName: "ServiceItems", + Handler: _Admin_ServiceItems_Handler, + }, + { + MethodName: "ServiceStatus", + Handler: _Admin_ServiceStatus_Handler, + }, + { + MethodName: "ServiceNames", + Handler: _Admin_ServiceNames_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "proto/admin.proto", diff --git a/admin/adminclient/admin.go b/admin/adminclient/admin.go index ac0429d..9091046 100644 --- a/admin/adminclient/admin.go +++ b/admin/adminclient/admin.go @@ -14,15 +14,19 @@ import ( ) type ( - AdminEditRequest = admin.AdminEditRequest - AdminEmptyRequest = admin.AdminEmptyRequest - AdminInfoRequest = admin.AdminInfoRequest - AdminItemsRequest = admin.AdminItemsRequest - AdminLoginRequest = admin.AdminLoginRequest - OwnPasswordRequest = admin.OwnPasswordRequest - PasswordRequest = admin.PasswordRequest - Response = admin.Response - StatusRequest = admin.StatusRequest + AdminEditRequest = admin.AdminEditRequest + AdminEmptyRequest = admin.AdminEmptyRequest + AdminInfoRequest = admin.AdminInfoRequest + AdminItemsRequest = admin.AdminItemsRequest + AdminLoginRequest = admin.AdminLoginRequest + InfoRequest = admin.InfoRequest + OwnPasswordRequest = admin.OwnPasswordRequest + PasswordRequest = admin.PasswordRequest + Response = admin.Response + ServiceEditRequest = admin.ServiceEditRequest + ServiceItemsRequest = admin.ServiceItemsRequest + ServiceNameRequest = admin.ServiceNameRequest + StatusRequest = admin.StatusRequest Admin interface { AdminEdit(ctx context.Context, in *AdminEditRequest, opts ...grpc.CallOption) (*Response, error) @@ -34,6 +38,11 @@ type ( AdminLogin(ctx context.Context, in *AdminLoginRequest, opts ...grpc.CallOption) (*Response, error) AdminRefresh(ctx context.Context, in *AdminEmptyRequest, opts ...grpc.CallOption) (*Response, error) LoginInfo(ctx context.Context, in *AdminEmptyRequest, opts ...grpc.CallOption) (*Response, error) + ServiceInfo(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*Response, error) + ServiceEdit(ctx context.Context, in *ServiceEditRequest, opts ...grpc.CallOption) (*Response, error) + ServiceItems(ctx context.Context, in *ServiceItemsRequest, opts ...grpc.CallOption) (*Response, error) + ServiceStatus(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) + ServiceNames(ctx context.Context, in *ServiceNameRequest, opts ...grpc.CallOption) (*Response, error) } defaultAdmin struct { @@ -91,3 +100,28 @@ func (m *defaultAdmin) LoginInfo(ctx context.Context, in *AdminEmptyRequest, opt client := admin.NewAdminClient(m.cli.Conn()) return client.LoginInfo(ctx, in, opts...) } + +func (m *defaultAdmin) ServiceInfo(ctx context.Context, in *InfoRequest, opts ...grpc.CallOption) (*Response, error) { + client := admin.NewAdminClient(m.cli.Conn()) + return client.ServiceInfo(ctx, in, opts...) +} + +func (m *defaultAdmin) ServiceEdit(ctx context.Context, in *ServiceEditRequest, opts ...grpc.CallOption) (*Response, error) { + client := admin.NewAdminClient(m.cli.Conn()) + return client.ServiceEdit(ctx, in, opts...) +} + +func (m *defaultAdmin) ServiceItems(ctx context.Context, in *ServiceItemsRequest, opts ...grpc.CallOption) (*Response, error) { + client := admin.NewAdminClient(m.cli.Conn()) + return client.ServiceItems(ctx, in, opts...) +} + +func (m *defaultAdmin) ServiceStatus(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (*Response, error) { + client := admin.NewAdminClient(m.cli.Conn()) + return client.ServiceStatus(ctx, in, opts...) +} + +func (m *defaultAdmin) ServiceNames(ctx context.Context, in *ServiceNameRequest, opts ...grpc.CallOption) (*Response, error) { + client := admin.NewAdminClient(m.cli.Conn()) + return client.ServiceNames(ctx, in, opts...) +} diff --git a/admin/internal/dao/servers.go b/admin/internal/dao/servers.go index 73145ff..0af56e4 100644 --- a/admin/internal/dao/servers.go +++ b/admin/internal/dao/servers.go @@ -1,36 +1,27 @@ package dao -import "pkg.local/utils" - // Services 项目表 type Services struct { - Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` - Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"` - Status uint8 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"` - Remarks string `gorm:"column:remarks;type:varchar(255);default:'';comment:描述;NOT NULL" json:"remarks"` - Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"` - AdminId int `gorm:"column:admin_id;type:int(11);comment:操作人员ID" json:"admin_id"` - AdminName string `gorm:"column:admin_name;type:varchar(255);comment:操作人员姓名" json:"admin_name"` - CreateTime utils.CustomTime `gorm:"column:create_time;type:datetime" json:"create_time"` - UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime" json:"update_time"` -} - -type ServicesItems struct { - Items []Services `json:"items"` - Count int64 `json:"count"` + Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` + Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"` + Status uint8 `gorm:"column:status;type:tinyint(1);default:1;comment:状态,1为正常,2为禁用;NOT NULL" json:"status"` + Description string `json:"description" gorm:"description"` // 描述 + Reason string `json:"reason" gorm:"reason"` // 理由 + AdminId int64 `gorm:"column:admin_id;type:int(11);comment:操作人员ID" json:"admin_id"` + AdminName string `gorm:"column:admin_name;type:varchar(255);comment:操作人员姓名" json:"admin_name"` } // ServicesStatus 修改状态 type ServicesStatus struct { - Id int `json:"id"` - Status uint8 `json:"status"` - Reason string `gorm:"column:reason;type:varchar(255);comment:原因" json:"reason"` - AdminId int `json:"admin_id"` - AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"` - UpdateTime utils.CustomTime `gorm:"column:update_time;type:datetime" json:"update_time"` + Id int64 `json:"id"` + Status uint8 `json:"status"` + Reason string `json:"reason" gorm:"reason"` // 理由 + AdminId int64 `json:"admin_id"` + AdminName string `gorm:"column:admin_name;type:varchar(100);comment:操作人姓名" json:"admin_name"` } -type ServicesNameItems struct { - Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` - Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"` +type ServicesNames struct { + Id int64 `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"` + Name string `gorm:"column:name;type:varchar(255);comment:项目描述;NOT NULL" json:"name"` + Description string `json:"description" gorm:"description"` // 描述 } diff --git a/admin/internal/logic/adminitemslogic.go b/admin/internal/logic/adminitemslogic.go index 2c7166d..ca40982 100644 --- a/admin/internal/logic/adminitemslogic.go +++ b/admin/internal/logic/adminitemslogic.go @@ -103,12 +103,12 @@ func (l *AdminItemsLogic) getRoleInfos(data []dao.AdminInfo) map[string]dao.Role } w = modelbase.Params{} - var serversItems []dao.ServicesNameItems + var serversItems []dao.ServicesNames pErr := model.ServicesModel{}.Init().Items(w, &serversItems) serverIds := make(map[int]string) if pErr == nil { for _, item := range serversItems { - serverIds[item.Id] = item.Name + serverIds[int(item.Id)] = item.Name } } for i := utils.NumberZero; i < len(items); i++ { diff --git a/admin/internal/logic/serviceeditlogic.go b/admin/internal/logic/serviceeditlogic.go new file mode 100644 index 0000000..00a3738 --- /dev/null +++ b/admin/internal/logic/serviceeditlogic.go @@ -0,0 +1,74 @@ +package logic + +import ( + "admin/internal/dao" + "admin/internal/model" + "admin/validator" + "context" + "strconv" + + "admin/admin" + "admin/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" + "pkg.local/modelbase" + "pkg.local/utils" +) + +type ServiceEditLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewServiceEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceEditLogic { + return &ServiceEditLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ServiceEditLogic) ServiceEdit(in *admin.ServiceEditRequest) (*admin.Response, error) { + var v validator.ServiceEditValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo), nil + } + edit := dao.Services{ + Name: in.Name, + Description: in.Description, + AdminId: adminInfo.ID, + AdminName: adminInfo.Name, + } + + modelObj := model.ServicesModel{}.Init() + var err error + if in.Id > utils.NumberZero { + w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}} + info := dao.Services{} + err = modelObj.GetOne(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail), nil + } + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund), nil + } + edit.Id = info.Id + _, err = modelObj.Edit(w, &edit) + } else { + err = modelObj.Create(&edit) + } + + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail), nil + } + + return l.ok(edit.Id), nil +} diff --git a/admin/internal/logic/serviceinfologic.go b/admin/internal/logic/serviceinfologic.go new file mode 100644 index 0000000..d24a4ef --- /dev/null +++ b/admin/internal/logic/serviceinfologic.go @@ -0,0 +1,47 @@ +package logic + +import ( + "admin/internal/dao" + "admin/internal/model" + "admin/validator" + "context" + "strconv" + + "admin/admin" + "admin/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" + "pkg.local/modelbase" + "pkg.local/utils" +) + +type ServiceInfoLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewServiceInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceInfoLogic { + return &ServiceInfoLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ServiceInfoLogic) ServiceInfo(in *admin.InfoRequest) (*admin.Response, error) { + var v validator.ServiceInfoValidator + l.Logger.Error(in.Id) + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + + info := dao.Services{} + w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}} + err := model.ServicesModel{}.Init().GetOne(w, &info) + if err != nil { + return l.fail(utils.ErrorNotFund), nil + } + return l.ok(info), nil +} diff --git a/admin/internal/logic/serviceitemslogic.go b/admin/internal/logic/serviceitemslogic.go new file mode 100644 index 0000000..4a51510 --- /dev/null +++ b/admin/internal/logic/serviceitemslogic.go @@ -0,0 +1,51 @@ +package logic + +import ( + "admin/internal/dao" + "admin/internal/model" + "context" + "strconv" + + "admin/admin" + "admin/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" + "pkg.local/modelbase" + "pkg.local/utils" +) + +type ServiceItemsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewServiceItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceItemsLogic { + return &ServiceItemsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ServiceItemsLogic) ServiceItems(in *admin.ServiceItemsRequest) (*admin.Response, error) { + modelObj := model.ServicesModel{}.Init() + w := modelbase.Params{ + Order: "id desc", + } + w.Like = make(map[string]string) + if in.Status > utils.NumberZero { + w.Eq = map[string]string{"status": strconv.Itoa(int(in.Status))} + } + if len(in.Name) > utils.NumberZero { + w.Like["name LIKE ? "] = "%%" + in.Name + "%%" + } + var data []dao.Services + err := modelObj.Items(w, &data) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail), nil + } + return l.ok(data), nil +} diff --git a/admin/internal/logic/servicenameslogic.go b/admin/internal/logic/servicenameslogic.go new file mode 100644 index 0000000..7dc1058 --- /dev/null +++ b/admin/internal/logic/servicenameslogic.go @@ -0,0 +1,46 @@ +package logic + +import ( + "admin/admin" + "admin/internal/dao" + "admin/internal/model" + "admin/internal/svc" + "context" + + "github.com/zeromicro/go-zero/core/logx" + "pkg.local/modelbase" + "pkg.local/utils" +) + +type ServiceNamesLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewServiceNamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceNamesLogic { + return &ServiceNamesLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ServiceNamesLogic) ServiceNames(in *admin.ServiceNameRequest) (*admin.Response, error) { + var items []dao.ServicesNames + modelObj := model.ServicesModel{}.Init() + w := modelbase.Params{ + Eq: map[string]string{"status": utils.StringStatusOk}, + } + w.Like = make(map[string]string) + if len(in.Name) > utils.NumberZero { + w.Like["name LIKE ? "] = "%%" + in.Name + "%%" + } + err := modelObj.Items(w, &items) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail), nil + } + return l.ok(items), nil +} diff --git a/admin/internal/logic/servicestatuslogic.go b/admin/internal/logic/servicestatuslogic.go new file mode 100644 index 0000000..bf043a1 --- /dev/null +++ b/admin/internal/logic/servicestatuslogic.go @@ -0,0 +1,65 @@ +package logic + +import ( + "admin/internal/dao" + "admin/internal/model" + "admin/validator" + "context" + "strconv" + + "admin/admin" + "admin/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" + "pkg.local/modelbase" + "pkg.local/utils" +) + +type ServiceStatusLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger + BaseLogic +} + +func NewServiceStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ServiceStatusLogic { + return &ServiceStatusLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ServiceStatusLogic) ServiceStatus(in *admin.StatusRequest) (*admin.Response, error) { + var v validator.ServiceStatusValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo), nil + } + info := dao.ServicesStatus{} + w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}} + modelObj := model.ServicesModel{}.Init() + err := modelObj.GetOne(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail), nil + } + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund), nil + } + + info.Status = uint8(in.Status) + info.Reason = in.Reason + info.AdminName = adminInfo.Name + info.AdminId = adminInfo.ID + _, editErr := modelObj.Edit(w, info) + if editErr != nil { + l.Logger.Error(editErr) + return l.fail(utils.Fail), nil + } + + return l.ok(utils.NumberOne), nil +} diff --git a/admin/internal/model/services.go b/admin/internal/model/services.go index 772c532..968dae5 100644 --- a/admin/internal/model/services.go +++ b/admin/internal/model/services.go @@ -19,6 +19,6 @@ func (m ServicesModel) Init() ServicesModel { return m } -func (m ServicesModel) Create(data *dao.Admin) error { +func (m ServicesModel) Create(data *dao.Services) error { return m.Base.Create(data) } diff --git a/admin/internal/server/adminserver.go b/admin/internal/server/adminserver.go index 832a393..9d5837e 100644 --- a/admin/internal/server/adminserver.go +++ b/admin/internal/server/adminserver.go @@ -67,3 +67,28 @@ func (s *AdminServer) LoginInfo(ctx context.Context, in *admin.AdminEmptyRequest l := logic.NewLoginInfoLogic(ctx, s.svcCtx) return l.LoginInfo(in) } + +func (s *AdminServer) ServiceInfo(ctx context.Context, in *admin.InfoRequest) (*admin.Response, error) { + l := logic.NewServiceInfoLogic(ctx, s.svcCtx) + return l.ServiceInfo(in) +} + +func (s *AdminServer) ServiceEdit(ctx context.Context, in *admin.ServiceEditRequest) (*admin.Response, error) { + l := logic.NewServiceEditLogic(ctx, s.svcCtx) + return l.ServiceEdit(in) +} + +func (s *AdminServer) ServiceItems(ctx context.Context, in *admin.ServiceItemsRequest) (*admin.Response, error) { + l := logic.NewServiceItemsLogic(ctx, s.svcCtx) + return l.ServiceItems(in) +} + +func (s *AdminServer) ServiceStatus(ctx context.Context, in *admin.StatusRequest) (*admin.Response, error) { + l := logic.NewServiceStatusLogic(ctx, s.svcCtx) + return l.ServiceStatus(in) +} + +func (s *AdminServer) ServiceNames(ctx context.Context, in *admin.ServiceNameRequest) (*admin.Response, error) { + l := logic.NewServiceNamesLogic(ctx, s.svcCtx) + return l.ServiceNames(in) +} diff --git a/admin/proto/admin.proto b/admin/proto/admin.proto index 283de22..297620f 100644 --- a/admin/proto/admin.proto +++ b/admin/proto/admin.proto @@ -58,6 +58,25 @@ message AdminLoginRequest { message AdminEmptyRequest { } +message InfoRequest { + int64 id = 1; +} + +message ServiceEditRequest { + int64 id = 1; + string name = 2; + string description = 3; +} + +message ServiceItemsRequest { + string name = 1; + int32 status = 2; +} + +message ServiceNameRequest { + string name = 1; +} + service Admin { rpc AdminEdit(AdminEditRequest) returns(Response){ option (google.api.http) = { @@ -113,4 +132,34 @@ service Admin { body: "*" }; }; + rpc ServiceInfo(InfoRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/service/info" + body: "*" + }; + }; + rpc ServiceEdit(ServiceEditRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/service/edit" + body: "*" + }; + }; + rpc ServiceItems(ServiceItemsRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/service/items" + body: "*" + }; + }; + rpc ServiceStatus(StatusRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/service/status" + body: "*" + }; + }; + rpc ServiceNames(ServiceNameRequest) returns(Response){ + option (google.api.http) = { + post: "/admin/v3/service/names" + body: "*" + }; + }; } \ No newline at end of file diff --git a/admin/validator/validator.go b/admin/validator/admin.go similarity index 100% rename from admin/validator/validator.go rename to admin/validator/admin.go diff --git a/admin/validator/service.go b/admin/validator/service.go new file mode 100644 index 0000000..1350d01 --- /dev/null +++ b/admin/validator/service.go @@ -0,0 +1,46 @@ +package validator + +import ( + "pkg.local/validate" +) + +// ServiceEditValidator 创建/编辑 +type ServiceEditValidator struct { + Name string `validate:"required"` +} + +// GetMessage 创建 - 提示消息 +func (p ServiceEditValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Name.required": "名称不能为空", + } +} + +// ServiceInfoValidator 查看信息 +type ServiceInfoValidator struct { + Id int64 `validate:"required"` +} + +// GetMessage 查看信息 - 提示消息 +func (p ServiceInfoValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Id.required": "ID不能为空", + } +} + +// ServiceStatusValidator 修改状态 +type ServiceStatusValidator struct { + Id int64 `validate:"required"` + Status int32 `validate:"required,oneof=1 2"` + Reason string `validate:"required_if=Status 2"` +} + +// GetMessage 修改状态 - 提示消息 +func (p ServiceStatusValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Id.required": "ID不能为空", + "Status.required": "状态不能为空", + "Status.oneof": "状态传值不对", + "Reason.required_if": "理由不能为空", + } +} diff --git a/bff/etc/admin.pb b/bff/etc/admin.pb index a9d7ac35bd8c9ab2fc5e36b3d6965cf51975cf28..72cfdd1c428219e01b55a8d3694184d6057dfdeb 100644 GIT binary patch delta 483 zcmdl`GP!EQV`HXuLYto&b2GCj$#QW|zH2JO7sVwMoLW?tnVjmHl36nOp{e*}ClgT} z1upKC)Z*l#%z~24{5%O}1x5|dAY>t>OfF%l#>q@(rj9~fEP08!sZf<*wvZSXTX9KZ zNolbJ3s6665R|8+0k_i+s3j=1ur#%}Wb#2i5oV*moSQ$JX)((Pg>rF2jrYt;%NG*T zOH9el%+mvLCKs6N7!^Ytt)B@Luwv8_ih-*K`9nw&svg;IKyCUkZK*&-AZ_tnJTPlY zQge%iq)_!uzH1?;r_^-$$z&!OC2@VQ8}!SJ;l^ZwG=a>C=Hi8#GdbE^Z}LNPVN;k@ ukRSjlii2AQ@^>-1BSC^dze$?mu@Dr-APb#1quBKz?nz=RD9SI%HwFNNG@bhZ delta 44 zcmbPSwV`CgV`HY%Je!{yb2Bp=tzz5EY@x+0?8F(xuBV@vlAD>A#8yz0Uy^SO0B0T! Ao&W#<