| Line 272... |
Line 272... |
| 272 |
newEscalationType = ticketAssigned.getEscalationType().next();
|
272 |
newEscalationType = ticketAssigned.getEscalationType().next();
|
| 273 |
if (newEscalationType == null || newEscalationType.equals(EscalationType.Final)) {
|
273 |
if (newEscalationType == null || newEscalationType.equals(EscalationType.Final)) {
|
| 274 |
LOGGER.info("Cant escalate further");
|
274 |
LOGGER.info("Cant escalate further");
|
| 275 |
return;
|
275 |
return;
|
| 276 |
}
|
276 |
}
|
| 277 |
} else {
|
- |
|
| 278 |
ticket.setL1AuthUser(0);
|
- |
|
| 279 |
ticket.setL2AuthUser(0);
|
- |
|
| 280 |
ticket.setL3AuthUser(0);
|
- |
|
| 281 |
ticket.setL4AuthUser(0);
|
- |
|
| 282 |
ticket.setL5AuthUser(0);
|
- |
|
| 283 |
}
|
277 |
}
|
| 284 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
278 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
| 285 |
|
279 |
|
| 286 |
|
- |
|
| 287 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
280 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
| 288 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketSubCategory.getCategoryId());
|
281 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketSubCategory.getCategoryId());
|
| 289 |
Map<Integer, EscalationType> escalationUserMap = new HashedMap<>();
|
- |
|
| 290 |
Set<Integer> assigneeUserIds = new LinkedHashSet<>();
|
- |
|
| 291 |
EscalationType escalationTypeNext = newEscalationType;
|
- |
|
| 292 |
do {
|
- |
|
| 293 |
int assigneeUserId = this.getAuthUserId(ticketCategory.getId(), escalationTypeNext, ticket.getFofoId());
|
- |
|
| 294 |
if (assigneeUserId == 0) {
|
- |
|
| 295 |
escalationTypeNext = escalationTypeNext.next();
|
- |
|
| 296 |
LOGGER.info("Escalation type next {}", escalationTypeNext);
|
- |
|
| 297 |
continue;
|
- |
|
| 298 |
}
|
- |
|
| 299 |
assigneeUserIds.add(assigneeUserId);
|
- |
|
| 300 |
escalationUserMap.put(assigneeUserId, escalationTypeNext);
|
- |
|
| 301 |
switch (escalationTypeNext) {
|
- |
|
| 302 |
case L1:
|
- |
|
| 303 |
ticket.setL1AuthUser(assigneeUserId);
|
- |
|
| 304 |
break;
|
- |
|
| 305 |
case L2:
|
- |
|
| 306 |
ticket.setL2AuthUser(assigneeUserId);
|
- |
|
| 307 |
break;
|
- |
|
| 308 |
case L3:
|
- |
|
| 309 |
ticket.setL3AuthUser(assigneeUserId);
|
- |
|
| 310 |
break;
|
- |
|
| 311 |
case L4:
|
- |
|
| 312 |
ticket.setL4AuthUser(assigneeUserId);
|
- |
|
| 313 |
break;
|
- |
|
| 314 |
case L5:
|
- |
|
| 315 |
ticket.setL5AuthUser(assigneeUserId);
|
- |
|
| 316 |
break;
|
- |
|
| 317 |
|
282 |
|
| 318 |
default:
|
- |
|
| 319 |
break;
|
283 |
// One-step escalation: pick the current-level assignee (with fallback to next level if
|
| 320 |
}
|
- |
|
| 321 |
escalationTypeNext = escalationTypeNext.next();
|
284 |
// the current level has no one configured), then pick one more level up as the manager.
|
| 322 |
// LOGGER.info("Escalation type next {}", escalationTypeNext);
|
285 |
// History is preserved in ticket_assigned; Ticket only carries current state.
|
| 323 |
} while (!escalationTypeNext.equals(EscalationType.Final));
|
286 |
EscalationAssignmentResult assigneeResult =
|
| 324 |
|
- |
|
| 325 |
int assigneeAuthId = assigneeUserIds.stream().findFirst().orElse(0);
|
287 |
this.getAuthUserWithFallback(ticketCategory.getId(), newEscalationType, ticket.getFofoId());
|
| 326 |
|
288 |
|
| 327 |
int managerAuthId = 0;
|
289 |
int assigneeAuthId;
|
| 328 |
EscalationType assigneeEscalationType = null;
|
290 |
EscalationType assigneeEscalationType;
|
| - |
|
291 |
int managerAuthId;
|
| - |
|
292 |
|
| 329 |
if (assigneeAuthId == 0) {
|
293 |
if (assigneeResult.getAuthUserId() == 0) {
|
| 330 |
assigneeAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
294 |
assigneeAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
| 331 |
assigneeEscalationType = EscalationType.Final;
|
295 |
assigneeEscalationType = EscalationType.Final;
|
| 332 |
managerAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
296 |
managerAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
| 333 |
} else {
|
297 |
} else {
|
| - |
|
298 |
assigneeAuthId = assigneeResult.getAuthUserId();
|
| 334 |
assigneeEscalationType = escalationUserMap.get(assigneeAuthId);
|
299 |
assigneeEscalationType = assigneeResult.getActualEscalationType();
|
| - |
|
300 |
|
| 335 |
managerAuthId = assigneeUserIds.stream().skip(1).findFirst().orElse(0);
|
301 |
EscalationType managerLevel = assigneeEscalationType.next();
|
| 336 |
if (managerAuthId == 0) {
|
302 |
if (managerLevel == null || managerLevel.equals(EscalationType.Final)) {
|
| 337 |
managerAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
303 |
managerAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
| - |
|
304 |
} else {
|
| - |
|
305 |
EscalationAssignmentResult managerResult =
|
| - |
|
306 |
this.getAuthUserWithFallback(ticketCategory.getId(), managerLevel, ticket.getFofoId());
|
| - |
|
307 |
managerAuthId = managerResult.getAuthUserId() > 0
|
| - |
|
308 |
? managerResult.getAuthUserId()
|
| - |
|
309 |
: ProfitMandiConstants.FINAL_AUTH_ID;
|
| 338 |
}
|
310 |
}
|
| 339 |
}
|
311 |
}
|
| 340 |
|
312 |
|
| - |
|
313 |
ticket.setCurrentAssigneeId(assigneeAuthId);
|
| - |
|
314 |
ticket.setCurrentManagerId(managerAuthId);
|
| - |
|
315 |
ticket.setCurrentEscalationLevel(assigneeEscalationType);
|
| - |
|
316 |
|
| 341 |
TicketAssigned ticketAssignedNew = new TicketAssigned();
|
317 |
TicketAssigned ticketAssignedNew = new TicketAssigned();
|
| 342 |
ticketAssignedNew.setTicketId(ticket.getId());
|
318 |
ticketAssignedNew.setTicketId(ticket.getId());
|
| 343 |
ticketAssignedNew.setAssineeId(assigneeAuthId);
|
319 |
ticketAssignedNew.setAssineeId(assigneeAuthId);
|
| 344 |
ticketAssignedNew.setEscalationType(assigneeEscalationType);
|
320 |
ticketAssignedNew.setEscalationType(assigneeEscalationType);
|
| 345 |
ticketAssignedNew.setManagerId(managerAuthId);
|
321 |
ticketAssignedNew.setManagerId(managerAuthId);
|
| Line 364... |
Line 340... |
| 364 |
} else {
|
340 |
} else {
|
| 365 |
this.addActivity(ticket, this.createActivity(ActivityType.ASSIGNED, "Ticket assigned to " + authUser.getName(), currentUserId));
|
341 |
this.addActivity(ticket, this.createActivity(ActivityType.ASSIGNED, "Ticket assigned to " + authUser.getName(), currentUserId));
|
| 366 |
}
|
342 |
}
|
| 367 |
}
|
343 |
}
|
| 368 |
|
344 |
|
| - |
|
345 |
@Override
|
| - |
|
346 |
public boolean isInEscalationChain(int ticketId, int authId) {
|
| - |
|
347 |
if (ticketId <= 0 || authId <= 0) {
|
| - |
|
348 |
return false;
|
| - |
|
349 |
}
|
| - |
|
350 |
return ticketAssignedRepository.selectByAssigneeIdAndTicketId(authId, ticketId) != null;
|
| - |
|
351 |
}
|
| - |
|
352 |
|
| - |
|
353 |
@Override
|
| - |
|
354 |
public Set<Integer> ticketsInEscalationChain(int authId, List<Integer> ticketIds) {
|
| - |
|
355 |
if (authId <= 0 || ticketIds == null || ticketIds.isEmpty()) {
|
| - |
|
356 |
return Collections.emptySet();
|
| - |
|
357 |
}
|
| - |
|
358 |
return ticketAssignedRepository.selectByTicketIds(ticketIds).stream()
|
| - |
|
359 |
.filter(ta -> ta.getAssineeId() == authId)
|
| - |
|
360 |
.map(TicketAssigned::getTicketId)
|
| - |
|
361 |
.collect(Collectors.toSet());
|
| - |
|
362 |
}
|
| - |
|
363 |
|
| 369 |
public void updateTicket(int categoryId, int subCategoryId, Ticket ticket, int authUserId, EscalationType escalationType) throws ProfitMandiBusinessException {
|
364 |
public void updateTicket(int categoryId, int subCategoryId, Ticket ticket, int authUserId, EscalationType escalationType) throws ProfitMandiBusinessException {
|
| 370 |
this.updateTicket(categoryId, subCategoryId, ticket, authUserId, escalationType, null,0);
|
365 |
this.updateTicket(categoryId, subCategoryId, ticket, authUserId, escalationType, null,0);
|
| 371 |
}
|
366 |
}
|
| 372 |
|
367 |
|
| 373 |
@Override
|
368 |
@Override
|
| Line 422... |
Line 417... |
| 422 |
|
417 |
|
| 423 |
LOGGER.info("authUser {}", authUser);
|
418 |
LOGGER.info("authUser {}", authUser);
|
| 424 |
|
419 |
|
| 425 |
int managerAuthId = authUser.getManagerId();
|
420 |
int managerAuthId = authUser.getManagerId();
|
| 426 |
|
421 |
|
| 427 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
- |
|
| 428 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketSubCategory.getCategoryId());
|
422 |
// One-step model: the manual assignment records the current assignee and the
|
| 429 |
|
- |
|
| 430 |
int authUserL2 = this.getAuthUserId(ticketCategory.getId(), EscalationType.L2, ticket.getFofoId());
|
423 |
// configured next-level manager. Downstream escalations still walk one level per
|
| 431 |
int authUserL3 = this.getAuthUserId(ticketCategory.getId(), EscalationType.L3, ticket.getFofoId());
|
- |
|
| 432 |
int authUserL4 = this.getAuthUserId(ticketCategory.getId(), EscalationType.L4, ticket.getFofoId());
|
- |
|
| 433 |
int authUserL5 = this.getAuthUserId(ticketCategory.getId(), EscalationType.L5, ticket.getFofoId());
|
424 |
// cron cycle in assignTicket(). History remains in ticket_assigned.
|
| 434 |
|
- |
|
| 435 |
if (escalationType.equals(EscalationType.L1)) {
|
- |
|
| 436 |
ticket.setL1AuthUser(authUserId);
|
425 |
int nextLevelManagerId = 0;
|
| 437 |
ticket.setL2AuthUser(authUserL2);
|
- |
|
| 438 |
ticket.setL3AuthUser(authUserL3);
|
426 |
if (escalationType != null) {
|
| 439 |
ticket.setL4AuthUser(authUserL4);
|
- |
|
| 440 |
ticket.setL5AuthUser(authUserL5);
|
427 |
EscalationType nextLevel = escalationType.next();
|
| 441 |
} else if (escalationType.equals(EscalationType.L2)) {
|
428 |
if (nextLevel != null && !nextLevel.equals(EscalationType.Final)) {
|
| 442 |
ticket.setL2AuthUser(authUserId);
|
429 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
| 443 |
ticket.setL3AuthUser(authUserL3);
|
- |
|
| 444 |
ticket.setL4AuthUser(authUserL4);
|
430 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketSubCategory.getCategoryId());
|
| 445 |
ticket.setL5AuthUser(authUserL5);
|
431 |
EscalationAssignmentResult mgr =
|
| 446 |
}
|
- |
|
| 447 |
if (escalationType.equals(EscalationType.L3)) {
|
432 |
this.getAuthUserWithFallback(ticketCategory.getId(), nextLevel, ticket.getFofoId());
|
| 448 |
ticket.setL3AuthUser(authUserId);
|
433 |
nextLevelManagerId = mgr.getAuthUserId();
|
| 449 |
ticket.setL4AuthUser(authUserL4);
|
- |
|
| 450 |
ticket.setL5AuthUser(authUserL5);
|
- |
|
| 451 |
}
|
434 |
}
|
| 452 |
if (escalationType.equals(EscalationType.L4)) {
|
- |
|
| 453 |
|
- |
|
| 454 |
ticket.setL4AuthUser(authUserId);
|
- |
|
| 455 |
ticket.setL5AuthUser(authUserL5);
|
- |
|
| 456 |
}
|
435 |
}
|
| 457 |
if (escalationType.equals(EscalationType.L5)) {
|
436 |
if (nextLevelManagerId <= 0) {
|
| 458 |
ticket.setL5AuthUser(authUserId);
|
437 |
nextLevelManagerId = managerAuthId > 0 ? managerAuthId : ProfitMandiConstants.FINAL_AUTH_ID;
|
| 459 |
}
|
438 |
}
|
| 460 |
|
439 |
|
| - |
|
440 |
ticket.setCurrentAssigneeId(authUserId);
|
| - |
|
441 |
ticket.setCurrentManagerId(nextLevelManagerId);
|
| - |
|
442 |
ticket.setCurrentEscalationLevel(escalationType);
|
| 461 |
|
443 |
|
| 462 |
TicketAssigned ticketAssignedNew = new TicketAssigned();
|
444 |
TicketAssigned ticketAssignedNew = new TicketAssigned();
|
| 463 |
ticketAssignedNew.setTicketId(ticket.getId());
|
445 |
ticketAssignedNew.setTicketId(ticket.getId());
|
| 464 |
ticketAssignedNew.setAssineeId(authUserId);
|
446 |
ticketAssignedNew.setAssineeId(authUserId);
|
| 465 |
ticketAssignedNew.setEscalationType(escalationType);
|
447 |
ticketAssignedNew.setEscalationType(escalationType);
|
| Line 614... |
Line 596... |
| 614 |
@Override
|
596 |
@Override
|
| 615 |
public Map<Integer, AuthUser> getTicketIdAndAuthUserMapUsingTickets(List<Ticket> tickets) {
|
597 |
public Map<Integer, AuthUser> getTicketIdAndAuthUserMapUsingTickets(List<Ticket> tickets) {
|
| 616 |
if (tickets == null || tickets.isEmpty()) {
|
598 |
if (tickets == null || tickets.isEmpty()) {
|
| 617 |
return new HashMap<>();
|
599 |
return new HashMap<>();
|
| 618 |
}
|
600 |
}
|
| 619 |
// OPTIMIZED: Batch fetch all AuthUsers instead of N+1 queries
|
601 |
// Batch fetch AuthUsers by current_assignee_id (one owner per ticket in the new model).
|
| 620 |
List<Integer> authUserIds = tickets.stream()
|
602 |
List<Integer> authUserIds = tickets.stream()
|
| 621 |
.map(this::getEffectiveAuthUserId)
|
603 |
.map(Ticket::getCurrentAssigneeId)
|
| 622 |
.filter(id -> id != null && id > 0)
|
604 |
.filter(id -> id > 0)
|
| 623 |
.distinct()
|
605 |
.distinct()
|
| 624 |
.collect(Collectors.toList());
|
606 |
.collect(Collectors.toList());
|
| 625 |
Map<Integer, AuthUser> authUserById = authRepository.selectByIds(authUserIds).stream()
|
607 |
Map<Integer, AuthUser> authUserById = authRepository.selectByIds(authUserIds).stream()
|
| 626 |
.collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
|
608 |
.collect(Collectors.toMap(AuthUser::getId, au -> au, (a, b) -> a));
|
| 627 |
|
609 |
|
| 628 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
610 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
| 629 |
for (Ticket ticket : tickets) {
|
611 |
for (Ticket ticket : tickets) {
|
| 630 |
authUserIdAndAuthUserMap.put(ticket.getId(), authUserById.get(ticket.getL1AuthUser()));
|
612 |
authUserIdAndAuthUserMap.put(ticket.getId(), authUserById.get(ticket.getCurrentAssigneeId()));
|
| 631 |
}
|
613 |
}
|
| 632 |
return authUserIdAndAuthUserMap;
|
614 |
return authUserIdAndAuthUserMap;
|
| 633 |
}
|
615 |
}
|
| 634 |
|
616 |
|
| 635 |
private Integer getEffectiveAuthUserId(Ticket ticket) {
|
- |
|
| 636 |
|
- |
|
| 637 |
if (ticket.getL1AuthUser() > 0) {
|
- |
|
| 638 |
return ticket.getL1AuthUser();
|
- |
|
| 639 |
}
|
- |
|
| 640 |
if (ticket.getL2AuthUser() > 0) {
|
- |
|
| 641 |
return ticket.getL2AuthUser();
|
- |
|
| 642 |
}
|
- |
|
| 643 |
if (ticket.getL3AuthUser() > 0) {
|
- |
|
| 644 |
return ticket.getL3AuthUser();
|
- |
|
| 645 |
}
|
- |
|
| 646 |
if (ticket.getL4AuthUser() > 0) {
|
- |
|
| 647 |
return ticket.getL4AuthUser();
|
- |
|
| 648 |
}
|
- |
|
| 649 |
return null;
|
- |
|
| 650 |
}
|
- |
|
| 651 |
|
- |
|
| 652 |
|
617 |
|
| 653 |
@Override
|
618 |
@Override
|
| 654 |
public Map<Integer, TicketSubCategory> getSubCategoryIdAndSubCategoryMap(List<Integer> subCategoryIds) {
|
619 |
public Map<Integer, TicketSubCategory> getSubCategoryIdAndSubCategoryMap(List<Integer> subCategoryIds) {
|
| 655 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = new HashMap<>();
|
620 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = new HashMap<>();
|
| 656 |
subCategoryIdAndSubCategoryMap = ticketSubCategoryRepository.selectByIds(subCategoryIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
621 |
subCategoryIdAndSubCategoryMap = ticketSubCategoryRepository.selectByIds(subCategoryIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|