Exemplo n.º 1
0
        public EBGetOrderListRequest(string username, string password, EBGetOrderListReqModel reqModel) : base(username, password)
        {
            service.Service   = "getOrderList";
            service.Plateform = "EB";
            IsoDateTimeConverter timeFormat = new IsoDateTimeConverter();

            timeFormat.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
            service.ParamsJson        = JsonConvert.SerializeObject(reqModel, timeFormat);
        }
        public async System.Threading.Tasks.Task RequestTestAsync()
        {
            EBGetOrderListReqModel model = new EBGetOrderListReqModel();

            model.GetAddress = IsOrNotEnum.是;
            model.GetDetail  = IsOrNotEnum.是;
            model.Page       = 1;
            model.PageSize   = 50;

            Conditions    con            = new Conditions();
            List <string> SaleOrderCodes = new List <string> {
                "8008275478477785"
            };

            con.SaleOrderCodes = SaleOrderCodes;

            con.Status      = StatusEnum.待发货;
            model.Condition = con;

            EBGetOrderListRequest req = new EBGetOrderListRequest("admin", "eccang123456", model);
            var response = await req.Request();
        }
Exemplo n.º 3
0
        public override async Task Job(DateTime?datetime = null)
        {
            var models   = new List <ECSalesOrder>();
            var reqModel = new EBGetOrderListReqModel();

            reqModel.Page       = 1;
            reqModel.PageSize   = 10;
            reqModel.GetDetail  = IsOrNotEnum.Yes;
            reqModel.GetAddress = IsOrNotEnum.Yes;
            Conditions conditions = new Conditions();

            conditions.CreatedDateAfter  = DateTime.Parse("2020-03-15");
            conditions.CreatedDateBefore = DateTime.Parse("2020/5/26 12:40:04");
            reqModel.Condition           = conditions;

            using (var uow = _uowProvider.CreateUnitOfWork())
            {
                var repository    = uow.GetRepository <ECSalesOrder>();
                var addRepository = uow.GetRepository <ECSalesOrderAddress>();
                //try
                //{
                //    await repository.DeleteAll();
                //    await addRepository.DeleteAll();
                //    await uow.SaveChangesAsync();
                //}
                //catch (Exception ex)
                //{
                //    log.Error($"初始化产品信息,删除产品信息异常:{ex.Message}");
                //    throw ex;
                //}
                EBGetOrderListRequest req = new EBGetOrderListRequest(login.Username, login.Password, reqModel);
                try
                {
                    var response = await req.Request();

                    response.TotalCount = response.TotalCount == null ? "1" : response.TotalCount;
                    int pageNum = (int)Math.Ceiling(long.Parse(response.TotalCount) * 1.0 / 1000);
                    for (int page = pageNum; page > 0; page--)
                    {
                        reqModel.PageSize = 1000;
                        reqModel.Page     = page;
                        try
                        {
                            req      = new EBGetOrderListRequest(login.Username, login.Password, reqModel);
                            response = await req.Request();
                        }
                        catch (Exception ex)
                        {
                            log.Error($"订单信息,接口调用异常:时间区间{reqModel.Condition.CreatedDateAfter.ToString()}TO{reqModel.Condition.CreatedDateBefore.ToString()}第{page}页;异常信息:{ex.Message}");

                            throw ex;
                        }
                        foreach (var item in response.Body)
                        {
                            try
                            {
                                var m = Mapper <EC_SalesOrder, ECSalesOrder> .Map(item);

                                List <BnsSendDeliverdToEc> templist = new List <BnsSendDeliverdToEc>();
                                BnsSendDeliverdToEc        temp     = new BnsSendDeliverdToEc();
                                temp.ShippingMethodNo = m.ShippingMethodNo;
                                temp.PlatformShipTime = m.PlatformShipTime;
                                templist.Add(temp);
                                m.BnsSendDeliverdToEcs = templist;
                                models.Add(m);
                            }
                            catch (Exception ex)
                            {
                                log.Error($"订单信息,接口调用异常:时间区间{reqModel.Condition.CreatedDateAfter.ToString()}TO{reqModel.Condition.CreatedDateBefore.ToString()}第{page}页;异常信息:{ex.Message}");
                                throw ex;
                            }
                        }

                        try
                        {
                            await repository.BulkInsertAsync(models, x => x.IncludeGraph = true);

                            uow.BulkSaveChanges();
                            models.Clear();
                        }
                        catch (Exception ex)
                        {
                            log.Error($"订单信息,写入数据库异常:时间区间{reqModel.Condition.CreatedDateAfter.ToString()}TO{reqModel.Condition.CreatedDateBefore.ToString()}第{page}页;异常信息:{ex.Message}");
                            throw ex;
                        }
                    }
                }
                catch (Exception ex)
                {
                    log.Error("接口调用出现异常");
                }
            }
        }
 public EBGetOrderListRequest(string username, string password, EBGetOrderListReqModel reqModel) : base(username, password)
 {
     service.Service    = "getOrderList";
     service.Plateform  = "EB";
     service.ParamsJson = JsonConvert.SerializeObject(reqModel);
 }
