Reputation: 942
I work in a small energy company and i was asked to create a method that would be called to determine which of our technicians would take home the company off hours phone.
we have 2 tables i could consider
the Technicians table
id name
--------------------
001 George
002 James
003 Wesley
004 Horace
005 Jason
006 Nice
the Leaves table
id leaveDate
--------------------
005 2020/12/29
005 2020/12/30
002 2021/01/05
002 2021/01/13
003 2021/01/13
005 2021/01/22
History table *not existing yet
id techPhoneDate
--------------------
001 2021/01/04
003 2021/01/05
i could create a new table with the phone history to keep tabs on who historically were assigned to it, i just want to have something that would make sure the rotation is fair and would skip the person if on leave and would assign them on the next possible day
i already have code that would return an error if its a weekend, and if the history table already has a calculated technician for that day, it would just return that technician. it should also consider in calculation if a new technician would be added.
I initially thought it would be an easy method, but how could i go about finding who's in charge of the phone for today?
private List<Technicians> techs;
private List<PhoneHistory> phoneHistory;
private List<Leaves> leaves;
public RotationResponse getTechOnDuty(String rotationDate) {
RotationResponse resp = new RotationResponse();
try {
resp.setRotationDate(rotationDate);
//check if its a weekend
resp = validateDate(resp);
if (resp.getErrorMessage() != null) {
return resp;
}
String techId = findTechIdForDate(rotationDate); // find in history if there is an existing tech already calculated
if (StringUtils.isNotBlank(techId)){
resp.setTechnician(findTechById(techId));
} else {
resp.setTechnician(findTechById(getTechPhoneRotationForToday(rotationDate)));
}
return resp;
} catch (Exception e) {
return resp.setErrorMessage(e.getMessage());
}
}
private String getTechPhoneRotationForToday(String rotationDate){
// TODO
}
Upvotes: 0
Views: 102
Reputation: 5808
Maybe:
determining whether a day was a workday is itself probably challenging
Upvotes: 1