service/app/mix/service/logic/notif_receive.go

92 lines
2.5 KiB
Go

package logic
import (
"service/api/consts"
"service/app/mix/dao"
"service/dbstruct"
"service/library/logger"
"time"
notificationproto "service/api/proto/notification/proto"
"github.com/gin-gonic/gin"
"github.com/qiniu/qmgo"
)
type NotifReceive struct {
store *dao.Store
}
func NewNotifReceive(store *dao.Store) (a *NotifReceive) {
a = &NotifReceive{
store: store,
}
return
}
func (p *NotifReceive) OpCreateBatch(ctx *gin.Context, notifReceives []*dbstruct.NotifReceive) error {
for _, notifReceive := range notifReceives {
notifReceiveIdSeq, err := p.store.GetAndUpdateNotifReceiveIdSeq(ctx)
if err != nil {
logger.Error("GetAndUpdateNotifReceiveIdSeq fail, err: %v", err)
return err
}
notifReceive.Id = notifReceiveIdSeq.Seq
//notifReceive.Ct = time.Now().Unix() // 创建时间由notification的创建时间或推送时间去决定
notifReceive.Ut = time.Now().Unix()
notifReceive.DelFlag = consts.Exist
}
err := p.store.CreateNotifReceives(ctx, notifReceives)
if err != nil {
logger.Error("CreateNotifReceives fail, err: %v", err)
return err
}
return nil
}
func (p *NotifReceive) OpReadByIds(ctx *gin.Context, req *notificationproto.ApiReadReq) (*qmgo.UpdateResult, error) {
result, err := p.store.ReadNotifReceiveByIds(ctx, req)
if err != nil {
logger.Error("ReadNotifReceiveByIds fail, err: %v", err)
return nil, err
}
return result, nil
}
func (p *NotifReceive) OpReadAll(ctx *gin.Context, mid, nType int64) (*qmgo.UpdateResult, error) {
result, err := p.store.ReadAllNotifReceive(ctx, mid, nType)
if err != nil {
logger.Error("ReadAllNotifReceive fail, err: %v", err)
return nil, err
}
return result, nil
}
func (p *NotifReceive) OpDeleteByIds(ctx *gin.Context, ids []int64) error {
err := p.store.DeleteNotifReceiveByIds(ctx, ids)
if err != nil {
logger.Error("DeleteNotifBcstByIds fail, err: %v", err)
return err
}
return nil
}
func (p *NotifReceive) OpListByObjMid(ctx *gin.Context, req *notificationproto.OpListNotifReceivesByMidReq) ([]*dbstruct.NotifReceive, error) {
list, err := p.store.GetNotifReceiveListByObjMid(ctx, req)
if err != nil {
logger.Error("GetNotifReceiveListByObjMid fail, err: %v", err)
return make([]*dbstruct.NotifReceive, 0), err
}
return list, nil
}
func (p *NotifReceive) OpGetUrc(ctx *gin.Context) ([]map[string]any, error) {
results, err := p.store.GetNotifReceiveUrc(ctx)
if err != nil {
logger.Error("GetNotifReceiveUrc fail, err: %v", err)
return make([]map[string]any, 0), err
}
return results, nil
}