// Copyright 2019 github.com. All rights reserved. // Use of this source code is governed by github.com. package project import ( "context" "github.com/jaryhe/gopkgs/database" "smart-site-management/errors" "smart-site-management/model" "smart-site-management/pb/v1" ) func DeviceVideoChannel(ctx context.Context, req *v1.DeviceVideoChannelRequest) (reply *v1.DeviceVideoChannelReply, err error) { reply = &v1.DeviceVideoChannelReply{} if req.ProjectId == 0 || req.Sn == ""{ return nil, errors.ParamsError } where := map[string]interface{}{ "project_id":req.ProjectId, "sn":req.Sn, } p := &model.TDevice{} err = p.Find(database.DB(), where) if err != nil { return nil, errors.DataBaseError } if p.Id == 0 { return nil, errors.NoRecordError } if p.VssChannelId == 0 { return reply, nil } pc := model.Vsschanneltbl{} where = map[string]interface{}{ "ID":p.VssChannelId, } err = pc.Find(database.DB(), where) if err != nil { return nil, errors.DataBaseError } if pc.ID == 0 { return nil, errors.NoRecordError } reply.Name = pc.Nickname reply.Id = pc.ID reply.ChannelNo = pc.Chanpubid reply.State = int32(pc.Alive) return reply, nil }