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;
using Hopetry.App.SugarModel.CommonModel;
using Yitter.IdGenerator;

namespace OpenAuth.WebApi.Controllers.ServiceControllers.FireManagement
{
    /// <summary>
    /// 防火管理模块
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class FireManagementController : ControllerBase
    {
        private readonly FireManagementApp _app;

        public FireManagementController(FireManagementApp app)
        {
            _app = app;
        }

        #region   任务
        /// <summary>
        /// 下发防火线索任务
        /// </summary>
        /// <param name="info">防火任信息</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> IssuedFireClueTask(FmFireclueTask info)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.IssuedFireClueTask(info);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 查询接收人员
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<SysUserResp>>> LoadFireClueUser(string username, string unitname)
        {
            Response<List<SysUserResp>> response = new Response<List<SysUserResp>>();
            try
            {
                return await _app.LoadFireClueUser(username, unitname);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 查询任务列表
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<FmFireclueTask>>> GetTaskList()
        {
            Response<List<FmFireclueTask>> response = new Response<List<FmFireclueTask>>();
            try
            {
                return await _app.GetTaskList();
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 任务详情
        /// </summary>
        /// <param name="id"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<FireClueTaskResp>> LoadFireTaskInfoById(long id, string userid)
        {
            Response<FireClueTaskResp> response = new Response<FireClueTaskResp>();
            try
            {
                return await _app.LoadFireTaskInfoById(id, userid);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 删除任务
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> DeleteTask(long id)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.DeleteTask(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 更新任务状态
        /// </summary>
        /// <param name="taskid">任务id</param>
        /// <param name="state">状态1-待接收，2-已接收，3-已完成</param>
        /// <param name="recipient">接收人Id</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> ReceiveFireClueTask(long taskid, int state, string recipient)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.ReceiveFireClueTask(taskid, state, recipient);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 查询任务列表--后台使用
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<FmFireclueTask>>>> GetTaskPageList([FromQuery] FireClueTaskReq req)
        {
            Response<PageInfo<List<FmFireclueTask>>> response = new Response<PageInfo<List<FmFireclueTask>>>();
            try
            {
                return await _app.GetTaskPageList(req);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        #endregion


        #region 人员单位管理
        /// <summary>
        /// 查询人员单位信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<FmUserUnit>>> GetUserUnit()
        {
            Response<List<FmUserUnit>> response = new Response<List<FmUserUnit>>();
            try
            {
                return await _app.GetUserUnit();
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 添加人员单位
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> AddUserUnit(FmUserUnit info)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.AddUserUnit(info);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 编辑人员单位
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> EditUserUnit(FmUserUnit info)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.EditUserUnit(info);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 删除人员单位
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> DeleteUserUnit(long id)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.DeleteUserUnit(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 获取单条人员单位
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]

        public async Task<Response<FmUserUnit>> LoadUserUnitById(long id)
        {
            Response<FmUserUnit> response = new Response<FmUserUnit>();
            try
            {
                return await _app.LoadUserUnitById(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }


        /// <summary>
        /// 人员单位信息导入
        /// </summary>
        /// <param name="formFiles"></param>
        /// <returns></returns>
        [HttpPost]
        public Response<bool> FireUserUnitUpload(IFormFileCollection formFiles)
        {
            Response<bool> response = new();
            try
            {
                return _app.FireUserUnitUpload(formFiles);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }


        #endregion

        #region 火情线索
        /// <summary>
        /// 添加火情线索
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> AddFireClueInfo(FmFireclueInfo info)
        {
            Response<bool> response = new();
            try
            {
                return await _app.AddFireClueInfo(info);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// H5 添加火情线索
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> AddFireClueInfoGZFK(FmFireclueInfo info)
        {
            Response<bool> response = new();
            try
            {
                return await _app.AddFireClueInfoGZFK(info);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 添加火情线索日志
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> AddFireClueLogInfo(FmFireclueinfoLog info)
        {
            Response<bool> response = new();
            try
            {
                return await _app.AddFireClueLogInfo(info);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 查询火情线索
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<FmFireclueInfo>> LoadClueInfoById(long id)
        {
            Response<FmFireclueInfo> response = new Response<FmFireclueInfo>();
            try
            {
                return await _app.LoadClueInfoById(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 查询火情日志
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<List<FmFireclueinfoLog>>> GetFireClueLog(long id)
        {
            Response<List<FmFireclueinfoLog>> response = new Response<List<FmFireclueinfoLog>>();
            try
            {
                return await _app.GetFireClueLog(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 获取火情信息和摄像机信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<dynamic>> LoadClueWithInfoById(long id)
        {
            Response<dynamic> response = new Response<dynamic>();
            try
            {
                return await _app.LoadClueWithInfoById(id);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 查询火情线索列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<FmFireclueInfo>>> GetFireClueList()
        {
            Response<List<FmFireclueInfo>> response = new Response<List<FmFireclueInfo>>();
            try
            {
                return await _app.GetFireClueList();
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 查询火情线索列表--后台用
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<PageInfo<List<FmFireclueInfo>>>> GetFireCluePageList([FromQuery]FireClueInfoReq req)
        {
            Response<PageInfo<List<FmFireclueInfo>>> response = new Response<PageInfo<List<FmFireclueInfo>>>();
            try
            {
                return await _app.GetFireCluePageList(req);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 修改火情线索状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> UpdatFireStateById(long id, int state)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.UpdatFireState(id, state);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 按日期统计火情线索
        /// </summary>
        /// <param name="type">1-月，2-年</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<FireInfoForChart>>> GetFireClueStatistics(int type)
        {
            Response<List<FireInfoForChart>> response = new Response<List<FireInfoForChart>>();
            try
            {
                return await _app.GetFireClueStatistics(type);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 按状态统计火情线索
        /// </summary>
        /// <param name="type">1-日，2-月，3-年</param>
        /// <param name="sourcetype">来源类型APP = 1 高空瞭望 = 2无人机 = 3人工合并 = 4，公众反馈=5  卫星遥感=6，摄像头=7</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<FireInfoStateForChart>>> GetFireClueStatisticsByState(int type,List<int> sourcetype)
        {
            Response<List<FireInfoStateForChart>> response = new Response<List<FireInfoStateForChart>>();
            try
            {
                return await _app.GetFireClueStatisticsByState(type,sourcetype);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 按等级统计火情线索
        /// </summary>
        /// <param name="type">1-日，2-月，3-年</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Response<List<FireInfoDegreeForChart>>> GetFireClueStatisticsByDegreeType(int type)
        {
            Response<List<FireInfoDegreeForChart>> response = new Response<List<FireInfoDegreeForChart>>();
            try
            {
                return await _app.GetFireClueStatisticsByDegreeType(type);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        #endregion
        /// <summary>
        /// 在线情况
        /// </summary>
        /// <param name="pageReq"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<PageInfo<dynamic>>> GetPointUserOnLine(UserOnLineReq pageReq)
        {
            Response<PageInfo<dynamic>> response = new Response<PageInfo<dynamic>>();
            try
            {
                return await _app.GetPointUserOnLine(pageReq);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }


        /// <summary>
        /// 添加人员坐标点
        /// </summary>
        /// <param name="info">坐标点</param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Response<bool>> AddPoint(FmUserPoint info)
        {
            return await _app.AddPointAsync(info);
        }

        /// <summary>
        /// 地图标绘保存
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> SaveMapPlotting(MapPlottingReq req)
        {
            if (string.IsNullOrEmpty(req.Title))
            {
                return new Response<bool>() { Code = 500, Message = "标题不能为空" };
            }

            if (string.IsNullOrEmpty(req.Description))
            {
                return new Response<bool>() { Code = 500, Message = "描述不能为空" };
            }
            return await _app.SaveMapPlotting(req);
        }
        /// <summary>
        /// 地图村绘列表
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<dynamic>>> GetMapPlotting([FromQuery] PageReq req)
        {
            return await _app.GetMapPlotting(req);
        }
        /// <summary>
        /// 查询人员上报的线索
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="state"></param>
        /// <param name="pageSize"></param>
        /// <param name="userid"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<FireClueInfoResp>>>> LoadFireClueInfoByUserId(int pageIndex, int state, int pageSize, string userid)
        {
            return await _app.LoadFireClueInfoByUserId(pageIndex, state, pageSize, userid);
        }
        /// <summary>
        /// 获取视频流
        /// </summary>
        /// <param name="deviceCode"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public string GetPreviewURLs(string deviceCode, string protocol)
        {
            try
            {
                return _app.GetPreviewURLs(deviceCode, protocol);
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }

        }



        /// <summary>
        /// 获取单个设备的视频流--通用
        /// </summary>
        /// <param name="cameraIndexCode">设备唯一标识吗</param>
        /// <param name="url">设备地址（例：192.168.10.163）</param>
        /// <param name="appkey"></param>
        /// <param name="appsecret"></param>
        /// <param name="port">设备端口（例1443）</param>
        /// <param name="protocol"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public string GetPreviewURL(string cameraIndexCode, string url, string appkey, string appsecret, int port, string protocol)
        {
            try
            {
                return _app.GetPreviewURL(cameraIndexCode, url,appkey,appsecret,port,protocol);
            }
            catch (Exception ex)
            {
                return ex.Message.ToString();
            }
        }


        /// <summary>
        /// 获取视频流---海康平台2
        /// </summary>
        /// <param name="deviceCode"></param>
        /// <returns></returns>
        [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<Response<UserTypeStatisticsRes>> GetUserTypeStatistics()
        {
            Response<UserTypeStatisticsRes> response = new Response<UserTypeStatisticsRes>();
            try
            {
                return await _app.GetUserTypeStatistics();
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        #endregion

        #region 获取物资相关接口
        /// <summary>
        /// 查询全部营房信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public Response<List<dynamic>> GetAllYingFang()
        {
            Response<List<dynamic>> response = new Response<List<dynamic>>();
            try
            {
                response.Result = _app.GetAllYingFang();
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 物资储备点
        /// </summary>
        /// <param name="wuzi">物资名称</param>
        /// <param name="areaname"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public TableData Loadwuzichubei(string wuzi, string areaname)
        {
            return _app.Loadwuzichubei(wuzi, areaname);
        }
        #endregion

        #region app任务
        /// <summary>
        /// 查询火情任务列表
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<FireClueTaskResp>>>> LoadFireClueTaskByUserId(string userid, int pageIndex = 1, int pageSize = 10)
        {
            Response<PageInfo<List<FireClueTaskResp>>> response = new Response<PageInfo<List<FireClueTaskResp>>>();
            try
            {
                return await _app.LoadFireClueTaskByUserId(userid, pageIndex, pageSize);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 查询所有任务
        /// </summary>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<FireClueTaskResp>>>> LoadAllTask(int pageIndex = 1, int pageSize = 10)
        {
            Response<PageInfo<List<FireClueTaskResp>>> response = new Response<PageInfo<List<FireClueTaskResp>>>();
            try
            {
                return await _app.LoadAllTask(pageIndex, pageSize);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }
        /// <summary>
        /// 查询线索
        /// </summary>
        /// <param name="areaname"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<FireClueInfoResp>>>> LoadFireClueInfoByAreaName(string areaname, int pageIndex = 1, int pageSize = 10)
        {
            Response<PageInfo<List<FireClueInfoResp>>> response = new Response<PageInfo<List<FireClueInfoResp>>>();
            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;
        }
        /// <summary>
        /// 查询在线人员
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<List<RYResApp>>> GetPointByAPP()
        {
            Response<List<RYResApp>> response = new Response<List<RYResApp>>();
            try
            {
                return await _app.GetPointByAPPAsync();
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;

        }
        #endregion

        #region 感知中心--摄像头类型
        /// <summary>
        /// 感知中心--摄像头类型统计
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<List<CameraCountRes>>> GetCameraCountByType()
        {
            try
            {
                return await _app.GetCameraCountByType();
            }
            catch (Exception ex)
            {
                return new Response<List<CameraCountRes>>
                {
                    Result = null,
                    Message = ex.Message.ToString()
                };
            }        
        }
        #endregion

        #region 海康火情订阅
        /// <summary>
        /// 海康 报警事件订阅回调方法  火点检测	192515，烟火检测	192514 ，烟雾检测 192513
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> AddCameraFireInfo(dynamic str)
        {
            var param = JsonConvert.DeserializeObject<JObject>(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<bool> response = new Response<bool>();
            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 摄像头信息处理
        /// <summary>
        /// 大华摄像头添加
        /// </summary>
        /// <param name="county">所属县区</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> AddCameraInfoYingJi(string county)
        {
            Response<bool> response = new Response<bool>();
            try
            {
                return await _app.AddCameraInfoYingJi(county);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        /// <summary>
        /// 获取海康平台摄像头列表信息，添加到数据库
        /// </summary>
        /// <param name="ip">海康平台ip</param>
        /// <param name="port">海康平台端口</param>
        /// <param name="pathid">组织架构路径id</param>
        /// <param name="appkey">appkey</param>
        /// <param name="appsecret">appsecret</param>
        /// <returns></returns>
        [HttpPost]
        [AllowAnonymous]
        public async Task<Response<bool>> AddHaiKangCameraInfo(string ip, int port, string pathid, string appkey, string appsecret)
        {
            Response<bool> response = new Response<bool>();
            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;
        }


        /// <summary>
        /// 查询摄像头列表--后台使用
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [AllowAnonymous]
        public async Task<Response<PageInfo<List<FmCamera>>>> GetCameraInfoPageList([FromQuery]FmCameraReq req)
        {
            Response<PageInfo<List<FmCamera>>> response = new Response<PageInfo<List<FmCamera>>>();
            try
            {
                return await _app.GetCameraInfoPageList(req);
            }
            catch (Exception ex)
            {
                response.Code = 500;
                response.Message = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        #endregion
        #region 在线人员获取
        [HttpGet]
        [AllowAnonymous]
        public async Task<TableData> GetPointByUserTypeAsync(string unitname, int type)
        {
            TableData response = new TableData();
            try
            {
                return await _app.GetPointByUserTypeAsync(unitname,type);
            }
            catch (Exception ex)
            {
                response.code = 500;
                response.msg = ex.InnerException?.Message ?? ex.Message;
            }
            return response;
        }

        #endregion

    }
}
