Browse Source

advance: 更新查询数据库逻辑

master
fajiao 2 years ago
parent
commit
b57277341b
  1. 3
      Cis.Application/Cb/Service/CbCameraParamsService.cs
  2. 10
      Cis.Application/Cb/Service/CbCameraService.cs
  3. 6
      Cis.Application/Cis.Application.xml
  4. 3
      Cis.Application/Cm/Service/CmMarkGroupService.cs
  5. 5
      Cis.Application/Cm/Service/CmMarkLabelService.cs
  6. 27
      Cis.Application/Sys/Service/SysDictDataService.cs
  7. 12
      Cis.Application/Sys/Service/SysDictTypeService.cs
  8. 5
      Cis.Core/Common/Entity/ServiceBase.cs

3
Cis.Application/Cb/Service/CbCameraParamsService.cs

@ -40,6 +40,7 @@ public class CbCameraParamsService : ServiceBase<CbCameraParams>, ITransient
var entity = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.FirstAsync();
return entity;
}
@ -69,6 +70,7 @@ public class CbCameraParamsService : ServiceBase<CbCameraParams>, ITransient
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.ToListAsync();
return list;
}
@ -100,6 +102,7 @@ public class CbCameraParamsService : ServiceBase<CbCameraParams>, ITransient
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.ToPageListAsync(pageObj.Index, pageObj.Size);
return list;
}

10
Cis.Application/Cb/Service/CbCameraService.cs

@ -43,6 +43,7 @@ public class CbCameraService : ServiceBase<CbCamera>, ITransient
var entity = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.FirstAsync();
return entity;
}
@ -72,6 +73,7 @@ public class CbCameraService : ServiceBase<CbCamera>, ITransient
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.ToListAsync();
return list;
}
@ -85,8 +87,8 @@ public class CbCameraService : ServiceBase<CbCamera>, ITransient
[HttpGet]
public override async Task<List<CbCamera>> GetPageList([Required] string pagination, string queryJson = "")
{
JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>();
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create<CbCamera>();
if (queryObj.TryGetValue("cbCameraParamsId", StringComparison.OrdinalIgnoreCase, out JToken cbCameraParamsId))
@ -103,6 +105,7 @@ public class CbCameraService : ServiceBase<CbCamera>, ITransient
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.ToPageListAsync(pageObj.Index, pageObj.Size);
return list;
}
@ -118,7 +121,7 @@ public class CbCameraService : ServiceBase<CbCamera>, ITransient
public async Task<CbCameraBO> GetBO([Required] long id)
{
CbCamera camera = await _baseRep.GetByIdAsync(id);
if (camera == null) return null;
if (camera == null || camera.IsDelete) return null;
CbCameraParams cameraParams = await _cbCameraParamsRep.GetByIdAsync(camera.CbCameraParamsId);
if (cameraParams == null) return null;
CbCameraBO bo = CbCameraBO.New(camera, cameraParams);
@ -143,11 +146,14 @@ public class CbCameraService : ServiceBase<CbCamera>, ITransient
exp.And(it => it.Ip.Contains(ip.ToString()));
if (queryObj.TryGetValue("IsDelete", StringComparison.OrdinalIgnoreCase, out JToken isDelete))
exp.And(it => it.IsDelete.Equals(isDelete));
else
exp.And(it => it.IsDelete.Equals(false));
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())
.OrderBy(it => it.CreateTime)
.ToListAsync();
HashSet<long> paramsIdSet = new();

6
Cis.Application/Cis.Application.xml

@ -1317,21 +1317,21 @@
<summary>
获取实体类
</summary>
<param name="queryJson">equal:sysDictTypeId,code,id,isDelete; between:[startTime,endTime];</param>
<param name="queryJson">equal:sysDictTypeId,id,isDelete; like:name,code; between:[startTime,endTime];</param>
<returns></returns>
</member>
<member name="M:Cis.Application.Sys.SysDictDataService.GetList(System.String)">
<summary>
批量获取实体类
</summary>
<param name="queryJson">equal:sysDictTypeId,code,isDelete; between:[startTime,endTime];</param>
<param name="queryJson">equal:sysDictTypeId,isDelete; like:name,code; between:[startTime,endTime];</param>
<returns></returns>
</member>
<member name="M:Cis.Application.Sys.SysDictDataService.GetPageList(System.String,System.String)">
<summary>
批量获取分页实体类
</summary>
<param name="queryJson">equal:sysDictTypeId,code,isDelete; between:[startTime,endTime];</param>
<param name="queryJson">equal:sysDictTypeId,isDelete; like:name,code; between:[startTime,endTime];</param>
<param name="pagination">index,size</param>
<returns></returns>
</member>

3
Cis.Application/Cm/Service/CmMarkGroupService.cs

