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