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.
 
 
 
 

67 lines
1.6 KiB

  1. package device
  2. import (
  3. "egg_im/pkg/pb"
  4. "time"
  5. )
  6. const (
  7. DeviceOnLine = 1 // 设备在线
  8. DeviceOffLine = 0 // 设备离线
  9. )
  10. // Device 设备
  11. type Device struct {
  12. Id int64 // 设备id
  13. UserId int64 // 用户id
  14. Type int32 // 设备类型,1:Android;2:IOS;3:Windows; 4:MacOS;5:Web
  15. Brand string // 手机厂商
  16. Model string // 机型
  17. SystemVersion string // 系统版本
  18. SDKVersion string // SDK版本
  19. Status int32 // 在线状态,0:离线;1:在线
  20. ConnAddr string // 连接层服务层地址
  21. ClientAddr string // 客户端地址
  22. CreateTime time.Time // 创建时间
  23. UpdateTime time.Time // 更新时间
  24. }
  25. func (d *Device) ToProto() *pb.Device {
  26. return &pb.Device{
  27. DeviceId: d.Id,
  28. UserId: d.UserId,
  29. Type: d.Type,
  30. Brand: d.Brand,
  31. Model: d.Model,
  32. SystemVersion: d.SystemVersion,
  33. SdkVersion: d.SDKVersion,
  34. Status: d.Status,
  35. ConnAddr: d.ConnAddr,
  36. ClientAddr: d.ClientAddr,
  37. CreateTime: d.CreateTime.Unix(),
  38. UpdateTime: d.UpdateTime.Unix(),
  39. }
  40. }
  41. func (d *Device) IsLegal() bool {
  42. if d.Type == 0 || d.Brand == "" || d.Model == "" ||
  43. d.SystemVersion == "" || d.SDKVersion == "" {
  44. return false
  45. }
  46. return true
  47. }
  48. func (d *Device) Online(userId int64, connAddr string, clientAddr string) {
  49. d.UserId = userId
  50. d.ConnAddr = connAddr
  51. d.ClientAddr = clientAddr
  52. d.Status = DeviceOnLine
  53. }
  54. func (d *Device) Offline(userId int64, connAddr string, clientAddr string) {
  55. d.UserId = userId
  56. d.ConnAddr = connAddr
  57. d.ClientAddr = clientAddr
  58. d.Status = DeviceOnLine
  59. }