using Newtonsoft.Json.Linq;
namespace Cis.Application.Cb;
///
/// 相机参数服务
///
[ApiDescriptionSettings(CbInfo.GroupName, Order = CbInfo.GroupOrder)]
public class CbCameraParamsService : IDynamicApiController, ITransient
{
private readonly SqlSugarRepository _baseRep;
public CbCameraParamsService(SqlSugarRepository baseRep)
{
_baseRep = baseRep;
}
[HttpPost]
public async Task Add([FromForm] CbCameraParams entity)
{
return await _baseRep.InsertAsync(entity);
}
[HttpPost]
public async Task Update([FromForm] CbCameraParams entity)
{
return await _baseRep.UpdateAsync(entity);
}
[HttpPost]
public async Task Delete([FromForm] CbCameraParams entity)
{
return await _baseRep.DeleteAsync(entity);
}
[HttpGet]
public async Task Get(long id)
{
CbCameraParams entity = await _baseRep.GetByIdAsync(id);
return entity;
}
///
///
///
/// equal:cameraType; like:name; between:[startTime,endTime];
///
[HttpGet]
public async Task> GetList(string queryJson = "")
{
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create();
if (queryObj.TryGetValue("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("cameraType", StringComparison.OrdinalIgnoreCase, out JToken cameraType))
exp.And(it => it.CameraType.Equals(cameraType));
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;
}
///
///
///
/// equal:cameraType; like:name; between:[startTime,endTime];
/// index,size
///
[HttpGet]
public async Task> GetPageList(string queryJson, string pagination)
{
Pagination pageObj = pagination.ToObject();
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create();
if (queryObj.TryGetValue("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("cameraType", StringComparison.OrdinalIgnoreCase, out JToken cameraType))
exp.And(it => it.CameraType.Equals(cameraType));
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;
}
}