ListFormWorkflow daki Information düğümü çalıştırıldı
This commit is contained in:
parent
6ed1c2dabc
commit
312f784e3e
1 changed files with 83 additions and 1 deletions
|
|
@ -2,16 +2,21 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Sozsoft.Platform.Data.Seeds;
|
||||||
using Sozsoft.Platform.Entities;
|
using Sozsoft.Platform.Entities;
|
||||||
using Sozsoft.Platform.Enums;
|
using Sozsoft.Platform.Enums;
|
||||||
using Sozsoft.Platform.ListForms.Select;
|
using Sozsoft.Platform.ListForms.Select;
|
||||||
using Sozsoft.Platform.Queries;
|
using Sozsoft.Platform.Queries;
|
||||||
|
using Sozsoft.Sender.Mail;
|
||||||
using Volo.Abp;
|
using Volo.Abp;
|
||||||
using Volo.Abp.Domain.Repositories;
|
using Volo.Abp.Domain.Repositories;
|
||||||
|
using Volo.Abp.Identity;
|
||||||
|
using Volo.Abp.Settings;
|
||||||
|
|
||||||
namespace Sozsoft.Platform.ListForms.Workflow;
|
namespace Sozsoft.Platform.ListForms.Workflow;
|
||||||
|
|
||||||
|
|
@ -28,19 +33,28 @@ public class ListFormWorkflowAppService : PlatformAppService, IListFormWorkflowA
|
||||||
private readonly IListFormAuthorizationManager authManager;
|
private readonly IListFormAuthorizationManager authManager;
|
||||||
private readonly IListFormSelectAppService listFormSelectAppService;
|
private readonly IListFormSelectAppService listFormSelectAppService;
|
||||||
private readonly IQueryManager queryManager;
|
private readonly IQueryManager queryManager;
|
||||||
|
private readonly IdentityUserManager identityUserManager;
|
||||||
|
private readonly ISozsoftEmailSender erpEmailSender;
|
||||||
|
private readonly ISettingProvider settingProvider;
|
||||||
|
|
||||||
public ListFormWorkflowAppService(
|
public ListFormWorkflowAppService(
|
||||||
IRepository<ListFormWorkflow, string> criteriaRepository,
|
IRepository<ListFormWorkflow, string> criteriaRepository,
|
||||||
IListFormManager listFormManager,
|
IListFormManager listFormManager,
|
||||||
IListFormAuthorizationManager authManager,
|
IListFormAuthorizationManager authManager,
|
||||||
IListFormSelectAppService listFormSelectAppService,
|
IListFormSelectAppService listFormSelectAppService,
|
||||||
IQueryManager queryManager)
|
IQueryManager queryManager,
|
||||||
|
IdentityUserManager identityUserManager,
|
||||||
|
ISozsoftEmailSender erpEmailSender,
|
||||||
|
ISettingProvider settingProvider)
|
||||||
{
|
{
|
||||||
this.criteriaRepository = criteriaRepository;
|
this.criteriaRepository = criteriaRepository;
|
||||||
this.listFormManager = listFormManager;
|
this.listFormManager = listFormManager;
|
||||||
this.authManager = authManager;
|
this.authManager = authManager;
|
||||||
this.listFormSelectAppService = listFormSelectAppService;
|
this.listFormSelectAppService = listFormSelectAppService;
|
||||||
this.queryManager = queryManager;
|
this.queryManager = queryManager;
|
||||||
|
this.identityUserManager = identityUserManager;
|
||||||
|
this.erpEmailSender = erpEmailSender;
|
||||||
|
this.settingProvider = settingProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("criteria")]
|
[HttpGet("criteria")]
|
||||||
|
|
@ -497,6 +511,74 @@ public class ListFormWorkflowAppService : PlatformAppService, IListFormWorkflowA
|
||||||
|
|
||||||
await UpdateRowAsync(context, update);
|
await UpdateRowAsync(context, update);
|
||||||
MergeRowValues(context.Row, update);
|
MergeRowValues(context.Row, update);
|
||||||
|
|
||||||
|
if (node.Kind == "Inform")
|
||||||
|
{
|
||||||
|
await SendInformEmailAsync(context, node);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task SendInformEmailAsync(WorkflowRunContext context, ListFormWorkflow node)
|
||||||
|
{
|
||||||
|
var recipientEmail = await ResolveApproverEmailAsync(node.Approver);
|
||||||
|
var senderName = await settingProvider.GetOrNullAsync(SeedConsts.AbpSettings.Mailing.Default.DefaultFromDisplayName);
|
||||||
|
var senderEmail = await settingProvider.GetOrNullAsync(SeedConsts.AbpSettings.Mailing.Default.DefaultFromAddress);
|
||||||
|
KeyValuePair<string, string>? sender = null;
|
||||||
|
if (!senderEmail.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
sender = new KeyValuePair<string, string>(senderName, senderEmail);
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = await erpEmailSender.SendEmailAsync(
|
||||||
|
recipientEmail,
|
||||||
|
sender,
|
||||||
|
new { },
|
||||||
|
BuildInformEmailBody(context, node),
|
||||||
|
$"Workflow Bilgilendirme: {node.Title}",
|
||||||
|
null,
|
||||||
|
true);
|
||||||
|
|
||||||
|
if (!result.Success)
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"Bilgilendirme maili gonderilemedi: {result.ErrorMessage}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<string> ResolveApproverEmailAsync(string approver)
|
||||||
|
{
|
||||||
|
if (approver.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException("Bilgilendirme dugumu icin approver tanimli degil.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (approver.Contains('@'))
|
||||||
|
{
|
||||||
|
return approver.Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
var user = await identityUserManager.FindByNameAsync(approver.Trim());
|
||||||
|
if (user == null || user.Email.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
throw new UserFriendlyException($"Bilgilendirme kullanicisinin mail adresi bulunamadi: {approver}");
|
||||||
|
}
|
||||||
|
|
||||||
|
return user.Email;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string BuildInformEmailBody(WorkflowRunContext context, ListFormWorkflow node)
|
||||||
|
{
|
||||||
|
var keyText = string.Join(", ", context.Keys.Select(key => WebUtility.HtmlEncode(key?.ToString() ?? string.Empty)));
|
||||||
|
var listFormCode = WebUtility.HtmlEncode(context.ListFormCode ?? string.Empty);
|
||||||
|
var nodeTitle = WebUtility.HtmlEncode(node.Title ?? string.Empty);
|
||||||
|
|
||||||
|
return $"""
|
||||||
|
<p>Workflow bilgilendirme adimina ulasildi.</p>
|
||||||
|
<table>
|
||||||
|
<tr><td><strong>Liste Formu</strong></td><td>{listFormCode}</td></tr>
|
||||||
|
<tr><td><strong>Adim</strong></td><td>{nodeTitle}</td></tr>
|
||||||
|
<tr><td><strong>Kayit</strong></td><td>{keyText}</td></tr>
|
||||||
|
</table>
|
||||||
|
""";
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task UpdateRowAsync(WorkflowRunContext context, Dictionary<string, object> data)
|
private async Task UpdateRowAsync(WorkflowRunContext context, Dictionary<string, object> data)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue