camera_list.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package camera
  4. import (
  5. "context"
  6. "github.com/jaryhe/gopkgs/database"
  7. "github.com/jaryhe/gopkgs/logger"
  8. "go.uber.org/zap"
  9. "smart-site-management/errors"
  10. "smart-site-management/model"
  11. "smart-site-management/pb/v1"
  12. )
  13. func CameraList(ctx context.Context, req *v1.CameraListRequest) (reply *v1.CameraListReply, err error) {
  14. reply = &v1.CameraListReply{}
  15. dbReq := model.CameraListRequest{
  16. Page:req.Page,
  17. ProjectId:req.ProjectId,
  18. VssId:req.VssId,
  19. IsUnused: req.IsUnused,
  20. IsAll:req.IsAll,
  21. DeviceId:req.DeviceId,
  22. }
  23. list, total, err := model.CameraList(database.DB(), &dbReq)
  24. if err != nil {
  25. logger.Error("CameraList",
  26. zap.String("err", err.Error()))
  27. return nil, errors.DataBaseError
  28. }
  29. reply.Page = req.Page
  30. reply.Total = total
  31. reply.PageSize = int32(model.PageSize)
  32. if total == 0 {
  33. return reply, nil
  34. }
  35. reply.List = make([]*v1.CameraListItem, len(list))
  36. for i, v := range list{
  37. item := &v1.CameraListItem{
  38. VssId:v.VssId,
  39. VssSn:v.VssSn,
  40. VssName:v.VssName,
  41. DeviceId:v.DeviceId,
  42. DeviceSn:v.DeviceSn,
  43. ChannelId:v.ChannelId,
  44. ChannelNo:v.ChannelNo,
  45. ChannelName:v.ChannelName,
  46. }
  47. reply.List[i] = item
  48. }
  49. reply.Page = req.Page
  50. reply.Total = total
  51. reply.PageSize = int32(model.PageSize)
  52. return reply, nil
  53. }