| | |
| | | /// <summary> |
| | | /// 系统自动日志模板(用于携客云接口调用记录) |
| | | /// </summary> |
| | | private string _logMessage = "【SysAuto】获取携客云送货单。"; |
| | | |
| | | /// <summary> |
| | | /// 请求报文缓存(存储序列化后的JSON请求内容) |
| | | /// </summary> |
| | | private string _requestJson = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 动态响应对象(存储反序列化的携客云接口响应) |
| | | /// </summary> |
| | | private dynamic _responseData = new System.Dynamic.ExpandoObject(); |
| | | |
| | | /// <summary> |
| | | /// 接口执行时间戳(格式:yyyy-MM-dd HH:mm:ss) |
| | | /// </summary> |
| | | private string _executeTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | /// <summary> |
| | | /// 接口调用状态(0-失败 1-成功) |
| | | /// </summary> |
| | | private int sendStatus = 0; |
| | | private string _logMessageDHD = ""; |
| | | |
| | | public dynamic XKY_GET_DHD(XKYGetDhdRequest entity) |
| | | /// <summary> |
| | | /// 系统自动日志模板(用于携客云接口调用记录) |
| | | /// </summary> |
| | | private string _logMessageDhdDetail = ""; |
| | | |
| | | /// <summary> |
| | | /// 系统自动日志模板(用于携客云接口调用记录) |
| | | /// </summary> |
| | | private string _logMessageDhdBar = "【SysAuto】获取携客云送货单条码。"; |
| | | |
| | | public dynamic GetXkyDhd(XKYGetDhdRequest entity) |
| | | { |
| | | _logMessageDHD = "【SysAuto】获取携客云送货单。"; |
| | | /// <summary> |
| | | /// 请求报文缓存(存储序列化后的JSON请求内容) |
| | | /// </summary> |
| | | string _requestJson = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 动态响应对象(存储反序列化的携客云接口响应) |
| | | /// </summary> |
| | | dynamic _responseData = new System.Dynamic.ExpandoObject(); |
| | | |
| | | /// <summary> |
| | | /// 接口执行时间戳(格式:yyyy-MM-dd HH:mm:ss) |
| | | /// </summary> |
| | | string _executeTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | /// <summary> |
| | | /// 接口调用状态(0-失败 1-成功) |
| | | /// </summary> |
| | | int sendStatus = 0; |
| | | |
| | | try |
| | | { |
| | | string ErrorMsg = ""; |
| | |
| | | |
| | | sendStatus = _responseData.result; |
| | | // 原120-131行替换为: |
| | | if (ProcessDeliveryNotice(_responseData) > 0) |
| | | if (SaveDeliveryNotice(_responseData) > 0) |
| | | sendStatus = 1; |
| | | else |
| | | sendStatus = 0; |
| | |
| | | edtUserGuid: Guid.Parse("11111111-1111-1111-1111-111111111111"), |
| | | abtGuid: null, |
| | | abtTable: "DELIVERY_NOTICE", |
| | | detail: _logMessage, |
| | | detail: _logMessageDHD, |
| | | orderNo: "", |
| | | sendJson: _requestJson, |
| | | rtnJson: JsonConvert.SerializeObject(_responseData), |
| | |
| | | edtUserGuid: Guid.Parse("11111111-1111-1111-1111-111111111111"), |
| | | abtGuid: null, |
| | | abtTable: "DELIVERY_NOTICE", |
| | | detail: _logMessage, |
| | | detail: _logMessageDHD, |
| | | orderNo: "", |
| | | sendJson: _requestJson, |
| | | rtnJson: JsonConvert.SerializeObject(_responseData), |
| | |
| | | //} |
| | | |
| | | //对获取到的携客云送货单做处理 |
| | | private int ProcessDeliveryNotice(dynamic responseJson) |
| | | private int SaveDeliveryNotice(dynamic responseJson) |
| | | { |
| | | List<DeliveryNotice> noticeList = JsonConvert.DeserializeObject<List<DeliveryNotice>>(responseJson.dataList.ToString()); |
| | | noticeList.ForEach(n => n.Id = Guid.NewGuid()); |
| | |
| | | }, |
| | | ex => { |
| | | // 增强异常信息 |
| | | _logMessage = _logMessage + $"数据库操作失败:{ex.Message}\n跟踪:{ex.StackTrace}"; |
| | | _logMessageDHD = _logMessageDHD + $"数据库操作失败:{ex.Message}\n跟踪:{ex.StackTrace}"; |
| | | //throw new Exception($"数据库操作失败:{ex.Message}\n跟踪:{ex.StackTrace}"); |
| | | }); |
| | | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | //获取携客云到货单明细 |
| | | public dynamic GetXkyDhdDetail(XKYGetDhdDeatilRequest entity) |
| | | { |
| | | _logMessageDhdDetail = "【SysAuto】获取携客云送货单明细。"; |
| | | /// <summary> |
| | | /// 请求报文缓存(存储序列化后的JSON请求内容) |
| | | /// </summary> |
| | | string _requestJson = string.Empty; |
| | | |
| | | /// <summary> |
| | | /// 动态响应对象(存储反序列化的携客云接口响应) |
| | | /// </summary> |
| | | dynamic _responseData = new System.Dynamic.ExpandoObject(); |
| | | |
| | | /// <summary> |
| | | /// 接口执行时间(格式:yyyy-MM-dd HH:mm:ss) |
| | | /// </summary> |
| | | string _executeTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | |
| | | /// <summary> |
| | | /// 接口调用状态(0-失败 1-成功) |
| | | /// </summary> |
| | | int sendStatus = 0; |
| | | |
| | | try |
| | | { |
| | | string ErrorMsg = ""; |
| | | ApiCommonParam Apiparam = ApiCommonParam.NewApiCommon(); |
| | | |
| | | _executeTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | string sendJson = JsonConvert.SerializeObject(entity); |
| | | ArrayList SQLStringList = new ArrayList(); |
| | | var url = "https://openapi.xiekeyun.com/delivery/getDetail.json"; |
| | | HttpClient httpClient = new HttpClient(); |
| | | httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); |
| | | |
| | | _requestJson = "{\"commonParam\":" + JsonConvert.SerializeObject(Apiparam) + ",\"body\":" + sendJson + "}"; |
| | | byte[] postData = Encoding.UTF8.GetBytes(_requestJson); |
| | | |
| | | // 创建请求对象 |
| | | HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); |
| | | request.Method = "POST"; |
| | | request.ContentType = "application/json"; |
| | | request.ContentLength = postData.Length; |
| | | |
| | | // 发送请求数据 |
| | | using (Stream stream = request.GetRequestStream()) |
| | | { |
| | | stream.Write(postData, 0, postData.Length); |
| | | } |
| | | |
| | | // 发送请求并获取响应 |
| | | HttpWebResponse response = (HttpWebResponse)request.GetResponse(); |
| | | using (Stream stream = response.GetResponseStream()) |
| | | using (StreamReader reader = new StreamReader(stream)) |
| | | { |
| | | string result2 = reader.ReadToEnd(); |
| | | |
| | | _responseData = JsonConvert.DeserializeObject(result2); |
| | | } |
| | | |
| | | |
| | | //// 新增日志记录(在返回响应前) |
| | | //using (var conn = new SqlConnection(DbHelperSQL.strConn)) |
| | | //{ |
| | | // using (var cmd = new SqlCommand("prc_log_create", conn)) |
| | | // { |
| | | // try |
| | | // { |
| | | // conn.Open(); |
| | | // cmd.CommandType = CommandType.StoredProcedure; |
| | | // SqlParameter[] logParams = |
| | | // { |
| | | // new("@edtUserGuid", SqlDbType.UniqueIdentifier) { Value = Guid.Parse("11111111-1111-1111-1111-111111111111") }, |
| | | // new("@abtGuid", SqlDbType.UniqueIdentifier) { Value = DBNull.Value }, |
| | | // new("@abtTable", SqlDbType.NVarChar, 40) { Value = "DELIVERY_NOTICE" }, |
| | | // new("@detail", SqlDbType.NVarChar, 2500) { Value = "【SysAuto】获取携客云送货单。" }, |
| | | // new("@hNo", SqlDbType.NVarChar, 100) { Value = "" }, |
| | | // new("@SendJson", SqlDbType.NVarChar) { Value = json }, |
| | | // new("@RtnJson", SqlDbType.NVarChar) { Value = JsonConvert.SerializeObject(responseJson) }, |
| | | // new("@xkyBeginTime", SqlDbType.NVarChar) { Value = (entity.startDate/1000).ToString() }, |
| | | // new("@xkyEndTime", SqlDbType.NVarChar) { Value = (entity.endDate/1000).ToString()}, |
| | | // new("@sendStatus", SqlDbType.NVarChar) { Value = responseJson.result.ToString()}, |
| | | // new("@executeTime", SqlDbType.NVarChar) { Value = executeTime}, |
| | | // }; |
| | | |
| | | // foreach (var param in logParams) |
| | | // cmd.Parameters.Add(param); |
| | | |
| | | // cmd.ExecuteNonQuery(); |
| | | // } |
| | | // catch (Exception logEx) |
| | | // { |
| | | // // 日志记录失败不中断主流程 |
| | | // Console.WriteLine($"日志记录失败: {logEx.Message}"); |
| | | // } |
| | | // finally |
| | | // { |
| | | // conn.Close(); |
| | | // } |
| | | // } |
| | | //} |
| | | |
| | | if (_responseData.result != 1) |
| | | throw new ApplicationException(_responseData.errorMsg); |
| | | |
| | | sendStatus = _responseData.result; |
| | | // 原120-131行替换为: |
| | | //if (SaveDeliveryNotice(_responseData) > 0) |
| | | // sendStatus = 1; |
| | | //else |
| | | // sendStatus = 0; |
| | | |
| | | var logService = new LogService(); |
| | | logService.CreateLogI( |
| | | db: Db, |
| | | edtUserGuid: Guid.Parse("11111111-1111-1111-1111-111111111111"), |
| | | abtGuid: null, |
| | | abtTable: "DELIVERY_NOTICE", |
| | | detail: _logMessageDHD, |
| | | orderNo: "", |
| | | sendJson: _requestJson, |
| | | rtnJson: JsonConvert.SerializeObject(_responseData), |
| | | xkyBeginTime: "", |
| | | xkyEndTime: "", |
| | | sendStatus: sendStatus, |
| | | executeTime: _executeTimestamp |
| | | ); |
| | | |
| | | return _responseData; |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | var logService = new LogService(); |
| | | logService.CreateLogI( |
| | | db: Db, |
| | | edtUserGuid: Guid.Parse("11111111-1111-1111-1111-111111111111"), |
| | | abtGuid: null, |
| | | abtTable: "DELIVERY_NOTICE", |
| | | detail: _logMessageDHD, |
| | | orderNo: "", |
| | | sendJson: _requestJson, |
| | | rtnJson: JsonConvert.SerializeObject(_responseData), |
| | | xkyBeginTime: "", |
| | | xkyEndTime: "", |
| | | sendStatus: 0, |
| | | executeTime: _executeTimestamp |
| | | ); |
| | | throw new Exception(e.Message); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |