| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.dao.repository.cs;
|
1 |
package com.spice.profitmandi.dao.repository.cs;
|
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDateTime;
|
3 |
import java.time.LocalDateTime;
|
| 4 |
import java.util.ArrayList;
|
4 |
import java.util.ArrayList;
|
| - |
|
5 |
import java.util.Arrays;
|
| 5 |
import java.util.HashMap;
|
6 |
import java.util.HashMap;
|
| 6 |
import java.util.HashSet;
|
7 |
import java.util.HashSet;
|
| - |
|
8 |
import java.util.LinkedHashSet;
|
| 7 |
import java.util.List;
|
9 |
import java.util.List;
|
| 8 |
import java.util.Map;
|
10 |
import java.util.Map;
|
| - |
|
11 |
import java.util.OptionalInt;
|
| - |
|
12 |
import java.util.Random;
|
| 9 |
import java.util.Set;
|
13 |
import java.util.Set;
|
| - |
|
14 |
import java.util.function.IntPredicate;
|
| 10 |
import java.util.stream.Collectors;
|
15 |
import java.util.stream.Collectors;
|
| 11 |
|
16 |
|
| 12 |
import org.apache.commons.collections4.map.HashedMap;
|
17 |
import org.apache.commons.collections4.map.HashedMap;
|
| 13 |
import org.apache.commons.lang.RandomStringUtils;
|
18 |
import org.apache.commons.lang.RandomStringUtils;
|
| 14 |
import org.apache.logging.log4j.LogManager;
|
19 |
import org.apache.logging.log4j.LogManager;
|
| Line 33... |
Line 38... |
| 33 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
38 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
| 34 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
39 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
| 35 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
40 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 36 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
41 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 37 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
42 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 38 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
- |
|
| 39 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
- |
|
| 40 |
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
|
- |
|
| 41 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
- |
|
| 42 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
- |
|
| 43 |
import com.spice.profitmandi.service.user.RetailerService;
|
43 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 44 |
|
44 |
|
| 45 |
@Component
|
45 |
@Component
|
| 46 |
public class CsServiceImpl implements CsService {
|
46 |
public class CsServiceImpl implements CsService {
|
| 47 |
|
47 |
|
| - |
|
48 |
private static final int ALL_PARTNERS_REGION = 5;
|
| - |
|
49 |
|
| 48 |
private static final Logger LOGGER = LogManager.getLogger(CsServiceImpl.class);
|
50 |
private static final Logger LOGGER = LogManager.getLogger(CsServiceImpl.class);
|
| 49 |
|
51 |
|
| 50 |
private static final String ASSIGNED_TICKET = "Dear %s,You have assigned a ticket by %s with ticketId#%s.Regards\nSmartdukaan";
|
52 |
private static final String ASSIGNED_TICKET = "Dear %s, New ticket #%s created by %s has been assigned to you. Regards\nSmartdukaan";
|
| - |
|
53 |
private static final String ESCALATED_TICKET = "Dear %s, Ticket #%s created by %s has been escalated to you. Regards\nSmartdukaan";
|
| - |
|
54 |
private static final String CATEGORY_CHANGED_TICKET = "Dear team, Category of Ticket #%s created by %s has been changed to %s. Regards\nSmartdukaan";
|
| 51 |
private static final String ASSINMENT_SUBJECT = "Assignment Ticket";
|
55 |
private static final String ASSINMENT_SUBJECT = "Assignment Ticket";
|
| 52 |
|
56 |
|
| 53 |
@Autowired
|
57 |
@Autowired
|
| 54 |
TicketRepository ticketRepository;
|
58 |
TicketRepository ticketRepository;
|
| 55 |
|
59 |
|
| Line 87... |
Line 91... |
| 87 |
private PartnersPositionRepository partnersPositionRepository;
|
91 |
private PartnersPositionRepository partnersPositionRepository;
|
| 88 |
|
92 |
|
| 89 |
@Autowired
|
93 |
@Autowired
|
| 90 |
private FofoStoreRepository fofoStoreRepository;
|
94 |
private FofoStoreRepository fofoStoreRepository;
|
| 91 |
|
95 |
|
| 92 |
@Autowired
|
- |
|
| 93 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
- |
|
| 94 |
|
- |
|
| 95 |
@Autowired
|
- |
|
| 96 |
private LeadRepository leadRepository;
|
- |
|
| 97 |
|
- |
|
| 98 |
@Autowired
|
- |
|
| 99 |
private HygieneDataRepository hygieneDataRepository;
|
- |
|
| 100 |
|
- |
|
| 101 |
@Autowired
|
- |
|
| 102 |
private PartnerInvestmentService partnerInvestmentService;
|
- |
|
| 103 |
|
- |
|
| 104 |
@Autowired
|
- |
|
| 105 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
- |
|
| 106 |
|
- |
|
| 107 |
@Override
|
96 |
@Override
|
| 108 |
public void createTicket(int fofoId, int categoryId, int subcategoryId, String message)
|
97 |
public void createTicket(int fofoId, int categoryId, int subcategoryId, String message)
|
| 109 |
throws ProfitMandiBusinessException {
|
98 |
throws ProfitMandiBusinessException {
|
| 110 |
|
99 |
|
| 111 |
ActivityType type = ActivityType.OPENED;
|
100 |
ActivityType type = ActivityType.OPENED;
|
| 112 |
EscalationType escalationTypeL1 = EscalationType.L1;
|
- |
|
| 113 |
EscalationType escalationTypeL2 = EscalationType.L2;
|
- |
|
| 114 |
EscalationType escalationTypeL3 = EscalationType.L3;
|
- |
|
| 115 |
Ticket ticket = new Ticket();
|
101 |
Ticket ticket = new Ticket();
|
| 116 |
TicketAssigned ticketAssigned = new TicketAssigned();
|
- |
|
| 117 |
ticket.setSubCategoryId(subcategoryId);
|
102 |
ticket.setSubCategoryId(subcategoryId);
|
| 118 |
ticket.setFofoId(fofoId);
|
103 |
ticket.setFofoId(fofoId);
|
| 119 |
ticket.setCreateTimestamp(LocalDateTime.now());
|
104 |
ticket.setCreateTimestamp(LocalDateTime.now());
|
| 120 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
105 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
| 121 |
ticket.setL2EscalationTimestamp(ticket.getUpdateTimestamp().plusDays(2));
|
- |
|
| 122 |
ticket.setL3EscalationTimestamp(ticket.getL2EscalationTimestamp().plusDays(2));
|
- |
|
| 123 |
ticket.setLastEscalationTimestamp(ticket.getL3EscalationTimestamp().plusDays(2));
|
- |
|
| 124 |
ticket.setHappyCode(getRandomString());
|
106 |
ticket.setHappyCode(getRandomString());
|
| - |
|
107 |
ticketRepository.persist(ticket);
|
| 125 |
int l1Auth = this.getAuthUserId(categoryId, escalationTypeL1, fofoId);
|
108 |
this.addActivity(ticket, this.createActivity(type, message, 0));
|
| 126 |
LOGGER.info("l1Auth" + l1Auth);
|
109 |
this.assignTicket(ticket);
|
| - |
|
110 |
|
| - |
|
111 |
}
|
| - |
|
112 |
|
| - |
|
113 |
@Override
|
| 127 |
int l2Auth = this.getAuthUserId(categoryId, escalationTypeL2, fofoId);
|
114 |
public void assignTicket(Ticket ticket) throws ProfitMandiBusinessException {
|
| 128 |
LOGGER.info("l2Auth" + l2Auth);
|
115 |
TicketAssigned ticketAssigned = null;
|
| - |
|
116 |
EscalationType newEscalationType = EscalationType.L1;
|
| - |
|
117 |
try {
|
| - |
|
118 |
ticketAssigned = ticketAssignedRepository.selectById(ticket.getAssignmentId());
|
| 129 |
int l3Auth = this.getAuthUserId(categoryId, escalationTypeL3, fofoId);
|
119 |
newEscalationType = ticketAssigned.getEscalationType().next();
|
| - |
|
120 |
if (newEscalationType == null) {
|
| 130 |
LOGGER.info("l3Auth" + l3Auth);
|
121 |
LOGGER.info("Cant escalate further");
|
| 131 |
if (l1Auth == 0) {
|
122 |
return;
|
| - |
|
123 |
}
|
| 132 |
if (l2Auth == 0) {
|
124 |
} catch (Exception e) {
|
| - |
|
125 |
}
|
| - |
|
126 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
| - |
|
127 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.selectById(ticket.getSubCategoryId());
|
| - |
|
128 |
TicketCategory ticketCategory = ticketCategoryRepository.selectById(ticketSubCategory.getCategoryId());
|
| - |
|
129 |
Map<Integer, EscalationType> escalationUserMap = new HashedMap<>();
|
| 133 |
this.setAssignment(ticket, ticketAssigned);
|
130 |
Set<Integer> assigneeUserIds = new LinkedHashSet<>();
|
| - |
|
131 |
EscalationType escalationTypeNext = newEscalationType;
|
| 134 |
} else {
|
132 |
do {
|
| - |
|
133 |
int assigneeUserId = this.getAuthUserId(ticketCategory.getId(), escalationTypeNext, ticket.getFofoId());
|
| 135 |
ticketAssigned.setAssineeId(l2Auth);
|
134 |
if (assigneeUserId == 0) {
|
| 136 |
ticket.setL1AuthUser(l2Auth);
|
135 |
escalationTypeNext = escalationTypeNext.next();
|
| - |
|
136 |
LOGGER.info("Escalation type next {}", escalationTypeNext);
|
| 137 |
ticket.setL2AuthUser(l2Auth);
|
137 |
continue;
|
| 138 |
}
|
138 |
}
|
| - |
|
139 |
assigneeUserIds.add(assigneeUserId);
|
| - |
|
140 |
escalationUserMap.put(assigneeUserId, escalationTypeNext);
|
| - |
|
141 |
switch (escalationTypeNext) {
|
| - |
|
142 |
case L1:
|
| - |
|
143 |
ticket.setL1AuthUser(assigneeUserId);
|
| - |
|
144 |
break;
|
| - |
|
145 |
case L2:
|
| - |
|
146 |
ticket.setL2AuthUser(assigneeUserId);
|
| - |
|
147 |
break;
|
| - |
|
148 |
case L3:
|
| - |
|
149 |
ticket.setL3AuthUser(assigneeUserId);
|
| - |
|
150 |
break;
|
| - |
|
151 |
case L4:
|
| - |
|
152 |
ticket.setL4AuthUser(assigneeUserId);
|
| - |
|
153 |
break;
|
| - |
|
154 |
case L5:
|
| - |
|
155 |
ticket.setL5AuthUser(assigneeUserId);
|
| - |
|
156 |
break;
|
| - |
|
157 |
|
| - |
|
158 |
default:
|
| - |
|
159 |
break;
|
| - |
|
160 |
}
|
| - |
|
161 |
escalationTypeNext = escalationTypeNext.next();
|
| - |
|
162 |
// LOGGER.info("Escalation type next {}", escalationTypeNext);
|
| - |
|
163 |
} while (!escalationTypeNext.equals(EscalationType.Final));
|
| - |
|
164 |
|
| - |
|
165 |
int assigneeAuthId = assigneeUserIds.stream().findFirst().orElse(0);
|
| - |
|
166 |
int managerAuthId = 0;
|
| - |
|
167 |
EscalationType assigneeEscalationType = null;
|
| - |
|
168 |
if (assigneeAuthId == 0) {
|
| - |
|
169 |
assigneeAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
| - |
|
170 |
assigneeEscalationType = EscalationType.Final;
|
| 139 |
} else {
|
171 |
} else {
|
| 140 |
ticketAssigned.setAssineeId(l1Auth);
|
172 |
assigneeEscalationType = escalationUserMap.get(assigneeAuthId);
|
| - |
|
173 |
managerAuthId = assigneeUserIds.stream().skip(1).findFirst().orElse(0);
|
| 141 |
ticket.setL1AuthUser(l1Auth);
|
174 |
if (managerAuthId == 0) {
|
| 142 |
ticket.setL2AuthUser(l2Auth);
|
175 |
managerAuthId = ProfitMandiConstants.FINAL_AUTH_ID;
|
| - |
|
176 |
}
|
| 143 |
}
|
177 |
}
|
| - |
|
178 |
|
| - |
|
179 |
TicketAssigned ticketAssignedNew = new TicketAssigned();
|
| - |
|
180 |
ticketAssignedNew.setTicketId(ticket.getId());
|
| - |
|
181 |
ticketAssignedNew.setAssineeId(assigneeAuthId);
|
| - |
|
182 |
ticketAssignedNew.setEscalationType(assigneeEscalationType);
|
| - |
|
183 |
if (!assigneeEscalationType.equals(EscalationType.Final)) {
|
| - |
|
184 |
ticketAssignedNew.setManagerId(managerAuthId);
|
| - |
|
185 |
}
|
| - |
|
186 |
ticketAssignedNew.setCreateTimestamp(LocalDateTime.now());
|
| - |
|
187 |
ticketAssignedRepository.persist(ticketAssignedNew);
|
| - |
|
188 |
LOGGER.info(ticketAssigned);
|
| - |
|
189 |
AuthUser authUser = authRepository.selectById(ticketAssignedNew.getAssineeId());
|
| - |
|
190 |
AuthUser authUserManager = null;
|
| 144 |
if (ticket.getL2AuthUser() == 0) {
|
191 |
if (managerAuthId > 0) {
|
| - |
|
192 |
authUserManager = authRepository.selectById(managerAuthId);
|
| - |
|
193 |
}
|
| - |
|
194 |
ticket.setAssignmentId(ticketAssignedNew.getId());
|
| - |
|
195 |
this.sendAssignedTicketMail(authUser, Arrays.asList(authUserManager), ticket, ticketAssigned!=null);
|
| - |
|
196 |
if (!ticketAssignedNew.getEscalationType().equals(EscalationType.L1)) {
|
| - |
|
197 |
this.addActivity(ticket, this.createActivity(ActivityType.ESCALATED,
|
| - |
|
198 |
"Ticket ecalated and assigned to " + authUser.getName(), 0));
|
| - |
|
199 |
} else {
|
| 145 |
ticket.setL2AuthUser(l3Auth);
|
200 |
this.addActivity(ticket,
|
| - |
|
201 |
this.createActivity(ActivityType.ASSIGNED, "Ticket assigned to " + authUser.getName(), 0));
|
| 146 |
}
|
202 |
}
|
| - |
|
203 |
}
|
| - |
|
204 |
|
| 147 |
ticket.setL3AuthUser(l3Auth);
|
205 |
@Override
|
| - |
|
206 |
public void updateTicket(int categoryId, int subCategoryId, Ticket ticket) throws ProfitMandiBusinessException {
|
| - |
|
207 |
|
| - |
|
208 |
TicketSubCategory ticketSubCategory = ticketSubCategoryRepository.getTicketSubCategoryMap().get(subCategoryId);
|
| 148 |
ticketRepository.persist(ticket);
|
209 |
TicketCategory ticketCategory = ticketSubCategory.getTicketCategory();
|
| - |
|
210 |
String storeName = retailerService.getFofoRetailers(true).get(ticket.getFofoId()).getBusinessName();
|
| - |
|
211 |
List<TicketAssigned> oldTicketAssignedList = ticketAssignedRepository.selectByTicketIds(Arrays.asList(ticket.getId()));
|
| 149 |
ticketAssigned.setTicketId(ticket.getId());
|
212 |
for(TicketAssigned oldTicketAssigned : oldTicketAssignedList) {
|
| 150 |
ticketAssignedRepository.persist(ticketAssigned);
|
213 |
ticketAssignedRepository.delete(oldTicketAssigned);
|
| - |
|
214 |
}
|
| - |
|
215 |
|
| 151 |
AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
|
216 |
if (subCategoryId != ticketSubCategory.getId() || categoryId != ticketCategory.getId()) {
|
| - |
|
217 |
ticket.setSubCategoryId(subCategoryId);
|
| - |
|
218 |
List<Integer> oldAssignedAuthUserIds = oldTicketAssignedList.stream().map(x->x.getAssineeId()).collect(Collectors.toList());
|
| - |
|
219 |
List<String> oldAssignedEmailIds = authRepository.selectAllAuthUserByIds(oldAssignedAuthUserIds).stream().map(x->x.getEmailId()).collect(Collectors.toList());
|
| 152 |
this.sendAssignedTicketMail(authUser, ticket);
|
220 |
String mailTo = oldAssignedEmailIds.remove(0);
|
| - |
|
221 |
String message = String.format(CATEGORY_CHANGED_TICKET, ticket.getId(),storeName, ticketSubCategory.getTicketCategory().getName() + " - " + ticketSubCategory.getName());
|
| - |
|
222 |
try {
|
| - |
|
223 |
Utils.sendMailWithAttachments(mailSender, mailTo, oldAssignedEmailIds.toArray(new String[0]), "Ticket Category/Subcategory Changed",
|
| - |
|
224 |
message, null);
|
| - |
|
225 |
} catch (Exception e) {
|
| - |
|
226 |
LOGGER.info("Could not send mail for ticket {}", ticket.toString());
|
| - |
|
227 |
}
|
| - |
|
228 |
}
|
| - |
|
229 |
|
| - |
|
230 |
|
| 153 |
Activity activity = this.createActivity(type, message, 0);
|
231 |
Activity categoryChangedActivity = this.createActivity(ActivityType.CATEGORY_CHANGED, "Category changed to "
|
| - |
|
232 |
+ ticketSubCategory.getTicketCategory().getName() + " - " + ticketSubCategory.getName(), 0);
|
| 154 |
this.addActivity(ticket.getId(), activity);
|
233 |
this.addActivity(ticket, categoryChangedActivity);
|
| - |
|
234 |
this.assignTicket(ticket);
|
| - |
|
235 |
|
| 155 |
}
|
236 |
}
|
| 156 |
|
237 |
|
| 157 |
private Activity createActivity(ActivityType activityType, String message, int createdBy) {
|
238 |
private Activity createActivity(ActivityType activityType, String message, int createdBy) {
|
| 158 |
Activity activity = new Activity();
|
239 |
Activity activity = new Activity();
|
| 159 |
activity.setMessage(message);
|
240 |
activity.setMessage(message);
|
| 160 |
activity.setCreatedBy(createdBy);
|
241 |
activity.setCreatedBy(createdBy);
|
| 161 |
activity.setType(activityType);
|
242 |
activity.setType(activityType);
|
| 162 |
activity.setCreateTimestamp(LocalDateTime.now());
|
243 |
activity.setCreateTimestamp(LocalDateTime.now());
|
| - |
|
244 |
activityRepository.persist(activity);
|
| 163 |
return activity;
|
245 |
return activity;
|
| 164 |
}
|
246 |
}
|
| 165 |
|
247 |
|
| 166 |
@Override
|
248 |
@Override
|
| 167 |
public int getAuthUserId(int categoryId, EscalationType escalationType, int fofoId) {
|
249 |
public int getAuthUserId(int categoryId, EscalationType escalationType, int fofoId) {
|
| 168 |
|
- |
|
| 169 |
List<Position> positions = null;
|
250 |
int authUserId = 0;
|
| 170 |
if (escalationType == EscalationType.L3) {
|
- |
|
| 171 |
positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(0, escalationType, 0);
|
251 |
List<Position> positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId,
|
| 172 |
} else {
|
252 |
escalationType);
|
| 173 |
List<PartnerRegion> regions = partnerRegionRepository.selectByfofoId(fofoId);
|
253 |
List<Integer> regionIds = partnerRegionRepository.selectByfofoId(fofoId).stream().map(x -> x.getRegionId())
|
| - |
|
254 |
.collect(Collectors.toList());
|
| 174 |
LOGGER.info("regions=" + regions);
|
255 |
// Add all Partner regions id
|
| - |
|
256 |
regionIds.add(ALL_PARTNERS_REGION);
|
| - |
|
257 |
LOGGER.info("Escalation Type {}, Region Ids {}", escalationType, regionIds);
|
| - |
|
258 |
List<Integer> partnerPositionsIds = partnersPositionRepository
|
| - |
|
259 |
.selectByRegionIdAndPartnerId(regionIds, Arrays.asList(0, fofoId)).stream().map(x -> x.getPositionId())
|
| - |
|
260 |
.collect(Collectors.toList());
|
| - |
|
261 |
positions = positions.stream().filter(x -> partnerPositionsIds.contains(x.getId()))
|
| - |
|
262 |
.collect(Collectors.toList());
|
| - |
|
263 |
LOGGER.info("User List List {}", positions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
| 175 |
if (regions.size() == 0) {
|
264 |
if (positions.size() > 0) {
|
| 176 |
regions = partnerRegionRepository.selectByfofoId(0);
|
265 |
List<AuthUser> authUsers = authRepository.selectAllAuthUserByIds(
|
| - |
|
266 |
positions.stream().map(x -> x.getAuthUserId()).collect(Collectors.toList()));
|
| - |
|
267 |
authUsers = authUsers.stream().filter(x -> x.isActive()).collect(Collectors.toList());
|
| - |
|
268 |
if (authUsers.size() > 0) {
|
| 177 |
LOGGER.info("regions=" + regions);
|
269 |
Random rand = new Random();
|
| - |
|
270 |
authUserId = authUsers.get(rand.nextInt(authUsers.size())).getId();
|
| 178 |
}
|
271 |
}
|
| 179 |
for (PartnerRegion region : regions) {
|
- |
|
| 180 |
LOGGER.info(categoryId + ":" + escalationType + ":" + region.getRegionId());
|
- |
|
| 181 |
positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId, escalationType,
|
- |
|
| 182 |
region.getRegionId());
|
- |
|
| 183 |
LOGGER.info("positions:-" + positions);
|
- |
|
| 184 |
if (positions.size() > 0) {
|
- |
|
| 185 |
break;
|
- |
|
| 186 |
}
|
- |
|
| 187 |
|
- |
|
| 188 |
}
|
- |
|
| 189 |
if (positions.size() == 0) {
|
- |
|
| 190 |
if (escalationType == EscalationType.L1) {
|
- |
|
| 191 |
regions = partnerRegionRepository.selectByfofoId(0);
|
- |
|
| 192 |
LOGGER.info("regions=" + regions);
|
- |
|
| 193 |
for (PartnerRegion region : regions) {
|
- |
|
| 194 |
positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId,
|
- |
|
| 195 |
escalationType, region.getRegionId());
|
- |
|
| 196 |
LOGGER.info("positions:-" + positions);
|
- |
|
| 197 |
if (positions.size() > 0) {
|
- |
|
| 198 |
break;
|
- |
|
| 199 |
}
|
- |
|
| 200 |
}
|
- |
|
| 201 |
} else {
|
- |
|
| 202 |
regions = partnerRegionRepository.selectByfofoId(0);
|
- |
|
| 203 |
LOGGER.info("regions=" + regions);
|
- |
|
| 204 |
for (PartnerRegion region : regions) {
|
- |
|
| 205 |
positions = positionRepository.selectPositionbyCategoryIdAndEscalationType(categoryId,
|
- |
|
| 206 |
escalationType, region.getRegionId());
|
- |
|
| 207 |
LOGGER.info("positions:-" + positions);
|
- |
|
| 208 |
if (positions.size() > 0) {
|
- |
|
| 209 |
break;
|
- |
|
| 210 |
}
|
- |
|
| 211 |
}
|
- |
|
| 212 |
}
|
- |
|
| 213 |
}
|
- |
|
| 214 |
|
- |
|
| 215 |
}
|
- |
|
| 216 |
if (positions.size() == 0) {
|
- |
|
| 217 |
return 0;
|
- |
|
| 218 |
}
|
272 |
}
|
| 219 |
LOGGER.info(positions.get(0).getAuthUserId());
|
- |
|
| 220 |
return positions.get(0).getAuthUserId();
|
273 |
return authUserId;
|
| 221 |
/*
|
- |
|
| 222 |
* if(ActivityType.escalationTypes.contains(escalationType)) {
|
- |
|
| 223 |
* //escalationMatrix } else { throw new
|
- |
|
| 224 |
* ProfitMandiBusinessException("SubCategory", subcategoryId,
|
- |
|
| 225 |
* "Could not find Assignee for "); }
|
- |
|
| 226 |
*/
|
- |
|
| 227 |
|
274 |
|
| 228 |
}
|
275 |
}
|
| 229 |
|
276 |
|
| 230 |
@Override
|
277 |
@Override
|
| 231 |
public void addActivity(int ticketId, Activity activity) {
|
278 |
public void addActivity(Ticket ticket, Activity activity) {
|
| 232 |
activity.setTicketId(ticketId);
|
279 |
activity.setTicketId(ticket.getId());
|
| - |
|
280 |
ticket.setLastActivity(activity.getType());
|
| 233 |
activityRepository.persist(activity);
|
281 |
ticket.setLastActivityId(activity.getId());
|
| 234 |
}
|
282 |
}
|
| 235 |
|
283 |
|
| 236 |
private String getRandomString() {
|
284 |
private String getRandomString() {
|
| 237 |
int length = 4;
|
285 |
int length = 4;
|
| 238 |
boolean useLetters = false;
|
286 |
boolean useLetters = false;
|
| Line 304... |
Line 352... |
| 304 |
public List<TicketCategory> getAllTicketCategotyFromSubCategory() {
|
352 |
public List<TicketCategory> getAllTicketCategotyFromSubCategory() {
|
| 305 |
|
353 |
|
| 306 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll();
|
354 |
List<TicketSubCategory> ticketSubCategories = ticketSubCategoryRepository.selectAll();
|
| 307 |
HashSet<Integer> categoryIds = new HashSet<>();
|
355 |
HashSet<Integer> categoryIds = new HashSet<>();
|
| 308 |
for (TicketSubCategory ticketSubcategory : ticketSubCategories) {
|
356 |
for (TicketSubCategory ticketSubcategory : ticketSubCategories) {
|
| 309 |
categoryIds.add(ticketSubcategory.getcategoryId());
|
357 |
categoryIds.add(ticketSubcategory.getCategoryId());
|
| 310 |
}
|
358 |
}
|
| 311 |
List<TicketCategory> ticketcategories = ticketCategoryRepository.selectAll(new ArrayList<>(categoryIds));
|
359 |
List<TicketCategory> ticketcategories = ticketCategoryRepository.selectAll(new ArrayList<>(categoryIds));
|
| 312 |
return ticketcategories;
|
360 |
return ticketcategories;
|
| 313 |
}
|
361 |
}
|
| 314 |
|
362 |
|
| 315 |
private Ticket setAssignment(Ticket ticket, TicketAssigned ticketAssigned) {
|
- |
|
| 316 |
TicketCategory ticketCategory = ticketCategoryRepository.selectByName(ProfitMandiConstants.CRM);
|
- |
|
| 317 |
List<Position> positions = positionRepository.selectPositionByCategoryId(ticketCategory.getId());
|
- |
|
| 318 |
for (Position position : positions) {
|
- |
|
| 319 |
if (position.getEscalationType().equals(EscalationType.L1)) {
|
- |
|
| 320 |
ticketAssigned.setAssineeId(position.getAuthUserId());
|
- |
|
| 321 |
ticket.setL1AuthUser(position.getAuthUserId());
|
- |
|
| 322 |
} else if (position.getEscalationType().equals(EscalationType.L2)) {
|
- |
|
| 323 |
ticket.setL2AuthUser(position.getAuthUserId());
|
- |
|
| 324 |
}
|
- |
|
| 325 |
}
|
- |
|
| 326 |
return ticket;
|
- |
|
| 327 |
}
|
- |
|
| 328 |
|
- |
|
| 329 |
@Override
|
363 |
@Override
|
| 330 |
public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMapUsingPositions(List<Position> positions) {
|
364 |
public Map<Integer, AuthUser> getAuthUserIdAndAuthUserMapUsingPositions(List<Position> positions) {
|
| 331 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
365 |
Map<Integer, AuthUser> authUserIdAndAuthUserMap = new HashMap<>();
|
| 332 |
for (Position position : positions) {
|
366 |
for (Position position : positions) {
|
| 333 |
AuthUser authUser = authRepository.selectById(position.getAuthUserId());
|
367 |
AuthUser authUser = authRepository.selectById(position.getAuthUserId());
|
| Line 405... |
Line 439... |
| 405 |
}
|
439 |
}
|
| 406 |
}
|
440 |
}
|
| 407 |
return authUserListMap;
|
441 |
return authUserListMap;
|
| 408 |
}
|
442 |
}
|
| 409 |
|
443 |
|
| 410 |
@Override
|
- |
|
| 411 |
public void updateTicket(int categoryId, int subCategoryId, Ticket ticket) throws ProfitMandiBusinessException {
|
444 |
private void sendAssignedTicketMail(AuthUser authUserTo, List<AuthUser> authUsersCc, Ticket ticket, boolean isEscalated)
|
| 412 |
TicketAssigned ticketAssigned = new TicketAssigned();
|
445 |
throws ProfitMandiBusinessException {
|
| 413 |
ticket.setSubCategoryId(subCategoryId);
|
446 |
try {
|
| 414 |
ticket.setUpdateTimestamp(LocalDateTime.now());
|
- |
|
| 415 |
ticket.setL2EscalationTimestamp(ticket.getUpdateTimestamp().plusDays(2));
|
- |
|
| 416 |
ticket.setL3EscalationTimestamp(ticket.getL2EscalationTimestamp().plusDays(2));
|
- |
|
| 417 |
ticket.setLastEscalationTimestamp(ticket.getL3EscalationTimestamp().plusDays(2));
|
- |
|
| 418 |
int l3Auth = this.getAuthUserId(categoryId, EscalationType.L3, ticket.getFofoId());
|
- |
|
| 419 |
int l2Auth = this.getAuthUserId(categoryId, EscalationType.L2, ticket.getFofoId());
|
447 |
String[] ccTo = authUsersCc.stream().filter(x -> x != null).map(x -> x.getEmailId()).toArray(String[]::new);
|
| 420 |
int l1Auth = this.getAuthUserId(categoryId, EscalationType.L1, ticket.getFofoId());
|
- |
|
| 421 |
LOGGER.info(l1Auth + "-" + l2Auth + "-" + l3Auth);
|
- |
|
| - |
|
448 |
|
| 422 |
if (l1Auth == 0) {
|
449 |
String messageFormat = null;
|
| 423 |
if (l2Auth == 0) {
|
450 |
if(isEscalated) {
|
| 424 |
this.setAssignment(ticket, ticketAssigned);
|
451 |
messageFormat = ESCALATED_TICKET;
|
| 425 |
} else {
|
452 |
} else {
|
| 426 |
ticketAssigned.setAssineeId(l2Auth);
|
453 |
messageFormat = ASSIGNED_TICKET;
|
| 427 |
ticket.setL1AuthUser(0);
|
- |
|
| 428 |
ticket.setL2AuthUser(l2Auth);
|
- |
|
| 429 |
}
|
454 |
}
|
| 430 |
} else {
|
- |
|
| 431 |
ticketAssigned.setAssineeId(l1Auth);
|
- |
|
| 432 |
ticket.setL1AuthUser(l1Auth);
|
- |
|
| 433 |
ticket.setL2AuthUser(l2Auth);
|
- |
|
| 434 |
}
|
- |
|
| 435 |
ticket.setL3AuthUser(l3Auth);
|
- |
|
| 436 |
ticketRepository.persist(ticket);
|
- |
|
| 437 |
ticketAssigned.setTicketId(ticket.getId());
|
455 |
String message = String.format(messageFormat, authUserTo.getName(), ticket.getId(),
|
| 438 |
ticketAssignedRepository.persist(ticketAssigned);
|
- |
|
| 439 |
AuthUser authUser = authRepository.selectById(ticketAssigned.getAssineeId());
|
456 |
retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName());
|
| 440 |
this.sendAssignedTicketMail(authUser, ticket);
|
- |
|
| 441 |
}
|
- |
|
| 442 |
|
- |
|
| 443 |
@Override
|
- |
|
| 444 |
public void sendAssignedTicketMail(AuthUser authUser, Ticket ticket) throws ProfitMandiBusinessException {
|
- |
|
| 445 |
try {
|
- |
|
| 446 |
Utils.sendMailWithAttachments(mailSender, authUser.getEmailId(), null, ASSINMENT_SUBJECT,
|
457 |
Utils.sendMailWithAttachments(mailSender, authUserTo.getEmailId(), ccTo, ASSINMENT_SUBJECT,
|
| 447 |
String.format(ASSIGNED_TICKET, authUser.getFirstName(),
|
- |
|
| 448 |
retailerService.getFofoRetailer(ticket.getFofoId()).getBusinessName(), ticket.getId()),
|
- |
|
| 449 |
null);
|
458 |
message, null);
|
| 450 |
} catch (Exception e) {
|
459 |
} catch (Exception e) {
|
| - |
|
460 |
e.printStackTrace();
|
| 451 |
throw new ProfitMandiBusinessException("Ticket Assingment", authUser.getEmailId(),
|
461 |
throw new ProfitMandiBusinessException("Ticket Assingment", authUserTo.getEmailId(),
|
| 452 |
"Could not send ticket assignment mail");
|
462 |
"Could not send ticket assignment mail");
|
| 453 |
}
|
463 |
}
|
| 454 |
}
|
464 |
}
|
| 455 |
|
465 |
|
| 456 |
@Override
|
466 |
@Override
|