using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using POSV.Entity; using POSV.HttpResponse; using POSV.Utils; using POSV.Entity.Pormotion; using POSV.ShoppingCart; namespace POSV.HttpApi { public class DownloadApi : BaseApi { protected static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); #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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "worker.list"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(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; } /// /// 处理下载的操作员数据 /// /// /// public static bool CacheWorker(DownloadNotify notify) { bool result = false; string tips = "门店操作员"; try { 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}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_worker];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { 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); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 员工角色(折扣免单权限)列表下载>>>> /// /// 员工角色(折扣免单权限)列表 /// /// public static DownloadNotify DownloadWorkerRole(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.WorkerRole; notify.IsPager = false; notify.PageNumber = 1; notify.PageCount = 1; notify.PageSize = pageSize; string tips = "员工角色"; try { OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business); SortedList parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "worker.posrole"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (string.IsNullOrEmpty(o.Id)) { o.Id = IdWorkerUtils.Instance.NextId(); } if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.WorkerRoleError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.WorkerRoleError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.WorkerRoleException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadWorkerRoleNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.WorkerRole; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "worker.posrole"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (string.IsNullOrEmpty(o.Id)) { o.Id = IdWorkerUtils.Instance.NextId(); } if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.WorkerRoleError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.WorkerRoleError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.WorkerRoleException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的信息 /// /// /// public static bool CacheWorkerRole(DownloadNotify notify) { bool result = false; string tips = "员工角色"; try { string template = "insert into [pos_worker_role] ([id],[tenantId],[storeId],[workerId],[roleId],[discount],[free],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_worker_role];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.StoreId, entity.WorkerId, entity.RoleId, entity.Discount, entity.Free, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 模块权限列表>>>> /// /// 模块权限列表 /// /// public static DownloadNotify DownloadWorkerPermissions(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.WorkerPermissions; notify.IsPager = false; notify.PageNumber = 1; notify.PageCount = 1; notify.PageSize = pageSize; string tips = "模块权限"; try { OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business); SortedList parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "worker.posmodule"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (string.IsNullOrEmpty(o.Id)) { o.Id = IdWorkerUtils.Instance.NextId(); } if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.WorkerPermissionsError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.WorkerPermissionsError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.WorkerPermissionsException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadWorkerPermissionsNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.WorkerPermissions; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "worker.posmodule"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (string.IsNullOrEmpty(o.Id)) { o.Id = IdWorkerUtils.Instance.NextId(); } if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.WorkerPermissionsError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.WorkerPermissionsError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.WorkerPermissionsException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的信息 /// /// /// public static bool CacheWorkerPermissions(DownloadNotify notify) { bool result = false; string tips = "员工角色"; try { string template = "insert into [pos_worker_permissions] ([id],[tenantId],[storeId],[workerId],[moduleNo],[ext1],[ext2],[ext3],[createUser],[createDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_worker_permissions];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.StoreId, entity.WorkerId, entity.ModuleNo, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取门店营业方案>>>> /// /// 门店营业方案数据下载 /// /// public static DownloadNotify DownloadBusinessPlan() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.BusinessPlan; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.businessplan"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { if (Global.Instance.Authc != null && result.Data.TenantId == null) { result.Data.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(result.Data); box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.BusinessPlanError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.BusinessPlanError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.BusinessPlanException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的门店营业方案 /// /// /// public static bool CacheBusinessPlan(DownloadNotify notify) { bool result = false; string tips = "门店营业方案"; try { string template = "insert into [pos_business_plan] ([id],[tenantId],[no],[name],[startType],[startTime],[endType],[endTime],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_business_plan];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.No, entity.Name, entity.StartType, entity.StartTime, entity.EndType, entity.EndTime, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取商品类别信息>>>> /// /// 菜品类别数据下载 /// /// 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.type"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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 = PaserErrors(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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.type"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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 = PaserErrors(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; } /// /// 处理下载的菜品类别信息 /// /// /// public static bool CacheProductType(DownloadNotify notify) { bool result = false; string tips = "菜品类别信息"; try { 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}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_type];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { 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); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 商品信息下载>>>> /// /// 菜品资料数据下载 /// /// 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.list"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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 = PaserErrors(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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.list"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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 = PaserErrors(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; } /// /// 处理下载的商品信息 /// /// /// 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],[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}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { 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.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取商品单位信息>>>> /// /// 菜品类别数据下载 /// /// 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.unit"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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 = PaserErrors(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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.unit"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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 = PaserErrors(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; } /// /// 处理下载的菜品类别信息 /// /// /// 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(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_unit];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { 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 { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取商品图片信息>>>> /// /// 菜品类别数据下载 /// /// public static DownloadNotify DownloadProductImage(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductImage; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.image"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.ProductImageError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductImageError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductImageException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadProductImageNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductImage; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.image"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductImageError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductImageError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductImageException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的菜品类别信息 /// /// /// public static bool CacheProductImage(DownloadNotify notify) { bool result = false; string tips = "商品图片信息"; try { string template = "insert into [pos_product_image] ([id],[tenantId],[productId],[width],[height],[groupName],[storageFileName],[length],[mimeType],[orderNo],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_image];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.ProductId, entity.Width, entity.Height, entity.GroupName, entity.StorageFileName, entity.Length, entity.MimeType, entity.OrderNo, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店仓库>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadStoreStorage() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.StoreStorage; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.storage"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.StoreStorageError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.StoreStorageError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.StoreStorageException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheStoreStorage(DownloadNotify notify) { bool result = false; string tips = "付款类型"; try { string template = "insert into [pos_store_storage] ([id],[tenantId],[no],[name],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_store_storage];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.No, entity.Name, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取商品库存系数信息>>>> /// /// 商品库存系数数据下载 /// /// public static DownloadNotify DownloadProductRatio(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductRatio; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.ratio"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.ProductRatioError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductRatioError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductRatioException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadProductRatioNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductRatio; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.ratio"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductRatioError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductRatioError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductRatioException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的商品库存系数信息 /// /// public static bool CacheProductRatio(DownloadNotify notify) { bool result = false; string tips = "商品库存系数信息"; try { string template = "insert into [pos_product_ratio] ([id],[tenantId],[productId],[dispatchUnitId],[purchaseUnitId],[pdScale],[packUnitId],[dpScale],[salesUnitId],[psScale],[maxStock],[minStock],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_ratio];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.ProductId, entity.DispatchUnitId, entity.PurchaseUnitId, entity.PdScale, entity.PackUnitId, entity.DpScale, entity.SalesUnitId, entity.PsScale, entity.MaxStock, entity.MinStock, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取门店商品库存信息>>>> /// /// 商品库存数据下载 /// /// public static DownloadNotify DownloadProductStock(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductStock; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.product.stock"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.ProductStockError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductStockError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductStockException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadProductStockNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductStock; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.product.stock"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductStockError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductStockError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductStockException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的商品库存信息 /// /// public static bool CacheProductStock(DownloadNotify notify) { bool result = false; string tips = "商品库存信息"; try { string template = "insert into [pos_product_stock] ([id],[tenantId],[storeId],[storageId],[storageName],[productId],[productNo],[productName],[specId],[specName],[productDescription],[dispatchUnitId],[dispatchUnitName],[packUnitId],[packUnitName],[stockAmount],[stockCost],[type],[typeId],[typeName],[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}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_stock];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.StoreId, entity.StorageId, entity.StorageName, entity.ProductId, entity.ProductNo, entity.ProductName, entity.SpecId, entity.SpecName, entity.ProductDescription, entity.DispatchUnitId, entity.DispatchUnitName, entity.PackUnitId, entity.PackUnitName, entity.StockAmount, entity.StockCost, entity.Type, entity.TypeId, entity.TypeName, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 营业日方案班次下载>>>>> /// /// 操作员数据下载 /// /// public static DownloadNotify DownloadBusinessPlanDetail() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.BusinessPlanDetail; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.businessplan.detail"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.BusinessPlanDetailError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.BusinessPlanDetailError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.BusinessPlanDetailException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的操作员数据 /// /// /// public static bool CacheBusinessPlanDetail(DownloadNotify notify) { bool result = false; string tips = "门店操作员"; try { string template = "insert into [pos_business_plandetail] ([id],[tenantId],[planId],[name],[startType],[startTime],[endType],[endTime],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_business_plandetail];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.PlanId, entity.Name, entity.StartType, entity.StartTime, entity.EndType, entity.EndTime, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取商品规格信息>>>> /// /// 菜品类别数据下载 /// /// 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.spec"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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 = PaserErrors(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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.spec"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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 = PaserErrors(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; } /// /// 处理下载的菜品类别信息 /// /// /// 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],[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}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_spec];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { 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.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 付款类型下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadPayType() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.PayType; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.paytype"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.PayTypeError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.PayTypeError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.PayTypeException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CachePayType(DownloadNotify notify) { bool result = false; string tips = "付款类型"; try { string template = "insert into [pos_paytype] ([id],[tenantId],[name],[no],[sign],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_paytype];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.Name, entity.No, entity.Sign, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 收银方式下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadPayMode() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.PayMode; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.paymode"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.PayModeError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.PayModeError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.PayModeException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CachePayMode(DownloadNotify notify) { bool result = false; string tips = "收银方式"; try { string template = "insert into [pos_paymode] ([id],[tenantId],[name],[no],[typeId],[shortcut],[pointFlag],[frontFlag],[rechargeFlag],[discount],[fixeAmount],[pbody],[certText],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_paymode];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.Name, entity.No, entity.TypeId, entity.Shortcut, entity.PointFlag, entity.FrontFlag, entity.RechargeFlag, entity.Discount, entity.FixeAmount, JsonUtils.Serialize(entity.Body),entity.CertText, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 餐桌区域下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadTableArea() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.TableArea; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.table.area"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.TableAreaError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.TableAreaError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.TableAreaException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheTableArea(DownloadNotify notify) { bool result = false; string tips = "餐桌区域"; try { string template = "insert into [pos_tablearea] ([id],[tenantId],[name],[no],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_tablearea];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.Name, entity.No, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 餐桌类型下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadTableType() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.TableType; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.table.type"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.TableTypeError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.TableTypeError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.TableTypeException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheTableType(DownloadNotify notify) { bool result = false; string tips = "餐桌类型"; try { string template = "insert into [pos_tabletype] ([id],[tenantId],[name],[no],[color],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_tabletype];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.Name, entity.No, entity.Color, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 餐桌信息下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadTable() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.Table; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.table"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.TableError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.TableError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.TableException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheTable(DownloadNotify notify) { bool result = false; string tips = "餐桌信息"; try { string template = "insert into [pos_table] ([id],[tenantId],[name],[no],[storeId],[areaId],[typeId],[number],[ext1],[ext2],[ext3],[createUser],[createDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_table];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.Name, entity.No, entity.StoreId, entity.AreaId, entity.TypeId, entity.Number, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店品牌下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadBrand() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.Brand; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.brand"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.BrandError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.BrandError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.BrandException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheBrand(DownloadNotify notify) { bool result = false; string tips = "门店品牌"; try { string template = "insert into [pos_brand] ([id],[tenantId],[name],[no],[memo],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_brand];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.Name, entity.No, entity.Memo, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 做法类型数据下载>>>> /// /// 操作员数据下载 /// /// public static DownloadNotify DownloadProductMakeType() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeType; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.maketype"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeTypeError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeTypeError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeTypeException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的做法类型数据 /// /// /// public static bool CacheProductMakeType(DownloadNotify notify) { bool result = false; string tips = "做法类型"; try { string template = "insert into [pos_product_maketype] ([id],[tenantId],[no],[name],[type],[isRadio],[seqNo],[color],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_maketype];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.No, entity.Name, entity.Type, entity.IsRadio, entity.SeqNo, entity.Color, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 做法信息数据下载>>>> /// /// 操作员数据下载 /// /// public static DownloadNotify DownloadProductMakeDetail() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetail; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.makedetail"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的做法类型数据 /// /// /// public static bool CacheProductMakeDetail(DownloadNotify notify) { bool result = false; string tips = "做法信息"; try { string template = "insert into [pos_product_makedetail] ([id],[tenantId],[no],[spell],[typeId],[addPrice],[qtyFlag],[memo],[orderNo],[color],[prvFlag],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_makedetail];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.No, entity.Spell, entity.TypeId, entity.AddPrice, entity.QtyFlag, entity.Memo, entity.OrderNo, entity.Color,entity.PrvFlag, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 商品私有做法信息下载>>>> /// /// 商品私有做法数据下载 /// /// public static DownloadNotify DownloadProductMakeDetailPrivate(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailPrivate; notify.IsPager = false; notify.PageNumber = 1; notify.PageCount = 1; notify.PageSize = pageSize; string tips = "商品私有做法信息"; try { OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business); SortedList parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.private.makedetail"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } if (string.IsNullOrEmpty(o.Id)) { o.Id = IdWorkerUtils.Instance.NextId(); } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.ProductMakeDetailPrivateError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailPrivateError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailPrivateException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadProductMakeDetailPrivateNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailPrivate; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.private.makedetail"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } if (string.IsNullOrEmpty(o.Id)) { o.Id = IdWorkerUtils.Instance.NextId(); } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailPrivateError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailPrivateError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailPrivateException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的商品私有做法信息 /// /// /// public static bool CacheProductMakeDetailPrivate(DownloadNotify notify) { bool result = false; string tips = "商品私有做法信息"; try { string template = "INSERT INTO [pos_product_makedetail_private] ([id], [tenantId], [productId], [makeId], [no], [spell], [typeId], [addPrice], [qtyFlag], [memo], [orderNo], [color], [ext1], [ext3], [ext2], [createUser], [createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_makedetail_private];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.ProductId, entity.MakeId, entity.No, entity.Spell, entity.TypeId, entity.AddPrice, entity.QtyFlag, entity.Memo, entity.OrderNo, entity.Color, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取套菜资料信息>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadProductSuit(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductSuit; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.suit"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.ProductSuitError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadProductSuitNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductSuit; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.suit"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的菜品类别信息 /// /// /// public static bool CacheProductSuit(DownloadNotify notify) { bool result = false; string tips = "套菜资料"; try { string template = "insert into [pos_product_suit] ([id],[tenantId],[no],[productId],[name],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_suit];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.No, entity.ProductId, entity.Name, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取套菜明细信息>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadProductSuitDetail(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitDetail; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.suit.detail"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.ProductSuitDetailError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitDetailError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitDetailException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadProductSuitDetailNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitDetail; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "product.suit.detail"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitDetailError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitDetailError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitDetailException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的菜品类别信息 /// /// /// public static bool CacheProductSuitDetail(DownloadNotify notify) { bool result = false; string tips = "套菜资料"; try { string template = "insert into [pos_product_suitdetail] ([id],[tenantId],[suitId],[suitProductId],[productId],[specId],[quantity],[addPrice],[defaultFlag],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_suitdetail];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.SuitId, entity.SuitProductId, entity.ProductId, entity.SpecId, entity.Quantity, entity.AddPrice, entity.DefaultFlag, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 厨打方案下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadKitPlan() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.KitPlan; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "kit.plan"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.KitPlanError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.KitPlanError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.KitPlanException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheKitPlan(DownloadNotify notify) { bool result = false; string tips = "厨打方案"; try { string template = "replace into [pos_kit_plan] ([id],[tenantId],[name],[no],[type],[memo],[keys],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}');"; var list = new ConcurrentQueue(); //清理数据 //list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId() , Priority = 0 , Sql = "delete from [pos_kit_plan];" , CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { List kits = null; using (var db = Global.Instance.OpenDataBase) { kits = db.Query().ToList(); } if (kits == null) { kits = new List(); } using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string typeName = "一菜一单"; switch (entity.Type) { case "1": { typeName = "一小类一单"; } break; case "2": { typeName = "一桌一单"; } break; case "0": default: { typeName = "一菜一单"; } break; } KitPlan oldValue = null; if (kits.Exists(x => x.Id == entity.Id)) { oldValue = kits.Find(x => x.Id.Equals(entity.Id)); var keys = string.Format("{0}-{1}({2})", entity.No, entity.Name, typeName); entity.Keys = string.IsNullOrEmpty(oldValue.Keys) ? keys : oldValue.Keys; } else { var keys = string.Format("{0}-{1}({2})", entity.No, entity.Name, typeName); entity.Keys = keys; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.Name, entity.No, entity.Type, entity.Memo, entity.Keys, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取厨打商品信息>>>> /// /// 厨打商品数据下载 /// /// public static DownloadNotify DownloadKitProduct(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.KitProduct; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "kit.product"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.KitProductError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.KitProductError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.KitProductException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadKitProductNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.KitProduct; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "kit.product"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.KitProductError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.KitProductError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.KitProductException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的信息 /// /// /// public static bool CacheKitProduct(DownloadNotify notify) { bool result = false; string tips = "厨打商品信息"; try { string template = "insert into [pos_kit_product] ([id],[tenantId],[storeId],[productId],[chudaFlag],[chuda],[chupinFlag],[chupin],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_kit_product];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.StoreId, entity.ProductId, entity.ChudaFlag, entity.Chuda, entity.ChupinFlag, entity.Chupin, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 厨显方案下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadKdsPlan() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.KdsPlan; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "kds.plan"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.KdsPlanError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.KdsPlanError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.KdsPlanException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheKdsPlan(DownloadNotify notify) { bool result = false; string tips = "厨显方案"; try { string template = "replace into [pos_kds_plan] ([id], [tenantId], [name], [no], [memo], [keys], [ext1], [ext2], [ext3], [createUser], [createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}');"; var list = new ConcurrentQueue(); //清理数据 //list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId() , Priority = 0 , Sql = "delete from [pos_kit_plan];" , CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { List kits = null; using (var db = Global.Instance.OpenDataBase) { kits = db.Query().ToList(); } if (kits == null) { kits = new List(); } using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { var keys = string.Format("{0}-{1}", entity.No, entity.Name); entity.Keys = keys; string sql = string.Format(template, entity.Id, entity.TenantId, entity.Name, entity.No, entity.Memo, entity.Keys, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取厨显商品信息>>>> /// /// 厨显商品数据下载 /// /// public static DownloadNotify DownloadKdsProduct(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.KdsProduct; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "kds.product"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.KdsProductError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.KdsProductError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.KdsProductException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadKdsProductNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.KdsProduct; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "kds.product"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.KdsProductError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.KdsProductError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.KdsProductException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的信息 /// /// /// public static bool CacheKdsProduct(DownloadNotify notify) { bool result = false; string tips = "厨显商品信息"; try { string template = "insert into [pos_kds_product] ([id], [tenantId], [storeId], [productId], [chuxianFlag], [chuxian], [chuxianTime], [chupinFlag], [chupin], [chupinTime], [ext1], [ext2], [ext3], [createUser], [createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_kds_product];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.StoreId, entity.ProductId, entity.ChuxianFlag, entity.Chuxian, entity.ChuxianTime, entity.ChupinFlag, entity.Chupin, entity.ChupinTime, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 打印机下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadPrinter() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.Printer; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "peripheral.printer.info"); parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters)); string response = HttpClientUtils.PostAsync(api, api.Url, parameters); if (Constant.IsSuccessful(response)) { var result = JsonUtils.Deserialize>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.PrinterError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.PrinterError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.PrinterException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CachePrinter(DownloadNotify notify) { bool result = false; string tips = "打印机"; try { string template = "insert into [pos_printer] ([id],[tenantId],[name],[type],[dynamic],[port],[pageWidth],[baudRate],[dataNum],[checkNum],[stopNum],[pid],[vid],[initCode],[zbkCode],[cutCode],[ztbgCode],[ptztCode],[bkbgCode],[moneyCode],[userDefined],[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}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_printer] where [userDefined] = 0;", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Name, entity.Type, entity.DynamicLibrary, entity.Port, entity.PageWidth, entity.BaudRate, entity.DataBit, entity.CheckBit, entity.StopBit, entity.Pid, entity.Vid, entity.InitCommand, entity.DoubleWidthCommand, entity.CutPageCommand, entity.DoubleHeightCommand, entity.NormalCommand, entity.DoubleWidthHeightCommand, entity.CashboxCommand, "0", entity.Memo, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 读卡器下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadCarder() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.Carder; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "peripheral.card.reader.info"); parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters)); string response = HttpClientUtils.PostAsync(api, api.Url, parameters); if (Constant.IsSuccessful(response)) { var result = JsonUtils.Deserialize>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.CarderError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.CarderError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.CarderException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheCarder(DownloadNotify notify) { bool result = false; string tips = "读卡器"; try { string template = "insert into [pos_carder] ([id],[tenantId],[name],[cardType],[port],[baudRate],[userDefined],[memo],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_carder] where [userDefined] = 0;", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Name, entity.CardType, entity.Port, entity.BaudRate, "0", entity.Memo, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店信息下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadStoreInfo() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.StoreInfo; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.message"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { if (Global.Instance.Authc != null && result.Data.TenantId == null) { result.Data.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(result.Data); box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.StoreInfoError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.StoreInfoError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.StoreInfoException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheStoreInfo(DownloadNotify notify) { bool result = false; string tips = "门店信息"; try { string template = "insert into pos_store_info (id,tenantId,name,[no],manager,telphone,mobile,orderTel,printName,address,mail,stapleFlag,width,height,groupName,storageFileName,dfsAccessDomain,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}','{19}','{20}','{21}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_store_info];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Name, entity.No, entity.Manager, entity.Telphone, entity.Mobile, entity.OrderTel, entity.PrintName, entity.Address, entity.Mail, entity.StapleFlag, entity.Width, entity.Height, entity.GroupName, entity.StorageFileName, entity.DfsAccessDomain, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店图片信息下载>>>> /// /// 数据下载 /// /// public static DownloadNotify DownloadStorePrintImage() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.StorePrintImage; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.print.image"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.StorePrintImageError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.StorePrintImageError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.StorePrintImageException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheStorePrintImage(DownloadNotify notify) { bool result = false; string tips = "门店图片信息"; try { string template = "insert into [pos_store_print_image] (id,tenantId,name,type,width,height,groupName,storageFileName,dfsAccessDomain,description,ext1,ext2,ext3,createUser,createDate)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_store_print_image];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Name, entity.Type, entity.Width, entity.Height, entity.GroupName, entity.StorageFileName, entity.DfsAccessDomain, entity.Description, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店双屏图片>>>> /// /// 数据下载 门店双屏图片 /// /// public static DownloadNotify DownloadStoreAdvertPicture() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.AdvertPicture; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.advert.picture"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.AdvertPictureError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.AdvertPictureError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.AdvertPictureException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheStoreAdvertPicture(DownloadNotify notify) { bool result = false; string tips = "门店双屏图片信息"; try { string template = "INSERT INTO [pos_advert_pictures] ([id], [tenantId], [name], [width], [height], [dfsAccessDomain], [groupName], [storageFileName], [orderNo], [createUser], [createDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_advert_pictures];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Name, entity.Width, entity.Height, entity.DfsAccessDomain, entity.GroupName, entity.StorageFileName, entity.OrderNo, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店双屏字幕>>>> /// /// 数据下载 门店双屏字幕 /// /// public static DownloadNotify DownloadStoreAdvertCaption() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.AdvertCaption; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.advert.caption"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.AdvertCaptionError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.AdvertCaptionError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.AdvertCaptionException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheStoreAdvertCaption(DownloadNotify notify) { bool result = false; string tips = "门店双屏字幕信息"; try { string template = "INSERT INTO [pos_advert_caption] ([id], [tenantId], [name], [content], [createUser], [createDate])values('{0}','{1}','{2}','{3}','{4}','{5}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_advert_caption];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Name, entity.Content, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 饿了么菜品映射>>>> /// /// 数据下载 饿了么菜品映射 /// /// public static DownloadNotify DownloadMappingDishEleMe() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.MappingDishEleMe; notify.IsPager = false; notify.PageNumber = 1; notify.PageCount = 1; string tips = "饿了么菜品映射信息"; try { logger.Info(string.Format("下载{0}......", tips)); OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai); SortedList parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "eleme.mapping.dish"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.MappingDishEleMeError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.MappingDishEleMeError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.MappingDishEleMeException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheMappingDishEleMe(DownloadNotify notify) { bool result = false; string tips = "饿了么映射信息"; try { string template = "INSERT INTO [pos_mapping_product_eleme] ([id],[tenantId], [foodId], [specId], [erpProductId], [erpSpecId], [createUser], [createDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_mapping_product_eleme];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.FoodId, entity.SpecId, entity.ErpProductId, entity.ErpSpecId, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 美团菜品映射>>>> /// /// 数据下载 美团菜品映射 /// /// public static DownloadNotify DownloadMeituanMappingDish() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.MappingDishMeiTuan; notify.IsPager = false; notify.PageNumber = 1; notify.PageCount = 1; string tips = "美团菜品映射信息"; try { logger.Info(string.Format("下载{0}......", tips)); OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai); SortedList parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "meituan.mapping.dish"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.MappingDishMeiTuanError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.MappingDishMeiTuanError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.MappingDishMeiTuanException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheMeituanMappingDish(DownloadNotify notify) { bool result = false; string tips = "美团映射信息"; try { string template = "INSERT INTO [pos_mapping_product_meituan] ([id],[tenantId], [dishId], [dishSkuId], [erpProductId], [erpSpecId], [createUser], [createDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_mapping_product_meituan];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.DishId, entity.DishSkuId, entity.ErpProductId, entity.ErpSpecId, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 百度菜品映射>>>> /// /// 数据下载 百度菜品映射 /// /// public static DownloadNotify DownloadBaiDuMappingDish() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.MappingDishBaiDu; notify.IsPager = false; notify.PageNumber = 1; notify.PageCount = 1; string tips = "百度菜品映射信息"; try { logger.Info(string.Format("下载{0}......", tips)); OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.WaiMai); SortedList parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "baidu.mapping.dish"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.MappingDishBaiDuError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.MappingDishBaiDuError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.MappingDishBaiDuException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheBaiDuMappingDish(DownloadNotify notify) { bool result = false; string tips = "百度映射信息"; try { string template = "INSERT INTO [pos_mapping_product_baidu] ([id],[tenantId], [dishId], [dishSkuId], [erpProductId], [erpSpecId], [createUser], [createDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_mapping_product_baidu];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.DishId, entity.DishSkuId, entity.ErpProductId, entity.ErpSpecId, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 费用项目>>>> /// /// 数据下载 费用项目 /// /// public static DownloadNotify DownloadFeeitem() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.Feeitem; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "store.feeitem.list"); parameters.Add("storeId", Global.Instance.Authc.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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.FeeitemError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.FeeitemError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.FeeitemException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheFeeitem(DownloadNotify notify) { bool result = false; string tips = "费用项目"; try { string template = "INSERT INTO [pos_feeitem] ([id],[tenantId], [name], [type], [enabled], [orderNo], [createUser], [createDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_feeitem];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Name, entity.Type, entity.Enabled, entity.OrderNo, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取门店熟客信息>>>> public static DownloadNotify DownloadVisitor(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.Visitor; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method" , "visitor.list"); parameters.Add("storeId" , Global.Instance.Authc.StoreId); parameters.Add("pageNumber" , Convert.ToString(notify.PageNumber)); parameters.Add("pageSize" , Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.VisitorError; notify.Message = string.Format("<{0}>-{1}" , result.ErrCode , result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......" , tips , notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.VisitorError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}" , tips , errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.VisitorException; notify.Message = string.Format("{0}下载发生异常" , tips); logger.Error(ex , notify.Message); } return notify; } public static DownloadNotify DownloadVisitorNextPage(int pageNum , int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.Visitor; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method" , "visitor.list"); parameters.Add("storeId" , Global.Instance.Authc.StoreId); parameters.Add("pageNumber" , Convert.ToString(pageNum)); parameters.Add("pageSize" , Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......" , pageNum , tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.VisitorError; notify.Message = string.Format("<{0}>-{1}" , result.ErrCode , result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......" , pageNum , tips , notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.VisitorError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}" , pageNum , tips , errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.VisitorException; notify.Message = string.Format("第{0}页{1}下载发生异常" , pageNum , tips); logger.Error(ex , notify.Message); } return notify; } /// /// 处理下载的信息 /// /// /// public static bool CacheVisitor(DownloadNotify notify) { bool result = false; string tips = "门店熟客信息"; try { string template = "insert into pos_visitor (id,tenantId,storeId,[no],name,tel,spell,sex,title,position,fphone,sphone,description,upload,ext1,ext2,ext3,createUser,createDate)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}',1,'{13}','{14}','{15}','{16}','{17}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId() , Priority = 0 , Sql = "delete from [pos_visitor] where [upload] = 1;" , CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName , null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template , entity.Id , entity.TenantId , entity.StoreId , entity.No , entity.Name , entity.Tel , entity.Spell , entity.Sex,entity.Title,entity.Position,entity.Phone1,entity.Phone2,entity.Description , entity.Ext1 , entity.Ext3 , entity.Ext2 , entity.CreateUser , entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId() , Priority = 1 , Sql = sql , CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex , string.Format("处理{0}发生异常" , tips)); result = false; } return result; } #endregion #region 获取门店熟客标签信息>>>> public static DownloadNotify DownloadVisitorTag(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.VisitorTag; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method" , "visitor.tag.list"); parameters.Add("storeId" , Global.Instance.Authc.StoreId); parameters.Add("pageNumber" , Convert.ToString(notify.PageNumber)); parameters.Add("pageSize" , Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.VisitorTagError; notify.Message = string.Format("<{0}>-{1}" , result.ErrCode , result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......" , tips , notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.VisitorTagError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}" , tips , errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.VisitorTagException; notify.Message = string.Format("{0}下载发生异常" , tips); logger.Error(ex , notify.Message); } return notify; } public static DownloadNotify DownloadVisitorTagNextPage(int pageNum , int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.VisitorTag; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method" , "visitor.tag.list"); parameters.Add("storeId" , Global.Instance.Authc.StoreId); parameters.Add("pageNumber" , Convert.ToString(pageNum)); parameters.Add("pageSize" , Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......" , pageNum , tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.VisitorTagError; notify.Message = string.Format("<{0}>-{1}" , result.ErrCode , result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......" , pageNum , tips , notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.VisitorTagError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}" , pageNum , tips , errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.VisitorTagException; notify.Message = string.Format("第{0}页{1}下载发生异常" , pageNum , tips); logger.Error(ex , notify.Message); } return notify; } /// /// 处理下载的信息 /// /// /// public static bool CacheVisitorTag(DownloadNotify notify) { bool result = false; string tips = "门店熟客标签信息"; try { string template = "insert into pos_visitor_tag (id,tenantId,visitorId,name,upload,ext1,ext2,ext3,createUser,createDate)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId() , Priority = 0 , Sql = "delete from [pos_visitor_tag] where [upload] = 1;" , CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName , null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template , entity.Id , entity.TenantId , entity.VisitorId , entity.Name ,1, entity.Ext1 , entity.Ext2 , entity.Ext3 , entity.CreateUser , entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId() , Priority = 1 , Sql = sql , CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex , string.Format("处理{0}发生异常" , tips)); result = false; } return result; } #endregion #region 获取门店熟客地址信息>>>> public static DownloadNotify DownloadVisitorAddress(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.VisitorAddress; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method" , "visitor.address.list"); parameters.Add("storeId" , Global.Instance.Authc.StoreId); parameters.Add("pageNumber" , Convert.ToString(notify.PageNumber)); parameters.Add("pageSize" , Convert.ToString(pageSize)); var ignore = new List(); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.VisitorAddressError; notify.Message = string.Format("<{0}>-{1}" , result.ErrCode , result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......" , tips , notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.VisitorAddressError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}" , tips , errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.VisitorAddressException; notify.Message = string.Format("{0}下载发生异常" , tips); logger.Error(ex , notify.Message); } return notify; } public static DownloadNotify DownloadVisitorAddressNextPage(int pageNum , int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.VisitorAddress; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method" , "visitor.address.list"); parameters.Add("storeId" , Global.Instance.Authc.StoreId); parameters.Add("pageNumber" , Convert.ToString(pageNum)); parameters.Add("pageSize" , Convert.ToString(pageSize)); var ignore = new List(); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......" , pageNum , tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.VisitorAddressError; notify.Message = string.Format("<{0}>-{1}" , result.ErrCode , result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......" , pageNum , tips , notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.VisitorAddressError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}" , pageNum , tips , errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.VisitorAddressException; notify.Message = string.Format("第{0}页{1}下载发生异常" , pageNum , tips); logger.Error(ex , notify.Message); } return notify; } /// /// 处理下载的信息 /// /// /// public static bool CacheVisitorAddress(DownloadNotify notify) { bool result = false; string tips = "门店熟客标签信息"; try { string template = "insert into pos_visitor_address (id,tenantId,name,visitorId,telephone,areaName,address,description,upload,ext1,ext2,ext3,createUser,createDate)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId() , Priority = 0 , Sql = "delete from [pos_visitor_address] where [upload] = 1;" , CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName , null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template , entity.Id , entity.TenantId ,entity.Name, entity.VisitorId , entity.Telephone , entity.AreaName , entity.Address , entity.Description ,1, entity.Ext1 , entity.Ext3 , entity.Ext2 , entity.CreateUser , entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId() , Priority = 1 , Sql = sql , CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex , string.Format("处理{0}发生异常" , tips)); result = false; } return result; } #endregion #region 促销下载>>>> #region 卡友日 /// /// 数据下载 卡友日 /// /// public static DownloadNotify DownloadCardProDay() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.CardProDay; notify.IsPager = false; notify.PageNumber = 1; notify.PageCount = 1; string tips = "会员促销"; try { logger.Info(string.Format("下载{0}......", tips)); OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Card); SortedList parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "card.pro.day.detail"); parameters.Add("shopNo", Global.Instance.Authc.StoreNo); parameters.Add("posNo", Global.Instance.Authc.PosNo); parameters.Add("sign", OpenApiUtils.Instance.Sign(api, parameters)); string response = HttpClientUtils.PostAsync(api, api.Url, parameters); if (Constant.IsSuccessful(response)) { var result = JsonUtils.Deserialize>(response); if (result.Status == 1) { if(result.Data.Id != null)//排除没有设置卡友日的情况 { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var data = result.Data; CardPromotion pro = new CardPromotion(); pro.Id = data.Id; pro.TenantId = data.TenantId; pro.Type = PromotionType.卡友日.ToString(); pro.Content = JsonUtils.Serialize(data); box.Bind(notify.CacheName).Insert(pro); box.Commit(); } } } notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.CardProDayError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.CardProDayError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.CardProDayException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheCardProDay(DownloadNotify notify) { bool result = false; string tips = "会员促销"; try { string template = "INSERT INTO [pos_card_promotion] ([id], [tenantId], [type], [content], [createUser], [createDate])values('{0}','{1}','{2}','{3}','{4}','{5}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_card_promotion];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Type, entity.Content, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 后台促销 /// /// 门店促销数据下载 /// /// public static DownloadNotify DownloadStoreTask(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreTask; notify.IsPager = false; notify.PageNumber = 1; notify.PageCount = 1; notify.PageSize = pageSize; string tips = "门店促销信息"; try { OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business); SortedList parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "promotion.store.task"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("startDate", DateTime.Now.ToString("yyyy-MM-dd")); parameters.Add("day", "3"); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); ignore.Add("day"); 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>(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.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } 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.PromotionStoreTaskError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreTaskError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreTaskException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadStoreTaskNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreTask; 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 parameters = OpenApiUtils.Instance.NewParameters(api); parameters.Add("method", "promotion.store.task"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("startDate", DateTime.Now.ToString("yyyy-MM-dd")); parameters.Add("day", "3"); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); ignore.Add("day"); 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>(response); if (result.Status == 1) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in result.List) { if (Global.Instance.Authc != null && o.TenantId == null) { o.TenantId = Global.Instance.Authc.TenantId; } box.Bind(notify.CacheName).Insert(o); } box.Commit(); } } notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreTaskError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = PaserErrors(response); notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreTaskError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreTaskException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的门店促销信息 /// /// /// public static bool CacheStoreTask(DownloadNotify notify) { bool result = false; string tips = "门店促销信息"; try { string template = "INSERT INTO [pos_promotion_task] ([id], [tenantId], [storeId], [sn], [scheduleId], [scheduleSn], [promotionId], [promotionSn], [promotionType], [valueType], [valueId], [valueNo], [valueName], [valueExt1], [valueExt2], [schemeId], [schemeSn], [startDate], [endDate], [startTime], [endTime], [validWeek], [isRepeatDiscount], [isAll], [goodsBlackList], [discountType], [discountValue], [rule], [status], [setMan], [setTime], [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}');"; var list = new ConcurrentQueue(); //清理数据 list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_promotion_task];", CacheName = notify.CacheName }); //记录本次更新的条数 int counts = 0; lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { var lists = box.Select("from " + notify.CacheName, null); if (lists.Count() > 0) { foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.StoreId, entity.Sn, entity.ScheduleId, entity.ScheduleSn, entity.PromotionId, entity.PromotionSn, entity.PromotionType, entity.ValueType, entity.ValueId, entity.ValueNo, entity.ValueName, entity.ValueExt1, entity.ValueExt2, entity.SchemeId, entity.SchemeSn, entity.StartDate, entity.EndDate, entity.StartTime, entity.EndTime, entity.ValidWeek, entity.IsRepeatDiscount, entity.IsAll, entity.GoodsBlackList, entity.DiscountType, entity.DiscountValue, entity.Rule, entity.Status, entity.SetMan, entity.SetTime, entity.CreateUser, entity.CreateDate); list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = notify.CacheName }); Interlocked.Increment(ref counts); } } } } DownloadCacheSql(list); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #endregion /// /// 缓存SQL语句,等待批量执行 /// /// private static void DownloadCacheSql(ConcurrentQueue list) { lock (Global.Instance.CacheLock) { using (var box = DownloadCache.Instance.AutoBoxTransaction) { foreach (var o in list) { box.Bind(DownloadCacheName.SqlCache.ToString()).Insert(o); } box.Commit(); } } } } }