Subversion Repositories SmartDukaan

Rev

Rev 11643 | Rev 12842 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 11643 Rev 12800
Line 8... Line 8...
8
import in.shop2020.model.v1.inventory.InventoryService;
8
import in.shop2020.model.v1.inventory.InventoryService;
9
import in.shop2020.thrift.clients.CatalogClient;
9
import in.shop2020.thrift.clients.CatalogClient;
10
import in.shop2020.thrift.clients.InventoryClient;
10
import in.shop2020.thrift.clients.InventoryClient;
11
import in.shop2020.thrift.clients.WarehouseClient;
11
import in.shop2020.thrift.clients.WarehouseClient;
12
import in.shop2020.warehouse.AmazonTransferredSkuDetail;
12
import in.shop2020.warehouse.AmazonTransferredSkuDetail;
-
 
13
import in.shop2020.warehouse.InvAgeConsiderItems;
13
import in.shop2020.warehouse.InventoryAge;
14
import in.shop2020.warehouse.InventoryAge;
-
 
15
import in.shop2020.warehouse.InventoryAvailability;
14
import in.shop2020.warehouse.Scan;
16
import in.shop2020.warehouse.Scan;
15
import in.shop2020.warehouse.ScanType;
17
import in.shop2020.warehouse.ScanType;
16
import in.shop2020.warehouse.WarehouseService.Client;
18
import in.shop2020.warehouse.WarehouseService.Client;
17
 
19
 
18
import java.io.BufferedInputStream;
20
import java.io.BufferedInputStream;
Line 22... Line 24...
22
import java.io.FileNotFoundException;
24
import java.io.FileNotFoundException;
23
import java.io.FileReader;
25
import java.io.FileReader;
24
import java.io.FileWriter;
26
import java.io.FileWriter;
25
import java.io.InputStream;
27
import java.io.InputStream;
26
import java.util.ArrayList;
28
import java.util.ArrayList;
-
 
29
import java.util.Collections;
27
import java.util.HashMap;
30
import java.util.HashMap;
28
import java.util.List;
31
import java.util.List;
29
import java.util.Map;
32
import java.util.Map;
30
 
33
 
