saibo_httpv1_commander.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package gate_command
  2. import (
  3. "git.getensh.com/common/gopkgs/database"
  4. "property-device/errors"
  5. dbmodel "property-device/model"
  6. "property-device/utils/gate_utils"
  7. "time"
  8. )
  9. type SaiboHttpv1Commander struct {
  10. command bool
  11. GateInfo *dbmodel.TGate
  12. }
  13. func (p *SaiboHttpv1Commander) Open() error {
  14. now := time.Now()
  15. tgc := &dbmodel.TGateCommand{
  16. CreatedAt: now,
  17. UpdatedAt: now,
  18. DeviceId: p.GateInfo.ID,
  19. //Param: req.CmdParams,
  20. Desc: gate_utils.CommandCodeMap[gate_utils.OpenCommand],
  21. Status: gate_utils.CommandStatusWait,
  22. ResultStatus: 0,
  23. ResultStatusDesc: "",
  24. Code: gate_utils.OpenCommand,
  25. }
  26. err := tgc.Insert(database.DB())
  27. if err != nil {
  28. return errors.DataBaseError
  29. }
  30. p.command = true
  31. return nil
  32. }
  33. func (p *SaiboHttpv1Commander) Reboot() error {
  34. now := time.Now()
  35. tgc := &dbmodel.TGateCommand{
  36. CreatedAt: now,
  37. UpdatedAt: now,
  38. DeviceId: p.GateInfo.ID,
  39. //Param: req.CmdParams,
  40. Desc: gate_utils.CommandCodeMap[gate_utils.RebootCommand],
  41. Status: gate_utils.CommandStatusWait,
  42. ResultStatus: 0,
  43. ResultStatusDesc: "",
  44. Code: gate_utils.RebootCommand,
  45. }
  46. err := tgc.Insert(database.DB())
  47. if err != nil {
  48. return errors.DataBaseError
  49. }
  50. p.command = true
  51. return nil
  52. }
  53. func (p *SaiboHttpv1Commander) Command() bool {
  54. return p.command
  55. }