| 5711 |
mandeep.dh |
1 |
/**
|
|
|
2 |
*
|
|
|
3 |
*/
|
|
|
4 |
package in.shop2020.inventory.controllers;
|
|
|
5 |
|
| 10689 |
manish.sha |
6 |
import in.shop2020.model.v1.catalog.CatalogService;
|
|
|
7 |
import in.shop2020.model.v1.inventory.AmazonFbaInventorySnapshot;
|
|
|
8 |
import in.shop2020.model.v1.inventory.InventoryService;
|
|
|
9 |
import in.shop2020.thrift.clients.CatalogClient;
|
|
|
10 |
import in.shop2020.thrift.clients.InventoryClient;
|
| 5711 |
mandeep.dh |
11 |
import in.shop2020.thrift.clients.WarehouseClient;
|
| 10689 |
manish.sha |
12 |
import in.shop2020.warehouse.AmazonTransferredSkuDetail;
|
| 5711 |
mandeep.dh |
13 |
import in.shop2020.warehouse.InventoryAge;
|
| 10689 |
manish.sha |
14 |
import in.shop2020.warehouse.Scan;
|
|
|
15 |
import in.shop2020.warehouse.ScanType;
|
| 5711 |
mandeep.dh |
16 |
import in.shop2020.warehouse.WarehouseService.Client;
|
|
|
17 |
|
|
|
18 |
import java.io.BufferedInputStream;
|
|
|
19 |
import java.io.BufferedWriter;
|
|
|
20 |
import java.io.File;
|
|
|
21 |
import java.io.FileInputStream;
|
| 10689 |
manish.sha |
22 |
import java.io.FileNotFoundException;
|
|
|
23 |
import java.io.FileReader;
|
| 5711 |
mandeep.dh |
24 |
import java.io.FileWriter;
|
|
|
25 |
import java.io.InputStream;
|
| 10689 |
manish.sha |
26 |
import java.util.ArrayList;
|
|
|
27 |
import java.util.HashMap;
|
| 5711 |
mandeep.dh |
28 |
import java.util.List;
|
| 10689 |
manish.sha |
29 |
import java.util.Map;
|
| 5711 |
mandeep.dh |
30 |
|
|
|
31 |
import javax.servlet.ServletOutputStream;
|
|
|
32 |
|
|
|
33 |
import org.apache.commons.lang.StringUtils;
|
|
|
34 |
import org.apache.commons.logging.Log;
|
|
|
35 |
import org.apache.commons.logging.LogFactory;
|
|
|
36 |
|
| 10689 |
manish.sha |
37 |
|
|
|
38 |
|
| 5711 |
mandeep.dh |
39 |
/**
|
|
|
40 |
* @author mandeep
|
|
|
41 |
*
|
|
|
42 |
*/
|
|
|
43 |
public class InventoryAgeController extends BaseController {
|
| 10689 |
manish.sha |
44 |
private static Log logger = LogFactory.getLog(InventoryAgeController.class);
|
| 5711 |
mandeep.dh |
45 |
|
| 10689 |
manish.sha |
46 |
public String index() {
|
|
|
47 |
try {
|
|
|
48 |
Client client = new WarehouseClient().getClient();
|
|
|
49 |
List<InventoryAge> inventoryAge = client.getInventoryAge();
|
|
|
50 |
List<InventoryAge> inventoryAgeAmazon = getAmazonInventoryAge();
|
|
|
51 |
byte[] buffer = null;
|
|
|
52 |
File file = createFile(inventoryAge, inventoryAgeAmazon);
|
|
|
53 |
Thread.sleep(30000);
|
|
|
54 |
buffer = new byte[(int) file.length()];
|
|
|
55 |
InputStream input = null;
|
|
|
56 |
try {
|
|
|
57 |
int totalBytesRead = 0;
|
|
|
58 |
input = new BufferedInputStream(new FileInputStream(file));
|
|
|
59 |
while (totalBytesRead < buffer.length) {
|
|
|
60 |
int bytesRemaining = buffer.length - totalBytesRead;
|
|
|
61 |
// input.read() returns -1, 0, or more :
|
|
|
62 |
int bytesRead = input.read(buffer, totalBytesRead,
|
|
|
63 |
bytesRemaining);
|
|
|
64 |
if (bytesRead > 0) {
|
|
|
65 |
totalBytesRead = totalBytesRead + bytesRead;
|
|
|
66 |
}
|
|
|
67 |
}
|
|
|
68 |
/*
|
|
|
69 |
* the above style is a bit tricky: it places bytes into the
|
|
|
70 |
* 'buffer' array; 'buffer' is an output parameter; the while
|
|
|
71 |
* loop usually has a single iteration only.
|
|
|
72 |
*/
|
|
|
73 |
} finally {
|
|
|
74 |
input.close();
|
|
|
75 |
}
|
| 5711 |
mandeep.dh |
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
| 10689 |
manish.sha |
80 |
response.setContentType("application/vnd.ms-excel");
|
|
|
81 |
response.setHeader("Content-disposition", "inline; filename="
|
|
|
82 |
+ file.getName());
|
| 5711 |
mandeep.dh |
83 |
|
| 10689 |
manish.sha |
84 |
ServletOutputStream sos = response.getOutputStream();
|
|
|
85 |
sos.write(buffer);
|
|
|
86 |
sos.flush();
|
| 5711 |
mandeep.dh |
87 |
|
| 10689 |
manish.sha |
88 |
}
|
|
|
89 |
catch (Exception e) {
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
return null;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
/**
|
|
|
96 |
* @param inventoryAge
|
|
|
97 |
* @return
|
|
|
98 |
*/
|
|
|
99 |
private File createFile(List<InventoryAge> inventoryAge, List<InventoryAge> inventoryAgeAmazon) {
|
|
|
100 |
Map<Long,InventoryAge> inventoryAgeMap = new HashMap<Long,InventoryAge>();
|
|
|
101 |
|
|
|
102 |
for(InventoryAge invAge : inventoryAge){
|
|
|
103 |
inventoryAgeMap.put(invAge.getItemId(), invAge);
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
for(InventoryAge invAge : inventoryAgeAmazon){
|
|
|
107 |
if(inventoryAgeMap.containsKey(invAge.getItemId())){
|
|
|
108 |
InventoryAge invAgeObj = inventoryAgeMap.get(invAge.getItemId());
|
|
|
109 |
invAgeObj.setFreshCount(invAgeObj.getFreshCount()+ invAge.getFreshCount());
|
|
|
110 |
invAgeObj.setOneToTwoCount(invAgeObj.getOneToTwoCount() + invAge.getOneToTwoCount());
|
|
|
111 |
invAgeObj.setTwoToThreeCount(invAgeObj.getTwoToThreeCount() + invAge.getTwoToThreeCount());
|
|
|
112 |
|
|
|
113 |
invAgeObj.setThreeToFourCount(invAgeObj.getThreeToFourCount() + invAge.getThreeToFourCount());
|
|
|
114 |
invAgeObj.setFourPlusCount(invAgeObj.getFourPlusCount() + invAge.getFourPlusCount());
|
|
|
115 |
invAgeObj.setThreeMonthPlusCount(invAgeObj.getThreeMonthPlusCount() + invAge.getThreeMonthPlusCount());
|
|
|
116 |
invAgeObj.setSixMonthPlusCount(invAgeObj.getSixMonthPlusCount() + invAge.getSixMonthPlusCount());
|
|
|
117 |
invAgeObj.setZeroPlusCount(invAgeObj.getZeroPlusCount() + invAge.getZeroPlusCount());
|
|
|
118 |
invAgeObj.setOnePlusCount(invAgeObj.getOnePlusCount() + invAge.getOnePlusCount());
|
|
|
119 |
invAgeObj.setZeroPlusCost(invAgeObj.getZeroPlusCost() + invAge.getZeroPlusCost());
|
|
|
120 |
invAgeObj.setOnePlusCost(invAgeObj.getOnePlusCost() + invAge.getOnePlusCost());
|
|
|
121 |
|
|
|
122 |
inventoryAgeMap.put(invAge.getItemId(), invAgeObj);
|
|
|
123 |
|
|
|
124 |
}
|
|
|
125 |
else{
|
|
|
126 |
inventoryAgeMap.put(invAge.getItemId(), invAge);
|
|
|
127 |
}
|
|
|
128 |
}
|
|
|
129 |
List<InventoryAge> finalInventoryAge = new ArrayList<InventoryAge>();
|
|
|
130 |
for(Long itemId : inventoryAgeMap.keySet()){
|
|
|
131 |
finalInventoryAge.add(inventoryAgeMap.get(itemId));
|
|
|
132 |
}
|
|
|
133 |
try {
|
|
|
134 |
File file = new File("/tmp/InventoryAge.xls");
|
|
|
135 |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
|
|
|
136 |
bufferedWriter.write(StringUtils.join(new String[] {
|
|
|
137 |
"Item Id",
|
|
|
138 |
"Category",
|
|
|
139 |
"Brand",
|
|
|
140 |
"Model Name",
|
|
|
141 |
"Model Number",
|
|
|
142 |
"Color",
|
|
|
143 |
"Fresh",
|
|
|
144 |
"1-2 week",
|
|
|
145 |
"2-3 week",
|
|
|
146 |
"3-4 week",
|
|
|
147 |
"4+ week",
|
|
|
148 |
"3+ month",
|
|
|
149 |
"6+ month",
|
|
|
150 |
"1+ week",
|
|
|
151 |
"1+ week cost",
|
|
|
152 |
"All",
|
|
|
153 |
"All cost" }, '\t'));
|
|
|
154 |
|
|
|
155 |
for (InventoryAge item : finalInventoryAge) {
|
|
|
156 |
bufferedWriter.newLine();
|
|
|
157 |
|
|
|
158 |
bufferedWriter.write(StringUtils.join(
|
|
|
159 |
new String[] {
|
|
|
160 |
String.valueOf(item.getItemId()),
|
|
|
161 |
item.getCategory(),
|
|
|
162 |
item.getBrand(),
|
|
|
163 |
item.getModelName(),
|
|
|
164 |
item.getModelNumber(),
|
|
|
165 |
item.getColor(),
|
|
|
166 |
String.valueOf(item.getFreshCount()),
|
|
|
167 |
String.valueOf(item.getOneToTwoCount()),
|
|
|
168 |
String.valueOf(item.getTwoToThreeCount()),
|
|
|
169 |
String.valueOf(item.getThreeToFourCount()),
|
|
|
170 |
String.valueOf(item.getFourPlusCount()),
|
|
|
171 |
String.valueOf(item.getThreeMonthPlusCount()),
|
|
|
172 |
String.valueOf(item.getSixMonthPlusCount()),
|
|
|
173 |
String.valueOf(item.getOnePlusCount()),
|
|
|
174 |
String.valueOf(item.getOnePlusCost()),
|
|
|
175 |
String.valueOf(item.getZeroPlusCount()),
|
|
|
176 |
String.valueOf(item.getZeroPlusCost())}, '\t'));
|
|
|
177 |
}
|
|
|
178 |
|
|
|
179 |
bufferedWriter.close();
|
|
|
180 |
return file;
|
|
|
181 |
} catch (Exception e) {
|
|
|
182 |
return null;
|
|
|
183 |
}
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
public List<InventoryAge> getAmazonInventoryAge(){
|
|
|
188 |
Long currentTimestamp = System.currentTimeMillis();
|
|
|
189 |
|
|
|
190 |
List<InventoryAge> amazonInventoryAge = new ArrayList<InventoryAge>();
|
|
|
191 |
try{
|
|
|
192 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
193 |
List<AmazonFbaInventorySnapshot> amazonFbaInventorySnapshot = inventoryClient.getAllAmazonFbaItemInventory();
|
|
|
194 |
|
|
|
195 |
List<Long> itemIds = new ArrayList<Long>();
|
|
|
196 |
for(AmazonFbaInventorySnapshot invSnapShot : amazonFbaInventorySnapshot)
|
|
|
197 |
itemIds.add(invSnapShot.getItem_id());
|
|
|
198 |
Client client = new WarehouseClient().getClient();
|
|
|
199 |
|
|
|
200 |
List<AmazonTransferredSkuDetail> amazonTransferredSkuDetails = client.getAmazonTransferredSkuDetails(itemIds);
|
|
|
201 |
|
|
|
202 |
Map<Long, List<AmazonTransferredSkuDetail>> skuDetailsMap = new HashMap<Long, List<AmazonTransferredSkuDetail>>();
|
|
|
203 |
|
|
|
204 |
for(AmazonFbaInventorySnapshot invSnapShot : amazonFbaInventorySnapshot){
|
|
|
205 |
Long itemId= invSnapShot.getItem_id();
|
|
|
206 |
List<AmazonTransferredSkuDetail> mappedList = new ArrayList<AmazonTransferredSkuDetail>();
|
|
|
207 |
for(AmazonTransferredSkuDetail detail: amazonTransferredSkuDetails){
|
|
|
208 |
if(itemId == detail.getItemId()){
|
|
|
209 |
mappedList.add(detail);
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
skuDetailsMap.put(itemId, mappedList);
|
|
|
213 |
}
|
|
|
214 |
|
|
|
215 |
//CatalogService.Client catalogClient = new CatalogClient().getClient();
|
|
|
216 |
|
|
|
217 |
for(AmazonFbaInventorySnapshot invSnapShot : amazonFbaInventorySnapshot){
|
|
|
218 |
try{
|
|
|
219 |
|
|
|
220 |
Long item_id = invSnapShot.getItem_id();
|
|
|
221 |
List<AmazonTransferredSkuDetail> amazonTranSkuDetails = skuDetailsMap.get(item_id);
|
|
|
222 |
long amazonFbaInvAvailability = invSnapShot.getAvailability();
|
|
|
223 |
List<AmazonTransferredSkuDetail> toBeIncludeList = new ArrayList<AmazonTransferredSkuDetail>();
|
|
|
224 |
|
|
|
225 |
long freshCount = 0;
|
|
|
226 |
long oneToTwoCount = 0;
|
|
|
227 |
long twoToThreeCount = 0;
|
|
|
228 |
long threeToFourCount = 0;
|
|
|
229 |
long fourPlusCount = 0;
|
|
|
230 |
long onePlusCount = 0;
|
|
|
231 |
long threeMonthPlusCount = 0;
|
|
|
232 |
long sixMonthPlusCount = 0;
|
|
|
233 |
long onePlusCost = 0;
|
|
|
234 |
long zeroPlusCount = 0;
|
|
|
235 |
long zeroPlusCost = 0;
|
|
|
236 |
String brand ="";
|
|
|
237 |
String modelName ="";
|
|
|
238 |
String modelNumber ="";
|
|
|
239 |
String color ="";
|
|
|
240 |
String category ="";
|
|
|
241 |
|
|
|
242 |
if(amazonTranSkuDetails!=null && amazonTranSkuDetails.size()>0){
|
|
|
243 |
brand = amazonTranSkuDetails.get(0).getBrand();
|
|
|
244 |
modelName = amazonTranSkuDetails.get(0).getModelName();
|
|
|
245 |
modelNumber = amazonTranSkuDetails.get(0).getModelNumber();
|
|
|
246 |
color = amazonTranSkuDetails.get(0).getColor();
|
|
|
247 |
category = amazonTranSkuDetails.get(0).getCategory();
|
|
|
248 |
}else{
|
|
|
249 |
continue;
|
|
|
250 |
}
|
|
|
251 |
double invAge = 0;
|
|
|
252 |
|
|
|
253 |
for(AmazonTransferredSkuDetail amazonSkuDetail : amazonTranSkuDetails){
|
|
|
254 |
if(amazonFbaInvAvailability == amazonSkuDetail.getQuantity()){
|
|
|
255 |
toBeIncludeList.add(amazonSkuDetail);
|
|
|
256 |
break;
|
|
|
257 |
}
|
|
|
258 |
if(amazonFbaInvAvailability > amazonSkuDetail.getQuantity()){
|
|
|
259 |
toBeIncludeList.add(amazonSkuDetail);
|
|
|
260 |
amazonFbaInvAvailability = amazonFbaInvAvailability- amazonSkuDetail.getQuantity();
|
|
|
261 |
continue;
|
|
|
262 |
}
|
|
|
263 |
if(amazonFbaInvAvailability < amazonSkuDetail.getQuantity()){
|
|
|
264 |
amazonSkuDetail.setQuantity(amazonFbaInvAvailability);
|
|
|
265 |
toBeIncludeList.add(amazonSkuDetail);
|
|
|
266 |
break;
|
|
|
267 |
}
|
|
|
268 |
}
|
|
|
269 |
|
|
|
270 |
for(AmazonTransferredSkuDetail amazonSkuInfo : toBeIncludeList){
|
|
|
271 |
if(!amazonSkuInfo.isSetPurchaseDate() || amazonSkuInfo.getPurchaseDate() == 0){
|
|
|
272 |
if(!client.isAlive()){
|
|
|
273 |
client = new WarehouseClient().getClient();
|
|
|
274 |
}
|
|
|
275 |
List<Scan> purchaseScans = client.getScansforPurchase(amazonSkuInfo.getPurchaseId(), ScanType.PURCHASE);
|
|
|
276 |
amazonSkuInfo.setPurchaseDate(purchaseScans.get(0).getScannedAt());
|
|
|
277 |
}
|
|
|
278 |
invAge = (double)(currentTimestamp - amazonSkuInfo.getPurchaseDate())/ (24 * 60 * 60 * 1000 * 7);
|
|
|
279 |
if(invAge < 1){
|
|
|
280 |
freshCount = freshCount + amazonSkuInfo.getQuantity();
|
|
|
281 |
}
|
|
|
282 |
if(invAge >= 1 && invAge < 2){
|
|
|
283 |
oneToTwoCount = oneToTwoCount + amazonSkuInfo.getQuantity();
|
|
|
284 |
}
|
|
|
285 |
if(invAge >= 2 && invAge < 3){
|
|
|
286 |
twoToThreeCount = twoToThreeCount + amazonSkuInfo.getQuantity();
|
|
|
287 |
}
|
|
|
288 |
if(invAge >= 3 && invAge < 4){
|
|
|
289 |
threeToFourCount = threeToFourCount + amazonSkuInfo.getQuantity();
|
|
|
290 |
}
|
|
|
291 |
if(invAge >= 4){
|
|
|
292 |
fourPlusCount = fourPlusCount + amazonSkuInfo.getQuantity();
|
|
|
293 |
}
|
|
|
294 |
if(invAge >= 1){
|
|
|
295 |
onePlusCount = onePlusCount + amazonSkuInfo.getQuantity();
|
|
|
296 |
onePlusCost = (long)(onePlusCost + ( amazonSkuInfo.getQuantity() * amazonSkuInfo.getUnitPrice() ));
|
|
|
297 |
}
|
|
|
298 |
if(invAge >= 13){
|
|
|
299 |
threeMonthPlusCount = threeMonthPlusCount + amazonSkuInfo.getQuantity();
|
|
|
300 |
}
|
|
|
301 |
if(invAge >= 26){
|
|
|
302 |
sixMonthPlusCount = sixMonthPlusCount + amazonSkuInfo.getQuantity();
|
|
|
303 |
}
|
|
|
304 |
|
|
|
305 |
zeroPlusCount = zeroPlusCount + amazonSkuInfo.getQuantity();
|
|
|
306 |
|
|
|
307 |
zeroPlusCost = (long)(zeroPlusCost + ( amazonSkuInfo.getQuantity() * amazonSkuInfo.getUnitPrice() ));
|
|
|
308 |
}
|
|
|
309 |
|
|
|
310 |
|
|
|
311 |
InventoryAge inventAge = new InventoryAge();
|
|
|
312 |
inventAge.setItemId(item_id);
|
|
|
313 |
inventAge.setBrand(brand);
|
|
|
314 |
inventAge.setModelName(modelName);
|
|
|
315 |
inventAge.setModelNumber(modelNumber);
|
|
|
316 |
inventAge.setColor(color);
|
|
|
317 |
inventAge.setFreshCount(freshCount);
|
|
|
318 |
inventAge.setOneToTwoCount(oneToTwoCount);
|
|
|
319 |
inventAge.setTwoToThreeCount(twoToThreeCount);
|
|
|
320 |
inventAge.setThreeToFourCount(threeToFourCount);
|
|
|
321 |
inventAge.setFourPlusCount(fourPlusCount);
|
|
|
322 |
inventAge.setThreeMonthPlusCount(threeMonthPlusCount);
|
|
|
323 |
inventAge.setSixMonthPlusCount(sixMonthPlusCount);
|
|
|
324 |
inventAge.setZeroPlusCount(zeroPlusCount);
|
|
|
325 |
inventAge.setOnePlusCount(onePlusCount);
|
|
|
326 |
inventAge.setZeroPlusCost(zeroPlusCost);
|
|
|
327 |
inventAge.setOnePlusCost(onePlusCost);
|
|
|
328 |
inventAge.setCategory(category);
|
|
|
329 |
|
|
|
330 |
amazonInventoryAge.add(inventAge);
|
|
|
331 |
}
|
|
|
332 |
catch(Exception e){
|
|
|
333 |
e.printStackTrace();
|
|
|
334 |
}
|
|
|
335 |
}
|
|
|
336 |
|
|
|
337 |
}
|
|
|
338 |
catch(Exception e){
|
|
|
339 |
e.printStackTrace();
|
|
|
340 |
}
|
|
|
341 |
return amazonInventoryAge;
|
|
|
342 |
}
|
|
|
343 |
|
|
|
344 |
public File createFile(List<InventoryAge> inventoryAge, String name){
|
|
|
345 |
try {
|
|
|
346 |
File file = new File(name);
|
|
|
347 |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
|
|
|
348 |
bufferedWriter.write(StringUtils.join(new String[] {
|
|
|
349 |
"Item Id",
|
|
|
350 |
"Category",
|
|
|
351 |
"Brand",
|
|
|
352 |
"Model Name",
|
|
|
353 |
"Model Number",
|
|
|
354 |
"Color",
|
|
|
355 |
"Fresh",
|
|
|
356 |
"1-2 week",
|
|
|
357 |
"2-3 week",
|
|
|
358 |
"3-4 week",
|
|
|
359 |
"4+ week",
|
|
|
360 |
"3+ month",
|
|
|
361 |
"6+ month",
|
|
|
362 |
"1+ week",
|
|
|
363 |
"1+ week cost",
|
|
|
364 |
"All",
|
|
|
365 |
"All cost" }, '\t'));
|
|
|
366 |
|
|
|
367 |
for (InventoryAge item : inventoryAge) {
|
|
|
368 |
bufferedWriter.newLine();
|
|
|
369 |
|
|
|
370 |
bufferedWriter.write(StringUtils.join(
|
|
|
371 |
new String[] {
|
|
|
372 |
String.valueOf(item.getItemId()),
|
|
|
373 |
item.getCategory(),
|
|
|
374 |
item.getBrand(),
|
|
|
375 |
item.getModelName(),
|
|
|
376 |
item.getModelNumber(),
|
|
|
377 |
item.getColor(),
|
|
|
378 |
String.valueOf(item.getFreshCount()),
|
|
|
379 |
String.valueOf(item.getOneToTwoCount()),
|
|
|
380 |
String.valueOf(item.getTwoToThreeCount()),
|
|
|
381 |
String.valueOf(item.getThreeToFourCount()),
|
|
|
382 |
String.valueOf(item.getFourPlusCount()),
|
|
|
383 |
String.valueOf(item.getThreeMonthPlusCount()),
|
|
|
384 |
String.valueOf(item.getSixMonthPlusCount()),
|
|
|
385 |
String.valueOf(item.getOnePlusCount()),
|
|
|
386 |
String.valueOf(item.getOnePlusCost()),
|
|
|
387 |
String.valueOf(item.getZeroPlusCount()),
|
|
|
388 |
String.valueOf(item.getZeroPlusCost())}, '\t'));
|
|
|
389 |
}
|
|
|
390 |
|
|
|
391 |
bufferedWriter.close();
|
|
|
392 |
return file;
|
|
|
393 |
} catch (Exception e) {
|
|
|
394 |
return null;
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
}
|
|
|
398 |
|
|
|
399 |
public void downloadAmazonInventoryAge(){
|
|
|
400 |
try {
|
|
|
401 |
List<InventoryAge> inventoryAgeAmazon = getAmazonInventoryAge();
|
|
|
402 |
byte[] buffer = null;
|
|
|
403 |
File file = createFile(inventoryAgeAmazon,"/tmp/AmazonInventoryAge.xls");
|
|
|
404 |
Thread.sleep(10000);
|
|
|
405 |
buffer = new byte[(int) file.length()];
|
|
|
406 |
InputStream input = null;
|
|
|
407 |
try {
|
|
|
408 |
int totalBytesRead = 0;
|
|
|
409 |
input = new BufferedInputStream(new FileInputStream(file));
|
|
|
410 |
while (totalBytesRead < buffer.length) {
|
|
|
411 |
int bytesRemaining = buffer.length - totalBytesRead;
|
|
|
412 |
// input.read() returns -1, 0, or more :
|
|
|
413 |
int bytesRead = input.read(buffer, totalBytesRead,
|
|
|
414 |
bytesRemaining);
|
|
|
415 |
if (bytesRead > 0) {
|
|
|
416 |
totalBytesRead = totalBytesRead + bytesRead;
|
|
|
417 |
}
|
|
|
418 |
}
|
|
|
419 |
/*
|
|
|
420 |
* the above style is a bit tricky: it places bytes into the
|
|
|
421 |
* 'buffer' array; 'buffer' is an output parameter; the while
|
|
|
422 |
* loop usually has a single iteration only.
|
|
|
423 |
*/
|
|
|
424 |
} finally {
|
|
|
425 |
input.close();
|
|
|
426 |
}
|
|
|
427 |
|
|
|
428 |
|
|
|
429 |
|
|
|
430 |
|
|
|
431 |
response.setContentType("application/vnd.ms-excel");
|
|
|
432 |
response.setHeader("Content-disposition", "inline; filename="
|
|
|
433 |
+ file.getName());
|
|
|
434 |
|
|
|
435 |
ServletOutputStream sos = response.getOutputStream();
|
|
|
436 |
sos.write(buffer);
|
|
|
437 |
sos.flush();
|
|
|
438 |
|
|
|
439 |
}
|
|
|
440 |
catch (Exception e) {
|
|
|
441 |
}
|
|
|
442 |
|
|
|
443 |
}
|
|
|
444 |
|
|
|
445 |
public void downloadSaholicInventoryAge(){
|
|
|
446 |
try {
|
|
|
447 |
Client client = new WarehouseClient().getClient();
|
|
|
448 |
List<InventoryAge> inventoryAge = client.getInventoryAge();
|
|
|
449 |
byte[] buffer = null;
|
|
|
450 |
File file = createFile(inventoryAge,"/tmp/SaholicInventoryAge.xls");
|
|
|
451 |
Thread.sleep(10000);
|
|
|
452 |
buffer = new byte[(int) file.length()];
|
|
|
453 |
InputStream input = null;
|
|
|
454 |
try {
|
|
|
455 |
int totalBytesRead = 0;
|
|
|
456 |
input = new BufferedInputStream(new FileInputStream(file));
|
|
|
457 |
while (totalBytesRead < buffer.length) {
|
|
|
458 |
int bytesRemaining = buffer.length - totalBytesRead;
|
|
|
459 |
// input.read() returns -1, 0, or more :
|
|
|
460 |
int bytesRead = input.read(buffer, totalBytesRead,
|
|
|
461 |
bytesRemaining);
|
|
|
462 |
if (bytesRead > 0) {
|
|
|
463 |
totalBytesRead = totalBytesRead + bytesRead;
|
|
|
464 |
}
|
|
|
465 |
}
|
|
|
466 |
/*
|
|
|
467 |
* the above style is a bit tricky: it places bytes into the
|
|
|
468 |
* 'buffer' array; 'buffer' is an output parameter; the while
|
|
|
469 |
* loop usually has a single iteration only.
|
|
|
470 |
*/
|
|
|
471 |
} finally {
|
|
|
472 |
input.close();
|
|
|
473 |
}
|
|
|
474 |
|
|
|
475 |
|
|
|
476 |
|
|
|
477 |
|
|
|
478 |
response.setContentType("application/vnd.ms-excel");
|
|
|
479 |
response.setHeader("Content-disposition", "inline; filename="
|
|
|
480 |
+ file.getName());
|
|
|
481 |
|
|
|
482 |
ServletOutputStream sos = response.getOutputStream();
|
|
|
483 |
sos.write(buffer);
|
|
|
484 |
sos.flush();
|
|
|
485 |
|
|
|
486 |
}
|
|
|
487 |
catch (Exception e) {
|
|
|
488 |
}
|
|
|
489 |
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
/*public static void main(String[] args) throws Exception{
|
|
|
493 |
|
|
|
494 |
}*/
|
| 5711 |
mandeep.dh |
495 |
}
|