| 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;
|
|
|
9 |
import in.shop2020.model.v1.catalog.status;
|
|
|
10 |
import in.shop2020.model.v1.inventory.InventoryType;
|
|
|
11 |
import in.shop2020.model.v1.inventory.ItemInventory;
|
|
|
12 |
import in.shop2020.model.v1.inventory.Warehouse;
|
|
|
13 |
import in.shop2020.model.v1.inventory.WarehouseLocation;
|
|
|
14 |
import in.shop2020.model.v1.inventory.WarehouseType;
|
|
|
15 |
import in.shop2020.model.v1.order.OrderSource;
|
|
|
16 |
import in.shop2020.serving.model.Order;
|
|
|
17 |
import in.shop2020.serving.model.OrderItems;
|
|
|
18 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
19 |
import in.shop2020.thrift.clients.InventoryClient;
|
|
|
20 |
import in.shop2020.thrift.clients.LogisticsClient;
|
|
|
21 |
import in.shop2020.thrift.clients.TransactionClient;
|
|
|
22 |
import inventory.FlipkartInventoryItem;
|
|
|
23 |
|
|
|
24 |
import java.io.BufferedReader;
|
|
|
25 |
import java.io.IOException;
|
|
|
26 |
import java.io.InputStreamReader;
|
|
|
27 |
import java.util.ArrayList;
|
|
|
28 |
import java.util.HashMap;
|
|
|
29 |
import java.util.List;
|
|
|
30 |
import java.util.Map;
|
|
|
31 |
import java.util.Map.Entry;
|
|
|
32 |
|
|
|
33 |
import org.apache.http.HttpResponse;
|
|
|
34 |
import org.apache.http.NameValuePair;
|
|
|
35 |
import org.apache.http.auth.AuthScope;
|
|
|
36 |
import org.apache.http.auth.UsernamePasswordCredentials;
|
|
|
37 |
import org.apache.http.client.ClientProtocolException;
|
|
|
38 |
import org.apache.http.client.HttpClient;
|
|
|
39 |
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
40 |
import org.apache.http.client.methods.HttpGet;
|
|
|
41 |
import org.apache.http.client.methods.HttpPost;
|
|
|
42 |
import org.apache.http.entity.StringEntity;
|
|
|
43 |
import org.apache.http.impl.client.DefaultHttpClient;
|
|
|
44 |
import org.apache.http.message.BasicNameValuePair;
|
|
|
45 |
import org.apache.thrift.TException;
|
|
|
46 |
import org.apache.thrift.transport.TTransportException;
|
|
|
47 |
|
|
|
48 |
import com.google.gson.Gson;
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
public class CreateSubmitFlipkartInventoryFeed {
|
|
|
53 |
private static Map<Long, FlipkartInventoryItem> flipkartItemsInventoryMap = new HashMap<Long, FlipkartInventoryItem>();
|
|
|
54 |
private static List<FlipkartItem> flipkartItems;
|
|
|
55 |
private static List<FlipkartItem> flipkartInventoryItems = new ArrayList<FlipkartItem>();
|
|
|
56 |
private static Map<Long,Long> itemIdOrdersMap = new HashMap<Long,Long>();
|
|
|
57 |
static
|
|
|
58 |
{
|
|
|
59 |
List<String> flipkartorderids = null;
|
|
|
60 |
Client catalogServiceClient = null;
|
|
|
61 |
try {
|
|
|
62 |
catalogServiceClient = new CatalogClient().getClient();
|
|
|
63 |
} catch (TTransportException e) {
|
|
|
64 |
e.printStackTrace();
|
|
|
65 |
}
|
|
|
66 |
try {
|
|
|
67 |
flipkartItems = catalogServiceClient.getAllFlipkartItems();
|
|
|
68 |
} catch (TException e) {
|
|
|
69 |
e.printStackTrace();
|
|
|
70 |
}
|
|
|
71 |
for(FlipkartItem flipkartItem:flipkartItems){
|
|
|
72 |
if(flipkartItem.isIsListedOnFlipkart() && !flipkartItem.isSuppressInventoryFeed())
|
|
|
73 |
flipkartInventoryItems.add(flipkartItem);
|
|
|
74 |
}
|
|
|
75 |
in.shop2020.model.v1.order.TransactionService.Client transactionClient;
|
|
|
76 |
try {
|
|
|
77 |
flipkartorderids = FetchOrders();
|
|
|
78 |
} catch (ClientProtocolException e1) {
|
|
|
79 |
e1.printStackTrace();
|
|
|
80 |
} catch (IOException e1) {
|
|
|
81 |
e1.printStackTrace();
|
|
|
82 |
}
|
|
|
83 |
try {
|
| 9948 |
vikram.rag |
84 |
transactionClient = new TransactionClient("support_transaction_service_server_host","transaction_service_server_port").getClient();
|
| 9947 |
vikram.rag |
85 |
itemIdOrdersMap = transactionClient.getCreatedOrdersForFlipkart(flipkartorderids);
|
|
|
86 |
} catch (TTransportException e) {
|
|
|
87 |
e.printStackTrace();
|
|
|
88 |
}catch (TException e) {
|
|
|
89 |
// TODO Auto-generated catch block
|
|
|
90 |
e.printStackTrace();
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
public static void main(String[] args) throws ClientProtocolException, IOException,TException{
|
|
|
96 |
calculateinventory();
|
|
|
97 |
DefaultHttpClient httpclient = new DefaultHttpClient();
|
|
|
98 |
httpclient = (DefaultHttpClient) WebClientWrapper.wrapClient(httpclient);
|
|
|
99 |
httpclient.getCredentialsProvider().setCredentials(
|
|
|
100 |
new AuthScope("sandbox-api.flipkart.net", 443),
|
|
|
101 |
new UsernamePasswordCredentials("og3yg5994bxbxxc1", "8a137068-417c-4e4f-ae95-9295ab938d88"));
|
|
|
102 |
HttpPost httppost = new HttpPost("https://sandbox-api.flipkart.net/sellers/skus/listings/bulk");
|
|
|
103 |
StringBuffer jsonRequest = new StringBuffer();
|
|
|
104 |
jsonRequest.append("{\"listings\":[");
|
|
|
105 |
//System.out.println("JSON request " + jsonRequest);
|
|
|
106 |
LogisticsClient logisticsServiceClient;
|
|
|
107 |
in.shop2020.logistics.LogisticsService.Client logisticsClient=null;
|
|
|
108 |
LogisticsInfo logisticinfo = null;
|
|
|
109 |
try {
|
|
|
110 |
logisticsServiceClient = new LogisticsClient("logistics_service_prod_server_host","logistics_service_prod_server_port");
|
|
|
111 |
logisticsClient = logisticsServiceClient.getClient();
|
|
|
112 |
|
|
|
113 |
} catch (TTransportException e) {
|
|
|
114 |
// TODO Auto-generated catch block
|
|
|
115 |
e.printStackTrace();
|
|
|
116 |
}
|
|
|
117 |
long stock=0;
|
|
|
118 |
int i=0;
|
|
|
119 |
long available,reserve,heldforsource,totalheld,allocable,holdinventory,defaultinventory;
|
|
|
120 |
for(Entry<Long, FlipkartInventoryItem> entry:flipkartItemsInventoryMap.entrySet()){
|
|
|
121 |
available = entry.getValue().getAvailability();
|
|
|
122 |
reserve = entry.getValue().getReserve();
|
|
|
123 |
heldforsource = entry.getValue().getHeldForSource();
|
|
|
124 |
totalheld = entry.getValue().getTotalHeldInventory();
|
|
|
125 |
holdinventory = entry.getValue().getHoldInventory();
|
|
|
126 |
defaultinventory = entry.getValue().getDefaultInventory();
|
|
|
127 |
if(!entry.getValue().getStatus().equals(status.PAUSED)){
|
|
|
128 |
if(entry.getValue().getRisky()){
|
|
|
129 |
if((available - reserve) < totalheld && totalheld!=0){
|
|
|
130 |
stock = (long) Math.floor(((available - reserve)*heldforsource/totalheld));
|
|
|
131 |
}
|
|
|
132 |
else{
|
|
|
133 |
allocable = available - reserve - totalheld - holdinventory;
|
|
|
134 |
if(allocable < 0){
|
|
|
135 |
allocable = 0;
|
|
|
136 |
}
|
|
|
137 |
stock = Math.round(allocable*1/3) + heldforsource;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
}
|
|
|
141 |
else{
|
|
|
142 |
allocable = available - reserve - totalheld;
|
|
|
143 |
if(allocable < 0){
|
|
|
144 |
allocable = 0;
|
|
|
145 |
}
|
|
|
146 |
if((allocable + heldforsource ) > defaultinventory){
|
|
|
147 |
stock = Math.round(allocable*1/3) + heldforsource;
|
|
|
148 |
}
|
|
|
149 |
else{
|
|
|
150 |
stock = defaultinventory;
|
|
|
151 |
}
|
|
|
152 |
}
|
|
|
153 |
System.out.println("Item ID " + entry.getKey()+" Stock "+stock +" Orders " + itemIdOrdersMap.get(entry.getKey()));
|
|
|
154 |
if(itemIdOrdersMap.containsKey(entry.getKey())){
|
|
|
155 |
stock = stock - itemIdOrdersMap.get(entry.getKey());
|
|
|
156 |
}
|
|
|
157 |
if(stock<0){
|
|
|
158 |
stock =0;
|
|
|
159 |
}
|
|
|
160 |
}
|
|
|
161 |
else{
|
|
|
162 |
stock =0;
|
|
|
163 |
}
|
|
|
164 |
try {
|
|
|
165 |
System.out.println("Item Id " + entry.getValue().getId());
|
|
|
166 |
logisticinfo = logisticsClient.getLogisticsEstimation(entry.getValue().getId(),"110001",DeliveryType.COD);
|
|
|
167 |
} catch (LogisticsServiceException e) {
|
|
|
168 |
e.printStackTrace();
|
|
|
169 |
continue;
|
|
|
170 |
}
|
|
|
171 |
jsonRequest.append("{\"skuId\":"+"\""+entry.getValue().getSkuAtflipkart()+
|
|
|
172 |
"\","+"\"attributeValues\""+":"+
|
|
|
173 |
"{\"procurement_sla\""+":"+"\""+logisticinfo.getShippingTime()+
|
|
|
174 |
"\","+"\"stock_count\""+":"+"\""+stock+"\""+"}}");
|
|
|
175 |
if(flipkartItemsInventoryMap.entrySet().size()!=1 && (i!=flipkartItemsInventoryMap.entrySet().size() -1 ) ){
|
|
|
176 |
jsonRequest.append(",");
|
|
|
177 |
}
|
|
|
178 |
i++;
|
|
|
179 |
if(i%10==0 || i==flipkartItemsInventoryMap.entrySet().size()){
|
|
|
180 |
jsonRequest.append("]}");
|
|
|
181 |
StringEntity input = new StringEntity(jsonRequest.toString());
|
|
|
182 |
input.setContentType("application/json");
|
|
|
183 |
System.out.println("Json input " + jsonRequest.toString());
|
|
|
184 |
httppost.setEntity(input);
|
|
|
185 |
HttpResponse response = httpclient.execute(httppost);
|
|
|
186 |
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
187 |
String line;
|
|
|
188 |
while ((line = rd.readLine()) != null) {
|
|
|
189 |
System.out.println(line);
|
|
|
190 |
}
|
|
|
191 |
}
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
private static void calculateinventory(){
|
|
|
195 |
CatalogClient catalogServiceClient = null;
|
|
|
196 |
Map<Long,ItemInventory> availability= new HashMap<Long,ItemInventory>();
|
|
|
197 |
try {
|
|
|
198 |
catalogServiceClient = new CatalogClient();
|
|
|
199 |
} catch (TTransportException e) {
|
|
|
200 |
// TODO Auto-generated catch block
|
|
|
201 |
e.printStackTrace();
|
|
|
202 |
}
|
|
|
203 |
in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = catalogServiceClient.getClient();
|
|
|
204 |
try {
|
|
|
205 |
List<Item> aliveItems = catalogClient.getAllAliveItems();
|
|
|
206 |
Map<Long,Item> aliveItemsMap = new HashMap<Long,Item>();
|
|
|
207 |
for(in.shop2020.model.v1.catalog.Item thriftItem:aliveItems){
|
|
|
208 |
aliveItemsMap.put(thriftItem.getId(), thriftItem);
|
|
|
209 |
|
|
|
210 |
}
|
|
|
211 |
InventoryClient inventoryServiceClient = new InventoryClient();
|
|
|
212 |
try {
|
|
|
213 |
inventoryServiceClient = new InventoryClient();
|
|
|
214 |
} catch (TTransportException e) {
|
|
|
215 |
e.printStackTrace();
|
|
|
216 |
}
|
|
|
217 |
in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = inventoryServiceClient.getClient();
|
|
|
218 |
List<in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems> ignoreItems = inventoryClient.getIgnoredWarehouseidsAndItemids();
|
|
|
219 |
availability = inventoryClient.getInventorySnapshot(0);
|
|
|
220 |
List<Warehouse> allwarehouses = inventoryClient.getWarehouses(null,null,0,0,0);
|
|
|
221 |
Map<Long,Warehouse> allWarehousesMap = new HashMap<Long,Warehouse>();
|
|
|
222 |
for(Warehouse warehouse:allwarehouses){
|
|
|
223 |
allWarehousesMap.put(warehouse.getId(),warehouse);
|
|
|
224 |
}
|
|
|
225 |
List<Warehouse> warehouses = inventoryClient.getWarehouses(WarehouseType.OURS_THIRDPARTY,null,0,0,0);
|
|
|
226 |
List<Warehouse> ours_warehouses = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, 0, 0, 0);
|
|
|
227 |
List<Long> thirdpartywarehouseids = new ArrayList<Long>();
|
|
|
228 |
List<Long> oursGoodWarehouse = new ArrayList<Long>();
|
|
|
229 |
for(Warehouse warehouse:warehouses){
|
|
|
230 |
thirdpartywarehouseids.add(warehouse.getId());
|
|
|
231 |
}
|
|
|
232 |
for (Warehouse warehouse:ours_warehouses){
|
|
|
233 |
oursGoodWarehouse.add(warehouse.getId());
|
|
|
234 |
}
|
|
|
235 |
long available=0;
|
|
|
236 |
long reserve=0;
|
|
|
237 |
long total_warehouse_held=0;
|
|
|
238 |
long heldForSource=0;
|
|
|
239 |
long total_held=0;
|
|
|
240 |
double nlc=0;
|
|
|
241 |
double maxnlc=0;
|
|
|
242 |
Item thriftItem;
|
|
|
243 |
for(FlipkartItem flipkartItem:flipkartInventoryItems){
|
|
|
244 |
if(aliveItemsMap.get(flipkartItem.getItem_id()) != null){
|
|
|
245 |
thriftItem = aliveItemsMap.get(flipkartItem.getItem_id());
|
|
|
246 |
}
|
|
|
247 |
else{
|
|
|
248 |
continue;
|
|
|
249 |
}
|
|
|
250 |
available=0;
|
|
|
251 |
reserve=0;
|
|
|
252 |
total_warehouse_held=0;
|
|
|
253 |
heldForSource=0;
|
|
|
254 |
total_held=0;
|
|
|
255 |
nlc=0;
|
|
|
256 |
List<Warehouse> vendor_warehouses=null;
|
|
|
257 |
FlipkartInventoryItem item;
|
|
|
258 |
if(availability.get(thriftItem.getId())!=null){
|
|
|
259 |
ItemInventory iteminventory = availability.get(thriftItem.getId());
|
|
|
260 |
Map<Long,Long> itemavailability = new HashMap<Long,Long>();
|
|
|
261 |
itemavailability = iteminventory.getAvailability();
|
|
|
262 |
if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
|
|
|
263 |
//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating availability)"+thriftItem.getPreferredVendor());
|
|
|
264 |
vendor_warehouses = inventoryClient.getWarehouses(WarehouseType.THIRD_PARTY,InventoryType.GOOD , thriftItem.getPreferredVendor(), 0, 0);
|
|
|
265 |
vendor_warehouses.addAll(ours_warehouses);
|
|
|
266 |
for (Warehouse warehouse:vendor_warehouses){
|
|
|
267 |
if(warehouse.getBillingWarehouseId()!=7){
|
|
|
268 |
if(warehouse.getLogisticsLocation().equals(WarehouseLocation.Delhi) && warehouse.getWarehouseType().equals(WarehouseType.THIRD_PARTY) && warehouse.getVendor().getId()!=1){
|
|
|
269 |
|
|
|
270 |
}
|
|
|
271 |
else{
|
|
|
272 |
continue;
|
|
|
273 |
}
|
|
|
274 |
}
|
|
|
275 |
in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
|
|
|
276 |
ignoredItem.setItemId(thriftItem.getId());
|
|
|
277 |
ignoredItem.setWarehouseId(warehouse.getId());
|
|
|
278 |
if (itemavailability.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(ignoredItem)){
|
|
|
279 |
try{
|
|
|
280 |
nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
|
|
|
281 |
}
|
|
|
282 |
catch(TTransportException e){
|
|
|
283 |
inventoryClient = inventoryServiceClient.getClient();
|
|
|
284 |
nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
|
|
|
285 |
}
|
|
|
286 |
maxnlc = flipkartItem.getMaxNlc();
|
|
|
287 |
|
|
|
288 |
//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
|
|
|
289 |
if(nlc !=0 && (maxnlc >= nlc)){
|
|
|
290 |
total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
|
|
|
291 |
heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 8);
|
|
|
292 |
available = available + itemavailability.get(warehouse.getId());
|
|
|
293 |
total_held = total_held + total_warehouse_held;
|
|
|
294 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
|
|
|
295 |
}
|
|
|
296 |
else if(maxnlc==0){
|
|
|
297 |
total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 0);
|
|
|
298 |
heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), warehouse.getId(), 8);
|
|
|
299 |
available = available + itemavailability.get(warehouse.getId());
|
|
|
300 |
total_held = total_held + total_warehouse_held;
|
|
|
301 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
|
|
|
302 |
}
|
|
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
}
|
|
|
306 |
else{
|
|
|
307 |
for (Map.Entry<Long,Long> entry : itemavailability.entrySet()) {
|
|
|
308 |
if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
|
|
|
309 |
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){
|
|
|
310 |
|
|
|
311 |
}
|
|
|
312 |
else{
|
|
|
313 |
continue;
|
|
|
314 |
}
|
|
|
315 |
}
|
|
|
316 |
in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
|
|
|
317 |
ignoredItem.setItemId(thriftItem.getId());
|
|
|
318 |
ignoredItem.setWarehouseId(entry.getKey());
|
|
|
319 |
if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
|
|
|
320 |
|
|
|
321 |
nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
|
|
|
322 |
maxnlc = flipkartItem.getMaxNlc();
|
|
|
323 |
//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
|
|
|
324 |
if(nlc !=0 && (maxnlc >= nlc)){
|
|
|
325 |
total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
|
|
|
326 |
heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 8);
|
|
|
327 |
available = available + entry.getValue();
|
|
|
328 |
total_held = total_held + total_warehouse_held;
|
|
|
329 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
|
|
|
330 |
}
|
|
|
331 |
else if(maxnlc==0){
|
|
|
332 |
total_warehouse_held = inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 0);
|
|
|
333 |
heldForSource = heldForSource + total_warehouse_held - inventoryClient.getHoldInventoryDetailForItemForWarehouseIdExceptSource(thriftItem.getId(), entry.getKey(), 8);
|
|
|
334 |
available = available + itemavailability.get(entry.getKey());
|
|
|
335 |
total_held = total_held + total_warehouse_held;
|
|
|
336 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\tavailable:" + available);
|
|
|
337 |
}
|
|
|
338 |
|
|
|
339 |
}
|
|
|
340 |
}
|
|
|
341 |
}
|
|
|
342 |
Map<Long,Long> itemreserve = new HashMap<Long,Long>();
|
|
|
343 |
itemreserve = iteminventory.getReserved();
|
|
|
344 |
if (thriftItem.isIsWarehousePreferenceSticky() && thriftItem.getPreferredVendor()!=0){
|
|
|
345 |
//System.out.println("Item id "+thriftItem.getId()+".Found prefered vendor and warehouse is marked sticky (Calculating Reserve)"+thriftItem.getPreferredVendor());
|
|
|
346 |
for (Warehouse warehouse:vendor_warehouses){
|
|
|
347 |
if(warehouse.getBillingWarehouseId()!=7){
|
|
|
348 |
if(warehouse.getLogisticsLocation().equals(WarehouseLocation.Delhi) && warehouse.getWarehouseType().equals(WarehouseType.THIRD_PARTY) && warehouse.getVendor().getId()!=1){
|
|
|
349 |
|
|
|
350 |
}
|
|
|
351 |
else{
|
|
|
352 |
continue;
|
|
|
353 |
}
|
|
|
354 |
}
|
|
|
355 |
in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
|
|
|
356 |
ignoredItem.setItemId(thriftItem.getId());
|
|
|
357 |
ignoredItem.setWarehouseId(warehouse.getId());
|
|
|
358 |
if (itemreserve.get(warehouse.getId())!=null && !thirdpartywarehouseids.contains(warehouse.getId()) && !ignoreItems.contains(warehouse.getId())){
|
|
|
359 |
nlc = inventoryClient.getNlcForWarehouse(warehouse.getId(),thriftItem.getId());
|
|
|
360 |
maxnlc = flipkartItem.getMaxNlc();
|
|
|
361 |
//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + warehouse.getId() );
|
|
|
362 |
if(nlc !=0 && (maxnlc >= nlc)){
|
|
|
363 |
reserve = reserve + itemreserve.get(warehouse.getId());
|
|
|
364 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
|
|
|
365 |
}
|
|
|
366 |
else if(maxnlc==0){
|
|
|
367 |
reserve = reserve + itemreserve.get(warehouse.getId());
|
|
|
368 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
|
|
|
369 |
}
|
|
|
370 |
|
|
|
371 |
}
|
|
|
372 |
}
|
|
|
373 |
}else{
|
|
|
374 |
for (Map.Entry<Long,Long> entry : itemreserve.entrySet()) {
|
|
|
375 |
if(allWarehousesMap.get(entry.getKey()).getBillingWarehouseId()!=7){
|
|
|
376 |
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){
|
|
|
377 |
|
|
|
378 |
}
|
|
|
379 |
else{
|
|
|
380 |
continue;
|
|
|
381 |
}
|
|
|
382 |
}
|
|
|
383 |
in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems ignoredItem = new in.shop2020.model.v1.inventory.IgnoredInventoryUpdateItems();
|
|
|
384 |
ignoredItem.setItemId(thriftItem.getId());
|
|
|
385 |
ignoredItem.setWarehouseId(entry.getKey());
|
|
|
386 |
if(!thirdpartywarehouseids.contains(entry.getKey()) && !ignoreItems.contains(ignoredItem)){
|
|
|
387 |
nlc = inventoryClient.getNlcForWarehouse(entry.getKey(),thriftItem.getId());
|
|
|
388 |
maxnlc = flipkartItem.getMaxNlc();
|
|
|
389 |
//System.out.println("itemId:" + thriftItem.getId() + "\tmaxnlc: " + maxnlc + "\tnlc:" + nlc + "\twid:" + entry.getKey() );
|
|
|
390 |
if(nlc !=0 && (maxnlc >= nlc)){
|
|
|
391 |
reserve = reserve + entry.getValue();
|
|
|
392 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
|
|
|
393 |
}
|
|
|
394 |
else if(maxnlc==0){
|
|
|
395 |
reserve = reserve + entry.getValue();
|
|
|
396 |
//System.out.println("itemId:" + thriftItem.getId() + "\ttotal_held: " + total_held + "\theldForSource:" + heldForSource + "\treserve:" + reserve);
|
|
|
397 |
}
|
|
|
398 |
|
|
|
399 |
}
|
|
|
400 |
|
|
|
401 |
else{
|
|
|
402 |
//System.out.println("skipping inventory for warehouse id " + entry.getKey());
|
|
|
403 |
}
|
|
|
404 |
}
|
|
|
405 |
}
|
|
|
406 |
item= new FlipkartInventoryItem(thriftItem.getId(),available,reserve,heldForSource,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),total_held,thriftItem.isRisky(),thriftItem.getItemStatus(),flipkartItem.getSkuAtFlipkart());
|
|
|
407 |
//System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
|
|
|
408 |
}
|
|
|
409 |
else{
|
|
|
410 |
item = new FlipkartInventoryItem(thriftItem.getId(),0,0,0,thriftItem.getHoldInventory(),thriftItem.getDefaultInventory(),0,thriftItem.isRisky(),thriftItem.getItemStatus(),flipkartItem.getSkuAtFlipkart());
|
|
|
411 |
//System.out.println("itemId:" + thriftItem.getId() + "\tavailable: " + available + "\treserve" + reserve + "\theldForSource:" + heldForSource + "\twebsite_hold:" + thriftItem.getHoldInventory() + "\tdefault_inv:" +thriftItem.getDefaultInventory());
|
|
|
412 |
}
|
|
|
413 |
|
|
|
414 |
//System.out.println(" Item details are " + thriftItem.getId() +" " + available + " " + reserve + " " + thriftItem.getHoldInventory() + " "+ thriftItem.getDefaultInventory() + " " + thriftItem.isRisky());
|
|
|
415 |
//System.out.println("+++++++++++++++++++++++");
|
|
|
416 |
flipkartItemsInventoryMap.put(thriftItem.getId(),item);
|
|
|
417 |
|
|
|
418 |
}
|
|
|
419 |
|
|
|
420 |
} catch (TException e) {
|
|
|
421 |
// TODO Auto-generated catch block
|
|
|
422 |
e.printStackTrace();
|
|
|
423 |
}
|
|
|
424 |
}
|
|
|
425 |
|
|
|
426 |
static List<String> FetchOrders() throws ClientProtocolException, IOException{
|
|
|
427 |
HttpClient client = new DefaultHttpClient();
|
|
|
428 |
HttpPost post = new HttpPost("https://seller.flipkart.com/login");
|
|
|
429 |
BufferedReader rd= null;
|
|
|
430 |
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
|
|
|
431 |
nameValuePairs.add(new BasicNameValuePair("authName",
|
|
|
432 |
"flipkart"));
|
|
|
433 |
nameValuePairs.add(new BasicNameValuePair("username",
|
|
|
434 |
"flipkart-support@saholic.com"));
|
|
|
435 |
nameValuePairs.add(new BasicNameValuePair("password",
|
|
|
436 |
"076c27ee24d7596b06608a8ed2559f87"));
|
|
|
437 |
post.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));
|
|
|
438 |
HttpResponse response = client.execute(post);
|
|
|
439 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
440 |
String line = "";
|
|
|
441 |
Gson gson;
|
|
|
442 |
List<Order> orders = new ArrayList<Order>();
|
|
|
443 |
OrderItems new_orders;
|
|
|
444 |
OrderItems conf_orders;
|
|
|
445 |
HttpGet get_new;
|
|
|
446 |
HttpGet get_conf;
|
|
|
447 |
long time;
|
|
|
448 |
int i=1;
|
|
|
449 |
while ((line = rd.readLine()) != null) {
|
|
|
450 |
System.out.println(line);
|
|
|
451 |
}
|
|
|
452 |
time = System.currentTimeMillis();
|
|
|
453 |
while(true){
|
|
|
454 |
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);
|
|
|
455 |
response = client.execute(get_new);
|
|
|
456 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
457 |
line = "";
|
|
|
458 |
gson = new Gson();
|
|
|
459 |
new_orders = (OrderItems) gson.fromJson(rd, OrderItems.class);
|
|
|
460 |
if(new_orders.getOrder_items().size()>0){
|
|
|
461 |
orders.addAll(new_orders.getOrder_items());
|
|
|
462 |
}
|
|
|
463 |
else{
|
|
|
464 |
break;
|
|
|
465 |
}
|
|
|
466 |
i++;
|
|
|
467 |
}
|
|
|
468 |
i=1;
|
|
|
469 |
time = System.currentTimeMillis();
|
|
|
470 |
while(true){
|
|
|
471 |
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);
|
|
|
472 |
response = client.execute(get_conf);
|
|
|
473 |
rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
|
|
474 |
line = "";
|
|
|
475 |
gson = new Gson();
|
|
|
476 |
conf_orders = (OrderItems) gson.fromJson(rd, OrderItems.class);
|
|
|
477 |
if(conf_orders.getOrder_items().size()>0){
|
|
|
478 |
orders.addAll(conf_orders.getOrder_items());
|
|
|
479 |
}
|
|
|
480 |
else{
|
|
|
481 |
break;
|
|
|
482 |
}
|
|
|
483 |
i++;
|
|
|
484 |
}
|
|
|
485 |
List<String> orderIdList = new ArrayList<String>();
|
|
|
486 |
for(Order order:orders){
|
|
|
487 |
System.out.println("Order " + order.getExternalId() +" "+order.getOrderItemId() + " : "+ order.getStatus() + " "+order.getStatusDateMessage() + " "
|
|
|
488 |
+ order.getStatusLabel() + " " + order.getPickup_by_date() + " "+ order.getTrackingId());
|
|
|
489 |
orderIdList.add(order.getExternalId());
|
|
|
490 |
}
|
|
|
491 |
return orderIdList;
|
|
|
492 |
}
|
|
|
493 |
}
|