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
//using iWareCommon.Utils;
//using iWareSql.MyDbContext;
//using Newtonsoft.Json;
//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;
//using System.Threading;
//using System.Threading.Tasks;
 
//namespace iWareCC
//{
//    public class InventorySnapshotHandler
//    {
//        public static string host = ConfigHelper.GetConfigString("WmsApiHost");
//        //public static DateTime? dateTime = null;
//        private static bool isHasRunHour1_Task = false;//是否执行了 每天1点的任务
//        private static bool isHasRunHour23_Month_Task = false;//是否执行了 每个月底的23点执行一次的任务
 
//        public static void Handler()
//        {
//            SystemWarningMsg._lbl_Alert_noti = "线程启动了。。。。";
//            Log4NetHelper.WriteInfoLog(LogType.InventorySnapshotHandler, "消息提醒线程启动了。。。。");
 
//            while (true)
//            {
//                Thread.Sleep(10000);//休眠10秒
//                try
//                {
//                    //DateTime nowdateTime = DateTime.Now;
//                    //if (dateTime == null)
//                    //{
//                    //    dateTime = nowdateTime;
//                    //}
//                    ////每天23点执行一次
//                    //DateTime plantime = ((DateTime)dateTime).Date.AddHours(23);
//                    ////每个月底的23点执行一次
//                    //DateTime d = DateTime.Parse(nowdateTime.ToString("yyyy-MM-01"));
//                    //DateTime plantime2 = d.AddMonths(1).AddDays(-1).Date.AddHours(23);
 
 
 
//                    //if (nowdateTime > plantime)
//                    //{
//                    //    dateTime = ((DateTime)dateTime).AddDays(1);
//                    //}
//                    //if (nowdateTime > plantime2)
//                    //{
//                    //    _Getage();
//                    //}
 
//                    #region 每个月底的23点执行一次
//                    #endregion
//                    // 获取当前日期
//                    DateTime today = DateTime.Now;
//                    // 获取当前月份的最后一天
//                    DateTime lastDayOfMonth = new DateTime(today.Year, today.Month, DateTime.DaysInMonth(today.Year, today.Month));
//                    // 比较当前日期是否是当月的最后一天
//                    if (today.ToString("yyyy-MM-dd") == lastDayOfMonth.ToString("yyyy-MM-dd") && DateTime.Now.Hour == 23)
//                    {
//                        // Console.WriteLine("今天是本月的最后一天。");
//                        if (isHasRunHour23_Month_Task == false)
//                        {
//                            isHasRunHour23_Month_Task = true;
 
//                            //TODO:执行任务
//                            _Getage();
//                        }
//                    }
//                    else
//                    {
//                        //Console.WriteLine("今天不是本月的最后一天。");
//                        isHasRunHour23_Month_Task = false;
//                    }
 
//                    #region 每天1点执行一次
 
//                    //每天1点执行一次
//                    if (DateTime.Now.Hour == 1)
//                    {//1点的时刻
//                        if (isHasRunHour1_Task == false)
//                        {
//                            isHasRunHour1_Task = true;
 
//                            //TODO:执行任务
//                            _Getcurrentstock();
 
//                            _Handlestockwarning();
 
//                            try
//                            {
//                                //库龄预警超期消息
//                                HttpHelper.Post(host + "WareNotifications/wareAge", "");
 
//                                //不需要这个提醒了 【Editby shaocx,2024-01-05】
//                                ////到货提醒
//                                //HttpHelper.Post(host + "WareNotifications/arrival", "");
//                                //发货提醒
//                                HttpHelper.Post(host + "WareNotifications/send", "");
//                                //借用超期消息提醒
//                                HttpHelper.Post(host + "WareNotifications/borrowreturn", "");
 
//                                //领用审核消息
//                                HttpHelper.Post(host + "WareNotifications/usereview", "");
//                                //借用审核消息
//                                HttpHelper.Post(host + "WareNotifications/borrowreview", "");
//                                //盘点审核消息
//                                HttpHelper.Post(host + "WareNotifications/checkreview", "");
 
//                                _SignOvertimeOrEndReceivingOvertimeWarning();
//                                _DeliveryRecordAddOverTimeWarning();
//                            }
//                            catch (Exception ex)
//                            {
//                                SystemWarningMsg._lbl_Alert_noti = "库龄提醒异常" + ex.Message;
//                                Log4NetHelper.WriteErrorLog(LogType.InventorySnapshotHandler, "库龄提醒异常) 出现异常:" + ex.Message, ex);
 
//                            }
//                        }
//                    }
//                    else
//                    {//非1点的时刻
//                        isHasRunHour1_Task = false;
//                    }
 
//                    #endregion
 
//                }
//                catch (Exception ex)
//                {
//                    SystemWarningMsg._lbl_Alert_noti = "消息提醒异常" + ex.Message;
//                    Log4NetHelper.WriteErrorLog(LogType.InventorySnapshotHandler, "消息提醒) 出现异常:" + ex.Message, ex);
//                }
//            }
//        }
 