@ -34,6 +34,7 @@ public class CmMarkGroupService : ServiceBase<CmMarkGroup>, ITransient
var entity = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.Order)
.FirstAsync();
return entity;
}
@ -61,6 +62,7 @@ public class CmMarkGroupService : ServiceBase<CmMarkGroup>, ITransient
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.Order)
.ToListAsync();
return list;
}
@ -88,6 +90,7 @@ public class CmMarkGroupService : ServiceBase<CmMarkGroup>, ITransient
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.Order)
.ToPageListAsync(pageObj.Index, pageObj.Size);
return list;
}

5
Cis.Application/Cm/Service/CmMarkLabelService.cs

@ -95,6 +95,7 @@ public class CmMarkLabelService : ServiceBase<CmMarkLabel>, ITransient
var entity = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.FirstAsync();
return entity;
}
@ -126,6 +127,7 @@ public class CmMarkLabelService : ServiceBase<CmMarkLabel>, ITransient
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.ToListAsync();
return list;
}
@ -139,8 +141,8 @@ public class CmMarkLabelService : ServiceBase<CmMarkLabel>, ITransient
[HttpGet]
public override async Task<List<CmMarkLabel>> GetPageList([Required] string pagination, string queryJson = "")
{
JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>();
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create<CmMarkLabel>();
if (queryObj.TryGetValue("cbCameraId", StringComparison.OrdinalIgnoreCase, out JToken cbCameraId))
@ -157,6 +159,7 @@ public class CmMarkLabelService : ServiceBase<CmMarkLabel>, ITransient
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.ToPageListAsync(pageObj.Index, pageObj.Size);
return list;
}

27
Cis.Application/Sys/Service/SysDictDataService.cs

