|
- package repo
-
- import (
- "egg-im/internal/logic/domain/group/model"
- "egg-im/pkg/db"
- "egg-im/pkg/gerrors"
-
- "github.com/jinzhu/gorm"
- )
-
- type groupNoticeDao struct{}
-
- var GroupNoticeDao = new(groupNoticeDao)
-
- // Get 获取群组公告信息
- func (*groupNoticeDao) Get(groupId int64) (*model.GroupNotice, error) {
- var group = model.GroupNotice{GroupId: groupId}
- err := db.DB.First(&group).Error
- if err != nil && err != gorm.ErrRecordNotFound {
- return nil, gerrors.WrapError(err)
- }
- if err == gorm.ErrRecordNotFound {
- return nil, nil
- }
- return &group, nil
- }
-
- // Save 插入一条群组
- func (g *groupNoticeDao) Save(groupNotice *model.GroupNotice, isPublish bool) error {
- mm, err := g.Get(groupNotice.GroupId)
- if err != nil {
- return err
- }
- if mm != nil && isPublish {
- mm.Content = groupNotice.Content
- mm.LikeNums = 0
- mm.ReadNums = 0
- mm.PublishType = groupNotice.PublishType
- mm.UpdateTime = groupNotice.UpdateTime
-
- //清除群组点赞记录
- err = GroupNoticeWithLikeRecordsDao.Clean(groupNotice.GroupId)
- if err != nil {
- return err
- }
- err = db.DB.Save(&mm).Error
- if err != nil {
- return gerrors.WrapError(err)
- }
- //删除缓存
- GroupNoticeCache.Del(groupNotice.GroupId)
- } else {
- err = db.DB.Save(&groupNotice).Error
- if err != nil {
- return gerrors.WrapError(err)
- }
- }
- return nil
- }
|