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.

2187 lines
89 KiB
C#

using JwKdsV.Core.HttpApi;
using JwKdsV.Core.Utils;
using JwKdsV.Entity;
using JwKdsV.Entity.Common;
using JwKdsV.Entity.Normal;
using JwKdsV.Entity.Product;
using LiteDB;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using TeaV2.Entity;
namespace JwKdsV.Core.Download
{
public class DownloadApi : BaseApi
{
protected static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
public static string SQL_CACHE_NAME = "pos_sqls";
public static string POS_PRODUCT_X = "pos_product_x";
private static object _lock = new object();
private static DownloadApi _instance = null;
private ConcurrentQueue<DownloadSqlCache> _cache = null;
public static DownloadApi Instance
{
get
{
if (_instance == null)
{
lock (_lock)
{
_instance = new DownloadApi();
_instance.InitCache();
}
}
return _instance;
}
}
public void InitCache()
{
this._cache = new ConcurrentQueue<DownloadSqlCache>();
}
private void AddCache(DownloadSqlCache data)
{
this._cache.Enqueue(data);
}
public ConcurrentQueue<DownloadSqlCache> Cache()
{
return this._cache;
}
#region 操作员数据下载
public static DownloadNotify DownloadWorker()
{
DownloadNotify notify = new DownloadNotify();
notify.Success = false;
notify.Operate = DownloadCacheName.Worker;
notify.IsPager = false;
notify.PageNumber = 1;
notify.PageCount = 1;
string tips = "门店操作员";
try
{
logger.Info(string.Format("下载{0}......", tips));
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
parameters.Add("method", "worker.list");
parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters));
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
if (Constant.IsSuccessful(response))
{
var result = JsonUtils.Deserialize<ListResponse<Worker>>(response);
if (result.Status == 1)
{
if (CacheWorker(notify.CacheName, result.List))
{
notify.Success = true;
notify.Message = string.Format("{0}下载成功......", tips);
logger.Info(result.Message);
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.WorkerError;
notify.Message = string.Format("缓存{0}发生错误", tips);
logger.Info(notify.Message);
}
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.WorkerError;
notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message));
}
}
else
{
string errorMessage = ParseErrors(response);
notify.Success = false;
notify.Operate = DownloadCacheName.WorkerError;
notify.Message = errorMessage;
logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage));
}
}
catch (Exception ex)
{
notify.Success = false;
notify.Operate = DownloadCacheName.WorkerException;
notify.Message = string.Format("{0}下载发生异常", tips);
logger.Error(ex, notify.Message);
}
return notify;
}
private static bool CacheWorker(string cacheName, List<Worker> lists)
{
bool result = false;
string tips = "门店操作员";
try
{
//清理数据
DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_worker];", CacheName = cacheName });
if (lists.Count() > 0)
{
string template = "insert into [pos_worker] ([id],[tenantId],[storeId],[departmentId],[no],[passwd],[name],[sex],[birthday],[email],[mobile],[session],[lastDate],[memo],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}');";
foreach (var entity in lists)
{
if (Global.Instance.StoreInfo != null && entity.TenantId == null)
{
entity.TenantId = Global.Instance.StoreInfo.TenantId;
}
string sql = string.Format(template, entity.Id, entity.TenantId, entity.StoreId, entity.DepartmentId, entity.No, entity.Passwd, entity.Name, entity.Sex, entity.Birthday, entity.Email, entity.Mobile, entity.Session, entity.LastDate, entity.Memo, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate);
DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName });
}
}
result = true;
}
catch (Exception ex)
{
logger.Error(ex, string.Format("处理{0}发生异常", tips));
result = false;
}
return result;
}
#endregion
#region 获取商品类别信息
/// <summary>
/// 菜品类别数据下载
/// </summary>
/// <returns></returns>
public static DownloadNotify DownloadProductType(int pageSize)
{
DownloadNotify notify = new DownloadNotify();
notify.Success = false;
notify.Operate = DownloadCacheName.ProductType;
notify.IsPager = false;
notify.PageNumber = 1;
notify.PageCount = 1;
notify.PageSize = pageSize;
string tips = "商品类别信息";
try
{
logger.Info(string.Format("下载{0}......", tips));
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
parameters.Add("method", "product.type");
parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
parameters.Add("pageNumber", Convert.ToString(notify.PageNumber));
parameters.Add("pageSize", Convert.ToString(pageSize));
var ignore = new List<string>();
ignore.Add("pageNumber");
ignore.Add("pageSize");
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
if (Constant.IsSuccessful(response))
{
var result = JsonUtils.Deserialize<ListPagerResponse<ProductType>>(response);
if (result.Status == 1)
{
if (CacheProductType(notify.CacheName, result.List, true))
{
//服务端返回的分页信息,用于下一页数据下载
notify.IsPager = result.PageCount > 1;
notify.PageNumber = result.PageNumber;
notify.PageCount = result.PageCount;
notify.PageSize = result.PageSize;
notify.Success = true;
if (result.PageCount > 1)
{
notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips);
}
else
{
notify.Message = string.Format("{0}下载成功......", tips);
}
logger.Info(result.Message);
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductTypeError;
notify.Message = string.Format("缓存{0}发生错误", tips);
logger.Info(notify.Message);
}
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductTypeError;
notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message));
}
}
else
{
string errorMessage = ParseErrors(response);
notify.Success = false;
notify.Operate = DownloadCacheName.ProductTypeError;
notify.Message = errorMessage;
logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage));
}
}
catch (Exception ex)
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductTypeException;
notify.Message = string.Format("{0}下载发生异常", tips);
logger.Error(ex, notify.Message);
}
return notify;
}
public static DownloadNotify DownloadProductTypeNextPage(int pageNum, int pageSize)
{
DownloadNotify notify = new DownloadNotify();
notify.Success = false;
notify.Operate = DownloadCacheName.ProductType;
notify.IsPager = true;
notify.PageNumber = 1;
notify.PageCount = 1;
string tips = "商品分类信息";
try
{
logger.Info(string.Format("下载{0}......", tips));
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
parameters.Add("method", "product.type");
parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
parameters.Add("pageNumber", Convert.ToString(pageNum));
parameters.Add("pageSize", Convert.ToString(pageSize));
var ignore = new List<string>();
ignore.Add("pageNumber");
ignore.Add("pageSize");
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
if (Constant.IsSuccessful(response))
{
var result = JsonUtils.Deserialize<ListPagerResponse<ProductType>>(response);
if (result.Status == 1)
{
if (CacheProductType(notify.CacheName, result.List, false))
{
notify.Success = true;
notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips);
logger.Info(result.Message);
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductTypeError;
notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum);
logger.Info(notify.Message);
}
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductTypeError;
notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message));
}
}
else
{
string errorMessage = ParseErrors(response);
notify.Success = false;
notify.Operate = DownloadCacheName.ProductTypeError;
notify.Message = errorMessage;
logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage));
}
}
catch (Exception ex)
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductTypeException;
notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips);
logger.Error(ex, notify.Message);
}
return notify;
}
/// <summary>
/// 处理下载的菜品类别信息
/// </summary>
/// <param name="notify"></param>
/// <returns></returns>
public static bool CacheProductType(string cacheName, List<ProductType> lists, bool firstPager = true)
{
bool result = false;
string tips = "菜品类别信息";
try
{
//清理数据
if (firstPager)
{
DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_type];", CacheName = cacheName });
}
if (lists.Count() > 0)
{
string template = "insert into [pos_product_type] ([id],[tenantId],[parentId],[no],[name],[path],[color],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}');";
foreach (var entity in lists)
{
if (Global.Instance.StoreInfo != null && entity.TenantId == null)
{
entity.TenantId = Global.Instance.StoreInfo.TenantId;
}
string sql = string.Format(template, entity.Id, entity.TenantId, entity.ParentId, entity.No, entity.Name, entity.Path, entity.Color, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate.ToString("yyyy-MM-dd HH:mm:ss"));
DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName });
}
}
result = true;
}
catch (Exception ex)
{
logger.Error(ex, string.Format("处理{0}发生异常", tips));
result = false;
}
return result;
}
#endregion
#region 商品信息下载
/// <summary>
/// 菜品资料数据下载
/// </summary>
/// <returns></returns>
public static DownloadNotify DownloadProduct(int pageSize)
{
DownloadNotify notify = new DownloadNotify();
notify.Success = false;
notify.Operate = DownloadCacheName.Product;
notify.IsPager = false;
notify.PageNumber = 1;
notify.PageCount = 1;
notify.PageSize = pageSize;
string tips = "商品信息";
try
{
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
parameters.Add("method", "product.list");
parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
parameters.Add("pageNumber", Convert.ToString(notify.PageNumber));
parameters.Add("pageSize", Convert.ToString(pageSize));
var ignore = new List<string>();
ignore.Add("pageNumber");
ignore.Add("pageSize");
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
if (Constant.IsSuccessful(response))
{
var result = JsonUtils.Deserialize<ListPagerResponse<Product>>(response);
if (result.Status == 1)
{
if (CacheProduct(notify.CacheName, result.List, true))
{
//服务端返回的分页信息,用于下一页数据下载
notify.IsPager = result.PageCount > 1;
notify.PageNumber = result.PageNumber;
notify.PageCount = result.PageCount;
notify.PageSize = result.PageSize;
notify.Success = true;
if (result.PageCount > 1)
{
notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips);
}
else
{
notify.Message = string.Format("{0}下载成功......", tips);
}
logger.Info(result.Message);
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductError;
notify.Message = string.Format("缓存{0}发生错误", tips);
logger.Info(notify.Message);
}
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductError;
notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message));
}
}
else
{
string errorMessage = ParseErrors(response);
notify.Success = false;
notify.Operate = DownloadCacheName.ProductError;
notify.Message = errorMessage;
logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage));
}
}
catch (Exception ex)
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductException;
notify.Message = string.Format("{0}下载发生异常", tips);
logger.Error(ex, notify.Message);
}
return notify;
}
public static DownloadNotify DownloadProductNextPage(int pageNum, int pageSize)
{
DownloadNotify notify = new DownloadNotify();
notify.Success = false;
notify.Operate = DownloadCacheName.Product;
notify.IsPager = true;
notify.PageNumber = 1;
notify.PageCount = 1;
string tips = "商品信息";
try
{
logger.Info(string.Format("下载{0}......", tips));
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
parameters.Add("method", "product.list");
parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
parameters.Add("pageNumber", Convert.ToString(pageNum));
parameters.Add("pageSize", Convert.ToString(pageSize));
var ignore = new List<string>();
ignore.Add("pageNumber");
ignore.Add("pageSize");
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
if (Constant.IsSuccessful(response))
{
var result = JsonUtils.Deserialize<ListPagerResponse<Product>>(response);
if (result.Status == 1)
{
if (CacheProduct(notify.CacheName, result.List, false))
{
notify.Success = true;
notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips);
logger.Info(result.Message);
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductError;
notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum);
logger.Info(notify.Message);
}
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductError;
notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message));
}
}
else
{
string errorMessage = ParseErrors(response);
notify.Success = false;
notify.Operate = DownloadCacheName.ProductError;
notify.Message = errorMessage;
logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage));
}
}
catch (Exception ex)
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductException;
notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips);
logger.Error(ex, notify.Message);
}
return notify;
}
/// <summary>
/// 处理下载的商品信息
/// </summary>
/// <param name="notify"></param>
/// <returns></returns>
public static bool CacheProduct(string cacheName, List<Product> lists, bool firstPager = true)
{
bool result = false;
string tips = "商品信息";
try
{
//清理数据
if (firstPager)
{
DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product];", CacheName = cacheName });
}
if (lists.Count() > 0)
{
string template = "insert into [pos_product] ([id],[tenantId],[brandId],[typeId],[typePath],[no],[name],[shortName],[spell],[assistNo],[otherNo],[barCode],[english],[unitId],[price],[memberPrice],[memo],[commissionType],[commissionValue],[discountFlag],[suitFlag],[tapleFlag],[weighFlag],[currentFlag],[labelPrintFlag],[stopFlag],[groupName],[picture],[mebDiscountFlag],[giveFlag],[promotionFlag],[type],[stockFlag],[pointType],[pointValue],[purchaseTax],[saleTax],[lyRate],[costPrice],[purchasePrice],[dispatchPrice],[otherPrice],[specCount],[minPrice],[kdsFlag],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}','{33}','{34}','{35}','{36}','{37}','{38}','{39}','{40}','{41}','{42}','{43}','{44}','{45}','{46}','{47}','{48}','{49}');";
foreach (var entity in lists)
{
string sql = string.Empty;
try
{
sql = string.Format(template, entity.Id, entity.TenantId, entity.BrandId, entity.TypeId, entity.TypePath, entity.No, entity.Name, entity.ShortName, entity.Spell, entity.AssistNo, entity.OtherNo, entity.BarCode, entity.English, entity.UnitId, entity.Price, entity.MemberPrice, entity.Memo, entity.CommissionType, entity.CommissionValue, entity.DiscountFlag, entity.SuitFlag, entity.TapleFlag, entity.WeighFlag, entity.CurrentFlag, entity.LabelPrintFlag, entity.StopFlag, entity.GroupName, entity.Picture, entity.MebDiscountFlag, entity.GiveFlag, entity.PromotionFlag, entity.Type, entity.StockFlag, entity.PointType, entity.PointValue, entity.PurchaseTax, entity.SaleTax, entity.LyRate, entity.CostPrice, entity.PurchasePrice, entity.DispatchPrice, entity.OtherPrice, entity.SpecCount, entity.MinPrice, entity.KdsFlag, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate);
DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName });
}
catch (Exception ex)
{
logger.Info(sql);
logger.Info(ex);
}
}
}
result = true;
}
catch (Exception ex)
{
logger.Error(ex, string.Format("处理{0}发生异常", tips));
result = false;
}
return result;
}
#endregion
#region 获取商品单位信息
/// <summary>
/// 菜品类别数据下载
/// </summary>
/// <returns></returns>
public static DownloadNotify DownloadProductUnit(int pageSize)
{
DownloadNotify notify = new DownloadNotify();
notify.Success = false;
notify.Operate = DownloadCacheName.ProductUnit;
notify.IsPager = false;
notify.PageNumber = 1;
notify.PageCount = 1;
notify.PageSize = pageSize;
string tips = "商品单位信息";
try
{
logger.Info(string.Format("下载{0}......", tips));
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
parameters.Add("method", "product.unit");
parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
parameters.Add("pageNumber", Convert.ToString(notify.PageNumber));
parameters.Add("pageSize", Convert.ToString(pageSize));
var ignore = new List<string>();
ignore.Add("pageNumber");
ignore.Add("pageSize");
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
if (Constant.IsSuccessful(response))
{
var result = JsonUtils.Deserialize<ListPagerResponse<ProductUnit>>(response);
if (result.Status == 1)
{
if (CacheProductUnit(notify.CacheName, result.List, true))
{
//服务端返回的分页信息,用于下一页数据下载
notify.IsPager = result.PageCount > 1;
notify.PageNumber = result.PageNumber;
notify.PageCount = result.PageCount;
notify.PageSize = result.PageSize;
notify.Success = true;
if (result.PageCount > 1)
{
notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips);
}
else
{
notify.Message = string.Format("{0}下载成功......", tips);
}
logger.Info(result.Message);
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductUnitError;
notify.Message = string.Format("缓存{0}发生错误", tips);
logger.Info(notify.Message);
}
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductUnitError;
notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message));
}
}
else
{
string errorMessage = ParseErrors(response);
notify.Success = false;
notify.Operate = DownloadCacheName.ProductUnitError;
notify.Message = errorMessage;
logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage));
}
}
catch (Exception ex)
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductUnitException;
notify.Message = string.Format("{0}下载发生异常", tips);
logger.Error(ex, notify.Message);
}
return notify;
}
public static DownloadNotify DownloadProductUnitNextPage(int pageNum, int pageSize)
{
DownloadNotify notify = new DownloadNotify();
notify.Success = false;
notify.Operate = DownloadCacheName.ProductUnit;
notify.IsPager = true;
notify.PageNumber = 1;
notify.PageCount = 1;
string tips = "商品单位信息";
try
{
logger.Info(string.Format("下载{0}......", tips));
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
parameters.Add("method", "product.unit");
parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
parameters.Add("pageNumber", Convert.ToString(pageNum));
parameters.Add("pageSize", Convert.ToString(pageSize));
var ignore = new List<string>();
ignore.Add("pageNumber");
ignore.Add("pageSize");
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
if (Constant.IsSuccessful(response))
{
var result = JsonUtils.Deserialize<ListPagerResponse<ProductUnit>>(response);
if (result.Status == 1)
{
if (CacheProductUnit(notify.CacheName, result.List, false))
{
notify.Success = true;
notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips);
logger.Info(result.Message);
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductUnitError;
notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum);
logger.Info(notify.Message);
}
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductUnitError;
notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message));
}
}
else
{
string errorMessage = ParseErrors(response);
notify.Success = false;
notify.Operate = DownloadCacheName.ProductUnitError;
notify.Message = errorMessage;
logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage));
}
}
catch (Exception ex)
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductUnitException;
notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips);
logger.Error(ex, notify.Message);
}
return notify;
}
/// <summary>
/// 处理下载的菜品单位信息
/// </summary>
/// <param name="notify"></param>
/// <returns></returns>
public static bool CacheProductUnit(string cacheName, List<ProductUnit> lists, bool firstPager = true)
{
bool result = false;
string tips = "商品单位信息";
try
{
//清理数据
if (firstPager)
{
DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_unit];", CacheName = cacheName });
}
if (lists.Count() > 0)
{
string template = "insert into [pos_product_unit] ([id],[tenantId],[no],[name],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}');";
foreach (var entity in lists)
{
if (Global.Instance.StoreInfo != null && entity.TenantId == null)
{
entity.TenantId = Global.Instance.StoreInfo.TenantId;
}
string sql = string.Format(template, entity.Id, entity.TenantId, entity.No, entity.Name, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate);
DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName });
}
}
result = true;
}
catch (Exception ex)
{
logger.Error(ex, string.Format("处理{0}发生异常", tips));
result = false;
}
return result;
}
#endregion
#region 获取商品规格信息
/// <summary>
/// 菜品类别数据下载
/// </summary>
/// <returns></returns>
public static DownloadNotify DownloadProductSpec(int pageSize)
{
DownloadNotify notify = new DownloadNotify();
notify.Success = false;
notify.Operate = DownloadCacheName.ProductSpec;
notify.IsPager = false;
notify.PageNumber = 1;
notify.PageCount = 1;
notify.PageSize = pageSize;
string tips = "商品规格信息";
try
{
logger.Info(string.Format("下载{0}......", tips));
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
parameters.Add("method", "product.spec");
parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
parameters.Add("pageNumber", Convert.ToString(notify.PageNumber));
parameters.Add("pageSize", Convert.ToString(pageSize));
var ignore = new List<string>();
ignore.Add("pageNumber");
ignore.Add("pageSize");
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
if (Constant.IsSuccessful(response))
{
var result = JsonUtils.Deserialize<ListPagerResponse<ProductSpec>>(response);
if (result.Status == 1)
{
if (CacheProductSpec(notify.CacheName, result.List, true))
{
//服务端返回的分页信息,用于下一页数据下载
notify.IsPager = result.PageCount > 1;
notify.PageNumber = result.PageNumber;
notify.PageCount = result.PageCount;
notify.PageSize = result.PageSize;
notify.Success = true;
if (result.PageCount > 1)
{
notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips);
}
else
{
notify.Message = string.Format("{0}下载成功......", tips);
}
logger.Info(result.Message);
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductSpecError;
notify.Message = string.Format("缓存{0}发生错误", tips);
logger.Info(notify.Message);
}
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductSpecError;
notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message));
}
}
else
{
string errorMessage = ParseErrors(response);
notify.Success = false;
notify.Operate = DownloadCacheName.ProductSpecError;
notify.Message = errorMessage;
logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage));
}
}
catch (Exception ex)
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductSpecException;
notify.Message = string.Format("{0}下载发生异常", tips);
logger.Error(ex, notify.Message);
}
return notify;
}
public static DownloadNotify DownloadProductSpecNextPage(int pageNum, int pageSize)
{
DownloadNotify notify = new DownloadNotify();
notify.Success = false;
notify.Operate = DownloadCacheName.ProductSpec;
notify.IsPager = true;
notify.PageNumber = 1;
notify.PageCount = 1;
string tips = "商品规格信息";
try
{
logger.Info(string.Format("下载{0}......", tips));
OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
parameters.Add("method", "product.spec");
parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
parameters.Add("pageNumber", Convert.ToString(pageNum));
parameters.Add("pageSize", Convert.ToString(pageSize));
var ignore = new List<string>();
ignore.Add("pageNumber");
ignore.Add("pageSize");
parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
if (Constant.IsSuccessful(response))
{
var result = JsonUtils.Deserialize<ListPagerResponse<ProductSpec>>(response);
if (result.Status == 1)
{
if (CacheProductSpec(notify.CacheName, result.List, false))
{
notify.Success = true;
notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips);
logger.Info(result.Message);
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductSpecError;
notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum);
logger.Info(notify.Message);
}
}
else
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductSpecError;
notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message));
}
}
else
{
string errorMessage = ParseErrors(response);
notify.Success = false;
notify.Operate = DownloadCacheName.ProductSpecError;
notify.Message = errorMessage;
logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage));
}
}
catch (Exception ex)
{
notify.Success = false;
notify.Operate = DownloadCacheName.ProductSpecException;
notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips);
logger.Error(ex, notify.Message);
}
return notify;
}
/// <summary>
/// 处理下载的菜品类别信息
/// </summary>
/// <param name="notify"></param>
/// <returns></returns>
public static bool CacheProductSpec(string cacheName, List<ProductSpec> lists, bool firstPager = true)
{
bool result = false;
string tips = "商品规格信息";
try
{
//清理数据
if (firstPager)
{
DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_spec];", CacheName = cacheName });
}
if (lists.Count() > 0)
{
string template = "insert into [pos_product_spec] ([id],[tenantId],[productId],[no],[name],[price],[memberPrice],[otherPrice],[costPrice],[purchasePrice],[dispatchPrice],[materialRate],[isDefault],[minPrice],[deleteFlag],[thUseLevel],[realThUseLevel],[cost],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}');";
foreach (var entity in lists)
{
if (Global.Instance.StoreInfo != null && entity.TenantId == null)
{
entity.TenantId = Global.Instance.StoreInfo.TenantId;
}
string sql = string.Format(template, entity.Id, entity.TenantId, entity.ProductId, entity.No, entity.Name, entity.Price, entity.MemberPrice, entity.OtherPrice, entity.CostPrice, entity.PurchasePrice, entity.DispatchPrice, entity.MaterialRate, entity.IsDefault, entity.MinPrice, entity.DeleteFlag, entity.ThUseLevel, entity.RealThUseLevel, entity.Cost, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate);
DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName });
}
}
result = true;
}
catch (Exception ex)
{
logger.Error(ex, string.Format("处理{0}发生异常", tips));
result = false;
}
return result;
}
#endregion
//#region 获取商品类别信息
///// <summary>
///// 菜品类别数据下载
///// </summary>
///// <returns></returns>
//public static DownloadNotify DownloadProductType(int pageSize)
//{
// DownloadNotify notify = new DownloadNotify();
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductType;
// notify.IsPager = false;
// notify.PageNumber = 1;
// notify.PageCount = 1;
// notify.PageSize = pageSize;
// string tips = "商品类别信息";
// try
// {
// logger.Info(string.Format("下载{0}......", tips));
// OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
// SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
// parameters.Add("method", "product.type");
// parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
// parameters.Add("pageNumber", Convert.ToString(notify.PageNumber));
// parameters.Add("pageSize", Convert.ToString(pageSize));
// var ignore = new List<string>();
// ignore.Add("pageNumber");
// ignore.Add("pageSize");
// parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
// string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
// if (Constant.IsSuccessful(response))
// {
// var result = JsonUtils.Deserialize<ListPagerResponse<ProductType>>(response);
// if (result.Status == 1)
// {
// //服务端返回的分页信息,用于下一页数据下载
// notify.IsPager = result.PageCount > 1;
// notify.PageNumber = result.PageNumber;
// notify.PageCount = result.PageCount;
// notify.PageSize = result.PageSize;
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// if (db.CollectionExists(notify.CacheName))
// {
// db.DropCollection(notify.CacheName);
// }
// var table = db.GetCollection<ProductType>(notify.CacheName);
// table.Insert(result.List);
// }
// }
// notify.Success = true;
// if (result.PageCount > 1)
// {
// notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips);
// }
// else
// {
// notify.Message = string.Format("{0}下载成功......", tips);
// }
// logger.Info(result.Message);
// }
// else
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductTypeError;
// notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
// logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message));
// }
// }
// else
// {
// string errorMessage = ParseErrors(response);
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductTypeError;
// notify.Message = errorMessage;
// logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage));
// }
// }
// catch (Exception ex)
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductTypeException;
// notify.Message = string.Format("{0}下载发生异常", tips);
// logger.Error(ex, notify.Message);
// }
// return notify;
//}
//public static DownloadNotify DownloadProductTypeNextPage(int pageNum, int pageSize)
//{
// DownloadNotify notify = new DownloadNotify();
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductType;
// notify.IsPager = true;
// notify.PageNumber = 1;
// notify.PageCount = 1;
// string tips = "商品分类信息";
// try
// {
// logger.Info(string.Format("下载{0}......", tips));
// OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
// SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
// parameters.Add("method", "product.type");
// parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
// parameters.Add("pageNumber", Convert.ToString(pageNum));
// parameters.Add("pageSize", Convert.ToString(pageSize));
// var ignore = new List<string>();
// ignore.Add("pageNumber");
// ignore.Add("pageSize");
// parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
// string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
// if (Constant.IsSuccessful(response))
// {
// var result = JsonUtils.Deserialize<ListPagerResponse<ProductType>>(response);
// if (result.Status == 1)
// {
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// if (db.CollectionExists(notify.CacheName))
// {
// db.DropCollection(notify.CacheName);
// }
// var table = db.GetCollection<ProductType>(notify.CacheName);
// table.Insert(result.List);
// }
// }
// notify.Success = true;
// notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips);
// logger.Info(result.Message);
// }
// else
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductTypeError;
// notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
// logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message));
// }
// }
// else
// {
// string errorMessage = ParseErrors(response);
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductTypeError;
// notify.Message = errorMessage;
// logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage));
// }
// }
// catch (Exception ex)
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductTypeException;
// notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips);
// logger.Error(ex, notify.Message);
// }
// return notify;
//}
///// <summary>
///// 处理下载的菜品类别信息
///// </summary>
///// <param name="notify"></param>
///// <returns></returns>
//public static bool CacheProductType(string cacheName, List<ProductType> lists, bool firstPager = true)
//{
// bool result = false;
// string tips = "菜品类别信息";
// try
// {
// //清理数据
// if (firstPager)
// {
// DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_type];", CacheName = cacheName });
// }
// if (lists.Count() > 0)
// {
// string template = "insert into [pos_product_type] ([id],[tenantId],[parentId],[no],[name],[path],[color],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}');";
// foreach (var entity in lists)
// {
// if (Global.Instance.StoreInfo.TenantId != null && entity.TenantId == null)
// {
// entity.TenantId = Global.Instance.StoreInfo.TenantId;
// }
// string sql = string.Format(template, entity.Id, entity.TenantId, entity.ParentId, entity.No, entity.Name, entity.Path, entity.Color, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate);
// DownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName });
// }
// }
// result = true;
// }
// catch (Exception ex)
// {
// logger.Error(ex, string.Format("处理{0}发生异常", tips));
// result = false;
// }
// return result;
//}
//#endregion
//#region 商品信息下载
///// <summary>
///// 菜品资料数据下载
///// </summary>
///// <returns></returns>
//public static DownloadNotify DownloadProduct(int pageSize)
//{
// DownloadNotify notify = new DownloadNotify();
// notify.Success = false;
// notify.Operate = DownloadCacheName.Product;
// notify.IsPager = false;
// notify.PageNumber = 1;
// notify.PageCount = 1;
// notify.PageSize = pageSize;
// string tips = "商品信息";
// try
// {
// OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
// SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
// parameters.Add("method", "product.list");
// parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
// parameters.Add("pageNumber", Convert.ToString(notify.PageNumber));
// parameters.Add("pageSize", Convert.ToString(pageSize));
// var ignore = new List<string>();
// ignore.Add("pageNumber");
// ignore.Add("pageSize");
// parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
// string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
// if (Constant.IsSuccessful(response))
// {
// var result = JsonUtils.Deserialize<ListPagerResponse<Product>>(response);
// if (result.Status == 1)
// {
// //服务端返回的分页信息,用于下一页数据下载
// notify.IsPager = result.PageCount > 1;
// notify.PageNumber = result.PageNumber;
// notify.PageCount = result.PageCount;
// notify.PageSize = result.PageSize;
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// if (db.CollectionExists(notify.CacheName))
// {
// db.DropCollection(notify.CacheName);
// }
// var table = db.GetCollection<Product>(notify.CacheName);
// table.Insert(result.List);
// }
// }
// notify.Success = true;
// if (result.PageCount > 1)
// {
// notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips);
// }
// else
// {
// notify.Message = string.Format("{0}下载成功......", tips);
// }
// logger.Info(result.Message);
// }
// else
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductError;
// notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
// logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message));
// }
// }
// else
// {
// string errorMessage = ParseErrors(response);
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductError;
// notify.Message = errorMessage;
// logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage));
// }
// }
// catch (Exception ex)
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductException;
// notify.Message = string.Format("{0}下载发生异常", tips);
// logger.Error(ex, notify.Message);
// }
// return notify;
//}
//public static DownloadNotify DownloadProductNextPage(int pageNum, int pageSize)
//{
// DownloadNotify notify = new DownloadNotify();
// notify.Success = false;
// notify.Operate = DownloadCacheName.Product;
// notify.IsPager = true;
// notify.PageNumber = 1;
// notify.PageCount = 1;
// string tips = "商品信息";
// try
// {
// logger.Info(string.Format("下载{0}......", tips));
// OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
// SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
// parameters.Add("method", "product.list");
// parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
// parameters.Add("pageNumber", Convert.ToString(pageNum));
// parameters.Add("pageSize", Convert.ToString(pageSize));
// var ignore = new List<string>();
// ignore.Add("pageNumber");
// ignore.Add("pageSize");
// parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
// string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
// if (Constant.IsSuccessful(response))
// {
// var result = JsonUtils.Deserialize<ListPagerResponse<Product>>(response);
// if (result.Status == 1)
// {
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// if (db.CollectionExists(notify.CacheName))
// {
// db.DropCollection(notify.CacheName);
// }
// var table = db.GetCollection<Product>(notify.CacheName);
// table.Insert(result.List);
// }
// }
// notify.Success = true;
// notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips);
// logger.Info(result.Message);
// }
// else
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductError;
// notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
// logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message));
// }
// }
// else
// {
// string errorMessage = ParseErrors(response);
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductError;
// notify.Message = errorMessage;
// logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage));
// }
// }
// catch (Exception ex)
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductException;
// notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips);
// logger.Error(ex, notify.Message);
// }
// return notify;
//}
///// <summary>
///// 处理下载的商品信息
///// </summary>
///// <param name="notify"></param>
///// <returns></returns>
//public static bool CacheProduct(DownloadNotify notify)
//{
// bool result = false;
// string tips = "商品信息";
// try
// {
// string template = "insert into [pos_product] ([id],[tenantId],[brandId],[typeId],[typePath],[no],[name],[shortName],[spell],[assistNo],[otherNo],[barCode],[english],[unitId],[price],[memberPrice],[memo],[commissionType],[commissionValue],[discountFlag],[suitFlag],[tapleFlag],[weighFlag],[currentFlag],[labelPrintFlag],[stopFlag],[groupName],[picture],[mebDiscountFlag],[giveFlag],[promotionFlag],[type],[stockFlag],[pointType],[pointValue],[purchaseTax],[saleTax],[lyRate],[costPrice],[purchasePrice],[dispatchPrice],[otherPrice],[specCount],[minPrice],[kdsFlag],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}','{33}','{34}','{35}','{36}','{37}','{38}','{39}','{40}','{41}','{42}','{43}','{44}','{45}','{46}','{47}','{48}','{49}');";
// var list = new ConcurrentQueue<DownloadSqlCache>();
// //记录本次更新的条数
// int counts = 0;
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// list.Enqueue(new DownloadSqlCache { Sql = "delete from [pos_product];", CacheName = notify.CacheName });
// var table = db.GetCollection<Product>(notify.CacheName);
// if (table.Count() > 0)
// {
// var lists = table.FindAll();
// foreach (var entity in lists)
// {
// string sql = string.Format(template, entity.Id, entity.TenantId, entity.BrandId, entity.TypeId, entity.TypePath, entity.No, entity.Name, entity.ShortName, entity.Spell, entity.AssistNo, entity.OtherNo, entity.BarCode, entity.English, entity.UnitId, entity.Price, entity.MemberPrice, entity.Memo, entity.CommissionType, entity.CommissionValue, entity.DiscountFlag, entity.SuitFlag, entity.TapleFlag, entity.WeighFlag, entity.CurrentFlag, entity.LabelPrintFlag, entity.StopFlag, entity.GroupName, entity.Picture, entity.MebDiscountFlag, entity.GiveFlag, entity.PromotionFlag, entity.Type, entity.StockFlag, entity.PointType, entity.PointValue, entity.PurchaseTax, entity.SaleTax, entity.LyRate, entity.CostPrice, entity.PurchasePrice, entity.DispatchPrice, entity.OtherPrice, entity.SpecCount, entity.MinPrice, entity.KdsFlag, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate);
// list.Enqueue(new DownloadSqlCache { Sql = sql, CacheName = notify.CacheName });
// Interlocked.Increment(ref counts);
// }
// }
// CacheSql(list);
// }
// }
// result = true;
// }
// catch (Exception ex)
// {
// logger.Error(ex, string.Format("处理{0}发生异常", tips));
// result = false;
// }
// return result;
//}
//#endregion
//#region 获取商品单位信息
///// <summary>
///// 商品单位信息数据下载
///// </summary>
///// <returns></returns>
//public static DownloadNotify DownloadProductUnit(int pageSize)
//{
// DownloadNotify notify = new DownloadNotify();
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductUnit;
// notify.IsPager = false;
// notify.PageNumber = 1;
// notify.PageCount = 1;
// notify.PageSize = pageSize;
// string tips = "商品单位信息";
// try
// {
// OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
// SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
// parameters.Add("method", "product.unit");
// parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
// parameters.Add("pageNumber", Convert.ToString(notify.PageNumber));
// parameters.Add("pageSize", Convert.ToString(pageSize));
// var ignore = new List<string>();
// ignore.Add("pageNumber");
// ignore.Add("pageSize");
// parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
// string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
// if (Constant.IsSuccessful(response))
// {
// var result = JsonUtils.Deserialize<ListPagerResponse<ProductUnit>>(response);
// if (result.Status == 1)
// {
// //服务端返回的分页信息,用于下一页数据下载
// notify.IsPager = result.PageCount > 1;
// notify.PageNumber = result.PageNumber;
// notify.PageCount = result.PageCount;
// notify.PageSize = result.PageSize;
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// if (db.CollectionExists(notify.CacheName))
// {
// db.DropCollection(notify.CacheName);
// }
// var table = db.GetCollection<ProductUnit>(notify.CacheName);
// table.Insert(result.List);
// }
// }
// notify.Success = true;
// if (result.PageCount > 1)
// {
// notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips);
// }
// else
// {
// notify.Message = string.Format("{0}下载成功......", tips);
// }
// logger.Info(result.Message);
// }
// else
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductUnitError;
// notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
// logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message));
// }
// }
// else
// {
// string errorMessage = ParseErrors(response);
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductUnitError;
// notify.Message = errorMessage;
// logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage));
// }
// }
// catch (Exception ex)
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductUnitException;
// notify.Message = string.Format("{0}下载发生异常", tips);
// logger.Error(ex, notify.Message);
// }
// return notify;
//}
//public static DownloadNotify DownloadProductUnitNextPage(int pageNum, int pageSize)
//{
// DownloadNotify notify = new DownloadNotify();
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductUnit;
// notify.IsPager = true;
// notify.PageNumber = 1;
// notify.PageCount = 1;
// string tips = "商品单位信息";
// try
// {
// logger.Info(string.Format("下载{0}......", tips));
// OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
// SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
// parameters.Add("method", "product.unit");
// parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
// parameters.Add("pageNumber", Convert.ToString(pageNum));
// parameters.Add("pageSize", Convert.ToString(pageSize));
// var ignore = new List<string>();
// ignore.Add("pageNumber");
// ignore.Add("pageSize");
// parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
// string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
// if (Constant.IsSuccessful(response))
// {
// var result = JsonUtils.Deserialize<ListPagerResponse<ProductUnit>>(response);
// if (result.Status == 1)
// {
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// if (db.CollectionExists(notify.CacheName))
// {
// db.DropCollection(notify.CacheName);
// }
// var table = db.GetCollection<ProductUnit>(notify.CacheName);
// table.Insert(result.List);
// }
// }
// notify.Success = true;
// notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips);
// logger.Info(result.Message);
// }
// else
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductUnitError;
// notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
// logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message));
// }
// }
// else
// {
// string errorMessage = ParseErrors(response);
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductUnitError;
// notify.Message = errorMessage;
// logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage));
// }
// }
// catch (Exception ex)
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductUnitException;
// notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips);
// logger.Error(ex, notify.Message);
// }
// return notify;
//}
///// <summary>
///// 处理下载的商品单位信息
///// </summary>
///// <param name="notify"></param>
///// <returns></returns>
//public static bool CacheProductUnit(DownloadNotify notify)
//{
// bool result = false;
// string tips = "商品单位信息";
// try
// {
// string template = "insert into [pos_product_unit] ([id],[tenantId],[no],[name],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}');";
// var list = new ConcurrentQueue<DownloadSqlCache>();
// //记录本次更新的条数
// int counts = 0;
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// list.Enqueue(new DownloadSqlCache { Sql = "delete from [pos_product_unit];", CacheName = notify.CacheName });
// var table = db.GetCollection<ProductUnit>(notify.CacheName);
// if (table.Count() > 0)
// {
// var lists = table.FindAll();
// foreach (var entity in lists)
// {
// string sql = string.Format(template, entity.Id, entity.TenantId, entity.No, entity.Name, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate);
// list.Enqueue(new DownloadSqlCache { Sql = sql, CacheName = notify.CacheName });
// Interlocked.Increment(ref counts);
// }
// }
// CacheSql(list);
// }
// }
// result = true;
// }
// catch (Exception ex)
// {
// logger.Error(ex, string.Format("处理{0}发生异常", tips));
// result = false;
// }
// return result;
//}
//#endregion
//#region 获取商品规格信息
///// <summary>
///// 商品规格信息数据下载
///// </summary>
///// <returns></returns>
//public static DownloadNotify DownloadProductSpec(int pageSize)
//{
// DownloadNotify notify = new DownloadNotify();
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductSpec;
// notify.IsPager = false;
// notify.PageNumber = 1;
// notify.PageCount = 1;
// notify.PageSize = pageSize;
// string tips = "商品规格信息";
// try
// {
// OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
// SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
// parameters.Add("method", "product.spec");
// parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
// parameters.Add("pageNumber", Convert.ToString(notify.PageNumber));
// parameters.Add("pageSize", Convert.ToString(pageSize));
// var ignore = new List<string>();
// ignore.Add("pageNumber");
// ignore.Add("pageSize");
// parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
// string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
// if (Constant.IsSuccessful(response))
// {
// var result = JsonUtils.Deserialize<ListPagerResponse<ProductSpec>>(response);
// if (result.Status == 1)
// {
// //服务端返回的分页信息,用于下一页数据下载
// notify.IsPager = result.PageCount > 1;
// notify.PageNumber = result.PageNumber;
// notify.PageCount = result.PageCount;
// notify.PageSize = result.PageSize;
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// if (db.CollectionExists(notify.CacheName))
// {
// db.DropCollection(notify.CacheName);
// }
// var table = db.GetCollection<ProductSpec>(notify.CacheName);
// table.Insert(result.List);
// }
// }
// notify.Success = true;
// if (result.PageCount > 1)
// {
// notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips);
// }
// else
// {
// notify.Message = string.Format("{0}下载成功......", tips);
// }
// logger.Info(result.Message);
// }
// else
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductSpecError;
// notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
// logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message));
// }
// }
// else
// {
// string errorMessage = ParseErrors(response);
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductSpecError;
// notify.Message = errorMessage;
// logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage));
// }
// }
// catch (Exception ex)
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductSpecException;
// notify.Message = string.Format("{0}下载发生异常", tips);
// logger.Error(ex, notify.Message);
// }
// return notify;
//}
//public static DownloadNotify DownloadProductSpecNextPage(int pageNum, int pageSize)
//{
// DownloadNotify notify = new DownloadNotify();
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductSpec;
// notify.IsPager = true;
// notify.PageNumber = 1;
// notify.PageCount = 1;
// string tips = "商品规格信息";
// try
// {
// logger.Info(string.Format("下载{0}......", tips));
// OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business);
// SortedList<string, string> parameters = OpenApiUtils.Instance.NewParameters(api);
// parameters.Add("method", "product.spec");
// parameters.Add("storeId", Global.Instance.StoreInfo.StoreId);
// parameters.Add("pageNumber", Convert.ToString(pageNum));
// parameters.Add("pageSize", Convert.ToString(pageSize));
// var ignore = new List<string>();
// ignore.Add("pageNumber");
// ignore.Add("pageSize");
// parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters, ignore));
// string response = HttpClientUtils.PostAsync(api, api.Url, parameters);
// if (Constant.IsSuccessful(response))
// {
// var result = JsonUtils.Deserialize<ListPagerResponse<ProductSpec>>(response);
// if (result.Status == 1)
// {
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// if (db.CollectionExists(notify.CacheName))
// {
// db.DropCollection(notify.CacheName);
// }
// var table = db.GetCollection<ProductSpec>(notify.CacheName);
// table.Insert(result.List);
// }
// }
// notify.Success = true;
// notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips);
// logger.Info(result.Message);
// }
// else
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductSpecError;
// notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage);
// logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message));
// }
// }
// else
// {
// string errorMessage = ParseErrors(response);
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductSpecError;
// notify.Message = errorMessage;
// logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage));
// }
// }
// catch (Exception ex)
// {
// notify.Success = false;
// notify.Operate = DownloadCacheName.ProductSpecException;
// notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips);
// logger.Error(ex, notify.Message);
// }
// return notify;
//}
///// <summary>
///// 处理下载的商品规格信息
///// </summary>
///// <param name="notify"></param>
///// <returns></returns>
//public static bool CacheProductSpec(DownloadNotify notify)
//{
// bool result = false;
// string tips = "商品规格信息";
// try
// {
// string template = "insert into [pos_product_spec] ([id],[tenantId],[productId],[no],[name],[price],[memberPrice],[otherPrice],[costPrice],[purchasePrice],[dispatchPrice],[materialRate],[isDefault],[minPrice],[deleteFlag],[thUseLevel],[realThUseLevel],[cost],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}');";
// var list = new ConcurrentQueue<DownloadSqlCache>();
// //记录本次更新的条数
// int counts = 0;
// lock (Global.Instance.SyncLiteLock)
// {
// using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
// {
// list.Enqueue(new DownloadSqlCache { Sql = "delete from [pos_product_spec];", CacheName = notify.CacheName });
// var table = db.GetCollection<ProductSpec>(notify.CacheName);
// if (table.Count() > 0)
// {
// var lists = table.FindAll();
// foreach (var entity in lists)
// {
// string sql = string.Format(template, entity.Id, entity.TenantId, entity.ProductId, entity.No, entity.Name, entity.Price, entity.MemberPrice, entity.OtherPrice, entity.CostPrice, entity.PurchasePrice, entity.DispatchPrice, entity.MaterialRate, entity.IsDefault, entity.MinPrice, entity.DeleteFlag, entity.ThUseLevel, entity.RealThUseLevel, entity.Cost, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate);
// list.Enqueue(new DownloadSqlCache { Sql = sql, CacheName = notify.CacheName });
// Interlocked.Increment(ref counts);
// }
// }
// CacheSql(list);
// }
// }
// result = true;
// }
// catch (Exception ex)
// {
// logger.Error(ex, string.Format("处理{0}发生异常", tips));
// result = false;
// }
// return result;
//}
//#endregion
private static void CacheSql(ConcurrentQueue<DownloadSqlCache> list)
{
lock (Global.Instance.SyncLiteLock)
{
using (var db = new LiteDatabase(Global.Instance.CacheFullPath))
{
var table = db.GetCollection<DownloadSqlCache>(SQL_CACHE_NAME);
table.Insert(list);
}
}
}
}
}