Browse Source

advance: 添加 ServiceBase 类,满足基本数据操作

master
fajiao 2 years ago
parent
commit
40fdd0e248
  1. 39
      Cis.Application/Cb/Service/CbCameraParamsService.cs
  2. 39
      Cis.Application/Cb/Service/CbCameraService.cs
  3. 39
      Cis.Application/Cm/Service/CmMarkGroupService.cs
  4. 38
      Cis.Application/Cm/Service/CmMarkLabelService.cs
  5. 2
      Cis.Application/Core/Service/MarkSearchService.cs
  6. 39
      Cis.Application/Sys/Service/SysDictDataService.cs
  7. 39
      Cis.Application/Sys/Service/SysDictTypeService.cs
  8. 78
      Cis.Core/Cis.Core.xml
  9. 165
      Cis.Core/Common/Entity/ServiceBase.cs

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

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq; using Cis.Core.Common;
using Newtonsoft.Json.Linq;
namespace Cis.Application.Cb; namespace Cis.Application.Cb;
@ -6,38 +7,10 @@ namespace Cis.Application.Cb;
/// 相机参数服务 /// 相机参数服务
/// </summary> /// </summary>
[ApiDescriptionSettings(CbInfo.GroupName, Order = CbInfo.GroupOrder)] [ApiDescriptionSettings(CbInfo.GroupName, Order = CbInfo.GroupOrder)]
public class CbCameraParamsService : IDynamicApiController, ITransient public class CbCameraParamsService : ServiceBase<CbCameraParams>, ITransient
{ {
private readonly SqlSugarRepository<CbCameraParams> _baseRep; public CbCameraParamsService(SqlSugarRepository<CbCameraParams> baseRep) : base(baseRep)
public CbCameraParamsService(SqlSugarRepository<CbCameraParams> baseRep)
{
_baseRep = baseRep;
}
[HttpPost]
public async Task<bool> Add([FromForm] CbCameraParams entity)
{
return await _baseRep.InsertAsync(entity);
}
[HttpPost]
public async Task<bool> Update([FromForm] CbCameraParams entity)
{
return await _baseRep.UpdateAsync(entity);
}
[HttpPost]
public async Task<bool> Delete([FromForm] CbCameraParams entity)
{
return await _baseRep.DeleteAsync(entity);
}
[HttpGet]
public async Task<CbCameraParams> Get(long id)
{ {
CbCameraParams entity = await _baseRep.GetByIdAsync(id);
return entity;
} }
/// <summary> /// <summary>
@ -46,7 +19,7 @@ public class CbCameraParamsService : IDynamicApiController, ITransient
/// <param name="queryJson">equal:cameraType; like:name; between:[startTime,endTime];</param> /// <param name="queryJson">equal:cameraType; like:name; between:[startTime,endTime];</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<CbCameraParams>> GetList(string queryJson = "") public override async Task<List<CbCameraParams>> GetList(string queryJson = "")
{ {
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();
@ -72,7 +45,7 @@ public class CbCameraParamsService : IDynamicApiController, ITransient
/// <param name="pagination">index,size</param> /// <param name="pagination">index,size</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<CbCameraParams>> GetPageList(string queryJson, string pagination) public override async Task<List<CbCameraParams>> GetPageList(string queryJson, string pagination)
{ {
Pagination pageObj = pagination.ToObject<Pagination>(); Pagination pageObj = pagination.ToObject<Pagination>();
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();

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

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq; using Cis.Core.Common;
using Newtonsoft.Json.Linq;
namespace Cis.Application.Cb; namespace Cis.Application.Cb;
@ -6,38 +7,10 @@ namespace Cis.Application.Cb;
/// 相机服务 /// 相机服务
/// </summary> /// </summary>
[ApiDescriptionSettings(CbInfo.GroupName, Order = CbInfo.GroupOrder)] [ApiDescriptionSettings(CbInfo.GroupName, Order = CbInfo.GroupOrder)]
public class CbCameraService : IDynamicApiController, ITransient public class CbCameraService : ServiceBase<CbCamera>, ITransient
{ {
private readonly SqlSugarRepository<CbCamera> _baseRep; public CbCameraService(SqlSugarRepository<CbCamera> baseRep) : base(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>
@ -46,7 +19,7 @@ public class CbCameraService : IDynamicApiController, ITransient
/// <param name="queryJson">equal:cbCameraParamsId; like:ip,name; between:[startTime,endTime];</param> /// <param name="queryJson">equal:cbCameraParamsId; like:ip,name; between:[startTime,endTime];</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<CbCamera>> GetList(string queryJson = "") public override async Task<List<CbCamera>> GetList(string queryJson = "")
{ {
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();
@ -74,7 +47,7 @@ public class CbCameraService : IDynamicApiController, ITransient
/// <param name="pagination">index,size</param> /// <param name="pagination">index,size</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<CbCamera>> GetPageList(string queryJson, string pagination) public override async Task<List<CbCamera>> GetPageList(string queryJson, string pagination)
{ {
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>(); Pagination pageObj = pagination.ToObject<Pagination>();

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

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq; using Cis.Core.Common;
using Newtonsoft.Json.Linq;
namespace Cis.Application.Cm; namespace Cis.Application.Cm;
@ -6,38 +7,10 @@ namespace Cis.Application.Cm;
/// 标记分组服务 /// 标记分组服务
/// </summary> /// </summary>
[ApiDescriptionSettings(CmInfo.GroupName, Order = CmInfo.GroupOrder)] [ApiDescriptionSettings(CmInfo.GroupName, Order = CmInfo.GroupOrder)]
public class CmMarkGroupService : IDynamicApiController, ITransient public class CmMarkGroupService : ServiceBase<CmMarkGroup>, ITransient
{ {
private readonly SqlSugarRepository<CmMarkGroup> _baseRep; public CmMarkGroupService(SqlSugarRepository<CmMarkGroup> baseRep) : base(baseRep)
public CmMarkGroupService(SqlSugarRepository<CmMarkGroup> baseRep)
{
_baseRep = baseRep;
}
[HttpPost]
public async Task<bool> Add([FromForm] CmMarkGroup entity)
{
return await _baseRep.InsertAsync(entity);
}
[HttpPost]
public async Task<bool> Update([FromForm] CmMarkGroup entity)
{
return await _baseRep.UpdateAsync(entity);
}
[HttpPost]
public async Task<bool> Delete([FromForm] CmMarkGroup entity)
{
return await _baseRep.DeleteAsync(entity);
}
[HttpGet]
public async Task<CmMarkGroup> Get(long id)
{ {
CmMarkGroup entity = await _baseRep.GetByIdAsync(id);
return entity;
} }
/// <summary> /// <summary>
@ -46,7 +19,7 @@ public class CmMarkGroupService : IDynamicApiController, ITransient
/// <param name="queryJson">like:name; between:[startTime,endTime];</param> /// <param name="queryJson">like:name; between:[startTime,endTime];</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<CmMarkGroup>> GetList(string queryJson) public override async Task<List<CmMarkGroup>> GetList(string queryJson)
{ {
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();
@ -70,7 +43,7 @@ public class CmMarkGroupService : IDynamicApiController, ITransient
/// <param name="pagination">index,size</param> /// <param name="pagination">index,size</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<CmMarkGroup>> GetPageList(string queryJson, string pagination) public override async Task<List<CmMarkGroup>> GetPageList(string queryJson, string pagination)
{ {
Pagination pageObj = pagination.ToObject<Pagination>(); Pagination pageObj = pagination.ToObject<Pagination>();
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();

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

@ -1,4 +1,5 @@
using Cis.Application.Core.Component.PtzServer; using Cis.Application.Core.Component.PtzServer;
using Cis.Core.Common;
using EC.Helper.CameraSDK; using EC.Helper.CameraSDK;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
@ -8,23 +9,17 @@ namespace Cis.Application.Cm;
/// 标签服务 /// 标签服务
/// </summary> /// </summary>
[ApiDescriptionSettings(CmInfo.GroupName, Order = CmInfo.GroupOrder)] [ApiDescriptionSettings(CmInfo.GroupName, Order = CmInfo.GroupOrder)]
public class CmMarkLabelService : IDynamicApiController, ITransient public class CmMarkLabelService : ServiceBase<CmMarkLabel>, ITransient
{ {
private readonly SqlSugarRepository<CmMarkLabel> _baseRep;
private ICameraSdkServer _cameraSdk { get; set; } private ICameraSdkServer _cameraSdk { get; set; }
public CmMarkLabelService( public CmMarkLabelService(SqlSugarRepository<CmMarkLabel> baseRep, ICameraSdkServer cameraSdk) : base(baseRep)
SqlSugarRepository<CmMarkLabel> baseRep,
ICameraSdkServer cameraSdk
)
{ {
_baseRep = baseRep;
_cameraSdk = cameraSdk; _cameraSdk = cameraSdk;
} }
[HttpPost] [HttpPost]
public async Task<bool> Add([FromForm] CmMarkLabel entity) public override async Task<bool> Add([FromForm] CmMarkLabel entity)
{ {
bool ret = _cameraSdk.TryGetPtzInfoById(entity.CbCameraId.ToString(), out PtzInfo ptzInfo); bool ret = _cameraSdk.TryGetPtzInfoById(entity.CbCameraId.ToString(), out PtzInfo ptzInfo);
if (!ret) return false; if (!ret) return false;
@ -35,7 +30,7 @@ public class CmMarkLabelService : IDynamicApiController, ITransient
} }
[HttpPost] [HttpPost]
public async Task<long> AddReturnId([FromForm] CmMarkLabel entity) public override async Task<long> AddReturnId([FromForm] CmMarkLabel entity)
{ {
bool ret = _cameraSdk.TryGetPtzInfoById(entity.CbCameraId.ToString(), out PtzInfo ptzInfo); bool ret = _cameraSdk.TryGetPtzInfoById(entity.CbCameraId.ToString(), out PtzInfo ptzInfo);
if (!ret) return 0; if (!ret) return 0;
@ -46,32 +41,13 @@ public class CmMarkLabelService : IDynamicApiController, ITransient
return entity.Id; return entity.Id;
} }
[HttpPost]
public async Task<bool> Update([FromForm] CmMarkLabel entity)
{
return await _baseRep.UpdateAsync(entity);
}
[HttpPost]
public async Task<bool> Delete([FromForm] CmMarkLabel entity)
{
return await _baseRep.DeleteAsync(entity);
}
[HttpGet]
public async Task<CmMarkLabel> Get(long id)
{
CmMarkLabel entity = await _baseRep.GetByIdAsync(id);
return entity;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
/// <param name="queryJson">equal:cbCameraId,cmMarkGroupId; like:name; between:[startTime,endTime];</param> /// <param name="queryJson">equal:cbCameraId,cmMarkGroupId; like:name; between:[startTime,endTime];</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<CmMarkLabel>> GetList(string queryJson = "") public override async Task<List<CmMarkLabel>> GetList(string queryJson = "")
{ {
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();
@ -99,7 +75,7 @@ public class CmMarkLabelService : IDynamicApiController, ITransient
/// <param name="pagination">index,size</param> /// <param name="pagination">index,size</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<CmMarkLabel>> GetPageList(string queryJson, string pagination) public override async Task<List<CmMarkLabel>> GetPageList(string queryJson, string pagination)
{ {
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>(); Pagination pageObj = pagination.ToObject<Pagination>();

2
Cis.Application/Core/Service/MarkSearchService.cs

@ -11,7 +11,7 @@ public class MarkSearchService : IDynamicApiController, ITransient
#endregion Attr #endregion Attr
public MarkSearchService(CameraDataCenter cameraDataCenter, IMarkSearcherServer markSearcherServer) public MarkSearchService(IMarkSearcherServer markSearcherServer)
{ {
_markSearcherServer = markSearcherServer; _markSearcherServer = markSearcherServer;
} }

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

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq; using Cis.Core.Common;
using Newtonsoft.Json.Linq;
namespace Cis.Application.Sys; namespace Cis.Application.Sys;
@ -6,38 +7,10 @@ namespace Cis.Application.Sys;
/// 系统字典值服务 /// 系统字典值服务
/// </summary> /// </summary>
[ApiDescriptionSettings(SysInfo.GroupName, Order = SysInfo.GroupOrder)] [ApiDescriptionSettings(SysInfo.GroupName, Order = SysInfo.GroupOrder)]
public class SysDictDataService : IDynamicApiController, ITransient public class SysDictDataService : ServiceBase<SysDictData>, ITransient
{ {
private readonly SqlSugarRepository<SysDictData> _baseRep; public SysDictDataService(SqlSugarRepository<SysDictData> baseRep) : base(baseRep)
public SysDictDataService(SqlSugarRepository<SysDictData> baseRep)
{
_baseRep = baseRep;
}
[HttpPost]
public async Task<bool> Add([FromForm] SysDictData entity)
{
return await _baseRep.InsertAsync(entity);
}
[HttpPost]
public async Task<bool> Update([FromForm] SysDictData entity)
{
return await _baseRep.UpdateAsync(entity);
}
[HttpPost]
public async Task<bool> Delete([FromForm] SysDictData entity)
{
return await _baseRep.DeleteAsync(entity);
}
[HttpGet]
public async Task<SysDictData> Get(long id)
{ {
SysDictData entity = await _baseRep.GetByIdAsync(id);
return entity;
} }
/// <summary> /// <summary>
@ -46,7 +19,7 @@ public class SysDictDataService : IDynamicApiController, ITransient
/// <param name="queryJson">equal:sysDictTypeId; like:code; between:[startTime,endTime];</param> /// <param name="queryJson">equal:sysDictTypeId; like:code; between:[startTime,endTime];</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<SysDictData>> GetList(string queryJson) public override async Task<List<SysDictData>> GetList(string queryJson)
{ {
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();
@ -72,7 +45,7 @@ public class SysDictDataService : IDynamicApiController, ITransient
/// <param name="pagination">index,size</param> /// <param name="pagination">index,size</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<SysDictData>> GetPageList(string queryJson, string pagination) public override async Task<List<SysDictData>> GetPageList(string queryJson, string pagination)
{ {
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>(); Pagination pageObj = pagination.ToObject<Pagination>();

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

@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq; using Cis.Core.Common;
using Newtonsoft.Json.Linq;
namespace Cis.Application.Sys; namespace Cis.Application.Sys;
@ -6,38 +7,10 @@ namespace Cis.Application.Sys;
/// 系统字典类型服务 /// 系统字典类型服务
/// </summary> /// </summary>
[ApiDescriptionSettings(SysInfo.GroupName, Order = SysInfo.GroupOrder)] [ApiDescriptionSettings(SysInfo.GroupName, Order = SysInfo.GroupOrder)]
public class SysDictTypeService : IDynamicApiController, ITransient public class SysDictTypeService : ServiceBase<SysDictType>, ITransient
{ {
private readonly SqlSugarRepository<SysDictType> _baseRep; public SysDictTypeService(SqlSugarRepository<SysDictType> baseRep) : base(baseRep)
public SysDictTypeService(SqlSugarRepository<SysDictType> baseRep)
{
_baseRep = baseRep;
}
[HttpPost]
public async Task<bool> Add([FromForm] SysDictType entity)
{
return await _baseRep.InsertAsync(entity);
}
[HttpPost]
public async Task<bool> Update([FromForm] SysDictType entity)
{
return await _baseRep.UpdateAsync(entity);
}
[HttpPost]
public async Task<bool> Delete([FromForm] SysDictType entity)
{
return await _baseRep.DeleteAsync(entity);
}
[HttpGet]
public async Task<SysDictType> Get(long id)
{ {
SysDictType entity = await _baseRep.GetByIdAsync(id);
return entity;
} }
/// <summary> /// <summary>
@ -46,7 +19,7 @@ public class SysDictTypeService : IDynamicApiController, ITransient
/// <param name="queryJson">equal:code; like:name; between:[startTime,endTime];</param> /// <param name="queryJson">equal:code; like:name; between:[startTime,endTime];</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<SysDictType>> GetList(string queryJson) public override async Task<List<SysDictType>> GetList(string queryJson)
{ {
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();
@ -72,7 +45,7 @@ public class SysDictTypeService : IDynamicApiController, ITransient
/// <param name="pagination">index,size</param> /// <param name="pagination">index,size</param>
/// <returns></returns> /// <returns></returns>
[HttpGet] [HttpGet]
public async Task<List<SysDictType>> GetPageList(string queryJson, string pagination) public override async Task<List<SysDictType>> GetPageList(string queryJson, string pagination)
{ {
JObject queryObj = queryJson.ToJObject(); JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>(); Pagination pageObj = pagination.ToObject<Pagination>();

78
Cis.Core/Cis.Core.xml

@ -194,6 +194,84 @@
时间戳 时间戳
</summary> </summary>
</member> </member>
<member name="M:Cis.Core.Common.ServiceBase`1.Add(`0)">
<summary>
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:Cis.Core.Common.ServiceBase`1.AddReturnId(`0)">
<summary>
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:Cis.Core.Common.ServiceBase`1.AddArray(`0[])">
<summary>
</summary>
<param name="array"></param>
<returns></returns>
</member>
<member name="M:Cis.Core.Common.ServiceBase`1.Update(`0)">
<summary>
</summary>
<param name="entity"></param>
<returns></returns>
</member>
<member name="M:Cis.Core.Common.ServiceBase`1.UpdateArray(`0[])">
<summary>
</summary>
<param name="array"></param>
<returns></returns>
</member>
<member name="M:Cis.Core.Common.ServiceBase`1.Delete(System.Int64)">
<summary>
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:Cis.Core.Common.ServiceBase`1.DeleteArray(`0[])">
<summary>
</summary>
<param name="array"></param>
<returns></returns>
</member>
<member name="M:Cis.Core.Common.ServiceBase`1.FakeDelete(System.Int64)">
<summary>
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:Cis.Core.Common.ServiceBase`1.Get(System.Int64)">
<summary>
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="M:Cis.Core.Common.ServiceBase`1.GetList(System.String)">
<summary>
</summary>
<param name="queryJson">between:[startTime,endTime];</param>
<returns></returns>
</member>
<member name="M:Cis.Core.Common.ServiceBase`1.GetPageList(System.String,System.String)">
<summary>
</summary>
<param name="queryJson">between:[startTime,endTime];</param>
<param name="pagination">index,size</param>
<returns></returns>
</member>
<member name="T:Cis.Core.StatusEnum"> <member name="T:Cis.Core.StatusEnum">
<summary> <summary>
通用状态枚举 通用状态枚举

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

@ -0,0 +1,165 @@
using Furion.DynamicApiController;
using Newtonsoft.Json.Linq;
namespace Cis.Core.Common;
[NonController]
public class ServiceBase<T> : IDynamicApiController where T : EntityBase, new()
{
protected readonly SqlSugarRepository<T> _baseRep;
public ServiceBase(SqlSugarRepository<T> baseRep)
{
_baseRep = baseRep;
}
/// <summary>
///
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost]
public virtual async Task<bool> Add([FromForm] T entity)
{
return await _baseRep.InsertAsync(entity);
}
/// <summary>
///
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost]
public virtual async Task<long> AddReturnId([FromForm] T entity)
{
bool ret = await _baseRep.InsertAsync(entity);
if (!ret) return 0;
return entity.Id;
}
/// <summary>
///
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
[HttpPost]
public virtual async Task<bool> AddArray([FromForm] T[] array)
{
return await _baseRep.InsertRangeAsync(array);
}
/// <summary>
///
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
[HttpPost]
public virtual async Task<bool> Update([FromForm] T entity)
{
return await _baseRep.UpdateAsync(entity);
}
/// <summary>
///
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
[HttpPost]
public virtual async Task<bool> UpdateArray([FromForm] T[] array)
{
return await _baseRep.UpdateRangeAsync(array);
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
public virtual async Task<bool> Delete(long id)
{
return await _baseRep.DeleteByIdAsync(id);
}
/// <summary>
///
/// </summary>
/// <param name="array"></param>
/// <returns></returns>
[HttpPost]
public virtual async Task<bool> DeleteArray(T[] array)
{
return await _baseRep.DeleteByIdsAsync(array);
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpPost]
public virtual async Task<bool> FakeDelete(long id)
{
return await _baseRep.AsUpdateable()
.Where(it => it.Id.Equals(id))
.Where("limit 1")
.ReSetValue(it => it.IsDelete = true)
.ExecuteCommandAsync() > 0;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public virtual async Task<T> Get(long id)
{
T entity = await _baseRep.GetByIdAsync(id);
return entity;
}
/// <summary>
///
/// </summary>
/// <param name="queryJson">between:[startTime,endTime];</param>
/// <returns></returns>
[HttpGet]
public virtual async Task<List<T>> GetList(string queryJson = "")
{
JObject queryObj = queryJson.ToJObject();
var exp = Expressionable.Create<T>();
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">between:[startTime,endTime];</param>
/// <param name="pagination">index,size</param>
/// <returns></returns>
[HttpGet]
public virtual async Task<List<T>> GetPageList(string queryJson, string pagination)
{
JObject queryObj = queryJson.ToJObject();
Pagination pageObj = pagination.ToObject<Pagination>();
var exp = Expressionable.Create<T>();
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;
}
}
Loading…
Cancel
Save