Exemplo n.º 1
0
        /// <summary>
        /// 批量更新大货订单
        /// </summary>
        /// <param name="clientID"></param>
        /// <param name="token"></param>
        /// <param name="refreshToken"></param>
        /// <returns></returns>
        public static bool UpdateAliBulkOrders(string clientID, string token, string refreshToken, out List <string> failGodesCodes)
        {
            failGodesCodes = new List <string>();
            #region 获取需要更新的阿里大货订单列表
            List <AliOrderUpdateLog> logs = AliOrderBusiness.BaseBusiness.GetAliOrderUpdateLogs(EnumOrderType.LargeOrder, clientID);
            if (logs.Count == 0)
            {
                return(true);
            }
            List <AlibabaSdk.MutableOrder> list = new List <AlibabaSdk.MutableOrder>();
            foreach (var log in logs)
            {
                AlibabaSdk.MutableOrder item = new AlibabaSdk.MutableOrder();
                item.bulkGoodsCode = log.AliOrderCode;
                item.status        = AlibabaSdk.HttpRequest.GetEnumDesc <AlibabaSdk.EnumOrderStageStatus>((AlibabaSdk.EnumOrderStageStatus)log.OrderStatus);
                item.statusDate    = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                item.statusDesc    = string.Empty;

                list.Add(item);
            }
            #endregion

            //分页更新
            var totalCount = list.Count;
            int numb       = 10;
            int size       = (int)Math.Ceiling((decimal)totalCount / numb);

            for (int i = 1; i <= size; i++)
            {
                var qList             = list.Skip((i - 1) * numb).Take(numb).ToList();
                var batchUpdateResult = AlibabaSdk.OrderBusiness.BatchUpdateBulkList(qList, token);
                #region 批量更新打样订单失败
                if (batchUpdateResult.error_code > 0)
                {
                    //token失效
                    if (batchUpdateResult.error_code == 401)
                    {
                        //通过refreshToken获取用户token
                        var tokenResult = AlibabaSdk.OauthBusiness.GetTokenByRefreshToken(refreshToken);
                        if (!string.IsNullOrEmpty(tokenResult.access_token))
                        {
                            token = tokenResult.access_token;
                            AliOrderBusiness.BaseBusiness.UpdateAliOrderDownloadPlanToken(clientID, tokenResult.access_token, refreshToken);

                            batchUpdateResult = AlibabaSdk.OrderBusiness.BatchUpdateBulkList(qList, token);
                        }
                        else
                        {
                            AliOrderBusiness.BaseBusiness.UpdateAliOrderDownloadPlanStatus(clientID, AlibabaSdk.AliOrderPlanStatus.RefreshTokenError, "error_code:" + tokenResult.error_code + " error_message:" + tokenResult.error_message);
                            return(false);
                        }
                    }
                    else
                    {
                        AliOrderBusiness.BaseBusiness.UpdateAliOrderDownloadPlanStatus(clientID, AlibabaSdk.AliOrderPlanStatus.Exception, "error_code:" + batchUpdateResult.error_code + " error_message:" + batchUpdateResult.error_message);
                        return(false);
                    }
                }
                #endregion

                //更新订单更新日志的更新状态成功
                List <string> succeseGodesCodeList = batchUpdateResult.succeseGodesCodeList;
                AliOrderBusiness.BaseBusiness.UpdateAllAliOrderUpdateLogStatus(string.Join(",", succeseGodesCodeList), AlibabaSdk.AliOrderUpdateStatus.Success);

                //更新订单更新日志的更新状态失败
                if (succeseGodesCodeList.Count < list.Count)
                {
                    List <string> failGodesCodeList = new List <string>();
                    foreach (var item in list)
                    {
                        if (!succeseGodesCodeList.Contains(item.bulkGoodsCode))
                        {
                            failGodesCodeList.Add(item.bulkGoodsCode);
                        }
                    }
                    AliOrderBusiness.BaseBusiness.UpdateAllAliOrderUpdateLogStatus(string.Join(",", failGodesCodeList), AlibabaSdk.AliOrderUpdateStatus.Fail);
                    failGodesCodes.AddRange(failGodesCodeList);
                }
            }

            return(failGodesCodes.Count == 0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 批量更新大货订单
        /// </summary>
        /// <param name="clientID"></param>
        /// <param name="token"></param>
        /// <param name="refreshToken"></param>
        /// <returns></returns>
        public static bool UpdateAliBulkOrders(string clientID, string token, string refreshToken, out List<string> failGodesCodes)
        {
            failGodesCodes = new List<string>();
            #region 获取需要更新的阿里大货订单列表
            List<AliOrderUpdateLog> logs = AliOrderBusiness.BaseBusiness.GetAliOrderUpdateLogs(EnumOrderType.LargeOrder, clientID);
            if (logs.Count == 0) return true;
            List<AlibabaSdk.MutableOrder> list = new List<AlibabaSdk.MutableOrder>();
            foreach (var log in logs)
            {
                AlibabaSdk.MutableOrder item = new AlibabaSdk.MutableOrder();
                item.bulkGoodsCode = log.AliOrderCode;
                item.status = AlibabaSdk.HttpRequest.GetEnumDesc<AlibabaSdk.EnumOrderStageStatus>((AlibabaSdk.EnumOrderStageStatus)log.OrderStatus);
                item.statusDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                item.statusDesc = string.Empty;

                list.Add(item);
            }
            #endregion

            //分页更新
            var totalCount = list.Count;
            int numb = 10;
            int size = (int)Math.Ceiling((decimal)totalCount / numb);

            for (int i = 1; i <= size; i++)
            {
                var qList = list.Skip((i - 1) * numb).Take(numb).ToList();
                var batchUpdateResult = AlibabaSdk.OrderBusiness.BatchUpdateBulkList(qList, token);
                #region 批量更新打样订单失败
                if (batchUpdateResult.error_code > 0)
                {
                    //token失效
                    if (batchUpdateResult.error_code == 401)
                    {
                        //通过refreshToken获取用户token
                        var tokenResult = AlibabaSdk.OauthBusiness.GetTokenByRefreshToken(refreshToken);
                        if (!string.IsNullOrEmpty(tokenResult.access_token))
                        {
                            token = tokenResult.access_token;
                            AliOrderBusiness.BaseBusiness.UpdateAliOrderDownloadPlanToken(clientID, tokenResult.access_token, refreshToken);

                            batchUpdateResult = AlibabaSdk.OrderBusiness.BatchUpdateBulkList(qList, token);
                        }
                        else
                        {
                            AliOrderBusiness.BaseBusiness.UpdateAliOrderDownloadPlanStatus(clientID, AlibabaSdk.AliOrderPlanStatus.RefreshTokenError, "error_code:" + tokenResult.error_code + " error_message:" + tokenResult.error_message);
                            return false;
                        }

                    }
                    else
                    {
                        AliOrderBusiness.BaseBusiness.UpdateAliOrderDownloadPlanStatus(clientID, AlibabaSdk.AliOrderPlanStatus.Exception, "error_code:" + batchUpdateResult.error_code + " error_message:" + batchUpdateResult.error_message);
                        return false;
                    }
                }
                #endregion

                //更新订单更新日志的更新状态成功
                List<string> succeseGodesCodeList = batchUpdateResult.succeseGodesCodeList;
                AliOrderBusiness.BaseBusiness.UpdateAllAliOrderUpdateLogStatus(string.Join(",", succeseGodesCodeList), AlibabaSdk.AliOrderUpdateStatus.Success);

                //更新订单更新日志的更新状态失败
                if (succeseGodesCodeList.Count < list.Count)
                {
                    List<string> failGodesCodeList = new List<string>();
                    foreach (var item in list)
                    {
                        if (!succeseGodesCodeList.Contains(item.bulkGoodsCode))
                        {
                            failGodesCodeList.Add(item.bulkGoodsCode);
                        }

                    }
                    AliOrderBusiness.BaseBusiness.UpdateAllAliOrderUpdateLogStatus(string.Join(",", failGodesCodeList), AlibabaSdk.AliOrderUpdateStatus.Fail);
                    failGodesCodes.AddRange(failGodesCodeList);
                }
            }

            return failGodesCodes.Count==0;
        }