//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("下载地址: 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);
|
// }
|
// }
|
// }
|
// }
|
//}
|