fix_ok_row.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. //go:generate reform
  2. package models
  3. import (
  4. "encoding/json"
  5. )
  6. //reform:fixok_userid2empguid
  7. type FixOkRow struct {
  8. Id int `reform:"UserId,pk"`
  9. EmpGUID int `reform:"EmpGUID"`
  10. }
  11. func (fixOkRow *FixOkRow) AfterFind() error {
  12. return nil
  13. }
  14. func (pass *FixOkRow) ParseFixokJson(fixokJsonPass map[string]interface{}) *FixOkRow {
  15. passId, err := fixokJsonPass["id"].(json.Number).Int64()
  16. if err != nil {
  17. panic(err)
  18. }
  19. pass.Id = int(passId)
  20. fixokJsonPassPersonIdN, fixokJsonPassPersonIdOk := fixokJsonPass["person_id"].(json.Number)
  21. if !fixokJsonPassPersonIdOk {
  22. return pass
  23. }
  24. personId, err := fixokJsonPassPersonIdN.Int64()
  25. if err != nil {
  26. panic(err)
  27. }
  28. pass.EmpGUID = int(personId)
  29. //pass.Firstname = fixokJsonPass["Firstname"].(string)
  30. //pass.Lastname = fixokJsonPass["Lastname"].(string)
  31. /*patronymic, patronymicOk := fixokJsonPass["Patronymic"].(string)
  32. if patronymicOk {
  33. pass.Patronymic = &patronymic
  34. }
  35. photoIdN, photoIdOk := fixokJsonPass["photo_id"].(json.Number)
  36. if !photoIdOk {
  37. // print warning
  38. pass.PhotoId = 0
  39. } else {
  40. photoId, err := photoIdN.Int64()
  41. if err != nil {
  42. panic(err)
  43. }
  44. pass.PhotoId = int(photoId)
  45. }
  46. pass.IsActual, _ = fixokJsonPass["is_actual"].(bool)*/
  47. return pass
  48. }
  49. type FixOkRows []FixOkRow
  50. func (passes FixOkRows) ToMap() map[int]*FixOkRow {
  51. passMap := map[int]*FixOkRow{}
  52. for idx, pass := range passes {
  53. passMap[pass.Id] = &passes[idx]
  54. }
  55. return passMap
  56. }