123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- package specialAPIModels
- import (
- I "devel.mephi.ru/dyokunev/wwwvoip/app/iface"
- "github.com/revel/revel"
- "voip/app/models"
- )
- type Person struct {
- common
- Login *string `json:",omitempty"`
- Firstname string `json:",omitempty"`
- Lastname string `json:",omitempty"`
- Patronymic *string `json:",omitempty"`
- Displayname *string `json:",omitempty"`
- DisplaynameLatin *string `json:"displayname_latin,omitempty"`
- PhotoUrl string `json:"photo_url,omitempty"`
- ShowEmail interface{} `json:"show_email,omitempty"`
- }
- type Persons []Person
- func (persons *Persons) IConvert(apiHost string, affiliateUnit *models.Unit) (I.Slice, error) {
- var convertedPersons models.Subscribers
- convertedPersons = make([]models.Subscriber, len(*persons))
- sem := make(chan bool, 512)
- i := 0
- for _, person := range *persons {
- sem <- true
- go func(person Person, i int) {
- defer func() { <-sem }()
- revel.TRACE.Printf("person == %v", person)
- var convertedPerson models.Subscriber
- {
- specialPersonId := person.Id
- convertedPerson = models.Subscriber{
- Firstname: person.Firstname,
- Lastname: person.Lastname,
- Patronymic: person.Patronymic,
- Key: int64(-(affiliateUnit.Code.Mid*100000 + person.Id%100000)),
- Login: person.Login,
- HasSecurityLevel: 50,
- SecurityLevel: -512,
- DisplayName: "",
- DisplayNameLatin: "",
- PhotoUrl: person.PhotoUrl,
- SourceAPIHost: &apiHost,
- SpecialAPIId: &specialPersonId,
- }
- convertedPerson.IsFake = false
- convertedPerson.Notes = ""
- }
- switch v := person.ShowEmail.(type) {
- case int:
- convertedPerson.ShowEmail = v != 0
- case int64:
- convertedPerson.ShowEmail = v != 0
- case float32:
- convertedPerson.ShowEmail = v != 0
- case float64:
- convertedPerson.ShowEmail = v != 0
- case bool:
- convertedPerson.ShowEmail = v
- case string:
- convertedPerson.ShowEmail = v != "0"
- case nil:
- convertedPerson.ShowEmail = true
- default:
- revel.ERROR.Printf("Unknown type of variable \"person.ShowEmail\", value: \"%v\", type: \"%T\"", v, v)
- }
- var err error
- convertedPerson.PhotoUrl, err = convertedPerson.DownloadRemotePhoto()
- if err != nil {
- revel.ERROR.Printf("Persons.IConvert(\"%v\", affiliateUnit) error: %v", apiHost, err.Error())
- //return nil, err
- }
- convertedPerson.FixDisplayNames()
- convertedPersons[i] = convertedPerson
- }(person, i)
- i++
- }
- for i := 0; i < cap(sem); i++ {
- sem <- true
- }
- return convertedPersons, nil
- }
|