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