@Override public boolean process() { try { List<SalesCustomer> salesCusotmerList = new ArrayList<SalesCustomer>(); HSSFWorkbook workbook = new HSSFWorkbook(fileInputStream); HSSFSheet sheet = workbook.getSheetAt(0); // Iterate through each rows one by one Iterator<Row> rowIterator = sheet.iterator(); boolean firstRow = true; while (rowIterator.hasNext()) { Row row = rowIterator.next(); if (firstRow) { firstRow = false; continue; } SalesCustomer salesCustomer = new SalesCustomer(); long customerTel = (long) row.getCell(0).getNumericCellValue(); int salesRepCode = (int) row.getCell(1).getNumericCellValue(); float commission = (float) row.getCell(2).getNumericCellValue(); SalesRep salesRep = salesRepDAO.getSalesRepByPK(salesRepCode); if (salesRep == null) { salesRep = new SalesRep(); salesRep.setCode(salesRepCode); salesRep = salesRepDAO.save(salesRep); } // salesRep=salesRepDAO.getSalesRepByPK(salesRepCode); Customer customer = customerDAO.findOne(customerTel); salesCustomer.setCommission(commission); salesCustomer.setCustomer(customer); salesCustomer.setSalesRep(salesRep); salesCusotmerList.add(salesCustomer); } salesCustomerDAO.save(salesCusotmerList); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
public List<Customer> getAllCustomers() { List<Customer> customers; customers = (List<Customer>) customerDao.findAll(); return customers; }