Subversion Repositories SmartDukaan

Rev

Rev 24471 | Rev 24526 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 24471 Rev 24500
Line 1... Line 1...
1
package com.spice.profitmandi.dao.repository.cs;
1
package com.spice.profitmandi.dao.repository.cs;
-
 
2
 
2
import java.time.LocalDateTime;
3
import java.time.LocalDateTime;
3
import java.util.ArrayList;
4
import java.util.ArrayList;
4
import java.util.HashMap;
5
import java.util.HashMap;
5
import java.util.HashSet;
6
import java.util.HashSet;
6
import java.util.List;
7
import java.util.List;
7
import java.util.Map;
8
import java.util.Map;
-
 
9
import java.util.stream.Collectors;
-
 
10
 
8
import org.apache.commons.lang.RandomStringUtils;
11
import org.apache.commons.lang.RandomStringUtils;
9
import org.apache.logging.log4j.LogManager;
12
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.Logger;
13
import org.apache.logging.log4j.Logger;
11
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.mail.javamail.JavaMailSender;
15
import org.springframework.mail.javamail.JavaMailSender;
Line 19... Line 22...
19
import com.spice.profitmandi.dao.entity.cs.Activity;
22
import com.spice.profitmandi.dao.entity.cs.Activity;
20
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
23
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
21
import com.spice.profitmandi.dao.entity.cs.Position;
24
import com.spice.profitmandi.dao.entity.cs.Position;
22
import com.spice.profitmandi.dao.entity.cs.Region;
25
import com.spice.profitmandi.dao.entity.cs.Region;
23
import com.spice.profitmandi.dao.entity.cs.Ticket;
26
import com.spice.profitmandi.dao.entity.cs.Ticket;
-
 
27
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
24
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
28
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
25
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
29
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
26
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
30
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
27
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
31
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
28
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
32
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
Line 60... Line 64...
60
	@Autowired
64
	@Autowired
61
	private AuthRepository authRepository;
65
	private AuthRepository authRepository;
62
 
66
 
63
	@Autowired
67
	@Autowired
64
	private RetailerService retailerService;
68
	private RetailerService retailerService;
65
	
69
 
66
	@Autowired
70
	@Autowired
67
	private RegionRepository regionRepository;
71
	private RegionRepository regionRepository;
68
 
72
 
-
 
73
	@Autowired
-
 
74
	private TicketAssignedRepository ticketAssignedRepository;
-
 
75
 
69
	@Override
76
	@Override
70
	public void createTicket(int fofoId, int categoryId, int subcategoryId, String message)
77
	public void createTicket(int fofoId, int categoryId, int subcategoryId, String message)
71
			throws ProfitMandiBusinessException {
78
			throws ProfitMandiBusinessException {
72
 
79
 
73
		ActivityType type = ActivityType.OPENED;
80
		ActivityType type = ActivityType.OPENED;
74
		EscalationType escalationTypeL1 = EscalationType.L1;
81
		EscalationType escalationTypeL1 = EscalationType.L1;
75
		EscalationType escalationTypeL2 = EscalationType.L2;
82
		EscalationType escalationTypeL2 = EscalationType.L2;
76
		EscalationType escalationTypeL3 = EscalationType.L3;
83
		EscalationType escalationTypeL3 = EscalationType.L3;
77
		Ticket ticket = new Ticket();
84
		Ticket ticket = new Ticket();
-
 
85
		TicketAssigned ticketAssigned = new TicketAssigned();
78
		ticket.setSubCategoryId(subcategoryId);
86
		ticket.setSubCategoryId(subcategoryId);
79
		ticket.setFofoId(fofoId);
87
		ticket.setFofoId(fofoId);
80
		ticket.setCreateTimestamp(LocalDateTime.now());
88
		ticket.setCreateTimestamp(LocalDateTime.now());
81
		ticket.setUpdateTimestamp(LocalDateTime.now());
89
		ticket.setUpdateTimestamp(LocalDateTime.now());
82
		ticket.setL2EscalationTimestamp(ticket.getUpdateTimestamp().plusDays(2));
90
		ticket.setL2EscalationTimestamp(ticket.getUpdateTimestamp().plusDays(2));
Line 87... Line 95...
87
		int l1Auth = this.getAuthUserId(categoryId, escalationTypeL1, fofoId);
95
		int l1Auth = this.getAuthUserId(categoryId, escalationTypeL1, fofoId);
88
		int l2Auth = this.getAuthUserId(categoryId, escalationTypeL2, fofoId);
96
		int l2Auth = this.getAuthUserId(categoryId, escalationTypeL2, fofoId);
89
		LOGGER.info(l1Auth + "-" + l2Auth + "-" + l3Auth);
97
		LOGGER.info(l1Auth + "-" + l2Auth + "-" + l3Auth);
90
		if (l1Auth == 0) {
98
		if (l1Auth == 0) {
91
			if (l2Auth == 0) {
99
			if (l2Auth == 0) {
92
				this.setAssignment(ticket);
100
				this.setAssignment(ticket, ticketAssigned);
93
			} else {
101
			} else {
94
				ticket.setAssigneeId(l2Auth);
102
				ticketAssigned.setAssineeId(l2Auth);
95
			}
103
			}
96
		} else {
104
		} else {
97
			ticket.setAssigneeId(l1Auth);
105
			ticketAssigned.setAssineeId(l1Auth);
98
			ticket.setL1AuthUser(l1Auth);
106
			ticket.setL1AuthUser(l1Auth);
99
			ticket.setL2AuthUser(l2Auth);
107
			ticket.setL2AuthUser(l2Auth);
100
		}
108
		}
101
		ticket.setL3AuthUser(l3Auth);
109
		ticket.setL3AuthUser(l3Auth);
102
		ticketRepository.persist(ticket);
110
		ticketRepository.persist(ticket);
-
 
111
		ticketAssigned.setTicketId(ticket.getId());
-
 
112
		ticketAssignedRepository.persist(ticketAssigned);
103
		AuthUser authUser = authRepository.selectById(ticket.getAssigneeId());
113
		AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
104
		try {
114
		try {
105
			Utils.sendMailWithAttachments(mailSender, authUser.getEmailId(), null, ASSINMENT_SUBJECT,
115
			Utils.sendMailWithAttachments(mailSender, authUser.getEmailId(), null, ASSINMENT_SUBJECT,
106
					String.format(ASSIGNED_TICKET, authUser.getFirstName(),
116
					String.format(ASSIGNED_TICKET, authUser.getFirstName(),
107
							retailerService.getFofoRetailer(fofoId).getBusinessName()),
117
							retailerService.getFofoRetailer(fofoId).getBusinessName()),
108
					null);
118
					null);
Line 129... Line 139...
129
		if (escalationType == EscalationType.L3) {
139
		if (escalationType == EscalationType.L3) {
130
			positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(0, escalationType, 0);
140
			positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(0, escalationType, 0);
131
		} else {
141
		} else {
132
			List<PartnerRegion> regions = partnerRegionRepository.selectByfofoId(fofoId);
142
			List<PartnerRegion> regions = partnerRegionRepository.selectByfofoId(fofoId);
133
			LOGGER.info("regions=" + regions);
143
			LOGGER.info("regions=" + regions);
134
			if(regions.size()==0)
144
			if (regions.size() == 0) {
135
			{
-
 
136
				regions=partnerRegionRepository.selectByfofoId(0);
145
				regions = partnerRegionRepository.selectByfofoId(0);
137
				LOGGER.info("regions=" + regions);
146
				LOGGER.info("regions=" + regions);
138
			}
147
			}
139
			for (PartnerRegion region : regions) {
148
			for (PartnerRegion region : regions) {
140
				positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType,
149
				positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType,
141
						region.getRegionId());
150
						region.getRegionId());
142
				LOGGER.info("positions:-" + positions);
151
				LOGGER.info("positions:-" + positions);
143
				if (positions != null) {
152
				if (positions.size() > 0) {
144
					break;
153
					break;
145
				}
154
				}
146
 
155
 
147
			}
156
			}
148
			if (positions.size() == 0) {
157
			if (positions.size() == 0) {
Line 188... Line 197...
188
			}
197
			}
189
		}
198
		}
190
	}
199
	}
