// 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 }