feat:新增定时任务发布

This commit is contained in:
bx1834938347-prog 2025-12-18 16:40:59 +08:00
parent 8fa9cd79a4
commit 82a893f863
4 changed files with 73 additions and 46 deletions

View File

@ -139,6 +139,7 @@ type ScheduleTask struct {
UpdatedAt string `protobuf:"bytes,17,opt,name=updated_at,json=updatedAt,proto3" json:"updated_at"`
TaskDetail *TaskDetail `protobuf:"bytes,18,opt,name=task_detail,json=taskDetail,proto3" json:"task_detail"`
ExecutionRecords []*ExecutionRecord `protobuf:"bytes,19,rep,name=execution_records,json=executionRecords,proto3" json:"execution_records"`
StatusDesc string `protobuf:"bytes,113,opt,name=status_desc,json=statusDesc,proto3" json:"status_desc"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@ -299,6 +300,13 @@ func (x *ScheduleTask) GetExecutionRecords() []*ExecutionRecord {
return nil
}
func (x *ScheduleTask) GetStatusDesc() string {
if x != nil {
return x.StatusDesc
}
return ""
}
// 执行记录
type ExecutionRecord struct {
state protoimpl.MessageState `protogen:"open.v1"`
@ -976,11 +984,11 @@ type GetListScheduleTaskRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page"`
PageSize int32 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size"`
TaskTitle string `protobuf:"bytes,3,opt,name=task_title,json=taskTitle,proto3" json:"task_title"` //任务标题
PeriodType string `protobuf:"bytes,4,opt,name=period_type,json=periodType,proto3" json:"period_type"` //任务类型
StartTime string `protobuf:"bytes,5,opt,name=start_time,json=startTime,proto3" json:"start_time"` //开始日期
EndTime string `protobuf:"bytes,6,opt,name=end_time,json=endTime,proto3" json:"end_time"` //结束日期
Status int32 `protobuf:"varint,7,opt,name=Status,proto3" json:"Status"` // 状态
TaskTitle string `protobuf:"bytes,3,opt,name=task_title,json=taskTitle,proto3" json:"task_title"` //任务标题
PeriodType int32 `protobuf:"varint,4,opt,name=period_type,json=periodType,proto3" json:"period_type"` //任务类型
StartTime string `protobuf:"bytes,5,opt,name=start_time,json=startTime,proto3" json:"start_time"` //开始日期
EndTime string `protobuf:"bytes,6,opt,name=end_time,json=endTime,proto3" json:"end_time"` //结束日期
Status int32 `protobuf:"varint,7,opt,name=Status,proto3" json:"Status"` // 状态
ContentType int32 `protobuf:"varint,8,opt,name=content_type,json=contentType,proto3" json:"content_type"`
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
@ -1037,11 +1045,11 @@ func (x *GetListScheduleTaskRequest) GetTaskTitle() string {
return ""
}
func (x *GetListScheduleTaskRequest) GetPeriodType() string {
func (x *GetListScheduleTaskRequest) GetPeriodType() int32 {
if x != nil {
return x.PeriodType
}
return ""
return 0
}
func (x *GetListScheduleTaskRequest) GetStartTime() string {
@ -1158,14 +1166,14 @@ func (x *GetListScheduleTaskResponse) GetData() []*ScheduleTask {
type GetListExecutionRecordRequest struct {
state protoimpl.MessageState `protogen:"open.v1"`
Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page"` // 页码
PageSize int32 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size"` // 每页显示的记录数
TaskTitle string `protobuf:"bytes,3,opt,name=task_title,json=taskTitle,proto3" json:"task_title"` // 任务标题
PeriodType string `protobuf:"bytes,4,opt,name=period_type,json=periodType,proto3" json:"period_type"` // 执行周期类型
StartTime string `protobuf:"bytes,5,opt,name=start_time,json=startTime,proto3" json:"start_time"` // 起始时间
EndTime string `protobuf:"bytes,6,opt,name=end_time,json=endTime,proto3" json:"end_time"` // 结束时间
Status int32 `protobuf:"varint,7,opt,name=status,proto3" json:"status"` //状态
Result int32 `protobuf:"varint,8,opt,name=result,proto3" json:"result"` //结果
Page int32 `protobuf:"varint,1,opt,name=page,proto3" json:"page"` // 页码
PageSize int32 `protobuf:"varint,2,opt,name=page_size,json=pageSize,proto3" json:"page_size"` // 每页显示的记录数
TaskTitle string `protobuf:"bytes,3,opt,name=task_title,json=taskTitle,proto3" json:"task_title"` // 任务标题
PeriodType int32 `protobuf:"varint,4,opt,name=period_type,json=periodType,proto3" json:"period_type"` // 执行周期类型
StartTime string `protobuf:"bytes,5,opt,name=start_time,json=startTime,proto3" json:"start_time"` // 起始时间
EndTime string `protobuf:"bytes,6,opt,name=end_time,json=endTime,proto3" json:"end_time"` // 结束时间
Status int32 `protobuf:"varint,7,opt,name=status,proto3" json:"status"` //状态
Result int32 `protobuf:"varint,8,opt,name=result,proto3" json:"result"` //结果
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@ -1221,11 +1229,11 @@ func (x *GetListExecutionRecordRequest) GetTaskTitle() string {
return ""
}
func (x *GetListExecutionRecordRequest) GetPeriodType() string {
func (x *GetListExecutionRecordRequest) GetPeriodType() int32 {
if x != nil {
return x.PeriodType
}
return ""
return 0
}
func (x *GetListExecutionRecordRequest) GetStartTime() string {
@ -1588,7 +1596,9 @@ func (x *TaskStatus) GetValue() string {
type GetScheduleTaskStatusResponse struct {
state protoimpl.MessageState `protogen:"open.v1"`
Status []*TaskStatus `protobuf:"bytes,1,rep,name=status,proto3" json:"status"` // 多个任务状态
Code int32 `protobuf:"varint,1,opt,name=code,proto3" json:"code"` // 响应代码
Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message"` // 响应消息
Data []*TaskStatus `protobuf:"bytes,3,rep,name=data,proto3" json:"data"` // 多个任务状态
unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache
}
@ -1623,9 +1633,23 @@ func (*GetScheduleTaskStatusResponse) Descriptor() ([]byte, []int) {
return file_pb_cron_proto_rawDescGZIP(), []int{17}
}
func (x *GetScheduleTaskStatusResponse) GetStatus() []*TaskStatus {
func (x *GetScheduleTaskStatusResponse) GetCode() int32 {
if x != nil {
return x.Status
return x.Code
}
return 0
}
func (x *GetScheduleTaskStatusResponse) GetMessage() string {
if x != nil {
return x.Message
}
return ""
}
func (x *GetScheduleTaskStatusResponse) GetData() []*TaskStatus {
if x != nil {
return x.Data
}
return nil
}
@ -1639,7 +1663,7 @@ const file_pb_cron_proto_rawDesc = "" +
"\x02id\x18\x01 \x01(\rR\x02id\">\n" +
"\x0eCommonResponse\x12\x12\n" +
"\x04code\x18\x01 \x01(\x05R\x04code\x12\x18\n" +
"\amessage\x18\x02 \x01(\tR\amessage\"\x8a\x05\n" +
"\amessage\x18\x02 \x01(\tR\amessage\"\xab\x05\n" +
"\fScheduleTask\x12\x0e\n" +
"\x02id\x18\x01 \x01(\rR\x02id\x12\x1d\n" +
"\n" +
@ -1666,7 +1690,9 @@ const file_pb_cron_proto_rawDesc = "" +
"updated_at\x18\x11 \x01(\tR\tupdatedAt\x121\n" +
"\vtask_detail\x18\x12 \x01(\v2\x10.cron.TaskDetailR\n" +
"taskDetail\x12B\n" +
"\x11execution_records\x18\x13 \x03(\v2\x15.cron.ExecutionRecordR\x10executionRecords\"\xe6\x03\n" +
"\x11execution_records\x18\x13 \x03(\v2\x15.cron.ExecutionRecordR\x10executionRecords\x12\x1f\n" +
"\vstatus_desc\x18q \x01(\tR\n" +
"statusDesc\"\xe6\x03\n" +
"\x0fExecutionRecord\x12\x17\n" +
"\atask_id\x18\x01 \x01(\x05R\x06taskId\x12%\n" +
"\x0eexecution_date\x18\x02 \x01(\tR\rexecutionDate\x12\x1d\n" +
@ -1749,7 +1775,7 @@ const file_pb_cron_proto_rawDesc = "" +
"\tpage_size\x18\x02 \x01(\x05R\bpageSize\x12\x1d\n" +
"\n" +
"task_title\x18\x03 \x01(\tR\ttaskTitle\x12\x1f\n" +
"\vperiod_type\x18\x04 \x01(\tR\n" +
"\vperiod_type\x18\x04 \x01(\x05R\n" +
"periodType\x12\x1d\n" +
"\n" +
"start_time\x18\x05 \x01(\tR\tstartTime\x12\x19\n" +
@ -1768,7 +1794,7 @@ const file_pb_cron_proto_rawDesc = "" +
"\tpage_size\x18\x02 \x01(\x05R\bpageSize\x12\x1d\n" +
"\n" +
"task_title\x18\x03 \x01(\tR\ttaskTitle\x12\x1f\n" +
"\vperiod_type\x18\x04 \x01(\tR\n" +
"\vperiod_type\x18\x04 \x01(\x05R\n" +
"periodType\x12\x1d\n" +
"\n" +
"start_time\x18\x05 \x01(\tR\tstartTime\x12\x19\n" +
@ -1805,9 +1831,11 @@ const file_pb_cron_proto_rawDesc = "" +
"\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" +
"\x05value\x18\x02 \x01(\tR\x05value\"s\n" +
"\x1dGetScheduleTaskStatusResponse\x12\x12\n" +
"\x04code\x18\x01 \x01(\x05R\x04code\x12\x18\n" +
"\amessage\x18\x02 \x01(\tR\amessage\x12$\n" +
"\x04data\x18\x03 \x03(\v2\x10.cron.TaskStatusR\x04data2\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" +
@ -1863,7 +1891,7 @@ 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
16, // 10: cron.GetScheduleTaskStatusResponse.status:type_name -> cron.TaskStatus
16, // 10: cron.GetScheduleTaskStatusResponse.data: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

View File

@ -132,10 +132,10 @@ func (this *TaskStatus) Validate() error {
return nil
}
func (this *GetScheduleTaskStatusResponse) Validate() error {
for _, item := range this.Status {
for _, item := range this.Data {
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 github_com_mwitkow_go_proto_validators.FieldError("Data", err)
}
}
}

View File

@ -1,8 +1,6 @@
package router
import (
"fonchain-fiee/pkg/middleware"
"fonchain-fiee/pkg/service"
cronService "fonchain-fiee/pkg/service/cron"
"github.com/gin-gonic/gin"
@ -10,7 +8,7 @@ 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)
@ -20,6 +18,6 @@ func cronRouter(r *gin.RouterGroup) {
cron.POST("getListScheduleTask", cronService.GetListScheduleTask)
cron.POST("getListExecutionResult", cronService.GetListExecutionResult)
cron.POST("getListExecutionRecord", cronService.GetListExecutionRecord)
//cron.GET("getScheduleTaskStatus", cronService.GetScheduleTaskStatus)
cron.POST("getScheduleTaskStatus", cronService.GetScheduleTaskStatus)
}
}

View File

@ -8,6 +8,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding"
"google.golang.org/protobuf/types/known/emptypb"
)
func CreateScheduleTask(c *gin.Context) {
@ -134,15 +135,15 @@ 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)
//}
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)
}