新增批量更新接口

master
xiaochanghai 1 year ago
parent 7566e2e80e
commit 13e72e9694
  1. 15
      Tiobon.Core.Api/Controllers/Base/BaseController.cs
  2. 6
      Tiobon.Core.Api/Tiobon.Core.xml
  3. 4
      Tiobon.Core.Api/appsettings.json
  4. 1
      Tiobon.Core.IServices/BASE/IBaseServices.cs
  5. 10
      Tiobon.Core.Repository/BASE/BaseRepository.cs
  6. 7
      Tiobon.Core.Repository/BASE/IBaseRepository.cs
  7. 24
      Tiobon.Core.Services/BASE/BaseServices.cs

@ -1,4 +1,5 @@
using System.Reflection;
using SkyWalking.NetworkProtocol.V3;
namespace Tiobon.Core.Controllers;
@ -112,6 +113,20 @@ public class BaseController<IServiceBase, TEntity, TEntityDto, TInsertDto, TEdit
return Failed("更新失败");
return data;
}
/// <summary>
/// 扣费记录 -- 批量更新数据
/// </summary>
/// <param name="editModels"></param>
[HttpPut]
[Route("BulkUpdate")]
public async Task<ServiceResult> BulkUpdate([FromBody] Dictionary<long, TEditDto> editModels)
{
var data = Success("更新成功");
var flag = Convert.ToBoolean(await InvokeServiceAsync("Update", [editModels]));
if (!flag)
return Failed("更新失败");
return data;
}
#endregion
#region 删除

@ -114,6 +114,12 @@
<param name="editModel"></param>
<returns></returns>
</member>
<member name="M:Tiobon.Core.Controllers.BaseController`5.BulkUpdate(System.Collections.Generic.Dictionary{System.Int64,`4})">
<summary>
扣费记录 -- 批量更新数据
</summary>
<param name="editModels"></param>
</member>
<member name="M:Tiobon.Core.Controllers.BaseController`5.Delete(System.Int64)">
<summary>
删除数据

@ -107,8 +107,8 @@
"ConnId": "WMTiobon_MSSQL_Main",
"DBType": 1,
"Enabled": true,
"Connection": "Data Source=47.99.54.186;User ID=GHR;Password=Tiobon20190101;Database=GHR30;Encrypt=True;TrustServerCertificate=True;",
//"Connection": "Data Source=116.204.98.209;User ID=Tiobon;Password=&($!4UGUyU#$2sp9O;Database=Tiobon;Encrypt=True;TrustServerCertificate=True;",
//"Connection": "Data Source=47.99.54.186;User ID=GHR;Password=Tiobon20190101;Database=GHR30;Encrypt=True;TrustServerCertificate=True;",
"Connection": "Data Source=116.204.98.209;User ID=Tiobon;Password=&($!4UGUyU#$2sp9O;Database=Tiobon;Encrypt=True;TrustServerCertificate=True;",
"ProviderName": "System.Data.SqlClient"
},
{

@ -103,6 +103,7 @@ namespace Tiobon.Core.IServices.BASE
Task<bool> DeleteByIds(object[] ids);
Task<bool> Update(long Id, TEditDto model);
Task<bool> Update(Dictionary<long, TEditDto> editModels);
Task<bool> Update(List<TEntity> model);
Task<bool> Update(TEntity entity, string where);

@ -82,6 +82,16 @@ namespace Tiobon.Core.Repository.Base
return await _db.Queryable<TEntity>().In(objId).AnyAsync();
}
/// <summary>
/// 查询实体数据是否存在
/// </summary>
/// <param name="objId"></param>
/// <returns></returns>
public bool Any(object objId)
{
return _db.Queryable<TEntity>().In(objId).Any();
}
/// <summary>
/// 根据ID查询一条数据
/// </summary>

@ -20,6 +20,13 @@ namespace Tiobon.Core.IRepository.Base
/// <returns></returns>
Task<bool> AnyAsync(object objId);
/// <summary>
/// 查询实体数据是否存在
/// </summary>
/// <param name="objId"></param>
/// <returns></returns>
bool Any(object objId);
/// <summary>
/// 根据Id查询实体
/// </summary>

@ -12,6 +12,7 @@ using Tiobon.Core.Common.UserManager;
using Tiobon.Core.IRepository.Base;
using Tiobon.Core.IServices.BASE;
using Tiobon.Core.Model;
using Tiobon.Core.Repository.Base;
namespace Tiobon.Core.Services.BASE
{
@ -464,6 +465,29 @@ namespace Tiobon.Core.Services.BASE
ent.UpdateProg = api;
return await BaseDal.Update(entity);
}
public async Task<bool> Update(Dictionary<long, TEditDto> editModels)
{
HttpRequest request = UserContext.Context.Request;
var api = request.Path.ObjToString().TrimEnd('/').ToLower();
var ip = GetUserIp(UserContext.Context);
List<TEntity> entities = new List<TEntity>();
foreach (var keyValuePairs in editModels)
{
if (keyValuePairs.Value == null || !BaseDal.Any(keyValuePairs.Key))
continue;
var entity = await BaseDal.QueryById(keyValuePairs.Key);
ConvertTEditDto2TEntity(keyValuePairs.Value, entity);
BasePoco ent = entity as BasePoco;
ent.UpdateIP = ip;
ent.UpdateProg = api;
entities.Add(entity);
}
return await BaseDal.Update(entities);
}
/// <summary>
/// 更新实体数据
/// </summary>

Loading…
Cancel
Save