public function cloneleadcompanyAction()
 {
     set_time_limit(300);
     $page = $this->getRequest()->getQuery('page');
     $totalInserted = $this->getRequest()->getQuery('totalInserted') ?: 0;
     $dbSql = $this->getServiceLocator()->get('dbSql');
     $dbAdapter = $this->getServiceLocator()->get('dbAdapter');
     $select = $dbSql->select(array('l' => \Crm\Model\LeadMapper::TABLE_NAME));
     $select->join(['lc' => \Crm\Model\Lead\CompanyMapper::TABLE_NAME], 'l.id=lc.leadId', [], $select::JOIN_LEFT);
     $select->where(['lc.id IS NULL']);
     $select->order(['l.id ASC']);
     $paginatorAdapter = new \Zend\Paginator\Adapter\DbSelect($select, $dbAdapter);
     $paginator = new \Zend\Paginator\Paginator($paginatorAdapter);
     $paginator->setItemCountPerPage(200);
     // $page = $this->getRequest()->getQuery('page', 1);
     $paginator->setCurrentPageNumber(1);
     $leadCompanyMapper = $this->getServiceLocator()->get('\\Crm\\Model\\Lead\\CompanyMapper');
     foreach ($paginator as $pageRow) {
         $pageRow = (array) $pageRow;
         $leadCompany = new \Crm\Model\Lead\Company();
         $leadCompany->setCompanyId($pageRow['companyId']);
         $leadCompany->setLeadId($pageRow['id']);
         $leadCompanyMapper->isExisted($leadCompany);
         $leadCompany->setAccountId($pageRow['accountId']);
         $leadCompany->setOpportunityId($pageRow['opportunityId']);
         $leadCompany->setLastActivityDateTime($pageRow['lastActivityDateTime']);
         $leadCompany->setSource($pageRow['source']);
         $leadCompany->setSourceReference($pageRow['sourceReference']);
         $leadCompanyMapper->save($leadCompany);
         $totalInserted++;
     }
     $this->getViewModel()->setTerminal(true);
     $this->getViewModel()->setVariable('page', $page);
     $this->getViewModel()->setVariable('totalInserted', $totalInserted);
     $this->getViewModel()->setVariable('totalPages', $paginator->getTotalItemCount());
     if ($paginator->count()) {
         $this->getViewModel()->setVariable('redirectUri', '/system/tool/cloneleadcompany?page=' . ($page + 1) . '&totalInserted=' . $totalInserted);
     }
     $this->getViewModel()->setVariable('defaultRedirectUri', '/system/tool/cloneleadcompany');
     return $this->getViewModel();
 }