31
import javax.servlet.ServletOutputStream;
34
import javax.servlet.ServletOutputStream;
Line 43... Line 46...
43
public class InventoryAgeController extends BaseController {
46
public class InventoryAgeController extends BaseController {
44
	private static Log logger = LogFactory.getLog(InventoryAgeController.class);
47
	private static Log logger = LogFactory.getLog(InventoryAgeController.class);
45
 
48
 
46
	public String index() {
49
	public String index() {
47
		try {
50
		try {
48
			Client client = new WarehouseClient().getClient();
-
 
49
			List<InventoryAge> inventoryAge = client.getInventoryAge();
51
			List<InventoryAge> inventoryAge = getSorplInventoryAge();
50
			List<InventoryAge> inventoryAgeAmazon = getAmazonInventoryAge();
52
			List<InventoryAge> inventoryAgeAmazon = getAmazonInventoryAge();
51
			byte[] buffer = null;
53
			byte[] buffer = null;
52
			File file = createFile(inventoryAge, inventoryAgeAmazon);
54
			File file = createFile(inventoryAge, inventoryAgeAmazon);
53
			Thread.sleep(30000);
55
			Thread.sleep(30000);
54
			buffer = new byte[(int) file.length()];
56
			buffer = new byte[(int) file.length()];
Line 90... Line 92...
90
		}
92
		}
91
 
93
 
92
		return null;
94
		return null;
93
	}
95
	}
94
 
96
 
-
 
97
	
-
 
98
	public List<InventoryAge> getSorplInventoryAge(){
-
 
99
		List<InventoryAge> inventoryAge = new ArrayList<InventoryAge>();
-
 
100
		List<InventoryAvailability> serializedInventoryAvailability = new ArrayList<InventoryAvailability>();
-
 
101
		List<InventoryAvailability> nonSerializedInventoryAvailability = new ArrayList<InventoryAvailability>();
-
 
102
		Map<Long, InventoryAvailability> inventoryAvailabilityMap = new HashMap<Long, InventoryAvailability>();
-
 
103
		
-
 
104
		try {
-
 
105
			WarehouseClient whClient = new WarehouseClient();
-
 
106
			Client client = whClient.getClient();
-
 
107
			
-
 
108
			for(Long physicalWarehouseId : PHYSICAL_WAREHOUSES ){
-
 
109
				if(!client.isAlive()){
-
 
110
					client = whClient.getClient();
-
 
111
				}
-
 
112
				serializedInventoryAvailability = client.getCurrentSerializedInventoryByScans(physicalWarehouseId);
-
 
113
				nonSerializedInventoryAvailability  = client.getCurrentNonSerializedInventoryByScans(physicalWarehouseId);
-
 
114
				
-
 
115
				for(InventoryAvailability availability : serializedInventoryAvailability){
-
 
116
					if(inventoryAvailabilityMap.containsKey(availability.getItemId())){
-
 
117
						InventoryAvailability invAvailbility = inventoryAvailabilityMap.get(availability.getItemId());
-
 
118
						invAvailbility.setQuantity(invAvailbility.getQuantity()+availability.getQuantity());
-
 
119
						inventoryAvailabilityMap.put(invAvailbility.getItemId(), invAvailbility);
-
 
120
					}else{
-
 
121
						inventoryAvailabilityMap.put(availability.getItemId(), availability);
-
 
122
					}
-
 
123
				}
-
 
124
				for(InventoryAvailability availability : nonSerializedInventoryAvailability){
-
 
125
					if(inventoryAvailabilityMap.containsKey(availability.getItemId())){
-
 
126
						InventoryAvailability invAvailbility = inventoryAvailabilityMap.get(availability.getItemId());
-
 
127
						invAvailbility.setQuantity(invAvailbility.getQuantity()+availability.getQuantity());
-
 
128
						inventoryAvailabilityMap.put(invAvailbility.getItemId(), invAvailbility);
-
 
129
					}else{
-
 
130
						inventoryAvailabilityMap.put(availability.getItemId(), availability);
-
 
131
					}
-
 
132
				}
-
 
133
			}
-
 
134
			
-
 
135
			for(Long itemId : inventoryAvailabilityMap.keySet()){
-
 
136
				InventoryAvailability stockAvailability = inventoryAvailabilityMap.get(itemId);
-
 
137
				long stockQuantity = stockAvailability.getQuantity();
-
 
138
				
-
 
139
				if(!client.isAlive()){
-
 
140
					client = whClient.getClient();
-
 
141
				}
-
 
142
				
-
 
143
				List<InvAgeConsiderItems> invAgeConsiderItems = client.getInventoryAgeConsideredItems(itemId);
-
 
144
				
-
 
145
				long freshCount = 0;
-
 
146
				long oneToTwoCount = 0;
-
 
147
				long twoToThreeCount = 0;
-
 
148
				long threeToFourCount = 0;
-
 
149
				long fourPlusCount = 0;
-
 
150
				long onePlusCount = 0;
-
 
151
				long threeMonthPlusCount = 0;
-
 
152
				long sixMonthPlusCount = 0;
-
 
153
				long zeroToThreeMonthCount = 0;
-
 
154
				long threeToSixMonthsCount = 0;
-
 
155
				long sixToTwelveMonthsCount = 0;
-
 
156
				long twelveMonthsPlusCount = 0;					
-
 
157
				long onePlusCost = 0;
-
 
158
				long zeroPlusCount = 0;
-
 
159
				long zeroPlusCost = 0;
-
 
160
				String brand =stockAvailability.getBrand();
-
 
161
				String modelName =stockAvailability.getModelName();
-
 
162
				String modelNumber =stockAvailability.getModelNumber();
-
 
163
				String color =stockAvailability.getColor();
-
 
164
				String category ="";
-
 
165
				
-
 
166
				if(invAgeConsiderItems!=null && invAgeConsiderItems.size()>0){
-
 
167
					category = invAgeConsiderItems.get(0).getCategory();
-
 
168
				}
-
 
169
				
-
 
170
				if(invAgeConsiderItems==null || invAgeConsiderItems.size()==0){
-
 
171
					continue;
-
 
172
				}
-
 
173
				double invAge = 0.0;
-
 
174
				
-
 
175
				
-
 
176
				
-
 
177
				for(InvAgeConsiderItems invItem : invAgeConsiderItems){
-
 
178
					invAge = invItem.getAge();
-
 
179
					boolean breakInner = false;
-
 
180
					if(stockQuantity == invItem.getCurrentQuantity()){
-
 
181
						breakInner = true;
-
 
182
					}
-
 
183
					if(stockQuantity > invItem.getCurrentQuantity()){
-
 
184
						stockQuantity = stockQuantity - invItem.getCurrentQuantity();
-
 
185
					}
-
 
186
					if(stockQuantity < invItem.getCurrentQuantity()){
-
 
187
						invItem.setCurrentQuantity(stockQuantity);
-
 
188
						breakInner = true;
-
 
189
					}
-
 
190
					
-
 
191
					if(invAge < 1){
-
 
192
						freshCount = freshCount + invItem.getCurrentQuantity();
-
 
193
					}
-
 
194
					if(invAge >= 1 && invAge < 2){
-
 
195
						oneToTwoCount = oneToTwoCount + invItem.getCurrentQuantity();
-
 
196
					}
-
 
197
					if(invAge >= 2 && invAge < 3){
-
 
198
						twoToThreeCount = twoToThreeCount + invItem.getCurrentQuantity();
-
 
199
					}
-
 
200
					if(invAge >= 3 && invAge < 4){
-
 
201
						threeToFourCount = threeToFourCount + invItem.getCurrentQuantity();
-
 
202
					}
-
 
203
					if(invAge >= 4){
-
 
204
						fourPlusCount = fourPlusCount + invItem.getCurrentQuantity();
-
 
205
					}
-
 
206
					if(invAge >= 1){
-
 
207
						onePlusCount = onePlusCount + invItem.getCurrentQuantity();
-
 
208
						onePlusCost = (long)(onePlusCost + invItem.getCost());
-
 
209
					}
-
 
210
					if(invAge >= 13){
-
 
211
						threeMonthPlusCount = threeMonthPlusCount + invItem.getCurrentQuantity();
-
 
212
					}
-
 
213
					if(invAge >= 26){
-
 
214
						sixMonthPlusCount = sixMonthPlusCount + invItem.getCurrentQuantity();
-
 
215
					}
-
 
216
 
-
 
217
					if(invAge >=0 && invAge <=13){
-
 
218
						zeroToThreeMonthCount = zeroToThreeMonthCount + invItem.getCurrentQuantity();
-
 
219
					}
-
 
220
 
-
 
221
					if(invAge >13 && invAge <=26){
-
 
222
						threeToSixMonthsCount = threeToSixMonthsCount + invItem.getCurrentQuantity();
-
 
223
					}
-
 
224
 
-
 
225
					if(invAge >26 && invAge <=52){
-
 
226
						sixToTwelveMonthsCount = sixToTwelveMonthsCount + invItem.getCurrentQuantity();
-
 
227
					}
-
 
228
 
-
 
229
					if(invAge > 52){
-
 
230
						twelveMonthsPlusCount = twelveMonthsPlusCount + invItem.getCurrentQuantity();
-
 
231
					}
-
 
232
 
-
 
233
					zeroPlusCount = zeroPlusCount + invItem.getCurrentQuantity();
-
 
234
 
-
 
235
					zeroPlusCost = (long)(zeroPlusCost + invItem.getCost());
-
 
236
					
-
 
237
					if(breakInner)
-
 
238
						break;
-
 
239
				}
-
 
240
				
-
 
241
				InventoryAge inventAge = new InventoryAge();
-
 
242
				inventAge.setItemId(itemId);
-
 
243
				inventAge.setBrand(brand);
-
 
244
				inventAge.setModelName(modelName);
-
 
245
				inventAge.setModelNumber(modelNumber);
-
 
246
				inventAge.setColor(color);
-
 
247
				inventAge.setFreshCount(freshCount);
-
 
248
				inventAge.setOneToTwoCount(oneToTwoCount);
-
 
249
				inventAge.setTwoToThreeCount(twoToThreeCount);
-
 
250
				inventAge.setThreeToFourCount(threeToFourCount);
-
 
251
				inventAge.setFourPlusCount(fourPlusCount);
-
 
252
				inventAge.setThreeMonthPlusCount(threeMonthPlusCount);
-
 
253
				inventAge.setSixMonthPlusCount(sixMonthPlusCount);
-
 
254
				inventAge.setZeroToThreeMonthCount(zeroToThreeMonthCount);
-
 
255
				inventAge.setThreeToSixMonthCount(threeToSixMonthsCount);
-
 
256
				inventAge.setSixToTwelveMonthCount(sixToTwelveMonthsCount);
-
 
257
				inventAge.setTwelveMonthsPlusCount(twelveMonthsPlusCount);
-
 
258
				inventAge.setZeroPlusCount(zeroPlusCount);
-
 
259
				inventAge.setOnePlusCount(onePlusCount);
-
 
260
				inventAge.setZeroPlusCost(zeroPlusCost);
-
 
261
				inventAge.setOnePlusCost(onePlusCost);
-
 
262
				inventAge.setCategory(category);
-
 
263
				inventoryAge.add(inventAge);
-
 
264
			}
-
 
265
			
-
 
266
			
-
 
267
		}
-
 
268
		catch (Exception e) {
-
 
269
			e.printStackTrace();
-
 
270
		}
-
 
271
		return inventoryAge;
-
 
272
	}
95
	/**
273
	/**
96
	 * @param inventoryAge
274
	 * @param inventoryAge
97
	 * @return
275
	 * @return
98
	 */
276
	 */
99
	private File createFile(List<InventoryAge> inventoryAge, List<InventoryAge> inventoryAgeAmazon) {
277
	private File createFile(List<InventoryAge> inventoryAge, List<InventoryAge> inventoryAgeAmazon) {
Line 335... Line 513...
335
						}
513
						}
336
						if(invAge >= 26){
514
						if(invAge >= 26){
337
							sixMonthPlusCount = sixMonthPlusCount + amazonSkuInfo.getQuantity();
515
							sixMonthPlusCount = sixMonthPlusCount + amazonSkuInfo.getQuantity();
338
						}
516
						}
339
 
517
 
340
						if(invAge >0 && invAge <=13){
518
						if(invAge >=0 && invAge <=13){
341
							zeroToThreeMonthCount = zeroToThreeMonthCount + amazonSkuInfo.getQuantity();
519
							zeroToThreeMonthCount = zeroToThreeMonthCount + amazonSkuInfo.getQuantity();
342
						}
520
						}
343
 
521
 
344
						if(invAge >13 && invAge <=26){
522
						if(invAge >13 && invAge <=26){
345
							threeToSixMonthsCount = threeToSixMonthsCount + amazonSkuInfo.getQuantity();
523
							threeToSixMonthsCount = threeToSixMonthsCount + amazonSkuInfo.getQuantity();
Line 505... Line 683...
505
 
683
 
506
	}
684
	}
507
 
685
 
508
	public void downloadSaholicInventoryAge(){
686
	public void downloadSaholicInventoryAge(){
509
		try {
687
		try {
510
			Client client = new WarehouseClient().getClient();
-
 
511
			List<InventoryAge> inventoryAge = client.getInventoryAge();
688
			List<InventoryAge> inventoryAge = getSorplInventoryAge();
512
			byte[] buffer = null;
689
			byte[] buffer = null;
513
			File file = createFile(inventoryAge,"/tmp/SaholicInventoryAge.xls");
690
			File file = createFile(inventoryAge,"/tmp/SaholicInventoryAge.xls");
514
			Thread.sleep(10000);
691
			Thread.sleep(10000);
515
			buffer = new byte[(int) file.length()];
692
			buffer = new byte[(int) file.length()];
516
			InputStream input = null;
693
			InputStream input = null;