person.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package specialAPIModels
  2. import (
  3. I "devel.mephi.ru/dyokunev/wwwvoip/app/iface"
  4. "github.com/revel/revel"
  5. "voip/app/models"
  6. )
  7. type Person struct {
  8. common
  9. Login *string `json:",omitempty"`
  10. Firstname string `json:",omitempty"`
  11. Lastname string `json:",omitempty"`
  12. Patronymic *string `json:",omitempty"`
  13. Displayname *string `json:",omitempty"`
  14. DisplaynameLatin *string `json:"displayname_latin,omitempty"`
  15. PhotoUrl string `json:"photo_url,omitempty"`
  16. ShowEmail interface{} `json:"show_email,omitempty"`
  17. }
  18. type Persons []Person
  19. func (persons *Persons) IConvert(apiHost string, affiliateUnit *models.Unit) (I.Slice, error) {
  20. var convertedPersons models.Subscribers
  21. convertedPersons = make([]models.Subscriber, len(*persons))
  22. sem := make(chan bool, 512)
  23. i := 0
  24. for _, person := range *persons {
  25. sem <- true
  26. go func(person Person, i int) {
  27. defer func() { <-sem }()
  28. revel.TRACE.Printf("person == %v", person)
  29. var convertedPerson models.Subscriber
  30. {
  31. specialPersonId := person.Id
  32. convertedPerson = models.Subscriber{
  33. Firstname: person.Firstname,
  34. Lastname: person.Lastname,
  35. Patronymic: person.Patronymic,
  36. Key: int64(-(affiliateUnit.Code.Mid*100000 + person.Id%100000)),
  37. Login: person.Login,
  38. HasSecurityLevel: 50,
  39. SecurityLevel: -512,
  40. DisplayName: "",
  41. DisplayNameLatin: "",
  42. PhotoUrl: person.PhotoUrl,
  43. SourceAPIHost: &apiHost,
  44. SpecialAPIId: &specialPersonId,
  45. }
  46. convertedPerson.IsFake = false
  47. convertedPerson.Notes = ""
  48. }
  49. switch v := person.ShowEmail.(type) {
  50. case int:
  51. convertedPerson.ShowEmail = v != 0
  52. case int64:
  53. convertedPerson.ShowEmail = v != 0
  54. case float32:
  55. convertedPerson.ShowEmail = v != 0
  56. case float64:
  57. convertedPerson.ShowEmail = v != 0
  58. case bool:
  59. convertedPerson.ShowEmail = v
  60. case string:
  61. convertedPerson.ShowEmail = v != "0"
  62. case nil:
  63. convertedPerson.ShowEmail = true
  64. default:
  65. revel.ERROR.Printf("Unknown type of variable \"person.ShowEmail\", value: \"%v\", type: \"%T\"", v, v)
  66. }
  67. var err error
  68. convertedPerson.PhotoUrl, err = convertedPerson.DownloadRemotePhoto()
  69. if err != nil {
  70. revel.ERROR.Printf("Persons.IConvert(\"%v\", affiliateUnit) error: %v", apiHost, err.Error())
  71. //return nil, err
  72. }
  73. convertedPerson.FixDisplayNames()
  74. convertedPersons[i] = convertedPerson
  75. }(person, i)
  76. i++
  77. }
  78. for i := 0; i < cap(sem); i++ {
  79. sem <- true
  80. }
  81. return convertedPersons, nil
  82. }