Advertisement
Guest User

Contoh BF Count

a guest
Jan 24th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. package org.jleaf.erp.sls.bo.generateverificationcode;
  2.  
  3. import javax.persistence.Query;
  4.  
  5. import org.jleaf.core.AbstractBusinessFunction;
  6. import org.jleaf.core.BusinessFunction;
  7. import org.jleaf.core.Dto;
  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.inv.dao.VerificationItemDao;
  13. import org.jleaf.erp.inv.entity.VerificationHeader;
  14. import org.jleaf.erp.inv.entity.VerificationItem;
  15. import org.jleaf.erp.master.entity.ProductCustom;
  16. import org.jleaf.util.ValidationUtil;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.stereotype.Service;
  19.  
  20. /**
  21. *
  22. * Henik, Jun 9, 2016
  23. *
  24. **/
  25. //@formatter:off
  26. @Service
  27. @InfoIn(value = {
  28. @Info(name = "tenantId", description = "tenant id", type = Long.class),
  29. @Info(name = "verificationId", description = "verification id", type = Long.class)
  30. })
  31. @InfoOut(value = {
  32. @Info(name = "count", description = "count verificationItemList", type = Long.class, required = false)
  33. })
  34. //@formatter:on
  35. public class CountGetVerificationItemListByVerificationHeader extends AbstractBusinessFunction implements BusinessFunction {
  36. @Autowired
  37. private VerificationItemDao verificationItemDao;
  38.  
  39. @Override
  40. public String getDescription() {
  41. return "Count Get Verification Item List By Verification Header";
  42. }
  43.  
  44. @Override
  45. public Dto execute(Dto inputDto) throws Exception {
  46. // Validation parameter input
  47. ValidationUtil.valDtoContainsKey(inputDto, "tenantId");
  48. ValidationUtil.valDtoContainsKey(inputDto, "verificationId");
  49.  
  50. // Get Variable
  51. Long tenantId = inputDto.getLong("tenantId");
  52. Long verificationId = inputDto.getLong("verificationId");
  53.  
  54. //@formatter:off
  55. QueryBuilder builder = new QueryBuilder();
  56. builder.add(" SELECT COUNT(1) ")
  57. .add(" FROM ").add(VerificationItem.TABLE_NAME).add(" A ")
  58. .add(" INNER JOIN ").add(VerificationHeader.TABLE_NAME).add(" B ON A.verification_id = B.verification_id ")
  59. .add(" LEFT OUTER JOIN ").add(ProductCustom.TABLE_NAME).add(" C ON A.product_id = C.product_id ")
  60. .add(" WHERE A.tenant_id = :tenantId ")
  61. .add(" AND A.verification_id = :verificationId ");
  62. //@formatter:on
  63. Query query = verificationItemDao.createNativeQuery(builder.toString());
  64. query.setParameter("tenantId", tenantId);
  65. query.setParameter("verificationId", verificationId);
  66.  
  67. Object result = query.getSingleResult();
  68. Long count = 0L;
  69.  
  70. if(result!=null){
  71. count = Long.valueOf( result.toString());
  72. }
  73.  
  74. return new Dto().put("count", count);
  75. }
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement