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/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
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