| 9947 |
vikram.rag |
1 |
package in.shop2020;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.logistics.DeliveryType;
|
|
|
4 |
import in.shop2020.logistics.LogisticsInfo;
|
|
|
5 |
import in.shop2020.logistics.LogisticsServiceException;
|
|
|
6 |
import in.shop2020.model.v1.catalog.CatalogService.Client;
|
|
|
7 |
import in.shop2020.model.v1.catalog.FlipkartItem;
|
|
|
8 |
import in.shop2020.model.v1.catalog.Item;
|
| 10174 |
vikram.rag |
9 |
import in.shop2020.model.v1.catalog.SnapdealItemDetails;
|
| 9947 |
vikram.rag |
10 |
import in.shop2020.model.v1.catalog.status;
|
| 10049 |
vikram.rag |
11 |
import in.shop2020.model.v1.inventory.FlipkartInventorySnapshot;
|
| 9947 |
vikram.rag |
12 |
import in.shop2020.model.v1.inventory.InventoryType;
|
|
|
13 |
import in.shop2020.model.v1.inventory.ItemInventory;
|
|
|
14 |
import in.shop2020.model.v1.inventory.Warehouse;
|
|
|
15 |
import in.shop2020.model.v1.inventory.WarehouseLocation;
|
|
|
16 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
|
|
17 |
import in.shop2020.model.v1.order.OrderSource;
|
|
|
18 |
import in.shop2020.serving.model.Order;
|
|
|
19 |
import in.shop2020.serving.model.OrderItems;
|
|
|
20 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
21 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
22 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
23 |
import in.shop2020.thrift.clients.TransactionClient;
|
| 9983 |
vikram.rag |
24 |
import in.shop2020.utils.GmailUtils;
|
| 9947 |
vikram.rag |
25 |
import inventory.FlipkartInventoryItem;
|
|
|
26 |
|
|
|
27 |
import java.io.BufferedReader;
|
| 9983 |
vikram.rag |
28 |
import java.io.File;
|
| 9947 |
vikram.rag |
29 |
import java.io.IOException;
|
|
|
30 |
import java.io.InputStreamReader;
|
| 9968 |
vikram.rag |
31 |
import java.io.UnsupportedEncodingException;
|
| 11442 |
vikram.rag |
32 |
import java.nio.charset.Charset;
|
| 9947 |
vikram.rag |
33 |
import java.util.ArrayList;
|
|
|
34 |
import java.util.HashMap;
|
|
|
35 |
import java.util.List;
|
|
|
36 |
import java.util.Map;
|
|
|
37 |
import java.util.Map.Entry;
|
|
|
38 |
|
| 9983 |
vikram.rag |
39 |
import javax.mail.MessagingException;
|
|
|
40 |
|
| 11443 |
vikram.rag |
41 |
import org.apache.commons.codec.binary.Base64;
|
| 11442 |
vikram.rag |
42 |
import org.apache.http.HttpHeaders;
|
| 9947 |
vikram.rag |
43 |
import org.apache.http.HttpResponse;
|
|
|
44 |
import org.apache.http.NameValuePair;
|
|
|
45 |
import org.apache.http.auth.AuthScope;
|
|
|
46 |
import org.apache.http.auth.UsernamePasswordCredentials;
|
|
|
47 |
import org.apache.http.client.ClientProtocolException;
|
|
|
48 |
import org.apache.http.client.HttpClient;
|
|
|
49 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
50 |
import org.apache.http.client.methods.HttpGet;
|
|
|
51 |
import org.apache.http.client.methods.HttpPost;
|
|
|
52 |
import org.apache.http.entity.StringEntity;
|
|
|
53 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
54 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
55 |
import org.apache.thrift.TException;
|
|
|
56 |
import org.apache.thrift.transport.TTransportException;
|
|
|
57 |
import com.google.gson.Gson;
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
public class CreateSubmitFlipkartInventoryFeed {
|
|
|
62 |
private static Map<Long, FlipkartInventoryItem> flipkartItemsInventoryMap = new HashMap<Long, FlipkartInventoryItem>();
|
|
|
63 |
private static List<FlipkartItem> flipkartItems;
|
|
|
64 |
private static List<FlipkartItem> flipkartInventoryItems = new ArrayList<FlipkartItem>();
|
|
|
65 |
private static Map<Long,Long> itemIdOrdersMap = new HashMap<Long,Long>();
|
| 9983 |
vikram.rag |
66 |
private static Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>();
|
| 10057 |
vikram.rag |
67 |
private static Map<String,Long> heldOrdersMap = new HashMap<String,Long>();
|
| 10122 |
vikram.rag |
68 |
private static Map<Long,Long> updatedFlipkartInventoryMap = new HashMap<Long,Long>();
|
| 9983 |
vikram.rag |
69 |
static java.text.SimpleDateFormat sdf;
|
|
|
70 |
static String emailFromAddress;
|
|
|
71 |
static String password;
|
|
|
72 |
static GmailUtils mailer;
|
|
|
73 |
static String sendTo[];
|
| 10174 |
vikram.rag |
74 |
private static List<SnapdealItemDetails> snapdealItems = new ArrayList<SnapdealItemDetails>();
|
|
|
75 |
private static Map<Long,SnapdealItemDetails> snapdealItemsMap = new HashMap<Long,SnapdealItemDetails>();
|
| 9947 |
vikram.rag |
76 |
static
|
|
|
77 |
{
|
| 9983 |
vikram.rag |
78 |
sdf = new java.text.SimpleDateFormat("yyyy-MM-dd-HH:mm:ss");
|
|
|
79 |
emailFromAddress = "build@shop2020.in";
|
|
|
80 |
password = "cafe@nes";
|
|
|
81 |
mailer = new GmailUtils();
|
| 11448 |
vikram.rag |
82 |
//sendTo = new String[]{"vikram.raghav@shop2020.in"};
|
|
|
83 |
sendTo = new String[]{ "sandeep.sachdeva@shop2020.in", "vikram.raghav@shop2020.in", "rajneesh.arora@shop2020.in",
|
| 9983 |
vikram.rag |
84 |
"khushal.bhatia@shop2020.in","manoj.kumar@saholic.com","chaitnaya.vats@saholic.com",
|
| 11448 |
vikram.rag |
85 |
"yukti.jain@shop2020.in","manoj.pal@shop2020.in","chandan.kumar@shop2020.in","ankush.dhingra@shop2020.in","amar.kumar@shop2020.in","anikendra.das@shop2020.in"};
|
|
|
86 |
List<String> flipkartorderids = null;
|
|
|
87 |
Client catalogServiceClient = null;
|
|
|
88 |
try {
|
|
|
89 |
catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port").getClient();
|
|
|
90 |
} catch (TTransportException e) {
|
|
|
91 |
e.printStackTrace();
|
|
|
92 |
}
|
|
|
93 |
try {
|
|
|
94 |
flipkartItems = catalogServiceClient.getAllFlipkartItems();
|
|
|
95 |
snapdealItems = catalogServiceClient.getAllSnapdealItems();
|
|
|
96 |
} catch (TException e) {
|
|
|
97 |
e.printStackTrace();
|
|
|
98 |
}
|
|
|
99 |
for(FlipkartItem flipkartItem:flipkartItems){
|
|
|
100 |
if(flipkartItem.isIsListedOnFlipkart() && !flipkartItem.isSuppressInventoryFeed())
|
|
|
101 |
flipkartInventoryItems.add(flipkartItem);
|
|
|
102 |
}
|
|
|
103 |
for(SnapdealItemDetails snapdealItem:snapdealItems){
|
|
|
104 |
snapdealItemsMap.put(snapdealItem.getItem_id(),snapdealItem);
|
|
|
105 |
}
|
|
|
106 |
if(flipkartInventoryItems.size()==0){
|
|
|
107 |
String text = "";
|
|
|
108 |
try {
|
|
|
109 |
mailer.sendSSLMessage(sendTo,"No items to send inventory ", emailFromAddress, password, text);
|
|
|
110 |
System.exit(0);
|
|
|
111 |
} catch (MessagingException e) {
|
|
|
112 |
e.printStackTrace();
|
|
|
113 |
}
|
|
|
114 |
}
|
|
|
115 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient = null;
|
|
|
116 |
try {
|
|
|
117 |
flipkartorderids = FetchOrders();
|
|
|
118 |
} catch (ClientProtocolException e1) {
|
|
|
119 |
e1.printStackTrace();
|
|
|
120 |
} catch (IOException e1) {
|
|
|
121 |
e1.printStackTrace();
|
|
|
122 |
}
|
|
|
123 |
try {
|
|
|
124 |
transactionClient = new TransactionClient().getClient();
|
|
|
125 |
if(flipkartorderids!=null && flipkartorderids.size()>0){
|
|
|
126 |
itemIdOrdersMap = transactionClient.getCreatedOrdersForFlipkart(flipkartorderids);
|
|
|
127 |
}
|
|
|
128 |
} catch (TTransportException e) {
|
|
|
129 |
try {
|
|
|
130 |
itemIdOrdersMap = transactionClient.getCreatedOrdersForFlipkart(flipkartorderids);
|
|
|
131 |
} catch (TException e1) {
|
|
|
132 |
e1.printStackTrace();
|
|
|
133 |
}
|
|
|
134 |
}catch (TException e) {
|
|
|
135 |
e.printStackTrace();
|
|
|
136 |
}
|
|
|
137 |
try {
|
|
|
138 |
List<FlipkartInventorySnapshot> updatedFlipkartInventoryList = new InventoryClient().getClient().getFlipkartInventorySnapshot();
|
|
|
139 |
for(FlipkartInventorySnapshot updatedFlipkartInventory:updatedFlipkartInventoryList){
|
|
|
140 |
updatedFlipkartInventoryMap.put(updatedFlipkartInventory.getItem_id(),updatedFlipkartInventory.getAvailability());
|
|
|
141 |
}
|
|
|
142 |
} catch (TException e) {
|
|
|
143 |
e.printStackTrace();
|
|
|
144 |
}
|
|
|
145 |
catch(Exception e){
|
|
|
146 |
List<FlipkartInventorySnapshot> updatedFlipkartInventoryList = null;
|
|
|
147 |
try {
|
|
|
148 |
updatedFlipkartInventoryList = new InventoryClient().getClient().getFlipkartInventorySnapshot();
|
|
|
149 |
} catch (TTransportException e1) {
|
|
|
150 |
e1.printStackTrace();
|
|
|
151 |
} catch (TException e1) {
|
|
|
152 |
e1.printStackTrace();
|
|
|
153 |
}
|
|
|
154 |
if(updatedFlipkartInventoryList != null){
|
|
|
155 |
for(FlipkartInventorySnapshot updatedFlipkartInventory:updatedFlipkartInventoryList){
|
|
|
156 |
updatedFlipkartInventoryMap.put(updatedFlipkartInventory.getItem_id(),updatedFlipkartInventory.getAvailability());
|
|
|
157 |
}
|
|
|
158 |
}
|
|
|
159 |
}
|
| 9947 |
vikram.rag |
160 |
|
| 10122 |
vikram.rag |
161 |
|
| 9947 |
vikram.rag |
162 |
}
|
|
|
163 |
|
| 9967 |
vikram.rag |
164 |
public static void main(String[] args) throws ClientProtocolException, TException{
|
| 9947 |
vikram.rag |
165 |
calculateinventory();
|
|
|
166 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
| 11440 |
vikram.rag |
167 |
//httpclient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpclient);
|
| 10051 |
vikram.rag |
168 |
//httpclient.getCredentialsProvider().setCredentials(
|
|
|
169 |
// new AuthScope("sandbox-api.flipkart.net", 443),
|
|
|
170 |
// new UsernamePasswordCredentials("og3yg5994bxbxxc1", "8a137068-417c-4e4f-ae95-9295ab938d88"));/// Test Server Access Keys
|
| 11440 |
vikram.rag |
171 |
//httpclient.getCredentialsProvider().setCredentials(
|
|
|
172 |
// new AuthScope("api.flipkart.net", 443),
|
|
|
173 |
// new UsernamePasswordCredentials("m2z93iskuj81qiid","0c7ab6a5-98c0-4cdc-8be3-72c591e0add4")); //Prod Server Access Keys
|
| 11448 |
vikram.rag |
174 |
|
| 10051 |
vikram.rag |
175 |
HttpPost httppost = new HttpPost("https://api.flipkart.net/sellers/skus/listings/bulk"); // PROD
|
| 11448 |
vikram.rag |
176 |
|
| 11442 |
vikram.rag |
177 |
String auth = "m2z93iskuj81qiid"+":"+"0c7ab6a5-98c0-4cdc-8be3-72c591e0add4";
|
|
|
178 |
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("US-ASCII")));
|
|
|
179 |
String authHeader = "Basic " + new String(encodedAuth);
|
|
|
180 |
httppost.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
|
| 10051 |
vikram.rag |
181 |
//HttpPost httppost = new HttpPost("https://sandbox-api.flipkart.net/sellers/skus/listings/bulk"); // TEST
|
| 9947 |
vikram.rag |
182 |
StringBuffer jsonRequest = new StringBuffer();
|
| 9983 |
vikram.rag |
183 |
StringBuffer jsonStart = new StringBuffer();
|
|
|
184 |
jsonStart = jsonStart.append("{\"listings\":[");
|
|
|
185 |
StringBuffer jsonEnd = new StringBuffer();
|
|
|
186 |
jsonEnd.append("]}");
|
| 9947 |
vikram.rag |
187 |
//System.out.println("JSON request " + jsonRequest);
|
|
|
188 |
LogisticsClient logisticsServiceClient;
|
|
|
189 |
in.shop2020.logistics.LogisticsService.Client logisticsClient=null;
|
|
|
190 |
LogisticsInfo logisticinfo = null;
|
|
|
191 |
try {
|
| 10154 |
vikram.rag |
192 |
logisticsServiceClient = new LogisticsClient();
|
| 9947 |
vikram.rag |
193 |
logisticsClient = logisticsServiceClient.getClient();
|
|
|
194 |
|
|
|
195 |
} catch (TTransportException e) {
|
|
|
196 |
e.printStackTrace();
|
|
|
197 |
}
|
|
|
198 |
long stock=0;
|
|
|
199 |
int i=0;
|
| 10176 |
vikram.rag |
200 |
long available,reserve,heldforsource,totalheld,allocable,holdinventory,defaultinventory,actualstock = 0,orders,heldorders;
|
|
|
201 |
float allocation;
|
| 9983 |
vikram.rag |
202 |
StringBuffer inventoryItems =new StringBuffer();
|
| 10122 |
vikram.rag |
203 |
StringBuffer backInStockItems =new StringBuffer();
|
|
|
204 |
StringBuffer outOfStockItems =new StringBuffer();
|
| 9983 |
vikram.rag |
205 |
String tableHeader = "<html><table border=\"1\" align=\"center\"><tr>"
|
|
|
206 |
+ "<td><b>" + "Product Name" +"</b></td>"
|
|
|
207 |
+"<td><b>" + "Item ID" + "</b></td>"
|
|
|
208 |
+"<td><b>" + "Inventory" + "</b></td>"
|
|
|
209 |
+"<td><b>" + "Orders Added to Inventory" + "</b></td>"
|
|
|
210 |
+"<td><b>" + "Sent Inventory" + "</b></td>"
|
| 10049 |
vikram.rag |
211 |
+"<td><b>" + "Procurement SLA" + "</b></td>"
|
|
|
212 |
+"<td><b>" + "Orders on Hold" + "</b></td>"
|
| 9983 |
vikram.rag |
213 |
+"</tr>";
|
| 10159 |
vikram.rag |
214 |
|
| 9983 |
vikram.rag |
215 |
String tableFooter = "</table></html>";
|
|
|
216 |
Item item;
|
| 10027 |
vikram.rag |
217 |
StringBuffer feedResponse= new StringBuffer();
|
| 10049 |
vikram.rag |
218 |
List<FlipkartInventorySnapshot> inventorysnapshotlist = new ArrayList<FlipkartInventorySnapshot>();
|
| 10450 |
vikram.rag |
219 |
long timestamp = System.currentTimeMillis();
|
| 9947 |
vikram.rag |
220 |
for(Entry<Long, FlipkartInventoryItem> entry:flipkartItemsInventoryMap.entrySet()){
|
| 10174 |
vikram.rag |
221 |
if(snapdealItemsMap.containsKey(entry.getKey()) && snapdealItemsMap.get(entry.getKey()).isIsListedOnSnapdeal()){
|
| 10306 |
vikram.rag |
222 |
allocation = (float) 0.33;
|
| 10174 |
vikram.rag |
223 |
}
|
|
|
224 |
else{
|
| 10306 |
vikram.rag |
225 |
allocation = (float) 0.67;
|
| 10174 |
vikram.rag |
226 |
}
|
| 9985 |
vikram.rag |
227 |
actualstock=0;
|
|
|
228 |
orders=0;
|
|
|
229 |
stock=0;
|
| 10049 |
vikram.rag |
230 |
heldorders=0;
|
| 9947 |
vikram.rag |
231 |
available = entry.getValue().getAvailability();
|
|
|
232 |
reserve = entry.getValue().getReserve();
|
|
|
233 |
heldforsource = entry.getValue().getHeldForSource();
|
|
|
234 |
totalheld = entry.getValue().getTotalHeldInventory();
|
|
|
235 |
holdinventory = entry.getValue().getHoldInventory();
|
|
|
236 |
defaultinventory = entry.getValue().getDefaultInventory();
|
| 9987 |
vikram.rag |
237 |
System.out.println("Item ID " + entry.getKey());
|
|
|
238 |
System.out.println("Available " + available);
|
|
|
239 |
System.out.println("Reserve " + reserve);
|
|
|
240 |
System.out.println("Held For Source " + heldforsource);
|
|
|
241 |
System.out.println("Total Held " + totalheld);
|
|
|
242 |
System.out.println("General Hold " + holdinventory );
|
|
|
243 |
System.out.println("Default Inventory " + defaultinventory);
|
| 9947 |
vikram.rag |
244 |
if(!entry.getValue().getStatus().equals(status.PAUSED)){
|
|
|
245 |
if(entry.getValue().getRisky()){
|
|
|
246 |
if((available - reserve) < totalheld && totalheld!=0){
|
|
|
247 |
stock = (long) Math.floor(((available - reserve)*heldforsource/totalheld));
|
|
|
248 |
}
|
|
|
249 |
else{
|
|
|
250 |
allocable = available - reserve - totalheld - holdinventory;
|
|
|
251 |
if(allocable < 0){
|
|
|
252 |
allocable = 0;
|
|
|
253 |
}
|
| 10174 |
vikram.rag |
254 |
stock = Math.round(allocable*allocation) + heldforsource;
|
| 9947 |
vikram.rag |
255 |
}
|
|
|
256 |
|
|
|
257 |
}
|
|
|
258 |
else{
|
|
|
259 |
allocable = available - reserve - totalheld;
|
|
|
260 |
if(allocable < 0){
|
|
|
261 |
allocable = 0;
|
|
|
262 |
}
|
|
|
263 |
if((allocable + heldforsource ) > defaultinventory){
|
| 10174 |
vikram.rag |
264 |
stock = Math.round(allocable*allocation) + heldforsource;
|
| 9947 |
vikram.rag |
265 |
}
|
|
|
266 |
else{
|
|
|
267 |
stock = defaultinventory;
|
|
|
268 |
}
|
|
|
269 |
}
|
|
|
270 |
System.out.println("Item ID " + entry.getKey()+" Stock "+stock +" Orders " + itemIdOrdersMap.get(entry.getKey()));
|
| 9992 |
vikram.rag |
271 |
actualstock = stock;
|
| 9971 |
vikram.rag |
272 |
if(itemIdOrdersMap!=null && itemIdOrdersMap.containsKey(entry.getKey())){
|
| 9977 |
vikram.rag |
273 |
stock = stock + itemIdOrdersMap.get(entry.getKey());
|
| 9983 |
vikram.rag |
274 |
orders = itemIdOrdersMap.get(entry.getKey());
|
| 9947 |
vikram.rag |
275 |
}
|
|
|
276 |
if(stock<0){
|
|
|
277 |
stock =0;
|
|
|
278 |
}
|
| 9977 |
vikram.rag |
279 |
else{
|
|
|
280 |
if(stock > 25){
|
|
|
281 |
stock=25;
|
|
|
282 |
}
|
|
|
283 |
}
|
| 9947 |
vikram.rag |
284 |
}
|
|
|
285 |
else{
|
|
|
286 |
stock =0;
|
|
|
287 |
}
|
|
|
288 |
try {
|
|
|
289 |
logisticinfo = logisticsClient.getLogisticsEstimation(entry.getValue().getId(),"110001",DeliveryType.COD);
|
|
|
290 |
} catch (LogisticsServiceException e) {
|
|
|
291 |
e.printStackTrace();
|
|
|
292 |
continue;
|
|
|
293 |
}
|
| 10029 |
vikram.rag |
294 |
catch (TTransportException e) {
|
| 10154 |
vikram.rag |
295 |
logisticsServiceClient = new LogisticsClient();
|
| 10029 |
vikram.rag |
296 |
logisticsClient = logisticsServiceClient.getClient();
|
|
|
297 |
}
|
| 10107 |
vikram.rag |
298 |
System.out.println("sku at flipkart " + entry.getValue().getSkuAtflipkart());
|
|
|
299 |
System.out.println("shipping time " + logisticinfo.getShippingTime());
|
|
|
300 |
System.out.println("stock " + stock);
|
| 11649 |
vikram.rag |
301 |
if(logisticinfo.getShippingTime() > 5 && stock > 0){
|
|
|
302 |
jsonRequest.append("{\"skuId\":"+"\""+entry.getValue().getSkuAtflipkart()+
|
|
|
303 |
"\","+"\"attributeValues\""+":"+
|
| 11650 |
vikram.rag |
304 |
"{\"procurement_sla\""+":"+"\""+"5"+
|
| 11649 |
vikram.rag |
305 |
"\","+"\"stock_count\""+":"+"\""+"0"+"\""+"}}");
|
|
|
306 |
}
|
|
|
307 |
else{
|
|
|
308 |
jsonRequest.append("{\"skuId\":"+"\""+entry.getValue().getSkuAtflipkart()+
|
|
|
309 |
"\","+"\"attributeValues\""+":"+
|
|
|
310 |
"{\"procurement_sla\""+":"+"\""+logisticinfo.getShippingTime()+
|
|
|
311 |
"\","+"\"stock_count\""+":"+"\""+stock+"\""+"}}");
|
|
|
312 |
}
|
| 10049 |
vikram.rag |
313 |
FlipkartInventorySnapshot inventorySnapshot = new FlipkartInventorySnapshot();
|
|
|
314 |
inventorySnapshot.setItem_id(entry.getKey());
|
|
|
315 |
inventorySnapshot.setAvailability(stock);
|
| 10450 |
vikram.rag |
316 |
if(stock > 0){
|
|
|
317 |
inventorySnapshot.setIs_oos(false);
|
|
|
318 |
}
|
|
|
319 |
else{
|
|
|
320 |
inventorySnapshot.setIs_oos(true);
|
|
|
321 |
}
|
| 10049 |
vikram.rag |
322 |
if(heldOrdersMap.containsKey(entry.getValue().getSkuAtflipkart())){
|
|
|
323 |
inventorySnapshot.setHeldOrders(heldOrdersMap.get(entry.getValue().getSkuAtflipkart()));
|
| 10060 |
vikram.rag |
324 |
heldorders = heldOrdersMap.get(entry.getValue().getSkuAtflipkart());
|
| 10049 |
vikram.rag |
325 |
}
|
|
|
326 |
else{
|
|
|
327 |
inventorySnapshot.setHeldOrders(0);
|
|
|
328 |
}
|
|
|
329 |
inventorySnapshot.setCreatedOrders(orders);
|
|
|
330 |
inventorysnapshotlist.add(inventorySnapshot);
|
| 9983 |
vikram.rag |
331 |
item = aliveItemsMap.get(entry.getValue().getId());
|
| 11004 |
vikram.rag |
332 |
System.out.println("++++++++++++++++++Before checking > 5 SLA+++++++++++++++++++++++++++++");
|
| 11000 |
vikram.rag |
333 |
if(logisticinfo.getShippingTime() > 5 && stock > 0){
|
| 11005 |
vikram.rag |
334 |
System.out.println("Product : "+getProductName(item)+" Item ID : " + item.getId() + " Stock : " + stock +" "+ " SLA : " + logisticinfo.getShippingTime());
|
|
|
335 |
stock = 0;
|
| 11000 |
vikram.rag |
336 |
}
|
| 11004 |
vikram.rag |
337 |
System.out.println("++++++++++++++++++++After checking > 5 SLA++++++++++++++++++++++++");
|
| 11448 |
vikram.rag |
338 |
|
| 10160 |
vikram.rag |
339 |
if(!updatedFlipkartInventoryMap.containsKey(entry.getKey())){
|
| 10122 |
vikram.rag |
340 |
inventoryItems.append("<tr>"
|
|
|
341 |
+ "<td>" +getProductName(item)+"</td>"
|
|
|
342 |
+"<td>" + item.getId() + "</td>"
|
|
|
343 |
+"<td>" + actualstock + "</td>"
|
|
|
344 |
+"<td>" + orders + "</td>"
|
|
|
345 |
+"<td>" + stock + "</td>"
|
|
|
346 |
+"<td>" + logisticinfo.getShippingTime() + "</td>"
|
|
|
347 |
+"<td>" + heldorders + "</td>"
|
|
|
348 |
+"</tr>");
|
|
|
349 |
}
|
| 10160 |
vikram.rag |
350 |
else if(updatedFlipkartInventoryMap.containsKey(entry.getKey()) && updatedFlipkartInventoryMap.get(entry.getKey()) != stock){
|
|
|
351 |
inventoryItems.append("<tr>"
|
|
|
352 |
+ "<td>" +getProductName(item)+"</td>"
|
|
|
353 |
+"<td>" + item.getId() + "</td>"
|
|
|
354 |
+"<td>" + actualstock + "</td>"
|
|
|
355 |
+"<td>" + orders + "</td>"
|
|
|
356 |
+"<td>" + stock + "</td>"
|
|
|
357 |
+"<td>" + logisticinfo.getShippingTime() + "</td>"
|
|
|
358 |
+"<td>" + heldorders + "</td>"
|
|
|
359 |
+"</tr>");
|
|
|
360 |
}
|
| 10122 |
vikram.rag |
361 |
if(updatedFlipkartInventoryMap.containsKey(entry.getKey()) && updatedFlipkartInventoryMap.get(entry.getKey()) == 0 && stock!=0){
|
|
|
362 |
backInStockItems.append("<tr>"
|
|
|
363 |
+ "<td>" +getProductName(item)+"</td>"
|
|
|
364 |
+"<td>" + item.getId() + "</td>"
|
|
|
365 |
+"<td>" + actualstock + "</td>"
|
|
|
366 |
+"<td>" + orders + "</td>"
|
|
|
367 |
+"<td>" + stock + "</td>"
|
|
|
368 |
+"<td>" + logisticinfo.getShippingTime() + "</td>"
|
|
|
369 |
+"<td>" + heldorders + "</td>"
|
|
|
370 |
+"</tr>");
|
|
|
371 |
}
|
|
|
372 |
if(updatedFlipkartInventoryMap.containsKey(entry.getKey()) && updatedFlipkartInventoryMap.get(entry.getKey()) != 0 && stock==0){
|
|
|
373 |
outOfStockItems.append("<tr>"
|
|
|
374 |
+ "<td>" +getProductName(item)+"</td>"
|
|
|
375 |
+"<td>" + item.getId() + "</td>"
|
|
|
376 |
+"<td>" + actualstock + "</td>"
|
|
|
377 |
+"<td>" + orders + "</td>"
|
|
|
378 |
+"<td>" + stock + "</td>"
|
|
|
379 |
+"<td>" + logisticinfo.getShippingTime() + "</td>"
|
|
|
380 |
+"<td>" + heldorders + "</td>"
|
|
|
381 |
+"</tr>");
|
|
|
382 |
}
|
| 10028 |
vikram.rag |
383 |
i++;
|
|
|
384 |
if(flipkartItemsInventoryMap.entrySet().size()!=1 && (i!=flipkartItemsInventoryMap.entrySet().size()) ){
|
| 11862 |
vikram.rag |
385 |
if(i%10!=0){
|
| 10026 |
vikram.rag |
386 |
jsonRequest.append(",");
|
|
|
387 |
}
|
| 9947 |
vikram.rag |
388 |
}
|
| 11862 |
vikram.rag |
389 |
if(i%10==0 || i==flipkartItemsInventoryMap.entrySet().size()){
|
| 9968 |
vikram.rag |
390 |
StringEntity input = null;
|
|
|
391 |
try {
|
| 9983 |
vikram.rag |
392 |
input = new StringEntity(jsonStart+jsonRequest.toString()+jsonEnd);
|
|
|
393 |
System.out.println("Json input " + jsonStart+jsonRequest.toString()+jsonEnd);
|
|
|
394 |
jsonRequest = new StringBuffer();
|
| 9968 |
vikram.rag |
395 |
} catch (UnsupportedEncodingException e) {
|
|
|
396 |
e.printStackTrace();
|
|
|
397 |
}
|
| 9947 |
vikram.rag |
398 |
input.setContentType("application/json");
|
| 10049 |
vikram.rag |
399 |
|
| 9947 |
vikram.rag |
400 |
httppost.setEntity(input);
|
| 9968 |
vikram.rag |
401 |
HttpResponse response = null;
|
|
|
402 |
try {
|
| 9970 |
vikram.rag |
403 |
System.out.println("Before send " );
|
| 9968 |
vikram.rag |
404 |
response = httpclient.execute(httppost);
|
| 9970 |
vikram.rag |
405 |
System.out.println("After send " );
|
| 9968 |
vikram.rag |
406 |
} catch (IOException e) {
|
|
|
407 |
e.printStackTrace();
|
|
|
408 |
}
|
| 9969 |
vikram.rag |
409 |
BufferedReader rd = null;
|
| 9968 |
vikram.rag |
410 |
try {
|
|
|
411 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
| 11862 |
vikram.rag |
412 |
if(!rd.readLine().equalsIgnoreCase("{\"status\":\"success\"}")){
|
|
|
413 |
System.out.println("Before send " );
|
|
|
414 |
httpclient = new DefaultHttpClient();
|
|
|
415 |
response = httpclient.execute(httppost);
|
|
|
416 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
417 |
}
|
| 9968 |
vikram.rag |
418 |
} catch (IllegalStateException e) {
|
|
|
419 |
e.printStackTrace();
|
|
|
420 |
} catch (IOException e) {
|
|
|
421 |
e.printStackTrace();
|
|
|
422 |
}
|
| 9947 |
vikram.rag |
423 |
String line;
|
| 10049 |
vikram.rag |
424 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryServiceClient;
|
| 9969 |
vikram.rag |
425 |
try {
|
|
|
426 |
while ((line = rd.readLine()) != null) {
|
|
|
427 |
System.out.println("Response " + line);
|
| 9983 |
vikram.rag |
428 |
if(line.equalsIgnoreCase("{\"status\":\"success\"}")){
|
| 10154 |
vikram.rag |
429 |
inventoryServiceClient = new InventoryClient().getClient();
|
| 10158 |
vikram.rag |
430 |
try{
|
| 10450 |
vikram.rag |
431 |
inventoryServiceClient.addOrUpdateFlipkartInventorySnapshot(inventorysnapshotlist,timestamp);
|
| 10158 |
vikram.rag |
432 |
}
|
|
|
433 |
catch(TTransportException e){
|
|
|
434 |
inventoryServiceClient = new InventoryClient().getClient();
|
| 10450 |
vikram.rag |
435 |
inventoryServiceClient.addOrUpdateFlipkartInventorySnapshot(inventorysnapshotlist,timestamp);
|
| 10158 |
vikram.rag |
436 |
}
|
| 10049 |
vikram.rag |
437 |
inventorysnapshotlist = new ArrayList<FlipkartInventorySnapshot>();
|
| 9983 |
vikram.rag |
438 |
}
|
|
|
439 |
else{
|
|
|
440 |
feedResponse.append(line);
|
|
|
441 |
}
|
| 10049 |
vikram.rag |
442 |
|
| 9969 |
vikram.rag |
443 |
}
|
|
|
444 |
} catch (IOException e) {
|
|
|
445 |
e.printStackTrace();
|
| 9947 |
vikram.rag |
446 |
}
|
|
|
447 |
}
|
|
|
448 |
}
|
| 9983 |
vikram.rag |
449 |
System.out.println("Before sending email");
|
| 10179 |
vikram.rag |
450 |
if(feedResponse.toString().length()>0){
|
|
|
451 |
try {
|
|
|
452 |
mailer.sendSSLMessage(sendTo, "Flipkart Inventory could not be updated " + sdf.format(System.currentTimeMillis()), feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
|
| 10181 |
vikram.rag |
453 |
} catch (Exception e) {
|
| 10183 |
vikram.rag |
454 |
emailFromAddress = "build-staging@shop2020.in";
|
|
|
455 |
password = "shop2020";
|
| 10179 |
vikram.rag |
456 |
try {
|
|
|
457 |
mailer.sendSSLMessage(sendTo, "Flipkart Inventory could not be updated " + sdf.format(System.currentTimeMillis()), feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
|
|
|
458 |
} catch (MessagingException e1) {
|
|
|
459 |
e1.printStackTrace();
|
|
|
460 |
}
|
|
|
461 |
e.printStackTrace();
|
|
|
462 |
}
|
|
|
463 |
}
|
|
|
464 |
else{
|
|
|
465 |
try {
|
|
|
466 |
mailer.sendSSLMessage(sendTo, "Flipkart Inventory updated successfully " + sdf.format(System.currentTimeMillis()), feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
|
|
|
467 |
} catch (MessagingException e) {
|
| 10183 |
vikram.rag |
468 |
emailFromAddress = "build-staging@shop2020.in";
|
|
|
469 |
password = "shop2020";
|
| 10179 |
vikram.rag |
470 |
try {
|
|
|
471 |
mailer.sendSSLMessage(sendTo, "Flipkart Inventory updated successfully " + sdf.format(System.currentTimeMillis()), feedResponse.toString(), emailFromAddress, password,new ArrayList<File>());
|
|
|
472 |
} catch (MessagingException e1) {
|
|
|
473 |
e1.printStackTrace();
|
|
|
474 |
}
|
|
|
475 |
e.printStackTrace();
|
|
|
476 |
}
|
|
|
477 |
}
|
|
|
478 |
|
|
|
479 |
String text;
|
| 10159 |
vikram.rag |
480 |
if(inventoryItems.toString().length()>0){
|
| 10179 |
vikram.rag |
481 |
text = tableHeader+inventoryItems.toString()+tableFooter;
|
| 10159 |
vikram.rag |
482 |
try {
|
|
|
483 |
mailer.sendSSLMessage(sendTo,"Flipkart Inventory Sent Details " + sdf.format(System.currentTimeMillis()), emailFromAddress, password, text);
|
|
|
484 |
} catch (MessagingException e) {
|
|
|
485 |
e.printStackTrace();
|
|
|
486 |
}
|
| 9983 |
vikram.rag |
487 |
}
|
| 10122 |
vikram.rag |
488 |
if(backInStockItems.toString().length()>0){
|
|
|
489 |
try {
|
|
|
490 |
text = tableHeader+backInStockItems.toString()+tableFooter;
|
| 10123 |
vikram.rag |
491 |
mailer.sendSSLMessage(sendTo,"Flipkart Inventory Back in Stock " + sdf.format(System.currentTimeMillis()), emailFromAddress, password, text);
|
| 10122 |
vikram.rag |
492 |
} catch (MessagingException e) {
|
|
|
493 |
e.printStackTrace();
|
|
|
494 |
}
|
| 10159 |
vikram.rag |
495 |
|
| 10122 |
vikram.rag |
496 |
}
|
|
|
497 |
if(outOfStockItems.toString().length()>0){
|
|
|
498 |
try {
|
|
|
499 |
text = tableHeader+outOfStockItems.toString()+tableFooter;
|
| 10123 |
vikram.rag |
500 |
mailer.sendSSLMessage(sendTo,"Flipkart Inventory Out of Stock " + sdf.format(System.currentTimeMillis()), emailFromAddress, password, text);
|
| 10122 |
vikram.rag |
501 |
} catch (MessagingException e) {
|
|
|
502 |
e.printStackTrace();
|
|
|
503 |
}
|
| 10159 |
vikram.rag |
504 |
|
| 10122 |
vikram.rag |
505 |
}
|
| 9947 |
vikram.rag |
506 |
}
|
| 9983 |
vikram.rag |
507 |
|
| 9947 |
vikram.rag |
508 |
private static void calculateinventory(){
|
|
|
509 |
CatalogClient catalogServiceClient = null;
|
|
|
510 |
Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
|
|
|
511 |
try {
|
| 10154 |
vikram.rag |
512 |
catalogServiceClient = new CatalogClient("catalog_service_server_host_amazon","catalog_service_server_port");
|
| 9947 |
vikram.rag |
513 |
} catch (TTransportException e) {
|
|
|
514 |
e.printStackTrace();
|
|
|
515 |
}
|
|
|
516 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
517 |
try {
|
|
|
518 |
List<Item> aliveItems = catalogClient.getAllAliveItems();
|
|
|
519 |
for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
|
|
|
520 |
aliveItemsMap.put(thriftItem.getId(), thriftItem);
|
|
|
521 |
|
|
|
522 |
}
|
|
|
523 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
|
|
524 |
try {
|
|
|
525 |
inventoryServiceClient = new InventoryClient();
|
|
|
526 |
} catch (TTransportException e) {
|
|
|
527 |
e.printStackTrace();
|
|
|
528 |
}
|
|
|
529 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
|
|
530 |
List<in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems> ignoreItems = inventoryClient.getIgnoredWarehouseidsAndItemids();
|
|
|
531 |
availability = inventoryClient.getInventorySnapshot(0);
|
|
|
532 |
List<Warehouse> allwarehouses = inventoryClient.getWarehouses(null,null,0,0,0);
|
|
|
533 |
Map<Long,Warehouse> allWarehousesMap = new HashMap<Long,Warehouse>();
|
|
|
534 |
for(Warehouse warehouse:allwarehouses){
|
|
|
535 |
allWarehousesMap.put(warehouse.getId(),warehouse);
|
|
|
536 |
}
|
|
|
537 |
List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS_THIRDPARTY,null,0,0,0);
|
|
|
538 |
List<Warehouse> ours_warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 0, 0, 0);
|
|
|
539 |
List<Long> thirdpartywarehouseids = new ArrayList<Long>();
|
|
|
540 |
List<Long> oursGoodWarehouse = new ArrayList<Long>();
|
|
|
541 |
for(Warehouse warehouse:warehouses){
|
|
|
542 |
thirdpartywarehouseids.add(warehouse.getId());
|
|
|
543 |
}
|
|
|
544 |
for (Warehouse warehouse:ours_warehouses){
|
|
|
545 |
oursGoodWarehouse.add(warehouse.getId());
|
|
|
546 |
}
|
|
|
547 |
long available=0;
|
|
|
548 |
long reserve=0;
|
|
|
549 |
long total_warehouse_held=0;
|
|
|
550 |
long heldForSource=0;
|
|
|
551 |
long total_held=0;
|
|
|
552 |
double nlc=0;
|
|
|
553 |
double maxnlc=0;
|
|
|
554 |
Item thriftItem;
|
|
|
555 |
for(FlipkartItem flipkartItem:flipkartInventoryItems){
|
|
|
556 |
if(aliveItemsMap.get(flipkartItem.getItem_id()) != null){
|
|
|
557 |
thriftItem = aliveItemsMap.get(flipkartItem.getItem_id());
|
|
|
558 |
}
|
|
|
559 |
else{
|
|
|
560 |
continue;
|
|
|
561 |
}
|
|
|
562 |
available=0;
|
|
|
563 |
reserve=0;
|
|
|
564 |
total_warehouse_held=0;
|
|
|
565 |
heldForSource=0;
|
|
|
566 |
total_held=0;
|
|
|
567 |
nlc=0;
|
|
|
568 |
List<Warehouse> vendor_warehouses=null;
|
|
|
569 |
FlipkartInventoryItem item;
|
|
|
570 |
if(availability.get(thriftItem.getId())!=null){
|
|
|
571 |
ItemInventory iteminventory = availability.get(thriftItem.getId());
|
|
|
572 |
Map<Long,Long> itemavailability = new HashMap<Long,Long>();
|
|
|
573 |
itemavailability = iteminventory.getAvailability();
|
|
|
574 |
if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
|
|
|
575 |
//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating availability)"+thriftItem.getPreferredVendor());
|
|
|
576 |
vendor_warehouses = inventoryClient.getWarehouses(WarehouseType.THIRD_PARTY,InventoryType.GOOD , thriftItem.getPreferredVendor(), 0, 0);
|
|
|
577 |
vendor_warehouses.addAll(ours_warehouses);
|
|
|
578 |
for (Warehouse warehouse:vendor_warehouses){
|
|
|
579 |
if(warehouse.getBillingWarehouseId()!=7){
|
|
|
580 |
if(warehouse.getLogisticsLocation().equals(WarehouseLocation.Delhi) && warehouse.getWarehouseType().equals(WarehouseType.THIRD_PARTY) && warehouse.getVendor().getId()!=1){
|
|
|
581 |
|
|
|
582 |
}
|
|
|
583 |
else{
|
|
|
584 |
continue;
|
|
|
585 |
}
|
|
|
586 |
}
|
|
|
587 |
in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
|
|
|
588 |
ignoredItem.setItemId(thriftItem.getId());
|
|
|
589 |
ignoredItem.setWarehouseId(warehouse.getId());
|
|
|
590 |
if (itemavailability.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(ignoredItem)){
|
|
|
591 |
try{
|
|
|
592 |
nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
|
|
|
593 |
}
|
|
|
594 |
catch(TTransportException e){
|
|
|
595 |
inventoryClient = inventoryServiceClient.getClient();
|
|
|
596 |
nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
|
|
|
597 |
}
|
|
|
598 |
maxnlc = flipkartItem.getMaxNlc();
|
|
|
599 |
|
|
|
600 |
//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
|
|
|
601 |
if(nlc !=0 && (maxnlc >= nlc)){
|
|
|
602 |
total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
|
|
|
603 |
heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 8);
|
|
|
604 |
available = available + itemavailability.get(warehouse.getId());
|
|
|
605 |
total_held = total_held + total_warehouse_held;
|
|
|
606 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
|
|
|
607 |
}
|
|
|
608 |
else if(maxnlc==0){
|
|
|
609 |
total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
|
|
|
610 |
heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 8);
|
|
|
611 |
available = available + itemavailability.get(warehouse.getId());
|
|
|
612 |
total_held = total_held + total_warehouse_held;
|
|
|
613 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
|
|
|
614 |
}
|
|
|
615 |
}
|
|
|
616 |
}
|
|
|
617 |
}
|
|
|
618 |
else{
|
|
|
619 |
for (Map.Entry<Long,Long> entry : itemavailability.entrySet()) {
|
|
|
620 |
if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
|
|
|
621 |
if(allWarehousesMap.get(entry.getKey()).getLogisticsLocation().equals(WarehouseLocation.Delhi) && allWarehousesMap.get(entry.getKey()).getWarehouseType().equals(WarehouseType.THIRD_PARTY) && allWarehousesMap.get(entry.getKey()).getVendor().getId()!=1){
|
|
|
622 |
|
|
|
623 |
}
|
|
|
624 |
else{
|
|
|
625 |
continue;
|
|
|
626 |
}
|
|
|
627 |
}
|
|
|
628 |
in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
|
|
|
629 |
ignoredItem.setItemId(thriftItem.getId());
|
|
|
630 |
ignoredItem.setWarehouseId(entry.getKey());
|
|
|
631 |
if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
|
|
|
632 |
|
|
|
633 |
nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
|
|
|
634 |
maxnlc = flipkartItem.getMaxNlc();
|
|
|
635 |
//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
|
|
|
636 |
if(nlc !=0 && (maxnlc >= nlc)){
|
|
|
637 |
total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
|
|
|
638 |
heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 8);
|
|
|
639 |
available = available + entry.getValue();
|
|
|
640 |
total_held = total_held + total_warehouse_held;
|
|
|
641 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
|
|
|
642 |
}
|
|
|
643 |
else if(maxnlc==0){
|
|
|
644 |
total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
|
|
|
645 |
heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 8);
|
|
|
646 |
available = available + itemavailability.get(entry.getKey());
|
|
|
647 |
total_held = total_held + total_warehouse_held;
|
|
|
648 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
|
|
|
649 |
}
|
|
|
650 |
|
|
|
651 |
}
|
|
|
652 |
}
|
|
|
653 |
}
|
|
|
654 |
Map<Long,Long> itemreserve = new HashMap<Long,Long>();
|
|
|
655 |
itemreserve = iteminventory.getReserved();
|
|
|
656 |
if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
|
|
|
657 |
//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating Reserve)"+thriftItem.getPreferredVendor());
|
|
|
658 |
for (Warehouse warehouse:vendor_warehouses){
|
|
|
659 |
if(warehouse.getBillingWarehouseId()!=7){
|
|
|
660 |
if(warehouse.getLogisticsLocation().equals(WarehouseLocation.Delhi) && warehouse.getWarehouseType().equals(WarehouseType.THIRD_PARTY) && warehouse.getVendor().getId()!=1){
|
|
|
661 |
|
|
|
662 |
}
|
|
|
663 |
else{
|
|
|
664 |
continue;
|
|
|
665 |
}
|
|
|
666 |
}
|
|
|
667 |
in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
|
|
|
668 |
ignoredItem.setItemId(thriftItem.getId());
|
|
|
669 |
ignoredItem.setWarehouseId(warehouse.getId());
|
|
|
670 |
if (itemreserve.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(warehouse.getId())){
|
|
|
671 |
nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
|
|
|
672 |
maxnlc = flipkartItem.getMaxNlc();
|
|
|
673 |
//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
|
|
|
674 |
if(nlc !=0 && (maxnlc >= nlc)){
|
|
|
675 |
reserve = reserve + itemreserve.get(warehouse.getId());
|
|
|
676 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
|
|
|
677 |
}
|
|
|
678 |
else if(maxnlc==0){
|
|
|
679 |
reserve = reserve + itemreserve.get(warehouse.getId());
|
|
|
680 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
|
|
|
681 |
}
|
|
|
682 |
|
|
|
683 |
}
|
|
|
684 |
}
|
|
|
685 |
}else{
|
|
|
686 |
for (Map.Entry<Long,Long> entry : itemreserve.entrySet()) {
|
|
|
687 |
if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
|
|
|
688 |
if(allWarehousesMap.get(entry.getKey()).getLogisticsLocation().equals(WarehouseLocation.Delhi) && allWarehousesMap.get(entry.getKey()).getWarehouseType().equals(WarehouseType.THIRD_PARTY) && allWarehousesMap.get(entry.getKey()).getVendor().getId()!=1){
|
|
|
689 |
|
|
|
690 |
}
|
|
|
691 |
else{
|
|
|
692 |
continue;
|
|
|
693 |
}
|
|
|
694 |
}
|
|
|
695 |
in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
|
|
|
696 |
ignoredItem.setItemId(thriftItem.getId());
|
|
|
697 |
ignoredItem.setWarehouseId(entry.getKey());
|
|
|
698 |
if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
|
|
|
699 |
nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
|
|
|
700 |
maxnlc = flipkartItem.getMaxNlc();
|
|
|
701 |
//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
|
|
|
702 |
if(nlc !=0 && (maxnlc >= nlc)){
|
|
|
703 |
reserve = reserve + entry.getValue();
|
|
|
704 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
|
|
|
705 |
}
|
|
|
706 |
else if(maxnlc==0){
|
|
|
707 |
reserve = reserve + entry.getValue();
|
|
|
708 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
|
|
|
709 |
}
|
|
|
710 |
|
|
|
711 |
}
|
|
|
712 |
|
|
|
713 |
else{
|
|
|
714 |
//System.out.println("skipping inventory for warehouse id " + entry.getKey());
|
|
|
715 |
}
|
|
|
716 |
}
|
|
|
717 |
}
|
|
|
718 |
item= new FlipkartInventoryItem(thriftItem.getId(),available,reserve,heldForSource,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),total_held,thriftItem.isRisky(),thriftItem.getItemStatus(),flipkartItem.getSkuAtFlipkart());
|
|
|
719 |
//System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
|
|
|
720 |
}
|
|
|
721 |
else{
|
|
|
722 |
item = new FlipkartInventoryItem(thriftItem.getId(),0,0,0,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),0,thriftItem.isRisky(),thriftItem.getItemStatus(),flipkartItem.getSkuAtFlipkart());
|
|
|
723 |
//System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
|
|
|
724 |
}
|
|
|
725 |
|
|
|
726 |
//System.out.println(" Item details are " + thriftItem.getId() +" " + available + " " + reserve + " " + thriftItem.getHoldInventory() + " "+ thriftItem.getDefaultInventory() + " " + thriftItem.isRisky());
|
|
|
727 |
//System.out.println("+++++++++++++++++++++++");
|
|
|
728 |
flipkartItemsInventoryMap.put(thriftItem.getId(),item);
|
|
|
729 |
|
|
|
730 |
}
|
|
|
731 |
|
|
|
732 |
} catch (TException e) {
|
|
|
733 |
e.printStackTrace();
|
|
|
734 |
}
|
|
|
735 |
}
|
|
|
736 |
|
|
|
737 |
static List<String> FetchOrders() throws ClientProtocolException, IOException{
|
|
|
738 |
HttpClient client = new DefaultHttpClient();
|
|
|
739 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
|
|
740 |
BufferedReader rd= null;
|
|
|
741 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
742 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
|
|
743 |
"flipkart"));
|
|
|
744 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
745 |
"flipkart-support@saholic.com"));
|
|
|
746 |
nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
747 |
"076c27ee24d7596b06608a8ed2559f87"));
|
|
|
748 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
749 |
HttpResponse response = client.execute(post);
|
|
|
750 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
751 |
String line = "";
|
|
|
752 |
Gson gson;
|
|
|
753 |
List<Order> orders = new ArrayList<Order>();
|
|
|
754 |
OrderItems new_orders;
|
|
|
755 |
OrderItems conf_orders;
|
|
|
756 |
HttpGet get_new;
|
|
|
757 |
HttpGet get_conf;
|
|
|
758 |
long time;
|
|
|
759 |
int i=1;
|
|
|
760 |
while ((line = rd.readLine()) != null) {
|
|
|
761 |
System.out.println(line);
|
|
|
762 |
}
|
|
|
763 |
time = System.currentTimeMillis();
|
|
|
764 |
while(true){
|
|
|
765 |
get_new = new HttpGet("https://seller.flipkart.com/dashboard/som/new_order_items?status=on_hold%2Capproved.payment_approved&sort=confirm_by_date&page="+i+"&page_size=100&_="+time);
|
|
|
766 |
response = client.execute(get_new);
|
|
|
767 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
768 |
line = "";
|
|
|
769 |
gson = new Gson();
|
|
|
770 |
new_orders = (OrderItems) gson.fromJson(rd, OrderItems.class);
|
|
|
771 |
if(new_orders.getOrder_items().size()>0){
|
|
|
772 |
orders.addAll(new_orders.getOrder_items());
|
|
|
773 |
}
|
|
|
774 |
else{
|
|
|
775 |
break;
|
|
|
776 |
}
|
|
|
777 |
i++;
|
|
|
778 |
}
|
|
|
779 |
i=1;
|
|
|
780 |
time = System.currentTimeMillis();
|
|
|
781 |
while(true){
|
|
|
782 |
get_conf = new HttpGet("https://seller.flipkart.com/dashboard/som/confirmed_order_items?status=approved.seller_approved&sort=confirm_by_date&page="+i+"&page_size=100&_="+time);
|
|
|
783 |
response = client.execute(get_conf);
|
|
|
784 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
785 |
line = "";
|
|
|
786 |
gson = new Gson();
|
|
|
787 |
conf_orders = (OrderItems) gson.fromJson(rd, OrderItems.class);
|
| 11862 |
vikram.rag |
788 |
if(conf_orders!=null & conf_orders.getOrder_items().size()>0){
|
| 9947 |
vikram.rag |
789 |
orders.addAll(conf_orders.getOrder_items());
|
|
|
790 |
}
|
|
|
791 |
else{
|
|
|
792 |
break;
|
|
|
793 |
}
|
|
|
794 |
i++;
|
|
|
795 |
}
|
|
|
796 |
List<String> orderIdList = new ArrayList<String>();
|
| 10054 |
vikram.rag |
797 |
Long heldOrders = 0L;
|
| 9947 |
vikram.rag |
798 |
for(Order order:orders){
|
| 10153 |
vikram.rag |
799 |
System.out.println("Order " + order.getExternalId() +" "+order.getOrderItemId() + " : "+ order.getStatus() + " "+order.getStatusDateMessage() + " "
|
|
|
800 |
+ order.getStatusLabel() + " " + order.getPickup_by_date() + " "+ order.getTrackingId());
|
| 9947 |
vikram.rag |
801 |
orderIdList.add(order.getExternalId());
|
| 10049 |
vikram.rag |
802 |
if(order.getStatus().equalsIgnoreCase("on_hold")){
|
| 10062 |
vikram.rag |
803 |
if(heldOrdersMap.containsKey(String.valueOf(order.getSku()))){
|
| 10057 |
vikram.rag |
804 |
heldOrders = heldOrdersMap.get(String.valueOf(order.getSku()))+order.getQuantity();
|
|
|
805 |
heldOrdersMap.put(String.valueOf(order.getSku()),heldOrders);
|
| 10059 |
vikram.rag |
806 |
System.out.println("Item ID " + order.getSku() + " Held Orders " + heldOrdersMap.get(String.valueOf(order.getSku())));
|
| 10049 |
vikram.rag |
807 |
}
|
|
|
808 |
else{
|
| 10054 |
vikram.rag |
809 |
heldOrders = (long) order.getQuantity();
|
| 10057 |
vikram.rag |
810 |
heldOrdersMap.put(String.valueOf(order.getSku()),heldOrders);
|
| 10059 |
vikram.rag |
811 |
System.out.println("Item ID " + order.getSku() + " Held Orders " + heldOrdersMap.get(String.valueOf(order.getSku())));
|
| 10049 |
vikram.rag |
812 |
}
|
|
|
813 |
}
|
| 9947 |
vikram.rag |
814 |
}
|
|
|
815 |
return orderIdList;
|
|
|
816 |
}
|
| 9983 |
vikram.rag |
817 |
static String getProductName(Item item){
|
|
|
818 |
return getName(item.getBrand())+" " + getName(item.getModelName())+" " + getName(item.getModelNumber())+" " + getName(item.getColor());
|
|
|
819 |
|
|
|
820 |
}
|
|
|
821 |
static String getName(String name){
|
|
|
822 |
if(name==null || name.length()==0){
|
|
|
823 |
return "";
|
|
|
824 |
}
|
|
|
825 |
else{
|
|
|
826 |
return name;
|
|
|
827 |
}
|
|
|
828 |
}
|
| 9947 |
vikram.rag |
829 |
}
|