1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
using MES.Service.Models;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.util;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Collections;
using System.Data;
using System.Net;
using System.Net.Http.Headers;
using System.Text;
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)
    {
        _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 = "";
            ApiCommonParam Apiparam = ApiCommonParam.NewApiCommon();
 
            _executeTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            //string data_inserted = "{\r\n  \"startDate\": 1746759300000,\r\n  \"endDate\": 1746762300000,\r\n  \"erpCode\": \"GXF001\"\r\n}";
            string sendJson = JsonConvert.SerializeObject(entity);
            ArrayList SQLStringList = new ArrayList();
            // var client = new HttpClient();
            var url = "https://openapi.xiekeyun.com/delivery/getNoList.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("https://openapi.xiekeyun.com/delivery/getNoList.json");
            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;
            //储存送货单号详细
            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: (entity.startDate / 1000).ToString(),
                xkyEndTime: (entity.endDate / 1000).ToString(),
                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+ $"系统异常错误:{e.Message}\n跟踪:{e.StackTrace}",
                orderNo: "",
                sendJson: _requestJson,
                rtnJson: JsonConvert.SerializeObject(_responseData),
                xkyBeginTime: (entity.startDate / 1000).ToString(),
                xkyEndTime: (entity.endDate / 1000).ToString(),
                sendStatus: 0,
                executeTime: _executeTimestamp
            );
            throw new Exception(e.Message);
        }
 
    }
 
    //对获取到的携客云送货单做处理
    private int SaveDeliveryNotice(dynamic responseJson)
    {
        var result = 1;
        List<DeliveryNotice> noticeList = JsonConvert.DeserializeObject<List<DeliveryNotice>>(responseJson.dataList.ToString());
 
        // 新增列表空值检查
        if (noticeList == null || !noticeList.Any() || noticeList.Count < 1)
        {
            _logMessageDHD += $"本次获取收货单数据为空";
            return result;
        }
 
 
        noticeList.ForEach(n => n.Id = Guid.NewGuid());
    
        var deliveryNos = noticeList.Select(n => n.DeliveryNo).Distinct().ToList();
        //var noticeIds = noticeList.Select(n => n.Id).ToList(); // 保持GUID类型
 
        Db.Ado.UseTran(() =>
        {
            // 添加空值检查
            if (deliveryNos.Any())
            {
                // 删除关联送货明细数据
                Db.Deleteable<DeliveryNoticeDetail>()
                .Where(d => deliveryNos.Contains(d.DeliveryNo))
                  .ExecuteCommand();
 
 
                //删除关联送货条码明细
                Db.Deleteable<TblBarcodeInformation>()
                  .Where(b => deliveryNos.Contains(b.DeliveryNo))
                  .ExecuteCommand();
 
                //删除送货单
                Db.Deleteable<DeliveryNotice>()
                  .Where(n => deliveryNos.Contains(n.DeliveryNo))
                  .ExecuteCommand();
            }
 
            // 批量插入优化
            result = Db.Fastest<DeliveryNotice>().BulkCopy(noticeList); 
        }, 
        ex => {
            // 增强异常信息
            //_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);
            }
 
            if (_responseData.result != 1)
                throw new ApplicationException(_responseData.errorMsg);
 
            sendStatus = _responseData.result;
            // 对数据做处理存入mes
            if (SaveDeliveryNoticeDetail(_responseData, entity.deliveryNo) > 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",
                detail: _logMessageDhdDetail,
                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",
                detail: _logMessageDhdDetail + $"系统异常错误:{e.Message}\n跟踪:{e.StackTrace}",
                orderNo: "",
                sendJson: _requestJson,
                rtnJson: JsonConvert.SerializeObject(_responseData),
                xkyBeginTime: "",
                xkyEndTime: "",
                sendStatus: 0,
                executeTime: _executeTimestamp
            );
            throw new Exception(e.Message);
        }
 
    }
 
    //对获取到的携客云送货单做处理
    private int SaveDeliveryNoticeDetail(dynamic responseJson,string deliveryNo)
    {
        var result = 1;
        List<DeliveryNoticeDetail> noticeList = JsonConvert.DeserializeObject<List<DeliveryNoticeDetail>>(responseJson.data.lineList.ToString());
 
        // 新增列表空值检查
        if (noticeList == null || !noticeList.Any() || noticeList.Count < 1)
        {
            _logMessageDhdBar += $"送货明细数据为空,送货单号:{deliveryNo}";
            return result;
        }
 
 
        // 获取送货单号并校验
        var deliveryNoObj = responseJson.data.deliveryNo;
        if (deliveryNoObj == null || string.IsNullOrEmpty(deliveryNoObj.ToString()))
        {
            throw new Exception($"【异常】获取送货单失败:{responseJson}");
        }
        deliveryNo = deliveryNoObj.ToString();
 
        //赋值guid和到货单号
        noticeList.ForEach(n => n.Id = Guid.NewGuid());
        noticeList.ForEach(n => n.DeliveryNo = deliveryNo);
        noticeList.ForEach(n => n.SynchronousDate = DateTime.Now);
 
 
        Db.Ado.UseTran(() =>
        {
            // 删除关联送货明细数据
            Db.Deleteable<DeliveryNoticeDetail>()
            .Where(d => d.DeliveryNo == deliveryNo)
              .ExecuteCommand();
 
            // 批量插入优化
            result = Db.Fastest<DeliveryNoticeDetail>().BulkCopy(noticeList);
        },
        ex => {
            // 增强异常信息
            //_logMessageDhdDetail = _logMessageDhdDetail + $"数据库操作失败:{ex.Message}\n跟踪:{ex.StackTrace}";
            throw new Exception($"数据库操作失败:{ex.Message}\n跟踪:{ex.StackTrace}");
        });
 
        return result;
    }
 
    //获取携客云到货单条码
    public dynamic GetXkyDhdBar(XKYGetDhdDeatilRequest entity)
    {
        _logMessageDhdBar = "【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/barcode/byDeliveryNo.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;
            // 对数据做处理存入mes
            if (SaveDeliveryNoticeBar(_responseData, entity.deliveryNo) > 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: "TBL_BARCODE_INFORMATION",
                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: "TBL_BARCODE_INFORMATION",
                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);
        }
 
    }
 
    //对获取到的携客云送货单条码做处理
    private int SaveDeliveryNoticeBar(dynamic responseJson,string deliveryNo)
    {
        var result = 1;
        List<XkyBarcodeDataDto> noticeList = JsonConvert.DeserializeObject<List<XkyBarcodeDataDto>>(responseJson.dataList.ToString());
 
        if (noticeList == null || !noticeList.Any())
        {
            _logMessageDhdBar += $"条码数据为空,送货单号:{deliveryNo}";
            return result;
        }
 
        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(),
 
            // 尺寸字段映射
            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();
 
            // 批量插入优化(使用正确的barcodeList)
            result = Db.Fastest<TblBarcodeInformation>().BulkCopy(barcodeList);
        },
        ex => {
            // 增强异常信息
            //_logMessageDhdBar = _logMessageDhdBar + $"数据库操作失败:{ex.Message}\n跟踪:{ex.StackTrace}";
            throw new Exception($"数据库操作失败:{ex.Message}\n跟踪:{ex.StackTrace}");
        });
 
        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);
        }
 
    }
}