using Infrastructure; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using OpenAuth.App.BaseApp.Base; using OpenAuth.App.Const; using OpenAuth.App.Response; using OpenAuth.App.ServiceApp.FireManagement; using OpenAuth.App.ServiceApp.FireManagement.Request; using OpenAuth.App.ServiceApp.FireManagement.Response; using OpenAuth.Repository.Domain.FireManagement; using DocumentFormat.OpenXml.EMMA; using OpenAuth.Repository.Domain; namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement { /// /// 防火管理模块 /// [Route("api/[controller]/[action]")] [ApiController] public class FireManagementController : ControllerBase { private readonly FireManagementApp _app; public FireManagementController(FireManagementApp app) { _app = app; } #region 任务 /// /// 下发防火线索任务 /// /// 防火任信息 /// [HttpPost] public async Task> IssuedFireClueTask(FmFireclueTask info) { Response response = new Response(); try { return await _app.IssuedFireClueTask(info); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询接收人员 /// /// /// [HttpGet] public async Task>> LoadFireClueUser(string username, string unitname) { Response> response = new Response>(); try { return await _app.LoadFireClueUser(username, unitname); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询任务列表 /// /// /// [HttpGet] public async Task>> GetTaskList() { Response> response = new Response>(); try { return await _app.GetTaskList(); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 任务详情 /// /// /// /// [HttpGet] public async Task> LoadFireTaskInfoById(long id, string userid) { Response response = new Response(); try { return await _app.LoadFireTaskInfoById(id, userid); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 删除任务 /// /// /// [HttpPost] public async Task> DeleteTask(long id) { Response response = new Response(); try { return await _app.DeleteTask(id); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 更新任务状态 /// /// 任务id /// 状态1-待接收,2-已接收,3-已完成 /// 接收人Id /// [HttpPost] [AllowAnonymous] public async Task> ReceiveFireClueTask(long taskid, int state, string recipient) { Response response = new Response(); try { return await _app.ReceiveFireClueTask(taskid, state, recipient); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询任务列表--后台使用 /// /// /// [HttpGet] public async Task>>> GetTaskPageList([FromQuery] FireClueTaskReq req) { Response>> response = new Response>>(); try { return await _app.GetTaskPageList(req); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } #endregion #region 人员单位管理 /// /// 查询人员单位信息 /// /// [HttpGet] public async Task>> GetUserUnit() { Response> response = new Response>(); try { return await _app.GetUserUnit(); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 添加人员单位 /// /// /// [HttpPost] public async Task> AddUserUnit(FmUserUnit info) { Response response = new Response(); try { return await _app.AddUserUnit(info); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 编辑人员单位 /// /// /// [HttpPost] public async Task> EditUserUnit(FmUserUnit info) { Response response = new Response(); try { return await _app.EditUserUnit(info); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 删除人员单位 /// /// /// [HttpPost] public async Task> DeleteUserUnit(long id) { Response response = new Response(); try { return await _app.DeleteUserUnit(id); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 获取单条人员单位 /// /// /// [HttpGet] public async Task> LoadUserUnitById(long id) { Response response = new Response(); try { return await _app.LoadUserUnitById(id); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 人员单位信息导入 /// /// /// [HttpPost] public Response FireUserUnitUpload(IFormFileCollection formFiles) { Response response = new(); try { return _app.FireUserUnitUpload(formFiles); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } #endregion #region 火情线索 /// /// 添加火情线索 /// /// /// [HttpPost] public async Task> AddFireClueInfo(FmFireclueInfo info) { Response response = new(); try { return await _app.AddFireClueInfo(info); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// H5 添加火情线索 /// /// /// [HttpPost] [AllowAnonymous] public async Task> AddFireClueInfoGZFK(FmFireclueInfo info) { Response response = new(); try { return await _app.AddFireClueInfoGZFK(info); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 添加火情线索日志 /// /// /// [HttpPost] public async Task> AddFireClueLogInfo(FmFireclueinfoLog info) { Response response = new(); try { return await _app.AddFireClueLogInfo(info); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询火情线索 /// /// [HttpGet] public async Task> LoadClueInfoById(long id) { Response response = new Response(); try { return await _app.LoadClueInfoById(id); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询火情日志 /// /// /// [HttpGet] [AllowAnonymous] public async Task>> GetFireClueLog(long id) { Response> response = new Response>(); try { return await _app.GetFireClueLog(id); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 获取火情信息和摄像机信息 /// /// /// [HttpGet] public async Task> LoadClueWithInfoById(long id) { Response response = new Response(); try { return await _app.LoadClueWithInfoById(id); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询火情线索列表 /// /// [HttpGet] public async Task>> GetFireClueList() { Response> response = new Response>(); try { return await _app.GetFireClueList(); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询火情线索列表--后台用 /// /// [HttpGet] public async Task>>> GetFireCluePageList([FromQuery]FireClueInfoReq req) { Response>> response = new Response>>(); try { return await _app.GetFireCluePageList(req); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 修改火情线索状态 /// /// /// /// [HttpPost] [AllowAnonymous] public async Task> UpdatFireStateById(long id, int state) { Response response = new Response(); try { return await _app.UpdatFireState(id, state); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 按日期统计火情线索 /// /// 1-月,2-年 /// [HttpGet] public async Task>> GetFireClueStatistics(int type) { Response> response = new Response>(); try { return await _app.GetFireClueStatistics(type); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 按状态统计火情线索 /// /// 1-日,2-月,3-年 /// [HttpGet] public async Task>> GetFireClueStatisticsByState(int type) { Response> response = new Response>(); try { return await _app.GetFireClueStatisticsByState(type); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 按等级统计火情线索 /// /// 1-日,2-月,3-年 /// [HttpGet] public async Task>> GetFireClueStatisticsByDegreeType(int type) { Response> response = new Response>(); try { return await _app.GetFireClueStatisticsByDegreeType(type); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } #endregion /// /// 在线情况 /// /// /// [HttpPost] public async Task>> GetPointUserOnLine(UserOnLineReq pageReq) { Response> response = new Response>(); try { return await _app.GetPointUserOnLine(pageReq); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 添加人员坐标点 /// /// 坐标点 /// [HttpPost] public async Task> AddPoint(FmUserPoint info) { return await _app.AddPointAsync(info); } /// /// 地图标绘保存 /// /// /// [HttpPost] [AllowAnonymous] public async Task> SaveMapPlotting(MapPlottingReq req) { if (string.IsNullOrEmpty(req.Title)) { return new Response() { Code = 500, Message = "标题不能为空" }; } if (string.IsNullOrEmpty(req.Description)) { return new Response() { Code = 500, Message = "描述不能为空" }; } return await _app.SaveMapPlotting(req); } /// /// 地图村绘列表 /// /// /// [HttpGet] [AllowAnonymous] public async Task>> GetMapPlotting([FromQuery] PageReq req) { return await _app.GetMapPlotting(req); } /// /// 查询人员上报的线索 /// /// /// /// /// /// [HttpGet] [AllowAnonymous] public async Task>>> LoadFireClueInfoByUserId(int pageIndex, int state, int pageSize, string userid) { return await _app.LoadFireClueInfoByUserId(pageIndex, state, pageSize, userid); } /// /// 获取视频流 /// /// /// [HttpGet] [AllowAnonymous] public string GetPreviewURLs(string deviceCode, string protocol) { try { return _app.GetPreviewURLs(deviceCode, protocol); } catch (Exception ex) { return ex.Message.ToString(); } } /// /// 获取视频流---海康平台2 /// /// /// [HttpGet] [AllowAnonymous] public string GetPreviewURLs2(string deviceCode, string protocol) { try { return _app.GetPreviewURLs2(deviceCode, protocol); } catch (Exception ex) { return ex.Message.ToString(); } } #region 人员类型统计查询 [HttpGet] [AllowAnonymous] public async Task> GetUserTypeStatistics() { Response response = new Response(); try { return await _app.GetUserTypeStatistics(); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } #endregion #region 获取物资相关接口 /// /// 查询全部营房信息 /// /// [HttpGet] [AllowAnonymous] public Response> GetAllYingFang() { Response> response = new Response>(); try { response.Result = _app.GetAllYingFang(); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 物资储备点 /// /// 物资名称 /// /// [HttpGet] [AllowAnonymous] public TableData Loadwuzichubei(string wuzi, string areaname) { return _app.Loadwuzichubei(wuzi, areaname); } #endregion #region app任务 /// /// 查询火情任务列表 /// /// /// /// /// [HttpGet] [AllowAnonymous] public async Task>>> LoadFireClueTaskByUserId(string userid, int pageIndex = 1, int pageSize = 10) { Response>> response = new Response>>(); try { return await _app.LoadFireClueTaskByUserId(userid, pageIndex, pageSize); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询所有任务 /// /// /// /// [HttpGet] [AllowAnonymous] public async Task>>> LoadAllTask(int pageIndex = 1, int pageSize = 10) { Response>> response = new Response>>(); try { return await _app.LoadAllTask(pageIndex, pageSize); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询线索 /// /// /// /// /// [HttpPost] [AllowAnonymous] public async Task>>> LoadFireClueInfoByAreaName(string areaname, int pageIndex = 1, int pageSize = 10) { Response>> response = new Response>>(); try { return await _app.LoadFireClueInfoByAreaName(areaname, pageIndex = 1, pageSize = 10); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询在线人员 /// /// [HttpGet] [AllowAnonymous] public async Task>> GetPointByAPP() { Response> response = new Response>(); try { return await _app.GetPointByAPPAsync(); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } #endregion #region 感知中心--摄像头类型 /// /// 感知中心--摄像头类型统计 /// /// [HttpGet] [AllowAnonymous] public async Task>> GetCameraCountByType() { try { return await _app.GetCameraCountByType(); } catch (Exception ex) { return new Response> { Result = null, Message = ex.Message.ToString() }; } } #endregion #region 海康火情订阅 /// /// 海康 报警事件订阅回调方法 火点检测 192515,烟火检测 192514 ,烟雾检测 192513 /// /// /// [HttpPost] [AllowAnonymous] public async Task> AddCameraFireInfo(dynamic str) { var param = JsonConvert.DeserializeObject(str.ToString()); FmFireclueInfo ewInfo = new FmFireclueInfo(); ewInfo.Address = param["params"]["events"][0]["data"]["fireDetection"][0]["targetAttrs"]["cameraAddress"]; ewInfo.EventId = param["params"]["events"][0]["eventId"]; ewInfo.ReportTime = param["params"]["events"][0]["happenTime"]; ewInfo.Image = param["params"]["events"][0]["data"]["fielddetection"][0]["imageUrl"]; //ewInfo.EWAddress = param["params"]["events"][0]["data"]["fielddetection"][0]["targetAttrs"]["cameraAddress"]; ewInfo.CreateId = param["params"]["events"][0]["data"]["fielddetection"][0]["targetAttrs"]["cameraIndexCode"]; ewInfo.Lat = param["params"]["events"][0]["data"]["fielddetection"][0]["targetAttrs"]["latitude"]; ewInfo.Lng = param["params"]["events"][0]["data"]["fielddetection"][0]["targetAttrs"]["longitude"]; ewInfo.SourceType = (int)SourceType.摄像头; ewInfo.State = (int)State.上报; ewInfo.AreaName = "feixian"; Response response = new Response(); try { return await _app.AddFireClueInfo(ewInfo); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException != null ? ex.InnerException.Message : ex.Message; response.Result=false; return response; } } #endregion #region 摄像头信息处理 /// /// 大华摄像头添加 /// /// 所属县区 /// [HttpPost] [AllowAnonymous] public async Task> AddCameraInfoYingJi(string county) { Response response = new Response(); try { return await _app.AddCameraInfoYingJi(county); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 获取海康平台摄像头列表信息,添加到数据库 /// /// 海康平台ip /// 海康平台端口 /// 组织架构路径id /// appkey /// appsecret /// [HttpPost] [AllowAnonymous] public async Task> AddHaiKangCameraInfo(string ip, int port, string pathid, string appkey, string appsecret) { Response response = new Response(); try { return await _app.AddHaiKangCameraInfo(ip,port,pathid,appkey,appsecret); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } /// /// 查询摄像头列表--后台使用 /// /// [HttpGet] [AllowAnonymous] public async Task>>> GetCameraInfoPageList([FromQuery]FmCameraReq req) { Response>> response = new Response>>(); try { return await _app.GetCameraInfoPageList(req); } catch (Exception ex) { response.Code = 500; response.Message = ex.InnerException?.Message ?? ex.Message; } return response; } #endregion } }