using POSV.Entity; using POSV.HttpResponse; using POSV.Utils; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; using System.Text; using POSV.Entity.Pormotion; using POSV.ShoppingCart; namespace POSV.HttpApi { public class FastDownloadApi : BaseApi { protected static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); private static object _lock = new object(); private static FastDownloadApi _instance = null; private ConcurrentQueue _cache = null; private static bool IS_Visitor = true; private static Dictionary visitorMap = new Dictionary(); private static Dictionary addressMap = new Dictionary(); public static FastDownloadApi Instance { get { if (_instance == null) { lock (_lock) { _instance = new FastDownloadApi(); _instance.InitCache(); } } return _instance; } } public void InitCache() { this._cache = new ConcurrentQueue(); } private void AddCache(DownloadSqlCache data) { this._cache.Enqueue(data); } public ConcurrentQueue Cache() { return this._cache; } #region 操作员数据下载 public static DownloadNotify DownloadWorker() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.Worker; notify.IsPager = false; notify.PageNumber = 1; notify.PageCount = 1; string tips = "门店操作员"; try { logger.Info(string.Format("下载{0}......", tips)); OpenApi api = OpenApiUtils.Instance.NextApi(ApiType.Business); SortedList 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) { if (CacheWorker(notify.CacheName, result.List)) { notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.WorkerError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.WorkerError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { string errorMessage = 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; } private static bool CacheWorker(string cacheName, List lists) { bool result = false; string tips = "门店操作员"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_worker];", CacheName = cacheName }); if (lists.Count() > 0) { string template = "insert into [pos_worker] ([id],[tenantId],[storeId],[departmentId],[no],[passwd],[name],[sex],[birthday],[email],[mobile],[session],[lastDate],[memo],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.StoreId, entity.DepartmentId, entity.No, entity.Passwd, entity.Name, entity.Sex, entity.Birthday, entity.Email, entity.Mobile, entity.Session, entity.LastDate, entity.Memo, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 员工角色(折扣免单权限)列表下载 /// /// 员工角色(折扣免单权限)列表 /// /// 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) { if (CacheWorkerRole(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.WorkerRoleError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheWorkerRole(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.WorkerRoleError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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; } /// /// 处理下载的信息 /// /// /// private static bool CacheWorkerRole(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "员工角色"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_worker_role];", CacheName = cacheName }); } if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (string.IsNullOrEmpty(entity.Id)) { entity.Id = IdWorkerUtils.Instance.NextId(); } if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 模块权限列表 /// /// 模块权限列表 /// /// 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) { if (CacheWorkerPermissions(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.WorkerPermissionsError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheWorkerPermissions(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.WorkerPermissionsError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "模块权限"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_worker_permissions];", CacheName = cacheName }); } if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (string.IsNullOrEmpty(entity.Id)) { entity.Id = IdWorkerUtils.Instance.NextId(); } if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取门店营业方案 /// /// 门店营业方案数据下载 /// /// 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) { if (CacheBusinessPlan(notify.CacheName, result.Data)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, BusinessPlan entity) { bool result = false; string tips = "门店营业方案"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_business_plan];", CacheName = cacheName }); 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}');"; if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取商品类别信息 /// /// 菜品类别数据下载 /// /// 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) { if (CacheProductType(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductTypeError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductTypeError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = 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) { if (CacheProductType(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductTypeError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductTypeError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = 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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "菜品类别信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_type];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_product_type] ([id],[tenantId],[parentId],[no],[name],[path],[color],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.ParentId, entity.No, entity.Name, entity.Path, entity.Color, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 商品信息下载 /// /// 菜品资料数据下载 /// /// 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) { if (CacheProduct(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = 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) { if (CacheProduct(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = 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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "商品信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_product] ([id],[tenantId],[brandId],[typeId],[typePath],[no],[name],[shortName],[spell],[assistNo],[otherNo],[barCode],[english],[unitId],[price],[memberPrice],[memo],[commissionType],[commissionValue],[discountFlag],[suitFlag],[tapleFlag],[weighFlag],[currentFlag],[labelPrintFlag],[stopFlag],[groupName],[picture],[mebDiscountFlag],[giveFlag],[promotionFlag],[type],[stockFlag],[pointType],[pointValue],[purchaseTax],[saleTax],[lyRate],[costPrice],[purchasePrice],[dispatchPrice],[otherPrice],[specCount],[minPrice],[kdsFlag],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}','{29}','{30}','{31}','{32}','{33}','{34}','{35}','{36}','{37}','{38}','{39}','{40}','{41}','{42}','{43}','{44}','{45}','{46}','{47}','{48}','{49}');"; foreach (var entity in lists) { string sql = string.Empty; try { sql = string.Format(template, entity.Id, entity.TenantId, entity.BrandId, entity.TypeId, entity.TypePath, entity.No, entity.Name, entity.ShortName, entity.Spell, entity.AssistNo, entity.OtherNo, entity.BarCode, entity.English, entity.UnitId, entity.Price, entity.MemberPrice, entity.Memo, entity.CommissionType, entity.CommissionValue, entity.DiscountFlag, entity.SuitFlag, entity.TapleFlag, entity.WeighFlag, entity.CurrentFlag, entity.LabelPrintFlag, entity.StopFlag, entity.GroupName, entity.Picture, entity.MebDiscountFlag, entity.GiveFlag, entity.PromotionFlag, entity.Type, entity.StockFlag, entity.PointType, entity.PointValue, entity.PurchaseTax, entity.SaleTax, entity.LyRate, entity.CostPrice, entity.PurchasePrice, entity.DispatchPrice, entity.OtherPrice, entity.SpecCount, entity.MinPrice, entity.KdsFlag, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } catch (Exception ex) { logger.Info(sql); logger.Info(ex); } } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取商品单位信息 /// /// 菜品类别数据下载 /// /// 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) { if (CacheProductUnit(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductUnitError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductUnitError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = 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) { if (CacheProductUnit(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductUnitError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductUnitError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = 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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "商品单位信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_unit];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_product_unit] ([id],[tenantId],[no],[name],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.No, entity.Name, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取商品图片信息 /// /// 菜品类别数据下载 /// /// 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) { if (CacheProductImage(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductImageError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheProductImage(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductImageError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "商品图片信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_image];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_product_image] ([id],[tenantId],[productId],[width],[height],[groupName],[storageFileName],[dfsAccessDomain],[length],[mimeType],[orderNo],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.ProductId, entity.Width, entity.Height, entity.GroupName, entity.StorageFileName, entity.DfsAccessDomain, entity.Length, entity.MimeType, entity.OrderNo, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店仓库 /// /// 数据下载 /// /// 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) { if (CacheStoreStorage(notify.CacheName, result.List)) { 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}发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "付款类型"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_store_storage];", CacheName = cacheName }); if (lists.Count() > 0) { string template = "insert into [pos_store_storage] ([id],[tenantId],[no],[name],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}');"; foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.No, entity.Name, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取商品库存系数信息 /// /// 商品库存系数数据下载 /// /// 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) { if (CacheProductRatio(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductRatioError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheProductRatio(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductRatioError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "商品库存系数信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_ratio];", CacheName = cacheName }); } if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取门店商品库存信息 /// /// 商品库存数据下载 /// /// 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) { if (CacheProductStock(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductStockError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheProductStock(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductStockError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "商品库存信息"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_stock];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 营业日方案班次下载 /// /// 操作员数据下载 /// /// 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) { if (CacheBusinessPlanDetail(notify.CacheName, result.List)) { 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("缓存操作员数据发生错误"); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.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(string cacheName, List lists) { bool result = false; string tips = "门店班次"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_business_plandetail];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取商品规格信息 /// /// 菜品类别数据下载 /// /// 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) { if (CacheProductSpec(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductSpecError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductSpecError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}......", tips, notify.Message)); } } else { string errorMessage = 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) { if (CacheProductSpec(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductSpecError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductSpecError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("第{0}页{1}下载出错:{2}......", pageNum, tips, notify.Message)); } } else { string errorMessage = 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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "商品规格信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_spec];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_product_spec] ([id],[tenantId],[productId],[no],[name],[price],[memberPrice],[otherPrice],[costPrice],[purchasePrice],[dispatchPrice],[materialRate],[isDefault],[minPrice],[deleteFlag],[thUseLevel],[realThUseLevel],[cost],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.ProductId, entity.No, entity.Name, entity.Price, entity.MemberPrice, entity.OtherPrice, entity.CostPrice, entity.PurchasePrice, entity.DispatchPrice, entity.MaterialRate, entity.IsDefault, entity.MinPrice, entity.DeleteFlag, entity.ThUseLevel, entity.RealThUseLevel, entity.Cost, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 付款类型下载 /// /// 数据下载 /// /// 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) { if (CachePayType(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "付款类型"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_paytype];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 收银方式下载 /// /// 数据下载 /// /// 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); //zhangy 2020-02-18 Edit 注释了该代码,启用新的store.period.discount.paymode,相比旧方法多了periodDiscount字段,解决不同支付方式扣率问题 ///parameters.Add("method", "store.paymode"); ///zhangy 2020-02-18 Add 启用新方法 parameters.Add("method", "store.period.discount.paymode"); //#if DEBUG // if ("571022".Equals(Global.Instance.Authc.TenantId)) // { // parameters.Add("method", "store.paymode"); // } // else // { // parameters.Add("method", "store.period.discount.paymode"); // } //#else // parameters.Add("method", "store.period.discount.paymode"); //#endif 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) { if (CachePayMode(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "收银方式"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_paymode];", CacheName = cacheName }); if (lists.Count() > 0) { string template = "insert into [pos_paymode] ([id],[tenantId],[name],[no],[typeId],[shortcut],[pointFlag],[frontFlag],[rechargeFlag],[discount],[fixeAmount],[pbody],[certText],[incomeFlag],[otherRateType],[otherRateValue],[periodDiscount],[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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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.IncomeFlag, entity.OtherRateType, entity.OtherRateValue, JsonUtils.Serialize(entity.Settlement), entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 餐桌区域下载 /// /// 数据下载 /// /// 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) { if (CacheTableArea(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "餐桌区域"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_tablearea];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.Name, entity.No, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 餐桌类型下载 /// /// 数据下载 /// /// 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) { if (CacheTableType(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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; } /// /// 处理下载的数据 /// /// /// private static bool CacheTableType(string cacheName, List lists) { bool result = false; string tips = "餐桌类型"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_tabletype];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 餐桌信息下载 /// /// 数据下载 /// /// 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) { if (CacheTable(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "餐桌信息"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_table];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店品牌下载 /// /// 数据下载 /// /// 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) { if (CacheBrand(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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; } /// /// 处理下载的数据 /// /// /// private static bool CacheBrand(string cacheName, List lists) { bool result = false; string tips = "门店品牌"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_brand];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 做法类型数据下载 /// /// 操作员数据下载 /// /// 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) { if (CacheProductMakeType(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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; } /// /// 处理下载的做法类型数据 /// /// /// private static bool CacheProductMakeType(string cacheName, List lists) { bool result = false; string tips = "做法类型"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_maketype];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 做法信息数据下载 /// /// 操作员数据下载 /// /// 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) { if (CacheProductMakeDetail(notify.CacheName, result.List)) { notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailError; notify.Message = string.Format("缓存{0}数据发生错误", tips); logger.Info(notify.Message); } } 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(string cacheName, List lists) { bool result = false; string tips = "做法信息"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_makedetail];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 商品私有做法信息下载 /// /// 商品私有做法数据下载 /// /// 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) { if (CacheProductMakeDetailPrivate(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailPrivateError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheProductMakeDetailPrivate(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductMakeDetailPrivateError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "商品私有做法信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_makedetail_private];", CacheName = cacheName }); } if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } if (string.IsNullOrEmpty(entity.Id)) { entity.Id = IdWorkerUtils.Instance.NextId(); } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取套菜资料信息 /// /// 数据下载 /// /// 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) { if (CacheProductSuit(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheProductSuit(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "套菜资料"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_suit];", CacheName = cacheName }); } if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取套菜明细信息 /// /// 数据下载 /// /// 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) { if (CacheProductSuitDetail(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitDetailError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheProductSuitDetail(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductSuitDetailError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "套菜资料"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_suitdetail];", CacheName = cacheName }); } if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 厨打方案下载 /// /// 数据下载 /// /// 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) { if (CacheKitPlan(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "厨打方案"; try { //清理数据 //list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId() , Priority = 0 , Sql = "delete from [pos_kit_plan];" , CacheName = notify.CacheName }); List kits = null; using (var db = Global.Instance.OpenDataBase) { kits = db.Query().ToList(); } if (kits == null) { kits = new List(); } if (lists.Count() > 0) { 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}');"; 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取厨打商品信息 /// /// 厨打商品数据下载 /// /// 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) { if (CacheKitProduct(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.KitProductError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheKitProduct(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.KitProductError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "厨打商品信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_kit_product];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_kit_product] ([id],[tenantId],[storeId],[productId],[chudaFlag],[chuda],[chupinFlag],[chupin],[labelFlag],[labelValue],[ext1],[ext3],[ext2],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.StoreId, entity.ProductId, entity.ChudaFlag, entity.Chuda, entity.ChupinFlag, entity.Chupin, entity.LabelFlag, entity.LabelValue, entity.Ext1, entity.Ext3, entity.Ext2, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 厨显方案下载 /// /// 数据下载 /// /// 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) { if (CacheKdsPlan(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "厨显方案"; try { //清理数据 //list.Enqueue(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId() , Priority = 0 , Sql = "delete from [pos_kit_plan];" , CacheName = notify.CacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取厨显商品信息 /// /// 厨显商品数据下载 /// /// 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) { if (CacheKdsProduct(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.KdsProductError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheKdsProduct(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.KdsProductError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "厨显商品信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_kds_product];", CacheName = cacheName }); } if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 打印机下载 /// /// 数据下载 /// /// 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) { if (CachePrinter(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "打印机"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_printer] where [userDefined] = 0;", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 读卡器下载 /// /// 数据下载 /// /// 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) { if (CacheCarder(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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; } /// /// 处理下载的数据 /// /// /// private static bool CacheCarder(string cacheName, List lists) { bool result = false; string tips = "读卡器"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_carder] where [userDefined] = 0;", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店信息下载 /// /// 数据下载 /// /// 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) { if (CacheStoreInfo(notify.CacheName, result.Data)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, StoreInfo entity) { bool result = false; string tips = "门店信息"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_store_info];", CacheName = cacheName }); string template = "insert into pos_store_info (id,tenantId,name,[no],manager,telphone,mobile,orderTel,printName,address,mail,stapleFlag,width,height,groupName,storageFileName,dfsAccessDomain,maxOffLine,costMode,dueDate,ext1,ext2,ext3,createUser,createDate,storeTaxRateFlag,saleTax,lyRate,storeRate,pbody) 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}');"; if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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.MaxOffLine, entity.CostMode, entity.DueDate, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate, entity.StoreTaxRateFlag, entity.SaleTax, entity.LyRate, entity.StoreRate, JsonUtils.Serialize(entity.Body)); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店图片信息下载 /// /// 数据下载 /// /// 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) { if (CacheStorePrintImage(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "门店图片信息"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_store_print_image];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店双屏图片 /// /// 数据下载 门店双屏图片 /// /// 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) { if (CacheStoreAdvertPicture(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "门店双屏图片信息"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_advert_pictures];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店双屏字幕 /// /// 数据下载 门店双屏字幕 /// /// 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) { if (CacheStoreAdvertCaption(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "门店双屏字幕信息"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_advert_caption];", CacheName = cacheName }); if (lists.Count() > 0) { string template = "INSERT INTO [pos_advert_caption] ([id], [tenantId], [name], [content], [createUser], [createDate])values('{0}','{1}','{2}','{3}','{4}','{5}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Name, entity.Content, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 饿了么菜品映射 /// /// 数据下载 饿了么菜品映射 /// /// 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) { if (CacheMappingDishEleMe(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "饿了么映射信息"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_mapping_product_eleme];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.FoodId, entity.SpecId, entity.ErpProductId, entity.ErpSpecId, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 美团菜品映射 /// /// 数据下载 美团菜品映射 /// /// 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) { if (CacheMeituanMappingDish(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "美团映射信息"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_mapping_product_meituan];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.DishId, entity.DishSkuId, entity.ErpProductId, entity.ErpSpecId, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 百度菜品映射 /// /// 数据下载 百度菜品映射 /// /// 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) { if (CacheBaiDuMappingDish(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "百度映射信息"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_mapping_product_baidu];", CacheName = cacheName }); if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.DishId, entity.DishSkuId, entity.ErpProductId, entity.ErpSpecId, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 费用项目 /// /// 数据下载 费用项目 /// /// 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) { if (CacheFeeitem(notify.CacheName, result.List)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, List lists) { bool result = false; string tips = "费用项目"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_feeitem];", CacheName = cacheName }); if (lists.Count() > 0) { string template = "INSERT INTO [pos_feeitem] ([id],[tenantId], [name], [type], [enabled], [orderNo], [createUser], [createDate])values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Name, entity.Type, entity.Enabled, entity.OrderNo, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取门店熟客信息 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)); if (IS_Visitor) { parameters.Add("createDate", GetDownloadDateTime()); } var ignore = new List(); ignore.Add("pageNumber"); ignore.Add("pageSize"); ignore.Add("createDate"); 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) { if (CacheVisitor(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.VisitorError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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)); if (IS_Visitor) { parameters.Add("createDate", GetDownloadDateTime()); } var ignore = new List(); ignore.Add("pageNumber"); ignore.Add("pageSize"); ignore.Add("createDate"); 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) { if (CacheVisitor(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.VisitorError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "门店熟客信息"; try { //清理数据 if (firstPager) { if (IS_Visitor) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_visitor] where [upload] = 1 and createDate > '" + GetDownloadDateTime() + "';", CacheName = cacheName }); } else { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_visitor] where [upload] = 1 ;", CacheName = cacheName }); } } if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } if (!visitorMap.ContainsKey(entity.Id)) { 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); visitorMap.Add(entity.Id, entity.Id); } } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } /// /// 获取请求时间 /// /// public static string GetDownloadDateTime() { DateTime _datetime = new DateTime(); using (var db = Global.Instance.OpenDataBase) { string _sql = "select count(1) from pos_visitor"; int count = db.FirstOrDefault(_sql); if (count > 500) { _datetime = DateTime.Now.AddDays(-30); return _datetime.ToString("yyyy-MM-dd HH:mm:ss"); } } return ""; } #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) { if (CacheVisitorTag(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.VisitorTagError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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) { if (CacheVisitorTag(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.VisitorTagError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "门店熟客标签信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_visitor_tag] where [upload] = 1;", CacheName = cacheName }); } if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.VisitorId, entity.Name, 1, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 获取门店熟客地址信息 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); if (IS_Visitor) { parameters.Add("createDate", GetDownloadDateTime()); } parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); var ignore = new List(); ignore.Add("pageNumber"); ignore.Add("pageSize"); ignore.Add("createDate"); 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) { if (CacheVisitorAddress(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.VisitorAddressError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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)); if (IS_Visitor) { parameters.Add("createDate", GetDownloadDateTime()); } var ignore = new List(); ignore.Add("pageNumber"); ignore.Add("pageSize"); ignore.Add("createDate"); 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) { if (CacheVisitorAddress(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.VisitorAddressError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "门店熟客标签信息"; try { //清理数据 if (firstPager) { if (IS_Visitor) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_visitor_address] where [upload] = 1 and createDate > '" + GetDownloadDateTime() + "';", CacheName = cacheName }); } else { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_visitor_address] where [upload] = 1 ;", CacheName = cacheName }); } } if (lists.Count() > 0) { 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}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } if (!addressMap.ContainsKey(entity.Id)) { 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); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); addressMap.Add(entity.Id, entity.Id); } } } 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) { CardPromotion pro = null; if (!string.IsNullOrEmpty(result.Data.Id))//排除没有设置卡友日的情况 { var data = result.Data; pro = new CardPromotion(); pro.Id = data.Id; pro.TenantId = data.TenantId; pro.Type = PromotionType.卡友日.ToString(); pro.Content = JsonUtils.Serialize(data); } if (CacheCardProDay(notify.CacheName, pro)) { 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}数据发生错误", tips); logger.Info(notify.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(string cacheName, CardPromotion entity) { bool result = false; string tips = "会员促销"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_card_promotion];", CacheName = cacheName }); //为空对象,没有设置卡友日或取消卡友日 if (entity != null) { string template = "INSERT INTO [pos_card_promotion] ([id], [tenantId], [type], [content], [createUser], [createDate])values('{0}','{1}','{2}','{3}','{4}','{5}');"; string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Type, entity.Content, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 后台促销 /// /// 门店促销数据下载 /// /// 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) { if (CachePromotionStoreTask(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreTaskError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.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(pageNum)); 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) { if (CachePromotionStoreTask(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreTaskError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.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; } /// /// 处理下载的门店促销信息 /// /// /// private static bool CachePromotionStoreTask(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "门店促销信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_promotion_task];", CacheName = cacheName }); } if (lists.Count() > 0) { 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],[validMonth], [isRepeatDiscount], [isAll], [goodsBlackList], [discountType], [discountValue], [rule], [status], [setMan], [setTime], [isOnlyMember], [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}');"; 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.ValidMonth, entity.IsRepeatDiscount, entity.IsAll, entity.GoodsBlackList, entity.DiscountType, entity.DiscountValue, entity.Rule, entity.Status, entity.SetMan, entity.SetTime, entity.IsOnlyMember, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店优惠券 /// /// 门店优惠券数据下载 /// /// public static DownloadNotify DownloadStoreCoupon(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreCoupon; 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", "store.coupon.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) { if (CacheStoreCoupon(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreCouponError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreCouponError; 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.PromotionStoreCouponError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreCouponException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadStoreCouponNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreCoupon; 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.coupon.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) { if (CacheStoreCoupon(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreCouponError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreCouponError; 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.PromotionStoreCouponError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.PromotionStoreCouponException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的门店优惠券信息 /// /// /// private static bool CacheStoreCoupon(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "门店促销信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_store_coupon];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "INSERT INTO pos_store_coupon (id, tenantId, name, startDate, endDate, startTime, endTime, weekDays, validMonth, description, type, rule, status,voucherFlag, createDate, createUser)values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}');"; foreach (var entity in lists) { string sql = string.Format(template, entity.Id, Global.Instance.Worker.TenantId, entity.Name, entity.StartDate, entity.EndDate, entity.StartTime, entity.EndTime, entity.WeekDays, entity.ValidMonth, entity.Description, entity.Type, entity.Rule, entity.Status, entity.VoucherFlag, entity.CreateDate, entity.CreateUser); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #endregion #region 总部支付参数下载 /// /// 数据下载 /// /// public static DownloadNotify DownloadRechargeParameter() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.RechargeParameter; 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.recharge.parameter.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) { if (CacheRechargeParameter(notify.CacheName, result.List)) { notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.RechargeParameterError; notify.Message = string.Format("缓存{0}数据发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.RechargeParameterError; 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.RechargeParameterError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.RechargeParameterException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheRechargeParameter(string cacheName, List lists) { bool result = false; string tips = "总部支付参数"; try { //清理数据 FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_recharge_parameter];", CacheName = cacheName }); if (lists.Count() > 0) { string template = "insert into [pos_recharge_parameter] ([id],[tenantId],[no],[name],[sign],[pbody],[certText],[ext1],[ext2],[ext3],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}');"; foreach (var entity in lists) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.No, entity.Name, entity.Sign, JsonUtils.Serialize(entity.Body), entity.CertText, entity.Ext1, entity.Ext2, entity.Ext3, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region POS设置信息下载 /// /// 数据下载 /// /// public static DownloadNotify DownloadSetPlan() { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.SetPlan; 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", "pos.setplan.down"); parameters.Add("storeId", Global.Instance.Authc.StoreId); parameters.Add("terminalType", "x86"); 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 (CacheSetPlan(notify.CacheName, result.Data)) { notify.Success = true; notify.Message = string.Format("{0}下载成功......", tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.SetPlanError; notify.Message = string.Format("缓存{0}数据发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.SetPlanError; 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.SetPlanError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.SetPlanException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的数据 /// /// /// public static bool CacheSetPlan(string cacheName, SetPlan setPlan) { bool result = false; string tips = "总部支付参数"; try { List resourcesList = setPlan.Resources; if (resourcesList != null && resourcesList.Count() > 0) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_resources];", CacheName = cacheName }); string template = "insert into [pos_resources] ([id],[tenantId],[group],[name],[keycode],[keydata],[enable],[permission],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}');"; foreach (var entity in resourcesList) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.Group, entity.Name, entity.KeyCode, entity.KeyData, entity.Enable, entity.PermissionCode, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } List shortcutList = setPlan.Shortcut; if (shortcutList != null && shortcutList.Count() > 0) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_shortcut];", CacheName = cacheName }); string template = "insert into [pos_shortcut] ([id],[tenantId],[area],[parentId],[name],[alias],[keycode],[keydata],[color1],[color2],[color3],[fontSize],[shortcut],[orderNo],[icon],[enable],[resourceId],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}');"; foreach (var entity in shortcutList) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } string sql = string.Format(template, entity.Id, entity.TenantId, entity.Area, entity.ParentId, entity.Name, entity.Alias, entity.KeyCode, entity.KeyData, entity.Color1, entity.Color2, entity.Color3, entity.FontSize, entity.Shortcut, entity.OrderNo, entity.Icon, entity.Enable, entity.ResourceId, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } List moduleList = setPlan.Module; if (moduleList != null && moduleList.Count() > 0) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_module];", CacheName = cacheName }); string template = "insert into [pos_module] ([id],[tenantId],[area],[parentId],[name],[alias],[keycode],[keydata],[color1],[color2],[color3],[fontSize],[shortcut],[orderNo],[icon],[enable],[resourceId],[layout],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}');"; foreach (var entity in moduleList) { if (Global.Instance.Authc != null && entity.TenantId == null) { entity.TenantId = Global.Instance.Authc.TenantId; } if (!"云参数上传".Equals(entity.KeyCode)) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.Area, entity.ParentId, entity.Name, entity.Alias, entity.KeyCode, entity.KeyData, entity.Color1, entity.Color2, entity.Color3, entity.FontSize, entity.Shortcut, entity.OrderNo, entity.Icon, entity.Enable, entity.ResourceId, entity.Layout, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 商品耗料配方信息下载 /// /// 商品耗料配方数据下载 /// /// public static DownloadNotify DownloadProductBurden(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductBurden; 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", "store.product.burden"); 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) { if (CacheProductBurden(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductBurdenError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductBurdenError; 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.ProductBurdenError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductBurdenException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadProductBurdenNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.ProductBurden; 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.burden"); 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) { if (CacheProductBurden(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductBurdenError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.ProductBurdenError; 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.ProductBurdenError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.ProductBurdenException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的商品耗料配方 /// /// /// public static bool CacheProductBurden(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "商品耗料配方信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_product_burden];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_product_burden] ([id],[tenantId],[productId],[specId],[burdenProductId],[burdenSpecId],[salesUnitId],[salesAmount],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}');"; foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.ProductId, entity.SpecId, entity.BurdenProductId, entity.BurdenSpecId, entity.SalesUnitId, entity.SalesAmount, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 做法耗料配方信息下载 /// /// 做法耗料配方数据下载 /// /// public static DownloadNotify DownloadMakeBurden(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.MakeBurden; 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", "store.make.burden"); 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) { if (CacheMakeBurden(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.MakeBurdenError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.MakeBurdenError; 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.MakeBurdenError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.MakeBurdenException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadMakeBurdenNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.MakeBurden; 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.make.burden"); 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) { if (CacheMakeBurden(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.MakeBurdenError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.MakeBurdenError; 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.MakeBurdenError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.MakeBurdenException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的做法耗料配方 /// /// /// public static bool CacheMakeBurden(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "商品耗料配方信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_make_burden];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_make_burden] ([id],[tenantId],[makeId],[burdenProductId],[burdenSpecId],[salesUnitId],[salesAmount],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}');"; foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.MakeId, entity.BurdenProductId, entity.BurdenSpecId, entity.SalesUnitId, entity.SalesAmount, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 门店商品优惠券信息下载 /// /// 门店商品优惠券信息下载 /// /// public static DownloadNotify DownloadStoreProductCoupon(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.StoreProductCoupon; 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", "store.product.coupon.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) { if (CacheStoreProductCoupon(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.StoreProductCouponError; notify.Message = string.Format("缓存{0}发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.StoreProductCouponError; 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.StoreProductCouponError; notify.Message = errorMessage; logger.Info(string.Format("{0}报文解析出错:{1}", tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.StoreProductCouponException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadStoreProductCouponNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.StoreProductCoupon; 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.coupon.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) { if (CacheStoreProductCoupon(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.StoreProductCouponError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.StoreProductCouponError; 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.StoreProductCouponError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.StoreProductCouponException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的商品优惠券 /// /// /// public static bool CacheStoreProductCoupon(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "商品优惠券信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_store_product_coupon];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_store_product_coupon] ([id],[tenantId],[storeId],[ticketId],[ticketNo],[description],[productId],[specId],[couponPrice],[startDate],[startTime],[endDate],[endTime],[weekDays],[createUser],[createDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8},'{9}','{10}','{11}','{12}','{13}','{14}','{15}');"; foreach (var entity in lists) { string sql = string.Format(template, entity.Id, entity.TenantId, entity.StoreId, entity.TicketId, entity.TicketNo, entity.Description, entity.ProductId, entity.SpecId, entity.CouponPrice, entity.StartDate, entity.StartTime, entity.EndDate, entity.EndTime, entity.WeekDays, entity.CreateUser, entity.CreateDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region subin 2023-07-09 add 分店账号信息、菜品分户账户关联信息 #region 分店账号信息下载 /// /// 分店账号信息下载 /// /// /// public static DownloadNotify DownloadSplitShopAccount(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.SplitShopAccount; 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", "splitShopAccount.list"); //parameters.Add("method", "sale.business.splitshops"); parameters.Add("pageNumber", Convert.ToString(notify.PageNumber)); parameters.Add("pageSize", Convert.ToString(pageSize)); parameters.Add("storeId", Global.Instance.Authc.StoreId); 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) { if (CacheSplitShopAccount(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.StoreInfoError; notify.Message = string.Format("缓存{0}数据发生错误", tips); logger.Info(notify.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 { notify.Success = false; notify.Operate = DownloadCacheName.StoreInfoException; notify.Message = string.Format("{0}下载发生异常", tips); } } 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 DownloadNotify DownloadSplitShopAccountNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.SplitShopAccount; 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", "splitShopAccount.list"); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); parameters.Add("storeId", Global.Instance.Authc.StoreId); 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) { if (CacheSplitShopAccount(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.SplitShopAccountError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.SplitShopAccountError; 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.SplitShopAccountError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.SplitShopAccountException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的分店账号信息 /// /// /// /// /// public static bool CacheSplitShopAccount(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "分店账号信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_split_shop_account];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_split_shop_account] ([id],[tenantId],[bizUserId],[shopId],[companyName],[createUser],[createDate],[modifyUser],[modifyDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}');"; foreach (var entity in lists) { string sql = string.Empty; try { sql = string.Format(template, entity.Id, entity.TenantId, entity.BizUserId.Trim(), entity.ShopId.Trim(), entity.CompanyName, entity.CreateUser, entity.CreateDate, entity.ModifyUser, entity.ModifyDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } catch (Exception ex) { logger.Info(sql); logger.Info(ex); } } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #region 菜品分户账户关联表下载 /// /// 分店账号信息下载 /// /// /// public static DownloadNotify DownloadSplitFoodAccount(int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.SplitFoodAccount; 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", "splitFoodAccount.list"); parameters.Add("storeId", Global.Instance.Authc.StoreId); 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) { if (CacheSplitFoodAccount(notify.CacheName, result.List, true)) { //服务端返回的分页信息,用于下一页数据下载 notify.IsPager = result.PageCount > 1; notify.PageNumber = result.PageNumber; notify.PageCount = result.PageCount; notify.PageSize = result.PageSize; notify.Success = true; if (result.PageCount > 1) { notify.Message = string.Format("第" + notify.PageNumber + "页{0}下载成功......", tips); } else { notify.Message = string.Format("{0}下载成功......", tips); } logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.SplitFoodAccountError; notify.Message = string.Format("缓存{0}数据发生错误", tips); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.SplitFoodAccountError; notify.Message = string.Format("<{0}>-{1}", result.ErrCode, result.ErrMessage); logger.Info(string.Format("{0}下载出错:{1}", tips, notify.Message)); } } else { notify.Success = false; notify.Operate = DownloadCacheName.SplitFoodAccountException; notify.Message = string.Format("{0}下载发生异常", tips); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.SplitFoodAccountException; notify.Message = string.Format("{0}下载发生异常", tips); logger.Error(ex, notify.Message); } return notify; } public static DownloadNotify DownloadSplitFoodAccountNextPage(int pageNum, int pageSize) { DownloadNotify notify = new DownloadNotify(); notify.Success = false; notify.Operate = DownloadCacheName.SplitFoodAccount; 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", "splitFoodAccount.list"); parameters.Add("pageNumber", Convert.ToString(pageNum)); parameters.Add("pageSize", Convert.ToString(pageSize)); parameters.Add("storeId", Global.Instance.Authc.StoreId); 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) { if (CacheSplitFoodAccount(notify.CacheName, result.List, false)) { notify.Success = true; notify.Message = string.Format("第{0}页{1}下载成功......", pageNum, tips); logger.Info(result.Message); } else { notify.Success = false; notify.Operate = DownloadCacheName.SplitFoodAccountError; notify.Message = string.Format("缓存{0}第{1}页发生错误", tips, pageNum); logger.Info(notify.Message); } } else { notify.Success = false; notify.Operate = DownloadCacheName.SplitFoodAccountError; 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.SplitFoodAccountError; notify.Message = errorMessage; logger.Info(string.Format("第{0}页{1}报文解析出错:{1}", pageNum, tips, errorMessage)); } } catch (Exception ex) { notify.Success = false; notify.Operate = DownloadCacheName.SplitShopAccountException; notify.Message = string.Format("第{0}页{1}下载发生异常", pageNum, tips); logger.Error(ex, notify.Message); } return notify; } /// /// 处理下载的菜品分户账户关联信息 /// /// /// /// /// public static bool CacheSplitFoodAccount(string cacheName, List lists, bool firstPager = true) { bool result = false; string tips = "菜品分户账户关联信息"; try { //清理数据 if (firstPager) { FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 0, Sql = "delete from [pos_split_food_account];", CacheName = cacheName }); } if (lists.Count() > 0) { string template = "insert into [pos_split_food_account] ([id],[tenantId],[shopId],[goodId],[accountId],[type],[status],[detail],[createUser],[createDate],[modifyUser],[modifyDate]) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}');"; foreach (var entity in lists) { string sql = string.Empty; try { //sql = string.Format(template, entity.splitFoodAccount.Id, entity.splitFoodAccount.TenantId, entity.splitFoodAccount.ShopId, entity.splitFoodAccount.ProductId, entity.splitFoodAccount.AccountId, entity.splitFoodAccount.Type, entity.splitFoodAccount.Status, entity.splitFoodAccount.Detail); sql = string.Format(template, entity.Id, entity.TenantId.Trim(), entity.ShopId.Trim(), entity.ProductId.Trim(), entity.AccountId, entity.Type, entity.Status, entity.Detail, entity.CreateUser, entity.CreateDate, entity.ModifyUser, entity.ModifyDate); FastDownloadApi.Instance.AddCache(new DownloadSqlCache { Id = IdWorkerUtils.Instance.NextId(), Priority = 1, Sql = sql, CacheName = cacheName }); } catch (Exception ex) { logger.Info(sql); logger.Info(ex); } } } result = true; } catch (Exception ex) { logger.Error(ex, string.Format("处理{0}发生异常", tips)); result = false; } return result; } #endregion #endregion } }