//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);
|
// }
|
// }
|
// }
|
// }
|
//}
|