Advertisement
tercnem

Untitled

Jul 7th, 2020
1,110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.19 KB | None | 0 0
  1. package org.jleaf.erp.master.bo.product;
  2.  
  3. import java.util.List;
  4. import javax.persistence.Query;
  5. import org.jleaf.erp.master.dao.ProductDao;
  6. import org.jleaf.erp.master.entity.CtgrProduct;
  7. import org.jleaf.erp.master.entity.ExtProduct;
  8. import org.jleaf.erp.master.entity.Product;
  9. import org.jleaf.erp.master.entity.SubCtgrProduct;
  10. import org.jleaf.common.CommonConstants;
  11. import org.jleaf.core.AbstractBusinessFunction;
  12. import org.jleaf.core.BusinessFunction;
  13. import org.jleaf.core.Dto;
  14. import org.jleaf.core.annotation.ErrorList;
  15. import org.jleaf.core.annotation.Info;
  16. import org.jleaf.core.annotation.InfoIn;
  17. import org.jleaf.core.annotation.InfoOut;
  18. import org.jleaf.core.dao.CriteriaHelper;
  19. import org.jleaf.core.dao.QueryBuilder;
  20. import org.jleaf.util.DtoUtil;
  21. import org.jleaf.util.ValidationUtil;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24.  
  25. /**
  26.  * Business Function: get product list
  27.  *
  28.  * @author david 23 Mei 2012
  29.  */
  30. //@formatter:off
  31. @Service
  32. @InfoIn(value = {@Info(name = "tenantId", description = "tenant id", type = Long.class),
  33.                  @Info(name = "code", description = "product code", type = String.class),
  34.                  @Info(name = "name", description = "product name", type = String.class),
  35.                  @Info(name = "flagAssembly", description = "with or without assembly (Y / N)", type = String.class),
  36.                  @Info(name = "active", description = "active", type = String.class)})
  37. @InfoOut(value = {@Info(name = "productList", description = "product list (id, code, name, active)")})
  38. @ErrorList(errorKeys = {})
  39. //@formatter:off
  40. public class GetProductList extends AbstractBusinessFunction implements BusinessFunction {
  41.  
  42.     @Autowired
  43.     ProductDao productDao;
  44.    
  45.     /*
  46.      * @author david 23 Mei 2012
  47.      */
  48.     @Override
  49.     public String getDescription() {
  50.         return "get product list";
  51.     }
  52.  
  53.     /*
  54.      * @author david 23 Mei 2012
  55.      */
  56.     @Override
  57.     public Dto execute(Dto inputDto) throws Exception {
  58.         List<Object[]> result = null;
  59.        
  60.         ValidationUtil.valDtoContainsKey(inputDto, "tenantId");
  61.  
  62.         QueryBuilder builder = new QueryBuilder();
  63.         builder.add("SELECT a.product_id, a.product_code, a.product_name, a.active FROM ")
  64.                .add(Product.TABLE_NAME)
  65.                .add(" a ")
  66.                .add(" WHERE a.tenant_id = :tenantId ")
  67.                .addIfNotEmpty(inputDto.getString("flagAssembly"), " AND a.product_id NOT IN ( SELECT b.product_id FROM " + ExtProduct.TABLE_NAME + " b ) ")
  68.                .addIfNotEmpty(inputDto.getString("code"), " AND " + CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("code"), "a.product_code"))
  69.                .addIfNotEmpty(inputDto.getString("name"), " AND " + CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("name"), "a.product_name"))
  70.                .addIfNotEmpty(inputDto.getString("active"), " AND " + CriteriaHelper.equalsExpressionIgnoreCase(inputDto.getString("active"), "a.active"))
  71.                .add(" ORDER BY a.product_code, a.product_name ASC ");
  72.        
  73.         Query q = productDao.createNativeQuery(builder.toString());
  74.         q.setParameter("tenantId", inputDto.getLong("tenantId"));
  75.  
  76.         result = q.getResultList();
  77.         return new Dto().putList("productList", DtoUtil.createDtoListFromArray(result, "id", "code", "name", "active"));
  78.     }
  79.  
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement