ExchangeDocumentProcessingTaskServerFunctions.cs
11.3 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Exchange.ExchangeDocumentProcessingTask;
using Sungero.Workflow;
namespace Sungero.Exchange.Server
{
partial class ExchangeDocumentProcessingTaskFunctions
{
#region Предметное отображение "Задачи"
/// <summary>
/// Построить модель контрола состояния документа.
/// </summary>
/// <param name="document">Документ.</param>
/// <returns>Модель контрола состояния.</returns>
public Sungero.Core.StateView GetStateView(Sungero.Docflow.IOfficialDocument document)
{
if (_obj.AllAttachments.Any(d => Equals(document, d)))
return this.GetStateView();
else
return StateView.Create();
}
/// <summary>
/// Построить модель контрола состояния.
/// </summary>
/// <returns>Модель контрола состояния.</returns>
[Remote(IsPure = true)]
public Sungero.Core.StateView GetStateView()
{
var stateView = StateView.Create();
// Добавить блок информации к блоку задачи.
var taskHeader = ExchangeDocumentProcessingTasks.Resources.StateViewInformationBlockFormat(ExchangeCore.PublicFunctions.BoxBase.GetExchangeService(_obj.Box));
this.AddInformationBlock(stateView, taskHeader, _obj.Started.Value);
// Блок информации о задаче.
var taskBlock = this.AddTaskBlock(stateView);
// Получить все задания по задаче.
var taskAssignments = ExchangeDocumentProcessingAssignments.GetAll(a => Equals(a.Task, _obj)).OrderBy(a => a.Created).ToList();
// Статус задачи.
var status = _obj.Info.Properties.Status.GetLocalizedValue(_obj.Status);
var lastAssignment = taskAssignments.OrderByDescending(a => a.Created).FirstOrDefault();
// Установить статус отказать, если обработка завершилась с этим результатом.
if (lastAssignment.Result == Exchange.ExchangeDocumentProcessingAssignment.Result.Abort)
status = lastAssignment.Info.Properties.Result.GetLocalizedValue(lastAssignment.Result);
if (!string.IsNullOrWhiteSpace(status))
Docflow.PublicFunctions.Module.AddInfoToRightContent(taskBlock, status);
// Блоки информации о заданиях.
foreach (var assignment in taskAssignments)
{
var assignmentBlock = this.GetAssignmentBlock(assignment);
taskBlock.AddChildBlock(assignmentBlock);
}
return stateView;
}
/// <summary>
/// Добавить блок информации о действии.
/// </summary>
/// <param name="stateView">Схема представления.</param>
/// <param name="text">Текст действия.</param>
/// <param name="date">Дата действия.</param>
[Public]
public void AddInformationBlock(object stateView, string text, DateTime date)
{
// Создать блок с пояснением.
var block = (stateView as StateView).AddBlock();
block.Entity = _obj;
block.DockType = DockType.Bottom;
block.ShowBorder = false;
// Иконка.
block.AssignIcon(ExchangeDocumentProcessingTasks.Resources.ExchangeDocumentIcon, StateBlockIconSize.Small);
// Текст блока.
block.AddLabel(text);
var style = Docflow.PublicFunctions.Module.CreateStyle(false, true);
block.AddLabel(string.Format("{0}: {1}", Docflow.OfficialDocuments.Resources.StateViewDate.ToString(),
Docflow.PublicFunctions.Module.ToShortDateShortTime(date.ToUserTime())), style);
}
/// <summary>
/// Добавить блок задачи на обработку входящих документов из сервиса обмена.
/// </summary>
/// <param name="stateView">Схема представления.</param>
/// <returns>Новый блок.</returns>
public Sungero.Core.StateBlock AddTaskBlock(Sungero.Core.StateView stateView)
{
// Создать блок задачи.
var taskBlock = stateView.AddBlock();
// Добавить ссылку на задачу и иконку.
taskBlock.Entity = _obj;
taskBlock.AssignIcon(StateBlockIconType.OfEntity, StateBlockIconSize.Large);
// Определить схлопнутость.
taskBlock.IsExpanded = _obj.Status == Workflow.Task.Status.InProcess;
taskBlock.AddLabel(ExchangeDocumentProcessingTasks.Resources.StateViewTaskBlockHeader, Sungero.Docflow.PublicFunctions.Module.CreateHeaderStyle());
taskBlock.AddLineBreak();
// Добавить отправителя.
var sender = _obj.Counterparty;
taskBlock.AddLabel(ExchangeDocumentProcessingTasks.Resources.StateViewSender, Sungero.Docflow.PublicFunctions.Module.CreateNoteStyle());
taskBlock.AddHyperlink(sender.Name, Hyperlinks.Get(sender));
taskBlock.AddLineBreak();
// Добавить получателя.
var receiver = _obj.Box;
taskBlock.AddLabel(ExchangeDocumentProcessingTasks.Resources.StateViewRecipient, Sungero.Docflow.PublicFunctions.Module.CreateNoteStyle());
taskBlock.AddHyperlink(receiver.Name, Hyperlinks.Get(receiver));
return taskBlock;
}
/// <summary>
/// Добавить блок задания на обработку входящих документов из сервиса обмена.
/// </summary>
/// <param name="assignment">Задание.</param>
/// <returns>Новый блок.</returns>
public Sungero.Core.StateBlock GetAssignmentBlock(IAssignment assignment)
{
// Стили.
var performerDeadlineStyle = Docflow.PublicFunctions.Module.CreatePerformerDeadlineStyle();
var boldStyle = Docflow.PublicFunctions.Module.CreateStyle(true, false);
var grayStyle = Docflow.PublicFunctions.Module.CreateStyle(false, true);
var separatorStyle = Docflow.PublicFunctions.Module.CreateSeparatorStyle();
var noteStyle = Docflow.PublicFunctions.Module.CreateNoteStyle();
var block = StateView.Create().AddBlock();
block.Entity = assignment;
// Иконка.
this.SetIcon(block, ExchangeDocumentProcessingAssignments.As(assignment));
// Заголовок.
block.AddLabel(ExchangeDocumentProcessingTasks.Resources.StateViewAssignmentBlockHeader, boldStyle);
block.AddLineBreak();
// Кому.
var assigneeShortName = Company.PublicFunctions.Employee.GetShortName(Company.Employees.As(assignment.Performer), false);
var performerInfo = string.Format("{0}: {1}", Docflow.OfficialDocuments.Resources.StateViewTo, assigneeShortName);
block.AddLabel(performerInfo, performerDeadlineStyle);
// Срок.
if (assignment.Deadline.HasValue)
{
var deadlineLabel = Docflow.PublicFunctions.Module.ToShortDateShortTime(assignment.Deadline.Value.ToUserTime());
block.AddLabel(string.Format("{0}: {1}", Docflow.OfficialDocuments.Resources.StateViewDeadline, deadlineLabel), performerDeadlineStyle);
}
// Текст задания.
var comment = Docflow.PublicFunctions.Module.GetAssignmentUserComment(Assignments.As(assignment));
if (!string.IsNullOrWhiteSpace(comment))
{
// Разделитель.
block.AddLineBreak();
block.AddLabel(Docflow.PublicFunctions.Module.GetSeparatorText(), separatorStyle);
block.AddLineBreak();
block.AddEmptyLine(Docflow.PublicFunctions.Module.GetEmptyLineMargin());
block.AddLabel(comment, noteStyle);
}
// Статус.
var status = AssignmentBases.Info.Properties.Status.GetLocalizedValue(assignment.Status);
// Для непрочитанных заданий указать это.
if (assignment.IsRead == false)
status = Docflow.ApprovalTasks.Resources.StateViewUnRead.ToString();
// Для исполненных заданий указать результат, с которым они исполнены, кроме "Обработано".
if (assignment.Status == Workflow.AssignmentBase.Status.Completed
&& assignment.Result != Exchange.ExchangeDocumentProcessingAssignment.Result.Complete)
status = Exchange.ExchangeDocumentProcessingAssignments.Info.Properties.Result.GetLocalizedValue(assignment.Result);
if (!string.IsNullOrWhiteSpace(status))
Docflow.PublicFunctions.Module.AddInfoToRightContent(block, status);
// Задержка исполнения.
if (assignment.Deadline.HasValue &&
assignment.Status == Workflow.AssignmentBase.Status.InProcess)
Docflow.PublicFunctions.OfficialDocument.AddDeadlineHeaderToRight(block, assignment.Deadline.Value, assignment.Performer);
return block;
}
/// <summary>
/// Установить иконку.
/// </summary>
/// <param name="block">Блок, для которого требуется установить иконку.</param>
/// <param name="assignment">Задание, от которого построен блок.</param>
private void SetIcon(StateBlock block, IExchangeDocumentProcessingAssignment assignment)
{
var iconSize = StateBlockIconSize.Large;
// Иконка по умолчанию.
block.AssignIcon(StateBlockIconType.OfEntity, iconSize);
// Прекращено, остановлено по ошибке.
if (assignment.Status == Workflow.AssignmentBase.Status.Aborted ||
assignment.Status == Workflow.AssignmentBase.Status.Suspended ||
assignment.Result == Exchange.ExchangeDocumentProcessingAssignment.Result.Abort)
{
block.AssignIcon(StateBlockIconType.Abort, iconSize);
return;
}
if (assignment.Result == null)
return;
if (assignment.Result == Exchange.ExchangeDocumentProcessingAssignment.Result.Complete ||
assignment.Result == Exchange.ExchangeDocumentProcessingAssignment.Result.ReAddress)
{
block.AssignIcon(StateBlockIconType.Completed, iconSize);
return;
}
}
#endregion
/// <summary>
/// Проверить, что все документы отправлены в работу.
/// </summary>
/// <returns>True, если все документы в работе, иначе - false.</returns>
[Remote]
public bool AreAllDocumentsSendToWork()
{
foreach (Sungero.Docflow.IOfficialDocument document in _obj.NeedSigning.All)
{
var docTypeGuid = Guid.Parse(document.DocumentKind.DocumentType.DocumentTypeGuid);
if (!Sungero.Workflow.Tasks
.GetAll(t => !ExchangeDocumentProcessingTasks.Is(t))
.Any(t => t.AttachmentDetails.Any(att => att.AttachmentId == document.Id &&
att.EntityTypeGuid == docTypeGuid)))
return false;
}
return true;
}
}
}