@ -16,7 +16,7 @@ public class SysDictDataService : ServiceBase<SysDictData>, ITransient
/// <summary>
/// 获取实体类
/// </summary>
/// <param name="queryJson">equal:sysDictTypeId,code,id,isDelete; between:[startTime,endTime];</param>
/// <param name="queryJson">equal:sysDictTypeId,id,isDelete; like:name,code; between:[startTime,endTime];</param>
/// <returns></returns>
[HttpGet]
public override async Task<SysDictData> GetByQ([Required] string queryJson)
@ -28,8 +28,10 @@ public class SysDictDataService : ServiceBase<SysDictData>, ITransient
exp.And(it => it.SysDictTypeId.Equals(sysDictTypeId));
if (queryObj.TryGetValue("Id", StringComparison.OrdinalIgnoreCase, out JToken Id))
exp.And(it => it.Id.Equals(Id));
if (queryObj.TryGetValue("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("code", StringComparison.OrdinalIgnoreCase, out JToken code))
exp.And(it => it.Code.Equals(code));
exp.And(it => it.Code.Contains(code.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)
@ -38,6 +40,7 @@ public class SysDictDataService : ServiceBase<SysDictData>, ITransient
var entity = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => new { it.SysDictTypeId, it.Order })
.FirstAsync();
return entity;
}
@ -45,7 +48,7 @@ public class SysDictDataService : ServiceBase<SysDictData>, ITransient
/// <summary>
/// 批量获取实体类
/// </summary>
/// <param name="queryJson">equal:sysDictTypeId,code,isDelete; between:[startTime,endTime];</param>
/// <param name="queryJson">equal:sysDictTypeId,isDelete; like:name,code; between:[startTime,endTime];</param>
/// <returns></returns>
[HttpGet]
public override async Task<List<SysDictData>> GetList(string queryJson = "")
@ -55,8 +58,10 @@ public class SysDictDataService : ServiceBase<SysDictData>, ITransient
var exp = Expressionable.Create<SysDictData>();
if (queryObj.TryGetValue("sysDictTypeId", StringComparison.OrdinalIgnoreCase, out JToken sysDictTypeId))
exp.And(it => it.SysDictTypeId.Equals(sysDictTypeId));
if (queryObj.TryGetValue("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("code", StringComparison.OrdinalIgnoreCase, out JToken code))
exp.And(it => it.Code.Equals(code));
exp.And(it => it.Code.Contains(code.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)
@ -64,7 +69,8 @@ public class SysDictDataService : ServiceBase<SysDictData>, ITransient
exp.And(it => it.CreateTime >= startTime.ToDateTime() && it.CreateTime <= endTime.ToDateTime());
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression()).OrderBy(it => it.Order)
.Where(exp.ToExpression())
.OrderBy(it => new { it.SysDictTypeId, it.Order })
.ToListAsync();
return list;
}
@ -72,20 +78,22 @@ public class SysDictDataService : ServiceBase<SysDictData>, ITransient
/// <summary>
/// 批量获取分页实体类
/// </summary>
/// <param name="queryJson">equal:sysDictTypeId,code,isDelete; between:[startTime,endTime];</param>
/// <param name="queryJson">equal:sysDictTypeId,isDelete; like:name,code; between:[startTime,endTime];</param>
/// <param name="pagination">index,size</param>
/// <returns></returns>
[HttpGet]
public override async Task<List<SysDictData>> GetPageList([Required] string pagination, string queryJson = "")
{
JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>();
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create<SysDictData>();
if (queryObj.TryGetValue("sysDictTypeId", StringComparison.OrdinalIgnoreCase, out JToken sysDictTypeId))
exp.And(it => it.SysDictTypeId.Equals(sysDictTypeId));
if (queryObj.TryGetValue("name", StringComparison.OrdinalIgnoreCase, out JToken name))
exp.And(it => it.Name.Contains(name.ToString()));
if (queryObj.TryGetValue("code", StringComparison.OrdinalIgnoreCase, out JToken code))
exp.And(it => it.Code.Equals(code));
exp.And(it => it.Code.Contains(code.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)
@ -93,7 +101,8 @@ public class SysDictDataService : ServiceBase<SysDictData>, ITransient
exp.And(it => it.CreateTime >= startTime.ToDateTime() && it.CreateTime <= endTime.ToDateTime());
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression()).OrderBy(it => it.Order)
.Where(exp.ToExpression())
.OrderBy(it => new { it.SysDictTypeId, it.Order })
.ToPageListAsync(pageObj.Index, pageObj.Size);
return list;
}

12
Cis.Application/Sys/Service/SysDictTypeService.cs

@ -41,6 +41,7 @@ public class SysDictTypeService : ServiceBase<SysDictType>, ITransient
var entity = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.Order)
.FirstAsync();
return entity;
}
@ -67,7 +68,8 @@ public class SysDictTypeService : ServiceBase<SysDictType>, ITransient
exp.And(it => it.CreateTime >= startTime.ToDateTime() && it.CreateTime <= endTime.ToDateTime());
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression()).OrderBy(it => it.Order)
.Where(exp.ToExpression())
.OrderBy(it => it.Order)
.ToListAsync();
return list;
}
@ -81,8 +83,8 @@ public class SysDictTypeService : ServiceBase<SysDictType>, ITransient
[HttpGet]
public override async Task<List<SysDictType>> GetPageList([Required] string pagination, string queryJson = "")
{
JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>();
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create<SysDictType>();
if (queryObj.TryGetValue("name", StringComparison.OrdinalIgnoreCase, out JToken name))
@ -96,7 +98,8 @@ public class SysDictTypeService : ServiceBase<SysDictType>, ITransient
exp.And(it => it.CreateTime >= startTime.ToDateTime() && it.CreateTime <= endTime.ToDateTime());
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression()).OrderBy(it => it.Order)
.Where(exp.ToExpression())
.OrderBy(it => it.Order)
.ToPageListAsync(pageObj.Index, pageObj.Size);
return list;
}
@ -114,12 +117,11 @@ public class SysDictTypeService : ServiceBase<SysDictType>, ITransient
SysDictType type = await _baseRep.AsQueryable()
.Where(it => it.Code.Equals(code))
.FirstAsync();
if (type == null) return null;
if (type == null || type.IsDelete) return null;
List<SysDictData> dataList = await _sysDictDataRep.AsQueryable()
.Where(it => it.SysDictTypeId.Equals(type.Id))
.OrderBy(it => it.Order)
.ToListAsync();
SysDictTypeBO bo = SysDictTypeBO.New(type, dataList);
return bo;
}

5
Cis.Core/Common/Entity/ServiceBase.cs

@ -140,6 +140,7 @@ public class ServiceBase<T> : IDynamicApiController where T : EntityBase, new()
var entity = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.FirstAsync();
return entity;
}
@ -163,6 +164,7 @@ public class ServiceBase<T> : IDynamicApiController where T : EntityBase, new()
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.ToListAsync();
return list;
}
@ -176,8 +178,8 @@ public class ServiceBase<T> : IDynamicApiController where T : EntityBase, new()
[HttpGet]
public virtual async Task<List<T>> GetPageList([Required] string pagination, string queryJson = "")
{
JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>();
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create<T>();
if (queryObj.TryGetValue("IsDelete", StringComparison.OrdinalIgnoreCase, out JToken isDelete))
@ -188,6 +190,7 @@ public class ServiceBase<T> : IDynamicApiController where T : EntityBase, new()
var list = await _baseRep.AsQueryable()
.Where(exp.ToExpression())
.OrderBy(it => it.CreateTime)
.ToPageListAsync(pageObj.Index, pageObj.Size);
return list;
}

Loading…
Cancel
Save