toMailList,string textBody)
+ {
+ // 鍒涘缓 MimeMessage 瀹炰緥
+ MimeMessage message = new MimeMessage();
+ message.From.Add(new MailboxAddress(_emailOptions.SenderName, _emailOptions.SenderEmail)); // 璁剧疆鍙戜欢浜哄鍚嶅拰閭鍦板潃
+ //message.To.Add(new MailboxAddress("Recipient Name", "244188119@qq.com")); // 璁剧疆鏀朵欢浜哄鍚嶅拰閭鍦板潃
+ message.To.AddRange(toMailList);
+ message.Subject = _emailOptions.SendTitle+$"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"; // 璁剧疆閭欢涓婚
+
+ // 鍒涘缓閭欢姝f枃
+ BodyBuilder bodyBuilder = new BodyBuilder();
+ bodyBuilder.TextBody = textBody; // 璁剧疆绾枃鏈唴瀹
+ //bodyBuilder.HtmlBody = "This is a test email sent from .NETCore.MailKit.lst
"; // 璁剧疆 HTML 鍐呭
+ message.Body = bodyBuilder.ToMessageBody();
+
+ try
+ {
+ // 杩炴帴 SMTP 鏈嶅姟鍣ㄥ苟鍙戦侀偖浠
+ using (SmtpClient client = new SmtpClient())
+ {
+ await client.ConnectAsync(_emailOptions.SmtpServer, _emailOptions.SmtpPort, SecureSocketOptions.StartTls); // 杩炴帴 SMTP 鏈嶅姟鍣
+ await client.AuthenticateAsync(_emailOptions.SenderEmail, _emailOptions.SenderEmailPwd); // 杩涜韬唤楠岃瘉
+ await client.SendAsync(message); // 鍙戦侀偖浠
+ await client.DisconnectAsync(true); // 鏂紑杩炴帴
+ }
+ _logger.LogInformation("閭鍙戦佹秷鎭細鎴愬姛->鏀朵欢鏂癸細"+JsonConvert.SerializeObject(toMailList)+" 鍐呭锛"+textBody);
+ return Result.ReSuccess();
+ }
+ catch (Exception ex)
+ {
+ _logger.LogInformation("閭鍙戦佹秷鎭細澶辫触->鏀朵欢鏂癸細" + JsonConvert.SerializeObject(toMailList) + " 鍐呭锛" + textBody);
+ return Result.ReFailure("閭鍙戦佸け璐ワ細"+ex.Message,50006);
+ }
+ }
+
+ ///
+ /// 鑾峰彇鏁版嵁
+ ///
+ ///
+ public async Task>> GetSendContent()
+ {
+ //1.鑾峰彇鐗╂枡闆嗗悎鍜岀粍缁囬泦鍚堝拰渚涘簲鍟嗙殑闆嗗悎
+ var materials = new List();
+ var materials_result = await _erpService.BillQueryForMaterial();
+ if (materials_result.IsSuccess)
+ materials = materials_result.Data.ToList();
+
+ //瀹㈡埛
+ var customerList= await _subscribeNotificationRepositories.GetList();
+ //瑕佸鐞嗗彂閫佺殑鏄庣粏
+ var notSendDetails=await _inStockTaskRepositories.GetNotSendErpDetails();
+
+
+ var sendDataList = new List();
+ if (customerList != null && customerList.Count != 0)
+ {
+ if (notSendDetails != null && notSendDetails.Count != 0)
+ {
+ var taskIds= notSendDetails.GroupBy(x => x.Fid).Select(x => x.Key).ToList();
+
+ var instockTotalDetails= await _inStockRepositories.GetInStockTotalDetails(taskIds);
+ foreach (var item in customerList)
+ {
+ var current_notSendDetails= notSendDetails.Where(x => x.CustomerCode == item.CustomerNumber).ToList();
+ if (current_notSendDetails != null && current_notSendDetails.Count != 0)
+ {
+ var data = new SendDataDto();
+ data.CustomerCode = item.CustomerNumber;
+ data.CustomerName = item.CustomerName;
+ data.PhoneNumbers = string.Join(",", item.Telephones);
+ data.Emails= string.Join(",", item.Emails);
+ foreach (var ema in item.Emails)
+ {
+ data.EmailList.Add(new MailboxAddress("Recipient Name", ema));
+ }
+
+ foreach (var current_det in current_notSendDetails)
+ {
+ var det = new SendDataDetailsDto();
+ det.MaterialName = _erpBasicDataExtendService.GetMaterialName(materials, current_det.MaterialNumber);
+ det.Specifications = _erpBasicDataExtendService.GetMaterialSpecifications(materials, current_det.MaterialNumber);
+ det.MaterialNumber = current_det.MaterialNumber;
+ det.Qty=instockTotalDetails.Where(x => x.TaskId == current_det.Fid && x.MaterialNumber == current_det.MaterialNumber).Sum(x => x.Qty);
+ if (det.Qty > 0)
+ data.Details.Add(det);
+ }
+ if (data.Details.Count != 0)
+ sendDataList.Add(data);
+
+ }
+
+ }
+ }
+ }
+
+ return Result>.ReSuccess(sendDataList);
+ }
+
+ ///
+ /// 鎵ц
+ ///
+ ///
+ public async Task Execute()
+ {
+ try
+ {
+ var sendContentList_result = await this.GetSendContent();
+ if (sendContentList_result.IsSuccess)
+ {
+ var sendContentList = sendContentList_result.Data;
+
+ if (sendContentList != null && sendContentList.Count != 0)
+ {
+
+ foreach (var item in sendContentList)
+ {
+
+ var content = "";
+ int i = 1;
+ foreach (var det in item.Details)
+ {
+ if (i == item.Details.Count)
+ content = det.Specifications + " X 鏁伴噺" + det.Qty;
+ else
+ content = det.Specifications + " X 鏁伴噺" + det.Qty + "锛";
+ i = i + 1;
+
+ }
+ //閭
+ await this.SendEmail(item.EmailList, content);
+ //鐭俊
+ this.SendSms(item.PhoneNumbers, content);
+ }
+ }
+ }
+
+ return Result.ReSuccess();
+ }
+ catch (Exception ex)
+ {
+ return Result.ReFailure("鍙戦佸け璐ワ細"+ex.Message,50006);
+ }
+
+ }
+ }
+}
diff --git a/src/WMS.Web.Domain/WMS.Web.Domain.csproj b/src/WMS.Web.Domain/WMS.Web.Domain.csproj
index 4631f06d..466c2992 100644
--- a/src/WMS.Web.Domain/WMS.Web.Domain.csproj
+++ b/src/WMS.Web.Domain/WMS.Web.Domain.csproj
@@ -20,6 +20,7 @@
+
diff --git a/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs b/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs
index 4f6f65ef..97d471ef 100644
--- a/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs
+++ b/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs
@@ -178,6 +178,13 @@ namespace WMS.Web.Repositories.DependencyInjection
Services.Configure(Configuration.GetSection("OpsOptions"));
Services.AddOptions();
Services.Configure(Configuration.GetSection("Qiniu"));
+ Services.AddOptions();
+ Services.Configure(Configuration.GetSection("EmailOptions"));
+ Services.AddOptions();
+ Services.Configure(Configuration.GetSection("SmsOptions"));
+
+
+
}
///
@@ -296,6 +303,8 @@ namespace WMS.Web.Repositories.DependencyInjection
Services.AddTransient();
Services.AddTransient();
Services.AddTransient();
+ Services.AddTransient();
+
}
}
diff --git a/src/WMS.Web.Repositories/InStockRepositories.cs b/src/WMS.Web.Repositories/InStockRepositories.cs
index 4eb00e19..173acd90 100644
--- a/src/WMS.Web.Repositories/InStockRepositories.cs
+++ b/src/WMS.Web.Repositories/InStockRepositories.cs
@@ -420,5 +420,15 @@ namespace WMS.Web.Repositories
var entity = await _context.InStockErpDetails.OrderByDescending(x => x.Id).FirstOrDefaultAsync();
return entity;
}
+
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task> GetInStockTotalDetails(List taskIds)
+ {
+ return await _context.InStockTotalDetails.Where(x => taskIds.Contains(x.TaskId)).ToListAsync();
+ }
}
}
diff --git a/src/WMS.Web.Repositories/InStockTaskRepositories.cs b/src/WMS.Web.Repositories/InStockTaskRepositories.cs
index 09b71c5c..bfb50e46 100644
--- a/src/WMS.Web.Repositories/InStockTaskRepositories.cs
+++ b/src/WMS.Web.Repositories/InStockTaskRepositories.cs
@@ -141,7 +141,7 @@ namespace WMS.Web.Repositories
if (suppliers_result.IsSuccess)
suppliers = suppliers_result.Data.ToList();
- var entity = await _context.InStockTask.Where(x => x.Id == id).FirstOrDefaultAsync();
+ var entity = await _context.InStockTask.Include(x=>x.Details).Where(x => x.Id == id).FirstOrDefaultAsync();
if (entity != null)
{
@@ -149,8 +149,8 @@ namespace WMS.Web.Repositories
{
Id = entity.Id,
BillNo = entity.BillNo,
- SourceBillNo = entity.SourceBillNo,
- SaleBillNo = entity.SaleBillNo,
+ SaleBillNo= (string.Join(",", entity.Details.Select(x => x.SaleBillNo).ToList()).TrimEnd(',')),
+ SourceBillNo = entity.SourceBillNo,
Status = entity.Status.GetRemark(),
Type = entity.Type.GetRemark(),
Supplier = _erpBasicDataExtendService.GetSupplierName(suppliers, entity.SupplierId??0),
@@ -207,7 +207,11 @@ namespace WMS.Web.Repositories
{
x.SerialNumbers = (string.Join(",", serialNumbList.Where(x => x.MaterialNumber == x.MaterialNumber).Select(x => x.SerialNumber).ToList())).TrimEnd(',');
});
+
+
}
+
+
response.Boxs = boxList;
}
else
@@ -753,5 +757,14 @@ namespace WMS.Web.Repositories
return (list, total);
}
+
+ ///
+ /// 鑾峰彇鏄庣粏
+ ///
+ ///
+ public async Task> GetNotSendErpDetails()
+ {
+ return await _context.InStockTaskDetails.Where(x =>x.AccruedQty!=0 && x.IsHasSend != null && x.IsHasSend == false && !string.IsNullOrEmpty(x.SaleBillNo) && !string.IsNullOrEmpty(x.CustomerCode)).ToListAsync();
+ }
}
}