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