using Cis.Application.Core.Component.PtzServer;
using Cis.Core.Common;
using EC.Helper.CameraSDK;
using Newtonsoft.Json.Linq;
namespace Cis.Application.Cm;
///
/// 标签服务
///
[ApiDescriptionSettings(CmInfo.GroupName, Order = CmInfo.CmMarkLabelGroupOrder)]
public class CmMarkLabelService : ServiceBase, ITransient
{
private ICameraSdkServer _cameraSdk { get; set; }
public CmMarkLabelService(SqlSugarRepository baseRep, ICameraSdkServer cameraSdk) : base(baseRep)
{
_cameraSdk = cameraSdk;
}
///
/// 添加实体类
///
/// 实体类
///
[HttpPost]
public override async Task Add([FromForm] CmMarkLabel entity)
{
bool ret = _cameraSdk.TryGetPtzInfoById(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);
}
///
/// 添加实体类并返回 id
///
/// 实体类
///
[HttpPost]
public override async Task AddReturnId([FromForm] CmMarkLabel entity)
{
bool ret = _cameraSdk.TryGetPtzInfoById(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 override async Task AddList([Required][FromForm] List list)
{
foreach (CmMarkLabel item in list)
{
bool ret = _cameraSdk.TryGetPtzInfoById(item.CbCameraId.ToString(), out PtzInfo ptzInfo);
if (!ret) return false;
item.PanPosition = ptzInfo.Pan;
item.TiltPosition = ptzInfo.Tilt;
item.ZoomPosition = ptzInfo.Zoom;
}
return await _baseRep.InsertRangeAsync(list);
}
///
/// 获取实体类
///
/// equal:cbCameraId,cmMarkGroupId,id,isDelete; like:name; between:[startTime,endTime];
///
[HttpGet]
public override async Task GetByQ([Required] string queryJson)
{
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create();
if (queryObj.TryGetValue("cbCameraId", StringComparison.OrdinalIgnoreCase, out JToken cbCameraId))
exp.And(it => it.CbCameraId.Equals(cbCameraId));
if (queryObj.TryGetValue("cmMarkGroupId", StringComparison.OrdinalIgnoreCase, out JToken cmMarkGroupId))
exp.And(it => it.CmMarkGroupId.Equals(cmMarkGroupId));
if (queryObj.TryGetValue("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("IsDelete", StringComparison.OrdinalIgnoreCase, out JToken isDelete))
exp.And(it => it.IsDelete.Equals(isDelete));
if (queryObj.TryGetValue("StartTime", StringComparison.OrdinalIgnoreCase, out JToken startTime)
&& queryObj.TryGetValue("EndTime", StringComparison.OrdinalIgnoreCase, out JToken endTime))
exp.And(it => it.CreateTime >= startTime.ToDateTime() && it.CreateTime <= endTime.ToDateTime());
var entity = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.FirstAsync();
return entity;
}
///
/// 批量获取实体类
///
/// equal:cbCameraId,cmMarkGroupId,isDelete; like:name; between:[startTime,endTime];
///
[HttpGet]
public override async Task> GetList(string queryJson = "")
{
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create();
if (queryObj.TryGetValue("cbCameraId", StringComparison.OrdinalIgnoreCase, out JToken cbCameraId))
exp.And(it => it.CbCameraId.Equals(cbCameraId));
if (queryObj.TryGetValue("cmMarkGroupId", StringComparison.OrdinalIgnoreCase, out JToken cmMarkGroupId))
exp.And(it => it.CmMarkGroupId.Equals(cmMarkGroupId));
if (queryObj.TryGetValue("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("Id", StringComparison.OrdinalIgnoreCase, out JToken Id))
exp.And(it => it.Id.Equals(Id));
if (queryObj.TryGetValue("IsDelete", StringComparison.OrdinalIgnoreCase, out JToken isDelete))
exp.And(it => it.IsDelete.Equals(isDelete));
if (queryObj.TryGetValue("StartTime", StringComparison.OrdinalIgnoreCase, out JToken startTime)
&& queryObj.TryGetValue("EndTime", StringComparison.OrdinalIgnoreCase, out JToken endTime))
exp.And(it => it.CreateTime >= startTime.ToDateTime() && it.CreateTime <= endTime.ToDateTime());
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.ToListAsync();
return list;
}
///
/// 批量获取分页实体类
///
/// equal:cbCameraId,cmMarkGroupId,isDelete; like:name; between:[startTime,endTime];
/// index,size
///
[HttpGet]
public override async Task> GetPageList([Required] string pagination, string queryJson = "")
{
Pagination pageObj = pagination.ToObject();
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create();
if (queryObj.TryGetValue("cbCameraId", StringComparison.OrdinalIgnoreCase, out JToken cbCameraId))
exp.And(it => it.CbCameraId.Equals(cbCameraId));
if (queryObj.TryGetValue("cmMarkGroupId", StringComparison.OrdinalIgnoreCase, out JToken cmMarkGroupId))
exp.And(it => it.CmMarkGroupId.Equals(cmMarkGroupId));
if (queryObj.TryGetValue("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("IsDelete", StringComparison.OrdinalIgnoreCase, out JToken isDelete))
exp.And(it => it.IsDelete.Equals(isDelete));
if (queryObj.TryGetValue("StartTime", StringComparison.OrdinalIgnoreCase, out JToken startTime)
&& queryObj.TryGetValue("EndTime", StringComparison.OrdinalIgnoreCase, out JToken endTime))
exp.And(it => it.CreateTime >= startTime.ToDateTime() && it.CreateTime <= endTime.ToDateTime());
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.ToPageListAsync(pageObj.Index, pageObj.Size);
return list;
}
}