//        /// <summary>
//        /// //签收超时/收货超时 预警消息
//        /// </summary>
//        private static void _SignOvertimeOrEndReceivingOvertimeWarning()
//        {
//            try
//            {
//                //签收超时/收货超时 预警消息
//                HttpHelper.Post(host + "WareNotifications/SignOvertimeOrEndReceivingOvertimeWarning", "");
//            }
//            catch (Exception ex)
//            {
//                SystemWarningMsg._lbl_Alert_noti = "签收超时/收货超时 预警消息 异常" + ex.Message;
//                Log4NetHelper.WriteErrorLog(LogType.InventorySnapshotHandler, "签收超时/收货超时 预警消息 异常) 出现异常:" + ex.Message, ex);
//            }
//        }
//        /// <summary>
//        /// 发货超时
//        /// </summary>
//        private static void _DeliveryRecordAddOverTimeWarning()
//        {
//            try
//            {
//                //发货超时 预警消息
//                HttpHelper.Post(host + "WareNotifications/DeliveryRecordAddOverTimeWarning", "");
//            }
//            catch (Exception ex)
//            {
//                SystemWarningMsg._lbl_Alert_noti = "发货超时 预警消息 异常" + ex.Message;
//                Log4NetHelper.WriteErrorLog(LogType.InventorySnapshotHandler, "发货超时 预警消息 异常) 出现异常:" + ex.Message, ex);
//            }
//        }
 
//        /// <summary>
//        /// 增加库存快照
//        /// </summary>
//        private static void _Getcurrentstock()
//        {
//            try
//            {
//                //增加库存快照
//                var result = HttpHelper.Post(host + "inventory/material/getcurrentstock", "");
//                Log4NetHelper.WriteInfoLog(LogType.InventorySnapshotHandler, "库存快照" + result);
//            }
//            catch (Exception ex)
//            {
//                SystemWarningMsg._lbl_Alert_noti = "库存快照异常" + ex.Message;
//                Log4NetHelper.WriteErrorLog(LogType.InventorySnapshotHandler, "库存快照异常) 出现异常:" + ex.Message, ex);
 
//            }
//        }
 
//        /// <summary>
//        /// 库存预警
//        /// </summary>
//        private static void _Handlestockwarning()
//        {
//            try
//            {
//                //库存预警
//                HttpHelper.Post(host + "WareNotifications/handlestockwarning", "");
//            }
//            catch (Exception ex)
//            {
//                SystemWarningMsg._lbl_Alert_noti = "库存提醒异常" + ex.Message;
//                Log4NetHelper.WriteErrorLog(LogType.InventorySnapshotHandler, "库存提醒异常) 出现异常:" + ex.Message, ex);
//            }
//        }
 
//        /// <summary>
//        /// 库龄结构
//        /// </summary>
//        private static void _Getage()
//        {
//            try
//            {
//                var result = HttpHelper.Post(host + "/inventory/material/getage", "");
//                Log4NetHelper.WriteInfoLog(LogType.InventorySnapshotHandler, "库龄结构" + result);
//            }
//            catch (Exception ex)
//            {
//                SystemWarningMsg._lbl_Alert_noti = "库龄结构异常" + ex.Message;
//                Log4NetHelper.WriteErrorLog(LogType.InventorySnapshotHandler, "库龄结构异常) 出现异常:" + ex.Message, ex);
 
//            }
//        }
 
//        public static void HandlerDueOrder()
//        {
//            while (true)
//            {
//                Thread.Sleep(1000);//休眠60秒
//                try
//                {
//                    List<ware_due_orders> dueorder = null;
//                    using (MyDbContext dbContext = new MyDbContext())
//                    {
//                        DateTime dateTime = DateTime.Now.AddDays(-1);//当天不解锁
//                        dueorder = dbContext.ware_due_orders.AsNoTracking().Where(u => u.OrderStatus == 1 && u.LockStockTime < dateTime).ToList();
//                    }
//                    if (dueorder != null)
//                    {
//                        if (dueorder.Count > 0)
//                        {
//                            DeliveryOrderDeleteInput input = new DeliveryOrderDeleteInput();
//                            string[] strings = new string[dueorder.Count];
//                            for (int i = 0; i < dueorder.Count; i++)
//                            {
//                                strings[i] = dueorder[i].OrderNo;
//                            }
//                            input.OrderNo = strings;
//                            var jsonstr = JsonConvert.SerializeObject(input);
//                            //解锁库存
//                            var result = HttpHelper.Post(host + "delivery/dueorder/unlock", jsonstr);
//                            dynamic obj = JsonConvert.DeserializeObject(result);
//                            if (obj.success == false)
//                            {
//                                Log4NetHelper.WriteErrorLog(LogType.InventorySnapshotHandler, "库存解锁) 反馈失败:" + result);
//                            }
//                        }
//                    }
//                }
//                catch (Exception ex)
//                {
//                    SystemWarningMsg._lbl_Alert_noti = "预DO单锁库自动解锁异常" + ex.Message;
//                    Log4NetHelper.WriteErrorLog(LogType.InventorySnapshotHandler, "库存解锁) 出现异常:" + ex.Message, ex);
//                }
//            }
//        }
//    }
 
//    public class DeliveryOrderDeleteInput
//    {
//        public string[] OrderNo { get; set; }
//    }
//}