Skip to content

Commit 324c6eb

Browse files
committed
Fixing code to do the update correctly.
1 parent 0cec9a8 commit 324c6eb

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed

ServiceBackendConfigurationPlugin/Scheduler/Jobs/SearchListJob.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,78 @@ await _sdkDbContext.Languages.SingleAsync(x =>
924924
}
925925
}
926926
break;
927+
case 5:
928+
{
929+
/* Find all compliances which have expired today and we have call sdk and move the eform from the current folder to the expired folder
930+
* also we need to set the ignore_end_date, when doing the call.
931+
* The expired folder is found by looking at the area rule -> area -> expired folder
932+
*/
933+
var changeDate = DateTime.Parse("2025-10-30");
934+
935+
var complianceList = await _backendConfigurationDbContext.Compliances
936+
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
937+
.Where(x => x.Deadline < DateTime.UtcNow)
938+
.Where(x => x.Deadline > changeDate)
939+
.AsNoTracking()
940+
.OrderBy(x => x.Deadline)
941+
.ToListAsync();
942+
943+
var listOfPropertieIdsFromComplianceList= complianceList
944+
.Select(x => x.PropertyId)
945+
.Distinct()
946+
.ToList();
947+
948+
var properties = await _backendConfigurationDbContext.Properties
949+
.Where(x => listOfPropertieIdsFromComplianceList.Contains(x.Id))
950+
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
951+
.ToListAsync();
952+
953+
foreach (var compliance in complianceList)
954+
{
955+
var areaRulePlanningQuery = _backendConfigurationDbContext.AreaRulePlannings
956+
.Include(x => x.AreaRulePlanningTags)
957+
.Where(x => x.WorkflowState != Constants.WorkflowStates.Removed)
958+
.Where(x => x.ItemPlanningId == compliance.PlanningId);
959+
960+
var areaRulePlanning = await areaRulePlanningQuery
961+
.Select(x => new { x.AreaRuleId, x.StartDate, x.Id, x.ComplianceEnabled })
962+
.FirstOrDefaultAsync();
963+
964+
if (!areaRulePlanning.ComplianceEnabled)
965+
{
966+
continue;
967+
}
968+
969+
var microtingSdkCaseId = compliance.MicrotingSdkCaseId;
970+
var theCase = await _sdkDbContext.Cases.Where(x => x.Id == microtingSdkCaseId)
971+
// .Select(x => x.MicrotingUid)
972+
.FirstAsync();
973+
974+
var property = properties
975+
// .Select(x => x.FolderId)
976+
.First(x => x.Id == compliance.PropertyId);
977+
978+
var folderAndFolderTranslation = await _sdkDbContext.Folders
979+
.Join(_sdkDbContext.FolderTranslations,
980+
folder => folder.Id,
981+
folderTranslation => folderTranslation.FolderId,
982+
(folder, folderTranslation) => new {folder, folderTranslation})
983+
.Where(x => x.folder.ParentId == property.FolderId &&
984+
x.folderTranslation.Name == "00. Overdue tasks")
985+
.FirstOrDefaultAsync();
986+
987+
var site = await _sdkDbContext.Sites
988+
.Where(x => x.Id == theCase.SiteId)
989+
.Select(x => x.MicrotingUid)
990+
.FirstAsync();
991+
992+
await _core.UpdateDeployedeForm((int)theCase.MicrotingUid, site.ToString(), (int)folderAndFolderTranslation.folder.MicrotingUid, true);
993+
Console.WriteLine($"Moved compliance case with id: {theCase.Id} to overdue folder");
994+
var comp = await _backendConfigurationDbContext.Compliances.FirstAsync(x => x.Id == compliance.Id);
995+
await comp.Delete(_backendConfigurationDbContext).ConfigureAwait(false);
996+
}
997+
break;
998+
}
927999
case 8:
9281000
{
9291001
Log.LogEvent("SearchListJob.Task: SearchListJob.Execute got called at 8:00 UTC - Opgavestatus");

0 commit comments

Comments
 (0)