Skip to content

Commit

Permalink
Merge pull request #2237 from bcgov/1.10.11
Browse files Browse the repository at this point in the history
TH-115131: recalculate rotation list order based on LastCalled
  • Loading branch information
bcgov-brwang authored Jun 20, 2024
2 parents cdbd925 + 003410d commit 207264e
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 3 deletions.
5 changes: 4 additions & 1 deletion Server/HetsApi/Controllers/RentalRequestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,7 +1199,10 @@ public virtual IActionResult GetSeniorityList(int id, bool counterCopy = false)
}
// TH-112626
listRecord.SeniorityList = listRecord.SeniorityList
.OrderByDescending(x => Convert.ToDecimal(x.Seniority))
// TH-115131
//.OrderByDescending(x => Convert.ToDecimal(x.Seniority))
.OrderBy(x => x.Block)
.ThenByDescending(x => Convert.ToDecimal(x.Seniority))
.ToList();
string documentName = $"SeniorityList-{DateTime.Now:yyyy-MM-dd}{(counterCopy ? "-(CounterCopy)" : "")}.docx";
byte[] document = SeniorityList.GetSeniorityList(seniorityList, documentName, counterCopy, (errMessage, ex) => {
Expand Down
2 changes: 1 addition & 1 deletion Server/HetsApi/HetsApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<PropertyGroup>
<VersionPrefix>1.0.0.0</VersionPrefix>
<VersionSuffix>sprint1</VersionSuffix>
<Version>1.10.10.0</Version>
<Version>1.10.11.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
2 changes: 1 addition & 1 deletion Server/HetsApi/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"LogoffUrl-Training": "https://logontest.gov.bc.ca/clp-cgi/logoff.cgi?returl=https://trn-hets.th.gov.bc.ca&retnow=1",
"LogoffUrl-UAT": "https://logontest.gov.bc.ca/clp-cgi/logoff.cgi?returl=https://uat-hets.th.gov.bc.ca&retnow=1",
"LogoffUrl-Production": "https://logon.gov.bc.ca/clp-cgi/logoff.cgi?returl=https://hets.th.gov.bc.ca&retnow=1",
"Version-Application": "Release 1.10.10.0",
"Version-Application": "Release 1.10.11.0",
"Version-Database": "Release 1.10.10.0",
"Maximum-Blank-Agreements": "3",
"ExceptionDescriptions": {
Expand Down
113 changes: 113 additions & 0 deletions Server/HetsData/Repositories/RentalRequestRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System;
using System.Linq;
using HetsCommon;
using System.Collections.Generic;
using Hangfire.Server;

namespace HetsData.Repositories
{
Expand Down Expand Up @@ -213,6 +215,117 @@ public RentalRequestDto GetRecordWithRotationList(int id, SeniorityScoringRules
{
sortedList[i].RotationListSortOrder = i + 1;
}

// TH-115131
// Recalculate the rotationListSortOrder based on LastCall
try
{
var sortedSeniorityList = request.HetRentalRequestSeniorityLists
.OrderBy(x => x.BlockNumber)
.ThenByDescending(x => Convert.ToDecimal(x.Seniority))
.ToList();
var lastCalledInGroup = sortedSeniorityList.Where(x => x.LastCalled).ToList();
var dicBlockCount = new Dictionary<int?, int>();
var dicBlockFirstItem = new Dictionary<int?, string>();

var dicBlockItemsBefore = new Dictionary<int?, int>();
var dicBlockItemsAfter = new Dictionary<int?, int>();
var dicBlockBeforeItems = new Dictionary<int?, List<HetRentalRequestSeniorityList>>();
var dicBlockAfterItems = new Dictionary<int?, List<HetRentalRequestSeniorityList>>();
var dicBlockAllItems = new Dictionary<int?, List<HetRentalRequestSeniorityList>>();

for (int i = 0; i < lastCalledInGroup.Count; i++)
{
var itemsCount = sortedList.Where(x => x.BlockNumber == lastCalledInGroup[i].BlockNumber).ToList().Count;
dicBlockCount.Add(lastCalledInGroup[i].BlockNumber, itemsCount);

}
for (int i = 1; i < sortedSeniorityList.Count; i++)
{
if (sortedSeniorityList[i - 1].BlockNumber == sortedSeniorityList[i].BlockNumber && sortedSeniorityList[i - 1].LastCalled == true && sortedSeniorityList[i].LastCalled == false)
{
dicBlockFirstItem.Add(sortedSeniorityList[i].BlockNumber, sortedSeniorityList[i].EquipmentCode);
}
}

var groupedByBlock = sortedSeniorityList.GroupBy(item => item.BlockNumber);
Dictionary<string, int> orders = new Dictionary<string, int>();
foreach (var block in groupedByBlock)
{
int countBefore = 0;
int countAfter = 0;
bool foundTrue = false;
var itemsBefore = new List<HetRentalRequestSeniorityList>();
var itemsAfter = new List<HetRentalRequestSeniorityList>();

foreach (var item in block)
{
if (item.LastCalled == true)
{
foundTrue = true;
continue;
}
else
{
if (foundTrue)
{
countBefore++;
itemsBefore.Add(item);
}
else
{
countAfter++;
itemsAfter.Add(item);
}
}
}
dicBlockItemsBefore.Add(block.Key, countBefore);
dicBlockItemsAfter.Add(block.Key, countAfter);
dicBlockBeforeItems.Add(block.Key, itemsBefore);
dicBlockAfterItems.Add(block.Key, itemsAfter);
}

int tempOrder = 0;

foreach (var kvp in dicBlockBeforeItems)
{
int? key = kvp.Key;
var items = kvp.Value;

foreach (var item in items)
{
tempOrder++;
orders.Add(item.EquipmentCode, tempOrder);

}

foreach (var item in dicBlockAfterItems[key])
{
tempOrder++;
orders.Add(item.EquipmentCode, tempOrder);
}

// last called item should be at the end of the group
var lastCalled = sortedSeniorityList.Where(x => x.BlockNumber == key && x.LastCalled).FirstOrDefault();
if (lastCalled != null)
{
tempOrder++;
orders.Add(lastCalled.EquipmentCode, tempOrder);
}
}

for (int i = 0; i < sortedList.Count; i++)
{
var currentOrder = orders.Where(x => x.Key == sortedList[i].Equipment.EquipmentCode).FirstOrDefault().Value;
sortedList[i].RotationListSortOrder = currentOrder;
}

}
catch (Exception ex)
{
Console.WriteLine("Rotation list order calculation error: " + ex.Message);
}

request.HetRentalRequestRotationLists = sortedList;
return _mapper.Map<RentalRequestDto>(request);
}
Expand Down

0 comments on commit 207264e

Please sign in to comment.