191
 
200
 
192
	@Override
201
	@Override
193
	public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<Ticket> tickets) {
202
	public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<TicketAssigned> ticketAssigneds) {
-
 
203
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
-
 
204
 
-
 
205
		for (TicketAssigned ticketAssigned : ticketAssigneds) {
-
 
206
			AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
-
 
207
			authUserIdAndAuthUserMap.put(ticketAssigned.getTicketId(), authUser);
-
 
208
		}
-
 
209
		return authUserIdAndAuthUserMap;
-
 
210
	}
-
 
211
 
-
 
212
	@Override
-
 
213
	public Map<Integer, AuthUser> getTicketIdAndAuthUserMapUsingTickets(List<Ticket> tickets) {
194
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
214
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
-
 
215
 
195
		for (Ticket ticket : tickets) {
216
		for (Ticket ticket : tickets) {
196
			AuthUser authUser = authRepository.selectById(ticket.getAssigneeId());
217
			AuthUser authUser = authRepository.selectById(ticket.getL1AuthUser());
197
			authUserIdAndAuthUserMap.put(ticket.getAssigneeId(), authUser);
218
			authUserIdAndAuthUserMap.put(ticket.getId(), authUser);
198
		}
219
		}
199
		return authUserIdAndAuthUserMap;
220
		return authUserIdAndAuthUserMap;
200
	}
221
	}
201
 
222
 
202
	@Override
223
	@Override
Line 229... Line 250...
229
		}
250
		}
230
		List<TicketCategory> ticketcategories = ticketCategoryRepository.selectAll(new ArrayList<>(categoryIds));
251
		List<TicketCategory> ticketcategories = ticketCategoryRepository.selectAll(new ArrayList<>(categoryIds));
231
		return ticketcategories;
252
		return ticketcategories;
232
	}
253
	}
233
 
254
 
234
	private Ticket setAssignment(Ticket ticket) {
255
	private Ticket setAssignment(Ticket ticket, TicketAssigned ticketAssigned) {
235
		TicketCategory ticketCategory = ticketCategoryRepository.selectByName(ProfitMandiConstants.CRM);
256
		TicketCategory ticketCategory = ticketCategoryRepository.selectByName(ProfitMandiConstants.CRM);
236
		List<Position> positions = positionRepository.selectPositionByCategoryId(ticketCategory.getId());
257
		List<Position> positions = positionRepository.selectPositionByCategoryId(ticketCategory.getId());
237
		for (Position position : positions) {
258
		for (Position position : positions) {
238
			if (position.getEscalationType().equals(EscalationType.L1)) {
259
			if (position.getEscalationType().equals(EscalationType.L1)) {
239
				ticket.setAssigneeId(position.getAuthUserId());
260
				ticketAssigned.setAssineeId(position.getAuthUserId());
240
				ticket.setL1AuthUser(position.getAuthUserId());
261
				ticket.setL1AuthUser(position.getAuthUserId());
241
			} else {
262
			} else {
242
				ticket.setL2AuthUser(position.getAuthUserId());
263
				ticket.setL2AuthUser(position.getAuthUserId());
243
			}
264
			}
244
		}
265
		}
245
		return ticket;
266
		return ticket;
246
	}
267
	}
247
	
268
 
248
	@Override
269
	@Override
249
	public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMapUsingPositions(List<Position> positions) {
270
	public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMapUsingPositions(List<Position> positions) {
250
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
271
		Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
251
		for (Position position : positions) {
272
		for (Position position : positions) {
252
			AuthUser authUser = authRepository.selectById(position.getAuthUserId());
273
			AuthUser authUser = authRepository.selectById(position.getAuthUserId());
253
			authUserIdAndAuthUserMap.put(position.getAuthUserId(), authUser);
274
			authUserIdAndAuthUserMap.put(position.getAuthUserId(), authUser);
254
		}
275
		}
255
		return authUserIdAndAuthUserMap;
276
		return authUserIdAndAuthUserMap;
256
	}
277
	}
257
	
278
 
258
	@Override
279
	@Override
259
	public Map<Integer, TicketCategory> getCategoryIdAndCategoryUsingPositions(List<Position> positions) {
280
	public Map<Integer, TicketCategory> getCategoryIdAndCategoryUsingPositions(List<Position> positions) {
260
		Map<Integer, TicketCategory> categoryIdAndCategoryMap = new HashMap<>();
281
		Map<Integer, TicketCategory> categoryIdAndCategoryMap = new HashMap<>();
261
		for (Position position : positions) {
282
		for (Position position : positions) {
262
			TicketCategory ticketCategory=ticketCategoryRepository.selectById(position.getCategoryId());
283
			TicketCategory ticketCategory = ticketCategoryRepository.selectById(position.getCategoryId());
263
			categoryIdAndCategoryMap.put(position.getCategoryId(), ticketCategory);
284
			categoryIdAndCategoryMap.put(position.getCategoryId(), ticketCategory);
264
		}
285
		}
265
		return categoryIdAndCategoryMap;
286
		return categoryIdAndCategoryMap;
266
	}
287
	}
267
 
288
 
268
	@Override
289
	@Override
269
	public Map<Integer, Region> getRegionIdAndRegionMap(List<Position> positions) {
290
	public Map<Integer, Region> getRegionIdAndRegionMap(List<Position> positions) {
270
		Map<Integer, Region> regionIdAndRegionMap = new HashMap<>();
291
		Map<Integer, Region> regionIdAndRegionMap = new HashMap<>();
271
		for (Position position : positions) {
292
		for (Position position : positions) {
272
			Region region=regionRepository.selectById(position.getRegionId());
293
			Region region = regionRepository.selectById(position.getRegionId());
273
			regionIdAndRegionMap.put(position.getRegionId(), region);
294
			regionIdAndRegionMap.put(position.getRegionId(), region);
274
		}
295
		}
275
		return regionIdAndRegionMap;
296
		return regionIdAndRegionMap;
276
	}
297
	}
-
 
298
 
-
 
299
	@Override
-
 
300
	public Map<Integer, List<AuthUser>> getAuthUserList(List<Ticket> tickets, EscalationType escalationType) {
-
 
301
		Map<Integer, List<AuthUser>> authUserListMap = new HashMap<>();
-
 
302
		for (Ticket ticket : tickets) {
-
 
303
			if (escalationType == EscalationType.L2) {
-
 
304
				List<AuthUser> authUsers = new ArrayList<>();
-
 
305
				authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
-
 
306
				authUserListMap.put(ticket.getId(), authUsers);
-
 
307
 
-
 
308
			} else if (escalationType == EscalationType.L3) {
-
 
309
				TicketAssigned ticketAssigned = ticketAssignedRepository
-
 
310
						.selectByAssigneeIdAndTicketId(ticket.getL2AuthUser(), ticket.getId());
-
 
311
				if (ticketAssigned == null) {
-
 
312
					List<AuthUser> authUsers = new ArrayList<>();
-
 
313
					authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
-
 
314
					authUserListMap.put(ticket.getId(), authUsers);
-
 
315
				} else {
-
 
316
					List<AuthUser> authUsers = new ArrayList<>();
-
 
317
					authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
-
 
318
					authUsers.add(authRepository.selectById(ticket.getL2AuthUser()));
-
 
319
					authUserListMap.put(ticket.getId(), authUsers);
-
 
320
				}
-
 
321
			} else {
-
 
322
				TicketAssigned ticketAssigned = ticketAssignedRepository
-
 
323
						.selectByAssigneeIdAndTicketId(ticket.getL3AuthUser(), ticket.getId());
-
 
324
				if (ticketAssigned == null) {
-
 
325
					ticketAssigned = ticketAssignedRepository.selectByAssigneeIdAndTicketId(ticket.getL2AuthUser(),
-
 
326
							ticket.getId());
-
 
327
					if (ticketAssigned == null) {
-
 
328
						List<AuthUser> authUsers = new ArrayList<>();
-
 
329
						authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
-
 
330
						authUserListMap.put(ticket.getId(), authUsers);
-
 
331
					} else {
-
 
332
						List<AuthUser> authUsers = new ArrayList<>();
-
 
333
						authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
-
 
334
						authUsers.add(authRepository.selectById(ticket.getL2AuthUser()));
-
 
335
						authUserListMap.put(ticket.getId(), authUsers);
-
 
336
					}
-
 
337
				} else {
-
 
338
					List<AuthUser> authUsers = new ArrayList<>();
-
 
339
					authUsers.add(authRepository.selectById(ticket.getL1AuthUser()));
-
 
340
					authUsers.add(authRepository.selectById(ticket.getL2AuthUser()));
-
 
341
					authUsers.add(authRepository.selectById(ticket.getL3AuthUser()));
-
 
342
					authUserListMap.put(ticket.getId(), authUsers);
-
 
343
 
-
 
344
				}
-
 
345
			}
-
 
346
		}
-
 
347
		return authUserListMap;
-
 
348
	}
