Subversion Repositories SmartDukaan

Rev

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

Rev 9873 Rev 10484
Line 13... Line 13...
13
import in.shop2020.catalog.dashboard.shared.VoucherItemMapping;
13
import in.shop2020.catalog.dashboard.shared.VoucherItemMapping;
14
import in.shop2020.config.ConfigException;
14
import in.shop2020.config.ConfigException;
15
import in.shop2020.content.ContentService;
15
import in.shop2020.content.ContentService;
16
import in.shop2020.content.ContentServiceException;
16
import in.shop2020.content.ContentServiceException;
17
import in.shop2020.model.v1.catalog.CatalogService.Client;
17
import in.shop2020.model.v1.catalog.CatalogService.Client;
-
 
18
import in.shop2020.model.v1.catalog.CatalogServiceException;
18
import in.shop2020.model.v1.catalog.Insurer;
19
import in.shop2020.model.v1.catalog.Insurer;
19
import in.shop2020.model.v1.catalog.ItemType;
20
import in.shop2020.model.v1.catalog.ItemType;
20
import in.shop2020.model.v1.catalog.status;
21
import in.shop2020.model.v1.catalog.status;
21
import in.shop2020.model.v1.inventory.InventoryService;
22
import in.shop2020.model.v1.inventory.InventoryService;
22
import in.shop2020.model.v1.inventory.ItemStockPurchaseParams;
23
import in.shop2020.model.v1.inventory.ItemStockPurchaseParams;
Line 322... Line 323...
322
		        		sameItemsWithDifferentColors.add(id); 
323
		        		sameItemsWithDifferentColors.add(id); 
323
		        	}
324
		        	}
324
	            }
325
	            }
325
            }
326
            }
326
            List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
327
            List<in.shop2020.model.v1.inventory.VendorItemPricing> vip = inventoryClient.getAllItemPricing(thriftItem.getId());
-
 
328
            Map<Long,String> stateIdNameMap = inventoryClient.getStateMaster();
-
 
329
            
327
            List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
330
            List<in.shop2020.model.v1.inventory.VendorItemMapping> vim = inventoryClient.getVendorItemMappings(thriftItem.getId());
328
            List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
331
            List<in.shop2020.model.v1.catalog.SourceItemPricing> sip = catalogClient.getAllSourcePricing(thriftItem.getId());
329
            List<in.shop2020.model.v1.catalog.Item> sit = catalogClient.getAllSimilarItems(thriftItem.getId());
332
            List<in.shop2020.model.v1.catalog.Item> sit = catalogClient.getAllSimilarItems(thriftItem.getId());
330
            in.shop2020.model.v1.inventory.ItemInventory itemInventory = inventoryClient.getItemInventoryByItemId(thriftItem.getId());
333
            in.shop2020.model.v1.inventory.ItemInventory itemInventory = inventoryClient.getItemInventoryByItemId(thriftItem.getId());
331
            ItemStockPurchaseParams stockPurchaseParams = inventoryClient.getItemStockPurchaseParams(thriftItem.getId());
334
            ItemStockPurchaseParams stockPurchaseParams = inventoryClient.getItemStockPurchaseParams(thriftItem.getId());
Line 346... Line 349...
346
            String spdLastNdaySale = getOosString(spdOosStatuses);
349
            String spdLastNdaySale = getOosString(spdOosStatuses);
347
            saleHistory.put(7L,spdLastNdaySale);
350
            saleHistory.put(7L,spdLastNdaySale);
348
            List<OOSStatus> fktOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 8, 5);
351
            List<OOSStatus> fktOosStatuses = inventoryClient.getOosStatusesForXDaysForItem(thriftItem.getId(), 8, 5);
349
            String fktLastNdaySale = getOosString(fktOosStatuses);
352
            String fktLastNdaySale = getOosString(fktOosStatuses);
350
            saleHistory.put(8L,fktLastNdaySale);
353
            saleHistory.put(8L,fktLastNdaySale);
351
            
-
 
352
            
-
 
353
            Long freebieItemId = catalogClient.getFreebieForItem(thriftItem.getId());
354
            Long freebieItemId = catalogClient.getFreebieForItem(thriftItem.getId());
354
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tvouchers = catalogClient.getAllItemVouchers(thriftItem.getId());
355
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tvouchers = catalogClient.getAllItemVouchers(thriftItem.getId());
-
 
356
            Map<String,String> stateNameVatPercentageMap = new HashMap<String,String>();
-
 
357
            catalogClient =  new CatalogClient("catalog_service_server_host_prod","catalog_service_server_port").getClient();
-
 
358
            double vatrate;
-
 
359
            for(Entry<Long, String> entry:stateIdNameMap.entrySet()){
-
 
360
            	try{
-
 
361
            	     vatrate= catalogClient.getVatPercentageForItem(thriftItem.getId(),entry.getKey(),thriftItem.getSellingPrice());
-
 
362
            	}
-
 
363
            	catch(CatalogServiceException cex){
-
 
364
            		vatrate = -1.0;
-
 
365
            	}
-
 
366
            	stateNameVatPercentageMap.put(entry.getValue(),String.valueOf(vatrate));
-
 
367
            }
355
            Item it = getItemFromThriftItem(thriftItem, vip, vim, sip, sit, itemInventory, tvouchers, stockPurchaseParams, saleHistory, freebieItemId);
368
            Item it = getItemFromThriftItem(thriftItem, vip, vim, sip, sit, itemInventory, tvouchers, stockPurchaseParams, saleHistory, freebieItemId , stateNameVatPercentageMap);
356
            it.setSameItemsWithDifferentColors(sameItemsWithDifferentColors);
369
            it.setSameItemsWithDifferentColors(sameItemsWithDifferentColors);
357
            return it;
370
            return it;
358
        }catch(Exception e){
371
        }catch(Exception e){
359
            logger.error("Error while getting the item from the catalog service", e);
372
            logger.error("Error while getting the item from the catalog service", e);
360
        }
373
        }
Line 1514... Line 1527...
1514
	        } catch (Exception e) {
1527
	        } catch (Exception e) {
1515
	            logger.error("Error while getting all the vendors: ", e);
1528
	            logger.error("Error while getting all the vendors: ", e);
1516
	        }
1529
	        }
1517
	        return insurersMap;
1530
	        return insurersMap;
1518
	}
1531
	}
-
 
1532
	
-
 
