public void CustomerServiceApiTest_GetCustomerAccountList() { var result = _weChatApi.GetCustomerAccountList(); if (!result.IsSuccess()) { Assert.Fail("获取多客服账号列表失败,返回结果如下:" + result.DetailResult); } }
/// <summary> /// 同步多客服账号 /// </summary> private async Task <bool> SyncWeChatMKF(bool isUserSync = false, string createBy = null) { var api = new CustomerServiceApi(); api.SetKey(_tenantId); var result = api.GetCustomerAccountList(); if (result.IsSuccess()) { if ((result.AccountList != null) && (result.AccountList.Length != 0)) { _db.WeiChat_KFCInfos.RemoveRange(_db.WeiChat_KFCInfos); _db.SaveChanges(); foreach (var item in result.AccountList) { var mkf = _db.WeiChat_KFCInfos.FirstOrDefault(p => p.Account == item.AccountName); if (mkf == null) { mkf = new WeiChat_KFCInfo { JobNumber = item.JobNumber, NickName = item.NickName, HeadImgUrl = item.HeadUrl, Account = item.AccountName, TenantId = _tenantId, CreateBy = createBy, CreateTime = DateTime.Now }; _db.WeiChat_KFCInfos.Add(mkf); } else { mkf.JobNumber = item.JobNumber; mkf.HeadImgUrl = item.HeadUrl; mkf.NickName = item.NickName; mkf.UpdateBy = createBy; mkf.UpdateTime = DateTime.Now; } } } else { _db.WeiChat_KFCInfos.RemoveRange(_db.WeiChat_KFCInfos); } } var log = new WeiChat_SyncLog { Type = WeiChat_SyncTypes.Sync_MKF, IsUserSync = isUserSync, TenantId = _tenantId, CreateBy = createBy, Message = string.Format("客服账号同步{1}!同步数量:{0}。", result.AccountList == null ? 0 : result.AccountList.Length, result.IsSuccess() ? "成功" : "失败(" + result.DetailResult + ")") }; _db.WeiChat_SyncLogs.Add(log); await _db.SaveChangesAsync(); return(await System.Threading.Tasks.Task.FromResult(true)); }
private void SyncMKF() { var notify = NotifyInfo; var notifier = Notifier; var strs = Parameter.ToString().Split(';'); var tenantId = int.Parse(strs[0]); var userId = strs[1]; var logger = Logger; try { ReportProgress(1, "正在初始化同步信息"); var api = new CustomerServiceApi(); api.SetKey(tenantId); var result = api.GetCustomerAccountList(); if (result.IsSuccess()) { ReportProgress(30, "已成功获取数据:" + result.AccountList.Length); using (var db = new AppDbContext()) { TenantManager.Current.EnableTenantFilter(db, tenantId); if ((result.AccountList != null) && (result.AccountList.Length != 0)) { db.WeiChat_KFCInfos.RemoveRange(db.WeiChat_KFCInfos); db.SaveChanges(); foreach (var item in result.AccountList) { var mkf = new WeiChat_KFCInfo { JobNumber = item.JobNumber, NickName = item.NickName, HeadImgUrl = item.HeadUrl, Account = item.AccountName, TenantId = tenantId, CreateBy = userId, CreateTime = DateTime.Now }; db.WeiChat_KFCInfos.Add(mkf); } } else { db.WeiChat_KFCInfos.RemoveRange(db.WeiChat_KFCInfos); } var count = result.AccountList == null ? 0 : result.AccountList.Length; ReportProgress(90, "正在写入数据,写入数量(" + count + ")..."); db.SaveChanges(); ReportProgress(100, "同步成功!同步数量(" + count + ")。"); } } else { ReportProgress(100, "同步失败!" + result.GetFriendlyMessage()); } } catch (Exception ex) { logger.Log(LoggerLevels.Debug, Title + " 失败!"); logger.LogException(ex); ReportProgress(100, "同步失败!" + ex.Message); return; } }