You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

60 lines
1.3 KiB

  1. package repo
  2. import (
  3. "egg-im/internal/logic/domain/group/model"
  4. "egg-im/pkg/db"
  5. "egg-im/pkg/gerrors"
  6. "github.com/jinzhu/gorm"
  7. )
  8. type groupNoticeDao struct{}
  9. var GroupNoticeDao = new(groupNoticeDao)
  10. // Get 获取群组公告信息
  11. func (*groupNoticeDao) Get(groupId int64) (*model.GroupNotice, error) {
  12. var group = model.GroupNotice{GroupId: groupId}
  13. err := db.DB.First(&group).Error
  14. if err != nil && err != gorm.ErrRecordNotFound {
  15. return nil, gerrors.WrapError(err)
  16. }
  17. if err == gorm.ErrRecordNotFound {
  18. return nil, nil
  19. }
  20. return &group, nil
  21. }
  22. // Save 插入一条群组
  23. func (g *groupNoticeDao) Save(groupNotice *model.GroupNotice, isPublish bool) error {
  24. mm, err := g.Get(groupNotice.GroupId)
  25. if err != nil {
  26. return err
  27. }
  28. if mm != nil && isPublish {
  29. mm.Content = groupNotice.Content
  30. mm.LikeNums = 0
  31. mm.ReadNums = 0
  32. mm.PublishType = groupNotice.PublishType
  33. mm.UpdateTime = groupNotice.UpdateTime
  34. //清除群组点赞记录
  35. err = GroupNoticeWithLikeRecordsDao.Clean(groupNotice.GroupId)
  36. if err != nil {
  37. return err
  38. }
  39. err = db.DB.Save(&mm).Error
  40. if err != nil {
  41. return gerrors.WrapError(err)
  42. }
  43. //删除缓存
  44. GroupNoticeCache.Del(groupNotice.GroupId)
  45. } else {
  46. err = db.DB.Save(&groupNotice).Error
  47. if err != nil {
  48. return gerrors.WrapError(err)
  49. }
  50. }
  51. return nil
  52. }