public UploadFilesHistory getUploadFilesHistoryByFileDate(final Date fileDate) {
   final String queryStr =
       "select * from upload_files_history where file_date = '"
           + CrmUtils.getDateString(fileDate, "yyyy-MM-dd")
           + "'";
   try {
     List<UploadFilesHistory> result =
         em.createNativeQuery(queryStr, UploadFilesHistory.class).getResultList();
     if (result == null || result.isEmpty()) {
       return null;
     } else {
       return result.get(0);
     }
   } catch (Exception e) {
     log.error(e);
     return null;
   }
 }
Beispiel #2
0
  public void insertOneRow(final ExcelRowDataModel dataModel, final long dateOfFile) {
    // check if dealer's name is the same as Fico's name, then both dealer and fico are the same
    // customer.
    // otherwise need to create a customer record for Fico.
    boolean sameCustomer = false;
    if (dataModel.getDealerName().equalsIgnoreCase(dataModel.getLenderName())) {
      sameCustomer = true;
    } else {
      if (CrmUtils.trimName(dataModel.getDealerName())
          .equalsIgnoreCase(CrmUtils.trimName(dataModel.getLenderName()))) {
        sameCustomer = true;
      }
    }

    // add dealer customer record
    Customer dealer =
        ejbCustomer.getCustomerByNameAndAddress(
            dataModel.getDealerName(), dataModel.getDealerAddress(), dataModel.getDealerZipCode());
    if (dealer == null) {
      dealer = new Customer();
      dealer.setName(dataModel.getDealerName());
      dealer.setCompareName(CrmUtils.trimName(dataModel.getDealerName()));
      dealer.setStatus(CrmConstants.CustomerStatus.Open.name());
      dealer.setType(
          sameCustomer
              ? CrmConstants.CustomerType.BOTH.name()
              : CrmConstants.CustomerType.DEALER.name());
      dealer.setFileDate(new Date(dateOfFile));
      ejbCustomer.create(dealer);

      Address address = new Address();
      address.setAddress1(dataModel.getDealerAddress());
      address.setCity(dataModel.getDealerCity());
      address.setCountry("US");
      address.setCounty(dataModel.getDealerCounty());
      address.setState(dataModel.getDealerState());
      address.setZipCode(dataModel.getDealerZipCode());
      if (dataModel.getDealerAddress().startsWith("P O BOX")) {
        address.setType(CrmConstants.AddressType.POBOX.name());
      } else {
        address.setType(CrmConstants.AddressType.REGULAR.name());
      }
      address.setPrincipal(Boolean.TRUE);
      address.setCustomerId(dealer);
      ejbAddress.create(address);

    } else {
      //            //check if dealer's name from excel is the same as in the db, if it is not the
      // same, this new name should be saved into known_customer_names
      //            if (!dealer.getName().equals(dataModel.getDealerName())) {
      //                HibernateHelper.addKnownCustomerName(dataModel.getDealerName(), dealer);
      //            }
    }

    // add Finance Company customer record
    Customer fico = null;
    if (!sameCustomer) {
      fico =
          ejbCustomer.getCustomerByNameAndType(
              dataModel.getLenderName(), CrmConstants.CustomerType.FINANCE_COMPANY.name());
      if (fico == null) {
        fico = new Customer();
        fico.setName(dataModel.getLenderName());
        fico.setCompareName(CrmUtils.trimName(dataModel.getLenderName()));
        fico.setStatus(CrmConstants.CustomerStatus.Open.name());
        fico.setType(CrmConstants.CustomerType.FINANCE_COMPANY.name());
        fico.setFileDate(new Date(dateOfFile));
        ejbCustomer.create(fico);
      } else {
        //                //check if fico's name from excel is the same as in the db, if it is not
        // the same, this new name should be saved into known_customer_names
        //                if (!fico.getName().equals(dataModel.getLenderName())) {
        //                    HibernateHelper.addKnownCustomerName(dataModel.getLenderName(), fico);
        //                }
      }
    } else {
      //            //check if fico's name from excel is the same as dealer's name from excel, if it
      // is not the same, this fico's name should be saved into known_customer_names
      //            if (!dataModel.getDealerName().equalsIgnoreCase(dataModel.getLenderName())) {
      //                HibernateHelper.addKnownCustomerName(dataModel.getLenderName(), dealer);
      //            }
    }

    addNewLead(dealer, sameCustomer ? dealer : fico, dataModel, dateOfFile);
  }