| 3137 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.serving.controllers;
|
|
|
5 |
|
| 3339 |
mandeep.dh |
6 |
import in.shop2020.crm.Activity;
|
|
|
7 |
import in.shop2020.crm.ActivityType;
|
| 3137 |
mandeep.dh |
8 |
import in.shop2020.crm.Agent;
|
| 3390 |
mandeep.dh |
9 |
import in.shop2020.crm.SearchFilter;
|
| 3137 |
mandeep.dh |
10 |
import in.shop2020.crm.Ticket;
|
| 3339 |
mandeep.dh |
11 |
import in.shop2020.crm.TicketCategory;
|
|
|
12 |
import in.shop2020.crm.TicketPriority;
|
| 3137 |
mandeep.dh |
13 |
import in.shop2020.crm.TicketStatus;
|
| 3546 |
mandeep.dh |
14 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
15 |
import in.shop2020.model.v1.order.Order;
|
|
|
16 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
17 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 3137 |
mandeep.dh |
18 |
import in.shop2020.model.v1.user.User;
|
|
|
19 |
import in.shop2020.model.v1.user.UserContextException;
|
| 3578 |
mandeep.dh |
20 |
import in.shop2020.payments.Payment;
|
|
|
21 |
import in.shop2020.payments.PaymentException;
|
|
|
22 |
import in.shop2020.payments.PaymentStatus;
|
| 3390 |
mandeep.dh |
23 |
import in.shop2020.serving.auth.CRMAuthorizingRealm;
|
|
|
24 |
import in.shop2020.thrift.clients.CRMClient;
|
| 3405 |
mandeep.dh |
25 |
import in.shop2020.thrift.clients.HelperClient;
|
| 3578 |
mandeep.dh |
26 |
import in.shop2020.thrift.clients.PaymentClient;
|
| 3546 |
mandeep.dh |
27 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 3390 |
mandeep.dh |
28 |
import in.shop2020.thrift.clients.UserClient;
|
| 3405 |
mandeep.dh |
29 |
import in.shop2020.util.CRMConstants;
|
| 4020 |
mandeep.dh |
30 |
import in.shop2020.util.CRMConstants.EscalationMatrix;
|
| 4241 |
anupam.sin |
31 |
import in.shop2020.util.CRMConstants.CODCancelMatrix;
|
| 3405 |
mandeep.dh |
32 |
import in.shop2020.utils.HelperService.Client;
|
|
|
33 |
import in.shop2020.utils.HelperServiceException;
|
| 3546 |
mandeep.dh |
34 |
import in.shop2020.utils.ModelUtils;
|
| 3137 |
mandeep.dh |
35 |
|
| 3397 |
mandeep.dh |
36 |
import java.text.ParseException;
|
| 3137 |
mandeep.dh |
37 |
import java.util.ArrayList;
|
| 3578 |
mandeep.dh |
38 |
import java.util.Calendar;
|
| 3390 |
mandeep.dh |
39 |
import java.util.Collections;
|
| 3405 |
mandeep.dh |
40 |
import java.util.Date;
|
| 3137 |
mandeep.dh |
41 |
import java.util.List;
|
|
|
42 |
|
| 3405 |
mandeep.dh |
43 |
import org.apache.shiro.SecurityUtils;
|
| 3137 |
mandeep.dh |
44 |
import org.apache.thrift.TException;
|
| 3546 |
mandeep.dh |
45 |
import org.apache.thrift.transport.TTransportException;
|
| 3137 |
mandeep.dh |
46 |
|
|
|
47 |
/**
|
|
|
48 |
* @author mandeep
|
|
|
49 |
*
|
|
|
50 |
*/
|
|
|
51 |
public class TicketsController extends BaseController {
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
*
|
|
|
55 |
*/
|
|
|
56 |
private static final long serialVersionUID = 1L;
|
|
|
57 |
|
|
|
58 |
List<Ticket> tickets = new ArrayList<Ticket>();
|
| 3405 |
mandeep.dh |
59 |
private String customerEmailId;
|
| 3339 |
mandeep.dh |
60 |
private String description;
|
|
|
61 |
private String assigneeEmailId;
|
|
|
62 |
private String priority;
|
|
|
63 |
private String category;
|
|
|
64 |
private String orderId;
|
| 3397 |
mandeep.dh |
65 |
private String[] agentIds;
|
|
|
66 |
private String startTimestamp;
|
|
|
67 |
private String endTimestamp;
|
| 3137 |
mandeep.dh |
68 |
|
| 3405 |
mandeep.dh |
69 |
private String userId;
|
|
|
70 |
private String id;
|
|
|
71 |
private String activityDescription;
|
|
|
72 |
private String status;
|
|
|
73 |
private String activityType;
|
|
|
74 |
private Ticket ticket;
|
|
|
75 |
private List<Activity> activities;
|
|
|
76 |
private String subject;
|
|
|
77 |
private String body;
|
|
|
78 |
private String customerName;
|
|
|
79 |
private String customerMobileNumber;
|
| 3546 |
mandeep.dh |
80 |
private User user;
|
|
|
81 |
private String orderStatus;
|
|
|
82 |
private List<Order> orders;
|
| 4020 |
mandeep.dh |
83 |
private String escalate;
|
| 4241 |
anupam.sin |
84 |
private String cancelReason;
|
| 3405 |
mandeep.dh |
85 |
|
|
|
86 |
public String index() {
|
|
|
87 |
try {
|
|
|
88 |
if (id != null && !id.isEmpty()) {
|
|
|
89 |
SearchFilter searchFilter = new SearchFilter();
|
|
|
90 |
crmServiceClient = new CRMClient().getClient();
|
|
|
91 |
searchFilter.setTicketId(Long.parseLong(id));
|
|
|
92 |
tickets = crmServiceClient.getTickets(searchFilter);
|
|
|
93 |
}
|
|
|
94 |
} catch (TException e) {
|
|
|
95 |
log.error("Error while getting tickets", e);
|
|
|
96 |
return EXCEPTION;
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
return INDEX;
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
public String edit() {
|
|
|
103 |
try {
|
|
|
104 |
long ticketId = Long.parseLong(id);
|
|
|
105 |
SearchFilter searchFilter = new SearchFilter();
|
|
|
106 |
searchFilter.setTicketId(ticketId);
|
|
|
107 |
crmServiceClient = new CRMClient().getClient();
|
|
|
108 |
ticket = crmServiceClient.getTickets(searchFilter).get(0);
|
|
|
109 |
activities = crmServiceClient.getActivities(searchFilter);
|
|
|
110 |
subject = createSubjectString(ticket);
|
|
|
111 |
|
|
|
112 |
if (ticket.isSetCustomerId()) {
|
|
|
113 |
userId = String.valueOf(ticket.getCustomerId());
|
| 3546 |
mandeep.dh |
114 |
userContextServiceClient = new UserClient().getClient();
|
|
|
115 |
|
|
|
116 |
try {
|
|
|
117 |
user = userContextServiceClient.getUserById(ticket
|
|
|
118 |
.getCustomerId());
|
|
|
119 |
} catch (UserContextException e) {
|
|
|
120 |
log.error("Could not fetch user details", e);
|
|
|
121 |
}
|
| 3405 |
mandeep.dh |
122 |
}
|
|
|
123 |
|
|
|
124 |
customerEmailId = ticket.getCustomerEmailId();
|
| 3546 |
mandeep.dh |
125 |
|
|
|
126 |
if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())) {
|
|
|
127 |
log.info("Fetching orders for " + ticket.getCustomerId());
|
|
|
128 |
orders = new ArrayList<Order>();
|
|
|
129 |
transactionServiceClient = new TransactionClient().getClient();
|
|
|
130 |
for (Order order : transactionServiceClient
|
|
|
131 |
.getOrdersForCustomer(ticket.getCustomerId(), 0, 0,
|
|
|
132 |
Collections.singletonList(OrderStatus.INIT))) {
|
|
|
133 |
log.info("Processing Order: " + order);
|
|
|
134 |
if (order.isCod()) {
|
|
|
135 |
orders.add(order);
|
|
|
136 |
}
|
|
|
137 |
}
|
|
|
138 |
}
|
| 3578 |
mandeep.dh |
139 |
|
|
|
140 |
if (TicketCategory.FAILED_PAYMENTS.equals(ticket.getCategory())) {
|
|
|
141 |
log.info("Fetching orders for " + ticket.getCustomerId());
|
|
|
142 |
orders = new ArrayList<Order>();
|
|
|
143 |
in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
|
|
|
144 |
|
|
|
145 |
long failedTransactionId = -1;
|
|
|
146 |
long lastfailedTransactionTimestamp = -1;
|
|
|
147 |
for (Payment payment : paymentClient.getPaymentsForUser(ticket.getCustomerId(), 0, getTomorrow().getTime(), PaymentStatus.FAILED, 0)) {
|
|
|
148 |
if (payment.getErrorTimestamp() > lastfailedTransactionTimestamp) {
|
|
|
149 |
failedTransactionId = payment.getMerchantTxnId();
|
|
|
150 |
}
|
|
|
151 |
}
|
|
|
152 |
|
|
|
153 |
transactionServiceClient = new TransactionClient().getClient();
|
|
|
154 |
orders.addAll(transactionServiceClient.getOrdersForTransaction(failedTransactionId, ticket.getCustomerId()));
|
|
|
155 |
}
|
| 4008 |
mandeep.dh |
156 |
|
|
|
157 |
if (TicketCategory.DELAYED_DELIVERY.equals(ticket.getCategory())) {
|
|
|
158 |
log.info("Fetching orders for " + ticket.getCustomerId());
|
|
|
159 |
orders = new ArrayList<Order>();
|
|
|
160 |
transactionServiceClient = new TransactionClient().getClient();
|
|
|
161 |
|
|
|
162 |
for (Order order : transactionServiceClient.getOrdersForCustomer(ticket.getCustomerId(), 0, 0, null)) {
|
|
|
163 |
if (order.getExpected_delivery_time() > order.getPromised_delivery_time() && order.getExpected_delivery_time() > new Date().getTime()) {
|
|
|
164 |
orders.add(order);
|
|
|
165 |
}
|
|
|
166 |
}
|
|
|
167 |
}
|
| 3405 |
mandeep.dh |
168 |
} catch (TException e) {
|
| 3546 |
mandeep.dh |
169 |
log.error("Error loading edit page", e);
|
|
|
170 |
} catch (NumberFormatException e) {
|
|
|
171 |
log.error("Error parsing orderId", e);
|
|
|
172 |
} catch (TransactionServiceException e) {
|
|
|
173 |
log.error("Error fetching orders for " + ticket.getCustomerId(), e);
|
| 3578 |
mandeep.dh |
174 |
} catch (PaymentException e) {
|
|
|
175 |
log.error("Error fetching payments for " + ticket.getCustomerId(), e);
|
| 3405 |
mandeep.dh |
176 |
}
|
|
|
177 |
|
|
|
178 |
return EDIT;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
private String createSubjectString(Ticket ticket) {
|
|
|
182 |
return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId()
|
|
|
183 |
+ " " + ticket.getCategory().name();
|
|
|
184 |
}
|
|
|
185 |
|
| 3578 |
mandeep.dh |
186 |
private Date getTomorrow() {
|
|
|
187 |
Calendar calendar = Calendar.getInstance();
|
|
|
188 |
calendar.setTime(new Date());
|
|
|
189 |
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
|
|
190 |
return calendar.getTime();
|
|
|
191 |
}
|
|
|
192 |
|
| 3339 |
mandeep.dh |
193 |
public String create() {
|
|
|
194 |
try {
|
| 3546 |
mandeep.dh |
195 |
long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
|
|
|
196 |
.getId();
|
| 3339 |
mandeep.dh |
197 |
Ticket ticket = new Ticket();
|
|
|
198 |
ticket.setDescription(description);
|
|
|
199 |
ticket.setCreatorId(creatorId);
|
|
|
200 |
ticket.setStatus(TicketStatus.OPEN);
|
|
|
201 |
ticket.setPriority(TicketPriority.valueOf(priority));
|
|
|
202 |
ticket.setCategory(TicketCategory.valueOf(category));
|
|
|
203 |
|
|
|
204 |
Activity activity = new Activity();
|
|
|
205 |
activity.setDescription("Creating Ticket");
|
|
|
206 |
activity.setType(ActivityType.OTHER);
|
|
|
207 |
activity.setTicketPriority(TicketPriority.valueOf(priority));
|
|
|
208 |
activity.setTicketStatus(TicketStatus.OPEN);
|
|
|
209 |
activity.setCreatorId(creatorId);
|
|
|
210 |
activity.setTicketCategory(TicketCategory.valueOf(category));
|
|
|
211 |
activity.setTicketDescription(description);
|
|
|
212 |
|
|
|
213 |
if (orderId != null && !orderId.isEmpty()) {
|
|
|
214 |
ticket.setOrderId(Long.parseLong(orderId));
|
|
|
215 |
}
|
|
|
216 |
|
| 3405 |
mandeep.dh |
217 |
if (userId != null && !userId.isEmpty()) {
|
|
|
218 |
ticket.setCustomerId(Long.parseLong(userId));
|
|
|
219 |
activity.setCustomerId(Long.parseLong(userId));
|
| 3546 |
mandeep.dh |
220 |
} else {
|
| 3390 |
mandeep.dh |
221 |
User user = null;
|
|
|
222 |
userContextServiceClient = new UserClient().getClient();
|
|
|
223 |
try {
|
| 3405 |
mandeep.dh |
224 |
if (customerName != null && !customerName.isEmpty()) {
|
|
|
225 |
ticket.setCustomerName(customerName);
|
|
|
226 |
activity.setCustomerName(customerName);
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
if (customerEmailId != null && !customerEmailId.isEmpty()) {
|
|
|
230 |
ticket.setCustomerEmailId(customerEmailId);
|
|
|
231 |
activity.setCustomerEmailId(customerEmailId);
|
| 3546 |
mandeep.dh |
232 |
user = userContextServiceClient
|
|
|
233 |
.getUserByEmail(customerEmailId);
|
| 3405 |
mandeep.dh |
234 |
}
|
|
|
235 |
|
| 3546 |
mandeep.dh |
236 |
if ((user == null || user.getUserId() == -1)
|
|
|
237 |
&& customerMobileNumber != null
|
|
|
238 |
&& !customerMobileNumber.isEmpty()) {
|
| 3405 |
mandeep.dh |
239 |
ticket.setCustomerMobileNumber(customerMobileNumber);
|
|
|
240 |
activity.setCustomerMobileNumber(customerMobileNumber);
|
| 3546 |
mandeep.dh |
241 |
user = userContextServiceClient
|
|
|
242 |
.getUserByMobileNumber(Long
|
|
|
243 |
.parseLong(customerMobileNumber));
|
| 3405 |
mandeep.dh |
244 |
}
|
| 3390 |
mandeep.dh |
245 |
} catch (UserContextException e) {
|
| 3546 |
mandeep.dh |
246 |
log.error("Could not fetch user for: " + customerEmailId
|
|
|
247 |
+ " " + customerMobileNumber + " " + customerName,
|
|
|
248 |
e);
|
| 3390 |
mandeep.dh |
249 |
}
|
| 3546 |
mandeep.dh |
250 |
|
| 3390 |
mandeep.dh |
251 |
if (user != null && user.getUserId() != -1) {
|
|
|
252 |
ticket.setCustomerId(user.getUserId());
|
|
|
253 |
activity.setCustomerId(user.getUserId());
|
|
|
254 |
}
|
| 3339 |
mandeep.dh |
255 |
}
|
|
|
256 |
|
|
|
257 |
// handling null values appropriately
|
|
|
258 |
if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
|
| 3546 |
mandeep.dh |
259 |
long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId)
|
|
|
260 |
.getId();
|
| 3339 |
mandeep.dh |
261 |
ticket.setAssigneeId(assigneeId);
|
|
|
262 |
activity.setTicketAssigneeId(assigneeId);
|
|
|
263 |
}
|
|
|
264 |
|
| 3546 |
mandeep.dh |
265 |
crmServiceClient = new CRMClient().getClient();
|
|
|
266 |
id = String
|
|
|
267 |
.valueOf(crmServiceClient.insertTicket(ticket, activity));
|
| 3339 |
mandeep.dh |
268 |
} catch (TException e) {
|
|
|
269 |
log.error("Error while creating ticket", e);
|
|
|
270 |
return EXCEPTION;
|
|
|
271 |
}
|
|
|
272 |
|
| 3405 |
mandeep.dh |
273 |
return index();
|
| 3339 |
mandeep.dh |
274 |
}
|
|
|
275 |
|
| 3405 |
mandeep.dh |
276 |
public boolean isAssigneeEditable() {
|
|
|
277 |
return SecurityUtils.getSubject().hasRole("TeamLead");
|
|
|
278 |
}
|
|
|
279 |
|
| 3397 |
mandeep.dh |
280 |
public String searchTickets() throws ParseException {
|
| 3137 |
mandeep.dh |
281 |
try {
|
| 3397 |
mandeep.dh |
282 |
SearchFilter searchFilter = new SearchFilter();
|
| 3405 |
mandeep.dh |
283 |
if (userId != null && !userId.isEmpty()) {
|
|
|
284 |
searchFilter.setCustomerId(Long.parseLong(userId));
|
|
|
285 |
}
|
|
|
286 |
|
| 3397 |
mandeep.dh |
287 |
if (agentIds != null && agentIds.length != 0) {
|
|
|
288 |
searchFilter.setTicketAssigneeIds(new ArrayList<Long>());
|
|
|
289 |
for (String agentId : agentIds) {
|
| 3546 |
mandeep.dh |
290 |
searchFilter.getTicketAssigneeIds().add(
|
|
|
291 |
CRMAuthorizingRealm.getAgent(agentId).getId());
|
| 3397 |
mandeep.dh |
292 |
}
|
|
|
293 |
}
|
| 3137 |
mandeep.dh |
294 |
|
| 3397 |
mandeep.dh |
295 |
if (startTimestamp != null && !startTimestamp.isEmpty()) {
|
| 3546 |
mandeep.dh |
296 |
searchFilter.setStartTimestamp(SDF.parse(startTimestamp)
|
|
|
297 |
.getTime());
|
| 3397 |
mandeep.dh |
298 |
}
|
|
|
299 |
|
|
|
300 |
if (endTimestamp != null && !endTimestamp.isEmpty()) {
|
|
|
301 |
searchFilter.setEndTimestamp(SDF.parse(endTimestamp).getTime());
|
|
|
302 |
}
|
|
|
303 |
|
| 3422 |
mandeep.dh |
304 |
if (id != null && !id.isEmpty()) {
|
|
|
305 |
searchFilter.setTicketId(Long.parseLong(id));
|
|
|
306 |
}
|
|
|
307 |
|
| 3499 |
mandeep.dh |
308 |
if (status != null && !status.isEmpty()) {
|
| 3972 |
mandeep.dh |
309 |
searchFilter.setTicketStatuses(new ArrayList<TicketStatus>());
|
|
|
310 |
searchFilter.getTicketStatuses().add(TicketStatus.valueOf(status));
|
|
|
311 |
if (TicketStatus.OPEN.name().equals(status)) {
|
|
|
312 |
searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
|
|
|
313 |
}
|
| 3499 |
mandeep.dh |
314 |
}
|
|
|
315 |
|
|
|
316 |
if (category != null && !category.isEmpty()) {
|
| 3546 |
mandeep.dh |
317 |
searchFilter
|
|
|
318 |
.setTicketCategory(TicketCategory.valueOf(category));
|
| 3499 |
mandeep.dh |
319 |
}
|
|
|
320 |
|
| 3546 |
mandeep.dh |
321 |
crmServiceClient = new CRMClient().getClient();
|
| 3405 |
mandeep.dh |
322 |
tickets = crmServiceClient.getTickets(searchFilter);
|
| 3137 |
mandeep.dh |
323 |
} catch (TException e) {
|
|
|
324 |
String errorString = "Error getting tickets for "
|
|
|
325 |
+ currentAgentEmailId;
|
|
|
326 |
log.error(errorString, e);
|
|
|
327 |
addActionError(errorString);
|
|
|
328 |
}
|
|
|
329 |
|
| 3405 |
mandeep.dh |
330 |
return index();
|
| 3137 |
mandeep.dh |
331 |
}
|
|
|
332 |
|
|
|
333 |
public String getUnassignedTickets() {
|
|
|
334 |
try {
|
| 3546 |
mandeep.dh |
335 |
crmServiceClient = new CRMClient().getClient();
|
| 3137 |
mandeep.dh |
336 |
tickets = crmServiceClient.getUnassignedTickets();
|
|
|
337 |
} catch (TException e) {
|
| 3339 |
mandeep.dh |
338 |
String errorString = "Error getting tickets for "
|
|
|
339 |
+ currentAgentEmailId;
|
| 3137 |
mandeep.dh |
340 |
log.error(errorString, e);
|
|
|
341 |
addActionError(errorString);
|
|
|
342 |
}
|
|
|
343 |
|
| 3405 |
mandeep.dh |
344 |
return index();
|
| 3137 |
mandeep.dh |
345 |
}
|
|
|
346 |
|
| 3405 |
mandeep.dh |
347 |
public String update() {
|
|
|
348 |
try {
|
|
|
349 |
long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
|
|
|
350 |
.getId();
|
|
|
351 |
|
| 3546 |
mandeep.dh |
352 |
SearchFilter searchFilter = new SearchFilter();
|
|
|
353 |
searchFilter.setTicketId(Long.parseLong(id));
|
|
|
354 |
crmServiceClient = new CRMClient().getClient();
|
|
|
355 |
Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
|
| 3405 |
mandeep.dh |
356 |
ticket.setDescription(description);
|
|
|
357 |
ticket.setPriority(TicketPriority.valueOf(priority));
|
|
|
358 |
|
|
|
359 |
// Update when a ticket is closed!
|
| 3578 |
mandeep.dh |
360 |
if (TicketStatus.CLOSED.name().equals(status) || TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())) {
|
| 3546 |
mandeep.dh |
361 |
if (TicketCategory.COD_VERIFICATION.equals(ticket.getCategory())
|
|
|
362 |
&& pendingCODOrders(ticket.getCustomerId())) {
|
|
|
363 |
addActionMessage("Cod orders pending for verification. Ticket can not be closed and its category cannot be changed.");
|
|
|
364 |
} else {
|
|
|
365 |
ticket.setCategory(TicketCategory.valueOf(category));
|
|
|
366 |
ticket.setStatus(TicketStatus.valueOf(status));
|
|
|
367 |
ticket.setCloseDate(new Date().getTime());
|
|
|
368 |
}
|
| 3405 |
mandeep.dh |
369 |
}
|
| 3546 |
mandeep.dh |
370 |
else {
|
|
|
371 |
ticket.setCategory(TicketCategory.valueOf(category));
|
| 3578 |
mandeep.dh |
372 |
ticket.setStatus(TicketStatus.valueOf(status));
|
| 3546 |
mandeep.dh |
373 |
}
|
| 3405 |
mandeep.dh |
374 |
|
|
|
375 |
if (activityDescription == null || activityDescription.isEmpty()) {
|
| 4241 |
anupam.sin |
376 |
activityDescription = "Ticket fields updated";
|
| 3405 |
mandeep.dh |
377 |
}
|
|
|
378 |
|
|
|
379 |
Activity activity = new Activity();
|
|
|
380 |
activity.setDescription(activityDescription);
|
|
|
381 |
activity.setType(ActivityType.valueOf(activityType));
|
| 3546 |
mandeep.dh |
382 |
activity.setTicketPriority(ticket.getPriority());
|
|
|
383 |
activity.setTicketStatus(ticket.getStatus());
|
| 3405 |
mandeep.dh |
384 |
activity.setCreatorId(creatorId);
|
| 3546 |
mandeep.dh |
385 |
activity.setTicketCategory(ticket.getCategory());
|
|
|
386 |
activity.setTicketDescription(ticket.getDescription());
|
| 3405 |
mandeep.dh |
387 |
|
|
|
388 |
if (userId != null && !userId.isEmpty()) {
|
|
|
389 |
activity.setCustomerId(Long.parseLong(userId));
|
|
|
390 |
}
|
|
|
391 |
|
| 4035 |
mandeep.dh |
392 |
// Handling null values appropriately
|
|
|
393 |
if (assigneeEmailId != null && !assigneeEmailId.isEmpty()) {
|
|
|
394 |
long assigneeId = CRMAuthorizingRealm.getAgent(assigneeEmailId)
|
|
|
395 |
.getId();
|
|
|
396 |
ticket.setAssigneeId(assigneeId);
|
|
|
397 |
activity.setTicketAssigneeId(assigneeId);
|
|
|
398 |
}
|
|
|
399 |
|
| 3405 |
mandeep.dh |
400 |
if (ActivityType.SEND_EMAIL_TO_CUSTOMER.equals(activity.getType())) {
|
|
|
401 |
log.info("Sending mail");
|
|
|
402 |
Client helperClient = new HelperClient().getClient();
|
|
|
403 |
activity.setUserEmailId(helperClient.saveUserEmailForSending(
|
| 3546 |
mandeep.dh |
404 |
customerEmailId, CRMConstants.CRM_EMAIL_SENDOR,
|
|
|
405 |
subject, body, null, CRMConstants.CRM_EMAIL_TYPE));
|
| 3405 |
mandeep.dh |
406 |
|
|
|
407 |
// We change activityType to OTHER when pop up box for email
|
|
|
408 |
// closes
|
|
|
409 |
activity.setDescription("Subject: " + subject + "\n\n"
|
|
|
410 |
+ "Body: " + body);
|
| 4206 |
mandeep.dh |
411 |
|
|
|
412 |
String activityDesc = activity.getDescription();
|
|
|
413 |
if (activityDesc.length() > CRMConstants.DESCRIPTION_MAX_WIDTH) {
|
|
|
414 |
activityDesc = activityDesc.substring(0, CRMConstants.DESCRIPTION_MAX_WIDTH);
|
|
|
415 |
activityDesc += "\n\nTHIS TEXT IS TRUNCATED. PLEASE VISIT INBOX TO SEE COMPLETE DETAILS.";
|
|
|
416 |
}
|
|
|
417 |
|
|
|
418 |
activity.setDescription(activityDesc);
|
| 3405 |
mandeep.dh |
419 |
}
|
|
|
420 |
|
| 4020 |
mandeep.dh |
421 |
if (ActivityType.ESCALATE_TICKET.equals(activity.getType())) {
|
|
|
422 |
log.info("Sending escalation mail");
|
|
|
423 |
EscalationMatrix escalation = CRMConstants.EscalationMatrix.valueOf(escalate);
|
|
|
424 |
List<Integer> escalationReceipients = escalation.getAgentIds();
|
|
|
425 |
|
|
|
426 |
String toMailIds = "";
|
|
|
427 |
for (Integer agentId : escalationReceipients) {
|
|
|
428 |
toMailIds += CRMAuthorizingRealm.getAgent(agentId).getEmailId() + ";";
|
| 4034 |
mandeep.dh |
429 |
|
|
|
430 |
// Setting last agent as assignee
|
|
|
431 |
ticket.setAssigneeId(agentId);
|
|
|
432 |
activity.setTicketAssigneeId(agentId);
|
| 4020 |
mandeep.dh |
433 |
}
|
|
|
434 |
|
|
|
435 |
Client helperClient = new HelperClient().getClient();
|
|
|
436 |
String escalationMailSubject = createEscalationMailSubject(ticket, escalation);
|
|
|
437 |
String escalationMailBody = createEscalationMailBody(ticket, escalation);
|
|
|
438 |
|
|
|
439 |
activity.setUserEmailId(helperClient.saveUserEmailForSending(
|
|
|
440 |
toMailIds, CRMConstants.CRM_EMAIL_SENDOR,
|
|
|
441 |
escalationMailSubject, escalationMailBody,
|
|
|
442 |
null, CRMConstants.CRM_EMAIL_TYPE));
|
|
|
443 |
|
|
|
444 |
// We change activityType to OTHER when pop up box for email
|
|
|
445 |
// closes
|
|
|
446 |
activity.setDescription("To: " + toMailIds + "\n\nSubject: " + escalationMailSubject + "\n\n"
|
|
|
447 |
+ "Body: " + escalationMailBody);
|
|
|
448 |
}
|
|
|
449 |
|
| 3405 |
mandeep.dh |
450 |
User user = null;
|
|
|
451 |
userContextServiceClient = new UserClient().getClient();
|
|
|
452 |
try {
|
|
|
453 |
if (customerName != null && !customerName.isEmpty()) {
|
|
|
454 |
ticket.setCustomerName(customerName);
|
|
|
455 |
activity.setCustomerName(customerName);
|
|
|
456 |
}
|
|
|
457 |
|
|
|
458 |
if (customerEmailId != null && !customerEmailId.isEmpty()) {
|
|
|
459 |
ticket.setCustomerEmailId(customerEmailId);
|
|
|
460 |
activity.setCustomerEmailId(customerEmailId);
|
| 3546 |
mandeep.dh |
461 |
user = userContextServiceClient
|
|
|
462 |
.getUserByEmail(customerEmailId);
|
| 3405 |
mandeep.dh |
463 |
}
|
|
|
464 |
|
| 3546 |
mandeep.dh |
465 |
if ((user == null || user.getUserId() == -1)
|
|
|
466 |
&& customerMobileNumber != null
|
|
|
467 |
&& !customerMobileNumber.isEmpty()) {
|
| 3405 |
mandeep.dh |
468 |
ticket.setCustomerMobileNumber(customerMobileNumber);
|
|
|
469 |
activity.setCustomerMobileNumber(customerMobileNumber);
|
| 3546 |
mandeep.dh |
470 |
user = userContextServiceClient.getUserByMobileNumber(Long
|
|
|
471 |
.parseLong(customerMobileNumber));
|
| 3405 |
mandeep.dh |
472 |
}
|
|
|
473 |
} catch (UserContextException e) {
|
|
|
474 |
log.error("Could not fetch user for: " + customerEmailId + " "
|
|
|
475 |
+ customerMobileNumber + " " + customerName, e);
|
|
|
476 |
}
|
| 3546 |
mandeep.dh |
477 |
|
| 3405 |
mandeep.dh |
478 |
if (user != null && user.getUserId() != -1) {
|
|
|
479 |
ticket.setCustomerId(user.getUserId());
|
|
|
480 |
activity.setCustomerId(user.getUserId());
|
|
|
481 |
}
|
|
|
482 |
|
|
|
483 |
crmServiceClient = new CRMClient().getClient();
|
|
|
484 |
crmServiceClient.updateTicket(ticket, activity);
|
|
|
485 |
} catch (TException e) {
|
|
|
486 |
log.error("Error while updating ticket", e);
|
|
|
487 |
return EXCEPTION;
|
|
|
488 |
} catch (HelperServiceException hse) {
|
|
|
489 |
log.error("Error while sending mail", hse);
|
|
|
490 |
return EXCEPTION;
|
|
|
491 |
}
|
|
|
492 |
|
|
|
493 |
return index();
|
|
|
494 |
}
|
|
|
495 |
|
| 4020 |
mandeep.dh |
496 |
private String createEscalationMailBody(Ticket ticket,
|
|
|
497 |
EscalationMatrix escalation)
|
|
|
498 |
{
|
|
|
499 |
return body + "<br />Please visit following URL to check ticket details.<br />" +
|
|
|
500 |
"http://cs.shop2020.in:8080/crm?ticketId=" + ticket.getId();
|
|
|
501 |
}
|
|
|
502 |
|
|
|
503 |
private String createEscalationMailSubject(Ticket ticket,
|
|
|
504 |
EscalationMatrix escalation)
|
|
|
505 |
{
|
|
|
506 |
return CRMConstants.CRM_SUBJECT_PREFIX_FOR_TICKET_ID + ticket.getId() + " - ESCALATION FROM CRM - Type: " + escalation.name();
|
|
|
507 |
}
|
|
|
508 |
|
| 3546 |
mandeep.dh |
509 |
private boolean pendingCODOrders(long customerId) {
|
|
|
510 |
try {
|
|
|
511 |
log.info("Trying to fetch orders for " + customerId);
|
|
|
512 |
transactionServiceClient = new TransactionClient().getClient();
|
|
|
513 |
for (Order order : transactionServiceClient.getOrdersForCustomer(
|
|
|
514 |
customerId, 0, 0,
|
|
|
515 |
Collections.singletonList(OrderStatus.INIT))) {
|
|
|
516 |
log.info("Processing order: " + order.getId() + " with COD: " + order.isCod());
|
|
|
517 |
if (order.isCod()) {
|
|
|
518 |
log.info("Returning true from pendingCODOrders() for " + customerId);
|
|
|
519 |
return true;
|
|
|
520 |
}
|
|
|
521 |
}
|
|
|
522 |
} catch (TTransportException e) {
|
|
|
523 |
log.error("Error while creating thrift client", e);
|
|
|
524 |
} catch (TransactionServiceException e) {
|
|
|
525 |
log.error("Error fetching orders", e);
|
|
|
526 |
} catch (TException e) {
|
|
|
527 |
log.error("Error fetching orders", e);
|
|
|
528 |
}
|
|
|
529 |
|
|
|
530 |
log.info("Returning false from pendingCODOrders() for " + customerId);
|
|
|
531 |
return false;
|
|
|
532 |
}
|
|
|
533 |
|
|
|
534 |
public String updateOrderStatus() throws NumberFormatException,
|
|
|
535 |
TransactionServiceException, TException {
|
|
|
536 |
long creatorId = CRMAuthorizingRealm.getAgent(currentAgentEmailId)
|
|
|
537 |
.getId();
|
|
|
538 |
|
| 3578 |
mandeep.dh |
539 |
OrderStatus orderStatusEnum = OrderStatus.valueOf(orderStatus);
|
| 3546 |
mandeep.dh |
540 |
transactionServiceClient = new TransactionClient().getClient();
|
|
|
541 |
|
| 3578 |
mandeep.dh |
542 |
if (OrderStatus.SUBMITTED_FOR_PROCESSING.equals(orderStatusEnum)) {
|
|
|
543 |
transactionServiceClient.verifyOrder(Long.parseLong(orderId));
|
|
|
544 |
}
|
|
|
545 |
else if (OrderStatus.CANCELED.equals(orderStatusEnum)) {
|
| 4241 |
anupam.sin |
546 |
transactionServiceClient.refundOrder(Long.parseLong(orderId), currentAgentEmailId, cancelReason);
|
| 3578 |
mandeep.dh |
547 |
}
|
|
|
548 |
else {
|
|
|
549 |
throw new UnsupportedOperationException("Cannot update status of orderId: " + orderId + " to: " + orderStatus);
|
|
|
550 |
}
|
|
|
551 |
|
| 3546 |
mandeep.dh |
552 |
SearchFilter searchFilter = new SearchFilter();
|
|
|
553 |
searchFilter.setTicketId(Long.parseLong(id));
|
|
|
554 |
crmServiceClient = new CRMClient().getClient();
|
|
|
555 |
Ticket ticket = crmServiceClient.getTickets(searchFilter).get(0);
|
|
|
556 |
|
|
|
557 |
// Inserting activity
|
|
|
558 |
Activity activity = new Activity();
|
| 4241 |
anupam.sin |
559 |
activity.setDescription("Status updated for Order Id: " + orderId
|
|
|
560 |
+ " to " + orderStatus + ", Reason: " + cancelReason + body);
|
| 3546 |
mandeep.dh |
561 |
activity.setType(ActivityType.OTHER);
|
|
|
562 |
activity.setTicketPriority(ticket.getPriority());
|
|
|
563 |
activity.setTicketStatus(ticket.getStatus());
|
|
|
564 |
activity.setCreatorId(creatorId);
|
|
|
565 |
activity.setTicketCategory(ticket.getCategory());
|
|
|
566 |
activity.setTicketDescription(ticket.getDescription());
|
|
|
567 |
activity.setCustomerId(ticket.getCustomerId());
|
|
|
568 |
activity.setTicketAssigneeId(ticket.getAssigneeId());
|
|
|
569 |
|
|
|
570 |
crmServiceClient = new CRMClient().getClient();
|
|
|
571 |
crmServiceClient.updateTicket(ticket, activity);
|
|
|
572 |
|
|
|
573 |
return edit();
|
|
|
574 |
}
|
|
|
575 |
|
| 3137 |
mandeep.dh |
576 |
public User getUser(Long userId) {
|
|
|
577 |
User user = null;
|
|
|
578 |
|
|
|
579 |
try {
|
| 3390 |
mandeep.dh |
580 |
userContextServiceClient = new UserClient().getClient();
|
| 3137 |
mandeep.dh |
581 |
user = userContextServiceClient.getUserById(userId);
|
|
|
582 |
} catch (UserContextException e) {
|
|
|
583 |
String errorString = "Could not fetch user for " + userId;
|
|
|
584 |
log.error(errorString, e);
|
|
|
585 |
addActionError(errorString);
|
|
|
586 |
} catch (TException e) {
|
|
|
587 |
String errorString = "Could not create client";
|
|
|
588 |
log.error(errorString, e);
|
|
|
589 |
addActionError(errorString);
|
|
|
590 |
}
|
|
|
591 |
|
|
|
592 |
return user;
|
|
|
593 |
}
|
|
|
594 |
|
| 4020 |
mandeep.dh |
595 |
public EscalationMatrix[] getEscalationMatrix () {
|
|
|
596 |
return CRMConstants.EscalationMatrix.values();
|
|
|
597 |
}
|
|
|
598 |
|
| 4241 |
anupam.sin |
599 |
public CODCancelMatrix[] getCODCancelMatrix () {
|
|
|
600 |
return CRMConstants.CODCancelMatrix.values();
|
|
|
601 |
}
|
|
|
602 |
|
| 3546 |
mandeep.dh |
603 |
public String getAddress(Order order) {
|
|
|
604 |
return ModelUtils.extractAddressFromOrder(order);
|
|
|
605 |
}
|
|
|
606 |
|
|
|
607 |
public String getProductName(LineItem lineItem) {
|
| 4008 |
mandeep.dh |
608 |
return ModelUtils.extractProductNameFromLineItem(lineItem) + " " + lineItem.getColor();
|
| 3546 |
mandeep.dh |
609 |
}
|
|
|
610 |
|
| 3405 |
mandeep.dh |
611 |
public ActivityType[] getActivityTypes() {
|
|
|
612 |
return ActivityType.values();
|
|
|
613 |
}
|
|
|
614 |
|
|
|
615 |
public TicketStatus[] getTicketStatuses() {
|
|
|
616 |
return TicketStatus.values();
|
|
|
617 |
}
|
|
|
618 |
|
| 3390 |
mandeep.dh |
619 |
public Agent getAgent(long agentId) throws TException {
|
|
|
620 |
return CRMAuthorizingRealm.getAgent(agentId);
|
| 3137 |
mandeep.dh |
621 |
}
|
|
|
622 |
|
| 3339 |
mandeep.dh |
623 |
public List<Agent> getAllAgents() {
|
| 3390 |
mandeep.dh |
624 |
return CRMAuthorizingRealm.getAgents();
|
| 3339 |
mandeep.dh |
625 |
}
|
|
|
626 |
|
|
|
627 |
public TicketCategory[] getTicketCategories() {
|
|
|
628 |
return TicketCategory.values();
|
|
|
629 |
}
|
|
|
630 |
|
|
|
631 |
public TicketPriority[] getTicketPriorities() {
|
|
|
632 |
return TicketPriority.values();
|
|
|
633 |
}
|
|
|
634 |
|
| 3137 |
mandeep.dh |
635 |
public List<Ticket> getTickets() {
|
|
|
636 |
return tickets;
|
|
|
637 |
}
|
|
|
638 |
|
|
|
639 |
public void setTickets(List<Ticket> tickets) {
|
|
|
640 |
this.tickets = tickets;
|
|
|
641 |
}
|
| 3339 |
mandeep.dh |
642 |
|
| 3405 |
mandeep.dh |
643 |
public String getCustomerEmailId() {
|
|
|
644 |
return customerEmailId;
|
| 3339 |
mandeep.dh |
645 |
}
|
|
|
646 |
|
| 3405 |
mandeep.dh |
647 |
public void setCustomerEmailId(String customerEmailId) {
|
|
|
648 |
this.customerEmailId = customerEmailId;
|
| 3339 |
mandeep.dh |
649 |
}
|
|
|
650 |
|
|
|
651 |
public String getDescription() {
|
|
|
652 |
return description;
|
|
|
653 |
}
|
|
|
654 |
|
|
|
655 |
public void setDescription(String description) {
|
|
|
656 |
this.description = description;
|
|
|
657 |
}
|
|
|
658 |
|
|
|
659 |
public String getAssigneeEmailId() {
|
|
|
660 |
return assigneeEmailId;
|
|
|
661 |
}
|
|
|
662 |
|
|
|
663 |
public void setAssigneeEmailId(String assigneeEmailId) {
|
|
|
664 |
this.assigneeEmailId = assigneeEmailId;
|
|
|
665 |
}
|
|
|
666 |
|
|
|
667 |
public String getPriority() {
|
|
|
668 |
return priority;
|
|
|
669 |
}
|
|
|
670 |
|
|
|
671 |
public void setPriority(String priority) {
|
|
|
672 |
this.priority = priority;
|
|
|
673 |
}
|
|
|
674 |
|
|
|
675 |
public String getCategory() {
|
|
|
676 |
return category;
|
|
|
677 |
}
|
|
|
678 |
|
|
|
679 |
public void setCategory(String category) {
|
|
|
680 |
this.category = category;
|
|
|
681 |
}
|
|
|
682 |
|
|
|
683 |
public String getOrderId() {
|
|
|
684 |
return orderId;
|
|
|
685 |
}
|
|
|
686 |
|
|
|
687 |
public void setOrderId(String orderId) {
|
|
|
688 |
this.orderId = orderId;
|
|
|
689 |
}
|
| 3397 |
mandeep.dh |
690 |
|
|
|
691 |
public String[] getAgentIds() {
|
|
|
692 |
return agentIds;
|
|
|
693 |
}
|
|
|
694 |
|
|
|
695 |
public void setAgentIds(String[] agentIds) {
|
|
|
696 |
this.agentIds = agentIds;
|
|
|
697 |
}
|
|
|
698 |
|
|
|
699 |
public String getStartTimestamp() {
|
|
|
700 |
return startTimestamp;
|
|
|
701 |
}
|
|
|
702 |
|
|
|
703 |
public void setStartTimestamp(String startTimestamp) {
|
|
|
704 |
this.startTimestamp = startTimestamp;
|
|
|
705 |
}
|
|
|
706 |
|
|
|
707 |
public String getEndTimestamp() {
|
|
|
708 |
return endTimestamp;
|
|
|
709 |
}
|
|
|
710 |
|
|
|
711 |
public void setEndTimestamp(String endTimestamp) {
|
|
|
712 |
this.endTimestamp = endTimestamp;
|
|
|
713 |
}
|
| 3405 |
mandeep.dh |
714 |
|
|
|
715 |
public String getUserId() {
|
|
|
716 |
return userId;
|
|
|
717 |
}
|
|
|
718 |
|
|
|
719 |
public void setUserId(String userId) {
|
|
|
720 |
this.userId = userId;
|
|
|
721 |
}
|
|
|
722 |
|
|
|
723 |
public String getId() {
|
|
|
724 |
return id;
|
|
|
725 |
}
|
|
|
726 |
|
|
|
727 |
public void setId(String id) {
|
|
|
728 |
this.id = id;
|
|
|
729 |
}
|
|
|
730 |
|
|
|
731 |
public String getActivityDescription() {
|
|
|
732 |
return activityDescription;
|
|
|
733 |
}
|
|
|
734 |
|
|
|
735 |
public void setActivityDescription(String activityDescription) {
|
|
|
736 |
this.activityDescription = activityDescription;
|
|
|
737 |
}
|
|
|
738 |
|
|
|
739 |
public String getStatus() {
|
|
|
740 |
return status;
|
|
|
741 |
}
|
|
|
742 |
|
|
|
743 |
public void setStatus(String status) {
|
|
|
744 |
this.status = status;
|
|
|
745 |
}
|
|
|
746 |
|
|
|
747 |
public String getActivityType() {
|
|
|
748 |
return activityType;
|
|
|
749 |
}
|
|
|
750 |
|
|
|
751 |
public void setActivityType(String activityType) {
|
|
|
752 |
this.activityType = activityType;
|
|
|
753 |
}
|
|
|
754 |
|
|
|
755 |
public Ticket getTicket() {
|
|
|
756 |
return ticket;
|
|
|
757 |
}
|
|
|
758 |
|
|
|
759 |
public void setTicket(Ticket ticket) {
|
|
|
760 |
this.ticket = ticket;
|
|
|
761 |
}
|
|
|
762 |
|
|
|
763 |
public List<Activity> getActivities() {
|
|
|
764 |
return activities;
|
|
|
765 |
}
|
|
|
766 |
|
|
|
767 |
public void setActivities(List<Activity> activities) {
|
|
|
768 |
this.activities = activities;
|
|
|
769 |
}
|
|
|
770 |
|
|
|
771 |
public String getSubject() {
|
|
|
772 |
return subject;
|
|
|
773 |
}
|
|
|
774 |
|
|
|
775 |
public void setSubject(String subject) {
|
|
|
776 |
this.subject = subject;
|
|
|
777 |
}
|
|
|
778 |
|
|
|
779 |
public String getBody() {
|
|
|
780 |
return body;
|
|
|
781 |
}
|
|
|
782 |
|
|
|
783 |
public void setBody(String body) {
|
|
|
784 |
this.body = body;
|
|
|
785 |
}
|
|
|
786 |
|
|
|
787 |
public String getCustomerName() {
|
|
|
788 |
return customerName;
|
|
|
789 |
}
|
|
|
790 |
|
|
|
791 |
public void setCustomerName(String customerName) {
|
|
|
792 |
this.customerName = customerName;
|
|
|
793 |
}
|
|
|
794 |
|
|
|
795 |
public String getCustomerMobileNumber() {
|
|
|
796 |
return customerMobileNumber;
|
|
|
797 |
}
|
|
|
798 |
|
|
|
799 |
public void setCustomerMobileNumber(String customerMobileNumber) {
|
|
|
800 |
this.customerMobileNumber = customerMobileNumber;
|
|
|
801 |
}
|
| 3546 |
mandeep.dh |
802 |
|
|
|
803 |
public User getUser() {
|
|
|
804 |
return user;
|
|
|
805 |
}
|
|
|
806 |
|
|
|
807 |
public void setUser(User user) {
|
|
|
808 |
this.user = user;
|
|
|
809 |
}
|
|
|
810 |
|
|
|
811 |
public String getOrderStatus() {
|
|
|
812 |
return orderStatus;
|
|
|
813 |
}
|
|
|
814 |
|
|
|
815 |
public void setOrderStatus(String orderStatus) {
|
|
|
816 |
this.orderStatus = orderStatus;
|
|
|
817 |
}
|
|
|
818 |
|
|
|
819 |
public List<Order> getOrders() {
|
|
|
820 |
return orders;
|
|
|
821 |
}
|
|
|
822 |
|
|
|
823 |
public void setOrders(List<Order> orders) {
|
|
|
824 |
this.orders = orders;
|
|
|
825 |
}
|
| 4020 |
mandeep.dh |
826 |
|
|
|
827 |
public String getEscalate() {
|
|
|
828 |
return escalate;
|
|
|
829 |
}
|
|
|
830 |
|
|
|
831 |
public void setEscalate(String escalate) {
|
|
|
832 |
this.escalate = escalate;
|
|
|
833 |
}
|
| 4241 |
anupam.sin |
834 |
|
|
|
835 |
public String getCancelReason() {
|
|
|
836 |
return cancelReason;
|
|
|
837 |
}
|
|
|
838 |
|
|
|
839 |
public void setCancelReason(String cancelReason) {
|
|
|
840 |
this.cancelReason = cancelReason;
|
|
|
841 |
}
|
| 3137 |
mandeep.dh |
842 |
}
|