Merge branch 'master' of https://gitlab.com/kluppsoftware/smart-energia-api
This commit is contained in:
commit
3790cc54d5
33
app/Http/Controllers/FileController.php
Normal file
33
app/Http/Controllers/FileController.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class FileController extends Controller
|
||||
{
|
||||
public function store(Request $request)
|
||||
{
|
||||
if (!$request->hasFile('file')) {
|
||||
return $this->errorResponse( false, 'É necessário enviar um arquivo de imagem', 500);
|
||||
}
|
||||
|
||||
$file = $request->file('file');
|
||||
|
||||
$path = $file->storeAs('avatars', $file->hashName(),'s3');
|
||||
|
||||
$url = '';
|
||||
try{
|
||||
$url = Storage::disk('s3')->url($path);
|
||||
}catch(\Exception $e){
|
||||
return response()->json([
|
||||
'erro' => 'Não foi possível salvar o arquivo'
|
||||
], 500);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'url' => $url
|
||||
], 201);
|
||||
}
|
||||
}
|
||||
@ -43,6 +43,16 @@ class TelemetryController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function download(Request $request)
|
||||
{
|
||||
try {
|
||||
$response = $this->med5minContract->getDiscretization($request->all(), $request->getPathInfo());
|
||||
return (new TelemetryResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_OK);
|
||||
} catch (\Exception $ex) {
|
||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -33,7 +33,7 @@ class UserController extends Controller
|
||||
public function index(): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $this->user->withRelationsByAll('roles');
|
||||
$response = $this->user->getOrdered();
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_OK);
|
||||
@ -100,7 +100,9 @@ class UserController extends Controller
|
||||
public function update(Request $request, $id): JsonResponse
|
||||
{
|
||||
try {
|
||||
$response = $this->user->update($request->all(), $id);
|
||||
$data = $request->all();
|
||||
$data['password'] = bcrypt($request->password);
|
||||
$response = $this->user->update($data, $id);
|
||||
return (new UserResource($response))
|
||||
->response()
|
||||
->setStatusCode(Response::HTTP_ACCEPTED);
|
||||
|
||||
@ -170,9 +170,24 @@ class Med5minRepository extends AbstractRepository implements Med5minContractInt
|
||||
$fields =
|
||||
[
|
||||
'med_5min.ponto',
|
||||
'med_5min.dia_num',
|
||||
DB::raw("(
|
||||
med_5min.dia_num::INTEGER - extract(day from (
|
||||
//'med_5min.dia_num',
|
||||
// DB::raw("(
|
||||
// med_5min.dia_num::INTEGER - extract(day from (
|
||||
// (date('1899-12-30') + interval '1' day * med_5min.dia_num)
|
||||
// -
|
||||
// to_date(
|
||||
// concat(
|
||||
// extract( YEAR from date '1899-12-30' + cast (med_5min.dia_num as integer)),
|
||||
// '/',
|
||||
// extract( month from date '1899-12-30' + cast (med_5min.dia_num as integer))
|
||||
// ),
|
||||
// 'YYYY/MM'
|
||||
// )
|
||||
// ))
|
||||
// ) as dia_data"),
|
||||
// DB::raw("TO_CHAR((date('1899-12-30') + interval '1' day * med_5min.dia_num), 'DD/MM/YYYY') as day_formatted"),
|
||||
DB::raw("
|
||||
(med_5min.dia_num::INTEGER - extract(day from (
|
||||
(date('1899-12-30') + interval '1' day * med_5min.dia_num)
|
||||
-
|
||||
to_date(
|
||||
@ -184,8 +199,9 @@ class Med5minRepository extends AbstractRepository implements Med5minContractInt
|
||||
'YYYY/MM'
|
||||
)
|
||||
))
|
||||
) as dia_data"),
|
||||
DB::raw("TO_CHAR((date('1899-12-30') + interval '1' day * med_5min.dia_num), 'DD/MM/YYYY') as day_formatted"),
|
||||
) as dia_num_month
|
||||
"),
|
||||
DB::raw("TO_CHAR((date('1899-12-30') + interval '1' day * med_5min.dia_num), 'MM/YYYY') as day_formatted"),
|
||||
DB::raw("SUM(med_5min.ativa_consumo) As consumo"),
|
||||
DB::raw("SUM(med_5min.reativa_consumo+med_5min.reativa_geracao) As reativa")
|
||||
];
|
||||
@ -196,11 +212,17 @@ class Med5minRepository extends AbstractRepository implements Med5minContractInt
|
||||
|
||||
$groupBy = $this->groupField($typeField, $type);
|
||||
|
||||
return $this->execute($fields, $params)
|
||||
$result = $this->execute($fields, $params)
|
||||
->groupBy($groupBy)
|
||||
->orderBy(DB::raw("med_5min.dia_num, med_5min.ponto"))
|
||||
->orderBy(DB::raw("dia_num_month, med_5min.ponto"))
|
||||
->get();
|
||||
|
||||
foreach($result as $row) {
|
||||
$row['dia_num'] = $row['dia_num_month'];
|
||||
unset($row['dia_num_month']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function filterRow($params, $field = 'dia_num'): array
|
||||
@ -273,6 +295,10 @@ class Med5minRepository extends AbstractRepository implements Med5minContractInt
|
||||
array_splice($fields, 3);
|
||||
}
|
||||
|
||||
if($type === '1_mes') {
|
||||
$fields = ["med_5min.ponto", "dia_num_month", "day_formatted"];
|
||||
}
|
||||
|
||||
if ($typeField === false) {
|
||||
$item = ['dem_cont', 'dem_tolerancia'];
|
||||
return collect($fields)->merge($item)->all();
|
||||
|
||||
@ -6,5 +6,5 @@ use App\Repositories\ContractInterface;
|
||||
|
||||
interface UserContractInterface extends ContractInterface
|
||||
{
|
||||
|
||||
public function getOrdered();
|
||||
}
|
||||
@ -14,4 +14,8 @@ class UserRepository extends AbstractRepository implements UserContractInterface
|
||||
parent::__construct($user);
|
||||
}
|
||||
|
||||
public function getOrdered()
|
||||
{
|
||||
return $this->model->with('roles')->orderBy('name')->get();
|
||||
}
|
||||
}
|
||||
@ -52,6 +52,7 @@ Route::middleware(['auth:sanctum', 'ability:Admin'])->group(function () {
|
||||
|
||||
Route::post('aboutUs', [\App\Http\Controllers\AboutUsController::class, 'store']);
|
||||
|
||||
Route::post('sendFile', [\App\Http\Controllers\FileController::class, 'store']);
|
||||
});
|
||||
|
||||
Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
||||
@ -71,6 +72,8 @@ Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
||||
Route::post('telemetry/demand', [\App\Http\Controllers\TelemetryController::class, 'discretization']);
|
||||
Route::post('telemetry/discretization', [\App\Http\Controllers\TelemetryController::class, 'discretization']);
|
||||
|
||||
Route::get('telemetry/download', [\App\Http\Controllers\TelemetryController::class, 'download']);
|
||||
|
||||
Route::post('operation/summary', [\App\Http\Controllers\OperationSummaryController::class, 'operationSummary']); // Resumo Operações
|
||||
Route::post('operation', [\App\Http\Controllers\OperationSummaryController::class, 'index']);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user