Files
chat-deploy/pkg/common/db/table/chat/scheduled_task.go
kim.dev.6789 b7f8db7d08 复制项目
2026-01-14 22:35:45 +08:00

79 lines
3.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"context"
"time"
"github.com/openimsdk/tools/db/pagination"
)
// ScheduledTaskStatus 定时任务状态
const (
ScheduledTaskStatusDisabled = 0 // 已禁用
ScheduledTaskStatusEnabled = 1 // 已启用
)
// MessageType 消息类型
const (
MessageTypeText = 1 // 文本消息
MessageTypeImage = 2 // 图片消息
MessageTypeVideo = 3 // 视频消息
)
// ScheduledTask 定时任务配置
// CronExpression格式分 时 日 月 周
// 例如:"0 9 * * *" 表示每天9点执行
//
// "*/5 * * * *" 表示每5分钟执行
// "0 0 * * 1" 表示每周一0点执行
type ScheduledTask struct {
ID string `bson:"_id"` // 任务ID
UserID string `bson:"user_id"` // 用户ID
Name string `bson:"name"` // 任务名称
CronExpression string `bson:"cron_expression"` // Crontab表达式分 时 日 月 周(例如:"0 9 * * *"
Messages []Message `bson:"messages"` // 消息列表(支持多条消息一起发送)
RecvIDs []string `bson:"recv_ids"` // 接收者ID列表单聊可以多个
GroupIDs []string `bson:"group_ids"` // 群组ID列表群聊可以多个
Status int32 `bson:"status"` // 状态0-已禁用1-已启用
CreateTime time.Time `bson:"create_time"` // 创建时间
UpdateTime time.Time `bson:"update_time"` // 更新时间
}
// Message 消息内容
type Message struct {
Type int32 `bson:"type"` // 消息类型1-文本2-图片3-视频
Content string `bson:"content"` // 消息内容文本内容、图片URL、视频URL等
Thumbnail string `bson:"thumbnail"` // 缩略图URL用于图片和视频
Duration int32 `bson:"duration"` // 时长(秒,用于视频)
FileSize int64 `bson:"file_size"` // 文件大小(字节,用于图片和视频)
Width int32 `bson:"width"` // 宽度(像素,用于图片和视频)
Height int32 `bson:"height"` // 高度(像素,用于图片和视频)
}
func (ScheduledTask) TableName() string {
return "scheduled_tasks"
}
type ScheduledTaskInterface interface {
Create(ctx context.Context, tasks ...*ScheduledTask) error
Take(ctx context.Context, taskID string) (*ScheduledTask, error)
FindByUserID(ctx context.Context, userID string, pagination pagination.Pagination) (int64, []*ScheduledTask, error)
FindAll(ctx context.Context, pagination pagination.Pagination) (int64, []*ScheduledTask, error)
Update(ctx context.Context, taskID string, data map[string]any) error
Delete(ctx context.Context, taskIDs []string) error
}