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