VerificationAssignmentSharedFunctions.cs
7.14 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
using System;
using System.Collections.Generic;
using System.Linq;
using Sungero.Core;
using Sungero.CoreEntities;
using Sungero.Docflow;
using Sungero.SmartProcessing.VerificationAssignment;
namespace Sungero.SmartProcessing.Shared
{
partial class VerificationAssignmentFunctions
{
/// <summary>
/// Получить текст инструкции для задания.
/// </summary>
/// <returns>Текст инструкции.</returns>
public virtual string GetInstruction()
{
var instructionSteps = new List<string>()
{
VerificationAssignments.Resources.InstructionStep1,
VerificationAssignments.Resources.InstructionStep2,
VerificationAssignments.Resources.InstructionStep3,
VerificationAssignments.Resources.InstructionStep4,
VerificationAssignments.Resources.InstructionStep5,
VerificationAssignments.Resources.InstructionStep6,
VerificationAssignments.Resources.InstructionStep7
};
return string.Join(Environment.NewLine, instructionSteps);
}
/// <summary>
/// Получить документы для перекомплектования.
/// </summary>
/// <returns>Список документов.</returns>
public virtual List<IOfficialDocument> GetDocumentsSuitableForRepacking()
{
Logger.Debug("Repacking. GetDocumentsSuitableForRepacking");
var documents = this.GetOrderedDocuments();
var notSuitableDocuments = new List<IOfficialDocument>();
notSuitableDocuments.AddRange(this.GetEncryptedDocuments(documents));
notSuitableDocuments.AddRange(this.GetInaccesssibleDocuments(documents));
notSuitableDocuments.AddRange(this.GetNotSuitableExtensionDocuments(documents));
notSuitableDocuments.AddRange(this.GetDocumentsWithoutVersion(documents));
notSuitableDocuments.AddRange(this.GetDocumentsWithoutBody(documents));
documents = documents.Except(notSuitableDocuments).ToList();
this.LogDocumentsSuitableForRepackingFilter("GetDocumentsSuitableForRepacking", documents);
if (!documents.Any())
Logger.Debug("Repacking. No documents suitable for repacking.");
return documents;
}
/// <summary>
/// Получить список документов, отсортированных по порядку вложений в задаче.
/// </summary>
/// <returns>Список документов.</returns>
public virtual List<IOfficialDocument> GetOrderedDocuments()
{
var mainTask = VerificationTasks.As(_obj.Task);
var orderedAttachmentsIds = Functions.VerificationTask.Remote.GetOrderedAttachments(mainTask);
return _obj.AllAttachments
.OrderBy(x => orderedAttachmentsIds.IndexOf(x.Id))
.Where(x => OfficialDocuments.Is(x))
.Select(x => OfficialDocuments.As(x))
.ToList();
}
/// <summary>
/// Отфильтровать зашифрованные документы.
/// </summary>
/// <param name="documents">Документы.</param>
/// <returns>Список документов.</returns>
public virtual System.Collections.Generic.IEnumerable<IOfficialDocument> GetEncryptedDocuments(System.Collections.Generic.IEnumerable<IOfficialDocument> documents)
{
var encryptedDocuments = documents.Where(d => d.IsEncrypted);
this.LogDocumentsSuitableForRepackingFilter("GetEncryptedDocuments", encryptedDocuments);
return encryptedDocuments;
}
/// <summary>
/// Отфильтровать документы, на которые нет прав на изменение.
/// </summary>
/// <param name="documents">Документы.</param>
/// <returns>Список документов.</returns>
public virtual System.Collections.Generic.IEnumerable<IOfficialDocument> GetInaccesssibleDocuments(System.Collections.Generic.IEnumerable<IOfficialDocument> documents)
{
var inaccessibleDocuments = documents.Where(d => !d.AccessRights.CanUpdate());
this.LogDocumentsSuitableForRepackingFilter("GetInaccesssibleDocuments", inaccessibleDocuments);
return inaccessibleDocuments;
}
/// <summary>
/// Отфильтровать документы с неподходящим расширением.
/// </summary>
/// <param name="documents">Документы.</param>
/// <returns>Список документов.</returns>
public virtual System.Collections.Generic.IEnumerable<IOfficialDocument> GetNotSuitableExtensionDocuments(System.Collections.Generic.IEnumerable<IOfficialDocument> documents)
{
var notSuitableExtensionDocuments = documents.Where(d => d.LastVersion != null &&
d.LastVersion.AssociatedApplication.Extension != Docflow.PublicConstants.OfficialDocument.PdfExtension);
this.LogDocumentsSuitableForRepackingFilter("GetNotSuitableExtensionDocuments", notSuitableExtensionDocuments);
return notSuitableExtensionDocuments;
}
/// <summary>
/// Отфильтровать документы без версии.
/// </summary>
/// <param name="documents">Документы.</param>
/// <returns>Список документов.</returns>
public virtual System.Collections.Generic.IEnumerable<IOfficialDocument> GetDocumentsWithoutVersion(System.Collections.Generic.IEnumerable<IOfficialDocument> documents)
{
var documentsWithoutVersion = documents.Where(d => d.LastVersion == null);
this.LogDocumentsSuitableForRepackingFilter("GetDocumentsWithoutVersion", documentsWithoutVersion);
return documentsWithoutVersion;
}
/// <summary>
/// Отфильтровать документы без тела.
/// </summary>
/// <param name="documents">Документы.</param>
/// <returns>Список документов.</returns>
public virtual System.Collections.Generic.IEnumerable<IOfficialDocument> GetDocumentsWithoutBody(System.Collections.Generic.IEnumerable<IOfficialDocument> documents)
{
var documentsWithoutBody = documents.Where(d => d.LastVersion != null &&
d.LastVersion.Body.Size == 0 &&
d.LastVersion.PublicBody.Size == 0);
this.LogDocumentsSuitableForRepackingFilter("GetDocumentsWithoutBody", documentsWithoutBody);
return documentsWithoutBody;
}
/// <summary>
/// Вывести в лог сообщение о фильтрации документов для перекомплектования.
/// </summary>
/// <param name="name">Наименование фильтра.</param>
/// <param name="documents">Отфильтрованные документы.</param>
public virtual void LogDocumentsSuitableForRepackingFilter(string name, System.Collections.Generic.IEnumerable<IOfficialDocument> documents)
{
if (documents.Any())
Logger.DebugFormat(Constants.VerificationAssignment.LogDocumentsSuitableForRepackingFilterMessageFormat,
name,
string.Join(", ", documents.Select(d => d.Id)));
}
}
}