RequestProcessingTaskHandlers.cs
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using DirRX.Storage.RequestProcessingTask;
using Newtonsoft.Json.Linq;
namespace DirRX.Storage
{
partial class RequestProcessingTaskServerHandlers
{
public override void BeforeSave(Sungero.Domain.BeforeSaveEventArgs e)
{
var requestKindLocalized = Storage.RequestProcessingTasks.Info.Properties.RequestKind.GetLocalizedValue(_obj.RequestKind);
var initiator = string.Empty;
if (!string.IsNullOrWhiteSpace(_obj.RequestData))
{
initiator = JObject.Parse(_obj.RequestData)["Initiator"].ToString();
Logger.DebugFormat("initiator {0}", initiator);
}
else
{
var employee = Storage.PublicFunctions.Module.Remote.GetEmployeeForCurentUser();
if (employee == null)
initiator = Users.Current.Login.LoginName;
else
initiator = employee.DisplayValue;
}
_obj.Subject = RequestProcessingTasks.Resources.TaskSubjectFormat(requestKindLocalized, initiator, Calendar.Now.ToShortDateString(), _obj.Id);
}
public override void Created(Sungero.Domain.CreatedEventArgs e)
{
// Отв. за обработку запроса, исполнитель задания
var archivist = Storage.PublicFunctions.Module.Remote.GetRequestResponsible();
if (archivist != null)
{
_obj.Archivist = archivist;
// Черновик темы. Полностью будет заполнена в задании архивисту.
var requestKindLocalized = Storage.RequestProcessingTasks.Info.Properties.RequestKind.GetLocalizedValue(_obj.RequestKind);
var initiator = string.Empty;
var employee = Storage.PublicFunctions.Module.Remote.GetEmployeeForCurentUser();
if (employee == null)
initiator = Users.Current.Login.LoginName;
else
initiator = employee.DisplayValue;
_obj.Subject = RequestProcessingTasks.Resources.TaskSubjectFormat(requestKindLocalized, initiator, Calendar.Now.ToShortDateString(), _obj.Id);
// Конечный срок из константы
_obj.MaxDeadline = Calendar.Now.AddWorkingDays(Constants.RequestProcessingTask.DefaultMaxDeadline);
}
else
{
Logger.Error(RequestProcessingTasks.Resources.ErrorResponsibleNoDefined);
throw new Exception(RequestProcessingTasks.Resources.ErrorResponsibleNoDefined);
}
}
public override void BeforeStart(Sungero.Workflow.Server.BeforeStartEventArgs e)
{
if (string.IsNullOrWhiteSpace(_obj.ActiveText) && string.IsNullOrWhiteSpace(_obj.RequestData))
{
e.AddError(RequestProcessingTasks.Resources.ErrorEmptyRequestText);
return;
}
// Сформировать json-данные запроса, если задача создается в диалоге.
if (string.IsNullOrWhiteSpace(_obj.RequestData))
{
var json = new JObject();
var initiator = string.Empty;
// Заполнить инициатора текущим пользователем.
var employee = Storage.PublicFunctions.Module.Remote.GetEmployeeForCurentUser();
if (employee == null || employee.IsSystem == true)
{
initiator = Sungero.CoreEntities.Users.Current.Login.LoginName;
}
else
{
initiator = employee.Name;
_obj.Initiator = employee;
if (!string.IsNullOrWhiteSpace(employee.Phone))
json.Add("ContactInfo", employee.Phone);
if (!string.IsNullOrWhiteSpace(employee.Email))
json.Add("Email", employee.Email);
}
json.Add("RequestKind", _obj.RequestKind.ToString());
json.Add("Initiator", initiator);
json.Add("RequestText", _obj.ActiveText);
_obj.RequestData = json.ToString();
}
}
}
}