1DanielLee9

GetCustomerVisitPlanBySalesmanAndDate

May 7th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.90 KB | None | 0 0
  1. package org.jleaf.erp.sls.bo.tasksales;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. import org.jleaf.core.AbstractBusinessFunction;
  8. import org.jleaf.core.BusinessFunction;
  9. import org.jleaf.core.Dto;
  10. import org.jleaf.core.GeneralConstants;
  11. import org.jleaf.core.annotation.ErrorList;
  12. import org.jleaf.core.annotation.Info;
  13. import org.jleaf.core.annotation.InfoIn;
  14. import org.jleaf.core.annotation.InfoOut;
  15. import org.jleaf.core.dao.QueryBuilder;
  16. import org.jleaf.erp.sls.dao.SalesmanVisitPlanDao;
  17. //import org.jleaf.core.dao.QueryBuilder;
  18. import org.jleaf.util.DtoUtil;
  19. import org.jleaf.util.ValidationUtil;
  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24.  
  25. /**
  26.  * Get Customer Visit Plan By Salesman And Date
  27.  * @author Danielli Prasetyo Pangestu,May 5 2020
  28.  * @version 1.0.0
  29.  */
  30.  
  31. @Service
  32. @InfoIn(value={
  33.         @Info(name = "userLoginId", description = "User Login Id",type = Long.class),
  34.         @Info(name = "tenantLoginId", description = "Tenant Login Id", type = Long.class),
  35.         @Info(name = "roleLoginId", description = "Role Login Id", type = Long.class),
  36.         @Info(name = "datetime", description = "Date Time", type = String.class),
  37.        
  38.         @Info(name = "salesmanId", description = "Salesman Id", type = Long.class),
  39.         @Info(name = "date", description = "Date", type = String.class),
  40. })
  41. @InfoOut(value={
  42.         @Info(name = "customerList", description = "List of customerList(visitId, customerId, customerCode, customerName, customerAddress,longitude, latitude, checkInTimeLocal, checkInTimeServer, checkOutTimeLocal, checkOutTimeServer, strategy, remark, statusVisit)", type = List.class)
  43. })
  44. @ErrorList(errorKeys={})
  45.  
  46. public class GetCustomerVisitPlanBySalesmanAndDate extends AbstractBusinessFunction implements BusinessFunction{
  47.     private static final Logger log = LoggerFactory.getLogger(GetCustomerVisitPlanBySalesmanAndDate.class);
  48.  
  49.     @Autowired
  50.     SalesmanVisitPlanDao salesmanVisitPlanDao;
  51.    
  52.     @Override
  53.     public String getDescription() {
  54.         return "melihat daftar toko dalam periode terpilih yang harus di kunjungi";
  55.     }
  56.    
  57.     @SuppressWarnings("unchecked")
  58.     @Override
  59.     public Dto execute(Dto inputDto) throws Exception {
  60.        
  61.         //validasi
  62.         ValidationUtil.valBlankOrNull(inputDto, "salesmanId");
  63.         ValidationUtil.valBlankOrNull(inputDto, "date");
  64.        
  65.         //define input
  66.        
  67.         Long salesmanId = inputDto.getLong("salesmanId");      
  68.         log.info("SALESMAN ID = " + salesmanId );
  69.        
  70.         String date = inputDto.getString("date");
  71.         log.info("DATE = " + date );
  72.        
  73.         Long tenantId = inputDto.getLong("tenantLoginId");     
  74.         log.info("SALESMAN ID = " + tenantId );
  75.        
  76.         //set builder          
  77.        
  78.         QueryBuilder builder = new QueryBuilder();
  79.          builder.add(" SELECT A.salesman_visit_plan_id, A.tenant_id, A.customer_id, ")
  80.                 .add(" A.visit_date, A.visit_strategy, A.status_visit, ")
  81.                 .add(" COALESCE(B.check_in_time_local,0) AS check_in_time_local, COALESCE(B.check_in_time_server,0) AS check_in_time_server, COALESCE(B.check_out_time_local,0) AS check_out_time_local, ")
  82.                 .add(" COALESCE(B.check_out_time_server,0) AS check_out_time_server, COALESCE(B.check_out_remark,:null ) AS remark, C.partner_code, C.partner_name, ")
  83.                 .add(" D.address_desc, D.address1, D.address2, D.address3, D.zip_code, D.longitude ,D.latitude ")
  84.                 .add(" FROM sl_salesman_visit_plan A ")
  85.                 .add(" LEFT OUTER JOIN sl_salesman_visit_realization B ON A.salesman_visit_plan_id = B.salesman_visit_plan_id ")
  86.                 .add(" INNER JOIN m_partner C ON A.customer_id = C.partner_id ")
  87.                 .add(" INNER JOIN m_partner_address D ON C.partner_id = D.partner_id ")
  88.                 .add(" WHERE A.salesman_id = :salesmanId AND A.visit_date = :date AND D.flg_default = :flagAddress AND A.tenant_id = :tenantId ");
  89.                        
  90.          log.info("QUERY SQL : " + builder.toString());
  91.          
  92.         //set query in dao
  93.         Query query = salesmanVisitPlanDao.createNativeQuery(builder.toString());      
  94.          
  95.         //set parameter
  96.         query.setParameter("null", GeneralConstants.EMPTY_VALUE);
  97.         query.setParameter("salesmanId", salesmanId);
  98.         query.setParameter("date", date);      
  99.         query.setParameter("flagAddress", GeneralConstants.YES);
  100.         query.setParameter("tenantId", tenantId);
  101.        
  102.         //define output
  103.        
  104.         List<Object[]> result = query.getResultList();
  105.        
  106.         List<Dto> customerList = DtoUtil.createDtoListFromArray(result, "visitId", "tenantId", "customerId",
  107.                                                                         "visitDate", "strategy", "statusVisit",
  108.                                                                         "checkInTimeLocal", "checkInTimeServer", "checkOutTimeLocal",
  109.                                                                         "checkOutTimeServer", "remark", "customerCode","customerName",
  110.                                                                         "customerAddress", "customerAddress1", "customerAddress2", "customerAddress3",
  111.                                                                         "zipCode", "longitude", "latitiude"
  112.                                                                         );
  113.        
  114.         Dto outputDto = new Dto().put("customerList", customerList);
  115.         log.info("OUTPUT : " + outputDto);
  116.        
  117.         return outputDto;
  118.     }
  119.  
  120. }
Add Comment
Please, Sign In to add comment