| 6821 |
amar.kumar |
1 |
package in.shop2020.warehouse.util;
|
|
|
2 |
|
|
|
3 |
import java.io.File;
|
|
|
4 |
import java.util.ArrayList;
|
|
|
5 |
import java.util.Calendar;
|
|
|
6 |
import java.util.Date;
|
|
|
7 |
import java.util.HashMap;
|
|
|
8 |
import java.util.List;
|
|
|
9 |
import java.util.Map;
|
|
|
10 |
|
|
|
11 |
import javax.mail.MessagingException;
|
|
|
12 |
|
|
|
13 |
import org.apache.thrift.TException;
|
|
|
14 |
import org.apache.thrift.transport.TTransportException;
|
|
|
15 |
|
|
|
16 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
17 |
import in.shop2020.model.v1.catalog.Item;
|
|
|
18 |
import in.shop2020.model.v1.catalog.status;
|
|
|
19 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
20 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
21 |
import in.shop2020.thrift.clients.UserClient;
|
|
|
22 |
import in.shop2020.utils.GmailUtils;
|
|
|
23 |
|
|
|
24 |
public class OosStatusMarker {
|
|
|
25 |
private static final Integer OOS_STATUS_CUTOFF_HOUR = 23;
|
|
|
26 |
private static final Integer OOS_STATUS_CUTOFF_MINUTE = 59;
|
|
|
27 |
|
| 8183 |
amar.kumar |
28 |
private static final String[] tomail = {"amar.kumar@shop2020.in", "sandeep.sachdeva@shop2020.in", "khushal.bhatia@shop2020.in", "rajveer.singh@shop2020.in"};
|
|
|
29 |
//private static final String[] tomail = {"amar.kumar@shop2020.in"};
|
|
|
30 |
|
| 6821 |
amar.kumar |
31 |
public static void main(String[] args) throws TTransportException {
|
|
|
32 |
Calendar oosEvaluationDate = Calendar.getInstance();
|
|
|
33 |
Calendar cartAdditionStartDate = Calendar.getInstance();
|
|
|
34 |
oosEvaluationDate.add(Calendar.DATE, -1);
|
|
|
35 |
oosEvaluationDate.set(oosEvaluationDate.get(Calendar.YEAR),
|
|
|
36 |
oosEvaluationDate.get(Calendar.MONTH), oosEvaluationDate.get(Calendar.DATE),
|
|
|
37 |
OOS_STATUS_CUTOFF_HOUR , OOS_STATUS_CUTOFF_MINUTE, 0);
|
| 6844 |
amar.kumar |
38 |
cartAdditionStartDate.set(oosEvaluationDate.get(Calendar.YEAR),
|
|
|
39 |
oosEvaluationDate.get(Calendar.MONTH), oosEvaluationDate.get(Calendar.DATE) -1,
|
|
|
40 |
OOS_STATUS_CUTOFF_HOUR , OOS_STATUS_CUTOFF_MINUTE, 0);
|
| 6821 |
amar.kumar |
41 |
Map<Long, Boolean> oosStatusMap = new HashMap<Long, Boolean>();
|
|
|
42 |
|
|
|
43 |
List<Item> items = null;
|
|
|
44 |
try {
|
|
|
45 |
Client catalogClient = new CatalogClient().getClient();
|
|
|
46 |
items = catalogClient.getAllAliveItems();
|
|
|
47 |
} catch (Exception e) {
|
|
|
48 |
try {
|
|
|
49 |
Client catalogClient = new CatalogClient().getClient();
|
|
|
50 |
items = catalogClient.getAllAliveItems();
|
|
|
51 |
} catch (Exception ex) {
|
|
|
52 |
sendMailForError("Exception while getting all items \n" + e);
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
String failedItemsList = "";
|
|
|
57 |
in.shop2020.model.v1.user.UserContextService.Client client = new UserClient().getClient();
|
|
|
58 |
for(Item item : items) {
|
|
|
59 |
if (item.getItemStatus() == status.ACTIVE) {
|
|
|
60 |
oosStatusMap.put(item.getId(), false);
|
|
|
61 |
} else {
|
|
|
62 |
try {
|
|
|
63 |
if(client.isProductAddedToCart(item.getId(), cartAdditionStartDate.getTimeInMillis(), oosEvaluationDate.getTimeInMillis())) {
|
|
|
64 |
oosStatusMap.put(item.getId(), false);
|
|
|
65 |
} else {
|
|
|
66 |
oosStatusMap.put(item.getId(), true);
|
|
|
67 |
}
|
|
|
68 |
} catch (TException e) {
|
|
|
69 |
failedItemsList = new Long(item.getId()).toString() + "\n";
|
|
|
70 |
continue;
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
try {
|
|
|
76 |
in.shop2020.model.v1.inventory.InventoryService.Client invClient = new InventoryClient().getClient();
|
|
|
77 |
invClient.addOosStatusForItem(oosStatusMap, oosEvaluationDate.getTimeInMillis());
|
|
|
78 |
} catch(Exception e) {
|
|
|
79 |
sendMailForError("Error while adding OOS Status" + e);
|
|
|
80 |
}
|
|
|
81 |
sendMailForSuccess(failedItemsList);
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
private static void sendMailForError(String errorMessage) {
|
|
|
85 |
|
|
|
86 |
GmailUtils g = new GmailUtils();
|
|
|
87 |
try {
|
| 8183 |
amar.kumar |
88 |
g.sendSSLMessage(tomail, "Error while Marking OutOfStock Statuses for Items", errorMessage, "cnc.center@shop2020.in", "5h0p2o2o", new ArrayList<File>());
|
| 6821 |
amar.kumar |
89 |
} catch(MessagingException mex) {
|
|
|
90 |
try {
|
| 8183 |
amar.kumar |
91 |
g.sendSSLMessage(tomail, "Error while Marking OutOfStock Statuses for Items", errorMessage, "cnc.center@shop2020.in", "5h0p2o2o", new ArrayList<File>());
|
| 6821 |
amar.kumar |
92 |
} catch (Exception e) {
|
|
|
93 |
//TODO Logging
|
|
|
94 |
}
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
private static void sendMailForSuccess(String message) {
|
|
|
99 |
|
|
|
100 |
GmailUtils g = new GmailUtils();
|
|
|
101 |
try {
|
| 8183 |
amar.kumar |
102 |
g.sendSSLMessage(tomail, "Marked OutOfStock Statuses ", message, "cnc.center@shop2020.in", "5h0p2o2o", new ArrayList<File>());
|
| 6821 |
amar.kumar |
103 |
} catch(MessagingException mex) {
|
|
|
104 |
//TODO Logging
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
}
|