|
|
|
using Cis.Core.Common;
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
namespace Cis.Application.Cb;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 相机服务
|
|
|
|
/// </summary>
|
|
|
|
[ApiDescriptionSettings(CbInfo.GroupName, Order = CbInfo.CbCameraGroupOrder)]
|
|
|
|
public class CbCameraService : ServiceBase<CbCamera>, ITransient
|
|
|
|
{
|
|
|
|
protected readonly SqlSugarRepository<CbCameraParams> _cbCameraParamsRep;
|
|
|
|
|
|
|
|
public CbCameraService(SqlSugarRepository<CbCamera> baseRep, SqlSugarRepository<CbCameraParams> cbCameraParamsRep) : base(baseRep)
|
|
|
|
{
|
|
|
|
_cbCameraParamsRep = cbCameraParamsRep;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取实体类
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="queryJson">equal:cbCameraParamsId,id,isDelete; like:ip,name; between:[startTime,endTime];</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
public override async Task<CbCamera> GetByQ([Required] 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("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())
|
|
|
|
.FirstAsync();
|
|
|
|
return entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 批量获取实体类
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="queryJson">equal:cbCameraParamsId,isDelete; like:ip,name; between:[startTime,endTime];</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
public override 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("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:cbCameraParamsId,isDelete; like:ip,name; between:[startTime,endTime];</param>
|
|
|
|
/// <param name="pagination">index,size</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
public override async Task<List<CbCamera>> GetPageList([Required] string pagination, string queryJson = "")
|
|
|
|
{
|
|
|
|
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("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;
|
|
|
|
}
|
|
|
|
|
|
|
|
#region BO
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 获取实体类 BO
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="id">实体类 id</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
public async Task<CbCameraBO> GetBO([Required] long id)
|
|
|
|
{
|
|
|
|
CbCamera camera = await _baseRep.GetByIdAsync(id);
|
|
|
|
if (camera == null) return null;
|
|
|
|
CbCameraParams cameraParams = await _cbCameraParamsRep.GetByIdAsync(camera.CbCameraParamsId);
|
|
|
|
if (cameraParams == null) return null;
|
|
|
|
CbCameraBO bo = CbCameraBO.New(camera, cameraParams);
|
|
|
|
return bo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 批量获取实体类 BO
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="queryJson">equal:cbCameraParamsId,isDelete; like:ip,name; between:[startTime,endTime];</param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet]
|
|
|
|
public async Task<List<CbCameraBO>> GetBOList(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("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());
|
|
|
|
List<CbCamera> cameraList = await _baseRep.AsQueryable()
|
|
|
|
.Where(exp.ToExpression())
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
HashSet<long> paramsIdSet = new();
|
|
|
|
foreach (var item in cameraList)
|
|
|
|
paramsIdSet.Add(item.CbCameraParamsId);
|
|
|
|
List<CbCameraParams> paramsList = await _cbCameraParamsRep.AsQueryable()
|
|
|
|
.Where(it => paramsIdSet.ToList().Contains(it.Id))
|
|
|
|
.ToListAsync();
|
|
|
|
Dictionary<long, CbCameraParams> paramsDict = new();
|
|
|
|
foreach (var item in paramsList)
|
|
|
|
paramsDict.Add(item.Id, item);
|
|
|
|
|
|
|
|
List<CbCameraBO> boList = new();
|
|
|
|
foreach (var item in cameraList)
|
|
|
|
boList.Add(CbCameraBO.New(item, paramsDict[item.CbCameraParamsId]));
|
|
|
|
return boList;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion BO
|
|
|
|
}
|