Skip to content

Instantly share code, notes, and snippets.

@ivanursul
Created December 17, 2015 09:17
Show Gist options
  • Save ivanursul/b6dbfcad213f657d6db7 to your computer and use it in GitHub Desktop.
Save ivanursul/b6dbfcad213f657d6db7 to your computer and use it in GitHub Desktop.
@Timed
@RequestMapping(value = "/inventory/products/outlet/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<List<AbstractInventoryProductsDTO>> getInventoryProductsByInventory(@PathVariable Long id, @RequestParam OrderBy orderBy) {
/*Outlet outlet = outletRepository.findOne(id);
Inventory inventory = inventoryRepository.findByOutlet(outlet);
long t1 = System.currentTimeMillis();
List<InventoryProduct> inventoryProducts;
if (USE_CACHE) {
inventoryProducts = inventoryProductRepository.findAllByInventoryCached(inventory);
} else {
inventoryProducts = inventoryProductRepository.findAllByInventory(inventory);
}
long t2 = System.currentTimeMillis();
long duration = t2 - t1;
List<AbstractInventoryProductsDTO> filteredInventoryProducts = new ArrayList<>();
t2 = System.currentTimeMillis();
if (inventoryProducts.size() > 0) {
boolean no_data = true;
for (InventoryProduct inventoryProduct : inventoryProducts) {
if (inventoryProduct.getProduct() != null) {
no_data = false;
break;
}
}
if (!no_data) {
filteredInventoryProducts = inventoryService.getFilteredProducts(orderBy, inventoryProducts);
}
}
// for( AbstractInventoryProductsDTO AbstractInventoryProductDTO : filteredInventoryProducts ) {
// List<InventoryProductDTO> InventoryProductsDTO = AbstractInventoryProductDTO.getInventoryProducts();
// for( InventoryProductDTO InventoryProductDTOObj : InventoryProductsDTO ) {
// //InventoryProductDTOObj.getProduct().getId()
// //InventoryProductDTOObj.getOutstandingQuantity()
// InventoryProductDTOObj.setOutstandingQuantity( inventoryProductRepository.getOutstandingQty(id, InventoryProductDTOObj.getProduct().getId() ) );
// }
// }
HashMap<Long, BigDecimal> outstandingQuantityMap = new HashMap<>();
for (Object result : inventoryProductRepository.getOutstandingQtyByOutlet(id)) {
Object[] pair = (Object[]) result;
outstandingQuantityMap.put(((BigInteger) pair[0]).longValue(), (BigDecimal) pair[1]);
}
for (AbstractInventoryProductsDTO AbstractInventoryProductDTO : filteredInventoryProducts) {
List<InventoryProductDTO> InventoryProductsDTO = AbstractInventoryProductDTO.getInventoryProducts();
for (InventoryProductDTO InventoryProductDTOObj : InventoryProductsDTO) {
Long productId = InventoryProductDTOObj.getProduct().getId();
BigDecimal outstandingQuantity = outstandingQuantityMap.get(productId);
if (outstandingQuantity == null) {
outstandingQuantity = new BigDecimal(0);
}
InventoryProductDTOObj.setOutstandingQuantity(outstandingQuantity);
}
}*/
Outlet outlet = outletRepository.findOne(id);
Inventory inventory = inventoryRepository.findByOutlet(outlet);
List<InventoryProduct> inventoryProducts = new ArrayList<>();
List<AbstractInventoryProductsDTO> filteredInventoryProducts = new ArrayList<>();
List<Object[]> ipOs = inventoryProductRepository.getInventoryStorageArea(id);
for (Object[] ipO : ipOs) {
InventoryProduct ip = new InventoryProduct();
ip.setInventory(inventory);
Long inventory_product_id = Long.parseLong(ipO[0].toString());
ip.setId(inventory_product_id);
BigDecimal low_level_quantity = new BigDecimal(ipO[1].toString());
ip.setLowLevelQuantity(low_level_quantity);
BigDecimal actual_quantity = new BigDecimal(ipO[2].toString());
ip.setActualQuantity(actual_quantity);
Product p = new Product();
Long product_id = Long.parseLong(ipO[3].toString());
p.setId(product_id);
String product_code = ipO[4].toString();
p.setCode(product_code);
String product_name = ipO[5].toString();
p.setTitle(product_name);
String unit_description = ipO[6].toString();
p.setUnitDescription(unit_description);
Unit u = new Unit();
Long unit_id = Long.parseLong(ipO[7].toString());
u.setId(unit_id);
String unit_symbol = ipO[8].toString();
u.setUnitSymbol(unit_symbol);
p.setUnit(u);
Company supp = new Company();
Long supplier_id = Long.parseLong(ipO[11].toString());
supp.setId(supplier_id);
String supplier_name = ipO[12].toString();
supp.setName(supplier_name);
String supplier_code = ipO[13].toString();
supp.setCode(supplier_code);
SupplierDetails supp_d = new SupplierDetails();
Long supplier_details_id = Long.parseLong(ipO[16].toString());
supp_d.setId(supplier_details_id);
String supplier_bus_reg_number = ipO[17].toString();
supp_d.setBusRegNumber(supplier_bus_reg_number);
String supplier_address = ipO[18].toString();
supp_d.setAddress(supplier_address);
try {
String supplier_fax_number = ipO[19].toString();
supp_d.setFaxNumber(supplier_fax_number);
}catch(Exception e) {}
Boolean supplier_gst_registered = Boolean.parseBoolean(ipO[20].toString());
supp_d.setGstRegistered(supplier_gst_registered);
try {
String supplier_gst_registration_number = ipO[21].toString();
supp_d.setGstRegistrationNumber(supplier_gst_registration_number);
}catch(Exception e) {}
try {
String supplier_terms_conditions = ipO[22].toString();
supp_d.setTerms_conditions(supplier_terms_conditions);
}catch(Exception e) {}
//ordering method
supp.setSupplierDetails(supp_d);
p.setCompany(supp);
Picture pic = new Picture();
Long picture_product_id = Long.parseLong(ipO[23].toString());
pic.setId(picture_product_id);
String picture_product_url = ipO[24].toString();
pic.setUrl(picture_product_url);
p.setPicture(pic);
ip.setProduct(p);
try {
StorageArea sa = new StorageArea();
Long storage_area_id = Long.parseLong(ipO[9].toString());
sa.setId(storage_area_id);
String storage_area_name = ipO[10].toString();
sa.setTitle(storage_area_name);
ip.setStorageArea(sa);
}
catch(Exception e) {
}
inventoryProducts.add(ip);
}
filteredInventoryProducts = inventoryService.getFilteredProducts(orderBy, inventoryProducts);
HashMap<Long, BigDecimal> outstandingQuantityMap = new HashMap<>();
for (Object result : inventoryProductRepository.getOutstandingQtyByOutlet(id)) {
Object[] pair = (Object[]) result;
outstandingQuantityMap.put(((BigInteger) pair[0]).longValue(), (BigDecimal) pair[1]);
}
for (AbstractInventoryProductsDTO AbstractInventoryProductDTO : filteredInventoryProducts) {
List<InventoryProductDTO> InventoryProductsDTO = AbstractInventoryProductDTO.getInventoryProducts();
for (InventoryProductDTO InventoryProductDTOObj : InventoryProductsDTO) {
Long productId = InventoryProductDTOObj.getProduct().getId();
BigDecimal outstandingQuantity = outstandingQuantityMap.get(productId);
if (outstandingQuantity == null) {
outstandingQuantity = new BigDecimal(0);
}
InventoryProductDTOObj.setOutstandingQuantity(outstandingQuantity);
}
}
return new ResponseEntity(filteredInventoryProducts, HttpStatus.OK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment