Advertisement
Guest User

GetSoSettlementItemListByBrandIdForCopySoSettlement

a guest
Sep 16th, 2019
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.91 KB | None | 0 0
  1. package org.jleaf.erp.sls.bo.sosettlement;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. import org.jleaf.core.AbstractBusinessFunction;
  8. import org.jleaf.core.BusinessFunction;
  9. import org.jleaf.core.CoreException;
  10. import org.jleaf.core.CoreExceptionConstants;
  11. import org.jleaf.core.Dto;
  12. import org.jleaf.core.annotation.ErrorList;
  13. import org.jleaf.core.annotation.Info;
  14. import org.jleaf.core.annotation.InfoIn;
  15. import org.jleaf.core.annotation.InfoOut;
  16. import org.jleaf.core.dao.QueryBuilder;
  17. import org.jleaf.erp.master.entity.Product;
  18. import org.jleaf.erp.master.entity.ProductCustom;
  19. import org.jleaf.erp.sls.dao.SoSettlementItemDao;
  20. import org.jleaf.erp.sls.entity.SoSettlement;
  21. import org.jleaf.erp.sls.entity.SoSettlementItem;
  22. import org.jleaf.util.DtoUtil;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.stereotype.Service;
  25.  
  26. /**
  27.  *
  28.  * @author Congky, Mei 04, 2016
  29.  *
  30.  * Get So Settlement Item List By Brand Id For Copy So Settlement
  31.  *
  32. **/
  33.  
  34. //@formatter:off
  35. @Service
  36. @InfoIn(value = {
  37.         @Info(name = "soSettlementId", description = "so settlement id", type = Long.class),
  38.         @Info(name = "brandId", description = "Brand id", type = Long.class)
  39. })
  40. @InfoOut(value = {
  41.         @Info(name = "soSettlementItemList", description = "list of SO Settlement Item (id, tenantId, brandId, brandCode, brandName, productid, productCode, productName, stock, qtySo, qtySettlement, version, power)", type = List.class)
  42. })
  43. @ErrorList(errorKeys = {
  44. })
  45. //@formatter:on
  46. public class GetSoSettlementItemListByBrandIdForCopySoSettlement extends AbstractBusinessFunction implements BusinessFunction {
  47.  
  48.     @Autowired
  49.     private SoSettlementItemDao soSettlementItemDao;
  50.  
  51.     @Override
  52.     public String getDescription() {
  53.         return "Get So Settlement Item List By Brand Id For Copy So Settlement";
  54.     }
  55.  
  56.     @SuppressWarnings("unchecked")
  57.     @Override
  58.     public Dto execute(Dto inputDto) throws Exception {
  59.         if (inputDto == null) {
  60.             throw new CoreException(CoreExceptionConstants.DTO_CANNOT_NULL);
  61.         }
  62.  
  63.         List<Object[]> result = null;
  64.  
  65.         //@formatter:off
  66.         QueryBuilder builder = new QueryBuilder();
  67.         builder.add("SELECT A.so_settlement_item_id, A.so_settlement_id, A.tenant_id, B.brand_id, ")
  68.                .add(" f_get_brand_code(B.brand_id) AS brand_code, f_get_brand_name(B.brand_id) AS brand_name, ")
  69.                .add(" A.product_id, B.product_code, B.product_name, C.color, C.size, ")
  70.                .add(" f_get_uom_code(B.base_uom_id) AS uom_code, f_get_uom_name(B.base_uom_id) AS uom_name, ")
  71.                .add(" f_get_product_balance_stock_exclude_reserved(A.tenant_id, B.product_id, D.ou_id) AS stock, ")
  72.                .add(" A.qty_so, A.qty_settlement, A.version,  ")
  73.                .add(" CASE WHEN C.size = 'PL' THEN '00.00' ELSE substring(C.size, 1, 1)||lpad(substring(C.size, 2), 5, '0') END AS power_a ")
  74.                .add(" FROM ").add(SoSettlementItem.TABLE_NAME).add(" A ")
  75.                .add(" INNER JOIN ").add(Product.TABLE_NAME).add(" B ON A.product_id = B.product_id ")
  76.                .add(" INNER JOIN ").add(ProductCustom.TABLE_NAME).add(" C ON B.product_id = C.product_id ")
  77.                .add(" INNER JOIN ").add(SoSettlement.TABLE_NAME).add(" D ON A.so_settlement_id = D.so_settlement_id ")
  78.                .add(" WHERE A.so_settlement_id = :soSettlementId AND B.brand_id = :brandId AND A.qty_settlement > 0")
  79.                .add(" ORDER BY product_name COLLATE \"C\" ");
  80.         //@formatter:on
  81.  
  82.         Query query = soSettlementItemDao.createNativeQuery(builder.toString());
  83.         query.setParameter("soSettlementId", inputDto.getLong("soSettlementId"));
  84.         query.setParameter("brandId", inputDto.getLong("brandId"));
  85.  
  86.         result = query.getResultList();
  87.         return new Dto().putList("soSettlementItemList", DtoUtil.createDtoListFromArray(result, "id", "soSettlementId",
  88.                 "tenantId", "brandId", "brandCode", "brandName", "productId", "productCode", "productName", "color", "size",
  89.                 "uomCode", "uomName", "stock", "qtySo", "qtySettlement", "version", "power"));
  90.     }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement