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/dbs"
|
||||||
"github.com/iwind/TeaGo/maps"
|
"github.com/iwind/TeaGo/maps"
|
||||||
"github.com/iwind/TeaGo/types"
|
"github.com/iwind/TeaGo/types"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -81,7 +82,7 @@ func (this *MessageRecipientDAO) FindEnabledMessageRecipient(tx *dbs.Tx, recipie
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateRecipient 创建接收人
|
// 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 := NewMessageRecipientOperator()
|
||||||
op.AdminId = adminId
|
op.AdminId = adminId
|
||||||
op.InstanceId = instanceId
|
op.InstanceId = instanceId
|
||||||
@@ -98,13 +99,22 @@ func (this *MessageRecipientDAO) CreateRecipient(tx *dbs.Tx, adminId int64, inst
|
|||||||
}
|
}
|
||||||
op.GroupIds = groupIdsJSON
|
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.IsOn = true
|
||||||
op.State = MessageRecipientStateEnabled
|
op.State = MessageRecipientStateEnabled
|
||||||
return this.SaveInt64(tx, op)
|
return this.SaveInt64(tx, op)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateRecipient 修改接收人
|
// 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 {
|
if recipientId <= 0 {
|
||||||
return errors.New("invalid recipientId")
|
return errors.New("invalid recipientId")
|
||||||
}
|
}
|
||||||
@@ -126,6 +136,20 @@ func (this *MessageRecipientDAO) UpdateRecipient(tx *dbs.Tx, recipientId int64,
|
|||||||
op.GroupIds = groupIdsJSON
|
op.GroupIds = groupIdsJSON
|
||||||
|
|
||||||
op.Description = description
|
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
|
op.IsOn = isOn
|
||||||
return this.Save(tx, op)
|
return this.Save(tx, op)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
// 消息媒介接收人
|
// MessageRecipient 消息媒介接收人
|
||||||
type MessageRecipient struct {
|
type MessageRecipient struct {
|
||||||
Id uint32 `field:"id"` // ID
|
Id uint32 `field:"id"` // ID
|
||||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||||
@@ -9,6 +9,8 @@ type MessageRecipient struct {
|
|||||||
User string `field:"user"` // 接收人信息
|
User string `field:"user"` // 接收人信息
|
||||||
GroupIds string `field:"groupIds"` // 分组ID
|
GroupIds string `field:"groupIds"` // 分组ID
|
||||||
State uint8 `field:"state"` // 状态
|
State uint8 `field:"state"` // 状态
|
||||||
|
TimeFrom string `field:"timeFrom"` // 开始时间
|
||||||
|
TimeTo string `field:"timeTo"` // 结束时间
|
||||||
Description string `field:"description"` // 备注
|
Description string `field:"description"` // 备注
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,6 +22,8 @@ type MessageRecipientOperator struct {
|
|||||||
User interface{} // 接收人信息
|
User interface{} // 接收人信息
|
||||||
GroupIds interface{} // 分组ID
|
GroupIds interface{} // 分组ID
|
||||||
State interface{} // 状态
|
State interface{} // 状态
|
||||||
|
TimeFrom interface{} // 开始时间
|
||||||
|
TimeTo interface{} // 结束时间
|
||||||
Description interface{} // 备注
|
Description interface{} // 备注
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ func (this *MessageTaskDAO) FindSendingMessageTasks(tx *dbs.Tx, size int64) (res
|
|||||||
_, err = this.Query(tx).
|
_, err = this.Query(tx).
|
||||||
State(MessageTaskStateEnabled).
|
State(MessageTaskStateEnabled).
|
||||||
Attr("status", MessageTaskStatusNone).
|
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").
|
Desc("isPrimary").
|
||||||
AscPk().
|
AscPk().
|
||||||
Limit(size).
|
Limit(size).
|
||||||
|
|||||||
@@ -3,4 +3,20 @@ package models
|
|||||||
import (
|
import (
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
_ "github.com/iwind/TeaGo/bootstrap"
|
_ "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()
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -36,7 +36,7 @@ func (this *MessageRecipientService) UpdateMessageRecipient(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var tx = this.NullTx()
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -147,6 +147,8 @@ func (this *MessageRecipientService) ListEnabledMessageRecipients(ctx context.Co
|
|||||||
IsOn: recipient.IsOn == 1,
|
IsOn: recipient.IsOn == 1,
|
||||||
MessageRecipientGroups: pbGroups,
|
MessageRecipientGroups: pbGroups,
|
||||||
Description: recipient.Description,
|
Description: recipient.Description,
|
||||||
|
TimeFrom: recipient.TimeFrom,
|
||||||
|
TimeTo: recipient.TimeTo,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,5 +229,7 @@ func (this *MessageRecipientService) FindEnabledMessageRecipient(ctx context.Con
|
|||||||
IsOn: recipient.IsOn == 1,
|
IsOn: recipient.IsOn == 1,
|
||||||
MessageRecipientGroups: pbGroups,
|
MessageRecipientGroups: pbGroups,
|
||||||
Description: recipient.Description,
|
Description: recipient.Description,
|
||||||
|
TimeFrom: recipient.TimeFrom,
|
||||||
|
TimeTo: recipient.TimeTo,
|
||||||
}}, nil
|
}}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user