Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.erp.master.bo.product;
- import java.util.List;
- import javax.persistence.Query;
- import org.jleaf.erp.master.dao.ProductDao;
- import org.jleaf.erp.master.entity.CtgrProduct;
- import org.jleaf.erp.master.entity.ExtProduct;
- import org.jleaf.erp.master.entity.Product;
- import org.jleaf.erp.master.entity.SubCtgrProduct;
- import org.jleaf.common.CommonConstants;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.Dto;
- import org.jleaf.core.annotation.ErrorList;
- import org.jleaf.core.annotation.Info;
- import org.jleaf.core.annotation.InfoIn;
- import org.jleaf.core.annotation.InfoOut;
- import org.jleaf.core.dao.CriteriaHelper;
- import org.jleaf.core.dao.QueryBuilder;
- import org.jleaf.util.DtoUtil;
- import org.jleaf.util.ValidationUtil;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- * Business Function: get product list
- *
- * @author david 23 Mei 2012
- */
- //@formatter:off
- @Service
- @InfoIn(value = {@Info(name = "tenantId", description = "tenant id", type = Long.class),
- @Info(name = "code", description = "product code", type = String.class),
- @Info(name = "name", description = "product name", type = String.class),
- @Info(name = "flagAssembly", description = "with or without assembly (Y / N)", type = String.class),
- @Info(name = "active", description = "active", type = String.class)})
- @InfoOut(value = {@Info(name = "productList", description = "product list (id, code, name, active)")})
- @ErrorList(errorKeys = {})
- //@formatter:off
- public class GetProductList extends AbstractBusinessFunction implements BusinessFunction {
- @Autowired
- ProductDao productDao;
- /*
- * @author david 23 Mei 2012
- */
- @Override
- public String getDescription() {
- return "get product list";
- }
- /*
- * @author david 23 Mei 2012
- */
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- List<Object[]> result = null;
- ValidationUtil.valDtoContainsKey(inputDto, "tenantId");
- QueryBuilder builder = new QueryBuilder();
- builder.add("SELECT a.product_id, a.product_code, a.product_name, a.active FROM ")
- .add(Product.TABLE_NAME)
- .add(" a ")
- .add(" WHERE a.tenant_id = :tenantId ")
- .addIfNotEmpty(inputDto.getString("flagAssembly"), " AND a.product_id NOT IN ( SELECT b.product_id FROM " + ExtProduct.TABLE_NAME + " b ) ")
- .addIfNotEmpty(inputDto.getString("code"), " AND " + CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("code"), "a.product_code"))
- .addIfNotEmpty(inputDto.getString("name"), " AND " + CriteriaHelper.likeExpressionIgnoreCase(inputDto.getString("name"), "a.product_name"))
- .addIfNotEmpty(inputDto.getString("active"), " AND " + CriteriaHelper.equalsExpressionIgnoreCase(inputDto.getString("active"), "a.active"))
- .add(" ORDER BY a.product_code, a.product_name ASC ");
- Query q = productDao.createNativeQuery(builder.toString());
- q.setParameter("tenantId", inputDto.getLong("tenantId"));
- result = q.getResultList();
- return new Dto().putList("productList", DtoUtil.createDtoListFromArray(result, "id", "code", "name", "active"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement