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