Advertisement
Guest User

Untitled

a guest
Mar 30th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.80 KB | None | 0 0
  1. package org.jleaf.learntransaction.bo.salesordersimple;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. import org.jleaf.common.entity.OU;
  8. import org.jleaf.core.AbstractBusinessFunction;
  9. import org.jleaf.core.BusinessFunction;
  10. import org.jleaf.core.CoreException;
  11. import org.jleaf.core.Dto;
  12. import org.jleaf.core.GeneralConstants;
  13. import org.jleaf.core.annotation.ErrorList;
  14. import org.jleaf.core.annotation.Info;
  15. import org.jleaf.core.annotation.InfoIn;
  16. import org.jleaf.core.annotation.InfoOut;
  17. import org.jleaf.core.dao.CriteriaHelper;
  18. import org.jleaf.core.dao.QueryBuilder;
  19. import org.jleaf.erp.master.entity.Partner;
  20. import org.jleaf.learntransaction.LearnConstants;
  21. import org.jleaf.learntransaction.LearnExceptionConstants;
  22. import org.jleaf.learntransaction.dao.SalesOrderSimpleDao;
  23. import org.jleaf.learntransaction.entity.SalesOrderSimple;
  24. import org.jleaf.learntransaction.entity.SalesOrderSimpleItem;
  25. import org.jleaf.util.DtoUtil;
  26. import org.jleaf.util.ValidationUtil;
  27. import org.slf4j.Logger;
  28. import org.slf4j.LoggerFactory;
  29. import org.springframework.beans.factory.annotation.Autowired;
  30. import org.springframework.stereotype.Service;
  31.  
  32. @Service
  33. @InfoIn(value={
  34. @Info(name="ouId", description="Ou id", type=Long.class, required=true),
  35. @Info(name="docNo", description="Sales order simple id", type=Long.class, required=true),
  36. @Info(name="startDate", description="Start date", type=String.class, required=true),
  37. @Info(name="endDate", description="End date", type=String.class, required=true),
  38. @Info(name="limit", description="Limit", type=Long.class, required=true),
  39. @Info(name="offset", description="Offset", type=Long.class, required=true)
  40. })
  41.  
  42. @InfoOut(value={
  43. @Info(name="soSimpleList", description="list of sales order simple {id, ouName, docNo, docDate, "
  44. + "dueDate, remark, partnerName, partnerCp, discountPersentage, discountAmount}", type=List.class, required=true)
  45. })
  46.  
  47. @ErrorList(errorKeys={
  48. LearnExceptionConstants.SALES_ORDER_SIMPLE_NOT_FOUND
  49. })
  50.  
  51. public class GetApprovedSalesOrderSimpleListAdvance extends AbstractBusinessFunction implements BusinessFunction{
  52.  
  53. private static final Logger log = LoggerFactory.getLogger(GetApprovedSalesOrderSimpleListAdvance.class);
  54.  
  55. @Autowired
  56. SalesOrderSimpleDao salesOrderSimpleDao;
  57.  
  58. @Override
  59. public String getDescription() {
  60. // TODO Auto-generated method stub
  61. return "GetApprovedSalesOrderSimpleListAdvance";
  62. }
  63.  
  64. @SuppressWarnings("unchecked")
  65. @Override
  66. public Dto execute(Dto inputDto) throws Exception {
  67. // TODO Auto-generated method stub
  68. ValidationUtil.valDtoContainsKey(inputDto, "ouId");
  69. ValidationUtil.valDtoContainsKey(inputDto, "docNo");
  70. ValidationUtil.valDtoContainsKey(inputDto, "startDate");
  71. ValidationUtil.valDtoContainsKey(inputDto, "endDate");
  72.  
  73. Long ouId = inputDto.getLong("ouId");
  74. String docNo = inputDto.getString("docNo");
  75. String startDate = inputDto.getString("startDate");
  76. String endDate = inputDto.getString("endDate");
  77. Long limit = inputDto.getLong("limit");
  78. Long offset= inputDto.getLong("offset");
  79.  
  80. QueryBuilder builder = new QueryBuilder();
  81. builder.add("SELECT A.so_id, A.ou_id, A.doc_no, A.doc_date, A.due_date, A.remark, ");
  82. builder.add(" A.partner_id, A.partner_cp, B.discount_percentage, B.discount_amount ");
  83. builder.add(" FROM " + SalesOrderSimple.TABLE_NAME + " A ");
  84. builder.add(" LEFT JOIN "+ SalesOrderSimpleItem.TABLE_NAME + " B ON A.so_id=B.so_id ");
  85. builder.add(" WHERE A.doc_date BETWEEN :startDate AND :endDate");
  86. builder.addIfNotEquals(ouId, GeneralConstants.NULL_REF_VALUE_LONG, " AND A.ou_id=:ouId ");
  87. builder.add(" AND "+ CriteriaHelper.likeExpressionIgnoreCase(LearnConstants.STATUS_DOC_APPROVED," A.status_doc "));
  88. builder.addIfNotEmpty(docNo, " AND "+CriteriaHelper.likeExpressionIgnoreCase(docNo, " A.doc_no "));
  89.  
  90. if(limit != null) builder.add(" LIMIT "+ limit);
  91. if(offset != null) builder.add(" OFFSET "+ offset);
  92.  
  93. Query query = salesOrderSimpleDao.createNativeQuery(builder.toString());
  94. query.setParameter("startDate", startDate);
  95. query.setParameter("endDate", endDate);
  96.  
  97. if(!GeneralConstants.NULL_REF_VALUE_LONG.equals(ouId)){
  98. query.setParameter("ouId", ouId);
  99. }
  100. log.debug("query[GASoSLA] : "+builder.toString());
  101. List<Object[]> resultList = query.getResultList();
  102. log.debug("list[GASoSLA] : "+resultList);
  103. if(resultList.size() == 0){
  104. throw new CoreException(LearnExceptionConstants.SALES_ORDER_SIMPLE_NOT_FOUND);
  105. }
  106. List<Dto> salesOrderSimpleList = DtoUtil.createDtoListFromArray(
  107. resultList,
  108. "id", "ouName", "docNo", "docDate", "dueDate", "remark", "partnerName", "partnerCp",
  109. "discountPercentage", "discountAmount"
  110. );
  111.  
  112. Dto outputDto = new Dto();
  113. outputDto.put("salesOrderSimpleList[GASOSLA] : ", salesOrderSimpleList);
  114. return outputDto;
  115. }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement