using Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using OpenAuth.App; using OpenAuth.App.Response; using OpenAuth.Repository.Domain; using Org.BouncyCastle.Ocsp; using Yitter.IdGenerator; using Infrastructure.Helpers; namespace OpenAuth.WebApi.Controllers { /// /// 举报信息 /// [Route("api/[controller]/[action]")] [ApiController] class DroneClueReportingController : ControllerBase { DroneClueReportingApp clueReportingApp; public DroneClueReportingController(DroneClueReportingApp clueReportingApp) { this.clueReportingApp = clueReportingApp; } /// /// 举报查询 /// /// /// /// /// /// /// [HttpGet] [AllowAnonymous] public Response>> QueryClueReporting(string content, string beginDate, string endDate, int page, int limit) { var response = new Response>>(); try { response.Result = clueReportingApp.QueryClueReporting(content, beginDate, endDate, page, limit); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 获取摄像头信息 /// /// [HttpGet] public Response> GetCamerInfos() { var response = new Response>(); try { response.Result = clueReportingApp.GetCamerInfos(); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 通过海康平台添加摄像头信息 /// /// 配置信息id /// 平台地址 /// /// /// [HttpPost] public Response AddCameraInfos(long rtuid, string url, string appkey, string secret) { Response response = new Response(); try { string path = "/artemis/api/resource/v1/cameras"; var obj = new { pageNo = 1, pageSize = 1000 }; string body = JsonConvert.SerializeObject(obj); var result = HIKOpenAPI.HttpPost(url, path, body, appkey, secret); var res = JsonConvert.DeserializeObject(result); List cflist = new List(); foreach (var item in res["data"]["list"]) { DroneCameraInfo cf = new DroneCameraInfo(); cf.deviceId = YitIdHelper.NextId(); cf.deviceNum = item["cameraIndexCode"].ToString(); cf.deviceName = item["cameraName"].ToString(); cf.createTime = DateTime.Now; cf.rtuId = rtuid; cf.address = item["installLocation"].ToString(); if (item["longitude"].ToString() == "") { cf.lnglat = ""; } else { cf.lnglat = item["longitude"].ToString() + "," + item["latitude"].ToString(); } if (item["status"].ToString() == "") { cf.isonline = null; } else { if ((int)item["status"] == 1) { cf.isonline = true; } else { cf.isonline = false; } } cflist.Add(cf); } response.Result = clueReportingApp.AddCameraInfo(cflist); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; } return response; } /// /// 根据坐标点获取摄像头信息 /// /// 经度 /// 维度 /// 距离 /// [HttpGet] public Response> GetCamerInfoByLngLat(string lng, string lat, double distince) { var response = new Response>(); try { response.Result = clueReportingApp.GetCamerInfoByLngLat(lng, lat, distince); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } } }