1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package camera
- import (
- "context"
- "github.com/jaryhe/gopkgs/database"
- "github.com/jaryhe/gopkgs/logger"
- "go.uber.org/zap"
- "smart-site-management/errors"
- "smart-site-management/model"
- "smart-site-management/pb/v1"
- )
- func CameraList(ctx context.Context, req *v1.CameraListRequest) (reply *v1.CameraListReply, err error) {
- reply = &v1.CameraListReply{}
- dbReq := model.CameraListRequest{
- Page:req.Page,
- ProjectId:req.ProjectId,
- VssId:req.VssId,
- IsUnused: req.IsUnused,
- IsAll:req.IsAll,
- DeviceId:req.DeviceId,
- }
- list, total, err := model.CameraList(database.DB(), &dbReq)
- if err != nil {
- logger.Error("CameraList",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- reply.Page = req.Page
- reply.Total = total
- reply.PageSize = int32(model.PageSize)
- if total == 0 {
- return reply, nil
- }
- reply.List = make([]*v1.CameraListItem, len(list))
- for i, v := range list{
- item := &v1.CameraListItem{
- VssId:v.VssId,
- VssSn:v.VssSn,
- VssName:v.VssName,
- DeviceId:v.DeviceId,
- DeviceSn:v.DeviceSn,
- ChannelId:v.ChannelId,
- ChannelNo:v.ChannelNo,
- ChannelName:v.ChannelName,
- }
- reply.List[i] = item
- }
- reply.Page = req.Page
- reply.Total = total
- reply.PageSize = int32(model.PageSize)
- return reply, nil
- }
|