From 8fa9cd79a40944edd61db41b9b23a0a147abadb1 Mon Sep 17 00:00:00 2001 From: bx1834938347-prog Date: Thu, 18 Dec 2025 14:14:42 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E4=BF=AE=E6=94=B9=E6=88=90post?= =?UTF-8?q?=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/cron/cron.pb.go | 158 ++++++++++++++++++++++++++++------ api/cron/cron.validator.pb.go | 14 +++ api/cron/cron_triple.pb.go | 46 ++++++++++ pkg/router/cron.go | 12 +-- pkg/service/cron/cron.go | 13 +++ 5 files changed, 214 insertions(+), 29 deletions(-) diff --git a/api/cron/cron.pb.go b/api/cron/cron.pb.go index b92be90..a41008a 100644 --- a/api/cron/cron.pb.go +++ b/api/cron/cron.pb.go @@ -9,6 +9,7 @@ package cron import ( protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" reflect "reflect" sync "sync" unsafe "unsafe" @@ -1533,11 +1534,107 @@ func (x *GetListExecutionResultResponse) GetData() []*ExecutionResult { return nil } +type TaskStatus struct { + state protoimpl.MessageState `protogen:"open.v1"` + Key int32 `protobuf:"varint,1,opt,name=key,proto3" json:"key"` // 状态码 + Value string `protobuf:"bytes,2,opt,name=value,proto3" json:"value"` // 状态描述 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TaskStatus) Reset() { + *x = TaskStatus{} + mi := &file_pb_cron_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TaskStatus) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TaskStatus) ProtoMessage() {} + +func (x *TaskStatus) ProtoReflect() protoreflect.Message { + mi := &file_pb_cron_proto_msgTypes[16] + 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 TaskStatus.ProtoReflect.Descriptor instead. +func (*TaskStatus) Descriptor() ([]byte, []int) { + return file_pb_cron_proto_rawDescGZIP(), []int{16} +} + +func (x *TaskStatus) GetKey() int32 { + if x != nil { + return x.Key + } + return 0 +} + +func (x *TaskStatus) GetValue() string { + if x != nil { + return x.Value + } + return "" +} + +type GetScheduleTaskStatusResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Status []*TaskStatus `protobuf:"bytes,1,rep,name=status,proto3" json:"status"` // 多个任务状态 + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetScheduleTaskStatusResponse) Reset() { + *x = GetScheduleTaskStatusResponse{} + mi := &file_pb_cron_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetScheduleTaskStatusResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetScheduleTaskStatusResponse) ProtoMessage() {} + +func (x *GetScheduleTaskStatusResponse) ProtoReflect() protoreflect.Message { + mi := &file_pb_cron_proto_msgTypes[17] + 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 GetScheduleTaskStatusResponse.ProtoReflect.Descriptor instead. +func (*GetScheduleTaskStatusResponse) Descriptor() ([]byte, []int) { + return file_pb_cron_proto_rawDescGZIP(), []int{17} +} + +func (x *GetScheduleTaskStatusResponse) GetStatus() []*TaskStatus { + if x != nil { + return x.Status + } + return nil +} + var File_pb_cron_proto protoreflect.FileDescriptor const file_pb_cron_proto_rawDesc = "" + "\n" + - "\rpb/cron.proto\x12\x04cron\"!\n" + + "\rpb/cron.proto\x12\x04cron\x1a\x1bgoogle/protobuf/empty.proto\"!\n" + "\x0fCommonIDRequest\x12\x0e\n" + "\x02id\x18\x01 \x01(\rR\x02id\">\n" + "\x0eCommonResponse\x12\x12\n" + @@ -1704,7 +1801,13 @@ const file_pb_cron_proto_rawDesc = "" + "\x05total\x18\x03 \x01(\x03R\x05total\x12\x12\n" + "\x04page\x18\x04 \x01(\x05R\x04page\x12\x12\n" + "\x04size\x18\x05 \x01(\x05R\x04size\x12)\n" + - "\x04data\x18\x06 \x03(\v2\x15.cron.ExecutionResultR\x04data2\xda\x04\n" + + "\x04data\x18\x06 \x03(\v2\x15.cron.ExecutionResultR\x04data\"4\n" + + "\n" + + "TaskStatus\x12\x10\n" + + "\x03key\x18\x01 \x01(\x05R\x03key\x12\x14\n" + + "\x05value\x18\x02 \x01(\tR\x05value\"I\n" + + "\x1dGetScheduleTaskStatusResponse\x12(\n" + + "\x06status\x18\x01 \x03(\v2\x10.cron.TaskStatusR\x06status2\xb2\x05\n" + "\x04Cron\x12Y\n" + "\x12CreateScheduleTask\x12\x1f.cron.CreateScheduleTaskRequest\x1a .cron.CreateScheduleTaskResponse\"\x00\x12\\\n" + "\x13GetListScheduleTask\x12 .cron.GetListScheduleTaskRequest\x1a!.cron.GetListScheduleTaskResponse\"\x00\x12e\n" + @@ -1712,7 +1815,8 @@ const file_pb_cron_proto_rawDesc = "" + "\x16GetListExecutionResult\x12#.cron.GetListExecutionResultRequest\x1a$.cron.GetListExecutionResultResponse\"\x00\x12B\n" + "\x11PauseScheduleTask\x12\x15.cron.CommonIDRequest\x1a\x14.cron.CommonResponse\"\x00\x12B\n" + "\x11StartScheduleTask\x12\x15.cron.CommonIDRequest\x1a\x14.cron.CommonResponse\"\x00\x12C\n" + - "\x12DeleteScheduleTask\x12\x15.cron.CommonIDRequest\x1a\x14.cron.CommonResponse\"\x00B\bZ\x06./cronb\x06proto3" + "\x12DeleteScheduleTask\x12\x15.cron.CommonIDRequest\x1a\x14.cron.CommonResponse\"\x00\x12V\n" + + "\x15GetScheduleTaskStatus\x12\x16.google.protobuf.Empty\x1a#.cron.GetScheduleTaskStatusResponse\"\x00B\bZ\x06./cronb\x06proto3" var ( file_pb_cron_proto_rawDescOnce sync.Once @@ -1726,7 +1830,7 @@ func file_pb_cron_proto_rawDescGZIP() []byte { return file_pb_cron_proto_rawDescData } -var file_pb_cron_proto_msgTypes = make([]protoimpl.MessageInfo, 16) +var file_pb_cron_proto_msgTypes = make([]protoimpl.MessageInfo, 18) var file_pb_cron_proto_goTypes = []any{ (*CommonIDRequest)(nil), // 0: cron.CommonIDRequest (*CommonResponse)(nil), // 1: cron.CommonResponse @@ -1744,6 +1848,9 @@ var file_pb_cron_proto_goTypes = []any{ (*GetListExecutionRecordResponse)(nil), // 13: cron.GetListExecutionRecordResponse (*GetListExecutionResultRequest)(nil), // 14: cron.GetListExecutionResultRequest (*GetListExecutionResultResponse)(nil), // 15: cron.GetListExecutionResultResponse + (*TaskStatus)(nil), // 16: cron.TaskStatus + (*GetScheduleTaskStatusResponse)(nil), // 17: cron.GetScheduleTaskStatusResponse + (*emptypb.Empty)(nil), // 18: google.protobuf.Empty } var file_pb_cron_proto_depIdxs = []int32{ 5, // 0: cron.ScheduleTask.task_detail:type_name -> cron.TaskDetail @@ -1756,25 +1863,28 @@ var file_pb_cron_proto_depIdxs = []int32{ 2, // 7: cron.GetListScheduleTaskResponse.data:type_name -> cron.ScheduleTask 3, // 8: cron.GetListExecutionRecordResponse.data:type_name -> cron.ExecutionRecord 4, // 9: cron.GetListExecutionResultResponse.data:type_name -> cron.ExecutionResult - 7, // 10: cron.Cron.CreateScheduleTask:input_type -> cron.CreateScheduleTaskRequest - 10, // 11: cron.Cron.GetListScheduleTask:input_type -> cron.GetListScheduleTaskRequest - 12, // 12: cron.Cron.GetListExecutionRecord:input_type -> cron.GetListExecutionRecordRequest - 14, // 13: cron.Cron.GetListExecutionResult:input_type -> cron.GetListExecutionResultRequest - 0, // 14: cron.Cron.PauseScheduleTask:input_type -> cron.CommonIDRequest - 0, // 15: cron.Cron.StartScheduleTask:input_type -> cron.CommonIDRequest - 0, // 16: cron.Cron.DeleteScheduleTask:input_type -> cron.CommonIDRequest - 9, // 17: cron.Cron.CreateScheduleTask:output_type -> cron.CreateScheduleTaskResponse - 11, // 18: cron.Cron.GetListScheduleTask:output_type -> cron.GetListScheduleTaskResponse - 13, // 19: cron.Cron.GetListExecutionRecord:output_type -> cron.GetListExecutionRecordResponse - 15, // 20: cron.Cron.GetListExecutionResult:output_type -> cron.GetListExecutionResultResponse - 1, // 21: cron.Cron.PauseScheduleTask:output_type -> cron.CommonResponse - 1, // 22: cron.Cron.StartScheduleTask:output_type -> cron.CommonResponse - 1, // 23: cron.Cron.DeleteScheduleTask:output_type -> cron.CommonResponse - 17, // [17:24] is the sub-list for method output_type - 10, // [10:17] is the sub-list for method input_type - 10, // [10:10] is the sub-list for extension type_name - 10, // [10:10] is the sub-list for extension extendee - 0, // [0:10] is the sub-list for field type_name + 16, // 10: cron.GetScheduleTaskStatusResponse.status:type_name -> cron.TaskStatus + 7, // 11: cron.Cron.CreateScheduleTask:input_type -> cron.CreateScheduleTaskRequest + 10, // 12: cron.Cron.GetListScheduleTask:input_type -> cron.GetListScheduleTaskRequest + 12, // 13: cron.Cron.GetListExecutionRecord:input_type -> cron.GetListExecutionRecordRequest + 14, // 14: cron.Cron.GetListExecutionResult:input_type -> cron.GetListExecutionResultRequest + 0, // 15: cron.Cron.PauseScheduleTask:input_type -> cron.CommonIDRequest + 0, // 16: cron.Cron.StartScheduleTask:input_type -> cron.CommonIDRequest + 0, // 17: cron.Cron.DeleteScheduleTask:input_type -> cron.CommonIDRequest + 18, // 18: cron.Cron.GetScheduleTaskStatus:input_type -> google.protobuf.Empty + 9, // 19: cron.Cron.CreateScheduleTask:output_type -> cron.CreateScheduleTaskResponse + 11, // 20: cron.Cron.GetListScheduleTask:output_type -> cron.GetListScheduleTaskResponse + 13, // 21: cron.Cron.GetListExecutionRecord:output_type -> cron.GetListExecutionRecordResponse + 15, // 22: cron.Cron.GetListExecutionResult:output_type -> cron.GetListExecutionResultResponse + 1, // 23: cron.Cron.PauseScheduleTask:output_type -> cron.CommonResponse + 1, // 24: cron.Cron.StartScheduleTask:output_type -> cron.CommonResponse + 1, // 25: cron.Cron.DeleteScheduleTask:output_type -> cron.CommonResponse + 17, // 26: cron.Cron.GetScheduleTaskStatus:output_type -> cron.GetScheduleTaskStatusResponse + 19, // [19:27] is the sub-list for method output_type + 11, // [11:19] is the sub-list for method input_type + 11, // [11:11] is the sub-list for extension type_name + 11, // [11:11] is the sub-list for extension extendee + 0, // [0:11] is the sub-list for field type_name } func init() { file_pb_cron_proto_init() } @@ -1788,7 +1898,7 @@ func file_pb_cron_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_pb_cron_proto_rawDesc), len(file_pb_cron_proto_rawDesc)), NumEnums: 0, - NumMessages: 16, + NumMessages: 18, NumExtensions: 0, NumServices: 1, }, diff --git a/api/cron/cron.validator.pb.go b/api/cron/cron.validator.pb.go index 1ee4b41..8ace737 100644 --- a/api/cron/cron.validator.pb.go +++ b/api/cron/cron.validator.pb.go @@ -7,6 +7,7 @@ import ( fmt "fmt" math "math" proto "github.com/golang/protobuf/proto" + _ "google.golang.org/protobuf/types/known/emptypb" github_com_mwitkow_go_proto_validators "github.com/mwitkow/go-proto-validators" ) @@ -127,3 +128,16 @@ func (this *GetListExecutionResultResponse) Validate() error { } return nil } +func (this *TaskStatus) Validate() error { + return nil +} +func (this *GetScheduleTaskStatusResponse) Validate() error { + for _, item := range this.Status { + if item != nil { + if err := github_com_mwitkow_go_proto_validators.CallValidatorIfExists(item); err != nil { + return github_com_mwitkow_go_proto_validators.FieldError("Status", err) + } + } + } + return nil +} diff --git a/api/cron/cron_triple.pb.go b/api/cron/cron_triple.pb.go index 4f95091..676d2d7 100644 --- a/api/cron/cron_triple.pb.go +++ b/api/cron/cron_triple.pb.go @@ -18,6 +18,7 @@ import ( common "github.com/dubbogo/triple/pkg/common" constant "github.com/dubbogo/triple/pkg/common/constant" triple "github.com/dubbogo/triple/pkg/triple" + emptypb "google.golang.org/protobuf/types/known/emptypb" ) // This is a compile-time assertion to ensure that this generated file @@ -35,6 +36,7 @@ type CronClient interface { PauseScheduleTask(ctx context.Context, in *CommonIDRequest, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment) StartScheduleTask(ctx context.Context, in *CommonIDRequest, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment) DeleteScheduleTask(ctx context.Context, in *CommonIDRequest, opts ...grpc_go.CallOption) (*CommonResponse, common.ErrorWithAttachment) + GetScheduleTaskStatus(ctx context.Context, in *emptypb.Empty, opts ...grpc_go.CallOption) (*GetScheduleTaskStatusResponse, common.ErrorWithAttachment) } type cronClient struct { @@ -49,6 +51,7 @@ type CronClientImpl struct { PauseScheduleTask func(ctx context.Context, in *CommonIDRequest) (*CommonResponse, error) StartScheduleTask func(ctx context.Context, in *CommonIDRequest) (*CommonResponse, error) DeleteScheduleTask func(ctx context.Context, in *CommonIDRequest) (*CommonResponse, error) + GetScheduleTaskStatus func(ctx context.Context, in *emptypb.Empty) (*GetScheduleTaskStatusResponse, error) } func (c *CronClientImpl) GetDubboStub(cc *triple.TripleConn) CronClient { @@ -105,6 +108,12 @@ func (c *cronClient) DeleteScheduleTask(ctx context.Context, in *CommonIDRequest return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/DeleteScheduleTask", in, out) } +func (c *cronClient) GetScheduleTaskStatus(ctx context.Context, in *emptypb.Empty, opts ...grpc_go.CallOption) (*GetScheduleTaskStatusResponse, common.ErrorWithAttachment) { + out := new(GetScheduleTaskStatusResponse) + interfaceKey := ctx.Value(constant.InterfaceKey).(string) + return out, c.cc.Invoke(ctx, "/"+interfaceKey+"/GetScheduleTaskStatus", in, out) +} + // CronServer is the server API for Cron service. // All implementations must embed UnimplementedCronServer // for forward compatibility @@ -116,6 +125,7 @@ type CronServer interface { PauseScheduleTask(context.Context, *CommonIDRequest) (*CommonResponse, error) StartScheduleTask(context.Context, *CommonIDRequest) (*CommonResponse, error) DeleteScheduleTask(context.Context, *CommonIDRequest) (*CommonResponse, error) + GetScheduleTaskStatus(context.Context, *emptypb.Empty) (*GetScheduleTaskStatusResponse, error) mustEmbedUnimplementedCronServer() } @@ -145,6 +155,9 @@ func (UnimplementedCronServer) StartScheduleTask(context.Context, *CommonIDReque func (UnimplementedCronServer) DeleteScheduleTask(context.Context, *CommonIDRequest) (*CommonResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method DeleteScheduleTask not implemented") } +func (UnimplementedCronServer) GetScheduleTaskStatus(context.Context, *emptypb.Empty) (*GetScheduleTaskStatusResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetScheduleTaskStatus not implemented") +} func (s *UnimplementedCronServer) XXX_SetProxyImpl(impl protocol.Invoker) { s.proxyImpl = impl } @@ -376,6 +389,35 @@ func _Cron_DeleteScheduleTask_Handler(srv interface{}, ctx context.Context, dec return interceptor(ctx, in, info, handler) } +func _Cron_GetScheduleTaskStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc_go.UnaryServerInterceptor) (interface{}, error) { + in := new(emptypb.Empty) + if err := dec(in); err != nil { + return nil, err + } + base := srv.(dubbo3.Dubbo3GrpcService) + args := []interface{}{} + args = append(args, in) + md, _ := metadata.FromIncomingContext(ctx) + invAttachment := make(map[string]interface{}, len(md)) + for k, v := range md { + invAttachment[k] = v + } + invo := invocation.NewRPCInvocation("GetScheduleTaskStatus", args, invAttachment) + if interceptor == nil { + result := base.XXX_GetProxyImpl().Invoke(ctx, invo) + return result, result.Error() + } + info := &grpc_go.UnaryServerInfo{ + Server: srv, + FullMethod: ctx.Value("XXX_TRIPLE_GO_INTERFACE_NAME").(string), + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + result := base.XXX_GetProxyImpl().Invoke(ctx, invo) + return result, result.Error() + } + return interceptor(ctx, in, info, handler) +} + // Cron_ServiceDesc is the grpc_go.ServiceDesc for Cron service. // It's only intended for direct use with grpc_go.RegisterService, // and not to be introspected or modified (even as a copy) @@ -411,6 +453,10 @@ var Cron_ServiceDesc = grpc_go.ServiceDesc{ MethodName: "DeleteScheduleTask", Handler: _Cron_DeleteScheduleTask_Handler, }, + { + MethodName: "GetScheduleTaskStatus", + Handler: _Cron_GetScheduleTaskStatus_Handler, + }, }, Streams: []grpc_go.StreamDesc{}, Metadata: "pb/cron.proto", diff --git a/pkg/router/cron.go b/pkg/router/cron.go index 4452858..c9931ad 100644 --- a/pkg/router/cron.go +++ b/pkg/router/cron.go @@ -1,6 +1,8 @@ package router import ( + "fonchain-fiee/pkg/middleware" + "fonchain-fiee/pkg/service" cronService "fonchain-fiee/pkg/service/cron" "github.com/gin-gonic/gin" @@ -8,16 +10,16 @@ import ( func cronRouter(r *gin.RouterGroup) { auth := r.Group("") - //auth.Use(middleware.CheckWebLogin(service.AccountProvider)) + auth.Use(middleware.CheckWebLogin(service.AccountProvider)) cron := auth.Group("cron") { cron.POST("createScheduleTask", cronService.CreateScheduleTask) cron.POST("pauseScheduleTask", cronService.PauseScheduleTask) cron.POST("startScheduleTask", cronService.StartScheduleTask) cron.POST("deleteScheduleTask", cronService.DeleteScheduleTask) - cron.GET("getListScheduleTask", cronService.GetListScheduleTask) - cron.GET("getListExecutionResult", cronService.GetListExecutionResult) - cron.GET("getListExecutionRecord", cronService.GetListExecutionRecord) - + cron.POST("getListScheduleTask", cronService.GetListScheduleTask) + cron.POST("getListExecutionResult", cronService.GetListExecutionResult) + cron.POST("getListExecutionRecord", cronService.GetListExecutionRecord) + //cron.GET("getScheduleTaskStatus", cronService.GetScheduleTaskStatus) } } diff --git a/pkg/service/cron/cron.go b/pkg/service/cron/cron.go index 47390b3..39a8132 100644 --- a/pkg/service/cron/cron.go +++ b/pkg/service/cron/cron.go @@ -133,3 +133,16 @@ func DeleteScheduleTask(c *gin.Context) { } service.Success(c, res) } + +//func GetScheduleTaskStatus(c *gin.Context) { +// res, err := service.CronProvider.GetScheduleTaskStatus(context.Background(), &emptypb.Empty{}) +// if err != nil { +// service.Error(c, errors.New("网络超时,请重试")) +// return +// } +// if res.Code != 200 { +// service.Error(c, errors.New(res.Message)) +// return +// } +// service.Success(c, res) +//}