abirama62

FindTypeCustomerByPartnerId

May 18th, 2020
274
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package org.jleaf.erp.master.bo.partner;
  2.  
  3. import org.jleaf.core.AbstractBusinessFunction;
  4. import org.jleaf.core.BusinessFunction;
  5. import org.jleaf.core.CoreException;
  6. import org.jleaf.core.Dto;
  7. import org.jleaf.core.annotation.ErrorList;
  8. import org.jleaf.core.annotation.Info;
  9. import org.jleaf.core.annotation.InfoIn;
  10. import org.jleaf.core.annotation.InfoOut;
  11. import org.jleaf.core.dao.QueryBuilder;
  12. import org.jleaf.erp.master.MasterConstantsForSasa;
  13. import org.jleaf.erp.master.MasterExceptionConstants;
  14. import org.jleaf.erp.master.MasterExceptionConstantsForSasa;
  15. import org.jleaf.erp.master.dao.TypePartnerDao;
  16. import org.jleaf.erp.master.entity.Partner;
  17. import org.jleaf.erp.master.entity.PartnerType;
  18. import org.jleaf.erp.master.entity.TypePartner;
  19. import org.jleaf.util.DtoUtil;
  20. import org.jleaf.util.ValidationUtil;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23.  
  24. import javax.persistence.Query;
  25. import java.util.List;
  26.  
  27. // @formatter:off
  28. @Service
  29. @InfoIn(value={@Info(name = "tenantId", description = "tenant id", type=Long.class),
  30.         @Info(name = "partnerId", description = "partner id", type=Long.class)})
  31. @InfoOut(value={@Info(name = "id", description = "partner type id", type=Long.class),
  32.         @Info(name = "tenantId", description = "tenant id", type=Long.class),
  33.         @Info(name = "code", description = "type partner code", type=String.class),
  34.         @Info(name = "name", description = "type partner name", type=String.class),
  35.         @Info(name = "groupPartner", description = "group partner", type=String.class),
  36.         @Info(name = "coaId", description = "coa id", type=Long.class),
  37.         @Info(name = "active", description = "active", type = String.class)})
  38. @ErrorList(errorKeys = {MasterExceptionConstants.TYPE_PARTNER_NOT_FOUND})
  39. public class FindTypeCustomerByPartnerId extends AbstractBusinessFunction implements BusinessFunction {
  40.  
  41.     @Autowired
  42.     private TypePartnerDao typePartnerDao;
  43.  
  44.     @Override
  45.     public String getDescription() {
  46.         return "find type partner by tenant id and partner id";
  47.     }
  48.  
  49.     @SuppressWarnings("unchecked")
  50.     @Override
  51.     public Dto execute(Dto inputDto) throws Exception {
  52.         ValidationUtil.valDtoContainsKey(inputDto, "tenantId");
  53.         ValidationUtil.valDtoContainsKey(inputDto, "partnerId");
  54.  
  55.         Dto outputDto;
  56.  
  57.         Long tenantId = inputDto.getLong("tenantId");
  58.         Long partnerId = inputDto.getLong("partnerId");
  59.  
  60.         QueryBuilder builder = new QueryBuilder();
  61.         builder.add("SELECT A.type_partner_id, A.tenant_id, A.type_partner_code, A.type_partner_name, A.group_partner, A.coa_id, A.active, b.due_date ")
  62.                 .add(" FROM "+ Partner.TABLE_NAME +" C ")
  63.                 .add(" INNER JOIN "+ PartnerType.TABLE_NAME +" B ON C.partner_id = B.partner_id AND B.group_partner = :GROUP_CUSTOMER ")
  64.                 .add(" INNER JOIN "+TypePartner.TABLE_NAME+" A ON B.type_partner_id = A.type_partner_id ")
  65.                 .add(" WHERE C.tenant_id = :tenantId ")
  66.                 .add(" AND C.partner_id = :partnerId ")
  67.                 .add(" ");
  68.  
  69.         Query q = typePartnerDao.createNativeQuery(builder.toString());
  70.         q.setParameter("tenantId", tenantId);
  71.         q.setParameter("partnerId", partnerId);
  72.         q.setParameter("GROUP_CUSTOMER", MasterConstantsForSasa.GROUP_PARTNER_CODE_CUSTOMER);
  73.  
  74.         List<Object[]> typePartnerList = q.getResultList();
  75.         if (typePartnerList.size() != 0) {
  76.             outputDto = new Dto().putList("typePartnerList", DtoUtil.createDtoListFromArray(typePartnerList, "id",
  77.                     "tenantId", "code", "name", "groupPartner", "coaId", "active", "dueDate"));
  78.  
  79.             List<Dto> resultList = outputDto.getList("typePartnerList");
  80.  
  81.             return new Dto(resultList.get(0));
  82.         } else {
  83.             throw new CoreException(MasterExceptionConstantsForSasa.TYPE_PARTNER_NOT_FOUND_ID, partnerId);
  84.         }
  85.  
  86.     }
  87. }
RAW Paste Data