| 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;
|
| 25721 |
tejbeer |
5 |
import java.util.Arrays;
|
| 24417 |
govind |
6 |
import java.util.HashMap;
|
| 24439 |
govind |
7 |
import java.util.HashSet;
|
| 24417 |
govind |
8 |
import java.util.List;
|
|
|
9 |
import java.util.Map;
|
| 25570 |
tejbeer |
10 |
import java.util.Set;
|
|
|
11 |
import java.util.stream.Collectors;
|
| 24500 |
govind |
12 |
|
| 25570 |
tejbeer |
13 |
import org.apache.commons.collections4.map.HashedMap;
|
| 24439 |
govind |
14 |
import org.apache.commons.lang.RandomStringUtils;
|
|
|
15 |
import org.apache.logging.log4j.LogManager;
|
|
|
16 |
import org.apache.logging.log4j.Logger;
|
| 24383 |
amit.gupta |
17 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 25726 |
amit.gupta |
18 |
import org.springframework.cache.annotation.Cacheable;
|
| 24439 |
govind |
19 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 24383 |
amit.gupta |
20 |
import org.springframework.stereotype.Component;
|
| 24701 |
govind |
21 |
|
| 24383 |
amit.gupta |
22 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24417 |
govind |
23 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 24439 |
govind |
24 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
25 |
import com.spice.profitmandi.common.util.Utils;
|
| 24417 |
govind |
26 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 24383 |
amit.gupta |
27 |
import com.spice.profitmandi.dao.entity.cs.Activity;
|
| 24417 |
govind |
28 |
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
|
|
|
29 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 24471 |
govind |
30 |
import com.spice.profitmandi.dao.entity.cs.Region;
|
| 24383 |
amit.gupta |
31 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| 24500 |
govind |
32 |
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
|
| 24439 |
govind |
33 |
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
|
| 24417 |
govind |
34 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
| 24383 |
amit.gupta |
35 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
| 24417 |
govind |
36 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
|
|
37 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 25570 |
tejbeer |
38 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24417 |
govind |
39 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 24383 |
amit.gupta |
40 |
|
|
|
41 |
@Component
|
|
|
42 |
public class CsServiceImpl implements CsService {
|
| 24417 |
govind |
43 |
|
| 24439 |
govind |
44 |
private static final Logger LOGGER = LogManager.getLogger(CsServiceImpl.class);
|
|
|
45 |
|
| 24570 |
govind |
46 |
private static final String ASSIGNED_TICKET = "Dear %s,You have assigned a ticket by %s with ticketId#%s.Regards\nSmartdukaan";
|
| 24439 |
govind |
47 |
private static final String ASSINMENT_SUBJECT = "Assignment Ticket";
|
|
|
48 |
|
| 24383 |
amit.gupta |
49 |
@Autowired
|
|
|
50 |
TicketRepository ticketRepository;
|
| 24417 |
govind |
51 |
|
| 24383 |
amit.gupta |
52 |
@Autowired
|
| 24439 |
govind |
53 |
JavaMailSender mailSender;
|
|
|
54 |
|
|
|
55 |
@Autowired
|
| 24383 |
amit.gupta |
56 |
TicketCategoryRepository ticketCategoryRepository;
|
| 24417 |
govind |
57 |
|
| 24383 |
amit.gupta |
58 |
@Autowired
|
|
|
59 |
TicketSubCategoryRepository ticketSubCategoryRepository;
|
| 24417 |
govind |
60 |
|
|
|
61 |
@Autowired
|
| 24388 |
amit.gupta |
62 |
ActivityRepository activityRepository;
|
| 24417 |
govind |
63 |
|
|
|
64 |
@Autowired
|
| 24439 |
govind |
65 |
PartnerRegionRepository partnerRegionRepository;
|
| 24417 |
govind |
66 |
|
|
|
67 |
@Autowired
|
|
|
68 |
private PositionRepository positionRepository;
|
|
|
69 |
|
|
|
70 |
@Autowired
|
|
|
71 |
private AuthRepository authRepository;
|
|
|
72 |
|
|
|
73 |
@Autowired
|
|
|
74 |
private RetailerService retailerService;
|
| 24500 |
govind |
75 |
|
| 24471 |
govind |
76 |
@Autowired
|
|
|
77 |
private RegionRepository regionRepository;
|
| 24417 |
govind |
78 |
|
| 24500 |
govind |
79 |
@Autowired
|
|
|
80 |
private TicketAssignedRepository ticketAssignedRepository;
|
|
|
81 |
|
| 25570 |
tejbeer |
82 |
@Autowired
|
|
|
83 |
private PartnersPositionRepository partnersPositionRepository;
|
|
|
84 |
|
|
|
85 |
@Autowired
|
|
|
86 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
87 |
|
| 24383 |
amit.gupta |
88 |
@Override
|
| 24439 |
govind |
89 |
public void createTicket(int fofoId, int categoryId, int subcategoryId, String message)
|
|
|
90 |
throws ProfitMandiBusinessException {
|
| 24417 |
govind |
91 |
|
| 24383 |
amit.gupta |
92 |
ActivityType type = ActivityType.OPENED;
|
| 24439 |
govind |
93 |
EscalationType escalationTypeL1 = EscalationType.L1;
|
|
|
94 |
EscalationType escalationTypeL2 = EscalationType.L2;
|
|
|
95 |
EscalationType escalationTypeL3 = EscalationType.L3;
|
| 24383 |
amit.gupta |
96 |
Ticket ticket = new Ticket();
|
| 24500 |
govind |
97 |
TicketAssigned ticketAssigned = new TicketAssigned();
|
| 24383 |
amit.gupta |
98 |
ticket.setSubCategoryId(subcategoryId);
|
| 24417 |
govind |
99 |
ticket.setFofoId(fofoId);
|
| 24383 |
amit.gupta |
100 |
ticket.setCreateTimestamp(LocalDateTime.now());
|
| 24417 |
govind |
101 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
| 24467 |
govind |
102 |
ticket.setL2EscalationTimestamp(ticket.getUpdateTimestamp().plusDays(2));
|
|
|
103 |
ticket.setL3EscalationTimestamp(ticket.getL2EscalationTimestamp().plusDays(2));
|
|
|
104 |
ticket.setLastEscalationTimestamp(ticket.getL3EscalationTimestamp().plusDays(2));
|
| 24439 |
govind |
105 |
ticket.setHappyCode(getRandomString());
|
|
|
106 |
int l1Auth = this.getAuthUserId(categoryId, escalationTypeL1, fofoId);
|
| 24699 |
govind |
107 |
LOGGER.info("l1Auth" + l1Auth);
|
| 24439 |
govind |
108 |
int l2Auth = this.getAuthUserId(categoryId, escalationTypeL2, fofoId);
|
| 24699 |
govind |
109 |
LOGGER.info("l2Auth" + l2Auth);
|
| 24557 |
govind |
110 |
int l3Auth = this.getAuthUserId(categoryId, escalationTypeL3, fofoId);
|
| 24699 |
govind |
111 |
LOGGER.info("l3Auth" + l3Auth);
|
| 24439 |
govind |
112 |
if (l1Auth == 0) {
|
|
|
113 |
if (l2Auth == 0) {
|
| 24500 |
govind |
114 |
this.setAssignment(ticket, ticketAssigned);
|
| 24439 |
govind |
115 |
} else {
|
| 24500 |
govind |
116 |
ticketAssigned.setAssineeId(l2Auth);
|
| 24526 |
govind |
117 |
ticket.setL1AuthUser(l2Auth);
|
|
|
118 |
ticket.setL2AuthUser(l2Auth);
|
| 24439 |
govind |
119 |
}
|
|
|
120 |
} else {
|
| 24500 |
govind |
121 |
ticketAssigned.setAssineeId(l1Auth);
|
| 24439 |
govind |
122 |
ticket.setL1AuthUser(l1Auth);
|
|
|
123 |
ticket.setL2AuthUser(l2Auth);
|
|
|
124 |
}
|
| 24699 |
govind |
125 |
if (ticket.getL2AuthUser() == 0) {
|
| 24569 |
govind |
126 |
ticket.setL2AuthUser(l3Auth);
|
|
|
127 |
}
|
| 24439 |
govind |
128 |
ticket.setL3AuthUser(l3Auth);
|
|
|
129 |
ticketRepository.persist(ticket);
|
| 24500 |
govind |
130 |
ticketAssigned.setTicketId(ticket.getId());
|
|
|
131 |
ticketAssignedRepository.persist(ticketAssigned);
|
|
|
132 |
AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
|
| 24569 |
govind |
133 |
this.sendAssignedTicketMail(authUser, ticket);
|
| 24383 |
amit.gupta |
134 |
Activity activity = this.createActivity(type, message, 0);
|
|
|
135 |
this.addActivity(ticket.getId(), activity);
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
private Activity createActivity(ActivityType activityType, String message, int createdBy) {
|
|
|
139 |
Activity activity = new Activity();
|
|
|
140 |
activity.setMessage(message);
|
|
|
141 |
activity.setCreatedBy(createdBy);
|
|
|
142 |
activity.setType(activityType);
|
| 24417 |
govind |
143 |
activity.setCreateTimestamp(LocalDateTime.now());
|
| 24383 |
amit.gupta |
144 |
return activity;
|
|
|
145 |
}
|
| 24417 |
govind |
146 |
|
| 24439 |
govind |
147 |
private int getAuthUserId(int categoryId, EscalationType escalationType, int fofoId) {
|
| 24417 |
govind |
148 |
|
| 24439 |
govind |
149 |
List<Position> positions = null;
|
|
|
150 |
if (escalationType == EscalationType.L3) {
|
|
|
151 |
positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(0, escalationType, 0);
|
|
|
152 |
} else {
|
|
|
153 |
List<PartnerRegion> regions = partnerRegionRepository.selectByfofoId(fofoId);
|
|
|
154 |
LOGGER.info("regions=" + regions);
|
| 24500 |
govind |
155 |
if (regions.size() == 0) {
|
|
|
156 |
regions = partnerRegionRepository.selectByfofoId(0);
|
| 24452 |
govind |
157 |
LOGGER.info("regions=" + regions);
|
|
|
158 |
}
|
| 24439 |
govind |
159 |
for (PartnerRegion region : regions) {
|
| 24699 |
govind |
160 |
LOGGER.info(categoryId + ":" + escalationType + ":" + region.getRegionId());
|
| 24439 |
govind |
161 |
positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType,
|
|
|
162 |
region.getRegionId());
|
|
|
163 |
LOGGER.info("positions:-" + positions);
|
| 24500 |
govind |
164 |
if (positions.size() > 0) {
|
| 24439 |
govind |
165 |
break;
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
}
|
|
|
169 |
if (positions.size() == 0) {
|
| 24557 |
govind |
170 |
if (escalationType == EscalationType.L1) {
|
|
|
171 |
regions = partnerRegionRepository.selectByfofoId(0);
|
|
|
172 |
LOGGER.info("regions=" + regions);
|
|
|
173 |
for (PartnerRegion region : regions) {
|
|
|
174 |
positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId,
|
|
|
175 |
escalationType, region.getRegionId());
|
|
|
176 |
LOGGER.info("positions:-" + positions);
|
|
|
177 |
if (positions.size() > 0) {
|
|
|
178 |
break;
|
|
|
179 |
}
|
|
|
180 |
}
|
|
|
181 |
} else {
|
|
|
182 |
regions = partnerRegionRepository.selectByfofoId(0);
|
|
|
183 |
LOGGER.info("regions=" + regions);
|
|
|
184 |
for (PartnerRegion region : regions) {
|
|
|
185 |
positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId,
|
|
|
186 |
escalationType, region.getRegionId());
|
|
|
187 |
LOGGER.info("positions:-" + positions);
|
|
|
188 |
if (positions.size() > 0) {
|
|
|
189 |
break;
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
}
|
| 24439 |
govind |
193 |
}
|
| 24699 |
govind |
194 |
|
| 24439 |
govind |
195 |
}
|
| 24699 |
govind |
196 |
if (positions.size() == 0) {
|
| 24557 |
govind |
197 |
return 0;
|
|
|
198 |
}
|
|
|
199 |
LOGGER.info(positions.get(0).getAuthUserId());
|
| 24439 |
govind |
200 |
return positions.get(0).getAuthUserId();
|
| 24417 |
govind |
201 |
/*
|
|
|
202 |
* if(ActivityType.escalationTypes.contains(escalationType)) {
|
|
|
203 |
* //escalationMatrix } else { throw new
|
|
|
204 |
* ProfitMandiBusinessException("SubCategory", subcategoryId,
|
|
|
205 |
* "Could not find Assignee for "); }
|
|
|
206 |
*/
|
| 24439 |
govind |
207 |
|
| 24383 |
amit.gupta |
208 |
}
|
|
|
209 |
|
|
|
210 |
@Override
|
|
|
211 |
public void addActivity(int ticketId, Activity activity) {
|
|
|
212 |
activity.setTicketId(ticketId);
|
| 24417 |
govind |
213 |
activityRepository.persist(activity);
|
| 24383 |
amit.gupta |
214 |
}
|
|
|
215 |
|
| 24439 |
govind |
216 |
private String getRandomString() {
|
|
|
217 |
int length = 4;
|
|
|
218 |
boolean useLetters = false;
|
|
|
219 |
boolean useNumbers = true;
|
|
|
220 |
String generatedString = RandomStringUtils.random(length, useLetters, useNumbers);
|
|
|
221 |
return generatedString;
|
|
|
222 |
}
|
|
|
223 |
|
| 24417 |
govind |
224 |
@Override
|
|
|
225 |
public void addPartnerToRegion(int regionId, List<Integer> fofoIds) {
|
|
|
226 |
|
| 24557 |
govind |
227 |
for (int fofoId : fofoIds) {
|
|
|
228 |
PartnerRegion partnerRegion = new PartnerRegion();
|
|
|
229 |
partnerRegion.setFofoId(fofoId);
|
|
|
230 |
partnerRegion.setRegionId(regionId);
|
|
|
231 |
partnerRegionRepository.persist(partnerRegion);
|
| 24417 |
govind |
232 |
}
|
|
|
233 |
}
|
|
|
234 |
|
|
|
235 |
@Override
|
| 24500 |
govind |
236 |
public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<TicketAssigned> ticketAssigneds) {
|
| 24417 |
govind |
237 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
| 24500 |
govind |
238 |
|
|
|
239 |
for (TicketAssigned ticketAssigned : ticketAssigneds) {
|
|
|
240 |
AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
|
|
|
241 |
authUserIdAndAuthUserMap.put(ticketAssigned.getTicketId(), authUser);
|
|
|
242 |
}
|
|
|
243 |
return authUserIdAndAuthUserMap;
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
@Override
|
|
|
247 |
public Map<Integer, AuthUser> getTicketIdAndAuthUserMapUsingTickets(List<Ticket> tickets) {
|
|
|
248 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
|
|
249 |
|
| 24417 |
govind |
250 |
for (Ticket ticket : tickets) {
|
| 24500 |
govind |
251 |
AuthUser authUser = authRepository.selectById(ticket.getL1AuthUser());
|
|
|
252 |
authUserIdAndAuthUserMap.put(ticket.getId(), authUser);
|
| 24417 |
govind |
253 |
}
|
|
|
254 |
return authUserIdAndAuthUserMap;
|
|
|
255 |
}
|
|
|
256 |
|
|
|
257 |
@Override
|
|
|
258 |
public Map<Integer, TicketSubCategory> getSubCategoryIdAndSubCategoryMap(List<Ticket> tickets) {
|
|
|
259 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = new HashMap<>();
|
| 24699 |
govind |
260 |
if (tickets != null) {
|
|
|
261 |
for (Ticket ticket : tickets) {
|
|
|
262 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
263 |
subCategoryIdAndSubCategoryMap.put(ticket.getSubCategoryId(), ticketSubCategory);
|
|
|
264 |
}
|
| 24417 |
govind |
265 |
}
|
|
|
266 |
return subCategoryIdAndSubCategoryMap;
|
|
|
267 |
}
|
|
|
268 |
|
|
|
269 |
@Override
|
|
|
270 |
public Map<Integer, CustomRetailer> getPartnerByFofoIds(List<Ticket> tickets) {
|
|
|
271 |
List<Integer> fofoIds = new ArrayList<>();
|
| 24569 |
govind |
272 |
LOGGER.info(tickets);
|
| 24699 |
govind |
273 |
if (tickets == null) {
|
| 24569 |
govind |
274 |
return null;
|
|
|
275 |
}
|
| 24417 |
govind |
276 |
for (Ticket ticket : tickets) {
|
|
|
277 |
fofoIds.add(ticket.getFofoId());
|
|
|
278 |
}
|
| 24699 |
govind |
279 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService.getFofoRetailers(fofoIds);
|
| 24417 |
govind |
280 |
return fofoIdsAndCustomRetailer;
|
|
|
281 |
}
|
|
|
282 |
|
| 24439 |
govind |
283 |
@Override
|
|
|
284 |
public List<TicketCategory> getAllTicketCategotyFromSubCategory() {
|
|
|
285 |
|
|
|
286 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll();
|
|
|
287 |
HashSet<Integer> categoryIds = new HashSet<>();
|
|
|
288 |
for (TicketSubCategory ticketSubcategory : ticketSubCategories) {
|
|
|
289 |
categoryIds.add(ticketSubcategory.getcategoryId());
|
|
|
290 |
}
|
|
|
291 |
List<TicketCategory> ticketcategories = ticketCategoryRepository.selectAll(new ArrayList<>(categoryIds));
|
|
|
292 |
return ticketcategories;
|
|
|
293 |
}
|
|
|
294 |
|
| 24500 |
govind |
295 |
private Ticket setAssignment(Ticket ticket, TicketAssigned ticketAssigned) {
|
| 24439 |
govind |
296 |
TicketCategory ticketCategory = ticketCategoryRepository.selectByName(ProfitMandiConstants.CRM);
|
|
|
297 |
List<Position> positions = positionRepository.selectPositionByCategoryId(ticketCategory.getId());
|
|
|
298 |
for (Position position : positions) {
|
|
|
299 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
| 24500 |
govind |
300 |
ticketAssigned.setAssineeId(position.getAuthUserId());
|
| 24439 |
govind |
301 |
ticket.setL1AuthUser(position.getAuthUserId());
|
| 24557 |
govind |
302 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
| 24439 |
govind |
303 |
ticket.setL2AuthUser(position.getAuthUserId());
|
|
|
304 |
}
|
|
|
305 |
}
|
|
|
306 |
return ticket;
|
|
|
307 |
}
|
| 24500 |
govind |
308 |
|
| 24471 |
govind |
309 |
@Override
|
|
|
310 |
public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMapUsingPositions(List<Position> positions) {
|
|
|
311 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
|
|
312 |
for (Position position : positions) {
|
|
|
313 |
AuthUser authUser = authRepository.selectById(position.getAuthUserId());
|
|
|
314 |
authUserIdAndAuthUserMap.put(position.getAuthUserId(), authUser);
|
|
|
315 |
}
|
|
|
316 |
return authUserIdAndAuthUserMap;
|
|
|
317 |
}
|
| 24500 |
govind |
318 |
|
| 24471 |
govind |
319 |
@Override
|
|
|
320 |
public Map<Integer, TicketCategory> getCategoryIdAndCategoryUsingPositions(List<Position> positions) {
|
|
|
321 |
Map<Integer, TicketCategory> categoryIdAndCategoryMap = new HashMap<>();
|
|
|
322 |
for (Position position : positions) {
|
| 24500 |
govind |
323 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(position.getCategoryId());
|
| 24471 |
govind |
324 |
categoryIdAndCategoryMap.put(position.getCategoryId(), ticketCategory);
|
|
|
325 |
}
|
|
|
326 |
return categoryIdAndCategoryMap;
|
|
|
327 |
}
|
| 24439 |
govind |
328 |
|
| 24471 |
govind |
329 |
@Override
|
|
|
330 |
public Map<Integer, Region> getRegionIdAndRegionMap(List<Position> positions) {
|
|
|
331 |
Map<Integer, Region> regionIdAndRegionMap = new HashMap<>();
|
|
|
332 |
for (Position position : positions) {
|
| 24500 |
govind |
333 |
Region region = regionRepository.selectById(position.getRegionId());
|
| 24471 |
govind |
334 |
regionIdAndRegionMap.put(position.getRegionId(), region);
|
|
|
335 |
}
|
|
|
336 |
return regionIdAndRegionMap;
|
|
|
337 |
}
|
| 24500 |
govind |
338 |
|
|
|
339 |
@Override
|
| 24699 |
govind |
340 |
public Map<Integer, List<AuthUser>> getAuthUserList(List<Ticket> tickets, AuthUser authUser) {
|
| 24500 |
govind |
341 |
Map<Integer, List<AuthUser>> authUserListMap = new HashMap<>();
|
|
|
342 |
for (Ticket ticket : tickets) {
|
| 24570 |
govind |
343 |
if (ticket.getL2AuthUser() == authUser.getId()) {
|
| 24500 |
govind |
344 |
List<AuthUser> authUsers = new ArrayList<>();
|
|
|
345 |
authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
|
|
|
346 |
authUserListMap.put(ticket.getId(), authUsers);
|
|
|
347 |
|
| 24570 |
govind |
348 |
} else if (ticket.getL3AuthUser() == authUser.getId()) {
|
| 24500 |
govind |
349 |
TicketAssigned ticketAssigned = ticketAssignedRepository
|
|
|
350 |
.selectByAssigneeIdAndTicketId(ticket.getL2AuthUser(), ticket.getId());
|
|
|
351 |
if (ticketAssigned == null) {
|
|
|
352 |
List<AuthUser> authUsers = new ArrayList<>();
|
|
|
353 |
authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
|
|
|
354 |
authUserListMap.put(ticket.getId(), authUsers);
|
|
|
355 |
} else {
|
|
|
356 |
List<AuthUser> authUsers = new ArrayList<>();
|
|
|
357 |
authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
|
|
|
358 |
authUsers.add(authRepository.selectById(ticket.getL2AuthUser()));
|
|
|
359 |
authUserListMap.put(ticket.getId(), authUsers);
|
|
|
360 |
}
|
|
|
361 |
} else {
|
|
|
362 |
TicketAssigned ticketAssigned = ticketAssignedRepository
|
|
|
363 |
.selectByAssigneeIdAndTicketId(ticket.getL3AuthUser(), ticket.getId());
|
|
|
364 |
if (ticketAssigned == null) {
|
|
|
365 |
ticketAssigned = ticketAssignedRepository.selectByAssigneeIdAndTicketId(ticket.getL2AuthUser(),
|
|
|
366 |
ticket.getId());
|
|
|
367 |
if (ticketAssigned == null) {
|
|
|
368 |
List<AuthUser> authUsers = new ArrayList<>();
|
|
|
369 |
authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
|
|
|
370 |
authUserListMap.put(ticket.getId(), authUsers);
|
|
|
371 |
} else {
|
|
|
372 |
List<AuthUser> authUsers = new ArrayList<>();
|
|
|
373 |
authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
|
|
|
374 |
authUsers.add(authRepository.selectById(ticket.getL2AuthUser()));
|
|
|
375 |
authUserListMap.put(ticket.getId(), authUsers);
|
|
|
376 |
}
|
|
|
377 |
} else {
|
|
|
378 |
List<AuthUser> authUsers = new ArrayList<>();
|
|
|
379 |
authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
|
|
|
380 |
authUsers.add(authRepository.selectById(ticket.getL2AuthUser()));
|
|
|
381 |
authUsers.add(authRepository.selectById(ticket.getL3AuthUser()));
|
|
|
382 |
authUserListMap.put(ticket.getId(), authUsers);
|
|
|
383 |
|
|
|
384 |
}
|
|
|
385 |
}
|
|
|
386 |
}
|
|
|
387 |
return authUserListMap;
|
|
|
388 |
}
|
| 24557 |
govind |
389 |
|
| 24500 |
govind |
390 |
@Override
|
| 24557 |
govind |
391 |
public void updateTicket(int categoryId, int subCategoryId, Ticket ticket) throws ProfitMandiBusinessException {
|
|
|
392 |
TicketAssigned ticketAssigned = new TicketAssigned();
|
| 24500 |
govind |
393 |
ticket.setSubCategoryId(subCategoryId);
|
|
|
394 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
|
|
395 |
ticket.setL2EscalationTimestamp(ticket.getUpdateTimestamp().plusDays(2));
|
|
|
396 |
ticket.setL3EscalationTimestamp(ticket.getL2EscalationTimestamp().plusDays(2));
|
|
|
397 |
ticket.setLastEscalationTimestamp(ticket.getL3EscalationTimestamp().plusDays(2));
|
|
|
398 |
int l3Auth = this.getAuthUserId(categoryId, EscalationType.L3, ticket.getFofoId());
|
| 25505 |
amit.gupta |
399 |
int l2Auth = this.getAuthUserId(categoryId, EscalationType.L2, ticket.getFofoId());
|
| 24500 |
govind |
400 |
int l1Auth = this.getAuthUserId(categoryId, EscalationType.L1, ticket.getFofoId());
|
|
|
401 |
LOGGER.info(l1Auth + "-" + l2Auth + "-" + l3Auth);
|
|
|
402 |
if (l1Auth == 0) {
|
|
|
403 |
if (l2Auth == 0) {
|
|
|
404 |
this.setAssignment(ticket, ticketAssigned);
|
|
|
405 |
} else {
|
|
|
406 |
ticketAssigned.setAssineeId(l2Auth);
|
| 24569 |
govind |
407 |
ticket.setL1AuthUser(0);
|
| 24536 |
govind |
408 |
ticket.setL2AuthUser(l2Auth);
|
| 24500 |
govind |
409 |
}
|
|
|
410 |
} else {
|
|
|
411 |
ticketAssigned.setAssineeId(l1Auth);
|
|
|
412 |
ticket.setL1AuthUser(l1Auth);
|
|
|
413 |
ticket.setL2AuthUser(l2Auth);
|
|
|
414 |
}
|
|
|
415 |
ticket.setL3AuthUser(l3Auth);
|
|
|
416 |
ticketRepository.persist(ticket);
|
|
|
417 |
ticketAssigned.setTicketId(ticket.getId());
|
|
|
418 |
ticketAssignedRepository.persist(ticketAssigned);
|
|
|
419 |
AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
|
| 24569 |
govind |
420 |
this.sendAssignedTicketMail(authUser, ticket);
|
|
|
421 |
}
|
|
|
422 |
|
|
|
423 |
@Override
|
| 24699 |
govind |
424 |
public void sendAssignedTicketMail(AuthUser authUser, Ticket ticket) throws ProfitMandiBusinessException {
|
| 24500 |
govind |
425 |
try {
|
|
|
426 |
Utils.sendMailWithAttachments(mailSender, authUser.getEmailId(), null, ASSINMENT_SUBJECT,
|
|
|
427 |
String.format(ASSIGNED_TICKET, authUser.getFirstName(),
|
| 24699 |
govind |
428 |
retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName(), ticket.getId()),
|
| 24500 |
govind |
429 |
null);
|
|
|
430 |
} catch (Exception e) {
|
|
|
431 |
throw new ProfitMandiBusinessException("Ticket Assingment", authUser.getEmailId(),
|
|
|
432 |
"Could not send ticket assignment mail");
|
|
|
433 |
}
|
|
|
434 |
}
|
| 25570 |
tejbeer |
435 |
|
|
|
436 |
@Override
|
|
|
437 |
public Map<Integer, List<CustomRetailer>> getPositionCustomRetailerMap(List<Position> positions) {
|
|
|
438 |
Map<Integer, List<CustomRetailer>> positionRetailerMap = new HashMap<>();
|
|
|
439 |
for (Position position : positions) {
|
|
|
440 |
List<Integer> fofoIds = partnersPositionRepository.selectByPositionId(position.getId()).stream()
|
|
|
441 |
.map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
442 |
|
|
|
443 |
if (!fofoIds.isEmpty()) {
|
|
|
444 |
if (fofoIds.contains(0)) {
|
|
|
445 |
fofoIds = partnerRegionRepository.selectByRegionId(position.getRegionId()).stream()
|
|
|
446 |
.map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
447 |
if (fofoIds.contains(0)) {
|
|
|
448 |
fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
|
|
449 |
.collect(Collectors.toList());
|
|
|
450 |
}
|
|
|
451 |
|
|
|
452 |
}
|
|
|
453 |
positionRetailerMap.put(position.getId(),
|
|
|
454 |
new ArrayList<CustomRetailer>(retailerService.getFofoRetailers(fofoIds).values()));
|
|
|
455 |
|
|
|
456 |
}
|
|
|
457 |
}
|
|
|
458 |
return positionRetailerMap;
|
|
|
459 |
}
|
|
|
460 |
|
|
|
461 |
@Override
|
|
|
462 |
public Map<Integer, List<CustomRetailer>> getpositionIdAndpartnerRegionMap(List<Position> positions) {
|
|
|
463 |
Map<Integer, List<CustomRetailer>> positionIdAndpartnerRegionMap = new HashedMap<>();
|
|
|
464 |
for (Position position : positions) {
|
|
|
465 |
List<Integer> fofoIds = partnerRegionRepository.selectByRegionId(position.getRegionId()).stream()
|
|
|
466 |
.map(x -> x.getFofoId()).collect(Collectors.toList());
|
|
|
467 |
|
|
|
468 |
if (!fofoIds.isEmpty()) {
|
|
|
469 |
if (fofoIds.contains(0)) {
|
|
|
470 |
fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId()).collect(Collectors.toList());
|
|
|
471 |
|
|
|
472 |
}
|
|
|
473 |
|
|
|
474 |
Map<Integer, CustomRetailer> fofoRetailers = retailerService.getFofoRetailers(fofoIds);
|
|
|
475 |
positionIdAndpartnerRegionMap.put(position.getRegionId(),
|
|
|
476 |
new ArrayList<CustomRetailer>(fofoRetailers.values()));
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
}
|
|
|
480 |
|
|
|
481 |
return positionIdAndpartnerRegionMap;
|
|
|
482 |
}
|
| 25597 |
amit.gupta |
483 |
|
|
|
484 |
@Override
|
| 25726 |
amit.gupta |
485 |
@Cacheable(value = "authUserEmailMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 25597 |
amit.gupta |
486 |
public Map<String, Set<String>> getAuthUserPartnerEmailMapping() {
|
|
|
487 |
Map<String, Set<String>> storeGuyMap = new HashMap<>();
|
|
|
488 |
Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
|
|
|
489 |
.collect(Collectors.toSet());
|
|
|
490 |
List<Position> categoryPositions = positionRepository
|
|
|
491 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
492 |
Map<Integer, Position> positionsMap = categoryPositions.stream()
|
|
|
493 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
494 |
|
| 25721 |
tejbeer |
495 |
Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
|
| 25597 |
amit.gupta |
496 |
for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
|
|
|
497 |
int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
|
|
|
498 |
Set<String> partnerEmails = positionPartnerEntry.getValue().stream()
|
|
|
499 |
.filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getEmail())
|
|
|
500 |
.collect(Collectors.toSet());
|
|
|
501 |
AuthUser authUser = authRepository.selectById(authUserId);
|
|
|
502 |
if (authUser.isActive()) {
|
|
|
503 |
storeGuyMap.put(authUser.getEmailId(), partnerEmails);
|
|
|
504 |
}
|
|
|
505 |
}
|
|
|
506 |
return storeGuyMap;
|
|
|
507 |
}
|
| 25721 |
tejbeer |
508 |
|
|
|
509 |
@Override
|
| 25777 |
amit.gupta |
510 |
@Cacheable(value = "authUserEmailPartnerIdMapping", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 25721 |
tejbeer |
511 |
public Map<String, Set<Integer>> getAuthUserPartnerIdMapping() {
|
|
|
512 |
Map<String, Set<Integer>> storeGuyMap = new HashMap<>();
|
| 25777 |
amit.gupta |
513 |
Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
|
|
|
514 |
.collect(Collectors.toSet());
|
| 25721 |
tejbeer |
515 |
List<Position> categoryPositions = positionRepository
|
|
|
516 |
.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
517 |
Map<Integer, Position> positionsMap = categoryPositions.stream()
|
|
|
518 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
|
|
519 |
|
|
|
520 |
Map<Integer, List<CustomRetailer>> positonPartnerMap = this.getPositionCustomRetailerMap(categoryPositions);
|
|
|
521 |
for (Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
|
|
|
522 |
int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
|
| 25777 |
amit.gupta |
523 |
Set<Integer> partnerEmails = positionPartnerEntry.getValue().stream()
|
|
|
524 |
.filter(x -> activeFofoIds.contains(x.getPartnerId())).map(x -> x.getPartnerId())
|
| 25721 |
tejbeer |
525 |
.collect(Collectors.toSet());
|
|
|
526 |
AuthUser authUser = authRepository.selectById(authUserId);
|
|
|
527 |
if (authUser.isActive()) {
|
| 25777 |
amit.gupta |
528 |
storeGuyMap.put(authUser.getEmailId(), partnerEmails);
|
| 25721 |
tejbeer |
529 |
}
|
|
|
530 |
}
|
|
|
531 |
return storeGuyMap;
|
|
|
532 |
}
|
|
|
533 |
|
|
|
534 |
@Override
|
|
|
535 |
public List<String> getAuthUserByPartnerId(int fofoId) {
|
|
|
536 |
|
|
|
537 |
List<String> emails = new ArrayList<>();
|
|
|
538 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
|
|
|
539 |
.collect(Collectors.toList());
|
|
|
540 |
|
|
|
541 |
regionIds.add(5);// All partners Id;
|
|
|
542 |
List<Integer> fofoIds = new ArrayList<>();
|
|
|
543 |
fofoIds.add(fofoId);
|
|
|
544 |
fofoIds.add(0);
|
| 25799 |
tejbeer |
545 |
|
|
|
546 |
LOGGER.info("fofoIds" + fofoIds);
|
| 25721 |
tejbeer |
547 |
List<Integer> partnerPositionIds = partnersPositionRepository.selectByRegionIdAndPartnerId(regionIds, fofoIds)
|
|
|
548 |
.stream().map(x -> x.getPositionId()).collect(Collectors.toList());
|
|
|
549 |
|
| 25799 |
tejbeer |
550 |
LOGGER.info("partnerPositionIds" + partnerPositionIds);
|
|
|
551 |
|
| 25721 |
tejbeer |
552 |
for (Integer partnerPostionId : partnerPositionIds) {
|
| 25799 |
tejbeer |
553 |
Position position = positionRepository.selectByIdAndCategoryId(partnerPostionId,
|
|
|
554 |
ProfitMandiConstants.TICKET_CATEGORY_SALES);
|
|
|
555 |
LOGGER.info("position" + position);
|
|
|
556 |
if (position != null) {
|
| 25721 |
tejbeer |
557 |
|
| 25799 |
tejbeer |
558 |
AuthUser authUser = authRepository.selectById(position.getAuthUserId());
|
|
|
559 |
LOGGER.info("authUser" + authUser);
|
|
|
560 |
emails.add(authUser.getEmailId());
|
|
|
561 |
}
|
| 25721 |
tejbeer |
562 |
}
|
|
|
563 |
|
|
|
564 |
return emails;
|
|
|
565 |
}
|
| 24383 |
amit.gupta |
566 |
}
|