using Cis.Application.Core;
using Cis.Application.Core.Component.CameraSDK;
using Cis.Application.Core.Component.PtzServer;
using EC.Helper.CameraSDK;
using Newtonsoft.Json.Linq;
namespace Cis.Application.Cm;
///
/// 标签服务
///
[ApiDescriptionSettings(CmInfo.GroupName, Order = CmInfo.GroupOrder)]
public class CmMarkLabelService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _baseRep;
private ICameraSdkServer _cameraSdk { get; set; }
public CmMarkLabelService(
SqlSugarRepository baseRep,
ICameraSdkServer cameraSdk
)
{
_baseRep = baseRep;
_cameraSdk = cameraSdk;
}
[HttpPost]
public async Task Add([FromForm] CmMarkLabel entity)
{
bool ret = _cameraSdk.GetPtzInfoById(entity.CbCameraId.ToString(), out PtzInfo ptzInfo);
if (!ret) return false;
entity.PanPosition = ptzInfo.Pan;
entity.TiltPosition = ptzInfo.Tilt;
entity.ZoomPosition = ptzInfo.Zoom;
return await _baseRep.InsertAsync(entity);
}
[HttpPost]
public async Task AddReturnId([FromForm] CmMarkLabel entity)
{
bool ret = _cameraSdk.GetPtzInfoById(entity.CbCameraId.ToString(), out PtzInfo ptzInfo);
if (!ret) return 0;
entity.PanPosition = ptzInfo.Pan;
entity.TiltPosition = ptzInfo.Tilt;
entity.ZoomPosition = ptzInfo.Zoom;
await _baseRep.InsertAsync(entity);
return entity.Id;
}
[HttpPost]
public async Task Update([FromForm] CmMarkLabel entity)
{
return await _baseRep.UpdateAsync(entity);
}
[HttpPost]
public async Task Delete([FromForm] CmMarkLabel entity)
{
return await _baseRep.DeleteAsync(entity);
}
[HttpGet]
public async Task Get(long id)
{
CmMarkLabel entity = await _baseRep.GetByIdAsync(id);
return entity;
}
[HttpGet]
public async Task> GetList(string queryJson = "")
{
JObject queryObj = queryJson.ToJObject();
List list = await _baseRep.AsQueryable()
.ToListAsync();
return list;
}
[HttpGet]
public async Task> GetPageList(string queryJson, string pagination)
{
Pagination pageObj = pagination.ToObject();
JObject queryObj = queryJson.ToJObject();
List list = await _baseRep.AsQueryable()
.ToPageListAsync(pageObj.Index, pageObj.Size);
return list;
}
}