This commit is contained in:
tongfei
2024-03-30 16:15:14 +08:00
parent b76111b79a
commit c0aa46faa2

View File

@@ -27,7 +27,7 @@ namespace WMS.Web.Domain.Services
/// <summary>
/// 阿里云短息服务
/// </summary>
public class SendMessageService: ISendMessageService
public class SendMessageService : ISendMessageService
{
private readonly ILogger<SendMessageService> _logger;
private readonly IClientProfile profile;
@@ -75,7 +75,7 @@ namespace WMS.Web.Domain.Services
request.SignName = _smsOptions.SignName; // 短信签名
//request.SignName = "深圳市元创时代"; // 短信签名
request.TemplateCode = _smsOptions.TemplateCode; // 短信模板编号
request.TemplateParam = "{\"material\":\"" + content+"\"}"; // 模板参数,根据实际情况填写
request.TemplateParam = "{\"material\":\"" + content + "\"}"; // 模板参数,根据实际情况填写
try
{
@@ -90,7 +90,7 @@ namespace WMS.Web.Domain.Services
else
{
_logger.LogInformation($"短信发送消息:失败->原因:{response.Message}->短信签名:{_smsOptions.SignName}->手机号码:" + phoneNumbers + " 内容:" + content);
return Result.ReFailure(response.Code,6000);
return Result.ReFailure(response.Code, 6000);
}
@@ -114,7 +114,7 @@ namespace WMS.Web.Domain.Services
/// <param name="toMailList"></param>
/// <param name="textBody"></param>
/// <returns></returns>
public async Task<Result> SendEmail(List<MailboxAddress> toMailList,string textBody,string coustomerName)
public async Task<Result> SendEmail(List<MailboxAddress> toMailList, string textBody, string coustomerName)
{
// 创建 MimeMessage 实例
MimeMessage message = new MimeMessage();
@@ -123,7 +123,7 @@ namespace WMS.Web.Domain.Services
//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")}"; // 设置邮件主题
message.Subject =$"【元创时代】-产品入库通知{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"; // 设置邮件主题
message.Subject = $"【元创时代】-产品入库通知{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"; // 设置邮件主题
// 创建邮件正文
BodyBuilder bodyBuilder = new BodyBuilder();
@@ -141,13 +141,13 @@ namespace WMS.Web.Domain.Services
await client.SendAsync(message); // 发送邮件
await client.DisconnectAsync(true); // 断开连接
}
_logger.LogInformation("邮箱发送消息:成功->收件方:"+JsonConvert.SerializeObject(toMailList)+" 内容:"+textBody);
_logger.LogInformation("邮箱发送消息:成功->收件方:" + JsonConvert.SerializeObject(toMailList) + " 内容:" + textBody);
return Result.ReSuccess();
}
catch (Exception ex)
{
_logger.LogInformation("邮箱发送消息:失败->收件方:" + JsonConvert.SerializeObject(toMailList) + " 内容:" + textBody);
return Result.ReFailure("邮箱发送失败:"+ex.Message,50006);
return Result.ReFailure("邮箱发送失败:" + ex.Message, 50006);
}
}
@@ -164,9 +164,9 @@ namespace WMS.Web.Domain.Services
materials = materials_result.Data.ToList();
//客户
var customerList= await _subscribeNotificationRepositories.GetList();
var customerList = await _subscribeNotificationRepositories.GetList();
//要处理发送的明细
var notSendDetails=await _inStockTaskRepositories.GetNotSendErpDetails();
var notSendDetails = await _inStockTaskRepositories.GetNotSendErpDetails();
var sendDataList = new List<SendDataDto>();
@@ -174,19 +174,19 @@ namespace WMS.Web.Domain.Services
{
if (notSendDetails != null && notSendDetails.Count != 0)
{
var taskIds= notSendDetails.GroupBy(x => x.Fid).Select(x => x.Key).ToList();
var taskIds = notSendDetails.GroupBy(x => x.Fid).Select(x => x.Key).ToList();
var instockTotalDetails= await _inStockRepositories.GetInStockTotalDetails(taskIds);
var instockTotalDetails = await _inStockRepositories.GetInStockTotalDetails(taskIds);
foreach (var item in customerList)
{
var current_notSendDetails= notSendDetails.Where(x => x.CustomerCode == item.CustomerNumber).ToList();
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);
data.Emails = string.Join(",", item.Emails);
foreach (var ema in item.Emails)
{
data.EmailList.Add(new MailboxAddress("Recipient Name", ema));
@@ -199,7 +199,7 @@ namespace WMS.Web.Domain.Services
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);
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);
}
@@ -242,7 +242,7 @@ namespace WMS.Web.Domain.Services
{
update_taskDetailsIds.Add(det.TaskDetailId);
if (i == item.Details.Count)
content = det.Specifications + " X 数量" +Convert.ToInt32(det.Qty);
content = det.Specifications + " X 数量" + Convert.ToInt32(det.Qty);
else
content = det.Specifications + " X 数量" + Convert.ToInt32(det.Qty) + "";
i = i + 1;
@@ -251,12 +251,12 @@ namespace WMS.Web.Domain.Services
//邮箱
await this.SendEmail(item.EmailList, content, item.CustomerName);
//短信
var sms_result= this.SendSms(item.PhoneNumbers, content);
var sms_result = this.SendSms(item.PhoneNumbers, content);
//内容过长-分段发送
if (!sms_result.IsSuccess && sms_result.Message== "isv.PARAM_LENGTH_LIMIT")
if (!sms_result.IsSuccess && sms_result.Message == "isv.PARAM_LENGTH_LIMIT")
{
//分段发送以字数480长度分段
var contentParts= this.SplitContent(content, 480);
var contentParts = this.SplitContent(content, 480);
foreach (var partContent in contentParts)
{
this.SendSms(item.PhoneNumbers, partContent);
@@ -266,30 +266,32 @@ namespace WMS.Web.Domain.Services
}
//任务明细:修改的
var tasksDetails = await _inStockTaskRepositories.GetDetailsList(update_taskDetailsIds.Distinct().ToList());
if(tasksDetails!=null && tasksDetails.Count != 0)
if (tasksDetails != null && tasksDetails.Count != 0)
{
tasksDetails.ForEach(x => { x.IsHasSend = true; });
var update_Result= await _inStockTaskRepositories.UpdateRange(tasksDetails);
var update_Result = await _inStockTaskRepositories.UpdateRange(tasksDetails);
if (!update_Result)
{
_logger.LogInformation("发送消息:失败-修改任务明细->" + JsonConvert.SerializeObject(tasksDetails));
}
}
}
else
_logger.LogInformation("发送消息:暂无可发送的通知明细");
}
return Result.ReSuccess();
}
catch (Exception ex)
{
return Result.ReFailure("发送失败:"+ex.Message,50006);
return Result.ReFailure("发送失败:" + ex.Message, 50006);
}
}
// 将消息分割成多个部分
public List<string> SplitContent(string content, int maxLength)
public List<string> SplitContent(string content, int maxLength)
{
List<string> parts = new List<string>();