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
//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 StoreWaringMailHandler
//    {
//        public static async void Handler()
//        {
//            SystemWarningMsg._lbl_Alert_StoreWaringMailHandler = "线程开始...";
//            while (true)
//            {
//                /*
//                 * 1、查询数据库中库存预警的数据
//                 * 2、按照预警数据,循环发送邮件 SMTPManager.MailSending
//                 * 3、建议每天执行一次该线程
//                 */
//                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_StoreWaringMailHandler = "邮件发送成功";
//                    //*/
 
 
 
//                    if (SystemValue.isAllowRuning_StoreWaringMailHandler && SystemValue.isStartedModel)
//                    {
//                        try
//                        {
//                            using (MyDbContext dbContext = new MyDbContext())
//                            {
//                                var ware_Stock_Early_WarmingsLst = await dbContext.v_ware_stock_early_warming.ToListAsync();
 
//                                if (ware_Stock_Early_WarmingsLst.Count == 0)
//                                {
//                                    Log4NetHelper.WriteInfoLog(LogType.StoreWaringMailHandler, "没有邮件要发");
//                                    continue;
//                                }
//                                SystemWarningMsg._lbl_Alert_StoreWaringMailHandler = "需要发送的邮件条数:" + ware_Stock_Early_WarmingsLst.Count;
//                                StringBuilder builder = new StringBuilder();
 
//                                builder.AppendLine($"物料库存预警,共{ware_Stock_Early_WarmingsLst.Count}条。如下: <br/> ");
//                                builder.AppendLine("<br/> ");
//                                foreach (var item in ware_Stock_Early_WarmingsLst)
//                                {
//                                    builder.AppendLine("物料编号【" + item.Code + "】,物料名称【" + item.Name + "】,当前库存【" + item.Quantity + "】,最小库存预警值【" + item.Miniquantity + "】,最大库存预警值【" + item.Maxquantity + "】  <br/> ");
//                                }
//                                builder.AppendLine("<br/> ");
//                                builder.AppendLine("下载地址: &nbsp;&nbsp;http://172.27.96.27:5565/#/statistical/inventoryWraning <br/> ");
//                                builder.AppendLine("<br/> ");
//                                builder.AppendLine("请查收!");
 
//                                MailBaseData mailBaseData = new MailBaseData();
 
//                                string RecipientEmail = ConfigHelper.GetConfigString("RecipientEmail");  // 收件人邮箱地址
 
//                                string realFilePath = "";
//                                CreatExcelForMail.creatEXcel(ware_Stock_Early_WarmingsLst, ref realFilePath, ref errMsg);
//                                if (!string.IsNullOrEmpty(errMsg))
//                                {
//                                    SystemWarningMsg._lbl_Alert_StoreWaringMailHandler = errMsg;
//                                    Log4NetHelper.WriteErrorLog(LogType.StoreWaringMailHandler, "库存邮箱预警线程-生成文件出现异常:" + errMsg, null);
//                                    continue;
//                                }
 
//                                SMTPManager.MailSending(mailBaseData, RecipientEmail, "物料库存预警信息", builder.ToString(), realFilePath);
 
 
 
//                                SystemWarningMsg._lbl_Alert_StoreWaringMailHandler = "邮件发送成功";
 
//                                Log4NetHelper.WriteInfoLog(LogType.StoreWaringMailHandler, "邮件发送成功:" + builder.ToString());
 
//                                Thread.Sleep(2000);
//                                //删掉文件
//                                FileHelper.DelectDir(SystemValueUtil.TEMPORARY_MAILWARNING_DIR);
 
//                            }
//                        }
//                        catch (Exception ex)
//                        {
//                            SystemWarningMsg._lbl_Alert_StoreWaringMailHandler = "库存邮箱预警线程 出现异常:" + ex.Message;
//                            Log4NetHelper.WriteErrorLog(LogType.StoreWaringMailHandler, "库存邮箱预警线程) 出现异常:" + ex.Message, ex);
//                        }
 
//                        Thread.Sleep(24 * 60 * 60 * 1000);//每天执行一次 
//                                                          //Thread.Sleep(10 * 1000);//每天执行一次 
//                    }
//                }
//                catch (Exception ex)
//                {
//                    SystemWarningMsg._lbl_Alert_StoreWaringMailHandler = "库存邮箱预警线程 出现异常:" + ex.Message;
//                    Log4NetHelper.WriteErrorLog(LogType.StoreWaringMailHandler, "库存邮箱预警线程) 出现异常:" + ex.Message, ex);
//                }
//            }
//        }
//    }
//}