fix 餐补直接入库处理
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.External.MealSupplement.Request;
|
||||
using Kurisu.AspNetCore.EventBus.Abstractions;
|
||||
using Kurisu.AspNetCore.EventBus.Abstractions.Handler;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
//using Dlhis.Entity.Canteen.Entities;
|
||||
//using Dlhis.External.MealSupplement.Request;
|
||||
//using Kurisu.AspNetCore.EventBus.Abstractions;
|
||||
//using Kurisu.AspNetCore.EventBus.Abstractions.Handler;
|
||||
//using Kurisu.SqlSugar.Services;
|
||||
//using Mapster;
|
||||
|
||||
namespace Dlhis.External.MealSupplement.Channel;
|
||||
//namespace Dlhis.External.MealSupplement.Channel;
|
||||
|
||||
public class MealSupplementHandler : IAsyncChannelHandler<MealSupplementMessage>
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
//public class MealSupplementHandler : IAsyncChannelHandler<MealSupplementMessage>
|
||||
//{
|
||||
// private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public MealSupplementHandler(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
// public MealSupplementHandler(IServiceProvider serviceProvider)
|
||||
// {
|
||||
// _serviceProvider = serviceProvider;
|
||||
// }
|
||||
|
||||
public async Task InvokeAsync(MealSupplementMessage message)
|
||||
{
|
||||
using var scope = _serviceProvider.CreateScope();
|
||||
var db = scope.ServiceProvider.GetService<IDbContext>();
|
||||
// public async Task InvokeAsync(MealSupplementMessage message)
|
||||
// {
|
||||
// using var scope = _serviceProvider.CreateScope();
|
||||
// var db = scope.ServiceProvider.GetService<IDbContext>();
|
||||
|
||||
var existsIds = await db.Queryable<MealSupplementRecordEntity>().Select(x => x.UniqueId).ToListAsync();
|
||||
var items = message.Items.Where(x => !existsIds.Contains(x.UniqueId)).ToList();
|
||||
// var existsIds = await db.Queryable<MealSupplementRecordEntity>().Select(x => x.UniqueId).ToListAsync();
|
||||
// var items = message.Items.Where(x => !existsIds.Contains(x.UniqueId)).ToList();
|
||||
|
||||
var entities = items.Adapt<List<MealSupplementRecordEntity>>();
|
||||
await db.InsertAsync(entities);
|
||||
}
|
||||
}
|
||||
// var entities = items.Adapt<List<MealSupplementRecordEntity>>();
|
||||
// await db.InsertAsync(entities);
|
||||
// }
|
||||
//}
|
||||
|
||||
public class MealSupplementMessage : IAsyncChannelMessage
|
||||
{
|
||||
public List<MealSupplementReceiveReuqest> Items { get; set; }
|
||||
}
|
||||
//public class MealSupplementMessage : IAsyncChannelMessage
|
||||
//{
|
||||
// public List<MealSupplementReceiveReuqest> Items { get; set; }
|
||||
//}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using Dlhis.Entity.Canteen.Entities;
|
||||
using Dlhis.External.MealSupplement.Channel;
|
||||
using Dlhis.External.MealSupplement.Request;
|
||||
using Kurisu.AspNetCore.EventBus.Abstractions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
|
||||
@@ -9,18 +7,30 @@ namespace Dlhis.External.MealSupplement.Services.Implements;
|
||||
|
||||
public class MealSupplementService : IMealSupplementService
|
||||
{
|
||||
private readonly IEventBus _eventBus;
|
||||
private readonly IDbContext _dbContext;
|
||||
|
||||
public MealSupplementService(IEventBus eventBus, IDbContext dbContext)
|
||||
public MealSupplementService(IDbContext dbContext)
|
||||
{
|
||||
_eventBus = eventBus;
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task DoSupplementsAsync(List<MealSupplementReceiveReuqest> reuqests)
|
||||
{
|
||||
await _dbContext.InsertAsync(reuqests.Adapt<List<MealSupplementRequestRecordEntity>>());
|
||||
await _eventBus.PublishAsync(new MealSupplementMessage { Items = reuqests });
|
||||
var entities = reuqests.Adapt<List<MealSupplementRecordEntity>>();
|
||||
foreach (var entity in entities)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!await _dbContext.Queryable<MealSupplementRecordEntity>().Where(x => x.UniqueId == entity.UniqueId).AnyAsync())
|
||||
{
|
||||
await _dbContext.InsertAsync(entity);
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
//await _eventBus.PublishAsync(new MealSupplementMessage { Items = reuqests });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using Kurisu.AspNetCore.EventBus.Extensions;
|
||||
using Kurisu.AspNetCore.Startup;
|
||||
using Kurisu.SqlSugar.Extensions;
|
||||
using Kurisu.Startup;
|
||||
@@ -24,6 +23,6 @@ public class Startup : DefaultStartup
|
||||
base.ConfigureServices(services);
|
||||
|
||||
services.AddSqlSugar();
|
||||
services.AddEventBus();
|
||||
//services.AddEventBus();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user