| Line 313... |
Line 313... |
| 313 |
}
|
313 |
}
|
| 314 |
|
314 |
|
| 315 |
@PostMapping(value = "/cs/createPosition")
|
315 |
@PostMapping(value = "/cs/createPosition")
|
| 316 |
public String createPosition(HttpServletRequest request, @RequestBody CreatePositionModel createPositionModel, Model model) throws Exception {
|
316 |
public String createPosition(HttpServletRequest request, @RequestBody CreatePositionModel createPositionModel, Model model) throws Exception {
|
| 317 |
|
317 |
|
| 318 |
|
- |
|
| 319 |
LOGGER.info("partnerPosition" + createPositionModel.isTicketAssigned());
|
318 |
LOGGER.info("partnerPosition" + createPositionModel.isTicketAssigned());
|
| - |
|
319 |
|
| - |
|
320 |
// Validate authUserId exists
|
| - |
|
321 |
int authUserId = createPositionModel.getAuthUserId();
|
| - |
|
322 |
if (authUserId <= 0 || authRepository.selectById(authUserId) == null) {
|
| - |
|
323 |
throw new ProfitMandiBusinessException("Position", authUserId, "Invalid authUserId");
|
| - |
|
324 |
}
|
| - |
|
325 |
|
| - |
|
326 |
// Validate categoryId exists (0 means "All Categories")
|
| - |
|
327 |
int categoryId = createPositionModel.getCategoryId();
|
| - |
|
328 |
if (categoryId > 0 && ticketCategoryRepository.selectById(categoryId) == null) {
|
| - |
|
329 |
throw new ProfitMandiBusinessException("Position", categoryId, "Invalid categoryId");
|
| - |
|
330 |
}
|
| - |
|
331 |
|
| - |
|
332 |
// Validate regionId exists (0 or 5 typically means "All Partners/Regions")
|
| - |
|
333 |
int regionId = createPositionModel.getRegionId();
|
| - |
|
334 |
if (regionId > 0 && regionId != 5 && regionRepository.selectById(regionId) == null) {
|
| - |
|
335 |
throw new ProfitMandiBusinessException("Position", regionId, "Invalid regionId");
|
| - |
|
336 |
}
|
| - |
|
337 |
|
| - |
|
338 |
// Validate fofoIds exist
|
| - |
|
339 |
List<Integer> fofoIds = createPositionModel.getFofoIds();
|
| - |
|
340 |
if (fofoIds != null && !fofoIds.isEmpty()) {
|
| - |
|
341 |
Map<Integer, CustomRetailer> validRetailers = retailerService.getFofoRetailers(false);
|
| - |
|
342 |
for (int fofoId : fofoIds) {
|
| - |
|
343 |
if (!validRetailers.containsKey(fofoId)) {
|
| - |
|
344 |
throw new ProfitMandiBusinessException("Position", fofoId, "Invalid fofoId");
|
| - |
|
345 |
}
|
| - |
|
346 |
}
|
| - |
|
347 |
}
|
| - |
|
348 |
|
| 320 |
Position position = positionRepository.selectPosition(createPositionModel.getAuthUserId(), createPositionModel.getCategoryId(), createPositionModel.getRegionId(), createPositionModel.getEscalationType());
|
349 |
Position position = positionRepository.selectPosition(authUserId, categoryId, regionId, createPositionModel.getEscalationType());
|
| 321 |
if (position == null) {
|
350 |
if (position == null) {
|
| 322 |
position = new Position();
|
351 |
position = new Position();
|
| 323 |
position.setAuthUserId(createPositionModel.getAuthUserId());
|
352 |
position.setAuthUserId(authUserId);
|
| 324 |
position.setCategoryId(createPositionModel.getCategoryId());
|
353 |
position.setCategoryId(categoryId);
|
| 325 |
position.setEscalationType(createPositionModel.getEscalationType());
|
354 |
position.setEscalationType(createPositionModel.getEscalationType());
|
| 326 |
position.setRegionId(createPositionModel.getRegionId());
|
355 |
position.setRegionId(regionId);
|
| 327 |
position.setCreateTimestamp(LocalDateTime.now());
|
356 |
position.setCreateTimestamp(LocalDateTime.now());
|
| 328 |
position.setTicketAssignee(createPositionModel.isTicketAssigned());
|
357 |
position.setTicketAssignee(createPositionModel.isTicketAssigned());
|
| 329 |
positionRepository.persist(position);
|
358 |
positionRepository.persist(position);
|
| 330 |
|
359 |
|
| - |
|
360 |
if (fofoIds != null) {
|
| 331 |
for (int fofoId : createPositionModel.getFofoIds()) {
|
361 |
for (int fofoId : fofoIds) {
|
| 332 |
|
- |
|
| 333 |
PartnerPosition partnerPosition = new PartnerPosition();
|
362 |
PartnerPosition partnerPosition = new PartnerPosition();
|
| 334 |
partnerPosition.setFofoId(fofoId);
|
363 |
partnerPosition.setFofoId(fofoId);
|
| 335 |
partnerPosition.setRegionId(createPositionModel.getRegionId());
|
364 |
partnerPosition.setRegionId(regionId);
|
| 336 |
partnerPosition.setPositionId(position.getId());
|
365 |
partnerPosition.setPositionId(position.getId());
|
| 337 |
partnerPositionRepository.persist(partnerPosition);
|
366 |
partnerPositionRepository.persist(partnerPosition);
|
| 338 |
LOGGER.info("partnerPosition" + partnerPosition);
|
367 |
LOGGER.info("partnerPosition" + partnerPosition);
|
| - |
|
368 |
}
|
| 339 |
}
|
369 |
}
|
| 340 |
|
370 |
|
| 341 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
371 |
model.addAttribute("response1", mvcResponseSender.createResponseString(true));
|
| 342 |
} else {
|
372 |
} else {
|
| 343 |
throw new ProfitMandiBusinessException("Position", createPositionModel.getAuthUserId(), "already exists!");
|
373 |
throw new ProfitMandiBusinessException("Position", authUserId, "already exists!");
|
| 344 |
}
|
374 |
}
|
| 345 |
return "response";
|
375 |
return "response";
|
| 346 |
}
|
376 |
}
|
| 347 |
|
377 |
|
| 348 |
@PostMapping(value = "/cs/updatePartnerPosition")
|
378 |
@PostMapping(value = "/cs/updatePartnerPosition")
|
| Line 532... |
Line 562... |
| 532 |
|
562 |
|
| 533 |
|
563 |
|
| 534 |
@GetMapping(value = "/cs/getActivities")
|
564 |
@GetMapping(value = "/cs/getActivities")
|
| 535 |
public String getActivity(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) throws Exception {
|
565 |
public String getActivity(HttpServletRequest request, @RequestParam(name = "ticketId", defaultValue = "0") int ticketId, Model model) throws Exception {
|
| 536 |
List<Activity> allactivities = activityRepository.selectAll(ticketId);
|
566 |
List<Activity> allactivities = activityRepository.selectAll(ticketId);
|
| - |
|
567 |
|
| - |
|
568 |
// Batch fetch all documents for attachments (fix N+1 query)
|
| 537 |
List<List<ActivityAttachment>> activityAttachments = allactivities.stream().map(x -> x.getActivityAttachment()).collect(Collectors.toList());
|
569 |
List<Integer> documentIds = allactivities.stream()
|
| 538 |
for (List<ActivityAttachment> aA : activityAttachments) {
|
570 |
.flatMap(a -> a.getActivityAttachment().stream())
|
| 539 |
// List<ActivityAttachment> documentId = aA.stream().map(x ->
|
571 |
.map(ActivityAttachment::getDocumentId)
|
| - |
|
572 |
.distinct()
|
| 540 |
// x).collect(Collectors.toList());
|
573 |
.collect(Collectors.toList());
|
| - |
|
574 |
|
| - |
|
575 |
Map<Integer, Document> documentMap = Collections.emptyMap();
|
| - |
|
576 |
if (!documentIds.isEmpty()) {
|
| - |
|
577 |
documentMap = documentRepository.selectByIds(documentIds).stream()
|
| - |
|
578 |
.collect(Collectors.toMap(Document::getId, d -> d));
|
| - |
|
579 |
}
|
| - |
|
580 |
|
| - |
|
581 |
// Set document names transiently (do not persist during GET)
|
| - |
|
582 |
for (Activity activity : allactivities) {
|
| 541 |
for (ActivityAttachment attachment : aA) {
|
583 |
for (ActivityAttachment attachment : activity.getActivityAttachment()) {
|
| 542 |
Document document = documentRepository.selectById(attachment.getDocumentId());
|
584 |
Document document = documentMap.get(attachment.getDocumentId());
|
| - |
|
585 |
if (document != null) {
|
| 543 |
attachment.setDocumentName(document.getDisplayName());
|
586 |
attachment.setDocumentName(document.getDisplayName());
|
| 544 |
activityAttachmentRepository.persist(attachment);
|
587 |
}
|
| 545 |
}
|
588 |
}
|
| 546 |
}
|
589 |
}
|
| 547 |
List<Activity> activities = null;
|
590 |
List<Activity> activities = null;
|
| 548 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
591 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 549 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
592 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| Line 778... |
Line 821... |
| 778 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
821 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = csService.getSubCategoryIdAndCategoryMap(subCategoryIds);
|
| 779 |
|
822 |
|
| 780 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
823 |
List<Integer> ticketIds = tickets.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 781 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
824 |
Map<Integer, List<Activity>> activityMap = new HashMap<>();
|
| 782 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
825 |
Map<Integer, List<Activity>> activityMapWithActivityId = new HashMap<>();
|
| - |
|
826 |
Map<Integer, AuthUser> authUserMap = new HashMap<>();
|
| 783 |
|
827 |
|
| 784 |
if (!ticketIds.isEmpty()) {
|
828 |
if (!ticketIds.isEmpty()) {
|
| - |
|
829 |
// Fetch activities once and reuse for both maps (fix duplicate query)
|
| - |
|
830 |
List<Activity> allActivities = activityRepository.selectAll(ticketIds);
|
| 785 |
activityMap = activityRepository.selectAll(ticketIds).stream().collect(Collectors.groupingBy(x -> x.getTicketId()));
|
831 |
activityMap = allActivities.stream().collect(Collectors.groupingBy(Activity::getTicketId));
|
| 786 |
activityMapWithActivityId = activityRepository.selectAll(ticketIds).stream().collect(Collectors.groupingBy(x -> x.getId()));
|
832 |
activityMapWithActivityId = allActivities.stream().collect(Collectors.groupingBy(Activity::getId));
|
| 787 |
|
833 |
|
| - |
|
834 |
// Only fetch users who created activities (fix loading ALL users)
|
| - |
|
835 |
Set<Integer> activityCreatorIds = allActivities.stream()
|
| - |
|
836 |
.map(Activity::getCreatedBy)
|
| - |
|
837 |
.filter(id -> id > 0)
|
| - |
|
838 |
.collect(Collectors.toSet());
|
| - |
|
839 |
if (!activityCreatorIds.isEmpty()) {
|
| - |
|
840 |
authUserMap = authRepository.selectByIds(new ArrayList<>(activityCreatorIds))
|
| - |
|
841 |
.stream().collect(Collectors.toMap(AuthUser::getId, x -> x));
|
| - |
|
842 |
}
|
| 788 |
}
|
843 |
}
|
| 789 |
|
844 |
|
| 790 |
List<AuthUser> authUsersList = authRepository.selectAll();
|
- |
|
| 791 |
Map<Integer, AuthUser> authUserMap = authUsersList.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
- |
|
| 792 |
|
- |
|
| 793 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
845 |
model.addAttribute("ticketStatusValues", TicketStatus.values());
|
| 794 |
model.addAttribute("orderByValues", SortOrder.values());
|
846 |
model.addAttribute("orderByValues", SortOrder.values());
|
| 795 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
847 |
model.addAttribute("selectedticketStatus", ticketStatus);
|
| 796 |
model.addAttribute("selectedorderby", sortOrder);
|
848 |
model.addAttribute("selectedorderby", sortOrder);
|
| 797 |
model.addAttribute("tickets", tickets);
|
849 |
model.addAttribute("tickets", tickets);
|