| | |
| | | using System.Net; |
| | | using System.Net.Http.Headers; |
| | | using System.Text; |
| | | using System.Data.SqlClient; |
| | | using System.Data; |
| | | using NewPdaSqlServer.Dto.Xky; |
| | | using static NewPdaSqlServer.Controllers.Warehouse.MesXkyController; |
| | | |
| | | namespace NewPdaSqlServer.service.QC; |
| | |
| | | public class MesXkyService : RepositoryNoEntity |
| | | { |
| | | /// <summary> |
| | | /// 系统自动日志模板(用于携客云接口调用记录) |
| | | /// 送货单日志模板(用于携客云接口调用记录) |
| | | /// </summary> |
| | | private string _logMessageDHD = ""; |
| | | |
| | | /// <summary> |
| | | /// 系统自动日志模板(用于携客云接口调用记录) |
| | | /// 送货单明细日志模板(用于携客云接口调用记录) |
| | | /// </summary> |
| | | private string _logMessageDhdDetail = ""; |
| | | |
| | | /// <summary> |
| | | /// 系统自动日志模板(用于携客云接口调用记录) |
| | | /// 送货单条码日志模板(用于携客云接口调用记录) |
| | | /// </summary> |
| | | private string _logMessageDhdBar = ""; |
| | | |
| | | /// <summary> |
| | | /// 送货单货物送达日志模板(用于携客云接口调用记录) |
| | | /// </summary> |
| | | private string _logMessageDhdHwsd = ""; |
| | | |
| | | //获取携客云到货单 |
| | | public dynamic GetXkyDhd(XKYGetDhdRequest entity) |
| | |
| | | // 新增列表空值检查 |
| | | if (noticeList == null || !noticeList.Any() || noticeList.Count < 1) |
| | | { |
| | | _logMessageDhdBar += $"本次获取收货单数据为空"; |
| | | _logMessageDHD += $"本次获取收货单数据为空"; |
| | | return result; |
| | | } |
| | | |
| | |
| | | private int SaveDeliveryNoticeBar(dynamic responseJson,string deliveryNo) |
| | | { |
| | | var result = 1; |
| | | List<TblBarcodeInformation> noticeList = JsonConvert.DeserializeObject<List<TblBarcodeInformation>>(responseJson.dataList.ToString()); |
| | | |
| | | // 新增列表空值检查 |
| | | if (noticeList == null || !noticeList.Any() || noticeList.Count < 1) |
| | | List<XkyBarcodeDataDto> noticeList = JsonConvert.DeserializeObject<List<XkyBarcodeDataDto>>(responseJson.dataList.ToString()); |
| | | |
| | | if (noticeList == null || !noticeList.Any()) |
| | | { |
| | | _logMessageDhdBar += $"条码数据为空,送货单号:{deliveryNo}"; |
| | | return result; |
| | | } |
| | | |
| | | // 赋值guid和到货单号 |
| | | noticeList.ForEach(n => n.Id = Guid.NewGuid()); |
| | | noticeList.ForEach(n => n.DeliveryNo = deliveryNo); |
| | | noticeList.ForEach(n => n.SynchronousDate = DateTime.Now); |
| | | var barcodeList = noticeList.Select(n => new TblBarcodeInformation |
| | | { |
| | | Id = Guid.NewGuid(), |
| | | DeliveryNo = deliveryNo, |
| | | SynchronousDate = DateTime.Now, |
| | | |
| | | // 直接映射字段 |
| | | ProductCode = n.ProductCode, |
| | | SmallBarcode = n.SmallBarcode, |
| | | BigBarcode = n.BigBarcode, |
| | | OuterBarcode = n.OuterBarcode, |
| | | IncludeQty = n.IncludeQty.ToString(), |
| | | SmallPackageSn = n.SmallPackageSn, |
| | | BigPackageSn = n.BigPackageSn, |
| | | OutPackageSn = n.OuterPackageSn, |
| | | PackLevel = n.PackLevel.ToString(), |
| | | |
| | | Db.Ado.UseTran(() => |
| | | // 尺寸字段映射 |
| | | SmallPackageLength = n.SmallPackageLength?.ToString(), |
| | | SmallPackageWidth = n.SmallPackageWidth?.ToString(), |
| | | SmallPackageHeight = n.SmallPackageHeight?.ToString(), |
| | | BigPackageLength = n.BigPackageLength?.ToString(), |
| | | BigPackageWidth = n.BigPackageWidth?.ToString(), |
| | | BigPackageHeight = n.BigPackageHeight?.ToString(), |
| | | OuterPackageLength = n.OuterPackageLength?.ToString(), |
| | | OuterPackageWidth = n.OuterPackageWidth?.ToString(), |
| | | OuterPackageHeight = n.OuterPackageHeight?.ToString(), |
| | | |
| | | // 动态字段映射 |
| | | PoErpNo = n.DynamicData?.PoErpNo ?? n.PoErpNo, |
| | | PoLineNo = n.DynamicData?.PoLineNo ?? n.PoLineNo, |
| | | InnerVendorCode = n.DynamicData?.InnerVendorCode, |
| | | Customize1 = n.DynamicData?.Customize1, |
| | | Customize2 = n.DynamicData?.Customize2, |
| | | Customize3 = n.DynamicData?.Customize3, |
| | | |
| | | // 其他字段 |
| | | DnLines = n.DnLines // 根据数据库注释,ExtendN01对应项目(单身extendN01),这里映射dnLines |
| | | }).ToList(); |
| | | |
| | | Db.Ado.UseTran(() => |
| | | { |
| | | // 删除关联送货明细数据 |
| | | Db.Deleteable<TblBarcodeInformation>() |
| | | .Where(d => d.DeliveryNo == deliveryNo) |
| | | .ExecuteCommand(); |
| | | .ExecuteCommand(); |
| | | |
| | | // 批量插入优化 |
| | | result = Db.Fastest<TblBarcodeInformation>().BulkCopy(noticeList); |
| | | // 批量插入优化(使用正确的barcodeList) |
| | | result = Db.Fastest<TblBarcodeInformation>().BulkCopy(barcodeList); |
| | | }, |
| | | ex => { |
| | | // 增强异常信息 |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | |
| | | |
| | | public dynamic GetXkyHwsd(XKYGetDhdHwsdRequest entity) |
| | | { |
| | | _logMessageDhdHwsd = "【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/updateDeliveryStatus.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); |
| | | } |
| | | |
| | | if (_responseData.result != 1) |
| | | throw new ApplicationException(_responseData.errorMsg); |
| | | |
| | | sendStatus = _responseData.result; |
| | | |
| | | var logService = new LogService(); |
| | | logService.CreateLogI( |
| | | db: Db, |
| | | edtUserGuid: Guid.Parse("11111111-1111-1111-1111-111111111111"), |
| | | abtGuid: null, |
| | | abtTable: "MES_INV_ITEM_ARN", |
| | | detail: _logMessageDhdBar, |
| | | 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: "MES_INV_ITEM_ARN", |
| | | detail: _logMessageDhdBar + $"系统异常错误:{e.Message}\n跟踪:{e.StackTrace}", |
| | | orderNo: "", |
| | | sendJson: _requestJson, |
| | | rtnJson: JsonConvert.SerializeObject(_responseData), |
| | | xkyBeginTime: "", |
| | | xkyEndTime: "", |
| | | sendStatus: 0, |
| | | executeTime: _executeTimestamp |
| | | ); |
| | | throw new Exception(e.Message); |
| | | } |
| | | |
| | | } |
| | | } |