This commit is contained in:
tongfei
2024-04-17 16:33:51 +08:00
parent 7700bc37fb
commit 2e87e970a4
4 changed files with 56 additions and 1 deletions

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WMS.Web.Domain.IService.Public
{
public interface IRedisConcurrentProcessService
{
bool CanAccessMethod(string cacheKey);
void UpdateAccessStatus(string cacheKey, bool canAccess);
}
}

View File

@@ -0,0 +1,29 @@
using StackExchange.Redis;
using System;
using System.Collections.Generic;
using System.Text;
using WMS.Web.Domain.IService.Public;
namespace WMS.Web.Domain.Services.Public
{
public class RedisConcurrentProcessService: IRedisConcurrentProcessService
{
private readonly RedisClientService _redisClientService;
public RedisConcurrentProcessService(RedisClientService redisClientService)
{
this._redisClientService = redisClientService;
}
public bool CanAccessMethod(string cacheKey)
{
// 使用 Redis 来存储并发控制标记
return _redisClientService.SetStringKey(cacheKey, "true", TimeSpan.FromMinutes(1));
}
public void UpdateAccessStatus(string cacheKey, bool canAccess)
{
// 更新 Redis 缓存项的值
_redisClientService.SetStringKey(cacheKey, canAccess.ToString(), TimeSpan.FromMinutes(1));
}
}
}

View File

@@ -331,6 +331,7 @@ namespace WMS.Web.Repositories.DependencyInjection
Services.AddTransient<IBoxMarkService, BoxMarkService>(); Services.AddTransient<IBoxMarkService, BoxMarkService>();
Services.AddTransient<ISendMessageService, SendMessageService>(); Services.AddTransient<ISendMessageService, SendMessageService>();
Services.AddTransient<IMaterialService, MaterialService>(); Services.AddTransient<IMaterialService, MaterialService>();
Services.AddTransient<IRedisConcurrentProcessService, RedisConcurrentProcessService>();
} }

View File

@@ -4,6 +4,7 @@ using Microsoft.EntityFrameworkCore.Storage;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using WMS.Web.Core; using WMS.Web.Core;
@@ -762,7 +763,18 @@ namespace WMS.Web.Repositories
} }
if (dto.SerialNumbers != null && dto.SerialNumbers.Count != 0) if (dto.SerialNumbers != null && dto.SerialNumbers.Count != 0)
{ {
var tids= await _context.InStockDetails.Where(w => w.SerialNumbers.SequenceEqual(dto.SerialNumbers)).GroupBy(x => x.TaskId).Select(x => x.Key).ToListAsync(); //var tids= await _context.InStockDetails.Where(a => a.SerialNumbers.Intersect(dto.SerialNumbers).Count() == dto.SerialNumbers.Count).GroupBy(x => x.TaskId).Select(x => x.Key).ToListAsync();
string str = $"select * from t_wms_instock_details where ";
for (int i = 0; i < dto.SerialNumbers.Count(); i++)
{
if (i == 0)
str += $"SerialNumbers like '%\"{dto.SerialNumbers[i]}\"%'";
else
str += $" or SerialNumbers like '%\"{dto.SerialNumbers[i]}\"%'";
}
var fs = FormattableStringFactory.Create(str);
var InStockDetails = _context.Set<InStockDetails>().FromSqlInterpolated(fs).ToList();
var tids=InStockDetails.GroupBy(x => x.TaskId).Select(x => x.Key).ToList();
taskIds.AddRange(tids); taskIds.AddRange(tids);
} }