Evra70

BT AddCheckIn

May 11th, 2020
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.85 KB | None | 0 0
  1. /**
  2.  *
  3.  */
  4. package org.jleaf.erp.sls.bo.tasksales;
  5.  
  6. import java.text.SimpleDateFormat;
  7. import java.util.Date;
  8.  
  9. import org.jleaf.common.CommonExceptionConstants;
  10. import org.jleaf.core.BusinessFunction;
  11. import org.jleaf.core.BusinessTransaction;
  12. import org.jleaf.core.CoreException;
  13. import org.jleaf.core.DefaultBusinessTransaction;
  14. import org.jleaf.core.Dto;
  15. import org.jleaf.core.GeneralConstants;
  16. import org.jleaf.core.annotation.ErrorList;
  17. import org.jleaf.core.annotation.Info;
  18. import org.jleaf.core.annotation.InfoIn;
  19. import org.jleaf.core.annotation.InfoOut;
  20. import org.jleaf.erp.master.MasterExceptionConstants;
  21. import org.jleaf.erp.sls.SalesConstants;
  22. import org.jleaf.erp.sls.SalesExceptionConstants;
  23. import org.jleaf.erp.sls.dao.SalesmanVisitPlanDao;
  24. import org.jleaf.erp.sls.dao.SalesmanVisitRealizationDao;
  25. import org.jleaf.erp.sls.entity.SalesmanVisitPlan;
  26. import org.jleaf.erp.sls.entity.SalesmanVisitRealization;
  27. import org.jleaf.util.DateUtil;
  28. import org.jleaf.util.GsonUtil;
  29. import org.jleaf.util.ValidationUtil;
  30. import org.slf4j.Logger;
  31. import org.slf4j.LoggerFactory;
  32. import org.springframework.beans.factory.annotation.Autowired;
  33. import org.springframework.beans.factory.annotation.Qualifier;
  34. import org.springframework.stereotype.Service;
  35.  
  36. /**
  37.  *
  38.  * @author WTC, Jul 4, 2013
  39.  *
  40.  */
  41. //@formatter:off
  42. @Service
  43. @InfoIn(value = {
  44.         @Info(name = "userLoginId", description = "user Login Id", type = Long.class),
  45.         @Info(name = "roleLoginId", description = "role Login Id", type = Long.class),
  46.         @Info(name = "tenantLoginId", description = "tenant Login Id", type = Long.class),
  47.         @Info(name = "visitId", description = "visit Id", type = Long.class),
  48.         @Info(name = "tenantId", description = "tenant Id", type = Long.class),
  49.         @Info(name = "salesmanId", description = "salesman Id", type = Long.class),
  50.         @Info(name = "customerId", description = "customer Id", type = Long.class),
  51.         @Info(name = "datetime", description = "datetime", type = String.class),
  52.         @Info(name = "apiKey", description = "apiKey", type = String.class),
  53.         @Info(name = "customerCode", description = "customer Code", type = String.class),
  54.         @Info(name = "image", description = "image", type = String.class),
  55.         @Info(name = "latitude", description = "latitude", type = String.class),
  56.         @Info(name = "longtitude", description = "longtitude", type = String.class),
  57.         @Info(name = "checkInTime", description = "check In Time", type = String.class),
  58.         @Info(name = "strategy", description = "strategy", type = String.class),
  59. })
  60. @InfoOut(value = {
  61.         @Info(name = "tenantId", description = "tenant Id", type = Long.class),
  62.         @Info(name = "salesmanId", description = "salesman Id", type = Long.class),
  63.         @Info(name = "customerId", description = "customer Id", type = Long.class),
  64.         @Info(name = "createUserId", description = "create User Id", type = Long.class),
  65.         @Info(name = "updateUserId", description = "update User Id", type = Long.class),
  66.         @Info(name = "version", description = "version", type = Long.class),
  67.         @Info(name = "salesmanVisitPlanId", description = "salesman Visit PlanId", type = Long.class),
  68.         @Info(name = "checkInTimeLocal", description = "check In Time Local", type = String.class),
  69.         @Info(name = "checkInTimeServer", description = "check In Time Server", type = String.class),
  70.         @Info(name = "checkInLongitude", description = "check In Longitude", type = String.class),
  71.         @Info(name = "checkInLatitude", description = "check In Latitude", type = String.class),
  72.         @Info(name = "visitDate", description = "visit Date", type = String.class),
  73.         @Info(name = "statusVisit", description = "status Visit", type = String.class),
  74.         @Info(name = "checkInPhotoFileName", description = "check In Photo File Name", type = String.class),
  75.         @Info(name = "createDatetime", description = "create Datetime", type = String.class),
  76.         @Info(name = "updateDatetime", description = "update Datetime", type = String.class),
  77. })
  78. @ErrorList(errorKeys = {
  79.         CommonExceptionConstants.TENANT_LOGIN_CANT_USED,
  80.         CommonExceptionConstants.OU_ID_NOT_FOUND,
  81.         CommonExceptionConstants.OU_NOT_LEGAL_ENTITY,
  82.         CommonExceptionConstants.OULEGAL_ID_NOT_FOUND,
  83.         MasterExceptionConstants.PARTNER_ID_NOT_FOUND,
  84.         MasterExceptionConstants.POLICY_PARTNER_AUTHORIZATION_FAILED,
  85. })
  86. //@formatter:on
  87. public class AddSalesmanVisitCheckIn extends DefaultBusinessTransaction implements BusinessTransaction {
  88.  
  89.     private static final Logger log = LoggerFactory.getLogger(AddSalesmanVisitCheckIn.class);
  90.    
  91.     @Autowired
  92.     private SalesmanVisitPlanDao salesmanVisitPlanDao;
  93.    
  94.     @Autowired
  95.     private SalesmanVisitRealizationDao salesmanVisitRalizationDao;
  96.  
  97.     @Autowired
  98.     @Qualifier("findSalesmanVisitPlanById")
  99.     private BusinessFunction findSalesmanVisitPlanById;
  100.    
  101.     @Autowired
  102.     @Qualifier("findPartnerById")
  103.     private BusinessFunction findPartnerById;
  104.  
  105.     @Override
  106.     public String getDescription() {
  107.         return "Add Salesman Visit Check In";
  108.     }
  109.  
  110.     @SuppressWarnings("unchecked")
  111.     @Override
  112.     public Dto prepare(Dto inputDto, Dto originalDto) throws Exception {
  113.         log.info("INPUT DTO prepare {} --> {}", inputDto);
  114.  
  115.         ValidationUtil.valDtoContainsKey(inputDto, "userLoginId");
  116.         ValidationUtil.valDtoContainsKey(inputDto, "tenantLoginId");
  117.         ValidationUtil.valDtoContainsKey(inputDto, "roleLoginId");
  118.         ValidationUtil.valDtoContainsKey(inputDto, "datetime");
  119.        
  120.         Long userLoginId = inputDto.getLong("userLoginId");
  121.         Long tenantLoginId = inputDto.getLong("tenantLoginId");
  122.         Long roleLoginId = inputDto.getLong("roleLoginId");
  123.         String datetime = inputDto.getString("datetime");
  124.        
  125.         Long visitId  = inputDto.getLong("visitId");
  126.         String visitStrategy = inputDto.getString("strategy");
  127.        
  128.         Long salesmanId  = inputDto.getLong("salesmanId");
  129.         Long customerId  = inputDto.getLong("customerId");
  130.         String customerCode = inputDto.getString("customerCode");
  131.         String image = inputDto.getString("image");
  132.         Double latitude = inputDto.getDouble("latitude");
  133.         Double longtitude = inputDto.getDouble("longtitude");
  134.         String checkInTime = inputDto.getString("checkInTime");
  135.         String checkInTimeServer = DateUtil.dateTimeNow();
  136.        
  137.         Dto inputFindSalesmanVistPlanById = new Dto();
  138.         inputFindSalesmanVistPlanById.put("id", visitId);
  139.  
  140.         String now = DateUtil.dateTimeNow();
  141.         if( Long.valueOf(now) < Long.valueOf(checkInTime)) {
  142.             throw new CoreException(SalesExceptionConstants.CHECK_IN_TIME_INVALID);
  143.         }
  144.        
  145.         Dto inputFindSalesmanByIdDto = new Dto();
  146.         inputFindSalesmanByIdDto.put("id", salesmanId);
  147.         Dto salesman = findPartnerById.execute(inputFindSalesmanByIdDto);
  148.        
  149.         if (!GeneralConstants.YES.equals(salesman.getString("active"))) {
  150.             throw new CoreException(SalesExceptionConstants.DATA_NOT_ACTIVE,"Salesman");
  151.         }
  152.        
  153.         Dto inputFindCustomerByIdDto = new Dto();
  154.         inputFindCustomerByIdDto.put("id", customerId);
  155.         Dto customer = findPartnerById.execute(inputFindCustomerByIdDto);
  156.        
  157.         if (!GeneralConstants.YES.equals(customer.getString("active"))) {
  158.             throw new CoreException(SalesExceptionConstants.DATA_NOT_ACTIVE,"Customer");
  159.         }
  160.        
  161.         Dto salesmanVisitPlanDto = findSalesmanVisitPlanById.execute(inputFindSalesmanVistPlanById);
  162.         String statusVisit = salesmanVisitPlanDto.getString("statusVisit");
  163.         if(!GeneralConstants.NO.equals(statusVisit) && !SalesConstants.VISIT_PENDING.equals(statusVisit)) {
  164.             throw new CoreException(SalesExceptionConstants.CANT_VISIT_TO_CUSTOMER,customerCode);
  165.         }
  166.        
  167.         salesmanVisitPlanDto.put("visitStrategy",visitStrategy);
  168.         salesmanVisitPlanDto.put("statusVisit",SalesConstants.IN_PROGRESS_TRANSACTION);
  169.         this.prepareUpdateAudit(salesmanVisitPlanDto, userLoginId, datetime);
  170.        
  171.         inputDto.put("salesmanVisitPlanDto", salesmanVisitPlanDto);
  172.        
  173.         Dto salesmanVisitRealizationDto = new Dto();
  174.         salesmanVisitRealizationDto.put("salesmanVisitPlanId", visitId);
  175.         salesmanVisitRealizationDto.put("tenantId", tenantLoginId);
  176.         salesmanVisitRealizationDto.put("salesmanId", salesmanId);
  177.         salesmanVisitRealizationDto.put("visitDate", salesmanVisitPlanDto.getString("visitDate"));
  178.         salesmanVisitRealizationDto.put("customerId", customerId);
  179.         salesmanVisitRealizationDto.put("checkInTimeLocal", checkInTime);
  180.         salesmanVisitRealizationDto.put("checkInTimeServer", checkInTimeServer);
  181.         salesmanVisitRealizationDto.put("checkInLatitude", latitude);
  182.         salesmanVisitRealizationDto.put("checkInLongitude", longtitude);
  183.         salesmanVisitRealizationDto.put("checkInPhotoFileName", image);
  184.         salesmanVisitRealizationDto.put("statusVisit", SalesConstants.IN_PROGRESS_TRANSACTION);
  185.         this.prepareInsertAudit(salesmanVisitRealizationDto, userLoginId, datetime);
  186.         this.prepareUpdateAudit(salesmanVisitRealizationDto, userLoginId, datetime);
  187.         log.info("SALESMAN VISIT REALIZATION DTO prepare {} --> {}", salesmanVisitRealizationDto);
  188.         inputDto.put("salesmanVisitRealizationDto", salesmanVisitRealizationDto);
  189.        
  190.         return null;
  191.     }
  192.  
  193.     @SuppressWarnings("unchecked")
  194.     @Override
  195.     public Dto process(Dto inputDto, Dto originalDto) throws Exception {
  196.         log.info("INPUT DTO proses {} --> {}", inputDto);
  197.        
  198.         Dto outputDto = new Dto();
  199.         Dto salesmanVisitPlanDto = inputDto.getDto("salesmanVisitPlanDto");
  200.         log.info("SALESMAN VISIT PLAN DTO proses {} --> {}", salesmanVisitPlanDto);
  201.         Dto salesmanVisitRealizationDto = inputDto.getDto("salesmanVisitRealizationDto");
  202.         log.info("SALESMAN VISIT REALIZATION DTO proses {} --> {}", salesmanVisitRealizationDto);
  203.        
  204.         SalesmanVisitPlan salesmanVisitPlan = GsonUtil.fromDto(salesmanVisitPlanDto, SalesmanVisitPlan.class);
  205.         salesmanVisitPlan = salesmanVisitPlanDao.merge(salesmanVisitPlan.getId(), salesmanVisitPlan);
  206.        
  207.         SalesmanVisitRealization salesmanVisitRealization = GsonUtil.fromDto(salesmanVisitRealizationDto, SalesmanVisitRealization.class);
  208.         salesmanVisitRalizationDao.persist(salesmanVisitRealization);
  209.                
  210.         outputDto = new Dto(salesmanVisitRealization);
  211.         return outputDto;
  212.     }
  213. }
Add Comment
Please, Sign In to add comment