Esempio n. 1
0
        public async Task <bool> AddOrder(TmsOrderModel taobaoOrderModel, string logisticsInterface)
        {
            var entity = CreateMap(taobaoOrderModel, logisticsInterface);

            if (entity == null)
            {
                return(false);
            }

            entity.MSG_TYPE        = "JSON";
            entity.IS_SYNC_SUCCESS = 0;
            entity.CREATE_TIME     = DateTime.Now;
            //利用反射获取类的属性和值,并添加到Hashtable中//foreach (var item in entity.GetType().GetProperties()) { ht.Add(item.Name, item.GetValue(entity)); }
            var pdics = entity.GetType().GetProperties().ToDictionary(item => item.Name, item => item.GetValue(entity));

            try
            {
                return(await Insert(entity));
            }
            catch (Exception e)
            {
                var message = new StringBuilder();
                message.Append("\r\n新增订单写入时数据库发生错误:\r\n" + "外部订单号:" + entity.OUTSYS_ORDER_NO + "\r\n外部运单号:" + entity.OUTSYS_BILL_CODE);
                message.Append("\r\n订单内容:<MySqlOrderData>" + JsonConvert.SerializeObject(entity) + "</MySqlOrderData>");
                message.Append("\r\n" + e.Message + e.StackTrace);
                message.ToString().WriteToLog(LogerType.Error);
                return(false);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 映射数据
 /// </summary>
 /// <param name="taobaoOrderModel"></param>
 /// <param name="logisticsInterface"></param>
 /// <returns></returns>
 private T_MySql_Order CreateMap(TmsOrderModel taobaoOrderModel, string logisticsInterface)
 {
     try
     {
         var mySqlOrder = new T_MySql_Order
         {
             OUTSYS_BILL_CODE = string.IsNullOrEmpty(taobaoOrderModel.mailNo) ? " " : taobaoOrderModel.mailNo,
             OUTSYS_ORDER_NO  = string.IsNullOrEmpty(taobaoOrderModel.logisticsId)
                 ? " "
                 : taobaoOrderModel.logisticsId,
             ORDER_SOURCE = "TAOBAO_ONLINE",
             MSG_TYPE     = "JSON",
             //mySqlOrder.CREATE_BY = "",
             MSG_CONTENT     = string.IsNullOrEmpty(logisticsInterface) ? "" : logisticsInterface,
             IS_SYNC_SUCCESS = 0,
             CREATE_TIME     = DateTime.Now,
             CREATE_BY       = "TAOBAO_ONLINE",
             C1     = "",
             C2     = "",
             C3     = "",
             REMARK = ""
         };
         return(mySqlOrder);
     }
     catch (Exception e)
     {
         var message = new StringBuilder();
         message.Append("TAOBAO订单映射过程发生错误:" + logisticsInterface);
         message.Append(e.Message + e.StackTrace);
         message.ToString().WriteToLog(LogerType.Error);
         return(null);
     }
 }
Esempio n. 3
0
        private static string PostRequest(TmsOrderModel order, KeyValuePair <string, string> item)
        {
            order.logisticsId = item.Key;
            order.mailNo      = item.Value;
            var logisticsInterface = JsonConvert.SerializeObject(order);
            var dataDigest         = SignHelper.CreateDataDigest(logisticsInterface, BaseInfo.SecretKey);

            logisticsInterface = HttpUtility.UrlEncode(logisticsInterface);
            dataDigest         = HttpUtility.UrlEncode(dataDigest);
            var requestModel =
                new Dictionary <string, string>
            {
                ["logistics_interface"] = logisticsInterface,
                ["data_digest"]         = dataDigest,
                ["msg_type"]            = "TMS_CREATE_ORDER_ONLINE_NOTIFY",
                ["msg_id"]      = "DCP00000000000002354032",
                ["ecCompanyId"] = "TAOBAO"
            };

            var sw = new Stopwatch();

            sw.Start();

            var result = Http.PostAsync(requestModel);

            Log.Set($"本次数据提交总计用时:{sw.ElapsedMilliseconds}");
            sw.Stop();
            var model = JsonConvert.DeserializeObject <JObject>(result);

            if (model["success"].ToString().ToLower() == "true")
            {
                Log.Set($"订单提交成功,运单号:{order.mailNo},外部订单号:{order.logisticsId}", LogHandle.LogerType.Info);
            }
            else
            {
                Log.Set($"订单提交失败:{model["errorMsg"]},运单号:{order.mailNo},外部订单号:{order.logisticsId}", LogHandle.LogerType.Error);
            }

            return(result);
        }