| 4008 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.crm.util;
|
|
|
5 |
|
|
|
6 |
import in.shop2020.crm.ActivityType;
|
|
|
7 |
import in.shop2020.crm.TicketCategory;
|
|
|
8 |
import in.shop2020.crm.TicketPriority;
|
|
|
9 |
import in.shop2020.crm.TicketStatus;
|
| 21922 |
amit.gupta |
10 |
import in.shop2020.crm.domain.Activity;
|
|
|
11 |
import in.shop2020.crm.domain.SearchFilter;
|
|
|
12 |
import in.shop2020.crm.domain.Ticket;
|
| 4008 |
mandeep.dh |
13 |
import in.shop2020.crm.handler.ActivityHandler;
|
|
|
14 |
import in.shop2020.crm.handler.TicketHandler;
|
|
|
15 |
import in.shop2020.model.v1.order.ExtraTransactionProcessingType;
|
|
|
16 |
import in.shop2020.model.v1.order.Order;
|
|
|
17 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
18 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
19 |
import in.shop2020.model.v1.order.TransactionService.Client;
|
|
|
20 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 21922 |
amit.gupta |
21 |
import in.shop2020.model.v1.user.Counter;
|
| 4008 |
mandeep.dh |
22 |
import in.shop2020.model.v1.user.User;
|
|
|
23 |
import in.shop2020.model.v1.user.UserContextException;
|
|
|
24 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
25 |
import in.shop2020.thrift.clients.UserClient;
|
|
|
26 |
|
|
|
27 |
import java.util.ArrayList;
|
|
|
28 |
import java.util.List;
|
|
|
29 |
|
| 21922 |
amit.gupta |
30 |
import org.apache.commons.lang.StringUtils;
|
| 4008 |
mandeep.dh |
31 |
import org.apache.commons.logging.Log;
|
|
|
32 |
import org.apache.commons.logging.LogFactory;
|
|
|
33 |
import org.apache.thrift.TException;
|
|
|
34 |
import org.apache.thrift.transport.TTransportException;
|
| 5142 |
anupam.sin |
35 |
import org.springframework.context.ApplicationContext;
|
|
|
36 |
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
| 4008 |
mandeep.dh |
37 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* @author mandeep
|
|
|
41 |
* Processor all the COD transactions booked by customers, creates a ticket per
|
|
|
42 |
* customer so as our Outbound team can work on them like verifying users
|
|
|
43 |
* validity and order details.
|
|
|
44 |
*/
|
| 5142 |
anupam.sin |
45 |
public class CODTransactionProcessorTask {
|
| 4008 |
mandeep.dh |
46 |
private static Log log = LogFactory.getLog(CODTransactionProcessorTask.class);
|
|
|
47 |
private static final double TRUST_THRESHOLD_LEVEL = 4.5;
|
|
|
48 |
private static final long ADMIN_AGENT_ID = 1;
|
| 20296 |
kshitij.so |
49 |
private static final long OUTBOUND_DEFAULT_ASSIGNEE_ID = 33;
|
| 4008 |
mandeep.dh |
50 |
|
|
|
51 |
private TicketHandler ticketHandler;
|
|
|
52 |
private ActivityHandler activityHandler;
|
|
|
53 |
|
| 5142 |
anupam.sin |
54 |
public CODTransactionProcessorTask()
|
| 4008 |
mandeep.dh |
55 |
{
|
| 5142 |
anupam.sin |
56 |
ApplicationContext context = new ClassPathXmlApplicationContext("context.xml");
|
|
|
57 |
ticketHandler = context.getBean(TicketHandler.class);
|
|
|
58 |
activityHandler = context.getBean(ActivityHandler.class);
|
| 4008 |
mandeep.dh |
59 |
}
|
|
|
60 |
|
| 5142 |
anupam.sin |
61 |
|
|
|
62 |
public static void main(String[] args) {
|
| 4008 |
mandeep.dh |
63 |
try {
|
| 5142 |
anupam.sin |
64 |
CODTransactionProcessorTask newTask = new CODTransactionProcessorTask();
|
| 4008 |
mandeep.dh |
65 |
Client client = new TransactionClient().getClient();
|
|
|
66 |
List<Long> transactionIds = client.getTransactionsRequiringExtraProcessing(ExtraTransactionProcessingType.COD_VERIFICATION);
|
|
|
67 |
if (transactionIds != null && !transactionIds.isEmpty()) {
|
|
|
68 |
log.info("Fetched " + transactionIds.size() + " transactions");
|
|
|
69 |
for (Long transactionId : transactionIds) {
|
| 5142 |
anupam.sin |
70 |
newTask.processCODTxn(transactionId);
|
| 4022 |
mandeep.dh |
71 |
client = new TransactionClient().getClient();
|
| 4008 |
mandeep.dh |
72 |
client.markTransactionAsProcessed(transactionId, ExtraTransactionProcessingType.COD_VERIFICATION);
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
else {
|
|
|
76 |
log.info("No transactions to process");
|
|
|
77 |
}
|
|
|
78 |
} catch (TTransportException e) {
|
| 4191 |
mandeep.dh |
79 |
log.error("Error creating client", e);
|
| 4008 |
mandeep.dh |
80 |
} catch (TException e) {
|
|
|
81 |
log.error("Could not fetch transactions for processing", e);
|
| 4191 |
mandeep.dh |
82 |
} catch (TransactionServiceException e) {
|
|
|
83 |
log.error("Could not find transaction", e);
|
|
|
84 |
} catch (UserContextException e) {
|
|
|
85 |
log.error("Could not find user", e);
|
| 4008 |
mandeep.dh |
86 |
}
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Method that creates a ticket if necessary for COD verification
|
| 4191 |
mandeep.dh |
91 |
* @throws TException
|
|
|
92 |
* @throws TransactionServiceException
|
|
|
93 |
* @throws UserContextException
|
| 4008 |
mandeep.dh |
94 |
*/
|
| 4191 |
mandeep.dh |
95 |
private void processCODTxn(long transactionId)
|
|
|
96 |
throws TransactionServiceException, TException,
|
|
|
97 |
UserContextException {
|
|
|
98 |
log.info("Processing txn id: " + transactionId);
|
|
|
99 |
Client client = new TransactionClient().getClient();
|
|
|
100 |
Transaction transaction = client.getTransaction(transactionId);
|
|
|
101 |
in.shop2020.model.v1.user.UserContextService.Client userClient = new UserClient()
|
|
|
102 |
.getClient();
|
|
|
103 |
User user = userClient.getUserById(transaction.getCustomer_id());
|
| 21922 |
amit.gupta |
104 |
//PrivateDealUser pdu = userClient.getPrivateDealUser(transaction.getCustomer_id());
|
|
|
105 |
Counter counter = userClient.getCounterByUserId(user.getUserId());
|
|
|
106 |
if (user.getTrustLevel() - TRUST_THRESHOLD_LEVEL < 1e-4 || !validateCounter(counter)) {
|
| 4191 |
mandeep.dh |
107 |
for (Order order : transaction.getOrders()) {
|
|
|
108 |
log.info("Processing order: " + order.getId());
|
| 4663 |
rajveer |
109 |
if (order.isCod() && OrderStatus.COD_VERIFICATION_PENDING.equals(order.getStatus())) {
|
| 4191 |
mandeep.dh |
110 |
log.info("Processing COD order: " + order.getId());
|
|
|
111 |
in.shop2020.crm.domain.SearchFilter searchFilter = new SearchFilter();
|
|
|
112 |
searchFilter
|
|
|
113 |
.setTicketStatuses(new ArrayList<TicketStatus>());
|
|
|
114 |
searchFilter.getTicketStatuses().add(TicketStatus.OPEN);
|
|
|
115 |
searchFilter.getTicketStatuses().add(TicketStatus.REOPEN);
|
|
|
116 |
searchFilter
|
|
|
117 |
.setTicketCategory(TicketCategory.COD_VERIFICATION);
|
|
|
118 |
searchFilter.setCustomerId(transaction.getCustomer_id());
|
| 4008 |
mandeep.dh |
119 |
|
| 4191 |
mandeep.dh |
120 |
// No need to create a ticket if there exists one for the
|
|
|
121 |
// customer!
|
|
|
122 |
if (ticketHandler.getTickets(searchFilter).isEmpty()) {
|
|
|
123 |
log.info("Logging ticket");
|
|
|
124 |
Ticket ticket = new Ticket();
|
|
|
125 |
ticket.setCategory(TicketCategory.COD_VERIFICATION);
|
|
|
126 |
ticket.setCreatorId(ADMIN_AGENT_ID);
|
|
|
127 |
ticket.setCustomerId(transaction.getCustomer_id());
|
|
|
128 |
ticket.setDescription("Requires COD verification");
|
|
|
129 |
ticket.setPriority(TicketPriority.HIGH);
|
|
|
130 |
ticket.setStatus(TicketStatus.OPEN);
|
|
|
131 |
ticket.setAssigneeId(OUTBOUND_DEFAULT_ASSIGNEE_ID);
|
| 4008 |
mandeep.dh |
132 |
|
| 4191 |
mandeep.dh |
133 |
Activity activity = new Activity();
|
|
|
134 |
activity.setCreatorId(ticket.getCreatorId());
|
|
|
135 |
activity.setCustomerId(ticket.getCustomerId());
|
|
|
136 |
activity.setDescription("Creating ticket");
|
|
|
137 |
activity.setTicketCategory(ticket.getCategory());
|
|
|
138 |
activity.setTicketDescription(ticket.getDescription());
|
|
|
139 |
activity.setTicketPriority(ticket.getPriority());
|
|
|
140 |
activity.setTicketStatus(ticket.getStatus());
|
|
|
141 |
activity.setTicketAssigneeId(ticket.getAssigneeId());
|
|
|
142 |
activity.setType(ActivityType.OTHER);
|
| 4008 |
mandeep.dh |
143 |
|
| 4191 |
mandeep.dh |
144 |
createTicket(ticket, activity);
|
|
|
145 |
break;
|
| 4008 |
mandeep.dh |
146 |
}
|
|
|
147 |
}
|
|
|
148 |
}
|
| 4191 |
mandeep.dh |
149 |
} else {
|
|
|
150 |
log.info("Autoverifying orders");
|
|
|
151 |
// Submit order for processing
|
| 7357 |
anupam.sin |
152 |
TransactionClient tcl = new TransactionClient();
|
| 4191 |
mandeep.dh |
153 |
for (Order order : transaction.getOrders()) {
|
|
|
154 |
log.info("Processing order: " + order.getId());
|
| 7357 |
anupam.sin |
155 |
tcl.getClient().verifyOrder(order.getId());
|
| 4008 |
mandeep.dh |
156 |
}
|
|
|
157 |
}
|
|
|
158 |
}
|
| 21922 |
amit.gupta |
159 |
|
|
|
160 |
private boolean validateCounter(Counter c){
|
|
|
161 |
if(c!=null){
|
|
|
162 |
return c.isDocumentVerified();
|
|
|
163 |
}
|
|
|
164 |
return false;
|
|
|
165 |
}
|
| 4008 |
mandeep.dh |
166 |
|
|
|
167 |
@Transactional
|
|
|
168 |
private void createTicket(Ticket ticket, Activity activity) {
|
|
|
169 |
ticketHandler.insertTicket(ticket);
|
| 4179 |
mandeep.dh |
170 |
activity.setTicketId(ticket.getId());
|
| 4008 |
mandeep.dh |
171 |
activityHandler.insertActivity(activity);
|
|
|
172 |
}
|
|
|
173 |
}
|