| 24383 |
amit.gupta |
1 |
package com.spice.profitmandi.dao.repository.cs;
|
| 24500 |
govind |
2 |
|
| 24383 |
amit.gupta |
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24417 |
govind |
4 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 24439 |
govind |
5 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
6 |
import com.spice.profitmandi.common.util.Utils;
|
| 24417 |
govind |
7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 31829 |
amit.gupta |
8 |
import com.spice.profitmandi.dao.entity.cs.*;
|
| 24383 |
amit.gupta |
9 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
| 30003 |
tejbeer |
10 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 32923 |
ranu |
11 |
import com.spice.profitmandi.dao.enumuration.auth.CollectionRemark;
|
| 24417 |
govind |
12 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 32923 |
ranu |
13 |
import com.spice.profitmandi.dao.model.ActivityMediaModel;
|
| 30003 |
tejbeer |
14 |
import com.spice.profitmandi.dao.model.FofoReportingModel;
|
| 33161 |
ranu |
15 |
import com.spice.profitmandi.dao.model.FofoRBMReportingModel;
|
| 24417 |
govind |
16 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 25570 |
tejbeer |
17 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24417 |
govind |
18 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 31829 |
amit.gupta |
19 |
import org.apache.commons.collections4.map.HashedMap;
|
|
|
20 |
import org.apache.commons.lang.RandomStringUtils;
|
|
|
21 |
import org.apache.commons.lang.StringUtils;
|
|
|
22 |
import org.apache.logging.log4j.LogManager;
|
|
|
23 |
import org.apache.logging.log4j.Logger;
|
|
|
24 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
25 |
import org.springframework.cache.annotation.Cacheable;
|
|
|
26 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
27 |
import org.springframework.stereotype.Component;
|
| 24383 |
amit.gupta |
28 |
|
| 31829 |
amit.gupta |
29 |
import java.time.LocalDateTime;
|
|
|
30 |
import java.util.*;
|
|
|
31 |
import java.util.stream.Collectors;
|
|
|
32 |
|
| 24383 |
amit.gupta |
33 |
@Component
|
|
|
34 |
public class CsServiceImpl implements CsService {
|
| 24417 |
govind |
35 |
|
| 31762 |
tejbeer |
36 |
private static final int ALL_PARTNERS_REGION = 5;
|
| 27124 |
amit.gupta |
37 |
|
| 31762 |
tejbeer |
38 |
private static final Logger LOGGER = LogManager.getLogger(CsServiceImpl.class);
|
| 24439 |
govind |
39 |
|
| 31762 |
tejbeer |
40 |
private static final String ASSIGNED_TICKET = "Dear %s, New ticket #%s #%s created by %s has been assigned to you. Regards\nSmartdukaan";
|
|
|
41 |
private static final String ESCALATED_TICKET = "Dear %s, Ticket #%s #%s created by %s has been escalated to you. Regards\nSmartdukaan";
|
|
|
42 |
private static final String CATEGORY_CHANGED_TICKET = "Dear team, Category of Ticket #%s created by %s has been changed to %s. Regards\nSmartdukaan";
|
|
|
43 |
private static final String ASSINMENT_SUBJECT = "Assignment Ticket";
|
| 24439 |
govind |
44 |
|
| 31762 |
tejbeer |
45 |
@Autowired
|
|
|
46 |
TicketRepository ticketRepository;
|
| 24417 |
govind |
47 |
|
| 31762 |
tejbeer |
48 |
@Autowired
|
|
|
49 |
JavaMailSender mailSender;
|
| 24439 |
govind |
50 |
|
| 31762 |
tejbeer |
51 |
@Autowired
|
|
|
52 |
TicketCategoryRepository ticketCategoryRepository;
|
| 24417 |
govind |
53 |
|
| 31762 |
tejbeer |
54 |
@Autowired
|
|
|
55 |
TicketSubCategoryRepository ticketSubCategoryRepository;
|
| 24417 |
govind |
56 |
|
| 31762 |
tejbeer |
57 |
@Autowired
|
|
|
58 |
ActivityRepository activityRepository;
|
| 24417 |
govind |
59 |
|
| 31762 |
tejbeer |
60 |
@Autowired
|
| 32923 |
ranu |
61 |
TicketActivityMediaRepository activityMediaRepository;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
| 31762 |
tejbeer |
64 |
PartnerRegionRepository partnerRegionRepository;
|
| 24417 |
govind |
65 |
|
| 31762 |
tejbeer |
66 |
@Autowired
|
|
|
67 |
private PositionRepository positionRepository;
|
| 24417 |
govind |
68 |
|
| 31762 |
tejbeer |
69 |
@Autowired
|
|
|
70 |
private AuthRepository authRepository;
|
| 24417 |
govind |
71 |
|
| 31762 |
tejbeer |
72 |
@Autowired
|
|
|
73 |
private RetailerService retailerService;
|
| 24500 |
govind |
74 |
|
| 31762 |
tejbeer |
75 |
@Autowired
|
|
|
76 |
private RegionRepository regionRepository;
|
| 24417 |
govind |
77 |
|
| 31762 |
tejbeer |
78 |
@Autowired
|
|
|
79 |
private TicketAssignedRepository ticketAssignedRepository;
|
| 24500 |
govind |
80 |
|
| 31762 |
tejbeer |
81 |
@Autowired
|
| 32493 |
amit.gupta |
82 |
private PartnerPositionRepository partnerPositionRepository;
|
| 25570 |
tejbeer |
83 |
|
| 31762 |
tejbeer |
84 |
@Autowired
|
|
|
85 |
private FofoStoreRepository fofoStoreRepository;
|
| 25570 |
tejbeer |
86 |
|
| 31762 |
tejbeer |
87 |
@Override
|
|
|
88 |
public void createTicket(int fofoId, int categoryId, int subcategoryId, String message) throws ProfitMandiBusinessException {
|
| 32923 |
ranu |
89 |
this.createTicket(fofoId, categoryId, subcategoryId, message, 0);
|
|
|
90 |
}
|
| 24417 |
govind |
91 |
|
| 32923 |
ranu |
92 |
|
|
|
93 |
@Override
|
|
|
94 |
public void createTicket(int fofoId, int categoryId, int subcategoryId, String message, int createdByAuthId) throws ProfitMandiBusinessException {
|
|
|
95 |
|
| 31762 |
tejbeer |
96 |
ActivityType type = ActivityType.OPENED;
|
|
|
97 |
Ticket ticket = new Ticket();
|
|
|
98 |
ticket.setSubCategoryId(subcategoryId);
|
|
|
99 |
ticket.setFofoId(fofoId);
|
|
|
100 |
ticket.setCreateTimestamp(LocalDateTime.now());
|
|
|
101 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
102 |
ticket.setHappyCode(getRandomString());
|
|
|
103 |
ticketRepository.persist(ticket);
|
| 32923 |
ranu |
104 |
this.addActivity(ticket, this.createActivity(type, message, createdByAuthId));
|
|
|
105 |
ticket.setFirstActivityId(ticket.getLastActivityId());
|
| 33041 |
ranu |
106 |
if (createdByAuthId != 0) {
|
|
|
107 |
int l2AuthUser = this.getAuthUserId(categoryId, EscalationType.L2, fofoId);
|
| 32923 |
ranu |
108 |
this.updateTicket(categoryId, subcategoryId, ticket, l2AuthUser, EscalationType.L2);
|
| 33041 |
ranu |
109 |
} else {
|
| 32923 |
ranu |
110 |
this.assignTicket(ticket);
|
|
|
111 |
}
|
| 27124 |
amit.gupta |
112 |
|
| 31762 |
tejbeer |
113 |
}
|
| 27124 |
amit.gupta |
114 |
|
| 31762 |
tejbeer |
115 |
@Override
|
| 32923 |
ranu |
116 |
public void createTicketWithMedia(int fofoId, int categoryId, int subcategoryId, String message, int createdByAuthId, ActivityMediaModel selectedRecording) throws ProfitMandiBusinessException {
|
|
|
117 |
ActivityType type = ActivityType.OPENED;
|
|
|
118 |
Ticket ticket = new Ticket();
|
|
|
119 |
ticket.setSubCategoryId(subcategoryId);
|
|
|
120 |
ticket.setFofoId(fofoId);
|
|
|
121 |
ticket.setCreateTimestamp(LocalDateTime.now());
|
|
|
122 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
123 |
ticket.setHappyCode(getRandomString());
|
|
|
124 |
ticketRepository.persist(ticket);
|
|
|
125 |
this.addActivity(ticket, this.createActivity(type, message, createdByAuthId));
|
|
|
126 |
this.addMediaActivity(ticket, this.createMediaActivity(selectedRecording));
|
|
|
127 |
ticket.setFirstActivityId(ticket.getLastActivityId());
|
| 33041 |
ranu |
128 |
if (createdByAuthId != 0) {
|
|
|
129 |
int l2AuthUser = this.getAuthUserId(categoryId, EscalationType.L2, fofoId);
|
| 32923 |
ranu |
130 |
this.updateTicket(categoryId, subcategoryId, ticket, l2AuthUser, EscalationType.L2);
|
| 33041 |
ranu |
131 |
} else {
|
| 32923 |
ranu |
132 |
this.assignTicket(ticket);
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
|
|
|
136 |
public TicketActivityMedia createMediaActivity(ActivityMediaModel selectedRecording) {
|
|
|
137 |
TicketActivityMedia activity = new TicketActivityMedia();
|
|
|
138 |
activity.setMobile(selectedRecording.getMobile());
|
| 33009 |
ranu |
139 |
// add a prefix endpoint of mediaUrl
|
|
|
140 |
String customValue = "https://ccs1.smartpingcc.io/v2/recording/direct/71287091";
|
| 33041 |
ranu |
141 |
activity.setMediaUrl(customValue + selectedRecording.getMediaUrl());
|
| 32923 |
ranu |
142 |
activity.setDurationInSec(selectedRecording.getDurationInSec());
|
|
|
143 |
activity.setCallTime(selectedRecording.getCallConnectTime());
|
|
|
144 |
activity.setCreatedBy(0);
|
|
|
145 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
146 |
activityMediaRepository.persist(activity);
|
|
|
147 |
return activity;
|
|
|
148 |
}
|
|
|
149 |
|
|
|
150 |
public void addMediaActivity(Ticket ticket, TicketActivityMedia activity) {
|
| 32940 |
ranu |
151 |
activity.setActivityId(ticket.getLastActivityId());
|
| 32923 |
ranu |
152 |
}
|
|
|
153 |
|
|
|
154 |
@Override
|
|
|
155 |
public void createTicketRemarkEscalation(int fofoId, int authId, int categoryId, int subcategoryId, String message, CollectionRemark remark) throws ProfitMandiBusinessException {
|
|
|
156 |
|
|
|
157 |
ActivityType type = ActivityType.OPENED;
|
|
|
158 |
Ticket ticket = new Ticket();
|
|
|
159 |
ticket.setSubCategoryId(subcategoryId);
|
|
|
160 |
ticket.setFofoId(fofoId);
|
|
|
161 |
ticket.setCreateTimestamp(LocalDateTime.now());
|
|
|
162 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
163 |
ticket.setHappyCode(getRandomString());
|
|
|
164 |
ticketRepository.persist(ticket);
|
|
|
165 |
this.addActivity(ticket, this.createActivity(type, String.valueOf(remark), authId));
|
|
|
166 |
ticket.setFirstActivityId(ticket.getLastActivityId());
|
| 33041 |
ranu |
167 |
this.assignTicketByAuthId(ticket, authId, EscalationType.L2);
|
| 32923 |
ranu |
168 |
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
@Override
|
| 31762 |
tejbeer |
173 |
public void assignTicket(Ticket ticket) throws ProfitMandiBusinessException {
|
|
|
174 |
TicketAssigned ticketAssigned = null;
|
|
|
175 |
EscalationType newEscalationType = EscalationType.L1;
|
|
|
176 |
if (ticket.getAssignmentId() > 0) {
|
|
|
177 |
ticketAssigned = ticketAssignedRepository.selectById(ticket.getAssignmentId());
|
|
|
178 |
newEscalationType = ticketAssigned.getEscalationType().next();
|
|
|
179 |
if (newEscalationType == null || newEscalationType.equals(EscalationType.Final)) {
|
|
|
180 |
LOGGER.info("Cant escalate further");
|
|
|
181 |
return;
|
|
|
182 |
}
|
|
|
183 |
} else {
|
|
|
184 |
ticket.setL1AuthUser(0);
|
|
|
185 |
ticket.setL2AuthUser(0);
|
|
|
186 |
ticket.setL3AuthUser(0);
|
|
|
187 |
ticket.setL4AuthUser(0);
|
|
|
188 |
ticket.setL5AuthUser(0);
|
|
|
189 |
}
|
|
|
190 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
| 27124 |
amit.gupta |
191 |
|
|
|
192 |
|
| 31762 |
tejbeer |
193 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
194 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketSubCategory.getCategoryId());
|
|
|
195 |
Map<Integer, EscalationType> escalationUserMap = new HashedMap<>();
|
|
|
196 |
Set<Integer> assigneeUserIds = new LinkedHashSet<>();
|
|
|
197 |
EscalationType escalationTypeNext = newEscalationType;
|
|
|
198 |
do {
|
|
|
199 |
int assigneeUserId = this.getAuthUserId(ticketCategory.getId(), escalationTypeNext, ticket.getFofoId());
|
|
|
200 |
if (assigneeUserId == 0) {
|
|
|
201 |
escalationTypeNext = escalationTypeNext.next();
|
|
|
202 |
LOGGER.info("Escalation type next {}", escalationTypeNext);
|
|
|
203 |
continue;
|
|
|
204 |
}
|
|
|
205 |
assigneeUserIds.add(assigneeUserId);
|
|
|
206 |
escalationUserMap.put(assigneeUserId, escalationTypeNext);
|
|
|
207 |
switch (escalationTypeNext) {
|
|
|
208 |
case L1:
|
|
|
209 |
ticket.setL1AuthUser(assigneeUserId);
|
|
|
210 |
break;
|
|
|
211 |
case L2:
|
|
|
212 |
ticket.setL2AuthUser(assigneeUserId);
|
|
|
213 |
break;
|
|
|
214 |
case L3:
|
|
|
215 |
ticket.setL3AuthUser(assigneeUserId);
|
|
|
216 |
break;
|
|
|
217 |
case L4:
|
|
|
218 |
ticket.setL4AuthUser(assigneeUserId);
|
|
|
219 |
break;
|
|
|
220 |
case L5:
|
|
|
221 |
ticket.setL5AuthUser(assigneeUserId);
|
|
|
222 |
break;
|
| 27545 |
tejbeer |
223 |
|
| 31762 |
tejbeer |
224 |
default:
|
|
|
225 |
break;
|
|
|
226 |
}
|
|
|
227 |
escalationTypeNext = escalationTypeNext.next();
|
|
|
228 |
// LOGGER.info("Escalation type next {}", escalationTypeNext);
|
|
|
229 |
} while (!escalationTypeNext.equals(EscalationType.Final));
|
| 27124 |
amit.gupta |
230 |
|
| 31762 |
tejbeer |
231 |
int assigneeAuthId = assigneeUserIds.stream().findFirst().orElse(0);
|
| 27545 |
tejbeer |
232 |
|
| 31762 |
tejbeer |
233 |
int managerAuthId = 0;
|
|
|
234 |
EscalationType assigneeEscalationType = null;
|
|
|
235 |
if (assigneeAuthId == 0) {
|
|
|
236 |
assigneeAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
|
|
237 |
assigneeEscalationType = EscalationType.Final;
|
|
|
238 |
managerAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
|
|
239 |
} else {
|
|
|
240 |
assigneeEscalationType = escalationUserMap.get(assigneeAuthId);
|
|
|
241 |
managerAuthId = assigneeUserIds.stream().skip(1).findFirst().orElse(0);
|
|
|
242 |
if (managerAuthId == 0) {
|
|
|
243 |
managerAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
|
|
244 |
}
|
|
|
245 |
}
|
| 27545 |
tejbeer |
246 |
|
| 31762 |
tejbeer |
247 |
TicketAssigned ticketAssignedNew = new TicketAssigned();
|
|
|
248 |
ticketAssignedNew.setTicketId(ticket.getId());
|
|
|
249 |
ticketAssignedNew.setAssineeId(assigneeAuthId);
|
|
|
250 |
ticketAssignedNew.setEscalationType(assigneeEscalationType);
|
|
|
251 |
ticketAssignedNew.setManagerId(managerAuthId);
|
|
|
252 |
ticketAssignedNew.setCreateTimestamp(LocalDateTime.now());
|
|
|
253 |
ticketAssignedRepository.persist(ticketAssignedNew);
|
|
|
254 |
LOGGER.info(ticketAssigned);
|
| 24383 |
amit.gupta |
255 |
|
| 31762 |
tejbeer |
256 |
AuthUser authUser = authRepository.selectById(ticketAssignedNew.getAssineeId());
|
|
|
257 |
AuthUser authUserManager = null;
|
| 27124 |
amit.gupta |
258 |
|
| 31762 |
tejbeer |
259 |
// Dont send cc mail if both are same
|
|
|
260 |
if (managerAuthId != assigneeAuthId) {
|
|
|
261 |
authUserManager = authRepository.selectById(managerAuthId);
|
|
|
262 |
}
|
|
|
263 |
ticket.setAssignmentId(ticketAssignedNew.getId());
|
| 27124 |
amit.gupta |
264 |
|
| 31762 |
tejbeer |
265 |
List<Activity> activities = activityRepository.selectAll(ticket.getId());
|
|
|
266 |
this.sendAssignedTicketMail(authUser, Arrays.asList(authUserManager), ticket, ticketAssigned != null, activities);
|
|
|
267 |
if (!ticketAssignedNew.getEscalationType().equals(EscalationType.L1)) {
|
|
|
268 |
this.addActivity(ticket, this.createActivity(ActivityType.ESCALATED, "Ticket ecalated and assigned to " + authUser.getName(), 0));
|
|
|
269 |
} else {
|
|
|
270 |
this.addActivity(ticket, this.createActivity(ActivityType.ASSIGNED, "Ticket assigned to " + authUser.getName(), 0));
|
|
|
271 |
}
|
|
|
272 |
}
|
| 27124 |
amit.gupta |
273 |
|
| 31762 |
tejbeer |
274 |
@Override
|
|
|
275 |
public void updateTicket(int categoryId, int subCategoryId, Ticket ticket, int authUserId, EscalationType escalationType) throws ProfitMandiBusinessException {
|
| 27545 |
tejbeer |
276 |
|
| 31762 |
tejbeer |
277 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.getTicketSubCategoryMap().get(subCategoryId);
|
|
|
278 |
if (ticketSubCategory == null) {
|
|
|
279 |
throw new ProfitMandiBusinessException("Could not find subCategoryId " + subCategoryId + "- " + categoryId, "Problem", "Problem");
|
|
|
280 |
}
|
|
|
281 |
String storeName = retailerService.getAllFofoRetailers().get(ticket.getFofoId()).getBusinessName();
|
|
|
282 |
List<TicketAssigned> oldTicketAssignedList = ticketAssignedRepository.selectByTicketIds(Arrays.asList(ticket.getId()));
|
|
|
283 |
for (TicketAssigned oldTicketAssigned : oldTicketAssignedList) {
|
|
|
284 |
ticketAssignedRepository.delete(oldTicketAssigned);
|
|
|
285 |
}
|
| 27124 |
amit.gupta |
286 |
|
| 31762 |
tejbeer |
287 |
if (ticket.getSubCategoryId() != ticketSubCategory.getId()) {
|
|
|
288 |
ticket.setSubCategoryId(ticketSubCategory.getId());
|
|
|
289 |
List<Integer> oldAssignedAuthUserIds = oldTicketAssignedList.stream().map(x -> x.getAssineeId()).collect(Collectors.toList());
|
|
|
290 |
List<String> oldAssignedEmailIds = authRepository.selectAllAuthUserByIds(oldAssignedAuthUserIds).stream().map(x -> x.getEmailId()).collect(Collectors.toList());
|
|
|
291 |
String mailTo = oldAssignedEmailIds.remove(0);
|
|
|
292 |
String message = String.format(CATEGORY_CHANGED_TICKET, ticket.getId(), storeName, ticketSubCategory.getTicketCategory().getName() + " - " + ticketSubCategory.getName());
|
|
|
293 |
try {
|
|
|
294 |
Utils.sendMailWithAttachments(mailSender, mailTo, oldAssignedEmailIds.toArray(new String[0]), "Ticket Category/Subcategory Changed", message, null);
|
|
|
295 |
} catch (Exception e) {
|
|
|
296 |
LOGGER.info("Could not send mail for ticket {}", ticket.toString());
|
|
|
297 |
}
|
| 24417 |
govind |
298 |
|
| 31762 |
tejbeer |
299 |
Activity categoryChangedActivity = this.createActivity(ActivityType.CATEGORY_CHANGED, "Category changed to " + ticketSubCategory.getTicketCategory().getName() + " - " + ticketSubCategory.getName(), 0);
|
|
|
300 |
this.addActivity(ticket, categoryChangedActivity);
|
| 24439 |
govind |
301 |
|
| 24383 |
amit.gupta |
302 |
|
| 31762 |
tejbeer |
303 |
}
|
| 24383 |
amit.gupta |
304 |
|
| 31762 |
tejbeer |
305 |
if (authUserId > 0) {
|
| 24439 |
govind |
306 |
|
| 31762 |
tejbeer |
307 |
this.assignTicketByAuthId(ticket, authUserId, escalationType);
|
| 24417 |
govind |
308 |
|
| 31762 |
tejbeer |
309 |
} else {
|
|
|
310 |
ticket.setAssignmentId(0);
|
|
|
311 |
this.assignTicket(ticket);
|
|
|
312 |
}
|
| 24417 |
govind |
313 |
|
| 31762 |
tejbeer |
314 |
}
|
| 24500 |
govind |
315 |
|
| 31762 |
tejbeer |
316 |
private void assignTicketByAuthId(Ticket ticket, int authUserId, EscalationType escalationType) throws ProfitMandiBusinessException {
|
| 24500 |
govind |
317 |
|
| 31762 |
tejbeer |
318 |
AuthUser authUser = authRepository.selectById(authUserId);
|
| 24500 |
govind |
319 |
|
| 31762 |
tejbeer |
320 |
LOGGER.info("authUser {}", authUser);
|
| 24417 |
govind |
321 |
|
| 31762 |
tejbeer |
322 |
int managerAuthId = authUser.getManagerId();
|
| 24417 |
govind |
323 |
|
| 31762 |
tejbeer |
324 |
if (escalationType.equals(EscalationType.L1)) {
|
|
|
325 |
ticket.setL1AuthUser(authUserId);
|
|
|
326 |
ticket.setL2AuthUser(0);
|
|
|
327 |
ticket.setL3AuthUser(0);
|
|
|
328 |
ticket.setL4AuthUser(0);
|
|
|
329 |
ticket.setL5AuthUser(0);
|
|
|
330 |
} else if (escalationType.equals(EscalationType.L2)) {
|
|
|
331 |
ticket.setL2AuthUser(authUserId);
|
|
|
332 |
ticket.setL3AuthUser(0);
|
|
|
333 |
ticket.setL4AuthUser(0);
|
|
|
334 |
ticket.setL5AuthUser(0);
|
|
|
335 |
}
|
|
|
336 |
if (escalationType.equals(EscalationType.L3)) {
|
|
|
337 |
ticket.setL3AuthUser(authUserId);
|
|
|
338 |
ticket.setL4AuthUser(0);
|
|
|
339 |
ticket.setL5AuthUser(0);
|
|
|
340 |
}
|
|
|
341 |
if (escalationType.equals(EscalationType.L4)) {
|
| 30426 |
tejbeer |
342 |
|
| 31762 |
tejbeer |
343 |
ticket.setL4AuthUser(authUserId);
|
|
|
344 |
ticket.setL5AuthUser(0);
|
|
|
345 |
}
|
|
|
346 |
if (escalationType.equals(EscalationType.L5)) {
|
|
|
347 |
ticket.setL5AuthUser(authUserId);
|
|
|
348 |
}
|
| 30426 |
tejbeer |
349 |
|
| 24417 |
govind |
350 |
|
| 31762 |
tejbeer |
351 |
TicketAssigned ticketAssignedNew = new TicketAssigned();
|
|
|
352 |
ticketAssignedNew.setTicketId(ticket.getId());
|
|
|
353 |
ticketAssignedNew.setAssineeId(authUserId);
|
|
|
354 |
ticketAssignedNew.setEscalationType(escalationType);
|
|
|
355 |
ticketAssignedNew.setManagerId(managerAuthId);
|
|
|
356 |
ticketAssignedNew.setCreateTimestamp(LocalDateTime.now());
|
|
|
357 |
ticketAssignedRepository.persist(ticketAssignedNew);
|
| 24439 |
govind |
358 |
|
| 31762 |
tejbeer |
359 |
LOGGER.info("ticketAssignedNew {}", ticketAssignedNew);
|
| 24439 |
govind |
360 |
|
| 24500 |
govind |
361 |
|
| 31762 |
tejbeer |
362 |
AuthUser authUserManager = null;
|
| 24439 |
govind |
363 |
|
| 24500 |
govind |
364 |
|
| 31762 |
tejbeer |
365 |
// Dont send cc mail if both are same
|
|
|
366 |
if (managerAuthId != authUserId) {
|
|
|
367 |
authUserManager = authRepository.selectById(managerAuthId);
|
|
|
368 |
}
|
|
|
369 |
ticket.setAssignmentId(ticketAssignedNew.getId());
|
| 27124 |
amit.gupta |
370 |
|
| 25570 |
tejbeer |
371 |
|
| 31762 |
tejbeer |
372 |
List<Activity> activities = activityRepository.selectAll(ticket.getId());
|
| 25570 |
tejbeer |
373 |
|
| 31762 |
tejbeer |
374 |
this.sendAssignedTicketMail(authUser, Arrays.asList(authUserManager), ticket, false, activities);
|
|
|
375 |
if (!ticketAssignedNew.getEscalationType().equals(EscalationType.L1)) {
|
|
|
376 |
this.addActivity(ticket, this.createActivity(ActivityType.ESCALATED, "Ticket ecalated and assigned to " + authUser.getName(), 0));
|
|
|
377 |
} else {
|
|
|
378 |
this.addActivity(ticket, this.createActivity(ActivityType.ASSIGNED, "Ticket assigned to " + authUser.getName(), 0));
|
|
|
379 |
}
|
| 25570 |
tejbeer |
380 |
|
| 31762 |
tejbeer |
381 |
}
|
| 25570 |
tejbeer |
382 |
|
| 31762 |
tejbeer |
383 |
@Override
|
|
|
384 |
public Activity createActivity(ActivityType activityType, String message, int createdBy) {
|
|
|
385 |
Activity activity = new Activity();
|
|
|
386 |
activity.setMessage(message);
|
|
|
387 |
activity.setCreatedBy(createdBy);
|
|
|
388 |
activity.setType(activityType);
|
|
|
389 |
activity.setCreateTimestamp(LocalDateTime.now());
|
|
|
390 |
activityRepository.persist(activity);
|
|
|
391 |
return activity;
|
|
|
392 |
}
|
| 25570 |
tejbeer |
393 |
|
| 31762 |
tejbeer |
394 |
@Override
|
|
|
395 |
public int getAuthUserId(int categoryId, EscalationType escalationType, int fofoId) {
|
|
|
396 |
int authUserId = 0;
|
|
|
397 |
List<Position> positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType);
|
|
|
398 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId()).collect(Collectors.toList());
|
|
|
399 |
// Add all Partner regions id
|
|
|
400 |
regionIds.add(ALL_PARTNERS_REGION);
|
|
|
401 |
LOGGER.info("Escalation Type {}, Region Ids {}", escalationType, regionIds);
|
| 32493 |
amit.gupta |
402 |
List<Integer> partnerPositionsIds = partnerPositionRepository.selectByRegionIdAndPartnerId(regionIds, Arrays.asList(0, fofoId)).stream().map(x -> x.getPositionId()).collect(Collectors.toList());
|
| 33022 |
amit.gupta |
403 |
|
| 31829 |
amit.gupta |
404 |
List<Position> positionAssignee = positions.stream().filter(x -> x.isTicketAssignee() && partnerPositionsIds.contains(x.getId())).collect(Collectors.toList());
|
| 31762 |
tejbeer |
405 |
LOGGER.info("User List List {}", positions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
| 31829 |
amit.gupta |
406 |
if (positionAssignee.size() > 0) {
|
| 31762 |
tejbeer |
407 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(
|
| 33022 |
amit.gupta |
408 |
positionAssignee.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
| 31762 |
tejbeer |
409 |
authUsers = authUsers.stream().filter(x -> x.isActive()).collect(Collectors.toList());
|
|
|
410 |
if (authUsers.size() > 0) {
|
|
|
411 |
authUserId = authUsers.get(0).getId();
|
|
|
412 |
/*
|
|
|
413 |
* Random rand = new Random(); authUserId =
|
|
|
414 |
* authUsers.get(rand.nextInt(authUsers.size())).getId();
|
|
|
415 |
*/
|
|
|
416 |
}
|
|
|
417 |
}
|
|
|
418 |
return authUserId;
|
| 25570 |
tejbeer |
419 |
|
| 31762 |
tejbeer |
420 |
}
|
| 25597 |
amit.gupta |
421 |
|
| 33022 |
amit.gupta |
422 |
|
| 31762 |
tejbeer |
423 |
@Override
|
|
|
424 |
public void addActivity(Ticket ticket, Activity activity) {
|
|
|
425 |
activity.setTicketId(ticket.getId());
|
|
|
426 |
ticket.setLastActivity(activity.getType());
|
|
|
427 |
ticket.setLastActivityId(activity.getId());
|
|
|
428 |
}
|
| 25597 |
amit.gupta |
429 |
|
| 31762 |
tejbeer |
430 |
private String getRandomString() {
|
|
|
431 |
int length = 4;
|
|
|
432 |
boolean useLetters = false;
|
|
|
433 |
boolean useNumbers = true;
|
|
|
434 |
String generatedString = RandomStringUtils.random(length, useLetters, useNumbers);
|
|
|
435 |
return generatedString;
|
|
|
436 |
}
|
| 25721 |
tejbeer |
437 |
|
| 31762 |
tejbeer |
438 |
@Override
|
|
|
439 |
public void addPartnerToRegion(int regionId, List<Integer> fofoIds) {
|
| 25721 |
tejbeer |
440 |
|
| 31762 |
tejbeer |
441 |
for (int fofoId : fofoIds) {
|
|
|
442 |
PartnerRegion partnerRegion = new PartnerRegion();
|
|
|
443 |
partnerRegion.setFofoId(fofoId);
|
|
|
444 |
partnerRegion.setRegionId(regionId);
|
|
|
445 |
partnerRegionRepository.persist(partnerRegion);
|
|
|
446 |
}
|
|
|
447 |
}
|
| 25721 |
tejbeer |
448 |
|
| 31762 |
tejbeer |
449 |
@Override
|
|
|
450 |
public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<TicketAssigned> ticketAssigneds) {
|
|
|
451 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
| 31152 |
tejbeer |
452 |
|
| 31762 |
tejbeer |
453 |
for (TicketAssigned ticketAssigned : ticketAssigneds) {
|
|
|
454 |
AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
|
|
|
455 |
authUserIdAndAuthUserMap.put(ticketAssigned.getTicketId(), authUser);
|
|
|
456 |
}
|
|
|
457 |
return authUserIdAndAuthUserMap;
|
|
|
458 |
}
|
| 31465 |
tejbeer |
459 |
|
| 31762 |
tejbeer |
460 |
@Override
|
|
|
461 |
public Map<Integer, AuthUser> getTicketIdAndAuthUserMapUsingTickets(List<Ticket> tickets) {
|
|
|
462 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
| 31465 |
tejbeer |
463 |
|
| 31762 |
tejbeer |
464 |
for (Ticket ticket : tickets) {
|
|
|
465 |
AuthUser authUser = authRepository.selectById(ticket.getL1AuthUser());
|
|
|
466 |
authUserIdAndAuthUserMap.put(ticket.getId(), authUser);
|
|
|
467 |
}
|
|
|
468 |
return authUserIdAndAuthUserMap;
|
|
|
469 |
}
|
| 31152 |
tejbeer |
470 |
|
| 31762 |
tejbeer |
471 |
@Override
|
|
|
472 |
public Map<Integer, TicketSubCategory> getSubCategoryIdAndSubCategoryMap(List<Integer> subCategoryIds) {
|
|
|
473 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = new HashMap<>();
|
|
|
474 |
subCategoryIdAndSubCategoryMap = ticketSubCategoryRepository.selectByIds(subCategoryIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
475 |
return subCategoryIdAndSubCategoryMap;
|
|
|
476 |
}
|
| 31152 |
tejbeer |
477 |
|
| 31762 |
tejbeer |
478 |
@Override
|
|
|
479 |
public Map<Integer, CustomRetailer> getPartnerByFofoIds(List<Ticket> tickets) {
|
|
|
480 |
List<Integer> fofoIds = new ArrayList<>();
|
|
|
481 |
LOGGER.info(tickets);
|
|
|
482 |
if (tickets == null) {
|
|
|
483 |
return null;
|
|
|
484 |
}
|
|
|
485 |
for (Ticket ticket : tickets) {
|
|
|
486 |
fofoIds.add(ticket.getFofoId());
|
|
|
487 |
}
|
| 25721 |
tejbeer |
488 |
|
| 31762 |
tejbeer |
489 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 25721 |
tejbeer |
490 |
|
| 31762 |
tejbeer |
491 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = fofoIds.stream().distinct().map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
492 |
return fofoIdsAndCustomRetailer;
|
|
|
493 |
}
|
| 25799 |
tejbeer |
494 |
|
| 31762 |
tejbeer |
495 |
@Override
|
|
|
496 |
public List<TicketCategory> getAllTicketCategotyFromSubCategory() {
|
| 25721 |
tejbeer |
497 |
|
| 31830 |
amit.gupta |
498 |
Collection<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.getTicketSubCategoryMap().values();
|
|
|
499 |
return new ArrayList<>(ticketSubCategories.stream().map(x -> x.getTicketCategory()).collect(Collectors.toSet()));
|
| 31762 |
tejbeer |
500 |
}
|
| 25799 |
tejbeer |
501 |
|
| 31762 |
tejbeer |
502 |
@Override
|
|
|
503 |
public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMapUsingPositions(List<Position> positions) {
|
|
|
504 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
|
|
505 |
for (Position position : positions) {
|
|
|
506 |
AuthUser authUser = authRepository.selectById(position.getAuthUserId());
|
|
|
507 |
authUserIdAndAuthUserMap.put(position.getAuthUserId(), authUser);
|
|
|
508 |
}
|
|
|
509 |
return authUserIdAndAuthUserMap;
|
|
|
510 |
}
|
| 25721 |
tejbeer |
511 |
|
| 31762 |
tejbeer |
512 |
@Override
|
|
|
513 |
public Map<Integer, TicketCategory> getCategoryIdAndCategoryUsingPositions(List<Position> positions) {
|
|
|
514 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = new HashMap<>();
|
|
|
515 |
for (Position position : positions) {
|
|
|
516 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(position.getCategoryId());
|
|
|
517 |
categoryIdAndCategoryMap.put(position.getCategoryId(), ticketCategory);
|
|
|
518 |
}
|
|
|
519 |
return categoryIdAndCategoryMap;
|
|
|
520 |
}
|
| 29318 |
tejbeer |
521 |
|
| 31762 |
tejbeer |
522 |
@Override
|
|
|
523 |
public Map<Integer, Region> getRegionIdAndRegionMap(List<Position> positions) {
|
|
|
524 |
Map<Integer, Region> regionIdAndRegionMap = new HashMap<>();
|
|
|
525 |
for (Position position : positions) {
|
|
|
526 |
Region region = regionRepository.selectById(position.getRegionId());
|
|
|
527 |
regionIdAndRegionMap.put(position.getRegionId(), region);
|
|
|
528 |
}
|
|
|
529 |
return regionIdAndRegionMap;
|
|
|
530 |
}
|
| 29318 |
tejbeer |
531 |
|
| 31762 |
tejbeer |
532 |
private void sendAssignedTicketMail(AuthUser authUserTo, List<AuthUser> authUsersCc, Ticket ticket, boolean isEscalated, List<Activity> activities) throws ProfitMandiBusinessException {
|
|
|
533 |
try {
|
|
|
534 |
String[] ccTo = authUsersCc.stream().filter(x -> x != null).map(x -> x.getEmailId()).toArray(String[]::new);
|
| 25721 |
tejbeer |
535 |
|
| 31762 |
tejbeer |
536 |
String messageFormat = null;
|
|
|
537 |
if (isEscalated) {
|
|
|
538 |
messageFormat = ESCALATED_TICKET;
|
|
|
539 |
} else {
|
|
|
540 |
messageFormat = ASSIGNED_TICKET;
|
|
|
541 |
}
|
|
|
542 |
String message = String.format(messageFormat, authUserTo.getName(), ticket.getId(), activities.get(0).getMessage(), retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName());
|
|
|
543 |
Utils.sendMailWithAttachments(mailSender, authUserTo.getEmailId(), ccTo, ASSINMENT_SUBJECT, message, null);
|
|
|
544 |
} catch (Exception e) {
|
|
|
545 |
e.printStackTrace();
|
|
|
546 |
throw new ProfitMandiBusinessException("Ticket Assingment", authUserTo.getEmailId(), "Could not send ticket assignment mail");
|
|
|
547 |
}
|
|
|
548 |
}
|
| 26298 |
tejbeer |
549 |
|
| 31762 |
tejbeer |
550 |
@Override
|
|
|
551 |
public Map<Integer, List<CustomRetailer>> getPositionCustomRetailerMap(List<Position> positions) {
|
|
|
552 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
553 |
Map<Integer, List<CustomRetailer>> positionRetailerMap = new HashMap<>();
|
|
|
554 |
for (Position position : positions) {
|
| 32493 |
amit.gupta |
555 |
List<Integer> fofoIds = partnerPositionRepository.selectByPositionId(position.getId()).stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 26978 |
tejbeer |
556 |
|
| 33074 |
amit.gupta |
557 |
//LOGGER.info("fofoIds - {}", fofoIds);
|
| 31762 |
tejbeer |
558 |
if (!fofoIds.isEmpty()) {
|
|
|
559 |
if (fofoIds.contains(0)) {
|
|
|
560 |
fofoIds = partnerRegionRepository.selectByRegionId(position.getRegionId()).stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
561 |
if (fofoIds.contains(0)) {
|
|
|
562 |
fofoIds = new ArrayList<>(customRetailerMap.keySet());
|
|
|
563 |
}
|
| 26978 |
tejbeer |
564 |
|
| 31762 |
tejbeer |
565 |
}
|
| 33074 |
amit.gupta |
566 |
//LOGGER.info("fofoIds - {}", fofoIds);
|
| 31762 |
tejbeer |
567 |
positionRetailerMap.put(position.getId(), fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList()));
|
| 26978 |
tejbeer |
568 |
|
| 31762 |
tejbeer |
569 |
}
|
|
|
570 |
}
|
|
|
571 |
return positionRetailerMap;
|
|
|
572 |
}
|
| 26978 |
tejbeer |
573 |
|
| 31762 |
tejbeer |
574 |
@Override
|
|
|
575 |
public Map<Integer, List<CustomRetailer>> getRegionPartners(List<Position> positions) {
|
|
|
576 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
577 |
Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = new HashedMap<>();
|
|
|
578 |
for (Position position : positions) {
|
|
|
579 |
List<Integer> fofoIds = partnerRegionRepository.selectByRegionId(position.getRegionId()).stream().map(x -> x.getFofoId()).collect(Collectors.toList());
|
| 26978 |
tejbeer |
580 |
|
| 31762 |
tejbeer |
581 |
if (!fofoIds.isEmpty()) {
|
|
|
582 |
if (fofoIds.contains(0)) {
|
|
|
583 |
fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 26978 |
tejbeer |
584 |
|
| 31762 |
tejbeer |
585 |
}
|
| 26978 |
tejbeer |
586 |
|
| 31762 |
tejbeer |
587 |
Map<Integer, CustomRetailer> fofoRetailers = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
588 |
positionIdAndpartnerRegionMap.put(position.getRegionId(), new ArrayList<CustomRetailer>(fofoRetailers.values()));
|
|
|
589 |
}
|
| 26978 |
tejbeer |
590 |
|
| 31762 |
tejbeer |
591 |
}
|
| 26978 |
tejbeer |
592 |
|
| 31762 |
tejbeer |
593 |
return positionIdAndpartnerRegionMap;
|
|
|
594 |
}
|
| 26978 |
tejbeer |
595 |
|
| 31762 |
tejbeer |
596 |
@Override
|
|
|
597 |
@Cacheable(value = "authUserEmailMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
|
|
|
598 |
public Map<String, Set<String>> getAuthUserPartnerEmailMapping() {
|
|
|
599 |
Map<String, Set<String>> storeGuyMap = new HashMap<>();
|
|
|
600 |
Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId()).collect(Collectors.toSet());
|
|
|
601 |
List<Position> categoryPositions = positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
602 |
categoryPositions.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM));
|
|
|
603 |
Map<Integer, Position> positionsMap = categoryPositions.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 29229 |
tejbeer |
604 |
|
| 31762 |
tejbeer |
605 |
Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
|
|
|
606 |
for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
|
|
|
607 |
int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
|
|
|
608 |
Set<String> partnerEmails = positionPartnerEntry.getValue().stream().filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getEmail()).collect(Collectors.toSet());
|
|
|
609 |
AuthUser authUser = authRepository.selectById(authUserId);
|
|
|
610 |
if (authUser.isActive()) {
|
|
|
611 |
if (!storeGuyMap.containsKey(authUser.getEmailId())) {
|
|
|
612 |
storeGuyMap.put(authUser.getEmailId(), partnerEmails);
|
|
|
613 |
} else {
|
|
|
614 |
storeGuyMap.get(authUser.getEmailId()).addAll(partnerEmails);
|
|
|
615 |
}
|
|
|
616 |
}
|
|
|
617 |
}
|
|
|
618 |
return storeGuyMap;
|
|
|
619 |
}
|
| 29229 |
tejbeer |
620 |
|
| 31762 |
tejbeer |
621 |
@Override
|
|
|
622 |
@Cacheable(value = "authUserEmailPartnerIdMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
|
|
|
623 |
public Map<String, Set<Integer>> getAuthUserPartnerIdMapping() {
|
|
|
624 |
Map<String, Set<Integer>> storeGuyMap = new HashMap<>();
|
|
|
625 |
Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId()).collect(Collectors.toSet());
|
|
|
626 |
List<Position> categoryPositions = positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
627 |
categoryPositions.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM));
|
|
|
628 |
categoryPositions.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_BUSINESSINTELLIGENT));
|
|
|
629 |
Map<Integer, Position> positionsMap = categoryPositions.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 31161 |
tejbeer |
630 |
|
| 31762 |
tejbeer |
631 |
Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
|
|
|
632 |
for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
|
|
|
633 |
int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
|
|
|
634 |
Set<Integer> partnerIds = positionPartnerEntry.getValue().stream().filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId()).collect(Collectors.toSet());
|
|
|
635 |
AuthUser authUser = authRepository.selectById(authUserId);
|
|
|
636 |
if (authUser.isActive()) {
|
|
|
637 |
if (!storeGuyMap.containsKey(authUser.getEmailId())) {
|
|
|
638 |
storeGuyMap.put(authUser.getEmailId(), partnerIds);
|
|
|
639 |
} else {
|
|
|
640 |
storeGuyMap.get(authUser.getEmailId()).addAll(partnerIds);
|
|
|
641 |
}
|
|
|
642 |
}
|
|
|
643 |
}
|
|
|
644 |
return storeGuyMap;
|
|
|
645 |
}
|
| 31472 |
tejbeer |
646 |
|
| 31762 |
tejbeer |
647 |
@Override
|
|
|
648 |
@Cacheable(value = "authUserPartnerEmailPartnerIdMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
|
|
|
649 |
public Map<String, Set<Integer>> getAuthUserPartnerIdMappingByCategoryIds(List<Integer> categoryIds, boolean activeOnly) {
|
|
|
650 |
Map<String, Set<Integer>> authUserPartnerMap = new HashMap<>();
|
|
|
651 |
Set<Integer> activeFofoIds;
|
|
|
652 |
if (activeOnly) {
|
|
|
653 |
activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId()).collect(Collectors.toSet());
|
| 26298 |
tejbeer |
654 |
|
| 31762 |
tejbeer |
655 |
} else {
|
|
|
656 |
activeFofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId()).collect(Collectors.toSet());
|
| 26298 |
tejbeer |
657 |
|
| 31762 |
tejbeer |
658 |
}
|
| 26298 |
tejbeer |
659 |
|
| 31762 |
tejbeer |
660 |
List<Position> categoryPositions = positionRepository.selectPositionByCategoryIds(categoryIds);
|
|
|
661 |
Map<Integer, Position> positionsMap = categoryPositions.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 26298 |
tejbeer |
662 |
|
| 31762 |
tejbeer |
663 |
Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
|
|
|
664 |
for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
|
|
|
665 |
int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
|
|
|
666 |
Set<Integer> partnerIds = positionPartnerEntry.getValue().stream().filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId()).collect(Collectors.toSet());
|
|
|
667 |
AuthUser authUser = authRepository.selectById(authUserId);
|
|
|
668 |
if (authUser.isActive()) {
|
|
|
669 |
if (!authUserPartnerMap.containsKey(authUser.getEmailId())) {
|
|
|
670 |
authUserPartnerMap.put(authUser.getEmailId(), partnerIds);
|
|
|
671 |
} else {
|
|
|
672 |
authUserPartnerMap.get(authUser.getEmailId()).addAll(partnerIds);
|
|
|
673 |
}
|
|
|
674 |
}
|
|
|
675 |
}
|
|
|
676 |
return authUserPartnerMap;
|
|
|
677 |
}
|
| 26298 |
tejbeer |
678 |
|
| 31762 |
tejbeer |
679 |
@Override
|
|
|
680 |
public List<String> getAuthUserByPartnerId(int fofoId) {
|
| 26298 |
tejbeer |
681 |
|
| 31762 |
tejbeer |
682 |
List<String> emails = new ArrayList<>();
|
|
|
683 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId()).collect(Collectors.toList());
|
| 26298 |
tejbeer |
684 |
|
| 31762 |
tejbeer |
685 |
regionIds.add(5);// All partners Id;
|
| 26298 |
tejbeer |
686 |
|
| 32493 |
amit.gupta |
687 |
List<Integer> partnerPositionIds = partnerPositionRepository.selectByRegionIdAndPartnerId(regionIds, Arrays.asList(fofoId, 0)).stream().map(x -> x.getPositionId()).collect(Collectors.toList());
|
| 26448 |
amit.gupta |
688 |
|
| 31762 |
tejbeer |
689 |
LOGGER.info("partnerPositionIds" + partnerPositionIds);
|
| 27205 |
amit.gupta |
690 |
|
| 31762 |
tejbeer |
691 |
List<Position> positions = positionRepository.selectAll(partnerPositionIds);
|
| 27548 |
tejbeer |
692 |
|
| 31762 |
tejbeer |
693 |
positions = positions.stream().filter(x -> (x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES || x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_RBM)).collect(Collectors.toList());
|
| 27548 |
tejbeer |
694 |
|
| 31762 |
tejbeer |
695 |
if (!positions.isEmpty()) {
|
|
|
696 |
for (Position partnerPostionId : positions) {
|
| 27548 |
tejbeer |
697 |
|
| 31762 |
tejbeer |
698 |
AuthUser authUser = authRepository.selectById(partnerPostionId.getAuthUserId());
|
|
|
699 |
LOGGER.info("authUser" + authUser);
|
|
|
700 |
emails.add(authUser.getEmailId());
|
|
|
701 |
}
|
|
|
702 |
}
|
| 27548 |
tejbeer |
703 |
|
| 31762 |
tejbeer |
704 |
return emails;
|
|
|
705 |
}
|
| 27548 |
tejbeer |
706 |
|
| 31762 |
tejbeer |
707 |
@Override
|
|
|
708 |
public Map<EscalationType, String> getAuthUserAndEsclationTypeByPartnerId(int fofoId) {
|
| 27548 |
tejbeer |
709 |
|
| 31762 |
tejbeer |
710 |
List<String> emails = new ArrayList<>();
|
|
|
711 |
Map<EscalationType, String> emailEsclationTypeMap = new HashMap<>();
|
|
|
712 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId()).collect(Collectors.toList());
|
| 27548 |
tejbeer |
713 |
|
| 31762 |
tejbeer |
714 |
regionIds.add(5);// All partners Id;
|
|
|
715 |
List<Integer> fofoIds = new ArrayList<>();
|
|
|
716 |
fofoIds.add(fofoId);
|
|
|
717 |
fofoIds.add(0);
|
| 27548 |
tejbeer |
718 |
|
| 33074 |
amit.gupta |
719 |
//LOGGER.info("fofoIds" + fofoIds);
|
| 32493 |
amit.gupta |
720 |
List<Integer> partnerPositionIds = partnerPositionRepository.selectByRegionIdAndPartnerId(regionIds, fofoIds).stream().map(x -> x.getPositionId()).collect(Collectors.toList());
|
| 27548 |
tejbeer |
721 |
|
| 33074 |
amit.gupta |
722 |
//LOGGER.info("partnerPositionIds" + partnerPositionIds);
|
| 28377 |
tejbeer |
723 |
|
| 31762 |
tejbeer |
724 |
for (Integer partnerPostionId : partnerPositionIds) {
|
|
|
725 |
Position position = positionRepository.selectByIdAndCategoryId(partnerPostionId, ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
| 33074 |
amit.gupta |
726 |
//LOGGER.info("position" + position);
|
| 31762 |
tejbeer |
727 |
if (position != null) {
|
| 28377 |
tejbeer |
728 |
|
| 31762 |
tejbeer |
729 |
AuthUser authUser = authRepository.selectById(position.getAuthUserId());
|
| 33074 |
amit.gupta |
730 |
//LOGGER.info("authUser" + authUser);
|
| 28377 |
tejbeer |
731 |
|
| 31762 |
tejbeer |
732 |
emailEsclationTypeMap.put(position.getEscalationType(), authUser.getEmailId());
|
|
|
733 |
}
|
|
|
734 |
}
|
| 28377 |
tejbeer |
735 |
|
| 33074 |
amit.gupta |
736 |
//LOGGER.info("emailEsclationTypeMap" + emailEsclationTypeMap);
|
| 28377 |
tejbeer |
737 |
|
| 31762 |
tejbeer |
738 |
return emailEsclationTypeMap;
|
|
|
739 |
}
|
| 31020 |
tejbeer |
740 |
|
| 31762 |
tejbeer |
741 |
@Override
|
|
|
742 |
@Cacheable(value = "authUserIdPartnerIdMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
|
|
|
743 |
public Map<Integer, List<Integer>> getAuthUserIdPartnerIdMapping() {
|
|
|
744 |
Map<Integer, List<Integer>> storeGuyMap = new HashMap<>();
|
|
|
745 |
Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId()).collect(Collectors.toSet());
|
|
|
746 |
List<Position> categoryPositions = positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
747 |
categoryPositions.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM));
|
| 31020 |
tejbeer |
748 |
|
| 31762 |
tejbeer |
749 |
categoryPositions.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_CRM));
|
| 31020 |
tejbeer |
750 |
|
| 31762 |
tejbeer |
751 |
categoryPositions.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_MARKETING));
|
| 28377 |
tejbeer |
752 |
|
| 31762 |
tejbeer |
753 |
categoryPositions.addAll(positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_TRAINING));
|
| 28377 |
tejbeer |
754 |
|
| 31762 |
tejbeer |
755 |
Map<Integer, Position> positionsMap = categoryPositions.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 29229 |
tejbeer |
756 |
|
| 31762 |
tejbeer |
757 |
Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
|
|
|
758 |
for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
|
|
|
759 |
int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
|
|
|
760 |
List<Integer> partnerIds = positionPartnerEntry.getValue().stream().filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId()).collect(Collectors.toList());
|
|
|
761 |
AuthUser authUser = authRepository.selectById(authUserId);
|
|
|
762 |
if (authUser != null && authUser.isActive()) {
|
|
|
763 |
if (!storeGuyMap.containsKey(authUserId)) {
|
|
|
764 |
storeGuyMap.put(authUserId, partnerIds);
|
|
|
765 |
} else {
|
|
|
766 |
storeGuyMap.get(authUserId).addAll(partnerIds);
|
|
|
767 |
}
|
|
|
768 |
}
|
|
|
769 |
}
|
|
|
770 |
storeGuyMap.keySet().stream().forEach(x -> {
|
|
|
771 |
List<Integer> fofoIds = storeGuyMap.get(x);
|
|
|
772 |
storeGuyMap.put(x, fofoIds.stream().distinct().collect(Collectors.toList()));
|
|
|
773 |
});
|
|
|
774 |
return storeGuyMap;
|
|
|
775 |
}
|
| 28908 |
tejbeer |
776 |
|
| 31762 |
tejbeer |
777 |
@Override
|
|
|
778 |
@Cacheable(value = "L1L2Mapping", cacheManager = "thirtyMinsTimeOutCacheManager")
|
|
|
779 |
public Map<Integer, List<Integer>> getL2L1Mapping() {
|
|
|
780 |
List<Position> l1SalesPositions = positionRepository.selectPositionbyCategoryIdAndEscalationType(
|
|
|
781 |
ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L1);
|
|
|
782 |
List<Position> l2SalesPositions = positionRepository.selectPositionbyCategoryIdAndEscalationType(
|
|
|
783 |
ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L2);
|
| 28908 |
tejbeer |
784 |
|
| 33074 |
amit.gupta |
785 |
//LOGGER.info("position" + l1SalesPositions);
|
| 31762 |
tejbeer |
786 |
Map<Integer, List<Integer>> authUserPartnerListMap = this.getAuthUserIdPartnerIdMapping();
|
| 33074 |
amit.gupta |
787 |
//LOGGER.info("map" + authUserPartnerListMap);
|
| 28908 |
tejbeer |
788 |
|
| 31762 |
tejbeer |
789 |
Map<Integer, List<Integer>> l2l1ListMap = new HashMap<>();
|
| 29318 |
tejbeer |
790 |
|
| 31762 |
tejbeer |
791 |
for (Position l2SalePosition : l2SalesPositions) {
|
|
|
792 |
int l2AuthUserId = l2SalePosition.getAuthUserId();
|
|
|
793 |
if (authUserPartnerListMap.containsKey(l2SalePosition.getAuthUserId())) {
|
|
|
794 |
List<Integer> mappedL1AuthUsers = new ArrayList<>();
|
|
|
795 |
l2l1ListMap.put(l2AuthUserId, mappedL1AuthUsers);
|
|
|
796 |
List<Integer> l2FofoIds = authUserPartnerListMap.get(l2AuthUserId);
|
|
|
797 |
for (Position l1SalePosition : l1SalesPositions) {
|
|
|
798 |
int l1AuthUserId = l1SalePosition.getAuthUserId();
|
|
|
799 |
if (authUserPartnerListMap.containsKey(l1AuthUserId)) {
|
|
|
800 |
List<Integer> l1FofoIds = authUserPartnerListMap.get(l1SalePosition.getAuthUserId());
|
|
|
801 |
if (l2FofoIds.containsAll(l1FofoIds)) {
|
|
|
802 |
mappedL1AuthUsers.add(l1AuthUserId);
|
|
|
803 |
}
|
|
|
804 |
}
|
| 28856 |
manish |
805 |
|
| 31762 |
tejbeer |
806 |
}
|
|
|
807 |
}
|
| 29296 |
manish |
808 |
|
| 31762 |
tejbeer |
809 |
}
|
| 29296 |
manish |
810 |
|
| 31762 |
tejbeer |
811 |
return l2l1ListMap;
|
|
|
812 |
}
|
| 29296 |
manish |
813 |
|
| 31762 |
tejbeer |
814 |
@Override
|
|
|
815 |
public Map<Integer, List<AuthUser>> getAssignedAuthList(List<Ticket> tickets) {
|
|
|
816 |
if (tickets.size() == 0) {
|
|
|
817 |
return new HashMap<>();
|
|
|
818 |
}
|
|
|
819 |
List<TicketAssigned> ticketAssignedList = ticketAssignedRepository.selectByTicketIds(tickets.stream().map(x -> x.getId()).collect(Collectors.toList()));
|
|
|
820 |
List<Integer> authUserIds = ticketAssignedList.stream().map(x -> x.getAssineeId()).distinct().collect(Collectors.toList());
|
|
|
821 |
Map<Integer, AuthUser> authUserMap = authRepository.selectAllAuthUserByIds(authUserIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
822 |
return ticketAssignedList.stream().collect(Collectors.groupingBy(x -> x.getTicketId(), Collectors.mapping(x -> authUserMap.get(x.getAssineeId()), Collectors.toList())));
|
|
|
823 |
}
|
| 28908 |
tejbeer |
824 |
|
| 31762 |
tejbeer |
825 |
@Override
|
|
|
826 |
public Map<EscalationType, AuthUser> getAuthUserAndEsclationByPartnerId(int fofoId) {
|
|
|
827 |
Map<EscalationType, AuthUser> authuserEsclationTypeMap = new HashMap<>();
|
|
|
828 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId()).collect(Collectors.toList());
|
| 28908 |
tejbeer |
829 |
|
| 31762 |
tejbeer |
830 |
regionIds.add(5);// All partners Id;
|
|
|
831 |
List<Integer> fofoIds = new ArrayList<>();
|
|
|
832 |
fofoIds.add(fofoId);
|
|
|
833 |
fofoIds.add(0);
|
| 28908 |
tejbeer |
834 |
|
| 32877 |
amit.gupta |
835 |
//LOGGER.info("fofoIds" + fofoIds);
|
| 32493 |
amit.gupta |
836 |
List<Integer> partnerPositionIds = partnerPositionRepository.selectByRegionIdAndPartnerId(regionIds, fofoIds).stream().map(x -> x.getPositionId()).collect(Collectors.toList());
|
| 28908 |
tejbeer |
837 |
|
| 32877 |
amit.gupta |
838 |
//LOGGER.info("partnerPositionIds" + partnerPositionIds);
|
| 30003 |
tejbeer |
839 |
|
| 31762 |
tejbeer |
840 |
for (Integer partnerPostionId : partnerPositionIds) {
|
|
|
841 |
Position position = positionRepository.selectByIdAndCategoryId(partnerPostionId, ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
| 32877 |
amit.gupta |
842 |
//LOGGER.info("position" + position);
|
| 31762 |
tejbeer |
843 |
if (position != null) {
|
| 30003 |
tejbeer |
844 |
|
| 31762 |
tejbeer |
845 |
AuthUser authUser = authRepository.selectById(position.getAuthUserId());
|
| 32877 |
amit.gupta |
846 |
//LOGGER.info("authUser" + authUser);
|
| 30003 |
tejbeer |
847 |
|
| 31762 |
tejbeer |
848 |
authuserEsclationTypeMap.put(position.getEscalationType(), authUser);
|
|
|
849 |
}
|
|
|
850 |
}
|
| 30003 |
tejbeer |
851 |
|
| 32877 |
amit.gupta |
852 |
//LOGGER.info("emailEsclationTypeMap" + authuserEsclationTypeMap);
|
| 30003 |
tejbeer |
853 |
|
| 31762 |
tejbeer |
854 |
return authuserEsclationTypeMap;
|
|
|
855 |
}
|
| 30044 |
tejbeer |
856 |
|
| 31762 |
tejbeer |
857 |
@Override
|
|
|
858 |
public List<AuthUser> getAuthUserIdByPartnerId(int fofoId) {
|
| 33041 |
ranu |
859 |
return this.getAuthUserIdByPartnerId(fofoId, EscalationType.escalations.toArray(new EscalationType[0]));
|
|
|
860 |
}
|
|
|
861 |
|
|
|
862 |
@Override
|
|
|
863 |
public List<AuthUser> getAuthUserIdByPartnerId(int fofoId, EscalationType... escalationTypes) {
|
| 31762 |
tejbeer |
864 |
List<AuthUser> authUsers = new ArrayList<>();
|
|
|
865 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId()).collect(Collectors.toList());
|
| 30044 |
tejbeer |
866 |
|
| 31762 |
tejbeer |
867 |
regionIds.add(5);// All partners Id;
|
|
|
868 |
List<Integer> fofoIds = new ArrayList<>();
|
|
|
869 |
fofoIds.add(fofoId);
|
|
|
870 |
fofoIds.add(0);
|
| 30044 |
tejbeer |
871 |
|
| 33074 |
amit.gupta |
872 |
//LOGGER.info("fofoIds" + fofoIds);
|
| 32493 |
amit.gupta |
873 |
List<Integer> partnerPositionIds = partnerPositionRepository.selectByRegionIdAndPartnerId(regionIds, fofoIds).stream().map(x -> x.getPositionId()).collect(Collectors.toList());
|
| 30003 |
tejbeer |
874 |
|
| 33074 |
amit.gupta |
875 |
//LOGGER.info("partnerPositionIds" + partnerPositionIds);
|
| 33041 |
ranu |
876 |
List<Integer> allowedTicketCategoryIds = Arrays.asList(ProfitMandiConstants.TICKET_CATEGORY_SALES, ProfitMandiConstants.TICKET_CATEGORY_RBM);
|
| 30003 |
tejbeer |
877 |
|
| 30044 |
tejbeer |
878 |
|
| 33041 |
ranu |
879 |
List<Position> escalationBasedPositions = positionRepository.selectAll(partnerPositionIds).stream().filter(x -> allowedTicketCategoryIds.contains(x.getCategoryId()) &&
|
|
|
880 |
Arrays.stream(escalationTypes)
|
|
|
881 |
.anyMatch(y -> y.equals(x.getEscalationType()))).collect(Collectors.toList());
|
| 30003 |
tejbeer |
882 |
|
| 33041 |
ranu |
883 |
List<Integer> authUserIds = escalationBasedPositions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList());
|
| 30003 |
tejbeer |
884 |
|
| 33041 |
ranu |
885 |
return authRepository.selectAllAuthUserByIds(authUserIds);
|
| 30003 |
tejbeer |
886 |
|
| 31762 |
tejbeer |
887 |
}
|
| 30044 |
tejbeer |
888 |
|
| 31762 |
tejbeer |
889 |
@Override
|
|
|
890 |
public List<AuthUser> getAuthUserIds(int categoryId, List<EscalationType> escalationType) {
|
| 30044 |
tejbeer |
891 |
|
| 31762 |
tejbeer |
892 |
List<Position> positions = positionRepository.selectPositionbyCategoryIdAndEscalationTypes(categoryId, escalationType);
|
|
|
893 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
| 30003 |
tejbeer |
894 |
|
| 33074 |
amit.gupta |
895 |
//LOGGER.info("authIds" + authIds);
|
| 30003 |
tejbeer |
896 |
|
| 31762 |
tejbeer |
897 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(authIds);
|
|
|
898 |
|
|
|
899 |
LOGGER.info("authUsers" + authUsers);
|
|
|
900 |
return authUsers;
|
|
|
901 |
}
|
|
|
902 |
|
|
|
903 |
@Override
|
|
|
904 |
public List<AuthUser> getAuthUserByCategoryId(int categoryId, EscalationType escalationType) {
|
|
|
905 |
|
|
|
906 |
List<Position> positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType);
|
|
|
907 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
|
|
908 |
|
|
|
909 |
LOGGER.info("authIds" + authIds);
|
|
|
910 |
List<AuthUser> authUsers = new ArrayList<>();
|
|
|
911 |
if (!authIds.isEmpty()) {
|
|
|
912 |
authUsers = authRepository.selectAllAuthUserByIds(authIds);
|
|
|
913 |
}
|
|
|
914 |
|
|
|
915 |
LOGGER.info("authUsers" + authUsers);
|
|
|
916 |
return authUsers;
|
|
|
917 |
}
|
|
|
918 |
|
|
|
919 |
@Override
|
|
|
920 |
@Cacheable(value = "authUserByCategoryId", cacheManager = "thirtyMinsTimeOutCacheManager")
|
|
|
921 |
public List<AuthUser> getAuthUserByCategoryId(int categoryId) {
|
|
|
922 |
List<Position> positions = positionRepository.selectPositionByCategoryId(categoryId);
|
|
|
923 |
List<Integer> authIds = positions.stream().map(x -> x.getAuthUserId()).distinct().collect(Collectors.toList());
|
|
|
924 |
|
|
|
925 |
LOGGER.info("authIds" + authIds);
|
|
|
926 |
|
|
|
927 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(authIds).stream().filter(x -> x.getActive()).collect(Collectors.toList());
|
|
|
928 |
|
|
|
929 |
LOGGER.info("authUsers" + authUsers);
|
|
|
930 |
return authUsers;
|
|
|
931 |
}
|
|
|
932 |
|
|
|
933 |
private class SaleRoles {
|
|
|
934 |
|
|
|
935 |
private List<String> l1;
|
|
|
936 |
private List<String> l2;
|
|
|
937 |
private List<String> l3;
|
|
|
938 |
private List<String> l4;
|
|
|
939 |
|
|
|
940 |
public SaleRoles() {
|
|
|
941 |
l1 = new ArrayList<>();
|
|
|
942 |
l2 = new ArrayList<>();
|
|
|
943 |
l3 = new ArrayList<>();
|
|
|
944 |
l4 = new ArrayList<>();
|
|
|
945 |
}
|
|
|
946 |
|
|
|
947 |
public List<String> getL1() {
|
|
|
948 |
return l1;
|
|
|
949 |
}
|
|
|
950 |
|
|
|
951 |
public List<String> getL2() {
|
|
|
952 |
return l2;
|
|
|
953 |
}
|
|
|
954 |
|
|
|
955 |
public List<String> getL3() {
|
|
|
956 |
return l3;
|
|
|
957 |
}
|
|
|
958 |
|
|
|
959 |
public List<String> getL4() {
|
|
|
960 |
return l4;
|
|
|
961 |
}
|
|
|
962 |
|
|
|
963 |
@Override
|
|
|
964 |
public String toString() {
|
|
|
965 |
return "SaleRoles [l1=" + l1 + ", l2=" + l2 + ", l3=" + l3 + ", l4=" + l4 + "]";
|
|
|
966 |
}
|
|
|
967 |
|
|
|
968 |
}
|
|
|
969 |
|
| 33161 |
ranu |
970 |
|
|
|
971 |
|
| 31762 |
tejbeer |
972 |
@Override
|
|
|
973 |
@Cacheable(value = "partnerSaleHeader", cacheManager = "oneDayCacheManager")
|
|
|
974 |
public Map<Integer, FofoReportingModel> getPartnerIdSalesHeaders() {
|
|
|
975 |
Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
|
|
|
976 |
|
|
|
977 |
List<Position> positions = positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
978 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
979 |
Map<Integer, List<CustomRetailer>> positionIdRetailerMap = this.getPositionCustomRetailerMap(positions);
|
|
|
980 |
for (Position position : positions) {
|
|
|
981 |
List<CustomRetailer> crList = positionIdRetailerMap.get(position.getId());
|
|
|
982 |
if (crList == null)
|
|
|
983 |
continue;
|
|
|
984 |
for (CustomRetailer cr : crList) {
|
|
|
985 |
if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
|
|
|
986 |
partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
|
|
|
987 |
}
|
|
|
988 |
SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
|
|
|
989 |
AuthUser authUser = authUsersMap.get(position.getAuthUserId());
|
|
|
990 |
if (authUser == null) {
|
|
|
991 |
continue;
|
|
|
992 |
}
|
|
|
993 |
String name = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
994 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
|
|
995 |
saleRoles.getL1().add(name);
|
|
|
996 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
|
|
997 |
saleRoles.getL2().add(name);
|
|
|
998 |
}
|
|
|
999 |
|
|
|
1000 |
}
|
|
|
1001 |
}
|
|
|
1002 |
|
|
|
1003 |
Set<CustomRetailer> allCrList = new HashSet<>();
|
|
|
1004 |
for (List<CustomRetailer> cr : positionIdRetailerMap.values()) {
|
|
|
1005 |
allCrList.addAll(cr);
|
|
|
1006 |
}
|
|
|
1007 |
|
|
|
1008 |
Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1009 |
|
|
|
1010 |
Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = new HashMap<>();
|
|
|
1011 |
|
|
|
1012 |
for (CustomRetailer cr : allCrList) {
|
|
|
1013 |
FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
|
|
|
1014 |
if (fofoStore == null) {
|
|
|
1015 |
LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
|
|
|
1016 |
continue;
|
|
|
1017 |
}
|
|
|
1018 |
String code = fofoStore.getCode();
|
|
|
1019 |
// String storeName = "SmartDukaan-" +
|
|
|
1020 |
// fofoStore.getCode().replaceAll("[a-zA-Z]", "");
|
|
|
1021 |
String businessName = cr.getBusinessName();
|
|
|
1022 |
try {
|
|
|
1023 |
String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
|
|
|
1024 |
String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
|
|
|
1025 |
|
|
|
1026 |
if (StringUtils.isEmpty(territoryManager)) {
|
|
|
1027 |
territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
|
|
|
1028 |
}
|
|
|
1029 |
|
|
|
1030 |
FofoReportingModel reportingModel = new FofoReportingModel();
|
|
|
1031 |
reportingModel.setBusinessName(businessName);
|
|
|
1032 |
reportingModel.setCode(code);
|
|
|
1033 |
reportingModel.setFofoId(fofoStore.getId());
|
|
|
1034 |
reportingModel.setRegionalManager(stateManager);
|
|
|
1035 |
reportingModel.setTerritoryManager(territoryManager);
|
|
|
1036 |
partnerIdSalesHeadersMap.put(fofoStore.getId(), reportingModel);
|
|
|
1037 |
} catch (Exception e) {
|
|
|
1038 |
LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
|
|
|
1039 |
}
|
|
|
1040 |
}
|
|
|
1041 |
return partnerIdSalesHeadersMap;
|
|
|
1042 |
|
|
|
1043 |
}
|
|
|
1044 |
|
| 33161 |
ranu |
1045 |
|
|
|
1046 |
private class RBMRoles {
|
|
|
1047 |
|
|
|
1048 |
private List<String> l1;
|
|
|
1049 |
private List<String> l2;
|
|
|
1050 |
private List<String> l3;
|
|
|
1051 |
private List<String> l4;
|
|
|
1052 |
|
|
|
1053 |
public RBMRoles() {
|
|
|
1054 |
l1 = new ArrayList<>();
|
|
|
1055 |
l2 = new ArrayList<>();
|
|
|
1056 |
l3 = new ArrayList<>();
|
|
|
1057 |
l4 = new ArrayList<>();
|
|
|
1058 |
}
|
|
|
1059 |
|
|
|
1060 |
public List<String> getL1() {
|
|
|
1061 |
return l1;
|
|
|
1062 |
}
|
|
|
1063 |
|
|
|
1064 |
public List<String> getL2() {
|
|
|
1065 |
return l2;
|
|
|
1066 |
}
|
|
|
1067 |
|
|
|
1068 |
public List<String> getL3() {
|
|
|
1069 |
return l3;
|
|
|
1070 |
}
|
|
|
1071 |
|
|
|
1072 |
public List<String> getL4() {
|
|
|
1073 |
return l4;
|
|
|
1074 |
}
|
|
|
1075 |
|
|
|
1076 |
@Override
|
|
|
1077 |
public String toString() {
|
|
|
1078 |
return "RBMRoles [l1=" + l1 + ", l2=" + l2 + ", l3=" + l3 + ", l4=" + l4 + "]";
|
|
|
1079 |
}
|
|
|
1080 |
|
|
|
1081 |
}
|
|
|
1082 |
|
| 31762 |
tejbeer |
1083 |
@Override
|
| 33161 |
ranu |
1084 |
@Cacheable(value = "partnerRBMHeader", cacheManager = "oneDayCacheManager")
|
|
|
1085 |
public Map<Integer, FofoRBMReportingModel> getPartnerIdRBMHeaders() {
|
|
|
1086 |
Map<String, RBMRoles> partnerEmailRbmMap = new HashMap<>();
|
|
|
1087 |
|
|
|
1088 |
List<Position> positions = positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM);
|
|
|
1089 |
Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1090 |
Map<Integer, List<CustomRetailer>> positionIdRetailerMap = this.getPositionCustomRetailerMap(positions);
|
|
|
1091 |
for (Position position : positions) {
|
|
|
1092 |
List<CustomRetailer> crList = positionIdRetailerMap.get(position.getId());
|
|
|
1093 |
if (crList == null)
|
|
|
1094 |
continue;
|
|
|
1095 |
for (CustomRetailer cr : crList) {
|
|
|
1096 |
if (!partnerEmailRbmMap.containsKey(cr.getEmail())) {
|
|
|
1097 |
partnerEmailRbmMap.put(cr.getEmail(), new RBMRoles());
|
|
|
1098 |
}
|
|
|
1099 |
RBMRoles rbmRole = partnerEmailRbmMap.get(cr.getEmail());
|
|
|
1100 |
AuthUser authUser = authUsersMap.get(position.getAuthUserId());
|
|
|
1101 |
if (authUser == null) {
|
|
|
1102 |
continue;
|
|
|
1103 |
}
|
|
|
1104 |
String name = authUser.getFirstName() + " " + authUser.getLastName();
|
|
|
1105 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
|
|
1106 |
rbmRole.getL1().add(name);
|
|
|
1107 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
|
|
1108 |
rbmRole.getL2().add(name);
|
|
|
1109 |
}
|
|
|
1110 |
|
|
|
1111 |
}
|
|
|
1112 |
}
|
|
|
1113 |
|
|
|
1114 |
Set<CustomRetailer> allCrList = new HashSet<>();
|
|
|
1115 |
for (List<CustomRetailer> cr : positionIdRetailerMap.values()) {
|
|
|
1116 |
allCrList.addAll(cr);
|
|
|
1117 |
}
|
|
|
1118 |
|
|
|
1119 |
Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
1120 |
|
|
|
1121 |
Map<Integer, FofoRBMReportingModel> partnerIdRbmHeadersMap = new HashMap<>();
|
|
|
1122 |
|
|
|
1123 |
for (CustomRetailer cr : allCrList) {
|
|
|
1124 |
FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
|
|
|
1125 |
if (fofoStore == null) {
|
|
|
1126 |
LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
|
|
|
1127 |
continue;
|
|
|
1128 |
}
|
|
|
1129 |
String code = fofoStore.getCode();
|
|
|
1130 |
// String storeName = "SmartDukaan-" +
|
|
|
1131 |
// fofoStore.getCode().replaceAll("[a-zA-Z]", "");
|
|
|
1132 |
String businessName = cr.getBusinessName();
|
|
|
1133 |
try {
|
|
|
1134 |
String L2User = StringUtils.join(partnerEmailRbmMap.get(cr.getEmail()).getL2(), ", ");
|
|
|
1135 |
String L1USer = StringUtils.join(partnerEmailRbmMap.get(cr.getEmail()).getL1(), ", ");
|
|
|
1136 |
|
|
|
1137 |
if (StringUtils.isEmpty(L1USer)) {
|
|
|
1138 |
L1USer = StringUtils.join(partnerEmailRbmMap.get(cr.getEmail()).getL2(), ", ");
|
|
|
1139 |
}
|
|
|
1140 |
|
|
|
1141 |
FofoRBMReportingModel reportingModel = new FofoRBMReportingModel();
|
|
|
1142 |
reportingModel.setBusinessName(businessName);
|
|
|
1143 |
reportingModel.setCode(code);
|
|
|
1144 |
reportingModel.setFofoId(fofoStore.getId());
|
|
|
1145 |
reportingModel.setL1Manager(L2User);
|
|
|
1146 |
reportingModel.setL2Manager(L1USer);
|
|
|
1147 |
partnerIdRbmHeadersMap.put(fofoStore.getId(), reportingModel);
|
|
|
1148 |
} catch (Exception e) {
|
|
|
1149 |
LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
|
|
|
1150 |
}
|
|
|
1151 |
}
|
|
|
1152 |
return partnerIdRbmHeadersMap;
|
|
|
1153 |
|
|
|
1154 |
}
|
|
|
1155 |
|
|
|
1156 |
@Override
|
| 31762 |
tejbeer |
1157 |
public Map<Integer, TicketCategory> getSubCategoryIdAndCategoryMap(List<Integer> subCategoryIds) {
|
|
|
1158 |
Map<Integer, TicketCategory> subCategoryIdAndCategoryMap = new HashMap<>();
|
|
|
1159 |
|
|
|
1160 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectByIds(subCategoryIds);
|
|
|
1161 |
|
|
|
1162 |
for (TicketSubCategory ticketSubCategory : ticketSubCategories) {
|
|
|
1163 |
|
|
|
1164 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketSubCategory.getCategoryId());
|
|
|
1165 |
|
|
|
1166 |
subCategoryIdAndCategoryMap.put(ticketSubCategory.getId(), ticketCategory);
|
|
|
1167 |
|
|
|
1168 |
}
|
|
|
1169 |
return subCategoryIdAndCategoryMap;
|
|
|
1170 |
}
|
|
|
1171 |
|
| 24383 |
amit.gupta |
1172 |
}
|