Advertisement
aadddrr

Untitled

Apr 17th, 2017
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.36 KB | None | 0 0
  1. package org.jleaf.common.bo.ou;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. import org.jleaf.common.dao.OUDao;
  8. import org.jleaf.common.entity.OU;
  9. import org.jleaf.common.entity.OUType;
  10. import org.jleaf.common.entity.Tenant;
  11. import org.jleaf.core.AbstractBusinessFunction;
  12. import org.jleaf.core.BusinessFunction;
  13. import org.jleaf.core.CoreException;
  14. import org.jleaf.core.CoreExceptionConstants;
  15. import org.jleaf.core.Dto;
  16. import org.jleaf.core.annotation.Info;
  17. import org.jleaf.core.annotation.InfoIn;
  18. import org.jleaf.core.annotation.InfoOut;
  19. import org.jleaf.core.dao.CriteriaHelper;
  20. import org.jleaf.core.dao.QueryBuilder;
  21. import org.jleaf.util.DtoUtil;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24.  
  25. /**
  26.  * Find all of ou using advanced criteria
  27.  *
  28.  * @author NK
  29.  * @version 1.0
  30.  */
  31. @Service
  32. @InfoIn(value = { @Info(name = "code", description = "code ou", type = String.class),
  33.         @Info(name = "name", description = "name ou", type = String.class),
  34.         @Info(name = "tenantId", description = "tenantId", type = Long.class) })
  35. @InfoOut(value = { @Info(name = "ouList", description = "list of ou (id,code,name,ouParentId,ouParentName,ouTypeId,ouTypeName,flagBusinessUnit,flagAccounting,flagLegal,flagSubBusinessUnit,flagBranch,tenantId,tenantName,active,activeDateTime,nonActiveDateTime,version)") })
  36. public class GetOUListAdvance extends AbstractBusinessFunction implements BusinessFunction {
  37.  
  38.     @Autowired
  39.     OUDao ouDao;
  40.  
  41.     @SuppressWarnings("unchecked")
  42.     @Override
  43.     public Dto execute(Dto inputDto) throws Exception {
  44.         if (inputDto == null) {
  45.             throw new CoreException(CoreExceptionConstants.DTO_CANNOT_NULL);
  46.         }
  47.  
  48.         List<Object[]> result = null;
  49.  
  50.         QueryBuilder builder = new QueryBuilder();
  51.         //@formatter:off
  52.         builder.add(
  53.                 "SELECT e.ou_id, e.ou_code, e.ou_name,e.ou_parent_id,COALESCE(f.ou_name,''),e.ou_type_id,g.ou_type_name,g.flg_bu,g.flg_accounting,g.flg_legal,g.flg_sub_bu,g.flg_branch,e.tenant_id,h.tenant_name,e.active,e.active_datetime,e.non_active_datetime,e.version FROM ")
  54.                 .add(OU.TABLE_NAME)
  55.                 .add(" e LEFT OUTER JOIN ")
  56.                 .add(OU.TABLE_NAME)
  57.                 .add(" f ON e.ou_parent_id = f.ou_id, ")
  58.                 .add(OUType.TABLE_NAME)
  59.                 .add(" g, ")
  60.                 .add(Tenant.TABLE_NAME)
  61.                 .add(" h ")
  62.                 .add(" WHERE e.ou_type_id = g.ou_type_id AND e.tenant_id = h.tenant_id ")
  63.                 .add(" AND e.tenant_id = ")
  64.                 .add(inputDto.getLong("tenantId"))
  65.                 .addIfNotEmpty(
  66.                         inputDto.getString("code"),
  67.                         " AND "
  68.                                 + CriteriaHelper.likeExpressionIgnoreCase(
  69.                                         inputDto.getString("code"),
  70.                                         "e.ou_code"))
  71.                 .addIfNotEmpty(
  72.                         inputDto.getString("name"),
  73.                         " AND "
  74.                                 + CriteriaHelper.likeExpressionIgnoreCase(
  75.                                         inputDto.getString("name"),
  76.                                         "e.ou_name"));
  77.         //@formatter:on
  78.  
  79.         Query q = ouDao.createNativeQuery(builder.toString());
  80.  
  81.         result = q.getResultList();
  82.         return new Dto().putList("ouList", DtoUtil.createDtoListFromArray(result, "id", "code", "name", "ouParentId",
  83.                 "ouParentName", "ouTypeId", "ouTypeName", "flagBusinessUnit", "flagAccounting", "flagLegal",
  84.                 "flagSubBusinessUnit", "flagBranch", "tenantId", "tenantName", "active", "activeDateTime", "nonActiveDateTime",
  85.                 "version"));
  86.  
  87.     }
  88.  
  89.     @Override
  90.     public String getDescription() {
  91.         return "Find all ou with advanced criteria";
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement