|
|
@@ -12,6 +12,7 @@ using System.Net.Mail;
|
|
|
using System.Net;
|
|
|
using System.Globalization;
|
|
|
using Quartz;
|
|
|
+using GreenTree.Nachtragsmanagement.Services.Logging;
|
|
|
|
|
|
namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
{
|
|
|
@@ -22,6 +23,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
private readonly IUserService _userService;
|
|
|
private readonly IConfigurationService _configurationService;
|
|
|
private readonly IAppendixService _appendixService;
|
|
|
+ private readonly IServiceLogger _logger;
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
@@ -73,6 +75,14 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
"Verhandlungsprotokolle überprüfen",
|
|
|
"Erstellt automatisch Benachrichtigungen für Nachträge, die nach 2 Wochen zwar verhandelt sind, " +
|
|
|
"jedoch noch kein Protokoll aufweisen."
|
|
|
+ ),
|
|
|
+ new NotificationJob
|
|
|
+ (
|
|
|
+ Guid.Parse("B39FB44A-6E57-458C-A403-2C4FA7581F15"),
|
|
|
+ "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationOrder",
|
|
|
+ "Bestellnummern überprüfen",
|
|
|
+ "Erstellt automatisch Benachrichtigungen für Nachträge, die nach 2 Wochen zwar verhandelt sind, " +
|
|
|
+ "jedoch noch keine Bestellnummer aufweisen."
|
|
|
)
|
|
|
};
|
|
|
}
|
|
|
@@ -99,7 +109,8 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
return
|
|
|
"Erstellt automatisch Benachrichtigungen für Nachträge, die nach 8 Wochen nach Einreichung noch keinen " +
|
|
|
"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.";
|
|
|
+ "Benachrichtigungen für Nachträge erstellt, die zwar verhandelt sind, jedoch noch kein Protokoll aufweisen oder " +
|
|
|
+ "keine Bestellnummer aufweisen.";
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
@@ -115,11 +126,13 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
public AppendixNotificationPlugin(
|
|
|
IUserService userService,
|
|
|
IConfigurationService configurationService,
|
|
|
- IAppendixService appendixService)
|
|
|
+ IAppendixService appendixService,
|
|
|
+ IServiceLogger logger)
|
|
|
{
|
|
|
_userService = userService;
|
|
|
_configurationService = configurationService;
|
|
|
_appendixService = appendixService;
|
|
|
+ _logger = logger;
|
|
|
}
|
|
|
|
|
|
#region Quartz implmentation
|
|
|
@@ -135,8 +148,6 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
|
|
|
var mailNotifications = context.JobDetail.JobDataMap.Get("MailNotifications") as IEnumerable<MailNotification>;
|
|
|
|
|
|
- if (mailNotifications == null) return;
|
|
|
-
|
|
|
ProcessNotifications(mailNotifications);
|
|
|
}
|
|
|
|
|
|
@@ -150,24 +161,38 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
/// <param name="mailNotifications">The notifications which shall be generated.</param>
|
|
|
public void ProcessNotifications(IEnumerable<MailNotification> mailNotifications)
|
|
|
{
|
|
|
- if (mailNotifications == null || !mailNotifications.Any()) return;
|
|
|
+ if (mailNotifications == null || (mailNotifications != null && !mailNotifications.Any())) return;
|
|
|
|
|
|
foreach (var notification in mailNotifications)
|
|
|
{
|
|
|
- switch (notification.NotificationJobSystemName)
|
|
|
+ try
|
|
|
{
|
|
|
- case "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate":
|
|
|
- {
|
|
|
- ProcessNegotiationDateNotification(notification);
|
|
|
- }
|
|
|
- break;
|
|
|
- case "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationProtocol":
|
|
|
- {
|
|
|
- ProcessNegotiationProtocolNotification(notification);
|
|
|
- }
|
|
|
- break;
|
|
|
- default:
|
|
|
- continue;
|
|
|
+ switch (notification.NotificationJobSystemName)
|
|
|
+ {
|
|
|
+ case "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate":
|
|
|
+ {
|
|
|
+ ProcessNegotiationDateNotification(notification);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationProtocol":
|
|
|
+ {
|
|
|
+ ProcessNegotiationProtocolNotification(notification);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationOrder":
|
|
|
+ {
|
|
|
+ ProcessNegotiationOrderNotification(notification);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.Error(
|
|
|
+ String.Format(
|
|
|
+ "Fehler bei Mail-Benachrichtigung in \"{0}\" für \"{1}", SystemName, notification.NotificationJobSystemName), ex);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -182,8 +207,11 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
var ageDays = _configurationService.TryGetConfigItemValue<int>(
|
|
|
"GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate.AgeDays", 56);
|
|
|
|
|
|
- var stateSetId = _configurationService.TryGetConfigItemValue<int>(
|
|
|
- "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate.StateSet", 2);
|
|
|
+ var stateSetId = _configurationService.TryGetConfigItemValue<int[]>(
|
|
|
+ "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate.StateSet", new[] { 13 })[0];
|
|
|
+
|
|
|
+ var stateConditionIds = _configurationService.TryGetConfigItemValue<int[]>(
|
|
|
+ "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate.StateCondition", new[] { 1, 5, 6, 12 });
|
|
|
|
|
|
var interval = _configurationService.TryGetConfigItemValue<int>(
|
|
|
"GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationDate.Interval", 2);
|
|
|
@@ -198,13 +226,14 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
.Where(a => a.OfferingDate.HasValue &&
|
|
|
(DateTime.Now - a.OfferingDate).Value.Days >= ageDays &&
|
|
|
a.StateId != stateSetId && a.StateId != finishStateId &&
|
|
|
- a.NegotiationDate == null)
|
|
|
+ stateConditionIds.Contains(a.StateId.Value) && a.NegotiationDate == null)
|
|
|
.ToList();
|
|
|
|
|
|
var currentCalendarWeek = GetCalendarWeek(DateTime.Now);
|
|
|
|
|
|
appendices = appendices
|
|
|
- .Where(a => ((currentCalendarWeek - GetCalendarWeek(a.OfferingDate.Value) % interval == 0)))
|
|
|
+ .Where(a => (currentCalendarWeek - GetCalendarWeek(a.OfferingDate.Value) % interval == 0) ||
|
|
|
+ (currentCalendarWeek - GetCalendarWeek(a.OfferingDate.Value) < 0))
|
|
|
.ToList();
|
|
|
|
|
|
if (appendices.Any())
|
|
|
@@ -224,7 +253,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
|
|
|
/// <summary>
|
|
|
/// Sets the corresponding status for appendices which negotiation date is older than N weeks and notifies
|
|
|
- /// the correspondig recipients
|
|
|
+ /// the correspondig recipients when the protocol does not exist
|
|
|
/// </summary>
|
|
|
/// <param name="mailNotification">The notification which shall be generated.</param>
|
|
|
private void ProcessNegotiationProtocolNotification(MailNotification mailNotification)
|
|
|
@@ -232,9 +261,6 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
var ageDays = _configurationService.TryGetConfigItemValue<int>(
|
|
|
"GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationProtocol.AgeDays", 14);
|
|
|
|
|
|
- var stateConditionId = _configurationService.TryGetConfigItemValue<int>(
|
|
|
- "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationProtocol.StateCondition", 3);
|
|
|
-
|
|
|
var interval = _configurationService.TryGetConfigItemValue<int>(
|
|
|
"GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationProtocol.Interval", 2);
|
|
|
|
|
|
@@ -253,7 +279,8 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
var currentCalendarWeek = GetCalendarWeek(DateTime.Now);
|
|
|
|
|
|
appendices = appendices
|
|
|
- .Where(a => ((currentCalendarWeek - GetCalendarWeek(a.OfferingDate.Value) % interval == 0)))
|
|
|
+ .Where(a => (currentCalendarWeek - GetCalendarWeek(a.OfferingDate.Value) % interval == 0) ||
|
|
|
+ (currentCalendarWeek - GetCalendarWeek(a.OfferingDate.Value) < 0))
|
|
|
.ToList();
|
|
|
|
|
|
if (appendices.Any())
|
|
|
@@ -264,6 +291,46 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Sets the corresponding status for appendices which negotiation date is older than N weeks and notifies
|
|
|
+ /// the correspondig recipients when the order number is still missing
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="mailNotification">The notification which shall be generated.</param>
|
|
|
+ private void ProcessNegotiationOrderNotification(MailNotification mailNotification)
|
|
|
+ {
|
|
|
+ var ageDays = _configurationService.TryGetConfigItemValue<int>(
|
|
|
+ "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationOrder.AgeDays", 14);
|
|
|
+
|
|
|
+ var interval = _configurationService.TryGetConfigItemValue<int>(
|
|
|
+ "GreenTree.Nachtragsmanagement.AppendixNotificationPlugin.ProcessNegotiationOrder.Interval", 2);
|
|
|
+
|
|
|
+ interval = interval == 0
|
|
|
+ ? 1
|
|
|
+ : interval;
|
|
|
+
|
|
|
+ var finishStateId = _appendixService.GetFinishState().Id;
|
|
|
+
|
|
|
+ var appendices = _appendixService.GetAllAppendices()
|
|
|
+ .Where(a => a.NegotiationDate.HasValue &&
|
|
|
+ (DateTime.Now - a.NegotiationDate).Value.Days >= ageDays &&
|
|
|
+ String.IsNullOrEmpty(a.OrderNumber) && a.StateId != finishStateId)
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ var currentCalendarWeek = GetCalendarWeek(DateTime.Now);
|
|
|
+
|
|
|
+ appendices = appendices
|
|
|
+ .Where(a => (currentCalendarWeek - GetCalendarWeek(a.OfferingDate.Value) % interval == 0) ||
|
|
|
+ (currentCalendarWeek - GetCalendarWeek(a.OfferingDate.Value) < 0))
|
|
|
+ .ToList();
|
|
|
+
|
|
|
+ if (appendices.Any())
|
|
|
+ {
|
|
|
+ var mailBody = GenerateNegotiationOrderMailBody(appendices);
|
|
|
+
|
|
|
+ SendNotification(mailNotification, "Autom. Übersicht verhandelte Nachträge o. Bestellnummer", mailBody);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
#endregion
|
|
|
|
|
|
#region Mail body generation
|
|
|
@@ -301,7 +368,7 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
- /// Generates a mail body with a list of all appendices with a negotiation date later than N weeks
|
|
|
+ /// Generates a mail body with a list of all appendices with a negotiation date later than N weeks and not existing protocol
|
|
|
/// </summary>
|
|
|
/// <param name="appendices">Appendices matching that criteria.</param>
|
|
|
public string GenerateNegotiationProtocolMailBody(IEnumerable<Appendix> appendices)
|
|
|
@@ -325,7 +392,46 @@ namespace GreenTree.Nachtragsmanagement.Web.Implementations
|
|
|
{
|
|
|
appendicesList += String.Format(
|
|
|
"<li>Nachtrag <b>\"{0}\"</b> in Baustelle <b>\"{1}\"</b> - Verhandlungsdatum: <b>{2:dd.MM.yyyy}</b>",
|
|
|
- appendix.CustomNumber, appendix.Site.CustomNumber, appendix.NegotiationDate);
|
|
|
+ appendix.CustomNumber,
|
|
|
+ appendix.Site == null
|
|
|
+ ? String.Empty
|
|
|
+ : appendix.Site.CustomNumber,
|
|
|
+ appendix.NegotiationDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ return String.Format(template, appendicesList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// Generates a mail body with a list of all appendices with a negotiation date later than N weeks and not existing order number
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="appendices">Appendices matching that criteria.</param>
|
|
|
+ public string GenerateNegotiationOrderMailBody(IEnumerable<Appendix> appendices)
|
|
|
+ {
|
|
|
+ var template =
|
|
|
+ "<html>" +
|
|
|
+ " <body>" +
|
|
|
+ " <h3>Übersicht \"Verhandelte Nachträge ohne Bestellnummer\"</h3>" +
|
|
|
+ " <p>Folgende Nachträge haben ein Verhandlungstermin älter als zwei Wochen, jedoch noch keine Bestellnummer:" +
|
|
|
+ " <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> - Verhandlungsdatum: <b>{2:dd.MM.yyyy}</b>",
|
|
|
+ appendix.CustomNumber,
|
|
|
+ appendix.Site == null
|
|
|
+ ? String.Empty
|
|
|
+ : appendix.Site.CustomNumber,
|
|
|
+ appendix.NegotiationDate);
|
|
|
}
|
|
|
|
|
|
return String.Format(template, appendicesList);
|