device_vedio_channel.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package project
  4. import (
  5. "context"
  6. "github.com/jaryhe/gopkgs/database"
  7. "smart-site-management/errors"
  8. "smart-site-management/model"
  9. "smart-site-management/pb/v1"
  10. )
  11. func DeviceVideoChannel(ctx context.Context, req *v1.DeviceVideoChannelRequest) (reply *v1.DeviceVideoChannelReply, err error) {
  12. reply = &v1.DeviceVideoChannelReply{}
  13. if req.ProjectId == 0 || req.Sn == ""{
  14. return nil, errors.ParamsError
  15. }
  16. where := map[string]interface{}{
  17. "project_id":req.ProjectId,
  18. "sn":req.Sn,
  19. }
  20. p := &model.TDevice{}
  21. err = p.Find(database.DB(), where)
  22. if err != nil {
  23. return nil, errors.DataBaseError
  24. }
  25. if p.Id == 0 {
  26. return nil, errors.NoRecordError
  27. }
  28. if p.VssChannelId == 0 {
  29. return reply, nil
  30. }
  31. pc := model.Vsschanneltbl{}
  32. where = map[string]interface{}{
  33. "ID":p.VssChannelId,
  34. }
  35. err = pc.Find(database.DB(), where)
  36. if err != nil {
  37. return nil, errors.DataBaseError
  38. }
  39. if pc.ID == 0 {
  40. return nil, errors.NoRecordError
  41. }
  42. reply.Name = pc.Nickname
  43. reply.Id = pc.ID
  44. reply.ChannelNo = pc.Chanpubid
  45. reply.State = int32(pc.Alive)
  46. return reply, nil
  47. }