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));
///
/// 构造函数
///
///
public VmcCameraController(IVmcCameraService repository)
{
_repository = repository;
}
///
/// 新增
///
///
///
[HttpPost("CreateAsync")]
public async Task 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);
}
///
/// 删除
///
///
///
[HttpDelete("DeleteAsync/{id}")]
public async Task 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);
}
///
/// 禁用
///
///
///
[HttpPut("ForbiddenAsync/{id}")]
public async Task 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);
}
///
/// 更新
///
///
///
///
[HttpPut("UpdateAsync/{id}")]
[AllowAnonymous]
public async Task 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);
}
///
/// 获取列表
///
///
[HttpPost("PageAsync")]
[AllowAnonymous]
public async Task PageAsync(VmcCameraSearch searchModel)
{
if (searchModel == null)
{
return new ApiResult(ReturnCode.ArgsError);
}
try
{
var contentList = await _repository.GetConditionAsync(searchModel);
return new ApiResult>(new PagesModel(contentList, searchModel));
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
///
/// 通过id获取详情
///
///
[HttpGet("DetailsAsync")]
[AllowAnonymous]
public async Task DetailsAsync(string Id)
{
if (string.IsNullOrEmpty(Id))
{
return new ApiResult(ReturnCode.ArgsError);
}
try
{
VmcCameraViewModel data = await _repository.GetByIdAsync(Id);
return new ApiResult(data);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
///
/// 新增业主摄像头迁移
///
///
///
[HttpPost("CreateCameraMigrateAsync")]
public async Task 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);
}
///
/// 获取业主摄像头迁移列表
///
///
[HttpPost("CameraMigratePageAsync")]
[AllowAnonymous]
public async Task CameraMigratePageAsync(VmcCameraMigrateSearch searchModel)
{
if (searchModel == null)
{
return new ApiResult(ReturnCode.ArgsError);
}
try
{
var contentList = await _repository.GetCameraMigrateConditionAsync(searchModel);
return new ApiResult>(new PagesModel(contentList, searchModel));
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
///
/// 新增设备摄像头关联-单实体
///
///
///
[HttpPost("CreateDevCameraAsync")]
public async Task 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);
}
///
/// 新增设备摄像头关联-列表
///
///
///
[HttpPost("CreateDevCameraListAsync")]
public async Task 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);
}
///
/// 获取设备摄像头列表
///
///
[HttpPost("DevCameraPageAsync")]
[AllowAnonymous]
public async Task DevCameraPageAsync(VmcDevSearch searchModel)
{
if (searchModel == null)
{
return new ApiResult(ReturnCode.ArgsError);
}
try
{
var contentList = await _repository.GetDevCameraConditionAsync(searchModel);
return new ApiResult>(new PagesModel(contentList, searchModel));
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
///
/// 获取LiveGBS登录token
///
///
[HttpGet("GetLiveFBSToken")]
[AllowAnonymous]
public async Task GetLiveFBSToken()
{
try
{
GBSToken token = await LiveGBSHelper.GetToken();
return new ApiResult(token);
}
catch (Exception ex)
{
return new ApiResult(ReturnCode.GeneralError, ex.Message);
}
}
///
/// 获取LiveGBS列表
///
///
[HttpPost("GetLiveFBSListAsync")]
[AllowAnonymous]
public async Task 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 list = new List();
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);
}
else
{
return new ApiResult