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
//using Admin.NET.Core.TaskModule.Enum;
//using autuPrint.printService;
//using iWareCC.Common;
//using iWareCC.Common.Helper;
//using iWareCommon;
//using iWareCommon.Common.Globle;
//using iWareCommon.Utils;
//using iWareModel.Entity.WCS;
//using iWareSql.DataAccess;
//using iWareSql.MyDbContext;
//using Newtonsoft.Json;
//using System;
//using System.Collections.Generic;
//using System.Data.Entity;
//using System.IO;
//using System.Linq;
//using System.Text;
//using System.Threading;
 
//namespace iWareCC
//{
//    /// <summary>
//    ///邮件发送处理线程
//    /// </summary>
//    public static class PoDeliveryHandler
//    {
//        public static async void Handler()
//        {
//            SystemWarningMsg._lbl_Alert_PoDeliveryHandler = "线程开始...";
//            while (true)
//            {
//                var errMsg = "";
 
//                Thread.Sleep(2000);
//                try
//                {
//                    //测试代码
//                    /*
//                    StringBuilder builder = new StringBuilder();
 
//                    builder.AppendLine("物料库存预警,如下:");
//                    MailBaseData mailBaseData = new MailBaseData();
 
//                    string RecipientEmail = ConfigHelper.GetConfigString("RecipientEmail");  // 收件人邮箱地址
 
//                    SMTPManager.MailSending(mailBaseData, RecipientEmail, "物料预警信息", builder.ToString(), "");
 
//                    SystemWarningMsg._lbl_Alert_PoDeliveryHandler = "邮件发送成功";
//                    //*/
 
 
 
//                    if (SystemValue.isAllowRuning_PoDeliveryHandler && SystemValue.isStartedModel)
//                    {
//                        try
//                        {
//                            //发送状态(0 新建 1 发送成功 2发送失败 3:重试N次也发送失败的)
//                            using (MyDbContext dbContext = new MyDbContext())
//                            {
//                                var mailList = await dbContext.ware_send_email_flowing.Where(x => x.SendStatus == 0 || x.SendStatus == 2).OrderBy(x => x.Id).ToListAsync();
 
//                                if (mailList.Count == 0)
//                                {
//                                    Log4NetHelper.WriteInfoLog(LogType.PoDeliveryHandler, "没有邮件要发");
//                                    SystemWarningMsg._lbl_Alert_PoDeliveryHandler = "没有邮件要发";
//                                    continue;
//                                }
//                                SystemWarningMsg._lbl_Alert_PoDeliveryHandler = "需要发送的邮件条数:" + mailList.Count;
 
 
 
//                                MailBaseData mailBaseData = new MailBaseData();
//                                foreach (var item in mailList)
//                                {
//                                    try
//                                    {
//                                        //先改状态再推送
//                                        //成功后,转移到历史记录中
//                                        ware_send_email_flowing_history addHistory = new ware_send_email_flowing_history()
//                                        {
//                                            Id = item.Id,
//                                            SendType = item.SendType,
//                                            Message = item.Message,
//                                            CreatedTime = item.CreatedTime,
//                                            IsDeleted = item.IsDeleted,
//                                            CreatedUserId = item.CreatedUserId,
//                                            CreatedUserName = item.CreatedUserName,
//                                            OrderNo = item.OrderNo,
//                                            SendCount = item.SendCount++,
//                                            SendTime = DateTime.Now,
//                                            Title = item.Title,
//                                            ToEmailAdress = item.ToEmailAdress,
//                                            TypeName = item.TypeName,
//                                            UpdatedTime = item.UpdatedTime,
//                                            UpdatedUserId = item.UpdatedUserId,
//                                            UpdatedUserName = item.UpdatedUserName,
//                                        };
//                                        dbContext.ware_send_email_flowing_history.Add(addHistory);
//                                        dbContext.ware_send_email_flowing.Remove(item);
 
//                                        dbContext.SaveChanges();
 
//                                        SMTPManager.MailSending(mailBaseData, item.ToEmailAdress, item.Title, item.Message, "");
//                                        SystemWarningMsg._lbl_Alert_PoDeliveryHandler = "邮件发送成功";
 
//                                        Log4NetHelper.WriteInfoLog(LogType.PoDeliveryHandler, "邮件发送成功:" + item.Message.ToString());
//                                    }
//                                    catch (Exception ex)
//                                    {
//                                        SystemWarningMsg._lbl_Alert_PoDeliveryHandler = "邮件发送失败:" + ex.Message;
 
//                                        Log4NetHelper.WriteErrorLog(LogType.PoDeliveryHandler, "邮件发送失败:" + item.Message.ToString() + "," + ex.Message, ex);
 
//                                        item.SendCount++;
//                                        item.SendResult = "发送失败";
//                                        item.SendTime = DateTime.Now;
//                                        item.SendStatus = 2;
//                                        if (item.SendCount >= 3)
//                                        {
//                                            item.SendStatus = 3;
//                                        }
//                                        dbContext.SaveChanges();
//                                    }
//                                }
 
//                                Thread.Sleep(2000);
 
//                            }
//                        }
//                        catch (Exception ex)
//                        {
//                            SystemWarningMsg._lbl_Alert_PoDeliveryHandler = "邮件发送处理线程 出现异常:" + ex.Message;
//                            Log4NetHelper.WriteErrorLog(LogType.PoDeliveryHandler, "邮件发送处理线程) 出现异常:" + ex.Message, ex);
//                        }
//                        Thread.Sleep(2000);
//                    }
//                }
//                catch (Exception ex)
//                {
//                    SystemWarningMsg._lbl_Alert_PoDeliveryHandler = "邮件发送处理线程 出现异常:" + ex.Message;
//                    Log4NetHelper.WriteErrorLog(LogType.PoDeliveryHandler, "邮件发送处理线程) 出现异常:" + ex.Message, ex);
//                }
//            }
//        }
//    }
//}