diff --git a/SGGL/WebAPI/Controllers/VideoController.cs b/SGGL/WebAPI/Controllers/VideoController.cs index 88085129..b577f455 100644 --- a/SGGL/WebAPI/Controllers/VideoController.cs +++ b/SGGL/WebAPI/Controllers/VideoController.cs @@ -9,6 +9,8 @@ using System.Text; using BLL; using Microsoft.SqlServer.Server; using System.Configuration; +using System.Linq; +using Model; namespace WebAPI.Controllers { @@ -27,15 +29,38 @@ namespace WebAPI.Controllers var responeData = new Model.ResponeData(); try { - string url = ConfigurationManager.AppSettings["Video_URL"]; - List urls = new List(); - string res = APIGetHttpService.Http(url+"api/v1/device/channeltree"); - - List> jsonNvr = JsonConvert.DeserializeObject>>(res); - foreach (Dictionary nvr in jsonNvr) + using (Model.SGGLDB db = new Model.SGGLDB(Funs.ConnString)) { - string jsonCameras = APIGetHttpService.Http(url+"api/v1/device/channeltree?serial=" + nvr["serial"]); - responeData.data = JsonConvert.DeserializeObject>>(jsonCameras); + Base_Project project = null; + if (!string.IsNullOrEmpty(projectId)) + { + project = db.Base_Project.FirstOrDefault(x => x.ProjectId == projectId); + } + string url = ConfigurationManager.AppSettings["Video_URL"]; + List urls = new List(); + string res = APIGetHttpService.Http(url + "api/v1/device/channeltree"); + List> resDic = new List>(); + List> jsonNvr = JsonConvert.DeserializeObject>>(res); + foreach (Dictionary nvr in jsonNvr) + { + if (project != null && nvr["customName"].ToString() == project.ProjectName) + { + string jsonCameras = APIGetHttpService.Http(url + "api/v1/device/channeltree?serial=" + nvr["serial"]); + responeData.data = JsonConvert.DeserializeObject>>(jsonCameras); + return responeData; + } + else if (project == null) + { + string jsonCameras = APIGetHttpService.Http(url + "api/v1/device/channeltree?serial=" + nvr["serial"]); + resDic.AddRange(JsonConvert.DeserializeObject>>(jsonCameras)); + } + else + { + string jsonCameras = APIGetHttpService.Http(url + "api/v1/device/channeltree?serial=" + nvr["serial"]); + resDic.AddRange(JsonConvert.DeserializeObject>>(jsonCameras)); + } + } + responeData.data = resDic; } }