1533
	private Item getItemFromThriftItem(in.shop2020.model.v1.catalog.Item thriftItem, 
-
 
1534
            List<in.shop2020.model.v1.inventory.VendorItemPricing> tVendorPricings, 
-
 
1535
            List<in.shop2020.model.v1.inventory.VendorItemMapping> tVendorMappings,
-
 
1536
            List<in.shop2020.model.v1.catalog.SourceItemPricing> tSourceMappings,
-
 
1537
            List<in.shop2020.model.v1.catalog.Item> tSimilarItems, 
-
 
1538
            in.shop2020.model.v1.inventory.ItemInventory tItemInventory, 
-
 
1539
            List<in.shop2020.model.v1.catalog.VoucherItemMapping> tVoucherMappings, 
-
 
1540
            ItemStockPurchaseParams tStockPurchaseParams, Map<Long,String> saleHistory, Long freebieItemId,Map<String,String> stateNameVatPercentageMap){
1519
 
1541
 
-
 
1542
        Map<String, VendorItemMapping> vItemMap = new HashMap<String, VendorItemMapping>();
-
 
1543
        VendorItemMapping vItemMapping;
-
 
1544
        if(tVendorMappings != null) {
-
 
1545
            for(in.shop2020.model.v1.inventory.VendorItemMapping vim : tVendorMappings) {
-
 
1546
                vItemMapping = new VendorItemMapping();
-
 
1547
                vItemMapping.setVendorId(vim.getVendorId());
-
 
1548
                vItemMapping.setItemKey(vim.getItemKey());
-
 
1549
                vItemMap.put(vItemMapping.getVendorId() + Item.KEY_SEPARATOR + vim.getItemKey(), vItemMapping);
-
 
1550
            }
-
 
1551
        }
1520
 
1552
 
-
 
1553
        Map<Long, VendorPricings> vendorPricingMap = new HashMap<Long, VendorPricings>();
-
 
1554
        VendorPricings vPricings;
-
 
1555
        if(tVendorPricings != null) {
-
 
1556
            for(in.shop2020.model.v1.inventory.VendorItemPricing vip : tVendorPricings) {
-
 
1557
                vPricings = new VendorPricings();
-
 
1558
                vPricings.setVendorId(vip.getVendorId());
-
 
1559
                vPricings.setMop(vip.getMop());
-
 
1560
                vPricings.setDealerPrice(vip.getDealerPrice());
-
 
1561
                vPricings.setTransferPrice(vip.getTransferPrice());
-
 
1562
                vPricings.setNlc(vip.getNlc());
-
 
1563
                vendorPricingMap.put(vPricings.getVendorId(), vPricings);
1521
	
1564
            }
1522
		
1565
        }
1523
 
1566
 
-
 
1567
        Map<Long, SourcePricings> sourcePricingMap = new HashMap<Long, SourcePricings>();
-
 
1568
        SourcePricings sPricings;
-
 
1569
        if(tSourceMappings != null) {
-
 
1570
            for(in.shop2020.model.v1.catalog.SourceItemPricing sip : tSourceMappings) {
-
 
1571
                sPricings = new SourcePricings();
-
 
1572
                sPricings.setSourceId(sip.getSourceId());
-
 
1573
                sPricings.setMrp(sip.getMrp());
-
 
1574
                sPricings.setSellingPrice(sip.getSellingPrice());
-
 
1575
                sourcePricingMap.put(sPricings.getSourceId(), sPricings);
-
 
1576
            }
-
 
1577
        }
-
 
1578
        
-
 
1579
        Map<Long, Item> SimilarItemslist = new HashMap<Long, Item>();
-
 
1580
        Item sItems;
-
 
1581
        if(tSimilarItems != null) {
-
 
1582
            for(in.shop2020.model.v1.catalog.Item sit : tSimilarItems) {
-
 
1583
            	sItems = new Item();
-
 
1584
            	sItems.setCatalogItemId(sit.getCatalogItemId());
-
 
1585
            	sItems.setProductGroup(sit.getProductGroup());
-
 
1586
            	sItems.setBrand(sit.getBrand());
-
 
1587
            	sItems.setModelNumber(sit.getModelNumber());
-
 
1588
            	sItems.setModelName(sit.getModelName());
-
 
1589
            	sItems.setContentCategory(CategoryManager.getCategoryManager().getCategoryLabel(sit.getCategory()));
-
 
1590
            	SimilarItemslist.put(sit.getCatalogItemId(), sItems);
-
 
1591
            }
-
 
1592
        }
-
 
1593
 
-
 
1594
        Map<Long, ItemInventory> itemInventoryMap = new HashMap<Long, ItemInventory>();
-
 
1595
        ItemInventory warehousedata;
-
 
1596
        if(tItemInventory != null) {
-
 
1597
        	Map<Long, Long> availabilityMap = tItemInventory.getAvailability();
-
 
1598
        	Map<Long, Long> reservedMap = tItemInventory.getReserved();
-
 
1599
        	Map<Long, Long> heldMap = tItemInventory.getHeld();
-
 
1600
            for(Entry<Long, Long> availability : availabilityMap.entrySet()) {
-
 
1601
            	Map<Integer, Long> heldInventoryMap = new HashMap<Integer, Long>();
-
 
1602
            	warehousedata = new ItemInventory();
-
 
1603
            	warehousedata.setWarehouseId(availability.getKey());
-
 
1604
            	warehousedata.setAvailability(availability.getValue());
-
 
1605
            	warehousedata.setReserved(reservedMap.get(availability.getKey()));
-
 
1606
            	warehousedata.setHeld(heldMap.get(availability.getKey()));
-
 
1607
            	try {
-
 
1608
	            	if(warehousedata.getHeld()>0) {
-
 
1609
	            		InventoryService.Client inventoryClient = new InventoryClient().getClient();
-
 
1610
	            		heldInventoryMap = inventoryClient.getHeldInventoryMapForItem(thriftItem.getId(), availability.getKey());
-
 
1611
	            	}
-
 
1612
	            	if(heldInventoryMap.size()>0) {
-
 
1613
	            		for(Integer source : heldInventoryMap.keySet()) {
-
 
1614
	            			switch(source) {
-
 
1615
	            				case EBAYSOURCE: warehousedata.setEbayHeld(heldInventoryMap.get(source));
-
 
1616
	            				break;
-
 
1617
	            				case SNAPDEALSOURCE: warehousedata.setSnapdealHeld(heldInventoryMap.get(source));
-
 
1618
	            				break;
-
 
1619
	            				case FLIPKARTSOURCE: warehousedata.setFlipkartHeld(heldInventoryMap.get(source));
-
 
1620
	            			}
-
 
1621
	            		}
-
 
1622
	            	}
-
 
1623
            	} catch (Exception e) {
-
 
1624
            		logger.error("Error in getting data from holdInventoryDetail for itemId " + thriftItem.getId() + 
-
 
1625
            				" and warehouse " +availability.getKey());
-
 
1626
            	}
-
 
1627
            	itemInventoryMap.put(warehousedata.getWarehouseId(), warehousedata);
-
 
1628
            }
-
 
1629
        }
-
 
1630
        else {
-
 
1631
        	itemInventoryMap = null;
-
 
1632
        }
-
 
1633
        
-
 
1634
        Map<String, VoucherItemMapping> voucherMap = new HashMap<String, VoucherItemMapping>();
-
 
1635
        VoucherItemMapping voucher;
-
 
1636
        if(tVoucherMappings != null) {
-
 
1637
            for(in.shop2020.model.v1.catalog.VoucherItemMapping tvoucher : tVoucherMappings) {
-
 
1638
            	voucher = new VoucherItemMapping(tvoucher.getAmount(), VoucherType.findByValue((int) tvoucher.getVoucherType()).name());
-
 
1639
            	voucherMap.put(VoucherType.findByValue((int) tvoucher.getVoucherType()).name(), voucher);
-
 
1640
            }
-
 
1641
        }
-
 
1642
       
-
 
1643
        in.shop2020.catalog.dashboard.shared.ItemStockPurchaseParams stockPurchaseParams = 
-
 
1644
        	new in.shop2020.catalog.dashboard.shared.ItemStockPurchaseParams();
-
 
1645
        if(tStockPurchaseParams != null) {
-
 
1646
        	stockPurchaseParams.setItem_id(tStockPurchaseParams.getItem_id());
-
 
1647
        	stockPurchaseParams.setMinStockLevel(tStockPurchaseParams.getMinStockLevel());
-
 
1648
        	stockPurchaseParams.setNumOfDaysStock(tStockPurchaseParams.getNumOfDaysStock());
-
 
1649
        }
-
 
1650
        
-
 
1651
        Item item = new Item(thriftItem.getId(),
-
 
1652
                thriftItem.getProductGroup(),
-
 
1653
                thriftItem.getBrand(),
-
 
1654
                thriftItem.getModelNumber(),
-
 
1655
                thriftItem.getModelName(),
-
 
1656
                thriftItem.getColor(),
-
 
1657
                CategoryManager.getCategoryManager().getCategoryLabel(thriftItem.getCategory()),
-
 
1658
                thriftItem.getCategory(),
-
 
1659
                thriftItem.getComments(),
-
 
1660
                thriftItem.getCatalogItemId(),
-
 
1661
                thriftItem.getFeatureId(),
-
 
1662
                thriftItem.getFeatureDescription(),
-
 
1663
                thriftItem.isSetMrp() ? thriftItem.getMrp() : null,
-
 
1664
                thriftItem.isSetSellingPrice() ? thriftItem.getSellingPrice() : null,
-
 
1665
                thriftItem.isSetWeight() ? thriftItem.getWeight() : null,
-
 
1666
                thriftItem.getAddedOn(),
-
 
1667
                thriftItem.getStartDate(),
-
 
1668
                thriftItem.isSetComingSoonStartDate() ? thriftItem.getComingSoonStartDate() : null ,
-
 
1669
                thriftItem.isSetExpectedArrivalDate() ? thriftItem.getExpectedArrivalDate() : null ,
-
 
1670
                thriftItem.getRetireDate(),
-
 
1671
                thriftItem.getUpdatedOn(),
-
 
1672
                thriftItem.getItemStatus().name(),
-
 
1673
                thriftItem.getItemStatus().getValue(),
-
 
1674
                thriftItem.getStatus_description(),
-
 
1675
                thriftItem.getBestDealText(),
-
 
1676
                thriftItem.getBestDealsDetailsText(),
-
 
1677
                thriftItem.getBestDealsDetailsLink(),
-
 
1678
                thriftItem.isSetBestDealValue() ? thriftItem.getBestDealValue() : null,
-
 
1679
                thriftItem.isSetBestSellingRank() ? thriftItem.getBestSellingRank() : null,
-
 
1680
                thriftItem.isDefaultForEntity(),
-
 
1681
                thriftItem.isRisky(),
-
 
1682
                thriftItem.isSetExpectedDelay() ? thriftItem.getExpectedDelay() : null,
-
 
1683
                thriftItem.isIsWarehousePreferenceSticky(),
-
 
1684
                thriftItem.isHasItemNo(),
-
 
1685
                ItemType.SERIALIZED.equals(thriftItem.getType()),
-
 
1686
                thriftItem.isSetShowSellingPrice() ? thriftItem.isShowSellingPrice() : false,
-
 
1687
                thriftItem.isHoldOverride(),
-
 
1688
                thriftItem.isSetPreferredVendor() ? thriftItem.getPreferredVendor() : null,
-
 
1689
                thriftItem.isSetPreferredInsurer() ? thriftItem.getPreferredInsurer() : null,		
-
 
1690
                itemInventoryMap,
-
 
1691
                vendorPricingMap,
-
 
1692
                vItemMap,
-
 
1693
                sourcePricingMap,
-
 
1694
                SimilarItemslist,
-
 
1695
                voucherMap, 
-
 
1696
                stockPurchaseParams.getNumOfDaysStock(), 
-
 
1697
                stockPurchaseParams.getMinStockLevel(), 
-
 
1698
                saleHistory, 
-
 
1699
                freebieItemId,
-
 
1700
                thriftItem.getAsin(),
-
 
1701
                thriftItem.getHoldInventory(),
-
 
1702
                thriftItem.getDefaultInventory(),stateNameVatPercentageMap);
-
 
1703
        return item;
-
 
1704
    }
1524
}
1705
}