服务端的TigerApi 框架,基于.NET6 2024 版本
Rodney Chen
2024-05-31 d4c326deaa51e7d4897a84afc339684012b8cfbe
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
using Apache.NMS.ActiveMQ.Commands;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Org.BouncyCastle.Ocsp;
using Rhea.Common;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Security.Policy;
using System.Text;
using System.Threading.Tasks;
using Tiger.IBusiness;
using Tiger.Model;
using Tiger.Model.Minsun;
 
namespace Tiger.Business.WMS
{
    public partial class ErpT100 : IErpT100
    {
        /// <summary>
        /// T100接口URL
        /// </summary>
        public static string t100Url { get; set; } = @"http://172.18.8.11/wstopprd/ws/r/awsp920";
 
        public static List<string> curDeliveryNoList { get; set; } = new List<string>();
 
        /// <summary>
        /// 从T100获取二级供应商接口
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static T100ActionResult<resultStd_data<Parameter3>> GetSecondarySupplyInfo(SupplierInputParameter input)
        {
            var t100Action = new T100Action<actionStd_data<SupplierParameter>>
            {
                key = Guid.NewGuid().ToString("N"),
                type = "sync",
                host = new host
                {
                    prod = "WMS",
                    ip = "",
                    lang = "zh_CN",
                    acct = "tiptop",
                    timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
                },
                datakey = input.datakey,
                //datakey = new Datakey
                //{
                //    EntId = "88",
                //    CompanyId = "XCSJ" //据点 DGXC
                //},
                service = new Service
                {
                    ip = "",
                    prod = "T100",
                    id = "topprd",
                    name = "wms_ge_pmaauc"
                },
                payload = new PayloadData<actionStd_data<SupplierParameter>>
                {
                    std_data = new actionStd_data<SupplierParameter>
                    {
                        parameter = input.parameter
                    }
                }
            };
            var requestJson = JsonConvert.SerializeObject(t100Action);
            var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
            var result = JsonConvert.DeserializeObject<T100ActionResult<resultStd_data<Parameter3>>>(response.Message);
            Logger.Interface.Info($"T100获取二级供应商提交Json: {requestJson},返回Json: {response.Message}");
 
            return result;
        }
 
        /// <summary>
        /// 生成客供料到货单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static T100ActionResult<resultStd_data<Parameter>> GenerateCustReceipt(CustReceiptInputParameter input)
        {
            try
            {
                var t100Action = new T100Action<actionStd_data<Parameter<Detail>>>
                {
                    key = Guid.NewGuid().ToString("N"),
                    type = "sync",
                    host = new host
                    {
                        prod = "WMS",
                        ip = "",
                        lang = "zh_CN",
                        acct = "tiptop",
                        timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
                    },
                    datakey = input.datakey,
                    //datakey = new Datakey
                    //{
                    //    EntId = "108",  //正式 88
                    //    CompanyId = "XCSJ" //据点 DGXC
                    //},
                    service = new Service
                    {
                        ip = "",
                        prod = "T100",
                        id = "topprd",
                        name = "wms_gen_apmt520"
                    },
                    payload = new PayloadData<actionStd_data<Parameter<Detail>>>
                    {
                        std_data = new actionStd_data<Parameter<Detail>>
                        {
                            parameter = input.parameter
                            //parameter = new Parameter<Detail>
                            //{
                            //    pmds000 = "2",
                            //    pmdsdocno = "3453",
                            //    pmdsdocdt = "2023-04-26", //当天时间
                            //    pmds002 = "L36783", //用户ID
                            //    pmds003 = "",
                            //    pmds007 = "C0006", //供应商代码
                            //    pmds010 = "测试客供料无采购收货", //送货单号
                            //    pmdsud001 = "CM017", //二级供应编号
                            //    detail = new List<Detail>
                            //{
                            //    new Detail
                            //    {
                            //        pmdtseq= "1",
                            //        pmdt001= "",
                            //        pmdt002= "",
                            //        pmdt003= "",
                            //        pmdt004= "",
                            //        pmdt006= itemcode, //"K7015AA016141",
                            //        pmdt020= qty,  //"100.00000",
                            //        pmdtud011= "0"
                            //    }
                            //}
                            //}
                        }
                    }
                };
 
                //如果送货单已经在处理,刚不能再重复抛送
                if (!curDeliveryNoList.Contains(input.parameter.pmds010) || input.parameter.pmds010.IsNullOrEmpty())
                {
                    if (!input.parameter.pmds010.IsNullOrEmpty())
                    {
                        curDeliveryNoList.Add(input.parameter.pmds010);
                    }
                    var requestJson = JsonConvert.SerializeObject(t100Action);
                    var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
                    var result = JsonConvert.DeserializeObject<T100ActionResult<resultStd_data<Parameter>>>(response.Message);
                    Logger.Interface.Info($"生成到货单提交Json: {requestJson},返回Json: {response.Message}");
                    curDeliveryNoList.Remove(input.parameter.pmds010);
                    Logger.Interface.Info($"操作单号列表移除当前操作单号[{input.parameter.pmds010}]");
                    return result;
                }
                else
                {
                    T100ActionResult<resultStd_data<Parameter>> ret = new();
                    ret.payload.std_data.execution.code = "-1";
                    ret.payload.std_data.execution.description = $"此单[{input.parameter.pmds010}]正在推送到T100,不能重复推送!";
                    Logger.Interface.Warn($"生成到货单异常,返回: {ret.payload.std_data.execution.description}");
                    return ret;
                }
 
                #region 测试代码
 
                //var result = new T100ActionResult<resultStd_data<Parameter>>()
                //{
                //    payload = new()
                //    {
                //        std_data = new()
                //        {
                //            execution = new()
                //            {
                //                code = "0",
                //                sql_code = "0",
                //                description = "执行成功!",
                //            },
                //            parameter = new()
                //            {
                //                docno = $"DGrec-{DateTime.Now:yyMMddHHmm}",
                //            }
                //        }
                //    }
                //};
                //Logger.Interface.Info($"生成客供料到货单提交Json: {requestJson},返回Json: {{JsonConvert.SerializeObject(result)}}");
 
                #endregion 测试代码
            }
            catch (System.Exception ex)
            {
                curDeliveryNoList.Remove(input.parameter.pmds010);
                Logger.Interface.Error($"生成到货单异常,返回: {ex.Message}");
            }
 
            return new();
        }
 
