widana

Untitled

Feb 7th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.35 KB | None | 0 0
  1. package org.jleaf.erp.commerce.bo.cekstock;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. import org.jleaf.erp.master.entity.Product;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.jleaf.erp.master.entity.SellPriceProductForSo;
  11. import org.jleaf.erp.master.entity.Warehouse;
  12. import org.jleaf.core.AbstractBusinessFunction;
  13. import org.jleaf.core.BusinessFunction;
  14. import org.jleaf.core.Dto;
  15. import org.jleaf.erp.inv.entity.ProductBalanceStock;
  16. import org.jleaf.erp.inv.dao.ProductBalanceStockDao;
  17. import org.jleaf.erp.master.dao.ProductDao;
  18. import org.jleaf.erp.master.dao.SellPriceProductForSoDao;
  19. import org.jleaf.core.annotation.ErrorList;
  20. import org.jleaf.core.annotation.Info;
  21. import org.jleaf.core.annotation.InfoIn;
  22. import org.jleaf.core.annotation.InfoOut;
  23. import org.jleaf.core.dao.QueryBuilder;
  24. import org.jleaf.util.DtoUtil;
  25. import org.jleaf.util.ValidationUtil;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.stereotype.Service;
  28.  
  29. /**
  30. *
  31. * @author Widana Nur Azis, Feb 06, 2016
  32. *
  33. **/
  34. //@formatter:off
  35. @Service
  36. @InfoIn(value = {
  37.         @Info(name = "tenantId", description = "tenant id", type = Long.class),
  38.         @Info(name = "productId", description = "product id", type = Long.class)
  39. })
  40.  
  41. @InfoOut(value = {
  42.         @Info(name = "product", description = "list of product (id, productCode, productName)", type = List.class),
  43.         @Info(name = "stock", description = "list of stock (qty,uomName,warehouseCode,warehouseName)", type = List.class),
  44.         @Info(name = "price", description = "list of price (code,price, currCode)", type = List.class)
  45.  
  46. })
  47. @ErrorList(errorKeys = {
  48.  
  49. })
  50. //@formatter:on
  51. public class GetDetailProductById extends AbstractBusinessFunction implements BusinessFunction {
  52.  
  53.     private static Logger log = LoggerFactory.getLogger(GetDetailProductById.class);
  54.    
  55.     @Autowired
  56.     ProductDao productDao;
  57.    
  58.     @Autowired
  59.     SellPriceProductForSoDao sellPriceProductForSoDao;
  60.    
  61.     @Autowired
  62.     private ProductBalanceStockDao productBalanceStockDao;
  63.    
  64.     public String getDescription() {
  65.         // TODO Auto-generated method stub
  66.         return " untuk mendapatkan detail produk dari produk,stock dan price ";
  67.     }
  68.  
  69.     @SuppressWarnings({"unchecked"})
  70.     public Dto execute(Dto inputDto) throws Exception {
  71.  
  72.         // TODO Auto-generated method stub
  73.         ValidationUtil.valBlankOrNull(inputDto, "productId");
  74.  
  75.         ValidationUtil.valDtoContainsKey(inputDto, "productId");
  76.  
  77.         Long productId = inputDto.getLong("productId");
  78.         Long tenantId = inputDto.getLong("tenantId");
  79.        
  80.         Dto outputDtoOfList = new Dto();
  81.        
  82.         List<Object[]> resultDetailProductStock = null;
  83.         List<Object[]> resultDetailProductPrice = null;
  84.        
  85.         QueryBuilder builderProduct = new QueryBuilder();
  86.         builderProduct.add(" SELECT ")
  87.         .add(" product_id,tenant_id,product_code,product_name ")
  88.         .add(" FROM ").add(Product.TABLE_NAME)
  89.         .add(" WHERE product_id = :productId AND tenant_id = :tenantId LIMIT 1 ");
  90.        
  91.         Query queryProduct = productDao.createNativeQuery(builderProduct.toString());
  92.         queryProduct.setParameter("productId", productId);
  93.         queryProduct.setParameter("tenantId", tenantId);
  94.  
  95.         List<Object[]> list = queryProduct.getResultList();
  96.        
  97.         if(!list.isEmpty() && list.size() > 0L ) {
  98.             outputDtoOfList = outputDtoOfList.putList("product", DtoUtil.createDtoListFromArray(list, "id","tenantId","productCode","productName"));
  99.         }
  100.        
  101.         QueryBuilder builderDetailProductStock = new QueryBuilder();
  102.         builderDetailProductStock.add(" SELECT ")
  103.         .add(" COALESCE(SUM(A.qty),0),f_get_uom_name(A.base_uom_id) AS uom_name,B.warehouse_code,B.warehouse_name ")
  104.         .add(" FROM ").add(ProductBalanceStock.TABLE_NAME).add(" A ")
  105.         .add(" INNER JOIN  ").add(Warehouse.TABLE_NAME).add(" B ON A.warehouse_id = B.warehouse_id ")
  106.         .add(" WHERE A.product_id = :productId AND A.tenant_id = :tenantId ")
  107.         .add(" GROUP BY A.base_uom_id,B.warehouse_code,B.warehouse_name ")
  108.         .add(" ORDER BY B.warehouse_name ASC ");
  109.        
  110.         Query queryDetailProductStock  = productBalanceStockDao.createNativeQuery(builderDetailProductStock.toString());
  111.         queryDetailProductStock.setParameter("tenantId", tenantId);
  112.         queryDetailProductStock.setParameter("productId", productId);
  113.        
  114.         resultDetailProductStock = queryDetailProductStock.getResultList();
  115.         outputDtoOfList = outputDtoOfList.putList("stock", DtoUtil.createDtoListFromArray(resultDetailProductStock, "qty","uomName","warehouseCode","warehouseName"));
  116.  
  117.         QueryBuilder builderDetailProductPrice = new QueryBuilder();
  118.         builderDetailProductPrice.add(" SELECT ")
  119.         .add(" A.price_level,A.gross_sell_price,A.curr_code ")
  120.         .add(" FROM ").add(SellPriceProductForSo.TABLE_NAME).add(" A ")
  121.         .add(" WHERE A.tenant_id = :tenantId AND A.product_id = :productId ")
  122.         .add(" GROUP BY A.price_level,A.gross_sell_price,A.curr_code ")
  123.         .add(" ORDER BY A.gross_sell_price DESC ");
  124.  
  125.         Query queryDetailProductPrice  = productBalanceStockDao.createNativeQuery(builderDetailProductPrice.toString());
  126.         queryDetailProductPrice.setParameter("tenantId", tenantId);
  127.         queryDetailProductPrice.setParameter("productId", productId);
  128.        
  129.         resultDetailProductPrice = queryDetailProductPrice.getResultList();
  130.         outputDtoOfList = outputDtoOfList.putList("price", DtoUtil.createDtoListFromArray(resultDetailProductPrice, "code","price","currCode"));
  131.        
  132.         log.info(" OUTPUT INPUT " + outputDtoOfList);
  133.        
  134.         return outputDtoOfList;
  135.        
  136.     }
  137.  
  138. }
Advertisement
Add Comment
Please, Sign In to add comment