abirama62

GetAuthorizedEmbeddedOutletListAdvance

May 18th, 2020
226
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.jleaf.erp.master.bo.ou;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. import org.jleaf.common.entity.OU;
  8. import org.jleaf.common.entity.PolicyOU;
  9. import org.jleaf.common.entity.UserRole;
  10. import org.jleaf.core.*;
  11. import org.jleaf.core.annotation.ErrorList;
  12. import org.jleaf.core.annotation.Info;
  13. import org.jleaf.core.annotation.InfoIn;
  14. import org.jleaf.core.annotation.InfoOut;
  15. import org.jleaf.core.dao.CriteriaHelper;
  16. import org.jleaf.core.dao.QueryBuilder;
  17. import org.jleaf.erp.master.dao.WarehouseDao;
  18. import org.jleaf.util.DtoUtil;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23.  
  24. //@formatter:off
  25. @Service
  26. @InfoIn(value = {
  27.         @Info(name = "tenantId", type = Long.class, description = "Tenant Id"),
  28. //      @Info(name = "ouId", description = "ou id", type = Long.class),
  29.         @Info(name = "active", description = "active ", type = String.class),
  30.         @Info(name = "userLoginId", description = "user login id", type = Long.class),
  31.         @Info(name = "roleLoginId", description = "role login id", type = Long.class)
  32. })
  33. @InfoOut(value = {
  34.         @Info(name = "outletList", description = "list outlet")
  35. })
  36. @ErrorList(errorKeys = {CoreExceptionConstants.DTO_CANNOT_NULL})
  37. //@formatter:on
  38.  
  39. public class GetAuthorizedEmbeddedOutletListAdvance extends AbstractBusinessFunction implements BusinessFunction{
  40.     private static final Logger log = LoggerFactory.getLogger(GetAuthorizedEmbeddedOutletListAdvance.class);
  41.  
  42.     @Autowired
  43.     private WarehouseDao ouDao;
  44.  
  45.     @Override
  46.     public String getDescription() {
  47.         return " Get Embedded Outlet List Advance ";
  48.     }
  49.  
  50.     @SuppressWarnings("unchecked")
  51.     @Override
  52.     public Dto execute(Dto inputDto) throws Exception{
  53.  
  54.         if (inputDto == null) {
  55.             throw new CoreException(CoreExceptionConstants.DTO_CANNOT_NULL);
  56.         }
  57.         List<Object[]> result = null;
  58.         QueryBuilder builder = new QueryBuilder();
  59.         builder.add("SELECT E.outlet_id, E.ou_id, A.ou_code, A.ou_name, E.flg_internal, E.partner_id, E.warehouse_id, E.start_date_trx, E.flg_embedded, E.flg_accounts_receivable FROM ")
  60.                 .add(OU.TABLE_NAME)
  61.                 .add(" A INNER JOIN ")
  62.                 .add(UserRole.TABLE_NAME)
  63.                 .add(" C ON C.user_id = :userLoginId AND C.role_id = :roleLoginId ")
  64.                 .add(" INNER JOIN ")
  65.                 .add(PolicyOU.TABLE_NAME)
  66.                 .add(" D ON D.ou_id = A.ou_id AND D.policy_id = C.Policy_id ")
  67.                 .add(" INNER JOIN i_outlet ")
  68.                 .add(" E ON E.ou_id = A.ou_id ")
  69. //              .add("WHERE A.ou_id = :ouId ")
  70.                 .add(" WHERE A.tenant_id = " + inputDto.getLong("tenantId"))
  71.                 .add(" AND E.flg_embedded = '" + GeneralConstants.YES + "' ")
  72.                 .add(" AND A.active = :activeStatus ")
  73.                 .add(" ORDER BY ou_code, ou_name ");
  74.  
  75.         Query query = ouDao.createNativeQuery(builder.toString());
  76. //      query.setParameter("ouId", inputDto.getLong("ouId"));
  77.         query.setParameter("userLoginId", inputDto.getLong("userLoginId"));
  78.         query.setParameter("roleLoginId", inputDto.getLong("roleLoginId"));
  79.         query.setParameter("activeStatus", inputDto.getString("active"));
  80.  
  81.         log.info("user login: "+inputDto.getLong("userLoginId"));
  82.         log.info("role login: "+inputDto.getLong("roleLoginId"));
  83.  
  84.         log.info("Query for embedded outlet list>>>> "+builder.toString());
  85.         result = query.getResultList();
  86.  
  87.         return new Dto().putList("outletList", DtoUtil.createDtoListFromArray(result,
  88.                 "id", "ouId", "ouCode", "ouName", "flagInternal", "partnerId", "warehouseId", "startDateTrx", "flgEmbedded", "flgAccountsReceivable"));
  89.     }
  90. }
RAW Paste Data