123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565 |
- using log4net;
- using Microsoft.AspNetCore.Authorization;
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc;
- using Ropin.Inspection.Api.Common;
- using Ropin.Inspection.Model.SearchModel.VMC;
- using Ropin.Inspection.Model.ViewModel.VMC;
- using Ropin.Inspection.Model;
- using Ropin.Inspection.Service.VMC.Interface;
- using System.Threading.Tasks;
- using System;
- using Ropin.Inspection.Model.Entities;
- using Ropin.Inspection.Common.Helper;
- using System.Collections.Generic;
- using System.Linq;
- using Ropin.Inspection.Model.Common;
- namespace Ropin.Inspection.Api.Controllers.VMC
- {
- public class VmcCameraController : BaseController
- {
- private readonly IVmcCameraService _repository;
- private static readonly ILog log = LogManager.GetLogger(typeof(VmcCameraController));
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="repository"></param>
- public VmcCameraController(IVmcCameraService repository)
- {
- _repository = repository;
- }
- /// <summary>
- /// 新增
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateAsync")]
- public async Task<ApiResult> CreateAsync(VmcCameraViewModel content)
- {
- if (content == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _repository.CreateOneAsync(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 删除
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpDelete("DeleteAsync/{id}")]
- public async Task<ApiResult> DeleteAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _repository.DeleteAsync(id);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 禁用
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- [HttpPut("ForbiddenAsync/{id}")]
- public async Task<ApiResult> ForbiddenAsync(string id)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _repository.ForbiddenAsync(id);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 更新
- /// </summary>
- /// <param name="id"></param>
- /// <param name="updateModel"></param>
- /// <returns></returns>
- [HttpPut("UpdateAsync/{id}")]
- [AllowAnonymous]
- public async Task<ApiResult> UpdateAsync(string id, VmcCameraViewModel updateModel)
- {
- if (string.IsNullOrEmpty(id))
- {
- return new ApiResult(ReturnCode.GeneralError);
- }
- try
- {
- await _repository.UpdateAsync(updateModel, id);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 获取列表
- /// </summary>
- /// <returns></returns>
- [HttpPost("PageAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> PageAsync(VmcCameraSearch searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var contentList = await _repository.GetConditionAsync(searchModel);
- return new ApiResult<PagesModel<VmcCameraViewModel>>(new PagesModel<VmcCameraViewModel>(contentList, searchModel));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 通过id获取详情
- /// </summary>
- /// <returns></returns>
- [HttpGet("DetailsAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> DetailsAsync(string Id)
- {
- if (string.IsNullOrEmpty(Id))
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- VmcCameraViewModel data = await _repository.GetByIdAsync(Id);
- return new ApiResult<VmcCameraViewModel>(data);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 新增业主摄像头迁移
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateCameraMigrateAsync")]
- public async Task<ApiResult> CreateCameraMigrateAsync(TVMC_CameraMigrate content)
- {
- if (content == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _repository.CreateCameraMigrate(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 获取业主摄像头迁移列表
- /// </summary>
- /// <returns></returns>
- [HttpPost("CameraMigratePageAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> CameraMigratePageAsync(VmcCameraMigrateSearch searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var contentList = await _repository.GetCameraMigrateConditionAsync(searchModel);
- return new ApiResult<PagesModel<VmcCameraMigrateViewModel>>(new PagesModel<VmcCameraMigrateViewModel>(contentList, searchModel));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 新增设备摄像头关联-单实体
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateDevCameraAsync")]
- public async Task<ApiResult> CreateDevCameraAsync(TVMC_DevCamera content)
- {
- if (content == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _repository.CreateDevCamera(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 新增设备摄像头关联-列表
- /// </summary>
- /// <param name="content"></param>
- /// <returns></returns>
- [HttpPost("CreateDevCameraListAsync")]
- public async Task<ApiResult> CreateDevCameraListAsync(VmcDevCamera content)
- {
- if (content == null||content.CameraList == null|| content.CameraList.Count==0)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- await _repository.CreateDevCameraList(content);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- return new ApiResult(ReturnCode.Success);
- }
- /// <summary>
- /// 获取设备摄像头列表
- /// </summary>
- /// <returns></returns>
- [HttpPost("DevCameraPageAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> DevCameraPageAsync(VmcDevSearch searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- var contentList = await _repository.GetDevCameraConditionAsync(searchModel);
- return new ApiResult<PagesModel<VmcDevCameraViewModel>>(new PagesModel<VmcDevCameraViewModel>(contentList, searchModel));
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取LiveGBS登录token
- /// </summary>
- /// <returns></returns>
- [HttpGet("GetLiveFBSToken")]
- [AllowAnonymous]
- public async Task<ApiResult> GetLiveFBSToken()
- {
- try
- {
- GBSToken token = await LiveGBSHelper.GetToken();
- return new ApiResult<GBSToken>(token);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 获取LiveGBS列表
- /// </summary>
- /// <returns></returns>
- [HttpPost("GetLiveFBSListAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> GetLiveFBSListAsync(TbdmCodeSearchModel searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- if (!string.IsNullOrEmpty(searchModel.C_Value))
- {
- switch (searchModel.C_Code)
- {
- case "VIDEO_TYPE_001": LiveGBSHelper.loginUrl = searchModel.C_Value;break;
- default:
- break;
- }
- }
- //LiveGBS
- if (searchModel.C_Code== "VIDEO_TYPE_001")
- {
- List<LiveGBSModel> list = new List<LiveGBSModel>();
- DeviceChanneModel channeModel = await LiveGBSHelper.GetDeviceChannellist();
- if (channeModel != null && channeModel.ChannelList.Count > 0)
- {
- foreach (var item in channeModel.ChannelList)
- {
- LiveGBSModel model = new LiveGBSModel();
- model.ChannelID = item.ID;
- model.DeviceID = item.DeviceID;
- model.DeviceName = item.DeviceName;
- model.DeviceOnline = item.DeviceOnline;
- model.Channel = item.Channel;
- model.Name = item.Name;
- model.SnapURL = item.SnapURL;
- model.Model = item.Model;
- model.Status = item.Status;
- ChannelVideo channelVideo = await LiveGBSHelper.GeChannelVideo(item.DeviceID, item.ID);
- if (channelVideo != null)
- {
- model.StreamID = channelVideo.StreamID;
- model.SMSID = channelVideo.SMSID;
- if (!string.IsNullOrEmpty(channelVideo.FLV))
- {
- string flv = "/sms" + channelVideo.FLV?.Split("sms")[1];
- model.FLV = flv;
- }
- if (!string.IsNullOrEmpty(channelVideo.HLS))
- {
- string hls = "/sms" + channelVideo.HLS?.Split("sms")[1];
- model.HLS = hls;
- }
- model.RTMP = channelVideo.RTMP;
- //model.VSnapURL = channelVideo.SnapURL;
- model.WEBRTC = channelVideo.WEBRTC;
- model.WS_FLV = channelVideo.WS_FLV;
- }
- list.Add(model);
- }
- }
- return new ApiResult<List<LiveGBSModel>>(list);
- }
- else
- {
- return new ApiResult<object>(null);
- }
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 前端设备录像(历史视频)
- /// </summary>
- /// <returns></returns>
- [HttpPost("GetLiveFBSHistoryAsync")]
- [AllowAnonymous]
- public async Task<ApiResult> GetLiveFBSHistoryAsync(VmcCameraSearch searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- bool IsPage = searchModel.IsPagination;
- searchModel.IsPagination = false;
- var contentList = await _repository.GetConditionAsync(searchModel);
- if (contentList == null)
- {
- return new ApiResult<IEnumerable<RecordList>>(null);
- }
- List<RecordList> list = new List<RecordList>();
- foreach (var content in contentList)
- {
- //LiveGBS
- if (content.C_Type == "VIDEO_TYPE_001")
- {
- if (!string.IsNullOrEmpty(content.C_Serial) && !string.IsNullOrEmpty(content.C_CameraCode))
- {
- LiveGBSHelper.loginUrl = content.TypeValue;
- string startTime = searchModel.VideoStartData;
- string EndTime = searchModel.VideoEndData;
- if (string.IsNullOrEmpty(startTime))
- {
- startTime = DateTime.Now.AddHours(-1).ToString("yyy-MM-ddTHH:mm:ss");
- }
- if (string.IsNullOrEmpty(EndTime))
- {
- EndTime = DateTime.Now.ToString("yyy-MM-ddTHH:mm:ss");
- }
- playbackRecordList datas = await LiveGBSHelper.playbackRecordList(content.C_Serial, content.C_CameraCode, startTime, EndTime);
- if (datas != null && datas.RecordList != null && datas.RecordList.Count > 0)
- {
- datas.RecordList.ForEach(record =>
- {
- record.CameraName = content.C_Name;
- record.DeviceID = content.C_Serial;
- record.ChannelID = content.C_CameraCode;
- });
- list.AddRange(datas.RecordList);
- }
- }
- }
- }
- searchModel.TotalCount=list.Count;
- if (IsPage)
- {
- var pageLIst= list.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize);
- return new ApiResult<PagesModel<RecordList>>(new PagesModel<RecordList>(pageLIst, searchModel));
- }
- else
- {
- return new ApiResult<PagesModel<RecordList>>(new PagesModel<RecordList>(list, searchModel));
- }
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 前端设备录像-视频回放
- /// </summary>
- /// <returns></returns>
- [HttpPost("LiveFBSPlaybackStart")]
- [AllowAnonymous]
- public async Task<ApiResult> LiveFBSPlaybackStart(LiveFBSSearch searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- string startTime = searchModel.VideoStartData;
- string EndTime = searchModel.VideoEndData;
- ChannelVideo datas = await LiveGBSHelper.playbackStart(searchModel.C_Serial, searchModel.C_CameraCode, startTime, EndTime,searchModel.Download,searchModel.DownloadSpeed);
- if (!string.IsNullOrEmpty(datas.FLV))
- {
- string flv = "/sms" + datas.FLV?.Split("sms")[1];
- datas.FLV = flv;
- }
- if (!string.IsNullOrEmpty(datas.HLS))
- {
- string hls = "/sms" + datas.HLS?.Split("sms")[1];
- datas.HLS = hls;
- }
- return new ApiResult<ChannelVideo>(datas);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 前端设备录像-回放控制
- /// </summary>
- /// <returns></returns>
- [HttpPost("LiveFBSPlaybackControl")]
- [AllowAnonymous]
- public async Task<ApiResult> LiveFBSPlaybackControl(LiveGBSPlayControl searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- string datas = await LiveGBSHelper.playbackControl(searchModel.StreamId, searchModel.Command,searchModel.Range, searchModel.Scale);
- return new ApiResult<object>(datas);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 前端设备录像- 视频回放流停止
- /// </summary>
- /// <returns></returns>
- [HttpPost("LiveFBSPlaybackStop")]
- [AllowAnonymous]
- public async Task<ApiResult> LiveFBSPlaybackStop(LiveFBSSearch searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- playbackStopPlaybackFileURL datas = await LiveGBSHelper.playbackStop(searchModel.StreamId);
- if (datas!=null&&!string.IsNullOrEmpty(datas.PlaybackFileURL))
- {
- string hls = "/sms" + datas.PlaybackFileURL.Split("sms")[1];
- datas.PlaybackFileURL = hls;
- }
- return new ApiResult<playbackStopPlaybackFileURL>(datas);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- /// <summary>
- /// 前端设备录像- 单条回放流信息
- /// </summary>
- /// <returns></returns>
- [HttpPost("LiveFBSPlaybackStreaminfo")]
- [AllowAnonymous]
- public async Task<ApiResult> LiveFBSPlaybackStreaminfo(LiveFBSSearch searchModel)
- {
- if (searchModel == null)
- {
- return new ApiResult(ReturnCode.ArgsError);
- }
- try
- {
- playbackStreaminfoEntity datas = await LiveGBSHelper.playbackStreaminfo(searchModel.StreamId);
- if (datas != null && !string.IsNullOrEmpty(datas.PlaybackFileURL))
- {
- string hls = "/sms" + datas.PlaybackFileURL.Split("sms")[1];
- datas.PlaybackFileURL = hls;
- }
- return new ApiResult<playbackStreaminfoEntity>(datas);
- }
- catch (Exception ex)
- {
- return new ApiResult(ReturnCode.GeneralError, ex.Message);
- }
- }
- }
- }
|