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