| 24383 |
amit.gupta |
1 |
package com.spice.profitmandi.dao.repository.cs;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
| 24417 |
govind |
4 |
import java.util.ArrayList;
|
|
|
5 |
import java.util.HashMap;
|
|
|
6 |
import java.util.List;
|
|
|
7 |
import java.util.Map;
|
| 24383 |
amit.gupta |
8 |
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.stereotype.Component;
|
|
|
11 |
|
|
|
12 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 24417 |
govind |
13 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
|
|
14 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 24383 |
amit.gupta |
15 |
import com.spice.profitmandi.dao.entity.cs.Activity;
|
| 24417 |
govind |
16 |
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
|
|
|
17 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 24383 |
amit.gupta |
18 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| 24417 |
govind |
19 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
| 24383 |
amit.gupta |
20 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
| 24417 |
govind |
21 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
|
|
22 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
23 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 24383 |
amit.gupta |
24 |
|
|
|
25 |
@Component
|
|
|
26 |
public class CsServiceImpl implements CsService {
|
| 24417 |
govind |
27 |
|
| 24383 |
amit.gupta |
28 |
@Autowired
|
|
|
29 |
TicketRepository ticketRepository;
|
| 24417 |
govind |
30 |
|
| 24383 |
amit.gupta |
31 |
@Autowired
|
|
|
32 |
TicketCategoryRepository ticketCategoryRepository;
|
| 24417 |
govind |
33 |
|
| 24383 |
amit.gupta |
34 |
@Autowired
|
|
|
35 |
TicketSubCategoryRepository ticketSubCategoryRepository;
|
| 24417 |
govind |
36 |
|
|
|
37 |
@Autowired
|
| 24388 |
amit.gupta |
38 |
ActivityRepository activityRepository;
|
| 24417 |
govind |
39 |
|
|
|
40 |
@Autowired
|
|
|
41 |
PartnerRegionRepository partnerRepository;
|
|
|
42 |
|
|
|
43 |
@Autowired
|
|
|
44 |
private PositionRepository positionRepository;
|
|
|
45 |
|
|
|
46 |
@Autowired
|
|
|
47 |
private AuthRepository authRepository;
|
|
|
48 |
|
|
|
49 |
@Autowired
|
|
|
50 |
private RetailerService retailerService;
|
|
|
51 |
|
| 24383 |
amit.gupta |
52 |
@Override
|
| 24417 |
govind |
53 |
public void createTicket(int fofoId, int categoryId, int subcategoryId, String message) {
|
|
|
54 |
|
| 24383 |
amit.gupta |
55 |
ActivityType type = ActivityType.OPENED;
|
| 24417 |
govind |
56 |
EscalationType escalationType = EscalationType.L1;
|
| 24383 |
amit.gupta |
57 |
Ticket ticket = new Ticket();
|
|
|
58 |
ticket.setSubCategoryId(subcategoryId);
|
| 24417 |
govind |
59 |
ticket.setFofoId(fofoId);
|
| 24383 |
amit.gupta |
60 |
ticket.setCreateTimestamp(LocalDateTime.now());
|
| 24417 |
govind |
61 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
| 24383 |
amit.gupta |
62 |
try {
|
| 24417 |
govind |
63 |
ticket.setAssigneeId(this.getAssigneeId(categoryId, escalationType));
|
| 24383 |
amit.gupta |
64 |
} catch (Exception e) {
|
|
|
65 |
e.printStackTrace();
|
|
|
66 |
}
|
|
|
67 |
ticketRepository.persist(ticket);
|
|
|
68 |
Activity activity = this.createActivity(type, message, 0);
|
|
|
69 |
this.addActivity(ticket.getId(), activity);
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
private Activity createActivity(ActivityType activityType, String message, int createdBy) {
|
|
|
73 |
Activity activity = new Activity();
|
|
|
74 |
activity.setMessage(message);
|
|
|
75 |
activity.setCreatedBy(createdBy);
|
|
|
76 |
activity.setType(activityType);
|
| 24417 |
govind |
77 |
activity.setCreateTimestamp(LocalDateTime.now());
|
| 24383 |
amit.gupta |
78 |
return activity;
|
|
|
79 |
}
|
| 24417 |
govind |
80 |
|
|
|
81 |
private int getAssigneeId(int categoryId, EscalationType escalationType) throws ProfitMandiBusinessException {
|
|
|
82 |
|
|
|
83 |
Position position = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType);
|
|
|
84 |
return position.getAuthUserId();
|
|
|
85 |
/*
|
|
|
86 |
* if(ActivityType.escalationTypes.contains(escalationType)) {
|
|
|
87 |
* //escalationMatrix } else { throw new
|
|
|
88 |
* ProfitMandiBusinessException("SubCategory", subcategoryId,
|
|
|
89 |
* "Could not find Assignee for "); }
|
|
|
90 |
*/
|
| 24383 |
amit.gupta |
91 |
}
|
|
|
92 |
|
|
|
93 |
@Override
|
|
|
94 |
public void addActivity(int ticketId, Activity activity) {
|
|
|
95 |
activity.setTicketId(ticketId);
|
| 24417 |
govind |
96 |
activityRepository.persist(activity);
|
| 24383 |
amit.gupta |
97 |
}
|
|
|
98 |
|
| 24417 |
govind |
99 |
@Override
|
|
|
100 |
public void addPartnerToRegion(int regionId, List<Integer> fofoIds) {
|
|
|
101 |
|
|
|
102 |
for (Integer fofoId : fofoIds) {
|
|
|
103 |
PartnerRegion partnerRegion = partnerRepository.selectByRegionIdAndFofoId(regionId, fofoId);
|
|
|
104 |
if (partnerRegion == null) {
|
|
|
105 |
partnerRegion = new PartnerRegion();
|
|
|
106 |
partnerRegion.setFofoId(fofoId);
|
|
|
107 |
partnerRegion.setRegionId(regionId);
|
|
|
108 |
partnerRepository.persist(partnerRegion);
|
|
|
109 |
} else {
|
|
|
110 |
continue;
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
@Override
|
|
|
116 |
public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMap(List<Ticket> tickets) {
|
|
|
117 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
|
|
118 |
for (Ticket ticket : tickets) {
|
|
|
119 |
AuthUser authUser = authRepository.selectById(ticket.getAssigneeId());
|
|
|
120 |
authUserIdAndAuthUserMap.put(ticket.getAssigneeId(), authUser);
|
|
|
121 |
}
|
|
|
122 |
return authUserIdAndAuthUserMap;
|
|
|
123 |
}
|
|
|
124 |
|
|
|
125 |
@Override
|
|
|
126 |
public Map<Integer, TicketSubCategory> getSubCategoryIdAndSubCategoryMap(List<Ticket> tickets) {
|
|
|
127 |
Map<Integer, TicketSubCategory> subCategoryIdAndSubCategoryMap = new HashMap<>();
|
|
|
128 |
for (Ticket ticket : tickets) {
|
|
|
129 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
|
|
130 |
subCategoryIdAndSubCategoryMap.put(ticket.getSubCategoryId(), ticketSubCategory);
|
|
|
131 |
}
|
|
|
132 |
return subCategoryIdAndSubCategoryMap;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
@Override
|
|
|
136 |
public Map<Integer, CustomRetailer> getPartnerByFofoIds(List<Ticket> tickets) {
|
|
|
137 |
List<Integer> fofoIds = new ArrayList<>();
|
|
|
138 |
for (Ticket ticket : tickets) {
|
|
|
139 |
fofoIds.add(ticket.getFofoId());
|
|
|
140 |
}
|
|
|
141 |
Map<Integer, CustomRetailer> fofoIdsAndCustomRetailer = retailerService.getFofoRetailers(fofoIds);
|
|
|
142 |
|
|
|
143 |
return fofoIdsAndCustomRetailer;
|
|
|
144 |
}
|
|
|
145 |
|
| 24383 |
amit.gupta |
146 |
}
|