        /// <summary>
        /// 从T100获取二级供应商接口返回iDropdownlist列表
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public List<iDropdownlist> GetSecondarySupplyInfoToDDL(SupplierInputParameter input)
        {
            List<iDropdownlist> iDropdownlists = new List<iDropdownlist>();
            var list = GetSecondarySupplyInfo(input).payload.std_data.parameter.@return;
            foreach (var item in list)
            {
                iDropdownlist _iDropdownlist = new()
                {
                    label = item.pmaauc003,
                    value = $"{item.pmaauc002},{item.pmaauc001}",
                };
                iDropdownlists.Add(_iDropdownlist);
            }
            return iDropdownlists;
        }
 
        /// <summary>
        /// 生成送检单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static T100ActionResult<resultStd_data<Parameter>> GenerateInspection(InsInputParameter input)
        {
            var t100Action = new T100Action<actionStd_data<InsParameter>>
            {
                key = Guid.NewGuid().ToString("N"),
                type = "sync",
                host = new host
                {
                    prod = "WMS",
                    ip = "",
                    lang = "zh_CN",
                    acct = "tiptop",
                    timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
                },
                datakey = input.datakey,
                //datakey = new Datakey
                //{
                //    EntId = "108",  //正式 88
                //    CompanyId = "XCSJ" //据点 DGXC
                //},
                service = new Service
                {
                    ip = "",
                    prod = "T100",
                    id = "topprd",
                    name = "wms_gen_aqct300"
                },
                payload = new PayloadData<actionStd_data<InsParameter>>
                {
                    std_data = new actionStd_data<InsParameter>
                    {
                        parameter = input.parameter
                    }
                }
            };
            var requestJson = JsonConvert.SerializeObject(t100Action);
            var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
            var result = JsonConvert.DeserializeObject<T100ActionResult<resultStd_data<Parameter>>>(response.Message);
            Logger.Interface.Info($"生成送检单提交Json: {requestJson},返回Json: {response.Message}");
 
            #region 测试代码
 
            //var result = new T100ActionResult<resultStd_data<Parameter>>()
            //{
            //    payload = new()
            //    {
            //        std_data = new()
            //        {
            //            execution = new()
            //            {
            //                code = "0",
            //                sql_code = "0",
            //                description = "执行成功!",
            //            },
            //            parameter = new()
            //            {
            //                docno = $"DGtest-{DateTime.Now:yyMMddHHmm}",
            //            }
            //        }
            //    }
            //};
            //Logger.Interface.Info($"生成送检单提交Json: {requestJson},返回Json: {JsonConvert.SerializeObject(result)}");
 
            #endregion 测试代码
 
            return result;
        }
 
