VmcCameraController.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  1. using log4net;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Http;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Ropin.Inspection.Api.Common;
  6. using Ropin.Inspection.Model.SearchModel.VMC;
  7. using Ropin.Inspection.Model.ViewModel.VMC;
  8. using Ropin.Inspection.Model;
  9. using Ropin.Inspection.Service.VMC.Interface;
  10. using System.Threading.Tasks;
  11. using System;
  12. using Ropin.Inspection.Model.Entities;
  13. using Ropin.Inspection.Common.Helper;
  14. using System.Collections.Generic;
  15. using System.Linq;
  16. using Ropin.Inspection.Model.Common;
  17. namespace Ropin.Inspection.Api.Controllers.VMC
  18. {
  19. public class VmcCameraController : BaseController
  20. {
  21. private readonly IVmcCameraService _repository;
  22. private static readonly ILog log = LogManager.GetLogger(typeof(VmcCameraController));
  23. /// <summary>
  24. /// 构造函数
  25. /// </summary>
  26. /// <param name="repository"></param>
  27. public VmcCameraController(IVmcCameraService repository)
  28. {
  29. _repository = repository;
  30. }
  31. /// <summary>
  32. /// 新增
  33. /// </summary>
  34. /// <param name="content"></param>
  35. /// <returns></returns>
  36. [HttpPost("CreateAsync")]
  37. public async Task<ApiResult> CreateAsync(VmcCameraViewModel content)
  38. {
  39. if (content == null)
  40. {
  41. return new ApiResult(ReturnCode.ArgsError);
  42. }
  43. try
  44. {
  45. await _repository.CreateOneAsync(content);
  46. }
  47. catch (Exception ex)
  48. {
  49. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  50. }
  51. return new ApiResult(ReturnCode.Success);
  52. }
  53. /// <summary>
  54. /// 删除
  55. /// </summary>
  56. /// <param name="id"></param>
  57. /// <returns></returns>
  58. [HttpDelete("DeleteAsync/{id}")]
  59. public async Task<ApiResult> DeleteAsync(string id)
  60. {
  61. if (string.IsNullOrEmpty(id))
  62. {
  63. return new ApiResult(ReturnCode.GeneralError);
  64. }
  65. try
  66. {
  67. await _repository.DeleteAsync(id);
  68. }
  69. catch (Exception ex)
  70. {
  71. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  72. }
  73. return new ApiResult(ReturnCode.Success);
  74. }
  75. /// <summary>
  76. /// 禁用
  77. /// </summary>
  78. /// <param name="id"></param>
  79. /// <returns></returns>
  80. [HttpPut("ForbiddenAsync/{id}")]
  81. public async Task<ApiResult> ForbiddenAsync(string id)
  82. {
  83. if (string.IsNullOrEmpty(id))
  84. {
  85. return new ApiResult(ReturnCode.GeneralError);
  86. }
  87. try
  88. {
  89. await _repository.ForbiddenAsync(id);
  90. }
  91. catch (Exception ex)
  92. {
  93. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  94. }
  95. return new ApiResult(ReturnCode.Success);
  96. }
  97. /// <summary>
  98. /// 更新
  99. /// </summary>
  100. /// <param name="id"></param>
  101. /// <param name="updateModel"></param>
  102. /// <returns></returns>
  103. [HttpPut("UpdateAsync/{id}")]
  104. [AllowAnonymous]
  105. public async Task<ApiResult> UpdateAsync(string id, VmcCameraViewModel updateModel)
  106. {
  107. if (string.IsNullOrEmpty(id))
  108. {
  109. return new ApiResult(ReturnCode.GeneralError);
  110. }
  111. try
  112. {
  113. await _repository.UpdateAsync(updateModel, id);
  114. }
  115. catch (Exception ex)
  116. {
  117. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  118. }
  119. return new ApiResult(ReturnCode.Success);
  120. }
  121. /// <summary>
  122. /// 获取列表
  123. /// </summary>
  124. /// <returns></returns>
  125. [HttpPost("PageAsync")]
  126. [AllowAnonymous]
  127. public async Task<ApiResult> PageAsync(VmcCameraSearch searchModel)
  128. {
  129. if (searchModel == null)
  130. {
  131. return new ApiResult(ReturnCode.ArgsError);
  132. }
  133. try
  134. {
  135. var contentList = await _repository.GetConditionAsync(searchModel);
  136. return new ApiResult<PagesModel<VmcCameraViewModel>>(new PagesModel<VmcCameraViewModel>(contentList, searchModel));
  137. }
  138. catch (Exception ex)
  139. {
  140. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  141. }
  142. }
  143. /// <summary>
  144. /// 通过id获取详情
  145. /// </summary>
  146. /// <returns></returns>
  147. [HttpGet("DetailsAsync")]
  148. [AllowAnonymous]
  149. public async Task<ApiResult> DetailsAsync(string Id)
  150. {
  151. if (string.IsNullOrEmpty(Id))
  152. {
  153. return new ApiResult(ReturnCode.ArgsError);
  154. }
  155. try
  156. {
  157. VmcCameraViewModel data = await _repository.GetByIdAsync(Id);
  158. return new ApiResult<VmcCameraViewModel>(data);
  159. }
  160. catch (Exception ex)
  161. {
  162. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  163. }
  164. }
  165. /// <summary>
  166. /// 新增业主摄像头迁移
  167. /// </summary>
  168. /// <param name="content"></param>
  169. /// <returns></returns>
  170. [HttpPost("CreateCameraMigrateAsync")]
  171. public async Task<ApiResult> CreateCameraMigrateAsync(TVMC_CameraMigrate content)
  172. {
  173. if (content == null)
  174. {
  175. return new ApiResult(ReturnCode.ArgsError);
  176. }
  177. try
  178. {
  179. await _repository.CreateCameraMigrate(content);
  180. }
  181. catch (Exception ex)
  182. {
  183. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  184. }
  185. return new ApiResult(ReturnCode.Success);
  186. }
  187. /// <summary>
  188. /// 获取业主摄像头迁移列表
  189. /// </summary>
  190. /// <returns></returns>
  191. [HttpPost("CameraMigratePageAsync")]
  192. [AllowAnonymous]
  193. public async Task<ApiResult> CameraMigratePageAsync(VmcCameraMigrateSearch searchModel)
  194. {
  195. if (searchModel == null)
  196. {
  197. return new ApiResult(ReturnCode.ArgsError);
  198. }
  199. try
  200. {
  201. var contentList = await _repository.GetCameraMigrateConditionAsync(searchModel);
  202. return new ApiResult<PagesModel<VmcCameraMigrateViewModel>>(new PagesModel<VmcCameraMigrateViewModel>(contentList, searchModel));
  203. }
  204. catch (Exception ex)
  205. {
  206. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  207. }
  208. }
  209. /// <summary>
  210. /// 新增设备摄像头关联-单实体
  211. /// </summary>
  212. /// <param name="content"></param>
  213. /// <returns></returns>
  214. [HttpPost("CreateDevCameraAsync")]
  215. public async Task<ApiResult> CreateDevCameraAsync(TVMC_DevCamera content)
  216. {
  217. if (content == null)
  218. {
  219. return new ApiResult(ReturnCode.ArgsError);
  220. }
  221. try
  222. {
  223. await _repository.CreateDevCamera(content);
  224. }
  225. catch (Exception ex)
  226. {
  227. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  228. }
  229. return new ApiResult(ReturnCode.Success);
  230. }
  231. /// <summary>
  232. /// 新增设备摄像头关联-列表
  233. /// </summary>
  234. /// <param name="content"></param>
  235. /// <returns></returns>
  236. [HttpPost("CreateDevCameraListAsync")]
  237. public async Task<ApiResult> CreateDevCameraListAsync(VmcDevCamera content)
  238. {
  239. if (content == null||content.CameraList == null|| content.CameraList.Count==0)
  240. {
  241. return new ApiResult(ReturnCode.ArgsError);
  242. }
  243. try
  244. {
  245. await _repository.CreateDevCameraList(content);
  246. }
  247. catch (Exception ex)
  248. {
  249. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  250. }
  251. return new ApiResult(ReturnCode.Success);
  252. }
  253. /// <summary>
  254. /// 获取设备摄像头列表
  255. /// </summary>
  256. /// <returns></returns>
  257. [HttpPost("DevCameraPageAsync")]
  258. [AllowAnonymous]
  259. public async Task<ApiResult> DevCameraPageAsync(VmcDevSearch searchModel)
  260. {
  261. if (searchModel == null)
  262. {
  263. return new ApiResult(ReturnCode.ArgsError);
  264. }
  265. try
  266. {
  267. var contentList = await _repository.GetDevCameraConditionAsync(searchModel);
  268. return new ApiResult<PagesModel<VmcDevCameraViewModel>>(new PagesModel<VmcDevCameraViewModel>(contentList, searchModel));
  269. }
  270. catch (Exception ex)
  271. {
  272. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  273. }
  274. }
  275. /// <summary>
  276. /// 获取LiveGBS登录token
  277. /// </summary>
  278. /// <returns></returns>
  279. [HttpGet("GetLiveFBSToken")]
  280. [AllowAnonymous]
  281. public async Task<ApiResult> GetLiveFBSToken()
  282. {
  283. try
  284. {
  285. GBSToken token = await LiveGBSHelper.GetToken();
  286. return new ApiResult<GBSToken>(token);
  287. }
  288. catch (Exception ex)
  289. {
  290. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  291. }
  292. }
  293. /// <summary>
  294. /// 获取LiveGBS列表
  295. /// </summary>
  296. /// <returns></returns>
  297. [HttpPost("GetLiveFBSListAsync")]
  298. [AllowAnonymous]
  299. public async Task<ApiResult> GetLiveFBSListAsync(TbdmCodeSearchModel searchModel)
  300. {
  301. if (searchModel == null)
  302. {
  303. return new ApiResult(ReturnCode.ArgsError);
  304. }
  305. try
  306. {
  307. if (!string.IsNullOrEmpty(searchModel.C_Value))
  308. {
  309. switch (searchModel.C_Code)
  310. {
  311. case "VIDEO_TYPE_001": LiveGBSHelper.loginUrl = searchModel.C_Value;break;
  312. default:
  313. break;
  314. }
  315. }
  316. //LiveGBS
  317. if (searchModel.C_Code== "VIDEO_TYPE_001")
  318. {
  319. List<LiveGBSModel> list = new List<LiveGBSModel>();
  320. DeviceChanneModel channeModel = await LiveGBSHelper.GetDeviceChannellist();
  321. if (channeModel != null && channeModel.ChannelList.Count > 0)
  322. {
  323. foreach (var item in channeModel.ChannelList)
  324. {
  325. LiveGBSModel model = new LiveGBSModel();
  326. model.ChannelID = item.ID;
  327. model.DeviceID = item.DeviceID;
  328. model.DeviceName = item.DeviceName;
  329. model.DeviceOnline = item.DeviceOnline;
  330. model.Channel = item.Channel;
  331. model.Name = item.Name;
  332. model.SnapURL = item.SnapURL;
  333. model.Model = item.Model;
  334. model.Status = item.Status;
  335. ChannelVideo channelVideo = await LiveGBSHelper.GeChannelVideo(item.DeviceID, item.ID);
  336. if (channelVideo != null)
  337. {
  338. model.StreamID = channelVideo.StreamID;
  339. model.SMSID = channelVideo.SMSID;
  340. if (!string.IsNullOrEmpty(channelVideo.FLV))
  341. {
  342. string flv = "/sms" + channelVideo.FLV?.Split("sms")[1];
  343. model.FLV = flv;
  344. }
  345. if (!string.IsNullOrEmpty(channelVideo.HLS))
  346. {
  347. string hls = "/sms" + channelVideo.HLS?.Split("sms")[1];
  348. model.HLS = hls;
  349. }
  350. model.RTMP = channelVideo.RTMP;
  351. //model.VSnapURL = channelVideo.SnapURL;
  352. model.WEBRTC = channelVideo.WEBRTC;
  353. model.WS_FLV = channelVideo.WS_FLV;
  354. }
  355. list.Add(model);
  356. }
  357. }
  358. return new ApiResult<List<LiveGBSModel>>(list);
  359. }
  360. else
  361. {
  362. return new ApiResult<object>(null);
  363. }
  364. }
  365. catch (Exception ex)
  366. {
  367. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  368. }
  369. }
  370. /// <summary>
  371. /// 前端设备录像(历史视频)
  372. /// </summary>
  373. /// <returns></returns>
  374. [HttpPost("GetLiveFBSHistoryAsync")]
  375. [AllowAnonymous]
  376. public async Task<ApiResult> GetLiveFBSHistoryAsync(VmcCameraSearch searchModel)
  377. {
  378. if (searchModel == null)
  379. {
  380. return new ApiResult(ReturnCode.ArgsError);
  381. }
  382. try
  383. {
  384. bool IsPage = searchModel.IsPagination;
  385. searchModel.IsPagination = false;
  386. var contentList = await _repository.GetConditionAsync(searchModel);
  387. if (contentList == null)
  388. {
  389. return new ApiResult<IEnumerable<RecordList>>(null);
  390. }
  391. List<RecordList> list = new List<RecordList>();
  392. foreach (var content in contentList)
  393. {
  394. //LiveGBS
  395. if (content.C_Type == "VIDEO_TYPE_001")
  396. {
  397. if (!string.IsNullOrEmpty(content.C_Serial) && !string.IsNullOrEmpty(content.C_CameraCode))
  398. {
  399. LiveGBSHelper.loginUrl = content.TypeValue;
  400. string startTime = searchModel.VideoStartData;
  401. string EndTime = searchModel.VideoEndData;
  402. if (string.IsNullOrEmpty(startTime))
  403. {
  404. startTime = DateTime.Now.AddHours(-1).ToString("yyy-MM-ddTHH:mm:ss");
  405. }
  406. if (string.IsNullOrEmpty(EndTime))
  407. {
  408. EndTime = DateTime.Now.ToString("yyy-MM-ddTHH:mm:ss");
  409. }
  410. playbackRecordList datas = await LiveGBSHelper.playbackRecordList(content.C_Serial, content.C_CameraCode, startTime, EndTime);
  411. if (datas != null && datas.RecordList != null && datas.RecordList.Count > 0)
  412. {
  413. datas.RecordList.ForEach(record =>
  414. {
  415. record.CameraName = content.C_Name;
  416. record.DeviceID = content.C_Serial;
  417. record.ChannelID = content.C_CameraCode;
  418. });
  419. list.AddRange(datas.RecordList);
  420. }
  421. }
  422. }
  423. }
  424. searchModel.TotalCount=list.Count;
  425. if (IsPage)
  426. {
  427. var pageLIst= list.Skip((searchModel.PageIndex - 1) * searchModel.PageSize).Take(searchModel.PageSize);
  428. return new ApiResult<PagesModel<RecordList>>(new PagesModel<RecordList>(pageLIst, searchModel));
  429. }
  430. else
  431. {
  432. return new ApiResult<PagesModel<RecordList>>(new PagesModel<RecordList>(list, searchModel));
  433. }
  434. }
  435. catch (Exception ex)
  436. {
  437. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  438. }
  439. }
  440. /// <summary>
  441. /// 前端设备录像-视频回放
  442. /// </summary>
  443. /// <returns></returns>
  444. [HttpPost("LiveFBSPlaybackStart")]
  445. [AllowAnonymous]
  446. public async Task<ApiResult> LiveFBSPlaybackStart(LiveFBSSearch searchModel)
  447. {
  448. if (searchModel == null)
  449. {
  450. return new ApiResult(ReturnCode.ArgsError);
  451. }
  452. try
  453. {
  454. string startTime = searchModel.VideoStartData;
  455. string EndTime = searchModel.VideoEndData;
  456. ChannelVideo datas = await LiveGBSHelper.playbackStart(searchModel.C_Serial, searchModel.C_CameraCode, startTime, EndTime,searchModel.Download,searchModel.DownloadSpeed);
  457. if (!string.IsNullOrEmpty(datas.FLV))
  458. {
  459. string flv = "/sms" + datas.FLV?.Split("sms")[1];
  460. datas.FLV = flv;
  461. }
  462. if (!string.IsNullOrEmpty(datas.HLS))
  463. {
  464. string hls = "/sms" + datas.HLS?.Split("sms")[1];
  465. datas.HLS = hls;
  466. }
  467. return new ApiResult<ChannelVideo>(datas);
  468. }
  469. catch (Exception ex)
  470. {
  471. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  472. }
  473. }
  474. /// <summary>
  475. /// 前端设备录像-回放控制
  476. /// </summary>
  477. /// <returns></returns>
  478. [HttpPost("LiveFBSPlaybackControl")]
  479. [AllowAnonymous]
  480. public async Task<ApiResult> LiveFBSPlaybackControl(LiveGBSPlayControl searchModel)
  481. {
  482. if (searchModel == null)
  483. {
  484. return new ApiResult(ReturnCode.ArgsError);
  485. }
  486. try
  487. {
  488. string datas = await LiveGBSHelper.playbackControl(searchModel.StreamId, searchModel.Command,searchModel.Range, searchModel.Scale);
  489. return new ApiResult<object>(datas);
  490. }
  491. catch (Exception ex)
  492. {
  493. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  494. }
  495. }
  496. /// <summary>
  497. /// 前端设备录像- 视频回放流停止
  498. /// </summary>
  499. /// <returns></returns>
  500. [HttpPost("LiveFBSPlaybackStop")]
  501. [AllowAnonymous]
  502. public async Task<ApiResult> LiveFBSPlaybackStop(LiveFBSSearch searchModel)
  503. {
  504. if (searchModel == null)
  505. {
  506. return new ApiResult(ReturnCode.ArgsError);
  507. }
  508. try
  509. {
  510. playbackStopPlaybackFileURL datas = await LiveGBSHelper.playbackStop(searchModel.StreamId);
  511. if (datas!=null&&!string.IsNullOrEmpty(datas.PlaybackFileURL))
  512. {
  513. string hls = "/sms" + datas.PlaybackFileURL.Split("sms")[1];
  514. datas.PlaybackFileURL = hls;
  515. }
  516. return new ApiResult<playbackStopPlaybackFileURL>(datas);
  517. }
  518. catch (Exception ex)
  519. {
  520. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  521. }
  522. }
  523. /// <summary>
  524. /// 前端设备录像- 单条回放流信息
  525. /// </summary>
  526. /// <returns></returns>
  527. [HttpPost("LiveFBSPlaybackStreaminfo")]
  528. [AllowAnonymous]
  529. public async Task<ApiResult> LiveFBSPlaybackStreaminfo(LiveFBSSearch searchModel)
  530. {
  531. if (searchModel == null)
  532. {
  533. return new ApiResult(ReturnCode.ArgsError);
  534. }
  535. try
  536. {
  537. playbackStreaminfoEntity datas = await LiveGBSHelper.playbackStreaminfo(searchModel.StreamId);
  538. if (datas != null && !string.IsNullOrEmpty(datas.PlaybackFileURL))
  539. {
  540. string hls = "/sms" + datas.PlaybackFileURL.Split("sms")[1];
  541. datas.PlaybackFileURL = hls;
  542. }
  543. return new ApiResult<playbackStreaminfoEntity>(datas);
  544. }
  545. catch (Exception ex)
  546. {
  547. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  548. }
  549. }
  550. }
  551. }