You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
10 KiB
C#

9 months ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using iBoxDB.LocalServer;
using POSV.Entity;
using POSV.Entity.Pormotion;
using iBoxDB.LocalServer.IO;
namespace POSV.HttpApi
{
public class DownloadCache
{
private static object _lock = new object();
private static DownloadCache _instance = null;
private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
private static string root = Path.Combine(AppDomain.CurrentDomain.BaseDirectory , "data" + Path.DirectorySeparatorChar + "v2");
private DB db = null;
private AutoBox auto = null;
private DownloadCache()
{
}
private void Init()
{
try
{
if (!Directory.Exists(root))
{
Directory.CreateDirectory(root);
}
DB.Root(root);//数据库存储路径
long address = (int)NoSql.Download;
iBoxDB.DBDebug.DDebug.DeleteDBFiles(address);
this.db = new DB(address);//数据库地址
var config = this.db.GetConfig();
//config.DBConfig.FileIncSize = 1024 * 1024 * 256;
//config.DBConfig.SwapMemoryBuffer = 1024 * 1024 * 128;
//config.DBConfig.SwapFileBuffer = 1024 * 1024 * 256;
RegisterTable(config);
if (this.auto == null)
{
this.auto = this.db.Open();
}
}
catch (Exception ex)
{
logger.Error(ex, "缓存系统初始化异常");
}
}
private void RegisterTable(DatabaseConfig.Config config)
{
//操作员缓存
config.EnsureTable<Worker>(DownloadCacheName.Worker.ToString() , "Id");
//门店营业方案
config.EnsureTable<BusinessPlan>(DownloadCacheName.BusinessPlan.ToString() , "Id");
//商品类别信息
config.EnsureTable<ProductType>(DownloadCacheName.ProductType.ToString() , "Id");
//商品信息
config.EnsureTable<Product>(DownloadCacheName.Product.ToString() , "Id");
//单位信息
config.EnsureTable<ProductUnit>(DownloadCacheName.ProductUnit.ToString() , "Id");
//图片信息
config.EnsureTable<ProductImage>(DownloadCacheName.ProductImage.ToString() , "Id");
//门店仓库
config.EnsureTable<StoreStorage>(DownloadCacheName.StoreStorage.ToString(), "Id");
//商品库存
config.EnsureTable<ProductStock>(DownloadCacheName.ProductStock.ToString(), "Id");
//库存系数
config.EnsureTable<ProductRatio>(DownloadCacheName.ProductRatio.ToString(), "Id");
//规格信息
config.EnsureTable<ProductSpec>(DownloadCacheName.ProductSpec.ToString() , "Id");
//做法类型
config.EnsureTable<ProductMakeType>(DownloadCacheName.ProductMakeType.ToString() , "Id");
//做法信息
config.EnsureTable<ProductMakeDetail>(DownloadCacheName.ProductMakeDetail.ToString() , "Id");
//私有做法信息
config.EnsureTable<ProductMakeDetailPrivate>(DownloadCacheName.ProductMakeDetailPrivate.ToString(), "Id");
//套菜
config.EnsureTable<ProductSuit>(DownloadCacheName.ProductSuit.ToString() , "Id");
//套菜明细
config.EnsureTable<ProductSuitDetail>(DownloadCacheName.ProductSuitDetail.ToString() , "Id");
//班次方案
config.EnsureTable<BusinessPlanDetail>(DownloadCacheName.BusinessPlanDetail.ToString() , "Id");
//付款类型
config.EnsureTable<PayType>(DownloadCacheName.PayType.ToString() , "Id");
//收银方式
config.EnsureTable<PayMode>(DownloadCacheName.PayMode.ToString() , "Id");
//餐桌区域
config.EnsureTable<TableArea>(DownloadCacheName.TableArea.ToString() , "Id");
//餐桌类型
config.EnsureTable<TableType>(DownloadCacheName.TableType.ToString() , "Id");
//餐桌信息
config.EnsureTable<Table>(DownloadCacheName.Table.ToString() , "Id");
//门店品牌
config.EnsureTable<Brand>(DownloadCacheName.Brand.ToString() , "Id");
//员工角色
config.EnsureTable<WorkerRole>(DownloadCacheName.WorkerRole.ToString() , "Id");
//员工权限
config.EnsureTable<WorkerPermissions>(DownloadCacheName.WorkerPermissions.ToString() , "Id");
//厨打方案
config.EnsureTable<KitPlan>(DownloadCacheName.KitPlan.ToString(), "Id");
//厨打商品
config.EnsureTable<KitProduct>(DownloadCacheName.KitProduct.ToString(), "Id");
//厨显方案
config.EnsureTable<KdsPlan>(DownloadCacheName.KdsPlan.ToString(), "Id");
//厨显商品
config.EnsureTable<KdsProduct>(DownloadCacheName.KdsProduct.ToString(), "Id");
//打印机信息
config.EnsureTable<POSV.Entity.Printer>(DownloadCacheName.Printer.ToString() , "Id");
//读卡器信息
config.EnsureTable<Carder>(DownloadCacheName.Carder.ToString() , "Id");
//门店信息
config.EnsureTable<StoreInfo>(DownloadCacheName.StoreInfo.ToString(), "Id");
//门店小票图片信息
config.EnsureTable<StorePrintImage>(DownloadCacheName.StorePrintImage.ToString(), "Id");
//门店双屏图片信息
config.EnsureTable<AdvertPictures>(DownloadCacheName.AdvertPicture.ToString(), "Id");
//门店双屏字幕信息
config.EnsureTable<AdvertCaption>(DownloadCacheName.AdvertCaption.ToString(), "Id");
//饿了么映射关系
config.EnsureTable<MappingDishEleMe>(DownloadCacheName.MappingDishEleMe.ToString(), "Id");
//美团映射关系
config.EnsureTable<MappingDishMeiTuan>(DownloadCacheName.MappingDishMeiTuan.ToString(), "Id");
//百度映射关系
config.EnsureTable<MappingDishBaiDu>(DownloadCacheName.MappingDishBaiDu.ToString(), "Id");
//门店费用项目列表
config.EnsureTable<Feeitem>(DownloadCacheName.Feeitem.ToString(), "Id");
//门店熟客信息
config.EnsureTable<Visitor>(DownloadCacheName.Visitor.ToString() , "Id");
//门店熟客标签
config.EnsureTable<VisitorTag>(DownloadCacheName.VisitorTag.ToString() , "Id");
//门店熟客地址
config.EnsureTable<VisitorAddress>(DownloadCacheName.VisitorAddress.ToString() , "Id");
//线上促销
config.EnsureTable<CardPromotion>(DownloadCacheName.CardProDay.ToString(), "Id");
//门店促销
config.EnsureTable<PromotionTask>(DownloadCacheName.PromotionStoreTask.ToString(), "Id");
//门店优惠券
config.EnsureTable<StoreCoupon>(DownloadCacheName.PromotionStoreCoupon.ToString(), "Id");
//充值支付参数
config.EnsureTable<RechargeParameter>(DownloadCacheName.RechargeParameter.ToString(), "Id");
//设置支付参数
config.EnsureTable<SetPlan>(DownloadCacheName.SetPlan.ToString(), "Id");
//商品耗料配方
config.EnsureTable<ProductBurden>(DownloadCacheName.ProductBurden.ToString(), "Id");
//做法耗料配方
config.EnsureTable<MakeBurden>(DownloadCacheName.MakeBurden.ToString(), "Id");
//门店商品优惠券
config.EnsureTable<StoreProductCoupon>(DownloadCacheName.StoreProductCoupon.ToString(), "Id");
//缓存待更新的Sql语句
config.EnsureTable<DownloadSqlCache>(DownloadCacheName.SqlCache.ToString() , "Id");
}
public static DownloadCache Instance
{
get
{
if (_instance == null)
{
lock (_lock)
{
_instance = new DownloadCache();
_instance.Init();
}
}
return _instance;
}
}
/// <summary>
/// IBox可以进行数据库的事务操作
/// </summary>
public AutoBox AutoBox
{
get
{
return _instance.auto;
}
}
/// <summary>
/// IBox可以进行数据库的事务操作
/// </summary>
public IBox AutoBoxTransaction
{
get
{
return AutoBox.Cube();
}
}
/// <summary>
/// 删除数据库IBoxDB中没有直接删除一个表的接口所以这个方法显得格外亲切~
/// 注意:删除数据库之前要关闭该数据库
/// </summary>
/// <param name="address">数据库地址</param>
public static void ClearAll()
{
try
{
if (Directory.Exists(root))
{
if (DownloadCache.Instance.db != null)
{
DownloadCache.Instance.AutoBox.GetDatabase().Dispose();
DownloadCache.Instance.db.Close();
DownloadCache.Instance.db.Dispose();
}
DownloadCache.Instance.db = null;
logger.Info("清理已下载的缓存数据....");
iBoxDB.LocalServer.DB.Root(root);
iBoxDB.DBDebug.DDebug.DeleteDBFiles((int)NoSql.Download);
logger.Info("缓存数据清理成功....");
_instance = null;
}
}
catch (Exception ex)
{
logger.Error(ex , "清理缓存异常");
}
}
}
public class BoxDBServer : LocalDatabaseServer
{
protected override DatabaseConfig BuildDatabaseConfig(long address)
{
return new BoxMemoryStreamConfig();
}
}
}