mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-09 12:00:25 +08:00
消息接收人可以设置接收消息时间段
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -81,7 +82,7 @@ func (this *MessageRecipientDAO) FindEnabledMessageRecipient(tx *dbs.Tx, recipie
|
||||
}
|
||||
|
||||
// CreateRecipient 创建接收人
|
||||
func (this *MessageRecipientDAO) CreateRecipient(tx *dbs.Tx, adminId int64, instanceId int64, user string, groupIds []int64, description string) (int64, error) {
|
||||
func (this *MessageRecipientDAO) CreateRecipient(tx *dbs.Tx, adminId int64, instanceId int64, user string, groupIds []int64, description string, timeFrom string, timeTo string) (int64, error) {
|
||||
op := NewMessageRecipientOperator()
|
||||
op.AdminId = adminId
|
||||
op.InstanceId = instanceId
|
||||
@@ -98,13 +99,22 @@ func (this *MessageRecipientDAO) CreateRecipient(tx *dbs.Tx, adminId int64, inst
|
||||
}
|
||||
op.GroupIds = groupIdsJSON
|
||||
|
||||
// 判断格式
|
||||
var timeReg = regexp.MustCompile(`^\d+:\d+:\d+$`)
|
||||
if timeReg.MatchString(timeFrom) {
|
||||
op.TimeFrom = timeFrom
|
||||
}
|
||||
if timeReg.MatchString(timeTo) {
|
||||
op.TimeTo = timeTo
|
||||
}
|
||||
|
||||
op.IsOn = true
|
||||
op.State = MessageRecipientStateEnabled
|
||||
return this.SaveInt64(tx, op)
|
||||
}
|
||||
|
||||
// UpdateRecipient 修改接收人
|
||||
func (this *MessageRecipientDAO) UpdateRecipient(tx *dbs.Tx, recipientId int64, adminId int64, instanceId int64, user string, groupIds []int64, description string, isOn bool) error {
|
||||
func (this *MessageRecipientDAO) UpdateRecipient(tx *dbs.Tx, recipientId int64, adminId int64, instanceId int64, user string, groupIds []int64, description string, timeFrom string, timeTo string, isOn bool) error {
|
||||
if recipientId <= 0 {
|
||||
return errors.New("invalid recipientId")
|
||||
}
|
||||
@@ -126,6 +136,20 @@ func (this *MessageRecipientDAO) UpdateRecipient(tx *dbs.Tx, recipientId int64,
|
||||
op.GroupIds = groupIdsJSON
|
||||
|
||||
op.Description = description
|
||||
|
||||
// 判断格式
|
||||
var timeReg = regexp.MustCompile(`^\d+:\d+:\d+$`)
|
||||
if timeReg.MatchString(timeFrom) {
|
||||
op.TimeFrom = timeFrom
|
||||
} else {
|
||||
op.TimeFrom = dbs.SQL("NULL")
|
||||
}
|
||||
if timeReg.MatchString(timeTo) {
|
||||
op.TimeTo = timeTo
|
||||
} else {
|
||||
op.TimeTo = dbs.SQL("NULL")
|
||||
}
|
||||
|
||||
op.IsOn = isOn
|
||||
return this.Save(tx, op)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
// 消息媒介接收人
|
||||
// MessageRecipient 消息媒介接收人
|
||||
type MessageRecipient struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
@@ -9,6 +9,8 @@ type MessageRecipient struct {
|
||||
User string `field:"user"` // 接收人信息
|
||||
GroupIds string `field:"groupIds"` // 分组ID
|
||||
State uint8 `field:"state"` // 状态
|
||||
TimeFrom string `field:"timeFrom"` // 开始时间
|
||||
TimeTo string `field:"timeTo"` // 结束时间
|
||||
Description string `field:"description"` // 备注
|
||||
}
|
||||
|
||||
@@ -20,6 +22,8 @@ type MessageRecipientOperator struct {
|
||||
User interface{} // 接收人信息
|
||||
GroupIds interface{} // 分组ID
|
||||
State interface{} // 状态
|
||||
TimeFrom interface{} // 开始时间
|
||||
TimeTo interface{} // 结束时间
|
||||
Description interface{} // 备注
|
||||
}
|
||||
|
||||
|
||||
@@ -113,6 +113,8 @@ func (this *MessageTaskDAO) FindSendingMessageTasks(tx *dbs.Tx, size int64) (res
|
||||
_, err = this.Query(tx).
|
||||
State(MessageTaskStateEnabled).
|
||||
Attr("status", MessageTaskStatusNone).
|
||||
Where("(recipientId=0 OR recipientId IN (SELECT id FROM "+SharedMessageRecipientDAO.Table+" WHERE state=1 AND isOn=1 AND (timeFrom IS NULL OR timeTo IS NULL OR :time BETWEEN timeFrom AND timeTo)))").
|
||||
Param("time", timeutil.Format("H:i:s")).
|
||||
Desc("isPrimary").
|
||||
AscPk().
|
||||
Limit(size).
|
||||
|
||||
@@ -3,4 +3,20 @@ package models
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMessageTaskDAO_FindSendingMessageTasks(t *testing.T) {
|
||||
dbs.NotifyReady()
|
||||
|
||||
var tx *dbs.Tx
|
||||
tasks, err := NewMessageTaskDAO().FindSendingMessageTasks(tx, 100)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(len(tasks), "tasks")
|
||||
for _, task := range tasks {
|
||||
t.Log("task:", task.Id, "recipient:", task.RecipientId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func (this *MessageRecipientService) CreateMessageRecipient(ctx context.Context,
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
recipientId, err := models.SharedMessageRecipientDAO.CreateRecipient(tx, req.AdminId, req.MessageMediaInstanceId, req.User, req.MessageRecipientGroupIds, req.Description)
|
||||
recipientId, err := models.SharedMessageRecipientDAO.CreateRecipient(tx, req.AdminId, req.MessageMediaInstanceId, req.User, req.MessageRecipientGroupIds, req.Description, req.TimeFrom, req.TimeTo)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func (this *MessageRecipientService) UpdateMessageRecipient(ctx context.Context,
|
||||
}
|
||||
|
||||
var tx = this.NullTx()
|
||||
err = models.SharedMessageRecipientDAO.UpdateRecipient(tx, req.MessageRecipientId, req.AdminId, req.MessageMediaInstanceId, req.User, req.MessageRecipientGroupIds, req.Description, req.IsOn)
|
||||
err = models.SharedMessageRecipientDAO.UpdateRecipient(tx, req.MessageRecipientId, req.AdminId, req.MessageMediaInstanceId, req.User, req.MessageRecipientGroupIds, req.Description, req.TimeFrom, req.TimeTo, req.IsOn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -147,6 +147,8 @@ func (this *MessageRecipientService) ListEnabledMessageRecipients(ctx context.Co
|
||||
IsOn: recipient.IsOn == 1,
|
||||
MessageRecipientGroups: pbGroups,
|
||||
Description: recipient.Description,
|
||||
TimeFrom: recipient.TimeFrom,
|
||||
TimeTo: recipient.TimeTo,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -227,5 +229,7 @@ func (this *MessageRecipientService) FindEnabledMessageRecipient(ctx context.Con
|
||||
IsOn: recipient.IsOn == 1,
|
||||
MessageRecipientGroups: pbGroups,
|
||||
Description: recipient.Description,
|
||||
TimeFrom: recipient.TimeFrom,
|
||||
TimeTo: recipient.TimeTo,
|
||||
}}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user