first commit
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package mysqldao
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/global"
|
||||
"git.lzcwy.cn/zhengchiliu/zt-closet-manage-backend/internal/mysqlmodel"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// NotificationDao 通知数据访问
|
||||
type NotificationDao struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// NewNotificationDao 创建通知 DAO
|
||||
func NewNotificationDao() *NotificationDao {
|
||||
return &NotificationDao{db: global.MysqlEngine}
|
||||
}
|
||||
|
||||
// NotificationBatchCreate 批量插入通知(单用户/分片广播共用)
|
||||
func (d *NotificationDao) NotificationBatchCreate(ctx context.Context, notifications []mysqlmodel.UserNotification) error {
|
||||
ctx, span := global.Tracer.Start(ctx, "mysqldao.NotificationBatchCreate")
|
||||
defer span.End()
|
||||
|
||||
if len(notifications) == 0 {
|
||||
return nil
|
||||
}
|
||||
if err := d.db.WithContext(ctx).CreateInBatches(notifications, 500).Error; err != nil {
|
||||
span.RecordError(err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user