From 721dc9571013dc5559538d277bca39708b9b959c Mon Sep 17 00:00:00 2001 From: Ryabov_PI Date: Mon, 23 Mar 2026 16:08:58 +0400 Subject: [PATCH 1/4] =?UTF-8?q?=D0=90=D0=BA=D1=82=D1=83=D0=B0=D0=BB=D0=B8?= =?UTF-8?q?=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=BF=D1=80=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BE=D0=BF=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D0=B8=D1=82=D0=B8=D0=BA=20=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sungero.Docflow/ModuleServerFunctions.cs | 10 +++-- .../CreateStoragePolicySettings_mssql.sql | 25 +++++++----- .../CreateStoragePolicySettings_postgres.sql | 39 +++++++++++-------- .../SelectDocumentsToTransferWithIdRange.sql | 31 +++++++++++++++ 4 files changed, 76 insertions(+), 29 deletions(-) create mode 100644 src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/SelectDocumentsToTransferWithIdRange.sql diff --git a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs index b6b196bd..bfdd2963 100644 --- a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs +++ b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs @@ -104,16 +104,18 @@ public override bool CanConvertToPdfInteractively(Sungero.Docflow.IOfficialDocum /// Текст запроса. public override string GetStoragePolicySettingsQuery(DateTime now) { - return string.Format(Docflow.Queries.Module.CreateStoragePolicySettings, Sungero.Docflow.Constants.Module.StoragePolicySettingsTableName, now.ToString("yyyy-MM-dd HH:mm:ss")); + return string.Format(Docflow.Queries.Module.CreateStoragePolicySettings, Sungero.Docflow.Constants.Module.StoragePolicySettingsTableName); } /// - /// Перекрытие. Получить запрос получения документов для перемещения. + /// Перекрытие. Получить запрос отбора документов для переноса в заданном диапазоне Id. /// + /// Нижняя граница диапазона Id (не включительно). + /// Верхняя граница диапазона Id (включительно). /// Текст запроса. - public override string GetDocumentsToTransferQuery() + public override string GetDocumentsToTransferWithIdRangeQuery(long fromId, long batchUpperBoundId) { - return string.Format(Docflow.Queries.Module.SelectDocumentsToTransfer, Sungero.Docflow.Constants.Module.StoragePolicySettingsTableName); + return string.Format(Docflow.Queries.Module.SelectDocumentsToTransferWithIdRange, Sungero.Docflow.Constants.Module.StoragePolicySettingsTableName, fromId, batchUpperBoundId); } /// diff --git a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/CreateStoragePolicySettings_mssql.sql b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/CreateStoragePolicySettings_mssql.sql index 6a49c683..d006ab3a 100644 --- a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/CreateStoragePolicySettings_mssql.sql +++ b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/CreateStoragePolicySettings_mssql.sql @@ -2,11 +2,11 @@ if exists (select * from information_schema.tables where table_name = '{0}') drop table {0} select r.Storage, rdk.DocumentKind, - case when r.DocDateType = 'DocumentDate' then dateadd(DD, -1 * r.DaysToMove, '{1}') else '2100-01-01 00:00:00.000' end as DocumentDate, - case when r.DocDateType = 'Modified' then dateadd(DD, -1 * r.DaysToMove, '{1}') else '2100-01-01 00:00:00.000' end as Modified, - case when r.DocDateType = 'LastRead' then dateadd(DD, -1 * r.DaysToMove, '{1}') else '2100-01-01 00:00:00.000' end as LastRead, + case when r.DocDateType = 'DocumentDate' then dateadd(DD, -1 * r.DaysToMove, @now) else @maxDate end as DocumentDate, + case when r.DocDateType = 'Modified' then dateadd(DD, -1 * r.DaysToMove, @now) else @maxDate end as Modified, + case when r.DocDateType = 'LastRead' then dateadd(DD, -1 * r.DaysToMove, @now) else @maxDate end as LastRead, case when r.Discriminator = '9fed5653-77e7-4543-b071-6586033907ef' then r.[Priority] else r.[Priority] + (select coalesce(max(r2.[Priority]), 0) from Sungero_Docflow_StoragePolicy r2 where r2.Discriminator = '9fed5653-77e7-4543-b071-6586033907ef') end as [Priority], - case when coalesce(r.NextRetention, '{1}') <= '{1}' then 1 else 0 end as NeedRetention + case when coalesce(r.NextRetention, @now) <= @now then 1 else 0 end as NeedRetention into {0} from Sungero_Docflow_StoragePolicy r join Sungero_Docflow_SPolicyDocKind rdk @@ -15,13 +15,20 @@ into {0} insert into {0} select r.Storage, rdk.Id, - case when r.DocDateType = 'DocumentDate' then dateadd(DD, -1 * r.DaysToMove, '{1}') else '2100-01-01 00:00:00.000' end as DocumentDate, - case when r.DocDateType = 'Modified' then dateadd(DD, -1 * r.DaysToMove, '{1}') else '2100-01-01 00:00:00.000' end as Modified, - case when r.DocDateType = 'LastRead' then dateadd(DD, -1 * r.DaysToMove, '{1}') else '2100-01-01 00:00:00.000' end as LastRead, + case when r.DocDateType = 'DocumentDate' then dateadd(DD, -1 * r.DaysToMove, @now) else @maxDate end as DocumentDate, + case when r.DocDateType = 'Modified' then dateadd(DD, -1 * r.DaysToMove, @now) else @maxDate end as Modified, + case when r.DocDateType = 'LastRead' then dateadd(DD, -1 * r.DaysToMove, @now) else @maxDate end as LastRead, case when r.Discriminator = '9fed5653-77e7-4543-b071-6586033907ef' then r.[Priority] else r.[Priority] + (select coalesce(max(r2.[Priority]), 0) from Sungero_Docflow_StoragePolicy r2 where r2.Discriminator = '9fed5653-77e7-4543-b071-6586033907ef') end as [Priority], - case when coalesce(r.NextRetention, '{1}') <= '{1}' then 1 else 0 end as NeedRetention + case when coalesce(r.NextRetention, @now) <= @now then 1 else 0 end as NeedRetention from Sungero_Docflow_StoragePolicy r join Sungero_Docflow_DocumentKind rdk on 1=1 where r.Status = 'Active' - and not exists (select 1 from Sungero_Docflow_SPolicyDocKind k where k.StoragePolicy = r.Id); \ No newline at end of file + and not exists (select 1 from Sungero_Docflow_SPolicyDocKind k where k.StoragePolicy = r.Id); + +insert into {0} +select s.Id, rdk.Id, @maxDate, @maxDate, @maxDate, -1, 1 + from Sungero_Core_Storage s + join Sungero_Docflow_DocumentKind rdk + on 1=1 + where s.IsDefault = 1; diff --git a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/CreateStoragePolicySettings_postgres.sql b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/CreateStoragePolicySettings_postgres.sql index e74cc20c..f4a3800c 100644 --- a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/CreateStoragePolicySettings_postgres.sql +++ b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/CreateStoragePolicySettings_postgres.sql @@ -8,26 +8,26 @@ END $$; SELECT r.Storage, rdk.DocumentKind, CASE WHEN r.DocDateType = 'DocumentDate' - THEN TO_TIMESTAMP('{1}','YYYY-MM-DD HH24:MI:SS') - r.DaysToMove * INTERVAL '1 day' - ELSE TO_TIMESTAMP('2100-01-01 00:00:00.000','YYYY-MM-DD HH24:MI:SS') + THEN @now - r.DaysToMove * INTERVAL '1 day' + ELSE @maxDate END AS DocumentDate, CASE WHEN r.DocDateType = 'Modified' - THEN TO_TIMESTAMP('{1}','YYYY-MM-DD HH24:MI:SS') - r.DaysToMove * INTERVAL '1 day' - ELSE TO_TIMESTAMP('2100-01-01 00:00:00.000','YYYY-MM-DD HH24:MI:SS') + THEN @now - r.DaysToMove * INTERVAL '1 day' + ELSE @maxDate END AS Modified, CASE WHEN r.DocDateType = 'LastRead' - THEN TO_TIMESTAMP('{1}','YYYY-MM-DD HH24:MI:SS') - r.DaysToMove * INTERVAL '1 day' - ELSE TO_TIMESTAMP('2100-01-01 00:00:00.000','YYYY-MM-DD HH24:MI:SS') - END AS LastRead, + THEN @now - r.DaysToMove * INTERVAL '1 day' + ELSE @maxDate + END AS LastRead, CASE WHEN r.Discriminator = '9fed5653-77e7-4543-b071-6586033907ef' THEN r.Priority ELSE r.Priority + (SELECT COALESCE(MAX(r2.Priority), 0) FROM Sungero_Docflow_StoragePolicy r2 WHERE r2.Discriminator = '9fed5653-77e7-4543-b071-6586033907ef') END AS Priority, CASE - WHEN COALESCE(r.NextRetention, '{1}') <= '{1}' + WHEN COALESCE(r.NextRetention, @now) <= @now THEN 1 ELSE 0 END AS NeedRetention @@ -41,18 +41,18 @@ INSERT INTO {0} SELECT r.Storage, rdk.Id, CASE WHEN r.DocDateType = 'DocumentDate' - THEN TO_TIMESTAMP('{1}','YYYY-MM-DD HH24:MI:SS') - r.DaysToMove * INTERVAL '1 day' - ELSE TO_TIMESTAMP('2100-01-01 00:00:00.000','YYYY-MM-DD HH24:MI:SS') + THEN @now - r.DaysToMove * INTERVAL '1 day' + ELSE @maxDate END AS DocumentDate, CASE WHEN r.DocDateType = 'Modified' - THEN TO_TIMESTAMP('{1}','YYYY-MM-DD HH24:MI:SS') - r.DaysToMove * INTERVAL '1 day' - ELSE TO_TIMESTAMP('2100-01-01 00:00:00.000','YYYY-MM-DD HH24:MI:SS') + THEN @now - r.DaysToMove * INTERVAL '1 day' + ELSE @maxDate END AS Modified, CASE WHEN r.DocDateType = 'LastRead' - THEN TO_TIMESTAMP('{1}','YYYY-MM-DD HH24:MI:SS') - r.DaysToMove * INTERVAL '1 day' - ELSE TO_TIMESTAMP('2100-01-01 00:00:00.000','YYYY-MM-DD HH24:MI:SS') + THEN @now - r.DaysToMove * INTERVAL '1 day' + ELSE @maxDate END AS LastRead, CASE WHEN r.Discriminator = '9fed5653-77e7-4543-b071-6586033907ef' @@ -60,7 +60,7 @@ SELECT r.Storage, rdk.Id, ELSE r.Priority + (SELECT COALESCE(MAX(r2.Priority), 0) FROM Sungero_Docflow_StoragePolicy r2 WHERE r2.Discriminator = '9fed5653-77e7-4543-b071-6586033907ef') END AS Priority, CASE - WHEN COALESCE(r.NextRetention, '{1}') <= '{1}' + WHEN COALESCE(r.NextRetention, @now) <= @now THEN 1 ELSE 0 END AS NeedRetention @@ -68,4 +68,11 @@ SELECT r.Storage, rdk.Id, JOIN Sungero_Docflow_DocumentKind rdk ON 1=1 WHERE r.Status = 'Active' - AND NOT EXISTS (SELECT 1 FROM Sungero_Docflow_SPolicyDocKind k WHERE k.StoragePolicy = r.Id); \ No newline at end of file + AND NOT EXISTS (SELECT 1 FROM Sungero_Docflow_SPolicyDocKind k WHERE k.StoragePolicy = r.Id); + +INSERT INTO {0} +SELECT s.Id, rdk.Id, @maxDate, @maxDate, @maxDate, -1, 1 + FROM Sungero_Core_Storage s + JOIN Sungero_Docflow_DocumentKind rdk + ON 1=1 + WHERE s.IsDefault = TRUE; diff --git a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/SelectDocumentsToTransferWithIdRange.sql b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/SelectDocumentsToTransferWithIdRange.sql new file mode 100644 index 00000000..166faaad --- /dev/null +++ b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/SelectDocumentsToTransferWithIdRange.sql @@ -0,0 +1,31 @@ +with RankedDocs as ( + select doc.Id, + doc.Storage_Docflow_Sungero as CurrentStorage, + t.Storage as TargetStorage, + t.NeedRetention, + row_number() over ( + partition by doc.Id + order by t.Priority desc + ) as rn + from Sungero_Content_EDoc doc + join (select EntityId, max(HistoryDate) as HD + from Sungero_Content_DocHistory + where Action in ('Read', 'Create', 'Update') + and VersionNumber is not null + and Operation <> 'DataTransfer' + group by EntityId) as hld + on hld.EntityId = doc.Id + join {0} t + on t.DocumentKind = doc.DocumentKind_Docflow_Sungero + and doc.DocumentDate_Docflow_Sungero <= t.DocumentDate + and doc.Modified <= t.Modified + and hld.HD <= t.LastRead + where t.NeedRetention = 1 + and doc.Storage_Docflow_Sungero is not null + and t.Storage != doc.Storage_Docflow_Sungero + and doc.Id > {1} + and doc.Id <= {2} +) +select Id, TargetStorage +from RankedDocs +where rn = 1 From 7dab84af0ea66da2cb05a947e7e5da83e1cdd40d Mon Sep 17 00:00:00 2001 From: Ryabov_PI Date: Mon, 23 Mar 2026 16:18:35 +0400 Subject: [PATCH 2/4] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=81=D1=82=D0=B0=D1=80=D0=BE=D0=B3=D0=BE=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Queries/SelectDocumentsToTransfer.sql | 23 ------------------- 1 file changed, 23 deletions(-) delete mode 100644 src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/SelectDocumentsToTransfer.sql diff --git a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/SelectDocumentsToTransfer.sql b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/SelectDocumentsToTransfer.sql deleted file mode 100644 index 48331a6b..00000000 --- a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/Queries/SelectDocumentsToTransfer.sql +++ /dev/null @@ -1,23 +0,0 @@ -select doc.Id, t.Storage - from Sungero_Content_EDoc doc - join (select EntityId, max(HistoryDate) as HD - from Sungero_Content_DocHistory - where Action in ('Read', 'Create', 'Update') - and VersionNumber is not null - and Operation <> 'DataTransfer' - group by EntityId) as hld - on hld.EntityId = doc.Id - join {0} t - on t.DocumentKind = doc.DocumentKind_Docflow_Sungero - and doc.DocumentDate_Docflow_Sungero <= t.DocumentDate - and doc.Modified <= t.Modified - and hld.HD <= t.LastRead - where t.Priority = (select max(tt.Priority) - from {0} tt - where tt.DocumentKind = doc.DocumentKind_Docflow_Sungero - and doc.DocumentDate_Docflow_Sungero <= tt.DocumentDate - and doc.Modified <= tt.Modified - and hld.HD <= t.LastRead) - and t.Storage != doc.Storage_Docflow_Sungero - and doc.Storage_Docflow_Sungero is not null - and t.NeedRetention = 1 \ No newline at end of file From 3fcb75bce74e1659bdf336e742d97d7fa1afbede Mon Sep 17 00:00:00 2001 From: Ryabov_PI Date: Mon, 6 Apr 2026 08:07:23 +0400 Subject: [PATCH 3/4] =?UTF-8?q?=D0=92=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sungero.Docflow/ModuleServerFunctions.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs index bfdd2963..86a4ab03 100644 --- a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs +++ b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs @@ -3,6 +3,7 @@ using System.Linq; using Sungero.Core; using Sungero.CoreEntities; +using Sungero.Notifications.Structures.Module; namespace Sungero.Examples.Module.Docflow.Server { @@ -129,5 +130,27 @@ public override List> GetMultipleMembersRoles() return roles; } + + /// + /// Перекрытие. Добавить отслеживание отправки к параметрам обработки рассылки о новых и просроченных заданиях. + /// + /// Параметры обработки рассылки о новых и просроченных заданиях. + public override IProcessingParameters CreateAssignmentsMailingProcessingParameters() + { + var parameters = base.CreateAssignmentsMailingProcessingParameters(); + parameters.TrackProcess = true; + return parameters; + } + + /// + /// Перекрытие. Добавить отслеживание отправки к параметрам обработки рассылки со сводкой о заданиях. + /// + /// Параметры обработки рассылки со сводкой о заданиях. + public override IProcessingParameters CreateSummaryMailingProcessingParameters() + { + var parameters = base.CreateSummaryMailingProcessingParameters(); + parameters.TrackProcess = true; + return parameters; + } } } \ No newline at end of file From a927f7ad3276e24476d97f8cd4e69d61d1d4169d Mon Sep 17 00:00:00 2001 From: Ryabov_PI Date: Mon, 6 Apr 2026 08:51:33 +0400 Subject: [PATCH 4/4] =?UTF-8?q?Revert=20"=D0=92=D0=BE=D0=B7=D0=B2=D1=80?= =?UTF-8?q?=D0=B0=D1=89=D0=B5=D0=BD=D1=8B=20=D1=84=D1=83=D0=BD=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=B8"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 3fcb75bce74e1659bdf336e742d97d7fa1afbede. --- .../Sungero.Docflow/ModuleServerFunctions.cs | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs index 86a4ab03..bfdd2963 100644 --- a/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs +++ b/src/Packages/Sungero.Examples/Sungero.Examples.Server/Sungero.Docflow/ModuleServerFunctions.cs @@ -3,7 +3,6 @@ using System.Linq; using Sungero.Core; using Sungero.CoreEntities; -using Sungero.Notifications.Structures.Module; namespace Sungero.Examples.Module.Docflow.Server { @@ -130,27 +129,5 @@ public override List> GetMultipleMembersRoles() return roles; } - - /// - /// Перекрытие. Добавить отслеживание отправки к параметрам обработки рассылки о новых и просроченных заданиях. - /// - /// Параметры обработки рассылки о новых и просроченных заданиях. - public override IProcessingParameters CreateAssignmentsMailingProcessingParameters() - { - var parameters = base.CreateAssignmentsMailingProcessingParameters(); - parameters.TrackProcess = true; - return parameters; - } - - /// - /// Перекрытие. Добавить отслеживание отправки к параметрам обработки рассылки со сводкой о заданиях. - /// - /// Параметры обработки рассылки со сводкой о заданиях. - public override IProcessingParameters CreateSummaryMailingProcessingParameters() - { - var parameters = base.CreateSummaryMailingProcessingParameters(); - parameters.TrackProcess = true; - return parameters; - } } } \ No newline at end of file