        /// <summary>
        /// 生成其他入库单
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static T100ActionResult<resultStd_data<Parameter>> GenerateOtherIn(OtherInputParameter<Detail4> input)
        {
            var t100Action = new T100Action<actionStd_data<InParameter<Detail4>>>
            {
                key = Guid.NewGuid().ToString("N"),
                type = "sync",
                host = new host
                {
                    prod = "WMS",
                    ip = "",
                    lang = "zh_CN",
                    acct = "tiptop",
                    timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
                },
                datakey = input.datakey,
                service = new Service
                {
                    ip = "",
                    prod = "T100",
                    id = "topprd",
                    name = "wms_gen_apmt570"
                },
                payload = new PayloadData<actionStd_data<InParameter<Detail4>>>
                {
                    std_data = new actionStd_data<InParameter<Detail4>>
                    {
                        parameter = input.parameter
                    }
                }
            };
            var requestJson = JsonConvert.SerializeObject(t100Action);
            var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
            var result = JsonConvert.DeserializeObject<T100ActionResult<resultStd_data<Parameter>>>(response.Message);
            if (result.payload.std_data.execution.code != "0")
            {
                throw new Exception($"T100生成入库单失败,失败原因:{result.payload.std_data.execution.description}");
            }
            Logger.Interface.Info($"生成入库单请求T100,传入参数Json:{requestJson},返回:{response.Message}");
            return result;
        }
 
        /// <summary>
        /// 根据领料单号拉单身
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public T100ActionResult<resultStd_data<reqParameter1>> GetMaterialReqDetail(ReqInputParameter input)
        {
            var t100Action = new T100Action<actionStd_data<reqParameter>>
            {
                key = Guid.NewGuid().ToString("N"),
                type = "sync",
                host = new host
                {
                    prod = "WMS",
                    ip = "",
                    lang = "zh_CN",
                    acct = "tiptop",
                    timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
                },
                datakey = input.datakey,
                service = new Service
                {
                    ip = "",
                    prod = "T100",
                    id = "topprd",
                    name = "wms_erp_wms_getwoissd"
                },
                payload = new PayloadData<actionStd_data<reqParameter>>
                {
                    std_data = new actionStd_data<reqParameter>
                    {
                        parameter = input.parameter
                    }
                }
            };
            var requestJson = JsonConvert.SerializeObject(t100Action);
            var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
            var result = JsonConvert.DeserializeObject<T100ActionResult<resultStd_data<reqParameter1>>>(response.Message);
            Logger.Interface.Info($"根据领料单号拉单身提交Json: {requestJson},返回Json: {response.Message}");
            return result;
        }
 
        /// <summary>
        /// 领料单过账
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static T100ActionResult<resultStd_data<Parameter>> MaterialReqToErp(ReqErpInputParameter input)
        {
            var t100Action = new T100Action<actionStd_data<Parameter4>>
            {
                key = Guid.NewGuid().ToString("N"),
                type = "sync",
                host = new host
                {
                    prod = "WMS",
                    ip = "",
                    lang = "zh_CN",
                    acct = "tiptop",
                    timestamp = DateTime.Now.ToString("yyyyMMddHHMMssfff"),
                },
                datakey = input.datakey,
                service = new Service
                {
                    ip = "",
                    prod = "T100",
                    id = "topprd",
                    name = "wms_gen_asft310"
                },
                payload = new PayloadData<actionStd_data<Parameter4>>
                {
                    std_data = new actionStd_data<Parameter4>
                    {
                        parameter = input.parameter
                    }
                }
            };
            var requestJson = JsonConvert.SerializeObject(t100Action);
            var response = HttpHelper.PostAsync(t100Url, requestJson).Result;
            var result = JsonConvert.DeserializeObject<T100ActionResult<resultStd_data<Parameter>>>(response.Message);
            Logger.Interface.Info($"领料单过账提交Json: {requestJson},返回Json: {response.Message}");
            if (input.datakey.CompanyId == "DGXC")
            {
                Logger.Interface.Info($"领料单[{input.parameter.sfdadocno}]过账Json保存到数据库开始");
                DbClient db = ApiConfig.IsOldVersion ? Biz.DataSource["WMS57"].Client : Business.Biz.Db;
                BIZ_ERP_PROD_OUT entity_h = db.Queryable<BIZ_ERP_PROD_OUT>().Where(x => x.BILLCODE == input.parameter.sfdadocno && x.ERP_BILL_CODE == null).First();
                if (entity_h != null)
                {
                    entity_h.COMMIT_JSON = requestJson;
                    entity_h.COMMIT_MSG = response.Message;
                }
                //数据库处理操作
                var dbTran = db.UseTran(() =>
                {
                    if (entity_h != null)
                    {
                        db.Updateable(entity_h).UpdateColumns(q => new { q.COMMIT_JSON, q.COMMIT_MSG }).ExecuteCommand();
                    }
                });
                if (!dbTran.IsSuccess)
                {
                    Logger.Interface.Error(dbTran.ErrorException);
                    throw dbTran.ErrorException;
                }
                Logger.Interface.Info($"领料单[{input.parameter.sfdadocno}]过账Json保存到数据库结束");
            }
 
            return result;
        }
    }
}