protected void WriteData(List<Jdp> jdps, ShopData shp, DateTime begin, DateTime end, string remark = "同步") { try { List<TradeFullinfoGetResponse> trdf = jdps.Select(k => TopUtils.ParseResponse<TradeFullinfoGetResponse>(k.jdp_response)) .Where(j => !string.IsNullOrEmpty(j.Trade.PayTime)).ToList(); if (null == trdf || trdf.Count < 1) return; using (var blk = new SqlBulkCopy(_con)) { blk.DestinationTableName = "T_ERP_SyncLog"; blk.WriteToServerAdv<T_ERP_SyncLog>(new List<T_ERP_SyncLog> { new T_ERP_SyncLog{ SellerNick=shp.SellerNick,MinDateTime=begin,MaxDateTime=end,Remark=remark,JdpCounts=jdps.Count,JdpResCounts=trdf.Count }}, Exclude); } var trdpayed = trdf.Select(k => k.Trade).ToList(); if (null == trdpayed || trdpayed.Count < 1) return; var trdpay = Caster.CastTrades(trdpayed); if (null == trdpay || trdpay.Count < 1) return; using (var blk = new SqlBulkCopy(_con)) { blk.DestinationTableName = "T_ERP_TaoBaoATS_Trade"; blk.WriteToServerAdv<T_ERP_TaoBao_Trade>(trdpay, Exclude); blk.DestinationTableName = "T_ERP_TaoBaoATS_Order"; var ords = trdpay.SelectMany(k => k.OrderList).ToList(); blk.WriteToServerAdv<T_ERP_TaoBao_Order>(ords, Exclude); blk.DestinationTableName = "T_ERP_TaoBaoATS_PromotionDetail"; var kpromt = trdpay.Where(j => j.PromotList != null).SelectMany(k => k.PromotList); if (null != kpromt) { try { var promots = kpromt.ToList(); if (null != promots && promots.Count > 0) blk.WriteToServerAdv<T_ERP_TaoBao_PromotionDetail>(promots, Exclude); } catch (Exception ex) { _applog.DebugException(new Exception(string.Format("SHOP:{0} Promot Error:{1}", shp.SellerNick, ex.Message))); } } blk.DestinationTableName = "T_ERP_TaobaoATS_ServiceOrder"; var ksvcs = trdpay.Where(j => j.ServiceOrderList != null).SelectMany(k => k.ServiceOrderList); if (null != ksvcs) { try { var svcs = ksvcs.ToList(); if (null != svcs && svcs.Count > 0) blk.WriteToServerAdv<T_ERP_Taobao_ServiceOrder>(svcs, Exclude); } catch (Exception ex) { _applog.DebugException(new Exception(string.Format("SHOP:{0} SvcOrder Error:{1}", shp.SellerNick, ex.Message))); } } } //登记同步时间 if (remark != "重试") _applog.DebugException(new Exception(string.Format("SHOP:{0} Begin:{1} End:{2} Count:{3}", shp.SellerNick, begin.ToDefaultStr(), end.ToDefaultStr(), jdps.Count))); else _applog.DebugException(new Exception(string.Format("RETRY\tSHOP:{1}\tCOUNT:{0}\tBegin:{2}\tEnd:{3}\tFor Retry Sync.", jdps.Count, shp.SellerNick, begin.ToDefaultStr(), end.ToDefaultStr()))); } catch (Exception ex) { _applog.DebugException(new Exception(string.Format("Shop:{0} Begin:{2} End:{3} Ex:{1}", shp.SellerNick, ex.Message, begin.ToDefaultStr(), end.ToDefaultStr()))); lock (objLock)//加入失败队列重新操作 { QueFail.Enqueue(new T_ERP_SyncLog { SellerNick = shp.SellerNick, MinDateTime = begin, MaxDateTime = end }); } #if DEBUG throw; #else #endif } }
private T_ERP_ShopRefund GetShopRefund(ShopData shop, DateTime begin, DateTime end, List<Jdp> jds, out List<Refund> refs) { List<RefundGetResponse> trdf = jds.Select(k => TopUtils.ParseResponse<RefundGetResponse>(k.jdp_response)) .ToList(); refs = trdf.Select(k => k.Refund).ToList(); Guid shpguid = Guid.NewGuid(); return new T_ERP_ShopRefund() { Begin = begin, End = end, Guid = shpguid, SellerNick = shop.SellerNick, JdpCount = refs.Count }; }
private string GetRefFileID(ShopData shop, DateTime begin, DateTime end, T_ERP_ShopRefund shpRef) { try { using (var blk = new SqlBulkCopy(_con)) { blk.DestinationTableName = shop.RefundTableName; blk.WriteToServer<T_ERP_ShopRefund>(shpRef); } var fileId = SqlHelper.ExecuteScalar(_con, System.Data.CommandType.Text, string.Format("select id from {0} where guid='{1}'", shop.RefundTableName, shpRef.Guid)); var fileName = _filepath + "refund\\" + shop.SellerNick + "\\" + fileId.ToString() + ".json"; if (!File.Exists(_filepath + "test.txt")) { _applog.DebugException(new Exception("路径不合法或者测试文件不存在!")); return string.Empty; } return fileName; } catch (Exception ex) { _applog.DebugException(ex); #if DEBUG throw; #else #endif } }
private T_ERP_ShopTrade GetShopTrade(ShopData shop, DateTime begin, DateTime end, List<Jdp> jds, out List<Trade> trds) { Guid shpguid = Guid.NewGuid(); List<TradeFullinfoGetResponse> trdf = jds.Select(k => TopUtils.ParseResponse<TradeFullinfoGetResponse>(k.jdp_response)) .ToList(); trds = trdf.Select(k => k.Trade).ToList(); var payed = trds.Where(p => !string.IsNullOrEmpty(p.PayTime)); var unpay = trds.Where(p => string.IsNullOrEmpty(p.PayTime)); var step = trds.Where(p => !string.IsNullOrEmpty(p.StepTradeStatus)); return new T_ERP_ShopTrade() { Begin = begin, End = end, Guid = shpguid, SellerNick = shop.SellerNick, JdpCount = trds.Count(), TrdPayed = payed == null ? 0 : payed.Count(), TrdUnPay = unpay == null ? 0 : unpay.Count(), TrdStep = step == null ? 0 : step.Count() }; }