Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.jleaf.common.bo.ou;
- import java.util.List;
- import javax.persistence.Query;
- import org.jleaf.common.dao.OUDao;
- import org.jleaf.common.entity.OU;
- import org.jleaf.common.entity.OUType;
- import org.jleaf.common.entity.Tenant;
- import org.jleaf.core.AbstractBusinessFunction;
- import org.jleaf.core.BusinessFunction;
- import org.jleaf.core.CoreException;
- import org.jleaf.core.CoreExceptionConstants;
- import org.jleaf.core.Dto;
- 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.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- /**
- * Find all of ou using advanced criteria
- *
- * @author NK
- * @version 1.0
- */
- @Service
- @InfoIn(value = { @Info(name = "code", description = "code ou", type = String.class),
- @Info(name = "name", description = "name ou", type = String.class),
- @Info(name = "tenantId", description = "tenantId", type = Long.class) })
- @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)") })
- public class GetOUListAdvance extends AbstractBusinessFunction implements BusinessFunction {
- @Autowired
- OUDao ouDao;
- @SuppressWarnings("unchecked")
- @Override
- public Dto execute(Dto inputDto) throws Exception {
- if (inputDto == null) {
- throw new CoreException(CoreExceptionConstants.DTO_CANNOT_NULL);
- }
- List<Object[]> result = null;
- QueryBuilder builder = new QueryBuilder();
- //@formatter:off
- builder.add(
- "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 ")
- .add(OU.TABLE_NAME)
- .add(" e LEFT OUTER JOIN ")
- .add(OU.TABLE_NAME)
- .add(" f ON e.ou_parent_id = f.ou_id, ")
- .add(OUType.TABLE_NAME)
- .add(" g, ")
- .add(Tenant.TABLE_NAME)
- .add(" h ")
- .add(" WHERE e.ou_type_id = g.ou_type_id AND e.tenant_id = h.tenant_id ")
- .add(" AND e.tenant_id = ")
- .add(inputDto.getLong("tenantId"))
- .addIfNotEmpty(
- inputDto.getString("code"),
- " AND "
- + CriteriaHelper.likeExpressionIgnoreCase(
- inputDto.getString("code"),
- "e.ou_code"))
- .addIfNotEmpty(
- inputDto.getString("name"),
- " AND "
- + CriteriaHelper.likeExpressionIgnoreCase(
- inputDto.getString("name"),
- "e.ou_name"));
- //@formatter:on
- Query q = ouDao.createNativeQuery(builder.toString());
- result = q.getResultList();
- return new Dto().putList("ouList", DtoUtil.createDtoListFromArray(result, "id", "code", "name", "ouParentId",
- "ouParentName", "ouTypeId", "ouTypeName", "flagBusinessUnit", "flagAccounting", "flagLegal",
- "flagSubBusinessUnit", "flagBranch", "tenantId", "tenantName", "active", "activeDateTime", "nonActiveDateTime",
- "version"));
- }
- @Override
- public String getDescription() {
- return "Find all ou with advanced criteria";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement