schangxiang@126.com
2025-09-17 ff43ddf18764629ff875478e4e47a7281cbd230a
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
using Admin.NET.Core;
using iWareCommon;
using iWareCommon.Utils;
using iWareSql.MyDbContext;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Net.Http;
using System.Threading;
 
namespace iWareCC
{
    /// <summary>
    /// po单收货线程
    /// </summary>
    public class ReceivingPoOrderHandler
    {
        private static object _lock;
        public static void Handler()
        {
            var errMsg = "";
            while (true)
            {
                try
                {
                    SystemWarningMsg.lbl_Alert_ReceivingPoOrderHandler = "循环开始...";
                    if (SystemValue.isAllowRuning_ReceivingPoOrderHandler && SystemValue.isStartedModel)
                    {
                        errMsg = "";//重置
                        try
                        {
                            lock (_lock)
                            {
                                Do(errMsg);
                                if (!string.IsNullOrEmpty(errMsg))
                                {
                                    SystemWarningMsg.lbl_Alert_ReceivingPoOrderHandler = errMsg;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Log4NetHelper.WriteErrorLog(LogType.ReceivingPoOrderHandler, "收货处理的线程=>" + errMsg + ",异常:" + ex.Message, ex);
                            SystemWarningMsg.lbl_Alert_ReceivingPoOrderHandler = "收货处理的线程=>" + errMsg + ",异常:" + ex.Message;
                        }
                    }
                }
                catch (Exception ex)
                {
                    SystemWarningMsg.lbl_Alert_ReceivingPoOrderHandler = "出现异常:" + ex.Message;
                    Log4NetHelper.WriteErrorLog(LogType.ReceivingPoOrderHandler, "PrintHandler 出现异常:" + ex.Message, ex);
                }
                Thread.Sleep(1 * 1000);//休眠40秒
            }
        }
 
 
        /// <summary>
        /// 接收收发货记录
        /// </summary>
        /// <param name="model"></param>
        /// <param name="Lane"></param>
        /// <param name="flag"></param>
        /// <param name="errMsg"></param>
        private static async void Do(string errMsg)
        {
            using (MyDbContext mycontext = new MyDbContext())
            {
 
                var inputData = new UpdateAdapterRecordByCCInput();
                var infoData = new AdapterLogsInfoUpdateInput();
                var recordAdapterIdList = new List<long>();
                var query_ErpPushStatus = 2;
                var receivingList = mycontext.wms_adapter_record.Where(x => (x.IsDelete == false) && x.DealWithStatus == query_ErpPushStatus && x.AdapterMethodName == "PO单收货")
                    .OrderBy(x => x.Id).ToList();
                if (receivingList.Count > 0)
                {
 
                }
                else
                {
                    errMsg = $"没有可收货的内容!";
                    return;
                }
                foreach (var receiving in receivingList)
                {
                    recordAdapterIdList.Add(receiving.Id);
 
                    inputData.ErpVoucher = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
                }
                inputData.RecordAdapterIdList = recordAdapterIdList;
                infoData.RecordAdapterIdList = recordAdapterIdList;
 
                string jsonData = JsonConvert.SerializeObject(inputData);
 
                string apiUrl1 = "http://localhost:5005/api/RecordAdapter/UpdateAdapterRecordByCC";
                string apiUrl2 = "http://localhost:5005/api/RecordAdapter/UpdateAdapterRecordInfo";
                using (var httpClient = new HttpClient())
                {
                    try
                    {
 
                        // 创建HttpContent对象,设置为JSON格式
                        var httpContent = new StringContent(jsonData, System.Text.Encoding.UTF8, "application/json");
 
                        // 发送POST请求
                        var response = await httpClient.PostAsync(apiUrl1, httpContent);
 
                        //// 检查响应是否成功
                        //response.EnsureSuccessStatusCode();
 
                        //// 读取响应内容
                        //string jsonResponse = await response.Content.ReadAsStringAsync();
                        //infoData.AdapterInputInfo = jsonResponse;
                        //string infoJsonData = JsonConvert.SerializeObject(infoData);
                        //var infoHttpContent = new StringContent(infoJsonData, System.Text.Encoding.UTF8, "application/json");
                        //// 发送POST请求
                        //var response2 = await httpClient.PostAsync(apiUrl2, infoHttpContent);
 
 
 
                    }
                    catch (Exception ex)
                    {
                        // 处理异常情况
                        throw ex;
                    }
                }
 
 
 
 
 
 
            }
        }
 
 
 
 
        /// <summary>
        /// 接收收发货记录
        /// </summary>
        /// <param name="model"></param>
        /// <param name="Lane"></param>
        /// <param name="flag"></param>
        /// <param name="errMsg"></param>
        private static void Do2(ref string errMsg)
        {
            using (MyDbContext mycontext = new MyDbContext())
            {
 
                var inputData = new UpdateAdapterRecordByCCInput();
 
                var query_ErpPushStatus = 0;
                var receivingList = mycontext.wms_adapter_record.Where(x => (x.IsDelete == false) && x.DealWithStatus == query_ErpPushStatus)
                    .OrderBy(x => x.Id).ToList();
                if (receivingList.Count > 0)
                {
                    foreach (var item in receivingList)
                    {
                        //判断是否是 PO收货
                        if (1 == 1)
                        {//是PO收货
                         //1、模拟调用SERP
                         //2、模拟调用成功ERP
                         //3、调用成功后- 更新wms_adapter_record的状态
                            item.DealWithStatus = 0;//已处理
                            item.UpdateTime = DateTime.Now;
                            item.UpdateUserName = "调度系统";
 
                            //查询收货记录表 ,更新他的ErpPushStatusEnum值
                            //
                        }
                    }
 
                }
                else
                {
                    errMsg = $"没有可收货的内容!";
                    return;
                }
                foreach (var receiving in receivingList)
                {
 
                    inputData.ErpVoucher = Yitter.IdGenerator.YitIdHelper.NextId().ToString();
                }
                string jsonData = JsonConvert.SerializeObject(inputData);
 
                string apiUrl = "http://localhost:5005/api/RecordAdapter/UpdateAdapterRecordByCC";
                using (var httpClient = new HttpClient())
                {
                    try
                    {
                        // 创建HttpContent对象,设置为JSON格式
                        var httpContent = new StringContent(jsonData, System.Text.Encoding.UTF8, "application/json");
 
                        // 发送POST请求
                        var response = httpClient.PostAsync(apiUrl, httpContent);
 
 
                    }
                    catch (Exception ex)
                    {
                        // 处理异常情况
                        Console.WriteLine($"发生异常:{ex.Message}");
                    }
                }
 
 
 
 
 
 
            }
        }
 
        public class UpdateAdapterRecordByCCInput
        {
            public List<long> RecordAdapterIdList { get; set; }
 
            public string ErpVoucher { get; set; }
        }
 
        public class AdapterLogsInfoUpdateInput
        {
            public List<long> RecordAdapterIdList { get; set; }
 
            public string AdapterInputInfo { get; set; }
        }
 
 
 
 
        private static bool GetPrintClassifyEnum(wms_record_sncode_print item, MyDbContext mycontext, ref string errMsg, ref PrintClassifyEnum printClassifyEnum)
        {
            if (item.PrintType == (int)PrintTypeEnum.看板卡)
            {
                printClassifyEnum = PrintClassifyEnum.看板卡;
            }
            else
            {
                wms_config_sncode_rule rule = null;
                var ruleList = mycontext.wms_config_sncode_rule.Where(x => (x.RuleName == "ASN一维码" || x.RuleName == "ASN二维码") && x.IsDisabled == false).ToList();
                if (ruleList != null && ruleList.Count > 1)
                {
                    errMsg = "条码生成规则配置中,ASN一维码和ASN二维码只能启用其中一个!";
                    return false;
                }
                if (ruleList == null || ruleList.Count == 0)
                {
                    errMsg = "条码生成规则配置中,ASN一维码和ASN二维码两个都没有配置启用!";
                    return false;
                }
                rule = ruleList.First();
 
                printClassifyEnum = default(PrintClassifyEnum);
                if (rule.RuleName == "ASN一维码")
                {
                    printClassifyEnum = PrintClassifyEnum.一维跟踪码;
                }
                else
                {
                    printClassifyEnum = PrintClassifyEnum.二维跟踪码;
                }
            }
 
            return true;
 
        }
 
    }
}