-
 
349
	@Override
-
 
350
	public void updateTicket(int categoryId,int subCategoryId,Ticket ticket) throws ProfitMandiBusinessException
-
 
351
	{
-
 
352
		TicketAssigned ticketAssigned=new TicketAssigned();
-
 
353
		ticket.setSubCategoryId(subCategoryId);
-
 
354
		ticket.setUpdateTimestamp(LocalDateTime.now());
-
 
355
		ticket.setL2EscalationTimestamp(ticket.getUpdateTimestamp().plusDays(2));
-
 
356
		ticket.setL3EscalationTimestamp(ticket.getL2EscalationTimestamp().plusDays(2));
-
 
357
		ticket.setLastEscalationTimestamp(ticket.getL3EscalationTimestamp().plusDays(2));
-
 
358
		int l3Auth = this.getAuthUserId(categoryId, EscalationType.L3, ticket.getFofoId());
-
 
359
		int l1Auth = this.getAuthUserId(categoryId, EscalationType.L1, ticket.getFofoId());
-
 
360
		int l2Auth = this.getAuthUserId(categoryId, EscalationType.L2, ticket.getFofoId());
-
 
361
		LOGGER.info(l1Auth + "-" + l2Auth + "-" + l3Auth);
-
 
362
		if (l1Auth == 0) {
-
 
363
			if (l2Auth == 0) {
-
 
364
				this.setAssignment(ticket, ticketAssigned);
-
 
365
			} else {
-
 
366
				ticketAssigned.setAssineeId(l2Auth);
-
 
367
			}
-
 
368
		} else {
-
 
369
			ticketAssigned.setAssineeId(l1Auth);
-
 
370
			ticket.setL1AuthUser(l1Auth);
-
 
371
			ticket.setL2AuthUser(l2Auth);
-
 
372
		}
-
 
373
		ticket.setL3AuthUser(l3Auth);
-
 
374
		ticketRepository.persist(ticket);
-
 
375
		ticketAssigned.setTicketId(ticket.getId());
-
 
376
		ticketAssignedRepository.persist(ticketAssigned);
-
 
377
		AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
-
 
378
		try {
-
 
379
			Utils.sendMailWithAttachments(mailSender, authUser.getEmailId(), null, ASSINMENT_SUBJECT,
-
 
380
					String.format(ASSIGNED_TICKET, authUser.getFirstName(),
-
 
381
							retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName()),
-
 
382
					null);
-
 
383
		} catch (Exception e) {
-
 
384
			throw new ProfitMandiBusinessException("Ticket Assingment", authUser.getEmailId(),
-
 
385
					"Could not send ticket assignment mail");
-
 
386
		}
-
 
387
	}
277
	
388
	
278
}
389
}