Exemplo n.º 5
0
        public override async Task Job(DateTime?datetime = null)
        {
            try
            {
                List <ECSalesOrder>    insertList   = new List <ECSalesOrder>();
                List <ECSalesOrder>    updateList   = new List <ECSalesOrder>();
                List <ECSalesOrder>    tempList     = new List <ECSalesOrder>();
                EBGetOrderListReqModel reqModel     = new EBGetOrderListReqModel();
                Conditions             reqCondition = new Conditions();
                reqModel.Page                  = 1;
                reqModel.PageSize              = 10;
                reqModel.GetDetail             = IsOrNotEnum.Yes;
                reqModel.GetAddress            = IsOrNotEnum.Yes;
                reqCondition.CreatedDateBefore = DateTime.Now;
                //List<string> list = new List<string>();
                //list.Add("8014690641387899");
                //reqCondition.RefNos = list;
                reqModel.Condition = reqCondition;
                using (var uow = _uowProvider.CreateUnitOfWork(false, false))
                {
                    var repository = uow.GetRepository <ECSalesOrder>();
                    var rep        = uow.GetRepository <ECSalesOrderAddress>();
                    //reqCondition.CreatedDateAfter = DateTime.Parse("2020-05-24");
                    reqCondition.CreatedDateAfter = ((DateTime)repository.GetPage(0, 1, x => x.OrderByDescending(c => c.CreatedDate)).FirstOrDefault().CreatedDate).AddHours(-3);
                    var updateTime = ((DateTime)repository.GetPage(0, 1, x => x.OrderByDescending(c => c.UpdateDate)).FirstOrDefault().UpdateDate).AddHours(-3);
                    //新增
                    Reqeust.EBGetOrderListRequest req = new EBGetOrderListRequest(login.Username, login.Password, reqModel);
                    log.Info($"订单新增数据 - 开始获取,请求参数:{JsonConvert.SerializeObject(reqModel, new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" })}");
                    var response = await req.Request();

                    response.TotalCount = response.TotalCount == null ? "1" : response.TotalCount;
                    int pageNum = (int)Math.Ceiling(long.Parse(response.TotalCount) * 1.0 / 1000);
                    log.Info($" 订单新增数据 - 共计{pageNum}页");
                    for (int page = 1; page < pageNum + 1; page++)
                    {
                        reqModel.PageSize = 1000;
                        reqModel.Page     = page;
                        try
                        {
                            log.Info($"订单新增数据 - 正在拉取第{page}页");
                            req      = new EBGetOrderListRequest(login.Username, login.Password, reqModel);
                            response = await req.Request();
                        }
                        catch (Exception ex)
                        {
                            log.Error($"订单新增数据 - 接口调用出现异常:{ex.Message}");
                            throw ex;
                        }
                        foreach (var item in response.Body)
                        {
                            try
                            {
                                var m = Mapper <EC_SalesOrder, ECSalesOrder> .Map(item);

                                log.Debug($"订单新增数据 - 接口接收到数据:orderId:{m.OrderId},refno:{m.RefNo},SaleOrderCode:{m.SaleOrderCode},SysOrderCode:{m.SysOrderCode}");

                                var had = repository.Get(m.OrderId, x => x.Include(a => a.BnsSendDeliverdToEcs).Include(a => a.SalesOrderAddress).Include(a => a.OrderDetails));
                                if (had != null)
                                {
                                    List <BnsSendDeliverdToEc> templist = new List <BnsSendDeliverdToEc>();
                                    had.BnsSendDeliverdToEcs[0].ShippingMethodNo = m.ShippingMethodNo;
                                    had.BnsSendDeliverdToEcs[0].PlatformShipTime = m.PlatformShipTime;
                                    templist.Add(had.BnsSendDeliverdToEcs[0]);
                                    m.BnsSendDeliverdToEcs = templist;
                                    m.SalesOrderAddress.Id = had.SalesOrderAddress.Id;

                                    updateList.Add(m);
                                }
                                else
                                {
                                    List <BnsSendDeliverdToEc> templist = new List <BnsSendDeliverdToEc>();
                                    BnsSendDeliverdToEc        temp     = new BnsSendDeliverdToEc();
                                    temp.ShippingMethodNo = m.ShippingMethodNo;
                                    temp.PlatformShipTime = m.PlatformShipTime;
                                    templist.Add(temp);
                                    m.BnsSendDeliverdToEcs = templist;
                                    if (m.PlatformShipTime != null)
                                    {
                                        m.DeliverEmail = true;
                                    }
                                    insertList.Add(m);
                                }
                            }
                            catch (Exception ex)
                            {
                                log.Debug($"订单新增数据 - 转换实体类出现异常:{ex.Message}");
                                throw ex;
                            }
                        }
                        //写入数据库
                        try
                        {
                            insertList = insertList.GroupBy(item => item.OrderId).Select(item => item.First()).ToList();
                            updateList = updateList.GroupBy(item => item.OrderId).Select(item => item.First()).ToList();
                            await repository.BulkInsertAsync(insertList, x => x.IncludeGraph = true);

                            await repository.BulkUpdateAsync(updateList, x => x.IncludeGraph = true);

                            uow.BulkSaveChanges();
                            insertList.Clear();
                            updateList.Clear();
                        }
                        catch (Exception ex)
                        {
                            log.Debug($"订单新增数据 - 写入数据库出现异常:{ex.Message}");
                            throw ex;
                        }
                    }
                    log.Info($"订单新增数据 - 拉取完成");
                    reqCondition.CreatedDateBefore = null;
                    reqCondition.CreatedDateAfter  = null;
                    reqCondition.UpdateDateBefore  = DateTime.Now;
                    reqCondition.UpdateDateAfter   = updateTime;
                    reqModel.Page     = 1;
                    reqModel.PageSize = 10;
                    req = new EBGetOrderListRequest(login.Username, login.Password, reqModel);
                    log.Info($"订单更新数据 - 开始获取 请求参数{JsonConvert.SerializeObject(reqModel, new IsoDateTimeConverter { DateTimeFormat = "yyyy-MM-dd HH:mm:ss" })}");

                    response = await req.Request();

                    response.TotalCount = response.TotalCount == null ? "1" : response.TotalCount;
                    pageNum             = (int)Math.Ceiling(long.Parse(response.TotalCount) * 1.0 / 1000);
                    log.Info($"订单更新数据 - 开始获取 共计{pageNum}页");
                    for (int page = 1; page < pageNum + 1; page++)
                    {
                        reqModel.PageSize = 1000;
                        reqModel.Page     = page;

                        try
                        {
                            log.Info($"订单更新数据 - 第{page}页;");
                            req      = new EBGetOrderListRequest(login.Username, login.Password, reqModel);
                            response = await req.Request();
                        }
                        catch (Exception ex)
                        {
                            log.Error($"订单更新数据 - 接口调用出现异常:{ex.Message}");
                            throw ex;
                        }
                        foreach (var item in response.Body)
                        {
                            try
                            {
                                var m = Mapper <EC_SalesOrder, ECSalesOrder> .Map(item);

                                var had = repository.Get(m.OrderId, x => x.Include(a => a.BnsSendDeliverdToEcs).Include(a => a.SalesOrderAddress).Include(a => a.OrderDetails));
                                if (had != null)
                                {
                                    log.Debug($"订单更新数据 - 接口接收到数据:orderId:{m.OrderId},refno:{m.RefNo},SaleOrderCode:{m.SaleOrderCode},SysOrderCode:{m.SysOrderCode}");
                                    List <BnsSendDeliverdToEc> templist = new List <BnsSendDeliverdToEc>();
                                    had.BnsSendDeliverdToEcs[0].ShippingMethodNo = m.ShippingMethodNo;
                                    had.BnsSendDeliverdToEcs[0].PlatformShipTime = m.PlatformShipTime;
                                    templist.Add(had.BnsSendDeliverdToEcs[0]);
                                    m.BnsSendDeliverdToEcs = templist;
                                    m.SalesOrderAddress.Id = had.SalesOrderAddress.Id;
                                    updateList.Add(m);
                                }
                                else
                                {
                                    log.Debug($"订单更新数据 - 还未插入表忽略,接口接收到数据:orderId:{m.OrderId},refno:{m.RefNo},SaleOrderCode:{m.SaleOrderCode},SysOrderCode:{m.SysOrderCode}");
                                }
                            }
                            catch (Exception ex)
                            {
                                log.Error($"订单更新数据 - 转换实体类出现异常:{ex.Message}");
                                throw ex;
                            }
                        }
                        //写入数据库
                        try
                        {
                            updateList = updateList.GroupBy(item => item.OrderId).Select(item => item.First()).ToList();
                            await repository.BulkUpdateAsync(updateList, x => x.IncludeGraph = true);

                            uow.BulkSaveChanges();
                            updateList.Clear();
                        }
                        catch (Exception ex)
                        {
                            log.Error($"订单更新数据 - 写入数据库异常:{ex.Message}");
                            throw ex;
                        }
                    }
                    log.Info("订单更新数据 - 拉取完成");
                }
            }
            catch (Exception ex)
            {
                log.Error($"订单更新数据 - 出现异常:{ex.Message}");
                throw ex;
            }
            log.Info($"订单数据 - 任务拉取完成");
        }
