golang-im聊天
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.

device_ack.go 686 B

2 jaren geleden
12345678910111213141516171819202122232425262728293031323334
  1. package service
  2. import (
  3. "context"
  4. "gim/internal/logic/domain/message/repo"
  5. )
  6. type deviceAckService struct{}
  7. var DeviceAckService = new(deviceAckService)
  8. // Update 更新ack
  9. func (*deviceAckService) Update(ctx context.Context, userId, deviceId, ack int64) error {
  10. if ack <= 0 {
  11. return nil
  12. }
  13. return repo.DeviceACKRepo.Set(userId, deviceId, ack)
  14. }
  15. // GetMaxByUserId 根据用户id获取最大ack
  16. func (*deviceAckService) GetMaxByUserId(ctx context.Context, userId int64) (int64, error) {
  17. acks, err := repo.DeviceACKRepo.Get(userId)
  18. if err != nil {
  19. return 0, err
  20. }
  21. var max int64 = 0
  22. for i := range acks {
  23. if acks[i] > max {
  24. max = acks[i]
  25. }
  26. }
  27. return max, nil
  28. }