using Cis.Core.Common;
using Newtonsoft.Json.Linq;
namespace Cis.Application.Cb;
///
/// 相机参数服务
///
[ApiDescriptionSettings(CbInfo.GroupName, Order = CbInfo.CbCameraParamsGroupOrder)]
public class CbCameraParamsService : ServiceBase, ITransient
{
public CbCameraParamsService(SqlSugarRepository baseRep) : base(baseRep)
{
}
///
/// 获取实体类
///
/// equal:manufactor,type,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("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("manufactor", StringComparison.OrdinalIgnoreCase, out JToken manufactor))
exp.And(it => it.Manufactor.Equals(manufactor));
if (queryObj.TryGetValue("type", StringComparison.OrdinalIgnoreCase, out JToken type))
exp.And(it => it.Type.Equals(type));
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 entity = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.FirstAsync();
return entity;
}
///
/// 批量获取实体类
///
/// equal:manufactor,type,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("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("manufactor", StringComparison.OrdinalIgnoreCase, out JToken manufactor))
exp.And(it => it.Manufactor.Equals(manufactor));
if (queryObj.TryGetValue("type", StringComparison.OrdinalIgnoreCase, out JToken type))
exp.And(it => it.Type.Equals(type));
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:manufactor,type,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("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("manufactor", StringComparison.OrdinalIgnoreCase, out JToken manufactor))
exp.And(it => it.Manufactor.Equals(manufactor));
if (queryObj.TryGetValue("type", StringComparison.OrdinalIgnoreCase, out JToken type))
exp.And(it => it.Type.Equals(type));
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;
}
}