yanjinhui
10 小时以前 07b532a6a6adf0a9d965b037cf98c1f98accd138
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
using HslCommunication;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Core;
using WIDESEA_Core.Helper;
using WIDESEA_ISquareCabinServices;
using WIDESEA_Model.Models;
using static WIDESEA_DTO.SquareCabin.OrderDto;
 
namespace WIDESEA_SquareCabinServices
{
    public partial class Business
    {
        #region 获取ERP入库单
        //static string SearchInOrderDate = "2025-11-01 00:00:00";
        //public WebResponseContent GetInOrder()
        //{
        //    WebResponseContent content = new WebResponseContent();
        //    try
        //    {
        //        var url = "http://121.37.118.63:80/GYZ2/95fck/inOrder";
        //        string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        //        if (string.IsNullOrEmpty(SearchInOrderDate)) SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        //        var requestData = new { searchDate = SearchInOrderDate };
        //        //SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        //        var result = HttpHelper.Post(url, requestData.ToJsonString());
        //        var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstreamOrderInfo>>(result);
        //        if (response == null) return content;
        //        if (response.data.Count < 1)
        //        {
        //            SearchInOrderDate = GetOutOrderDate;
        //            return content;
        //        }
        //        var ordernos = response.data.Select(x => x.order_no).ToList();
        //        var existingOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no)).Select(x => x.Order_no).Distinct().ToList();
        //        var newOrders = response.data.Where(order => !existingOrderNos.Contains(order.order_no)).ToList();
        //        if (newOrders.Count < 1)
        //        {
        //            SearchInOrderDate = GetOutOrderDate;
        //            return content;
        //        }
        //        int messQty = 0;
        //        foreach (var order in newOrders)
        //        {
        //            try
        //            {
        //                if (order.order_type == "1")
        //                {
        //                    content = _cabinOrderServices.CreateInboundOrder(order);
        //                    if (!content.Status) messQty++;
        //                }
        //                else if (order.order_type == "3")//入库退料
        //                {
        //                    #region 转换为出库单
        //                    UpstramOutOrderInfo upstramOutOrderInfo = new UpstramOutOrderInfo()
        //                    {
        //                        order_no = order.order_no,
        //                        order_type = order.order_type,
        //                        warehouse_no = order.warehouse_no,
        //                        details = new List<UpstreamOutOrderDetail>()
        //                    };
        //                    foreach (var item in order.details)
        //                    {
        //                        UpstreamOutOrderDetail detail = new UpstreamOutOrderDetail()
        //                        {
        //                            batch_num = item.batch_num,
        //                            goods_no = item.goods_no,
        //                            order_qty = item.order_qty,
        //                            exp_date = item.exp_date,
        //                        };
        //                        upstramOutOrderInfo.details.Add(detail);
        //                    }
        //                    #endregion
        //                    content = _deliveryOrderServices.CreateOutboundOrder(upstramOutOrderInfo);
        //                    if (!content.Status) messQty++;
        //                }
        //                else if (order.order_type == "5")//报溢入库
        //                {
        //                    content = _cabinOrderServices.CreateCheckInOrder(order);
        //                    if (!content.Status) messQty++;
        //                }
        //            }
        //            catch (Exception ex)
        //            {
        //                continue;
        //            }
        //        }
        //        if (messQty == 0) SearchInOrderDate = GetOutOrderDate;
        //        return content.OK();
        //    }
        //    catch (Exception ex)
        //    {
        //        Console.WriteLine("获取ERP入库单信息异常:" + ex.Message);
        //        return content.Error(ex.Message);
        //    }
        //}
        #endregion
 
        #region 获取ERP出库单
        //static string SearchOutOrderDate = "2025-11-01 00:00:00";
        //public WebResponseContent GetOutOrder()
        //{
        //    WebResponseContent content = new WebResponseContent();
        //    try
        //    {
        //        //var url = "http://121.37.118.63:80/GYZ2/95fck/outOrder";
        //         var url = "http://127.0.0.1:4523/m2/5660322-5340849-default/366751306?apifoxApiId=366751306";
        //        string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        //        if (string.IsNullOrEmpty(SearchOutOrderDate)) SearchOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        //        var requestData = new { searchDate = SearchOutOrderDate };
        //        var result = HttpHelper.Post(url, requestData.ToJsonString());
        //        var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstramOutOrderInfo>>(result);
 
