Camera Information System
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

134 lines
6.1 KiB

using Cis.Application.Core.Component.PtzServer;
using Cis.Core.Common;
using EC.Helper.CameraSDK;
using Newtonsoft.Json.Linq;
namespace Cis.Application.Cm;
/// <summary>
/// 标签服务
/// </summary>
[ApiDescriptionSettings(CmInfo.GroupName, Order = CmInfo.GroupOrder)]
public class CmMarkLabelService : ServiceBase<CmMarkLabel>, ITransient
{
private ICameraSdkServer _cameraSdk { get; set; }
public CmMarkLabelService(SqlSugarRepository<CmMarkLabel> baseRep, ICameraSdkServer cameraSdk) : base(baseRep)
{
_cameraSdk = cameraSdk;
}
[HttpPost]
public override async Task<bool> 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);
}
[HttpPost]
public override async Task<long> 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;
}
/// <summary>
///
/// </summary>
/// <param name="queryJson">equal:cbCameraId,cmMarkGroupId,id,isDelete; like:name; between:[startTime,endTime];</param>
/// <returns></returns>
[HttpGet]
public override async Task<CmMarkLabel> GetQ(string queryJson)
{
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create<CmMarkLabel>();
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())
.FirstAsync();
return entity;
}
/// <summary>
///
/// </summary>
/// <param name="queryJson">equal:cbCameraId,cmMarkGroupId,isDelete; like:name; between:[startTime,endTime];</param>
/// <returns></returns>
[HttpGet]
public override async Task<List<CmMarkLabel>> GetList(string queryJson = "")
{
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create<CmMarkLabel>();
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())
.ToListAsync();
return list;
}
/// <summary>
///
/// </summary>
/// <param name="queryJson">equal:cbCameraId,cmMarkGroupId,isDelete; like:name; between:[startTime,endTime];</param>
/// <param name="pagination">index,size</param>
/// <returns></returns>
[HttpGet]
public override async Task<List<CmMarkLabel>> GetPageList(string pagination, string queryJson="")
{
JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>();
var exp = Expressionable.Create<CmMarkLabel>();
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())
.ToPageListAsync(pageObj.Index, pageObj.Size);
return list;
}
}