Browse Source

更新

dev_DY_CC
赵新宇 1 year ago
parent
commit
d02f2aa8dd
  1. 16
      be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Boms/BomAppService.cs
  2. 71
      be/Modules/BaseData/src/Win_in.Sfs.Basedata.Application/Caches/CacheAppService.cs

16
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>,
IBomAppService
{
//private readonly CacheService _cacheService;
private new readonly IBomRepository _repository;
private readonly IBomManager _bomManager;
@ -32,29 +32,17 @@ public class BomAppService :
public BomAppService(IBomRepository repository
, IBomManager bomManager
, IDistributedCache<BomDTO> cache
//, CacheService cacheService
) : base(repository, cache)
{
_repository = repository;
_bomManager = bomManager;
//_cacheService = cacheService;
base.CreatePolicyName = BomPermissions.Create;
base.UpdatePolicyName = BomPermissions.Update;
base.DeletePolicyName = BomPermissions.Delete;
//_cacheService.StartAsync().ConfigureAwait(false);
}
#region Get
[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.Collections.Generic;
using System.Threading.Tasks;
using DocumentFormat.OpenXml.Office2010.Drawing;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
@ -15,6 +17,39 @@ using Win_in.Sfs.Basedata.Domain.Shared;
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
{
/// <summary>
@ -24,7 +59,7 @@ public class CycleOptions
}
/// <summary>
/// 提供缓存服务的类
/// 提供缓存服务的类(堵塞以后修改再用)
/// </summary>
public class CacheService:ISingletonDependency
{
@ -41,32 +76,32 @@ public class CacheService:ISingletonDependency
/// </summary>
private async Task BomsCycle()
{
using var serviceScope = _serviceProvider.CreateScope();
var repository = serviceScope.ServiceProvider.GetRequiredService<IBomRepository>();
var reassigner = new Reassigner(DateTime.Now, new TimeSpan(0, 0, _options.Value.BomsCycle==0?600: _options.Value.BomsCycle));
await reassigner.RunAsync(async () =>
{
Cache.Boms.Clear();
Cache.Boms = await repository.GetListAsync().ConfigureAwait(false);
}).ConfigureAwait(false);
//Task.Run(async () =>
//{
var reassigner = new Reassigner(DateTime.Now, new TimeSpan(0, 0, _options.Value.BomsCycle == 0 ? 60 : _options.Value.BomsCycle));
await reassigner.RunAsync(async () =>
{
using var serviceScope = _serviceProvider.CreateScope();
var repository = serviceScope.ServiceProvider.GetRequiredService<IBomRepository>();
Cache.Boms.Clear();
Cache.Boms = await repository.GetListAsync().ConfigureAwait(false);
}).ConfigureAwait(false);
//});
;
}
/// <summary>
/// 异步开始生命周期操作
/// 异步开始生命周期操作不能堵塞
/// </summary>
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