Exemplo n.º 6
0
        public async System.Threading.Tasks.Task RequestTestAsync()
        {
            EBGetOrderListReqModel reqModel = new EBGetOrderListReqModel();

            reqModel.GetDetail = IsOrNotEnum.Yes;
            reqModel.Page      = 1;
            reqModel.PageSize  = 100;
            Conditions    c    = new Conditions();
            List <string> list = new List <string>();

            list.Add("600153656");
            c.RefNos           = list;
            reqModel.Condition = c;
            EBGetOrderListRequest req = new EBGetOrderListRequest("admin", "longqi123456", reqModel);
            var rr = await req.Request();

            var repository = LogManager.CreateRepository(Common.LogFactory.repositoryName);

            // 指定配置文件
            XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
            var logger    = new Moq.Mock <ILogger <DataAccess> >();
            var sp        = new Moq.Mock <IServiceProvider>();
            var myContext = new Service.Context.XinDBContext(new Microsoft.EntityFrameworkCore.DbContextOptions <Service.Context.XinDBContext>());

            sp.Setup((o) => o.GetService(typeof(IEntityContext))).Returns(myContext);

            sp.Setup((o) => o.GetService(typeof(IRepository <ECSalesOrder>)))
            .Returns(new GenericEntityRepository <ECSalesOrder>(logger.Object));
            var provider = new UowProvider(logger.Object, sp.Object);

            using (var uow = provider.CreateUnitOfWork())
            {
                var repos = uow.GetRepository <ECSalesOrder>();
                List <ECSalesOrder> insertList = new List <ECSalesOrder>();
                List <ECSalesOrder> updateList = new List <ECSalesOrder>();
                foreach (var item in rr.Body)
                {
                    var m = Mapper <EC_SalesOrder, ECSalesOrder> .Map(item);

                    var had = repos.Get(m.OrderId, x => x.Include(a => a.BnsSendDeliverdToEcs));
                    if (had != null)
                    {
                        updateList.Add(m);
                    }
                    else
                    {
                        insertList.Add(m);
                    }
                }
                try
                {
                    insertList = insertList.GroupBy(item => item.OrderId).Select(item => item.First()).ToList();
                    updateList = updateList.GroupBy(item => item.OrderId).Select(item => item.First()).ToList();
                    await repos.BulkInsertAsync(insertList, x => x.IncludeGraph = true);

                    await repos.BulkUpdateAsync(updateList, x => x.IncludeGraph = true);

                    uow.BulkSaveChanges();
                    insertList.Clear();
                    updateList.Clear();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            Assert.Fail();
        }