Skip to content

Commit

Permalink
Merge pull request #693 from portabilis/portabilis-patch-2019-01-03
Browse files Browse the repository at this point in the history
[2.2] Portabilis patch 03/01/2019
  • Loading branch information
edersoares authored Jan 3, 2020
2 parents 07aec94 + af664a8 commit c1d34b8
Show file tree
Hide file tree
Showing 119 changed files with 10,591 additions and 2,770 deletions.
15 changes: 15 additions & 0 deletions app/Exceptions/Educacenso/NotImplementedYear.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace App\Exceptions\Educacenso;

use RuntimeException;

class NotImplementedYear extends RuntimeException
{
public function __construct($year)
{
$message = sprintf('A importação do ano %s não foi implementada', $year);

parent::__construct($message);
}
}
45 changes: 45 additions & 0 deletions app/Http/Controllers/Educacenso/ImportController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Http\Controllers\Educacenso;

use App\Http\Controllers\Controller;
use App\Models\EducacensoImport;
use App\Process;
use App\Services\Educacenso\HandleFileService;
use App\Services\Educacenso\ImportService;
use App\Services\Educacenso\ImportServiceFactory;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;

class ImportController extends Controller
{
public function import(Request $request)
{
$file = $request->file('arquivo');

$yearImportService = ImportServiceFactory::createImportService($request->get('ano'));

$importFileService = new HandleFileService($yearImportService, Auth::user());
$importFileService->handleFile($file);

return redirect()->route('educacenso.history');
}

/**
* @param Request $request
* @return View
*/
public function index(Request $request)
{
$this->breadcrumb('Historico de importações', [
url('intranet/educar_index.php') => 'Escola',
]);

$this->menu(Process::EDUCACENSO_IMPORT_HISTORY);

$imports = EducacensoImport::orderBy('created_at', 'desc')->get();

return view('educacenso.import.index', compact('imports'));
}
}
74 changes: 74 additions & 0 deletions app/Jobs/EducacensoImportJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Jobs;

use App\Models\EducacensoImport as EducacensoImportModel;
use App\Services\Educacenso\ImportServiceFactory;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\DB;
use Throwable;

class EducacensoImportJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* @var EducacensoImportModel
*/
private $educacensoImport;

/**
* @var array
*/
private $importArray;

/**
* @var string
*/
private $databaseConnection;

public $timeout = 600;

/**
* Create a new job instance.
*
* @param EducacensoImportModel $educacensoImport
* @param $importArray
* @param string $databaseConnection
*/
public function __construct(EducacensoImportModel $educacensoImport, $importArray, $databaseConnection)
{
$this->educacensoImport = $educacensoImport;
$this->importArray = $importArray;
$this->databaseConnection = $databaseConnection;
}

/**
* Execute the job.
*
* @return void
* @throws Throwable
*/
public function handle()
{
DB::setDefaultConnection($this->databaseConnection);
DB::beginTransaction();

try {
$importService = ImportServiceFactory::createImportService($this->educacensoImport->year);
$importService->import($this->importArray, $this->educacensoImport->user);
} catch (Throwable $e) {
DB::rollBack();
throw $e;
}

$educacensoImport = $this->educacensoImport;
$educacensoImport->finished = true;
$educacensoImport->save();

DB::commit();
}
}
66 changes: 66 additions & 0 deletions app/Models/Educacenso/Registro00.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,70 @@ class Registro00 implements RegistroEducacenso
*/
public $anoFimAnoLetivo;

/**
* @param int $column
* @return string
*/
public function getProperty($column)
{
$properties = [
'registro',
'codigoInep',
'situacaoFuncionamento',
'inicioAnoLetivo',
'fimAnoLetivo',
'nome',
'cep',
'codigoIbgeMunicipio',
'codigoIbgeDistrito',
'logradouro',
'numero',
'complemento',
'bairro',
'ddd',
'telefone',
'telefoneOutro',
'email',
'orgaoRegional',
'zonaLocalizacao',
'localizacaoDiferenciada',
'dependenciaAdministrativa',
'orgaoEducacao',
'orgaoSeguranca',
'orgaoSaude',
'orgaoOutro',
'mantenedoraEmpresa',
'mantenedoraSindicato',
'mantenedoraOng',
'mantenedoraInstituicoes',
'mantenedoraSistemaS',
'mantenedoraOscip',
'categoriaEscolaPrivada',
'conveniadaPoderPublico',
'cnpjMantenedoraPrincipal',
'cnpjEscolaPrivada',
'regulamentacao',
'esferaFederal',
'esferaEstadual',
'esferaMunicipal',
'unidadeVinculada',
'inepEscolaSede',
'codigoIes',
];

return $properties[$column];
}

/**
* Popula os campos do model a partir de um array de colunas
* do arquivo do censo
*
* @param $arrayColumns
*/
public function hydrateModel($arrayColumns)
{
foreach ($arrayColumns as $key => $value) {
$this->{$this->getProperty($key)} = trim($value);
}
}
}
Loading

0 comments on commit c1d34b8

Please sign in to comment.