public void SyncData(ShipInfo info) { dataSyncRecord = recordService.GetRecordByShipId(info.Id); var service = new JdDataService(); if (info.Status == 1) { // 初始化交易订单 //var trades = service.InitTradeSold(info).ToLocalTrades(info); //trades?.ForEach(x => //{ // SaveTrade(info, x, service); //}); //// 初始化商品数据 //var goods = service.QueryShopCatsInfo(info).ToLocalGoods(info); //goods?.ForEach(x => goodInfoService.Add(x)); } else { // 增量数据 //var incrementTrades = service.QueryTradeSoldIncrement(info, dataSyncRecord).ToLocalTrades(info); //incrementTrades?.ForEach(x => //{ // SaveTrade(info, x, service); //}); } // 运营数据 }
/// <summary> /// 更新同步状态 /// </summary> /// <param name="dataSyncRecord"></param> private void UpdateyncRecord(DataSyncRecord dataSyncRecord) { if (dataSyncRecord.Id < 0) { _dataSyncRecordService.Add(dataSyncRecord); } else { _dataSyncRecordService.Update(dataSyncRecord); } }
/// <summary> /// 获取同步状态 /// </summary> /// <param name="virtualShip"></param> /// <returns></returns> private DataSyncRecord GetSyncRecord(ShipInfo virtualShip) { var syncInfo = _dataSyncRecordService.GetRecordByShipId(virtualShip.Id); if (syncInfo == null) { syncInfo = new DataSyncRecord() { LastSynDate = DateTime.Now, LastSynSeriesNum = 1, ShopId = virtualShip.Id, Status = 1, UserId = virtualShip.UserId }; _dataSyncRecordService.Add(syncInfo); } return(syncInfo); }
/// <summary> /// 同步增量交易数据 /// </summary> /// <param name="info"></param> /// <returns></returns> public List <Trade> QueryTradeSoldIncrement(ShipInfo info, DataSyncRecord syncRecord) { ITopClient client = new DefaultTopClient(url, info.AppKey, info.AppSecret); var pageIndex = 1L; TradesSoldIncrementGetResponse rsp = null; var list = new List <Trade>(); do { try { TradesSoldIncrementGetRequest req = new TradesSoldIncrementGetRequest { Fields = "tid,type,status,payment,orders,rx_audit_status", StartModified = syncRecord.LastSynDate, EndModified = DateTime.Now, Status = "TRADE_NO_CREATE_PAY", Type = "fixed", BuyerNick = "zhangsan", ExtType = "service", Tag = "time_card", PageNo = 1L, RateStatus = "RATE_UNBUYER", PageSize = 40L, UseHasNext = true }; rsp = client.Execute(req, info.SessionKey); pageIndex++; if (!rsp.IsError) { list.AddRange(rsp.Trades); } syncRecord.LastSynDate = req.EndModified.Value; } catch (Exception e) { break; } } while (rsp.HasNext); return(list); }
private async Task <DataSyncRecord> GetOrCreateDataSyncRecord(string tenantId, string query) { var record = await dbContext.DataSyncRecords .Where(i => i.TenantId == tenantId) .Where(i => i.Query == query) .FirstOrDefaultAsync(); if (record == null) { var url = $"{Constants.Resources.MSGraph}/{Constants.Resources.MSGraphVersion}/{query}/delta"; record = new DataSyncRecord { Query = query, TenantId = tenantId, DeltaLink = url }; dbContext.DataSyncRecords.Add(record); } return(record); }
private async Task <DataSyncRecord> GetOrCreateDataSyncRecord(string tenantId, string query) { var record = await dbContext.DataSyncRecords .Where(i => i.TenantId == tenantId) .Where(i => i.Query == query) .FirstOrDefaultAsync(); if (record == null) { var url = string.Format("{0}/{1}/{2}?deltaLink=", Constants.Resources.AADGraph, tenantId, query); record = new DataSyncRecord { Query = query, TenantId = tenantId, DeltaLink = url }; dbContext.DataSyncRecords.Add(record); } return(record); }
/// <summary> /// 统计运营监控指标 计算同比环比 /// </summary> /// <param name="u"></param> private void StatisRealMonitorIndicator(ShipInfo virtualShip, int[] enityShipIds, DataSyncRecord syncRecord) { try { // 取出要统计的记录 var monitorResult = _monitorIndicatorRecordService.QueryRecordByShipIds(enityShipIds); if (monitorResult == null || !monitorResult.Any()) { return; } syncRecord.LastSynSeriesNum += 1; syncRecord.LastSynDate = DateTime.Now; // 多个不同店铺的数据按照指标id进行分组 var gp = from p in monitorResult group p by p.IndicatorId into g select new MonitorIndicatorRecord() { IndicatorId = g.Key, Name = g.First().Name, StatisDate = g.First().StatisDate, Unit = g.First().Unit, Value = g.Sum(x => x.Value), IsStatisRecord = true }; foreach (var item in gp) { if (_calcIndicatorIds.Contains(item.IndicatorId)) { var lastMonitorIndicator = _monitorIndicatorRecordService.QueryMonitorIndicator(new Common.DataModel.QueryRecordModel() { SeriesNum = syncRecord.LastSynSeriesNum, UserId = syncRecord.UserId, ShipId = syncRecord.ShopId, IndicatorId = item.IndicatorId }); if (lastMonitorIndicator == null || !lastMonitorIndicator.Any()) { continue; } var match = lastMonitorIndicator.First(); if (match.Value > 0) { item.MoM = (item.Value - match.Value) / match.Value * 100; } } item.ShipInfoId = virtualShip.Id; _monitorIndicatorRecordService.Add(item); } _monitorIndicatorRecordService.RemoveToHistory(modelList: monitorResult.ToArray()); _dataSyncRecordService.Update(syncRecord); } catch (Exception e) { FrameworkLog.LogModel.LogHelper.WriteErrorLog($"StatisMonitorIndicator数据同步失败", e); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(DataSyncRecord model, IDbTransaction transaction = null) { return(_ComplaintInfoRepository.Update(model, transaction)); }
/// <summary> /// 新增 /// </summary> public int Add(DataSyncRecord model, IDbTransaction transaction = null) { return(_ComplaintInfoRepository.Insert(model, transaction)); }