first commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.Common.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局字典缓存
|
||||
/// </summary>
|
||||
public static class GlobalDictionaryCache
|
||||
{
|
||||
/// <summary>
|
||||
/// 楞型
|
||||
/// </summary>
|
||||
public static Dictionary<int, string> Flutes = new()
|
||||
{
|
||||
{ 1, "A" },
|
||||
{ 2, "B" },
|
||||
{ 3, "C" },
|
||||
{ 5, "E" },
|
||||
{ 6, "F" },
|
||||
{ 7, "G" },
|
||||
{ 12, "AB" },
|
||||
{ 13, "AC" },
|
||||
{ 23, "BC" },
|
||||
{ 25, "BE" }
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
using JSMachine.DCS.Infrastructure;
|
||||
using JSMachine.WMS.Common.Cache.Model;
|
||||
using JSMachine.WMS.Infrastructure.Helper;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.Common.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局文件缓存(不适用于非常频繁的存取场景,否则会造成IO开销太大的情况)
|
||||
/// </summary>
|
||||
public static class GlobalFileCache
|
||||
{
|
||||
private static string _cahcheFilePath = @$"{AppDomain.CurrentDomain.BaseDirectory}orderCache.txt";
|
||||
|
||||
/// <summary>
|
||||
/// 清空缓存
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static bool ClearOrderCache()
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(_cahcheFilePath);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error("清空订单缓存出错",ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置订单缓存
|
||||
/// </summary>
|
||||
/// <param name="productionOrderCacheModel"></param>
|
||||
/// <returns></returns>
|
||||
public static bool SetOrderCache(ProductionOrderCacheModel productionOrderCacheModel)
|
||||
{
|
||||
try
|
||||
{
|
||||
File.WriteAllText(_cahcheFilePath, JsonConvert.SerializeObject(productionOrderCacheModel));
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error("添加订单缓存失败",ex);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取当前订单缓存
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static ProductionOrderCacheModel GetCurrentOrderCache()
|
||||
{
|
||||
if (!File.Exists(_cahcheFilePath))
|
||||
return null;
|
||||
|
||||
string json = File.ReadAllText(_cahcheFilePath);
|
||||
if (string.IsNullOrEmpty(json))
|
||||
return null;
|
||||
|
||||
return JsonConvert.DeserializeObject<ProductionOrderCacheModel>(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.Common.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// 全局内存缓存(需要注意在程序退出时持久化内存数据)
|
||||
/// 什么时候会进行过期缓存清理?特别注意:缓存清理并不会主动进行,即使设置了过期策略也必须在以下几种情况下才清理过期项
|
||||
/// </summary>
|
||||
public class GlobalMemoryCache
|
||||
{
|
||||
/// <summary>
|
||||
/// 内存缓存
|
||||
/// </summary>
|
||||
private static IMemoryCache MemoryCache = new MemoryCache(Options.Create(new MemoryCacheOptions()
|
||||
{
|
||||
ExpirationScanFrequency = TimeSpan.FromSeconds(10)
|
||||
}));
|
||||
|
||||
//默认缓存项缓存过期设置可以绝对过期和滑动过期同时设置,两个条件满足一个即视为当前缓存项过期
|
||||
//private static MemoryCacheEntryOptions DefaultCachOption = new()
|
||||
//{
|
||||
// //设置绝对过期时间为10分钟(10分钟后缓存项会移除)
|
||||
// AbsoluteExpirationRelativeToNow = TimeSpan.FromMinutes(30),
|
||||
// //容量为一份大小
|
||||
// Size = 1,
|
||||
// //设置滑动过期时间为10分钟(两分钟内缓存项未被访问则移除该缓存项)
|
||||
// SlidingExpiration = TimeSpan.FromMinutes(10)
|
||||
//};
|
||||
|
||||
/// <summary>
|
||||
/// 增加缓存
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="memoryCacheEntry"></param>
|
||||
public static void AddCach<TKey, TValue>(TKey key, TValue value, MemoryCacheEntryOptions memoryCacheEntry = null)
|
||||
{
|
||||
//不传递缓存选项则永不过期
|
||||
if (memoryCacheEntry == null)
|
||||
MemoryCache.Set(key, value);
|
||||
else
|
||||
MemoryCache.Set(key, value, memoryCacheEntry);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存项
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <typeparam name="TValue"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
/// <returns></returns>
|
||||
public static TValue GetCach<TKey, TValue>(TKey key)
|
||||
{
|
||||
return MemoryCache.Get<TValue>(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除缓存项
|
||||
/// </summary>
|
||||
/// <typeparam name="TKey"></typeparam>
|
||||
/// <param name="key"></param>
|
||||
public static void RemoveCach<TKey>(TKey key)
|
||||
{
|
||||
MemoryCache.Remove(key);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 激活缓存,以便让过期项被及时检测并触发超时移除事件
|
||||
/// 微软限制,当不访问缓存的时候过期策略失效
|
||||
/// 仅在需要的项目中调用此方法,以免不必要的性能消耗
|
||||
/// 什么时候会进行过期缓存清理?特别注意:缓存清理并不会主动进行,即使设置了过期策略也必须在以下几种情况下才清理过期项
|
||||
/// 添加新的
|
||||
/// 获取缓存项
|
||||
/// 删除缓存项目
|
||||
/// </summary>
|
||||
public static void ActicateCach()
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
Thread.Sleep(2000);
|
||||
MemoryCache.Get("AAA");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.Common.Cache.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 条码缓存信息
|
||||
/// </summary>
|
||||
public class BarCodeInfo
|
||||
{
|
||||
public string IP { get; set; }
|
||||
public string BarCode { get; set; }
|
||||
public DateTime AddTime { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
using JSMachine.WMS.App.Dto;
|
||||
using JSMachine.WMS.Common.Enum;
|
||||
|
||||
namespace JSMachine.WMS.Common.Cache.Model
|
||||
{
|
||||
/// <summary>
|
||||
/// 生产订单缓存
|
||||
/// </summary>
|
||||
public class ProductionOrderCacheModel
|
||||
{
|
||||
#region 订单基础信息
|
||||
/// <summary>
|
||||
/// 订单编号
|
||||
/// </summary>
|
||||
public string OrderNo { get; set; }
|
||||
/// <summary>
|
||||
/// 添加缓存时间
|
||||
/// </summary>
|
||||
public DateTime AddTime { get; set; }
|
||||
/// <summary>
|
||||
/// 换单时间(发送换单命令时刻)
|
||||
/// </summary>
|
||||
public DateTime? ChangeOrderTime { get; set; }
|
||||
/// <summary>
|
||||
/// 已生产持续时间(秒)
|
||||
/// </summary>
|
||||
public int? DurationOfProduction { get; set; }
|
||||
/// <summary>
|
||||
/// 第一个良品数产生时间(换单准备时间=第一个良品数产生时间-开始换单时间)
|
||||
/// </summary>
|
||||
public DateTime? FirstGoodProductTime { get; set; }
|
||||
/// <summary>
|
||||
/// 结束时间(结束生产)
|
||||
/// </summary>
|
||||
public DateTime? FinishedTime { get; set; }
|
||||
/// <summary>
|
||||
/// 实际生产数量
|
||||
/// </summary>
|
||||
public int ProductionNum { get; set; }
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using JSMachine.WMS.RPC.RcsRPC.Dto.In;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.Common.Cache
|
||||
{
|
||||
/// <summary>
|
||||
/// RCS 回调信息的进程内并发队列,供回调接收方与任务处理方之间暂存数据。
|
||||
/// </summary>
|
||||
public static class RcsCallbackCache
|
||||
{
|
||||
/// <summary>
|
||||
/// 待处理的 RCS AGV 执行信息队列。
|
||||
/// </summary>
|
||||
public static ConcurrentQueue<AgvExcutionInfo> RcsCallbackQueue = new();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using JSMachine.WMS.App.Dto;
|
||||
using JSMachine.WMS.RPC.RcsRPC.Dto.In;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JSMachine.WMS.Common.Cache
|
||||
{
|
||||
public class StockInSecondFloorCache
|
||||
{
|
||||
public static ConcurrentQueue<AllowPickUpInfo> StockInSecondFloorQue = new();
|
||||
}
|
||||
|
||||
public class AllowPickUpInfo
|
||||
{
|
||||
public ElevatorPlcQueueDto ElevatorPlcQueue { get; set; }
|
||||
public StorageRackDto StartWarehouseSecondFloor { get; set; }
|
||||
public AGVTaskDto AgvTask { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user