        //        if (response == null) return content;
        //        if (response.data.Count < 1)
        //        {
        //            SearchOutOrderDate = GetOutOrderDate;
        //            return content;
        //        }
        //        var ordernos = response.data.Select(x => x.order_no).ToList();
        //        var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no)).Select(x => x.Out_no).Distinct().ToList();
        //        var newOutOrders = response.data.Where(outorder => !existingOutOrderNos.Contains(outorder.order_no)).ToList();
        //        if (newOutOrders.Count < 1)
        //        {
        //            SearchOutOrderDate = GetOutOrderDate;
        //            return content;
        //        }
        //        int messQty = 0;
        //        foreach (var outorder in newOutOrders)
        //        {
        //            if (outorder.order_type == "1")// 正常出库单
        //            {
        //                content = _deliveryOrderServices.CreateOutboundOrder(outorder);
        //                if (!content.Status) messQty++;
        //            }
        //            else if (outorder.order_type == "2")//出库退货
        //            {
        //                #region 转换成入库单
        //                UpstreamOrderInfo order = new UpstreamOrderInfo()
        //                {
        //                    order_no = outorder.order_no,
        //                    order_type = outorder.order_type,
        //                    warehouse_no = outorder.warehouse_no,
        //                    details = new List<UpstreamOrderDetail>()
        //                };
        //                foreach (var item in outorder.details)
        //                {
        //                    UpstreamOrderDetail detail = new UpstreamOrderDetail()
        //                    {
        //                        batch_num = item.batch_num,
        //                        goods_no = item.goods_no,
        //                        order_qty = item.order_qty,
        //                        exp_date = item.exp_date,
        //                    };
        //                    order.details.Add(detail);
        //                }
        //                #endregion
        //                content = _cabinOrderServices.CreateInboundOrder(order);
        //                if (!content.Status) messQty++;
        //            }
        //            else if (outorder.order_type == "6")//报损出库
        //            {
        //                content = _deliveryOrderServices.CreateCheckOutOrder(outorder);
        //                if (!content.Status) messQty++;
        //            }
        //        }
        //        if (messQty == 0) SearchOutOrderDate = GetOutOrderDate;
        //    }
        //    catch (Exception ex)
        //    {
        //        content.Error(ex.Message);
        //    }
        //    return content;
        //}
        #endregion
 
 
 
        #region 获取ERP入库单
        static string SearchInOrderDate = "2025-11-01 00:00:00";
        public WebResponseContent GetInOrder()
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var url = "http://121.37.118.63:80/GYZ2/95fck/inOrder";
                string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (string.IsNullOrEmpty(SearchInOrderDate)) SearchInOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                var requestData = new { searchDate = SearchInOrderDate };
                var result = HttpHelper.Post(url, requestData.ToJsonString());
                var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstreamOrderInfo>>(result);
                if (response == null) return content;
                if (response.data.Count < 1)
                {
                    SearchInOrderDate = GetOutOrderDate;
                    return content;
                }
 
                var ordernos = response.data.Select(x => x.order_no).ToList();
 
                // 关键修改:按订单类型分别检查对应的表
                var inOrderTypes = new List<string> { "1", "5" }; // 入库类型
                var outOrderTypes = new List<string> { "3" };      // 出库类型
 
