Browse Source

更新

dev_DY_CC
赵新宇 1 year ago
parent
commit
d02f2aa8dd
  1. 2
      be/Hosts/Basedata.Host/Win_in.Sfs.Basedata.HttpApi.Host/BasedataHttpApiHostModule.cs
  2. 18
      be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Boms/BomAppService.cs
  3. 71
      be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Caches/CacheAppService.cs

2
be/Hosts/Basedata.Host/Win_in.Sfs.Basedata.HttpApi.Host/BasedataHttpApiHostModule.cs

@ -127,7 +127,7 @@ public class BasedataHttpApiHostModule : ModuleBase<BasedataHttpApiHostModule>
// { // {
// await scope.ServiceProvider // await scope.ServiceProvider
// .GetRequiredService<CacheService>().StartAsync().ConfigureAwait(false); // .GetRequiredService<CacheService>().StartAsync().ConfigureAwait(false);
// } // }
//}); //});

18
be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Boms/BomAppService.cs

@ -22,7 +22,7 @@ public class BomAppService :
SfsBaseDataAppServiceBase<Bom, BomDTO, SfsBaseDataRequestInputBase, BomEditInput, BomImportInput>, SfsBaseDataAppServiceBase<Bom, BomDTO, SfsBaseDataRequestInputBase, BomEditInput, BomImportInput>,
IBomAppService IBomAppService
{ {
//private readonly CacheService _cacheService;
private new readonly IBomRepository _repository; private new readonly IBomRepository _repository;
private readonly IBomManager _bomManager; private readonly IBomManager _bomManager;
@ -32,29 +32,17 @@ public class BomAppService :
public BomAppService(IBomRepository repository public BomAppService(IBomRepository repository
, IBomManager bomManager , IBomManager bomManager
, IDistributedCache<BomDTO> cache , IDistributedCache<BomDTO> cache
//, CacheService cacheService
) : base(repository, cache) ) : base(repository, cache)
{ {
_repository = repository; _repository = repository;
_bomManager = bomManager; _bomManager = bomManager;
//_cacheService = cacheService;
base.CreatePolicyName = BomPermissions.Create; base.CreatePolicyName = BomPermissions.Create;
base.UpdatePolicyName = BomPermissions.Update; base.UpdatePolicyName = BomPermissions.Update;
base.DeletePolicyName = BomPermissions.Delete; base.DeletePolicyName = BomPermissions.Delete;
//_cacheService.StartAsync().ConfigureAwait(false);
} }
#region Get #region Get
[HttpGet("get-by-productitemcode")] [HttpGet("get-by-productitemcode")]

71
be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Caches/CacheAppService.cs

@ -1,5 +1,7 @@
using System; using System;
using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using DocumentFormat.OpenXml.Office2010.Drawing;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -15,6 +17,39 @@ using Win_in.Sfs.Basedata.Domain.Shared;
namespace Win_in.Sfs.Basedata.Application; namespace Win_in.Sfs.Basedata.Application;
public class TaskQueue
{
private readonly List<TaskItem> _tasks = new List<TaskItem>();
public void Enqueue(string name, Action action)
{
_tasks.Add(new TaskItem { Name = name, Action = action });
}
public async Task StartAsync()
{
foreach (var task in _tasks)
{
await Task.Run(task.Action).ConfigureAwait(false);
}
}
}
public class TaskItem
{
public string Name { get; set; }
public Action Action { get; set; }
}
public class CycleOptions public class CycleOptions
{ {
/// <summary> /// <summary>
@ -24,7 +59,7 @@ public class CycleOptions
} }
/// <summary> /// <summary>
/// 提供缓存服务的类 /// 提供缓存服务的类(堵塞以后修改再用)
/// </summary> /// </summary>
public class CacheService:ISingletonDependency public class CacheService:ISingletonDependency
{ {
@ -41,32 +76,32 @@ public class CacheService:ISingletonDependency
/// </summary> /// </summary>
private async Task BomsCycle() private async Task BomsCycle()
{ {
using var serviceScope = _serviceProvider.CreateScope();
var repository = serviceScope.ServiceProvider.GetRequiredService<IBomRepository>(); //Task.Run(async () =>
var reassigner = new Reassigner(DateTime.Now, new TimeSpan(0, 0, _options.Value.BomsCycle==0?600: _options.Value.BomsCycle)); //{
await reassigner.RunAsync(async () => var reassigner = new Reassigner(DateTime.Now, new TimeSpan(0, 0, _options.Value.BomsCycle == 0 ? 60 : _options.Value.BomsCycle));
{ await reassigner.RunAsync(async () =>
Cache.Boms.Clear(); {
Cache.Boms = await repository.GetListAsync().ConfigureAwait(false); using var serviceScope = _serviceProvider.CreateScope();
var repository = serviceScope.ServiceProvider.GetRequiredService<IBomRepository>();
Cache.Boms.Clear();
Cache.Boms = await repository.GetListAsync().ConfigureAwait(false);
}).ConfigureAwait(false); }).ConfigureAwait(false);
//});
;
} }
/// <summary> /// <summary>
/// 异步开始生命周期操作 /// 异步开始生命周期操作不能堵塞
/// </summary> /// </summary>
public async Task StartAsync() public async Task StartAsync()
{ {
await BomsCycle().ConfigureAwait(false); BomsCycle();//异步处理不能堵塞主任务
}
/// <summary>
/// 异步重置BOM(Bill of Materials)生命周期操作
/// </summary>
public async Task ResetAsync()
{
await BomsCycle().ConfigureAwait(false);
} }
} }

Loading…
Cancel
Save