| 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>();
|
| 11639 |
anikendra |
101 |
|
| 10689 |
manish.sha |
102 |
for(InventoryAge invAge : inventoryAge){
|
|
|
103 |
inventoryAgeMap.put(invAge.getItemId(), invAge);
|
|
|
104 |
}
|
| 11639 |
anikendra |
105 |
|
| 10689 |
manish.sha |
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());
|
| 11639 |
anikendra |
112 |
|
| 10689 |
manish.sha |
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());
|
| 11219 |
manish.sha |
117 |
invAgeObj.setZeroToThreeMonthCount(invAgeObj.getZeroToThreeMonthCount() + invAge.getZeroToThreeMonthCount());
|
|
|
118 |
invAgeObj.setThreeToSixMonthCount(invAgeObj.getThreeToSixMonthCount() + invAge.getThreeToSixMonthCount());
|
|
|
119 |
invAgeObj.setSixToTwelveMonthCount(invAgeObj.getSixToTwelveMonthCount() + invAge.getSixToTwelveMonthCount());
|
|
|
120 |
invAgeObj.setTwelveMonthsPlusCount(invAgeObj.getTwelveMonthsPlusCount() + invAge.getTwelveMonthsPlusCount());
|
| 10689 |
manish.sha |
121 |
invAgeObj.setZeroPlusCount(invAgeObj.getZeroPlusCount() + invAge.getZeroPlusCount());
|
|
|
122 |
invAgeObj.setOnePlusCount(invAgeObj.getOnePlusCount() + invAge.getOnePlusCount());
|
|
|
123 |
invAgeObj.setZeroPlusCost(invAgeObj.getZeroPlusCost() + invAge.getZeroPlusCost());
|
|
|
124 |
invAgeObj.setOnePlusCost(invAgeObj.getOnePlusCost() + invAge.getOnePlusCost());
|
| 11639 |
anikendra |
125 |
|
| 10689 |
manish.sha |
126 |
inventoryAgeMap.put(invAge.getItemId(), invAgeObj);
|
| 11639 |
anikendra |
127 |
|
| 10689 |
manish.sha |
128 |
}
|
|
|
129 |
else{
|
|
|
130 |
inventoryAgeMap.put(invAge.getItemId(), invAge);
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
List<InventoryAge> finalInventoryAge = new ArrayList<InventoryAge>();
|
|
|
134 |
for(Long itemId : inventoryAgeMap.keySet()){
|
|
|
135 |
finalInventoryAge.add(inventoryAgeMap.get(itemId));
|
|
|
136 |
}
|
|
|
137 |
try {
|
|
|
138 |
File file = new File("/tmp/InventoryAge.xls");
|
|
|
139 |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
|
|
|
140 |
bufferedWriter.write(StringUtils.join(new String[] {
|
|
|
141 |
"Item Id",
|
|
|
142 |
"Category",
|
|
|
143 |
"Brand",
|
|
|
144 |
"Model Name",
|
|
|
145 |
"Model Number",
|
|
|
146 |
"Color",
|
|
|
147 |
"Fresh",
|
|
|
148 |
"1-2 week",
|
|
|
149 |
"2-3 week",
|
|
|
150 |
"3-4 week",
|
|
|
151 |
"4+ week",
|
|
|
152 |
"3+ month",
|
|
|
153 |
"6+ month",
|
| 11219 |
manish.sha |
154 |
"0-3 month",
|
|
|
155 |
"3-6 month",
|
|
|
156 |
"6-12 month",
|
|
|
157 |
"12+ month",
|
| 10689 |
manish.sha |
158 |
"1+ week",
|
|
|
159 |
"1+ week cost",
|
|
|
160 |
"All",
|
|
|
161 |
"All cost" }, '\t'));
|
|
|
162 |
|
|
|
163 |
for (InventoryAge item : finalInventoryAge) {
|
|
|
164 |
bufferedWriter.newLine();
|
|
|
165 |
|
|
|
166 |
bufferedWriter.write(StringUtils.join(
|
|
|
167 |
new String[] {
|
|
|
168 |
String.valueOf(item.getItemId()),
|
|
|
169 |
item.getCategory(),
|
|
|
170 |
item.getBrand(),
|
|
|
171 |
item.getModelName(),
|
|
|
172 |
item.getModelNumber(),
|
|
|
173 |
item.getColor(),
|
|
|
174 |
String.valueOf(item.getFreshCount()),
|
|
|
175 |
String.valueOf(item.getOneToTwoCount()),
|
|
|
176 |
String.valueOf(item.getTwoToThreeCount()),
|
|
|
177 |
String.valueOf(item.getThreeToFourCount()),
|
|
|
178 |
String.valueOf(item.getFourPlusCount()),
|
|
|
179 |
String.valueOf(item.getThreeMonthPlusCount()),
|
|
|
180 |
String.valueOf(item.getSixMonthPlusCount()),
|
| 11219 |
manish.sha |
181 |
String.valueOf(item.getZeroToThreeMonthCount()),
|
|
|
182 |
String.valueOf(item.getThreeToSixMonthCount()),
|
|
|
183 |
String.valueOf(item.getSixToTwelveMonthCount()),
|
|
|
184 |
String.valueOf(item.getTwelveMonthsPlusCount()),
|
| 10689 |
manish.sha |
185 |
String.valueOf(item.getOnePlusCount()),
|
|
|
186 |
String.valueOf(item.getOnePlusCost()),
|
|
|
187 |
String.valueOf(item.getZeroPlusCount()),
|
|
|
188 |
String.valueOf(item.getZeroPlusCost())}, '\t'));
|
|
|
189 |
}
|
|
|
190 |
|
|
|
191 |
bufferedWriter.close();
|
|
|
192 |
return file;
|
|
|
193 |
} catch (Exception e) {
|
|
|
194 |
return null;
|
|
|
195 |
}
|
|
|
196 |
}
|
|
|
197 |
|
|
|
198 |
|
|
|
199 |
public List<InventoryAge> getAmazonInventoryAge(){
|
|
|
200 |
Long currentTimestamp = System.currentTimeMillis();
|
|
|
201 |
|
|
|
202 |
List<InventoryAge> amazonInventoryAge = new ArrayList<InventoryAge>();
|
|
|
203 |
try{
|
|
|
204 |
InventoryService.Client inventoryClient = new InventoryClient().getClient();
|
|
|
205 |
List<AmazonFbaInventorySnapshot> amazonFbaInventorySnapshot = inventoryClient.getAllAmazonFbaItemInventory();
|
| 11639 |
anikendra |
206 |
|
| 10689 |
manish.sha |
207 |
List<Long> itemIds = new ArrayList<Long>();
|
| 11639 |
anikendra |
208 |
|
|
|
209 |
for(AmazonFbaInventorySnapshot invSnapShot : amazonFbaInventorySnapshot){
|
|
|
210 |
logger.info("AmazonFbaInventorySnapshot entry " + invSnapShot.getItem_id());
|
| 11640 |
vikram.rag |
211 |
itemIds.add(invSnapShot.getItem_id());
|
| 11639 |
anikendra |
212 |
}
|
|
|
213 |
|
| 10689 |
manish.sha |
214 |
Client client = new WarehouseClient().getClient();
|
| 11639 |
anikendra |
215 |
|
| 10689 |
manish.sha |
216 |
List<AmazonTransferredSkuDetail> amazonTransferredSkuDetails = client.getAmazonTransferredSkuDetails(itemIds);
|
| 11582 |
manish.sha |
217 |
Map<Long, AmazonFbaInventorySnapshot> amazonFbaSnapshotMap = new HashMap<Long, AmazonFbaInventorySnapshot> ();
|
| 11639 |
anikendra |
218 |
|
| 10689 |
manish.sha |
219 |
Map<Long, List<AmazonTransferredSkuDetail>> skuDetailsMap = new HashMap<Long, List<AmazonTransferredSkuDetail>>();
|
| 11639 |
anikendra |
220 |
|
| 10689 |
manish.sha |
221 |
for(AmazonFbaInventorySnapshot invSnapShot : amazonFbaInventorySnapshot){
|
|
|
222 |
Long itemId= invSnapShot.getItem_id();
|
| 11582 |
manish.sha |
223 |
if(!amazonFbaSnapshotMap.containsKey(itemId)){
|
|
|
224 |
amazonFbaSnapshotMap.put(itemId, invSnapShot);
|
| 11639 |
anikendra |
225 |
logger.info("Adding Availabity " + invSnapShot.getItem_id() + " Availability " +invSnapShot.getAvailability());
|
| 11582 |
manish.sha |
226 |
} else {
|
|
|
227 |
AmazonFbaInventorySnapshot invSS = amazonFbaSnapshotMap.get(itemId);
|
|
|
228 |
invSnapShot.setAvailability(invSnapShot.getAvailability() + invSS.getAvailability());
|
|
|
229 |
amazonFbaSnapshotMap.put(itemId, invSnapShot);
|
| 11639 |
anikendra |
230 |
logger.info("Updating Availabity " + invSnapShot.getItem_id() + " Availability " +invSnapShot.getAvailability());
|
| 11582 |
manish.sha |
231 |
}
|
| 11639 |
anikendra |
232 |
|
| 10689 |
manish.sha |
233 |
List<AmazonTransferredSkuDetail> mappedList = new ArrayList<AmazonTransferredSkuDetail>();
|
|
|
234 |
for(AmazonTransferredSkuDetail detail: amazonTransferredSkuDetails){
|
| 11641 |
vikram.rag |
235 |
if(itemId.longValue() == detail.getItemId()){
|
| 11639 |
anikendra |
236 |
logger.info("Amazon Transferred Sku Details Detail found for ITEM ID " + detail.getItemId());
|
| 10689 |
manish.sha |
237 |
mappedList.add(detail);
|
|
|
238 |
}
|
| 11639 |
anikendra |
239 |
else{
|
|
|
240 |
logger.info("Amazon Transferred Sku Details Detail not found for ITEM ID " + detail.getItemId());
|
|
|
241 |
}
|
| 10689 |
manish.sha |
242 |
}
|
| 11641 |
vikram.rag |
243 |
skuDetailsMap.put(itemId, mappedList);
|
| 10689 |
manish.sha |
244 |
}
|
|
|
245 |
|
|
|
246 |
//CatalogService.Client catalogClient = new CatalogClient().getClient();
|
| 11639 |
anikendra |
247 |
|
| 11582 |
manish.sha |
248 |
for(AmazonFbaInventorySnapshot invSnapShot : amazonFbaSnapshotMap.values()){
|
| 10689 |
manish.sha |
249 |
try{
|
|
|
250 |
|
|
|
251 |
Long item_id = invSnapShot.getItem_id();
|
|
|
252 |
List<AmazonTransferredSkuDetail> amazonTranSkuDetails = skuDetailsMap.get(item_id);
|
|
|
253 |
long amazonFbaInvAvailability = invSnapShot.getAvailability();
|
|
|
254 |
List<AmazonTransferredSkuDetail> toBeIncludeList = new ArrayList<AmazonTransferredSkuDetail>();
|
|
|
255 |
|
|
|
256 |
long freshCount = 0;
|
|
|
257 |
long oneToTwoCount = 0;
|
|
|
258 |
long twoToThreeCount = 0;
|
|
|
259 |
long threeToFourCount = 0;
|
|
|
260 |
long fourPlusCount = 0;
|
|
|
261 |
long onePlusCount = 0;
|
|
|
262 |
long threeMonthPlusCount = 0;
|
|
|
263 |
long sixMonthPlusCount = 0;
|
| 11219 |
manish.sha |
264 |
long zeroToThreeMonthCount = 0;
|
|
|
265 |
long threeToSixMonthsCount = 0;
|
|
|
266 |
long sixToTwelveMonthsCount = 0;
|
|
|
267 |
long twelveMonthsPlusCount = 0;
|
| 10689 |
manish.sha |
268 |
long onePlusCost = 0;
|
|
|
269 |
long zeroPlusCount = 0;
|
|
|
270 |
long zeroPlusCost = 0;
|
|
|
271 |
String brand ="";
|
|
|
272 |
String modelName ="";
|
|
|
273 |
String modelNumber ="";
|
|
|
274 |
String color ="";
|
|
|
275 |
String category ="";
|
|
|
276 |
|
|
|
277 |
if(amazonTranSkuDetails!=null && amazonTranSkuDetails.size()>0){
|
|
|
278 |
brand = amazonTranSkuDetails.get(0).getBrand();
|
|
|
279 |
modelName = amazonTranSkuDetails.get(0).getModelName();
|
|
|
280 |
modelNumber = amazonTranSkuDetails.get(0).getModelNumber();
|
|
|
281 |
color = amazonTranSkuDetails.get(0).getColor();
|
|
|
282 |
category = amazonTranSkuDetails.get(0).getCategory();
|
| 11639 |
anikendra |
283 |
}else{
|
|
|
284 |
logger.info("Amazon Sku Transfer details skipped " + item_id);
|
| 10689 |
manish.sha |
285 |
continue;
|
|
|
286 |
}
|
|
|
287 |
double invAge = 0;
|
|
|
288 |
|
|
|
289 |
for(AmazonTransferredSkuDetail amazonSkuDetail : amazonTranSkuDetails){
|
|
|
290 |
if(amazonFbaInvAvailability == amazonSkuDetail.getQuantity()){
|
|
|
291 |
toBeIncludeList.add(amazonSkuDetail);
|
|
|
292 |
break;
|
|
|
293 |
}
|
|
|
294 |
if(amazonFbaInvAvailability > amazonSkuDetail.getQuantity()){
|
|
|
295 |
toBeIncludeList.add(amazonSkuDetail);
|
|
|
296 |
amazonFbaInvAvailability = amazonFbaInvAvailability- amazonSkuDetail.getQuantity();
|
|
|
297 |
continue;
|
|
|
298 |
}
|
|
|
299 |
if(amazonFbaInvAvailability < amazonSkuDetail.getQuantity()){
|
|
|
300 |
amazonSkuDetail.setQuantity(amazonFbaInvAvailability);
|
|
|
301 |
toBeIncludeList.add(amazonSkuDetail);
|
|
|
302 |
break;
|
|
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
|
|
|
306 |
for(AmazonTransferredSkuDetail amazonSkuInfo : toBeIncludeList){
|
|
|
307 |
if(!amazonSkuInfo.isSetPurchaseDate() || amazonSkuInfo.getPurchaseDate() == 0){
|
|
|
308 |
if(!client.isAlive()){
|
|
|
309 |
client = new WarehouseClient().getClient();
|
|
|
310 |
}
|
|
|
311 |
List<Scan> purchaseScans = client.getScansforPurchase(amazonSkuInfo.getPurchaseId(), ScanType.PURCHASE);
|
|
|
312 |
amazonSkuInfo.setPurchaseDate(purchaseScans.get(0).getScannedAt());
|
|
|
313 |
}
|
|
|
314 |
invAge = (double)(currentTimestamp - amazonSkuInfo.getPurchaseDate())/ (24 * 60 * 60 * 1000 * 7);
|
|
|
315 |
if(invAge < 1){
|
|
|
316 |
freshCount = freshCount + amazonSkuInfo.getQuantity();
|
|
|
317 |
}
|
|
|
318 |
if(invAge >= 1 && invAge < 2){
|
|
|
319 |
oneToTwoCount = oneToTwoCount + amazonSkuInfo.getQuantity();
|
|
|
320 |
}
|
|
|
321 |
if(invAge >= 2 && invAge < 3){
|
|
|
322 |
twoToThreeCount = twoToThreeCount + amazonSkuInfo.getQuantity();
|
|
|
323 |
}
|
|
|
324 |
if(invAge >= 3 && invAge < 4){
|
|
|
325 |
threeToFourCount = threeToFourCount + amazonSkuInfo.getQuantity();
|
|
|
326 |
}
|
|
|
327 |
if(invAge >= 4){
|
|
|
328 |
fourPlusCount = fourPlusCount + amazonSkuInfo.getQuantity();
|
|
|
329 |
}
|
|
|
330 |
if(invAge >= 1){
|
|
|
331 |
onePlusCount = onePlusCount + amazonSkuInfo.getQuantity();
|
|
|
332 |
onePlusCost = (long)(onePlusCost + ( amazonSkuInfo.getQuantity() * amazonSkuInfo.getUnitPrice() ));
|
|
|
333 |
}
|
|
|
334 |
if(invAge >= 13){
|
|
|
335 |
threeMonthPlusCount = threeMonthPlusCount + amazonSkuInfo.getQuantity();
|
|
|
336 |
}
|
|
|
337 |
if(invAge >= 26){
|
|
|
338 |
sixMonthPlusCount = sixMonthPlusCount + amazonSkuInfo.getQuantity();
|
|
|
339 |
}
|
| 11639 |
anikendra |
340 |
|
| 11219 |
manish.sha |
341 |
if(invAge >0 && invAge <=13){
|
|
|
342 |
zeroToThreeMonthCount = zeroToThreeMonthCount + amazonSkuInfo.getQuantity();
|
|
|
343 |
}
|
| 11639 |
anikendra |
344 |
|
| 11219 |
manish.sha |
345 |
if(invAge >13 && invAge <=26){
|
|
|
346 |
threeToSixMonthsCount = threeToSixMonthsCount + amazonSkuInfo.getQuantity();
|
|
|
347 |
}
|
| 11639 |
anikendra |
348 |
|
| 11219 |
manish.sha |
349 |
if(invAge >26 && invAge <=52){
|
|
|
350 |
sixToTwelveMonthsCount = sixToTwelveMonthsCount + amazonSkuInfo.getQuantity();
|
|
|
351 |
}
|
| 11639 |
anikendra |
352 |
|
| 11219 |
manish.sha |
353 |
if(invAge > 52){
|
|
|
354 |
twelveMonthsPlusCount = twelveMonthsPlusCount + amazonSkuInfo.getQuantity();
|
|
|
355 |
}
|
| 10689 |
manish.sha |
356 |
|
|
|
357 |
zeroPlusCount = zeroPlusCount + amazonSkuInfo.getQuantity();
|
| 11639 |
anikendra |
358 |
|
| 10689 |
manish.sha |
359 |
zeroPlusCost = (long)(zeroPlusCost + ( amazonSkuInfo.getQuantity() * amazonSkuInfo.getUnitPrice() ));
|
|
|
360 |
}
|
|
|
361 |
|
| 11639 |
anikendra |
362 |
|
| 10689 |
manish.sha |
363 |
InventoryAge inventAge = new InventoryAge();
|
|
|
364 |
inventAge.setItemId(item_id);
|
|
|
365 |
inventAge.setBrand(brand);
|
|
|
366 |
inventAge.setModelName(modelName);
|
|
|
367 |
inventAge.setModelNumber(modelNumber);
|
|
|
368 |
inventAge.setColor(color);
|
|
|
369 |
inventAge.setFreshCount(freshCount);
|
|
|
370 |
inventAge.setOneToTwoCount(oneToTwoCount);
|
|
|
371 |
inventAge.setTwoToThreeCount(twoToThreeCount);
|
|
|
372 |
inventAge.setThreeToFourCount(threeToFourCount);
|
|
|
373 |
inventAge.setFourPlusCount(fourPlusCount);
|
|
|
374 |
inventAge.setThreeMonthPlusCount(threeMonthPlusCount);
|
|
|
375 |
inventAge.setSixMonthPlusCount(sixMonthPlusCount);
|
| 11219 |
manish.sha |
376 |
inventAge.setZeroToThreeMonthCount(zeroToThreeMonthCount);
|
|
|
377 |
inventAge.setThreeToSixMonthCount(threeToSixMonthsCount);
|
|
|
378 |
inventAge.setSixToTwelveMonthCount(sixToTwelveMonthsCount);
|
|
|
379 |
inventAge.setTwelveMonthsPlusCount(twelveMonthsPlusCount);
|
| 10689 |
manish.sha |
380 |
inventAge.setZeroPlusCount(zeroPlusCount);
|
|
|
381 |
inventAge.setOnePlusCount(onePlusCount);
|
|
|
382 |
inventAge.setZeroPlusCost(zeroPlusCost);
|
|
|
383 |
inventAge.setOnePlusCost(onePlusCost);
|
|
|
384 |
inventAge.setCategory(category);
|
|
|
385 |
|
|
|
386 |
amazonInventoryAge.add(inventAge);
|
|
|
387 |
}
|
|
|
388 |
catch(Exception e){
|
|
|
389 |
e.printStackTrace();
|
|
|
390 |
}
|
|
|
391 |
}
|
|
|
392 |
|
|
|
393 |
}
|
|
|
394 |
catch(Exception e){
|
|
|
395 |
e.printStackTrace();
|
|
|
396 |
}
|
|
|
397 |
return amazonInventoryAge;
|
|
|
398 |
}
|
| 11639 |
anikendra |
399 |
|
| 10689 |
manish.sha |
400 |
public File createFile(List<InventoryAge> inventoryAge, String name){
|
|
|
401 |
try {
|
|
|
402 |
File file = new File(name);
|
|
|
403 |
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(file));
|
|
|
404 |
bufferedWriter.write(StringUtils.join(new String[] {
|
|
|
405 |
"Item Id",
|
|
|
406 |
"Category",
|
|
|
407 |
"Brand",
|
|
|
408 |
"Model Name",
|
|
|
409 |
"Model Number",
|
|
|
410 |
"Color",
|
|
|
411 |
"Fresh",
|
|
|
412 |
"1-2 week",
|
|
|
413 |
"2-3 week",
|
|
|
414 |
"3-4 week",
|
|
|
415 |
"4+ week",
|
|
|
416 |
"3+ month",
|
|
|
417 |
"6+ month",
|
| 11219 |
manish.sha |
418 |
"0-3 month",
|
|
|
419 |
"3-6 month",
|
|
|
420 |
"6-12 month",
|
|
|
421 |
"12+ month",
|
| 10689 |
manish.sha |
422 |
"1+ week",
|
|
|
423 |
"1+ week cost",
|
|
|
424 |
"All",
|
|
|
425 |
"All cost" }, '\t'));
|
|
|
426 |
|
|
|
427 |
for (InventoryAge item : inventoryAge) {
|
|
|
428 |
bufferedWriter.newLine();
|
|
|
429 |
|
|
|
430 |
bufferedWriter.write(StringUtils.join(
|
|
|
431 |
new String[] {
|
|
|
432 |
String.valueOf(item.getItemId()),
|
|
|
433 |
item.getCategory(),
|
|
|
434 |
item.getBrand(),
|
|
|
435 |
item.getModelName(),
|
|
|
436 |
item.getModelNumber(),
|
|
|
437 |
item.getColor(),
|
|
|
438 |
String.valueOf(item.getFreshCount()),
|
|
|
439 |
String.valueOf(item.getOneToTwoCount()),
|
|
|
440 |
String.valueOf(item.getTwoToThreeCount()),
|
|
|
441 |
String.valueOf(item.getThreeToFourCount()),
|
|
|
442 |
String.valueOf(item.getFourPlusCount()),
|
|
|
443 |
String.valueOf(item.getThreeMonthPlusCount()),
|
|
|
444 |
String.valueOf(item.getSixMonthPlusCount()),
|
| 11219 |
manish.sha |
445 |
String.valueOf(item.getZeroToThreeMonthCount()),
|
|
|
446 |
String.valueOf(item.getThreeToSixMonthCount()),
|
|
|
447 |
String.valueOf(item.getSixToTwelveMonthCount()),
|
|
|
448 |
String.valueOf(item.getTwelveMonthsPlusCount()),
|
| 10689 |
manish.sha |
449 |
String.valueOf(item.getOnePlusCount()),
|
|
|
450 |
String.valueOf(item.getOnePlusCost()),
|
|
|
451 |
String.valueOf(item.getZeroPlusCount()),
|
|
|
452 |
String.valueOf(item.getZeroPlusCost())}, '\t'));
|
|
|
453 |
}
|
|
|
454 |
|
|
|
455 |
bufferedWriter.close();
|
|
|
456 |
return file;
|
|
|
457 |
} catch (Exception e) {
|
|
|
458 |
return null;
|
|
|
459 |
}
|
| 11639 |
anikendra |
460 |
|
| 10689 |
manish.sha |
461 |
}
|
| 11639 |
anikendra |
462 |
|
| 10689 |
manish.sha |
463 |
public void downloadAmazonInventoryAge(){
|
|
|
464 |
try {
|
|
|
465 |
List<InventoryAge> inventoryAgeAmazon = getAmazonInventoryAge();
|
|
|
466 |
byte[] buffer = null;
|
|
|
467 |
File file = createFile(inventoryAgeAmazon,"/tmp/AmazonInventoryAge.xls");
|
|
|
468 |
Thread.sleep(10000);
|
|
|
469 |
buffer = new byte[(int) file.length()];
|
|
|
470 |
InputStream input = null;
|
|
|
471 |
try {
|
|
|
472 |
int totalBytesRead = 0;
|
|
|
473 |
input = new BufferedInputStream(new FileInputStream(file));
|
|
|
474 |
while (totalBytesRead < buffer.length) {
|
|
|
475 |
int bytesRemaining = buffer.length - totalBytesRead;
|
|
|
476 |
// input.read() returns -1, 0, or more :
|
|
|
477 |
int bytesRead = input.read(buffer, totalBytesRead,
|
|
|
478 |
bytesRemaining);
|
|
|
479 |
if (bytesRead > 0) {
|
|
|
480 |
totalBytesRead = totalBytesRead + bytesRead;
|
|
|
481 |
}
|
|
|
482 |
}
|
|
|
483 |
/*
|
|
|
484 |
* the above style is a bit tricky: it places bytes into the
|
|
|
485 |
* 'buffer' array; 'buffer' is an output parameter; the while
|
|
|
486 |
* loop usually has a single iteration only.
|
|
|
487 |
*/
|
|
|
488 |
} finally {
|
|
|
489 |
input.close();
|
|
|
490 |
}
|
|
|
491 |
|
|
|
492 |
|
|
|
493 |
|
|
|
494 |
|
|
|
495 |
response.setContentType("application/vnd.ms-excel");
|
|
|
496 |
response.setHeader("Content-disposition", "inline; filename="
|
|
|
497 |
+ file.getName());
|
|
|
498 |
|
|
|
499 |
ServletOutputStream sos = response.getOutputStream();
|
|
|
500 |
sos.write(buffer);
|
|
|
501 |
sos.flush();
|
|
|
502 |
|
|
|
503 |
}
|
|
|
504 |
catch (Exception e) {
|
|
|
505 |
}
|
|
|
506 |
|
|
|
507 |
}
|
| 11639 |
anikendra |
508 |
|
| 10689 |
manish.sha |
509 |
public void downloadSaholicInventoryAge(){
|
|
|
510 |
try {
|
|
|
511 |
Client client = new WarehouseClient().getClient();
|
|
|
512 |
List<InventoryAge> inventoryAge = client.getInventoryAge();
|
|
|
513 |
byte[] buffer = null;
|
|
|
514 |
File file = createFile(inventoryAge,"/tmp/SaholicInventoryAge.xls");
|
|
|
515 |
Thread.sleep(10000);
|
|
|
516 |
buffer = new byte[(int) file.length()];
|
|
|
517 |
InputStream input = null;
|
|
|
518 |
try {
|
|
|
519 |
int totalBytesRead = 0;
|
|
|
520 |
input = new BufferedInputStream(new FileInputStream(file));
|
|
|
521 |
while (totalBytesRead < buffer.length) {
|
|
|
522 |
int bytesRemaining = buffer.length - totalBytesRead;
|
|
|
523 |
// input.read() returns -1, 0, or more :
|
|
|
524 |
int bytesRead = input.read(buffer, totalBytesRead,
|
|
|
525 |
bytesRemaining);
|
|
|
526 |
if (bytesRead > 0) {
|
|
|
527 |
totalBytesRead = totalBytesRead + bytesRead;
|
|
|
528 |
}
|
|
|
529 |
}
|
|
|
530 |
/*
|
|
|
531 |
* the above style is a bit tricky: it places bytes into the
|
|
|
532 |
* 'buffer' array; 'buffer' is an output parameter; the while
|
|
|
533 |
* loop usually has a single iteration only.
|
|
|
534 |
*/
|
|
|
535 |
} finally {
|
|
|
536 |
input.close();
|
|
|
537 |
}
|
|
|
538 |
|
|
|
539 |
|
|
|
540 |
|
|
|
541 |
|
|
|
542 |
response.setContentType("application/vnd.ms-excel");
|
|
|
543 |
response.setHeader("Content-disposition", "inline; filename="
|
|
|
544 |
+ file.getName());
|
|
|
545 |
|
|
|
546 |
ServletOutputStream sos = response.getOutputStream();
|
|
|
547 |
sos.write(buffer);
|
|
|
548 |
sos.flush();
|
|
|
549 |
|
|
|
550 |
}
|
|
|
551 |
catch (Exception e) {
|
|
|
552 |
}
|
|
|
553 |
|
|
|
554 |
}
|
|
|
555 |
|
|
|
556 |
/*public static void main(String[] args) throws Exception{
|
| 11639 |
anikendra |
557 |
|
| 10689 |
manish.sha |
558 |
}*/
|
| 5711 |
mandeep.dh |
559 |
}
|