                // 检查入库单表(只检查入库类型的订单)是否存在
                var existingInOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no))
                    .Select(x => x.Order_no).Distinct().ToList();
 
                // 检查出库单表(只检查出库类型的订单)
                var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no))
                    .Select(x => x.Out_no).Distinct().ToList();
 
                // 筛选新订单:入库类型检查入库表,出库类型检查出库表 选出不包含已存在在
                var newOrders = response.data.Where(order =>
                    (inOrderTypes.Contains(order.order_type) && !existingInOrderNos.Contains(order.order_no)) ||
                    (outOrderTypes.Contains(order.order_type) && !existingOutOrderNos.Contains(order.order_no))
                ).ToList();
 
                if (newOrders.Count < 1)
                {
                    SearchInOrderDate = GetOutOrderDate;
                    return content;
                }
 
                int messQty = 0;
                foreach (var order in newOrders)
                {
                    try
                    {
                        if (order.order_type == "1")
                        {
                            content = _cabinOrderServices.CreateInboundOrder(order);
                            if (!content.Status) messQty++;
                        }
                        else if (order.order_type == "3")//入库退料
                        {
                            #region 转换为出库单
                            UpstramOutOrderInfo upstramOutOrderInfo = new UpstramOutOrderInfo()
                            {
                                order_no = order.order_no,
                                order_type = order.order_type,
                                client_no=order.supplier_no,
                                client_name=order.supplier_name,
                                account_time=order.account_time,
                                warehouse_no = order.warehouse_no,
                                details = new List<UpstreamOutOrderDetail>()
                            };
                            foreach (var item in order.details)
                            {
                                UpstreamOutOrderDetail detail = new UpstreamOutOrderDetail()
                                {
                                    batch_num = item.batch_num,
                                    goods_no = item.goods_no,
                                    order_qty = item.order_qty,
                                    exp_date = item.exp_date,
                                };
                                upstramOutOrderInfo.details.Add(detail);
                            }
                            #endregion
                            content = _deliveryOrderServices.CreateOutboundOrder(upstramOutOrderInfo);
                            if (!content.Status) messQty++;
                        }
                        else if (order.order_type == "5")//报溢入库
                        {
                            content = _cabinOrderServices.CreateCheckInOrder(order);
                            if (!content.Status) messQty++;
                        }
                    }
                    catch (Exception ex)
                    {
                        continue;
                    }
                }
                if (messQty == 0) SearchInOrderDate = GetOutOrderDate;
                return content.OK();
            }
            catch (Exception ex)
            {
                Console.WriteLine("获取ERP入库单信息异常:" + ex.Message);
                return content.Error(ex.Message);
            }
        }
        #endregion
 
        #region 获取ERP出库单
        static string SearchOutOrderDate = "2025-11-01 00:00:00";
        public WebResponseContent GetOutOrder()
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                var url = "http://121.37.118.63:80/GYZ2/95fck/outOrder";
                string GetOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                if (string.IsNullOrEmpty(SearchOutOrderDate)) SearchOutOrderDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                var requestData = new { searchDate = SearchOutOrderDate };
                var result = HttpHelper.Post(url, requestData.ToJsonString());
                var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstramOutOrderInfo>>(result);
 
                if (response == null) return content;
                if (response.data.Count < 1)
                {
                    SearchOutOrderDate = GetOutOrderDate;
                    return content;
                }
 
                var ordernos = response.data.Select(x => x.order_no).ToList();
 
                // 按订单类型分别检查对应的表
                var outOrderTypes = new List<string> { "1", "6" }; // 出库类型
                var inOrderTypes = new List<string> { "2" };       // 入库类型
 
                // 检查出库单表(只检查出库类型的订单)
                var existingOutOrderNos = _deliveryOrderServices.Repository.QueryData(x => ordernos.Contains(x.Out_no))
                    .Select(x => x.Out_no).Distinct().ToList();
 
                // 检查入库单表(只检查入库类型的订单)
                var existingInOrderNos = _cabinOrderServices.Repository.QueryData(x => ordernos.Contains(x.Order_no))
                    .Select(x => x.Order_no).Distinct().ToList();
 
                // 筛选新订单:出库类型检查出库表,入库类型检查入库表
                var newOrders = response.data.Where(order =>
                    (outOrderTypes.Contains(order.order_type) && !existingOutOrderNos.Contains(order.order_no)) ||
                    (inOrderTypes.Contains(order.order_type) && !existingInOrderNos.Contains(order.order_no))
                ).ToList();
 
                if (newOrders.Count < 1)
                {
                    SearchOutOrderDate = GetOutOrderDate;
                    return content;
                }
 
                int messQty = 0;
                foreach (var outorder in newOrders)
                {
                    if (outorder.order_type == "1")// 正常出库单
                    {
                        content = _deliveryOrderServices.CreateOutboundOrder(outorder);
                        if (!content.Status) messQty++;
                    }
                    else if (outorder.order_type == "2")//出库退货
                    {
                        #region 转换成入库单
                        UpstreamOrderInfo order = new UpstreamOrderInfo()
                        {
                            order_no = outorder.order_no,
                            order_type = outorder.order_type,
                            supplier_no=outorder.client_no,
                            supplier_name=outorder.client_name,
                            account_time=outorder.account_time,
                            warehouse_no = outorder.warehouse_no,
                            details = new List<UpstreamOrderDetail>()
                        };
                        foreach (var item in outorder.details)
                        {
                            UpstreamOrderDetail detail = new UpstreamOrderDetail()
                            {
                                batch_num = item.batch_num,
                                goods_no = item.goods_no,
                                order_qty = item.order_qty,
                                exp_date = item.exp_date,
                            };
                            order.details.Add(detail);
                        }
                        #endregion
                        content = _cabinOrderServices.CreateInboundOrder(order);
                        if (!content.Status) messQty++;
                    }
                    else if (outorder.order_type == "6")//报损出库
                    {
                        content = _deliveryOrderServices.CreateCheckOutOrder(outorder);
                        if (!content.Status) messQty++;
                    }
                }
 
                if (messQty == 0) SearchOutOrderDate = GetOutOrderDate;
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            return content;
        }
 
        #endregion  
 
    }
}