/// <summary> /// 保存合包接口返回的数据 /// </summary> /// <param name="model"></param> /// <param name="json"></param> /// <param name="rjson"></param> /// <param name="orderList"></param> /// <returns></returns> public Result <bool> SaveCombineResponse(PushDataMethodsModel model, string json, string rjson, List <string> orderList) { var result = new Result <bool>() { HasError = false }; try { var sql = "insert [dbo].[EPC_CombineResponse] ([Number],[ResponseJson],[RequestJson],Parameter)values(@Number,@ResponseJson,@RequestJson,@Parameter)"; sql += @" update [EPC_OrderDetail] set status =4 where first_mile_tracking_id in @orderList; update EPC_Express set Status =4 where TrackingNumber in @orderList";//推送成功之后修改订单状态 using (var conn = OpenConnection("Yanwen_EPC")) { if (string.IsNullOrWhiteSpace(model.Parameter) || model.Parameter.ToUpper() == "NULL") { model.Parameter = "4"; } result.Data = conn.Execute(sql, new { Number = model.Number1, ResponseJson = rjson, RequestJson = json, Parameter = model.Parameter, orderList }) > 0; if (!result.Data) { result.HasError = true; result.ErrorMsg = $"保存合包JSON失败修改行数为0!SQLId[{model.SqlId}],Id[{model.Id}]单号[{model.Number1}]"; return(result); } } } catch (Exception e) { result.HasError = true; result.ErrorMsg = $"保存合包JSON代码异常!SQLId[{model.SqlId}],Id[{model.Id}]单号[{model.Number1}]详情:" + e.Message; return(result); } return(result); }
///// <summary> ///// 修改推送状态是否成功 ///// </summary> ///// <param name="t"></param> ///// <param name="type">0 修改失败 1修改成功</param> ///// <param name="json">json数据</param> ///// <param name="msg">首要错误信息</param> //public void ErrorLog(PushDataMethodsModel t, int type, string json, string msg) //{ // if (!string.IsNullOrWhiteSpace(msg)) // { // Logger.Error($"SqlId[{ t.SqlId}],单号[{ t.Number1}]{msg}"); // PushDataDal.Instance.SavePushMessage(0, t.Number1, msg, "[dbo].[EPC_PushDataMethods]", json); // } // var badState = PushDataDal.Instance.UpState(t, type, "[dbo].[EPC_PushDataMethods]"); // if (badState.HasError) // { // Logger.Error($"单号[{t.Number1}]修改推送状态时出错" + badState.ErrorMsg); // return; // } // if (type == 1) // { // Logger.Info($"SqlId[{t.SqlId}],单号[{t.Number1}]推送成功"); // PushDataDal.Instance.SavePushMessage(1, t.Number1, msg, "EPC_CombineResponse", json); // } //} /// <summary> /// 修改推送状态 /// </summary> /// <param name="t"></param> /// <param name="type">0 失败 1成功</param> /// <param name="qjson">请求json</param> /// <param name="fjson">返回json</param> /// <param name="msg">错误信息</param> /// <param name="node"></param> public void LogMsg(PushDataMethodsModel t, int type, string qjson, string fjson, string msg, string node) { var comstr = $"SqlId[{ t.SqlId}],单号[{ t.Number1}]"; if (type == 0)//失败 { comstr += $"失败!原因:[{msg}] 请求json:{qjson} 返回json:{fjson}"; Logger.Error(comstr); PushDataDal.Instance.SavePushMessage(new PushMessageModel { Type = "0", TaskId = t.Id, Number = t.Number1, Msg = msg, Table = "[dbo].[EPC_PushDataMethods]", Rjson = qjson, Fjson = fjson, Node = node }); } if (type == 1) { comstr += $"成功!"; Logger.Info(comstr); PushDataDal.Instance.SavePushMessage(new PushMessageModel { Type = "0", TaskId = t.Id, Number = t.Number1, Msg = msg, Table = "[dbo].[EPC_PushDataMethods]", Rjson = qjson, Fjson = fjson, Node = node }); } var badState = PushDataDal.Instance.UpState(t, type, "[dbo].[EPC_PushDataMethods]"); if (badState.HasError) { Logger.Error($"[{comstr}]修改推送状态时出错" + badState.ErrorMsg); return; } }
/// <summary> /// 修改状态 /// </summary> /// <param name="model"></param> /// <param name="type"></param> /// <param name="table"></param> /// <returns></returns> public Result <bool> UpState(PushDataMethodsModel model, int type, string table) { var result = new Result <bool>() { HasError = false }; try { var sql = ""; if (type == 0)//失败 { sql = $"update {table} set PushNum = PushNum+1 where Id=@Id and SqlId=@SqlId and StatusId=0"; } if (type == 1)//成功 { sql = $"update {table} set StatusId=1 where Id=@Id and SqlId=@SqlId and StatusId=0"; } if (type == 2)//MQ推送成功 { sql = $"update {table} set StatusId=1 where Id=@Id and StatusId=0"; } if (type == 3)//MQ推送失败 { sql = $"update {table} set PushNum = PushNum+1 where Id=@Id and StatusId=0"; } using (var conn = OpenConnection("Yanwen_EPC")) { result.Data = conn.Execute(sql, new { model.Id, model.SqlId }) > 0; if (!result.Data) { result.HasError = true; result.ErrorMsg = $"更新状态没有成功!SQLId[{model.SqlId}],Id[{model.Id}]单号[{model.Number1}]"; return(result); } } } catch (Exception e) { result.HasError = true; result.ErrorMsg = "更新状态出错!详情:" + e.Message; return(result); } return(result); }
/// <summary> /// 请求 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="t"></param> /// <param name="uri"></param> /// <param name="json"></param> /// <returns></returns> public T PostApi <T>(PushDataMethodsModel t, string uri, string json) { try { var res = CommonApi.Instance.Post(uri, json); if (res.HasError) { //LogMsg(t, 0, json, $"调取WISH接口出错!详情:{res.ErrorMsg}请求JSON:\r\n{json}\r\n返回Json:\r\n {res.Data}"); return(default(T)); } Logger.Info($"SqlId[{ t.SqlId}],单号[{ t.Number1}]返回Json:" + res.Data + "\r\n"); var result = JsonConvert.DeserializeObject <T>(res.Data); return(result); } catch (Exception ex) { //ErrorLog(t, 0, json, $"调取WISH接口出错!详情:{ex.Message} 明细{ex.InnerException}请求JSON:" + json); return(default(T)); } }