card_saibo_httpv1_whiter.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package gate_card
  2. import (
  3. "encoding/json"
  4. "git.getensh.com/common/gopkgs/database"
  5. dbmodel "property-device/model"
  6. "property-device/utils/gate_utils"
  7. "time"
  8. )
  9. type CardSaiboHttpv1Whiter struct {
  10. Gcard *dbmodel.TGateCard
  11. Device *dbmodel.TGate
  12. UCard *dbmodel.TUserCard
  13. command bool
  14. }
  15. func (p *CardSaiboHttpv1Whiter) PersonAdd() {
  16. params := make([]gate_utils.WhiteParams, 1)
  17. params[0].CodeType = "C"
  18. params[0].CodeVal = p.UCard.CardNumber
  19. params[0].ValidityStart = time.Now().Format("2006-01-02 15:04:05")
  20. params[0].ValidityEnd = "2099-01-02 15:04:05"
  21. params[0].DeleteFlag = "0"
  22. bytes, _ := json.Marshal(params)
  23. now := time.Now()
  24. gcmd := &dbmodel.TGateCommand{
  25. CreatedAt: now,
  26. UpdatedAt: now,
  27. DeviceId: p.Gcard.DeviceId,
  28. Param: string(bytes),
  29. Desc: gate_utils.CommandCodeMap[gate_utils.DownCommand],
  30. Status: gate_utils.CommandStatusWait,
  31. ResultStatus: 0,
  32. ResultStatusDesc: "",
  33. Code: gate_utils.DownCommand,
  34. }
  35. if err := gcmd.Insert(database.DB()); err != nil {
  36. whiteCardSetFail(p.UCard, p.Device, gate_utils.WhiteAddStatusPersonFail, err.Error())
  37. return
  38. }
  39. gcmd = &dbmodel.TGateCommand{
  40. CreatedAt: now,
  41. UpdatedAt: now,
  42. DeviceId: p.Gcard.DeviceId,
  43. Param: string(bytes),
  44. Desc: gate_utils.CommandCodeMap[gate_utils.QueryCommand],
  45. Status: gate_utils.CommandStatusWait,
  46. ResultStatus: 0,
  47. ResultStatusDesc: "",
  48. Code: gate_utils.QueryCommand,
  49. }
  50. if err := gcmd.Insert(database.DB()); err != nil {
  51. whiteCardSetFail(p.UCard, p.Device, gate_utils.WhiteAddStatusPersonFail, err.Error())
  52. return
  53. }
  54. p.command = true
  55. return
  56. }
  57. func (p *CardSaiboHttpv1Whiter) PersonDel() {
  58. params := make([]gate_utils.WhiteParams, 1)
  59. params[0].CodeType = "C"
  60. params[0].CodeVal = p.UCard.CardNumber
  61. params[0].ValidityStart = time.Now().Format("2006-01-02 15:04:05")
  62. params[0].ValidityEnd = "2099-01-02 15:04:05"
  63. params[0].DeleteFlag = "1"
  64. bytes, _ := json.Marshal(params)
  65. now := time.Now()
  66. gcmd := &dbmodel.TGateCommand{
  67. CreatedAt: now,
  68. UpdatedAt: now,
  69. DeviceId: p.Device.ID,
  70. Param: string(bytes),
  71. Desc: gate_utils.CommandCodeMap[gate_utils.DownCommand],
  72. Status: gate_utils.CommandStatusWait,
  73. ResultStatus: 0,
  74. ResultStatusDesc: "",
  75. Code: gate_utils.DownCommand,
  76. }
  77. if err := gcmd.Insert(database.DB()); err != nil {
  78. return
  79. }
  80. gcmd = &dbmodel.TGateCommand{
  81. CreatedAt: now,
  82. UpdatedAt: now,
  83. DeviceId: p.Device.ID,
  84. Param: string(bytes),
  85. Desc: gate_utils.CommandCodeMap[gate_utils.QueryCommand],
  86. Status: gate_utils.CommandStatusWait,
  87. ResultStatus: 0,
  88. ResultStatusDesc: "",
  89. Code: gate_utils.QueryCommand,
  90. }
  91. if err := gcmd.Insert(database.DB()); err != nil {
  92. return
  93. }
  94. p.command = true
  95. return
  96. }
  97. func (p *CardSaiboHttpv1Whiter) Command() bool {
  98. return p.command
  99. }