76 lines
2.1 KiB
C#
76 lines
2.1 KiB
C#
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);
|
|
}
|
|
}
|
|
}
|