ticket.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package ticket
  2. import (
  3. "github.com/ClickHouse/clickhouse-go/v2/lib/driver"
  4. "github.com/kelindar/bitmap"
  5. "google.golang.org/protobuf/types/known/timestamppb"
  6. "time"
  7. )
  8. func (x *Ticket) Scan(row driver.Rows) error {
  9. var (
  10. from map[string]string
  11. createdAt time.Time
  12. updatedAt time.Time
  13. err error
  14. )
  15. if err = row.Scan(
  16. &x.TicketId,
  17. &x.ThreadId,
  18. &x.To,
  19. &from,
  20. &x.Flags,
  21. &x.Meta,
  22. &x.Tags,
  23. &createdAt,
  24. &updatedAt,
  25. &x.MessageIds,
  26. &x.Subjects,
  27. ); err != nil {
  28. return err
  29. }
  30. x.From = &EmailAddress{
  31. Address: from["address"],
  32. Name: from["name"],
  33. }
  34. x.CreatedAt = timestamppb.New(createdAt)
  35. x.UpdatedAt = timestamppb.New(updatedAt)
  36. return nil
  37. }
  38. func (x *Ticket) SetFlags(flags ...TicketFlag) {
  39. mask := bitmap.FromBytes(x.Flags)
  40. for i := range flags {
  41. if TicketFlag_unknown_ticket_flag == flags[i] {
  42. continue
  43. }
  44. mask.Set(uint32(flags[i]))
  45. }
  46. x.Flags = mask.ToBytes()
  47. }
  48. func (x *Ticket) RemoveFlags(flags ...TicketFlag) {
  49. mask := bitmap.FromBytes(x.Flags)
  50. for i := range flags {
  51. if TicketFlag_unknown_ticket_flag == flags[i] {
  52. continue
  53. }
  54. mask.Remove(uint32(flags[i]))
  55. }
  56. x.Flags = mask.ToBytes()
  57. }
  58. func (x *Ticket) HasFlag(flag TicketFlag) bool {
  59. return bitmap.
  60. FromBytes(x.Flags).
  61. Contains(uint32(flag))
  62. }