|
|
@@ -5,6 +5,11 @@ using System.Linq;
|
|
|
using System.Web;
|
|
|
using GreenTree.Nachtragsmanagement.Core.Domain.Misc;
|
|
|
using GreenTree.Nachtragsmanagement.Services.User;
|
|
|
+using GreenTree.Nachtragsmanagement.Services.Configuration;
|
|
|
+using GreenTree.Nachtragsmanagement.Services.Appendix;
|
|
|
+using GreenTree.Nachtragsmanagement.Core.Domain.Appendix;
|
|
|
+using System.Net.Mail;
|
|
|
+using System.Net;
|
|
|
|
|
|
namespace GreenTree.Nachtragsmanagement.Web.Scheduling
|
|
|
{
|
|
|
@@ -13,6 +18,8 @@ namespace GreenTree.Nachtragsmanagement.Web.Scheduling
|
|
|
#region Services
|
|
|
|
|
|
private readonly IUserService _userService;
|
|
|
+ private readonly IConfigurationService _configurationService;
|
|
|
+ private readonly IAppendixService _appendixService;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
@@ -40,6 +47,35 @@ namespace GreenTree.Nachtragsmanagement.Web.Scheduling
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// List of available notification jobs
|
|
|
+ /// </summary>
|
|
|
+ public List<NotificationJob> AvailableNotificationJobs
|
|
|
+ {
|
|
|
+ get
|
|
|
+ {
|
|
|
+ return new List<NotificationJob>
|
|
|
+ {
|
|
|
+ new NotificationJob
|
|
|
+ (
|
|
|
+ Guid.Parse("2F3642E0-259D-466D-8629-CB279F740313"),
|
|
|
+ "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate",
|
|
|
+ "Verhandlungstermine überprüfen",
|
|
|
+ "Erstellt automatisch Benachrichtigungen für Nachträge, die nach 8 Wochen nach Einreichung noch keinen " +
|
|
|
+ "Verhandlungstermin gesetzt haben und ändert den entsprechenden Status ab"
|
|
|
+ ),
|
|
|
+ new NotificationJob
|
|
|
+ (
|
|
|
+ Guid.Parse("2E46B32A-1912-47F9-951E-C8188AA9BA50"),
|
|
|
+ "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationProtocol",
|
|
|
+ "Verhandlungsprotokolle überprüfen",
|
|
|
+ "Erstellt automatisch Benachrichtigungen für Nachträge, die nach 2 Wochen die zwar verhandelt sind, " +
|
|
|
+ "jedoch noch kein Protokoll aufweisen."
|
|
|
+ )
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Displayed name
|
|
|
/// </summary>
|
|
|
@@ -63,25 +99,179 @@ namespace GreenTree.Nachtragsmanagement.Web.Scheduling
|
|
|
"Verhandlungstermin gesetzt haben und ändert den entsprechenden Status ab. Außerdem werden alle 2 Wochen " +
|
|
|
"Benachrichtigungen für Nachträge erstellt, die zwar verhandelt sind, jedoch noch kein Protokoll aufweisen.";
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
#endregion
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Initializes a new instance of the AppendixNotificationPlugin class
|
|
|
+ /// </summary>
|
|
|
+ public AppendixNotificationPlugin() { }
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Initializes a new instance of the AppendixNotificationPlugin class
|
|
|
/// </summary>
|
|
|
public AppendixNotificationPlugin(
|
|
|
- IUserService userService)
|
|
|
+ IUserService userService,
|
|
|
+ IConfigurationService configurationService,
|
|
|
+ IAppendixService appendixService)
|
|
|
{
|
|
|
_userService = userService;
|
|
|
+ _configurationService = configurationService;
|
|
|
+ _appendixService = appendixService;
|
|
|
}
|
|
|
|
|
|
+ #region Processing
|
|
|
+
|
|
|
/// <summary>
|
|
|
/// Process all mail notifications registered for that plugin
|
|
|
/// </summary>
|
|
|
/// <param name="mailNotifications">The notifications which shall be generated.</param>
|
|
|
public void ProcessNotifications(IEnumerable<MailNotification> mailNotifications)
|
|
|
+ {
|
|
|
+ if (mailNotifications == null || !mailNotifications.Any()) return;
|
|
|
+
|
|
|
+ foreach (var notification in mailNotifications)
|
|
|
+ {
|
|
|
+ switch (notification.NotificationJobSystemName)
|
|
|
+ {
|
|
|
+ case "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate":
|
|
|
+ {
|
|
|
+ var conversionSuccess = false;
|
|
|
+
|
|
|
+ var ageDaysConfigItem = _configurationService.GetConfigItemByName(
|
|
|
+ "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate.AgeDays");
|
|
|
+
|
|
|
+ var ageDays = ageDaysConfigItem == null
|
|
|
+ ? 56
|
|
|
+ : _configurationService.TryGetConfigItemValue<int>(ageDaysConfigItem, out conversionSuccess);
|
|
|
+
|
|
|
+ if (!conversionSuccess)
|
|
|
+ ageDays = 56;
|
|
|
+
|
|
|
+ var stateSetConfigItem = _configurationService.GetConfigItemByName(
|
|
|
+ "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate.StateSet");
|
|
|
+
|
|
|
+ var stateId = stateSetConfigItem == null
|
|
|
+ ? 2
|
|
|
+ : _configurationService.TryGetConfigItemValue<int>(stateSetConfigItem, out conversionSuccess);
|
|
|
+
|
|
|
+ if (!conversionSuccess)
|
|
|
+ stateId = 2;
|
|
|
+
|
|
|
+ var appendices = _appendixService.GetAllAppendices()
|
|
|
+ .Where(a => a.OfferingDate <= DateTime.Now.AddDays(ageDays) &&
|
|
|
+ a.StateId != stateId &&
|
|
|
+ a.NegotiationDate == null)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ var mailBody = GenerateNegotiationDateMailBody(appendices);
|
|
|
+
|
|
|
+ foreach (var appendix in appendices)
|
|
|
+ {
|
|
|
+ appendix.StateId = stateId;
|
|
|
+
|
|
|
+ _appendixService.UpdateAppendix(appendix);
|
|
|
+ }
|
|
|
+
|
|
|
+ SendNotification(notification, "Autom. Übersicht nicht verhandelte Nachträge", mailBody);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationProtocol":
|
|
|
+
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Sets the corresponding status for appendices which offering date is older than 8 weeks and notifies the correspondig recipients
|
|
|
+ /// </summary>
|
|
|
+ private void ProcessNegotiationDateNotification()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Mail body generation
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Generates a mail body with a list of all appendices with a offering date later than 8 weeks
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="appendices">Appendices matching that criteria.</param>
|
|
|
+ public string GenerateNegotiationDateMailBody(IEnumerable<Appendix> appendices)
|
|
|
+ {
|
|
|
+ var template =
|
|
|
+ "<html>" +
|
|
|
+ " <body>" +
|
|
|
+ " <h3>Übersicht \"Nicht verhandelte Nachträge\"</h3>" +
|
|
|
+ " <p>Folgende Nachträge haben ein Einreichdatum älter als 8 Wochen, jedoch noch kein Verhandlungstermin" +
|
|
|
+ " gesetzt:</p>" +
|
|
|
+ " <ul>" +
|
|
|
+ " {0}" +
|
|
|
+ " </ul>" +
|
|
|
+ " </body>" +
|
|
|
+ "</html>";
|
|
|
+
|
|
|
+ if (!appendices.Any()) return String.Format(template, String.Empty);
|
|
|
+
|
|
|
+ var appendicesList = String.Empty;
|
|
|
+
|
|
|
+ foreach (var appendix in appendices)
|
|
|
+ {
|
|
|
+ appendicesList += String.Format(
|
|
|
+ "<li>Nachtrag <b>\"{0}\"</b> in Baustelle <b>\"{1}\"</b> - Einreichdatum: <b>{2:dd.MM.yyyy}</b>",
|
|
|
+ appendix.CustomNumber, appendix.Site.CustomNumber, appendix.OfferingDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ return String.Format(template, appendicesList);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region Mail sending
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Sends a generated mail body to the specified recipients in the mail notification
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="mailNotification">The mail notification.</param>
|
|
|
+ /// <param name="subject">The mail subject.</param>
|
|
|
+ /// <param name="body">The mail body.</param>
|
|
|
+ public void SendNotification(MailNotification mailNotification, string subject, string body)
|
|
|
+ {
|
|
|
+ if (mailNotification == null) return;
|
|
|
+
|
|
|
+ var mailServerConfig = _configurationService.GetCurrentConfiguration().MailServerElement;
|
|
|
+
|
|
|
+ var smptClient = new SmtpClient(mailServerConfig.SmtpServer, mailServerConfig.Port)
|
|
|
+ {
|
|
|
+ EnableSsl = mailServerConfig.UseSsl,
|
|
|
+ Credentials = new NetworkCredential(
|
|
|
+ mailServerConfig.Username,
|
|
|
+ mailServerConfig.Password,
|
|
|
+ mailServerConfig.Domain)
|
|
|
+ };
|
|
|
+
|
|
|
+ var recipients =
|
|
|
+ mailNotification.Users
|
|
|
+ .Select(u => u.MailAddress);
|
|
|
+
|
|
|
+ var mailMessage = new MailMessage
|
|
|
+ {
|
|
|
+ IsBodyHtml = true,
|
|
|
+ Subject = subject,
|
|
|
+ Body = body,
|
|
|
+ From = new MailAddress("Nachtragsbenachrichtigung@schweerbau.de")
|
|
|
+ };
|
|
|
+
|
|
|
+ foreach (var recipient in recipients)
|
|
|
+ mailMessage.To.Add(recipient);
|
|
|
+
|
|
|
+ smptClient.Send(mailMessage);
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
}
|
|
|
}
|