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