The PLD api, operation summary and some general corrections were developed.
This commit is contained in:
parent
2335dc6540
commit
18cf6ddad5
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Auth;
|
|||||||
|
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests\LoginResquest;
|
use App\Http\Requests\LoginResquest;
|
||||||
|
use App\Models\User;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Laravel\Sanctum\PersonalAccessToken;
|
use Laravel\Sanctum\PersonalAccessToken;
|
||||||
@ -19,8 +20,10 @@ class AuthController extends Controller
|
|||||||
abort(401, 'Inavalid Credentials');
|
abort(401, 'Inavalid Credentials');
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = auth()->user();
|
$user = User::with('roles')->firstWhere('email', $credentials['email']);
|
||||||
$token = $user->createToken('API Token');
|
$role = $user->roles()->first();
|
||||||
|
|
||||||
|
$token = $user->createToken('API Token', [$role->name]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'token' => $token->plainTextToken,
|
'token' => $token->plainTextToken,
|
||||||
|
|||||||
@ -1,22 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Actions\EconomyAction;
|
|
||||||
use App\Helper\Model\filter\FilterBuilder;
|
|
||||||
use App\Http\Requests\AzuxRequest;
|
|
||||||
use App\Models\DadosCadastrais;
|
|
||||||
use App\Models\Economy;
|
|
||||||
use App\Repositories\Economy\EconomyContractInterface;
|
use App\Repositories\Economy\EconomyContractInterface;
|
||||||
use App\Repository\Economy\EconomyRepository;
|
use App\Traits\ApiResponse;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
use Illuminate\Support\Facades\Gate;
|
|
||||||
use Symfony\Component\HttpFoundation\Response as ResponseAlias;
|
|
||||||
|
|
||||||
class EconomyController extends Controller
|
class EconomyController extends Controller
|
||||||
{
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected EconomyContractInterface $economyContract
|
protected EconomyContractInterface $economyContract
|
||||||
@ -24,6 +20,46 @@ class EconomyController extends Controller
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function grossEconomy(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$response = $this->economyContract->getGrossEconomy($request->all());
|
||||||
|
|
||||||
|
return $this->successResponse($response);
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function accumulatedEconomy(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->economyContract->getAccumulatedEconomy($request->all());
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function costEstimatesEconomy(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$this->economyContract->getCostEstimatesEconomy($request->all());
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function costMWhEconomy(Request $request): JsonResponse
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$response = $this->economyContract->getCostMWhEconomy($request->all());
|
||||||
|
return $this->successResponse($response);
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function __invoke(Request $request)
|
public function __invoke(Request $request)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
|||||||
33
app/Http/Controllers/OperationController.php
Normal file
33
app/Http/Controllers/OperationController.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Resources\OperationSummaryResource;
|
||||||
|
use App\Repositories\DadosTe\DadosTeContractInterface;
|
||||||
|
use App\Traits\ApiResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
class OperationController extends Controller
|
||||||
|
{
|
||||||
|
use ApiResponse;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
protected DadosTeContractInterface $dadosTeContract
|
||||||
|
)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public function operationSummary(Request $request)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$response = $this->dadosTeContract->getOperationSummary($request->all());
|
||||||
|
return (new OperationSummaryResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
app/Http/Resources/OperationSummaryResource.php
Normal file
19
app/Http/Resources/OperationSummaryResource.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class OperationSummaryResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return parent::toArray($request);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
@ -13,4 +14,33 @@ class DadosCadastrais extends Model implements Auditing
|
|||||||
use HasFactory, SoftDeletes, Auditable;
|
use HasFactory, SoftDeletes, Auditable;
|
||||||
|
|
||||||
protected $table = 'dados_cadastrais';
|
protected $table = 'dados_cadastrais';
|
||||||
|
|
||||||
|
protected $guarded = ['cod_smart_unidade'];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'cliente',
|
||||||
|
'unidade',
|
||||||
|
'codigo_scde',
|
||||||
|
'demanda_p',
|
||||||
|
'demanda_fp',
|
||||||
|
'status_empresa',
|
||||||
|
'status_unidade',
|
||||||
|
'data_de_migracao',
|
||||||
|
'cod_smart_cliente',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $hidden = [
|
||||||
|
'updated_at',
|
||||||
|
'created_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function serializeDate(DateTimeInterface $date): string
|
||||||
|
{
|
||||||
|
return $date->format('d/m/Y H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
@ -12,4 +13,33 @@ use OwenIt\Auditing\Auditable;
|
|||||||
class DadosTe extends Model implements Auditing
|
class DadosTe extends Model implements Auditing
|
||||||
{
|
{
|
||||||
use HasFactory, SoftDeletes, Auditable;
|
use HasFactory, SoftDeletes, Auditable;
|
||||||
|
|
||||||
|
protected $table = "dados_te";
|
||||||
|
|
||||||
|
protected $guarded = ['cod_te', 'cod_smart_unidade'];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'mes',
|
||||||
|
'operacao',
|
||||||
|
'tipo',
|
||||||
|
'montante_nf',
|
||||||
|
'preco_nf',
|
||||||
|
'nf_c_icms',
|
||||||
|
'perfil_contr',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $hidden = [
|
||||||
|
'updated_at',
|
||||||
|
'created_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function serializeDate(DateTimeInterface $date): string
|
||||||
|
{
|
||||||
|
return $date->format('d/m/Y H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
@ -15,4 +16,30 @@ class Economy extends Model implements Auditing
|
|||||||
|
|
||||||
protected $table = 'economia';
|
protected $table = 'economia';
|
||||||
|
|
||||||
|
protected $guarded = ['cod_te', 'cod_smart_unidade'];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'mes',
|
||||||
|
'custo_cativo',
|
||||||
|
'custo_livre',
|
||||||
|
'economia_mensal',
|
||||||
|
'economia_acumulada',
|
||||||
|
'custo_unit',
|
||||||
|
'dad_estimado',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $hidden = [
|
||||||
|
'updated_at',
|
||||||
|
'created_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function serializeDate(DateTimeInterface $date): string
|
||||||
|
{
|
||||||
|
return $date->format('d/m/Y H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,12 @@ class Faq extends Model implements Auditing
|
|||||||
'deleted_at',
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $hidden = [
|
||||||
|
'updated_at',
|
||||||
|
'created_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
protected function serializeDate(DateTimeInterface $date): string
|
protected function serializeDate(DateTimeInterface $date): string
|
||||||
{
|
{
|
||||||
return $date->format('d/m/Y H:i:s');
|
return $date->format('d/m/Y H:i:s');
|
||||||
|
|||||||
@ -21,6 +21,12 @@ class Notifications extends Model
|
|||||||
'user_id'
|
'user_id'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $hidden = [
|
||||||
|
'updated_at',
|
||||||
|
'created_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
protected function serializeDate(DateTimeInterface $date): string
|
protected function serializeDate(DateTimeInterface $date): string
|
||||||
{
|
{
|
||||||
return $date->format('d/m/Y H:i:s');
|
return $date->format('d/m/Y H:i:s');
|
||||||
@ -28,7 +34,7 @@ class Notifications extends Model
|
|||||||
|
|
||||||
public function users(): BelongsToMany
|
public function users(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(User::class, 'notificacoes_users', 'notification_id', 'user_id', );
|
return $this->belongsToMany(User::class, 'notificacoes_users', 'notification_id', 'user_id',);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use DateTimeInterface;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
@ -17,4 +18,28 @@ class Pld extends Model implements Auditing
|
|||||||
|
|
||||||
protected $guarded = ['id'];
|
protected $guarded = ['id'];
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'dia_num',
|
||||||
|
'hora',
|
||||||
|
'submercado',
|
||||||
|
'valor',
|
||||||
|
'mes_ref',
|
||||||
|
'dia_da_semana',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected $hidden = [
|
||||||
|
'updated_at',
|
||||||
|
'created_at',
|
||||||
|
'deleted_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
protected function serializeDate(DateTimeInterface $date): string
|
||||||
|
{
|
||||||
|
return $date->format('d/m/Y H:i:s');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,9 @@ class User extends Authenticatable implements Auditing
|
|||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'password',
|
'password',
|
||||||
'remember_token',
|
'remember_token',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Repositories\DadosTe\DadosTeContractInterface;
|
||||||
|
use App\Repositories\DadosTe\DadosTeRepository;
|
||||||
use App\Repositories\Economy\EconomyContractInterface;
|
use App\Repositories\Economy\EconomyContractInterface;
|
||||||
use App\Repositories\Economy\EconomyRepository;
|
use App\Repositories\Economy\EconomyRepository;
|
||||||
use App\Repositories\Faqs\FaqContractInterface;
|
use App\Repositories\Faqs\FaqContractInterface;
|
||||||
@ -43,6 +45,10 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
EconomyContractInterface::class,
|
EconomyContractInterface::class,
|
||||||
EconomyRepository::class
|
EconomyRepository::class
|
||||||
);
|
);
|
||||||
|
$this->app->bind(
|
||||||
|
DadosTeContractInterface::class,
|
||||||
|
DadosTeRepository::class
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
12
app/Repositories/DadosTe/DadosTeContractInterface.php
Normal file
12
app/Repositories/DadosTe/DadosTeContractInterface.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repositories\DadosTe;
|
||||||
|
|
||||||
|
use App\Repositories\ContractInterface;
|
||||||
|
|
||||||
|
interface DadosTeContractInterface extends ContractInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function getOperationSummary($params);
|
||||||
|
|
||||||
|
}
|
||||||
67
app/Repositories/DadosTe/DadosTeRepository.php
Normal file
67
app/Repositories/DadosTe/DadosTeRepository.php
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Repositories\DadosTe;
|
||||||
|
|
||||||
|
use App\Models\DadosTe;
|
||||||
|
use App\Repositories\AbstractRepository;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
|
use Illuminate\Support\Arr;
|
||||||
|
|
||||||
|
|
||||||
|
class DadosTeRepository extends AbstractRepository implements DadosTeContractInterface
|
||||||
|
{
|
||||||
|
|
||||||
|
public function __construct(DadosTe $dadosTe)
|
||||||
|
{
|
||||||
|
parent::__construct($dadosTe);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function execute($params): Builder
|
||||||
|
{
|
||||||
|
$query = $this->model
|
||||||
|
->select(
|
||||||
|
'dados_te.mes',
|
||||||
|
'dados_te.cod_smart_unidade',
|
||||||
|
'dados_te.operacao',
|
||||||
|
'dados_te.tipo',
|
||||||
|
'dados_te.perfil_contr as contraparte',
|
||||||
|
'dados_te.montante_nf',
|
||||||
|
'dados_te.preco_nf',
|
||||||
|
'dados_te.nf_c_icms'
|
||||||
|
)
|
||||||
|
->join(
|
||||||
|
"dados_cadastrais",
|
||||||
|
"dados_cadastrais.cod_smart_unidade",
|
||||||
|
"=",
|
||||||
|
"dados_te.cod_smart_unidade"
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!empty($params)) {
|
||||||
|
$query = static::getFilterBuilder($params)->applyFilter($query);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOperationSummary($params): Collection|array
|
||||||
|
{
|
||||||
|
$params = static::filterRow($params);
|
||||||
|
return $this->execute($params)->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function filterRow($params, $field = 'mes'): array
|
||||||
|
{
|
||||||
|
$arr['filters'] = collect($params['filters'])
|
||||||
|
->map(function ($value, $key) use ($field) {
|
||||||
|
if ($value['field'] === $field) {
|
||||||
|
Arr::set( $value, "field", "TO_CHAR(TO_DATE(dados_te.{$value['field']}, 'YYMM'), 'MM/YYYY')");
|
||||||
|
$value['row'] = true;
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
})->all();
|
||||||
|
return $arr;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,6 +7,10 @@ use App\Repositories\ContractInterface;
|
|||||||
interface EconomyContractInterface extends ContractInterface
|
interface EconomyContractInterface extends ContractInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
public function execute($params);
|
public function getGrossEconomy($params);
|
||||||
|
public function getAccumulatedEconomy($params);
|
||||||
|
public function getCostEstimatesEconomy($params);
|
||||||
|
public function getCostMWhEconomy($params);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Repositories\Economy;
|
namespace App\Repositories\Economy;
|
||||||
|
|
||||||
use App\Models\Economy;
|
use App\Models\Economy;
|
||||||
use App\Repositories\AbstractRepository;
|
use App\Repositories\AbstractRepository;
|
||||||
use App\Support\FilterBuilder\FilterQueryBuilder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class EconomyRepository extends AbstractRepository implements EconomyContractInterface
|
class EconomyRepository extends AbstractRepository implements EconomyContractInterface
|
||||||
@ -15,15 +18,12 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
parent::__construct($economy);
|
parent::__construct($economy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute($params)
|
public function execute($params, $field): Builder
|
||||||
{
|
{
|
||||||
|
|
||||||
$test = FilterQueryBuilder::for($params);
|
|
||||||
dd($test);
|
|
||||||
|
|
||||||
$query = $this->model
|
$query = $this->model
|
||||||
->select(
|
->select(
|
||||||
$this->getRowField()
|
$field
|
||||||
)
|
)
|
||||||
->join(
|
->join(
|
||||||
"dados_cadastrais",
|
"dados_cadastrais",
|
||||||
@ -32,7 +32,56 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
"economia.cod_smart_unidade",
|
"economia.cod_smart_unidade",
|
||||||
);
|
);
|
||||||
|
|
||||||
dd( $query->limit(5)->get());
|
if (!empty($params)) {
|
||||||
|
$query = static::getFilterBuilder($params)->applyFilter($query);
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGrossEconomy($params): Collection|array
|
||||||
|
{
|
||||||
|
$field = [
|
||||||
|
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'MM/YYYY') as mes"),
|
||||||
|
DB::raw("SUM(economia.economia_acumulada) as economia_acumulada"),
|
||||||
|
DB::raw("(SUM(economia.economia_mensal)/SUM(economia.custo_livre)) as econ_percentual"),
|
||||||
|
"economia.dad_estimado"
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->execute($params, $field)
|
||||||
|
->where(DB::raw("TO_DATE(economia.mes, 'YYMM')"),
|
||||||
|
">=",
|
||||||
|
DB::raw("TO_DATE(TO_CHAR(current_date , 'YYYY-01-01'), 'YYYY-MM-DD') - interval '1' year"))
|
||||||
|
->groupBy(['mes', 'dad_estimado'])
|
||||||
|
->get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAccumulatedEconomy($params)
|
||||||
|
{
|
||||||
|
// TODO: Implement getAccumulatedEconomy() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCostEstimatesEconomy($params)
|
||||||
|
{
|
||||||
|
// TODO: Implement getCostEstimatesEconomy() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCostMWhEconomy($params)
|
||||||
|
{
|
||||||
|
$field = [
|
||||||
|
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'MM/YYYY') as mes"),
|
||||||
|
DB::raw("SUM(economia.custo_unit) as custo_unit"),
|
||||||
|
"economia.dad_estimado"
|
||||||
|
];
|
||||||
|
|
||||||
|
return $this->execute($params, $field)
|
||||||
|
->whereBetween(DB::raw("TO_DATE(economia.mes, 'YYMM')"),
|
||||||
|
[
|
||||||
|
DB::raw("TO_DATE(TO_CHAR(current_date , 'YYYY-01-01'), 'YYYY-MM-DD') - interval '1' year"),
|
||||||
|
DB::raw("TO_DATE(TO_CHAR(current_date, 'YYYY-12-31'), 'YYYY-MM-DD') ")
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->groupBy(['mes', 'dad_estimado'])
|
||||||
|
->get();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,5 +105,4 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
DB::raw("COALESCE(economia.economia_mensal / NULLIF(economia.custo_livre, 0), 0) as custo")
|
DB::raw("COALESCE(economia.economia_mensal / NULLIF(economia.custo_livre, 0), 0) as custo")
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -128,7 +128,7 @@ class PldRepository extends AbstractRepository implements PldContractInterface
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getConsumptionBySchedule($params, $field = "dia_num")
|
public function getConsumptionBySchedule($params, $field = "dia_num"): Collection|array
|
||||||
{
|
{
|
||||||
$fields = static::getRowField();
|
$fields = static::getRowField();
|
||||||
|
|
||||||
|
|||||||
@ -29,14 +29,13 @@ abstract class EntityJson implements \JsonSerializable
|
|||||||
{
|
{
|
||||||
$vars = get_object_vars($jsonData);
|
$vars = get_object_vars($jsonData);
|
||||||
foreach ($vars as $key => $value) {
|
foreach ($vars as $key => $value) {
|
||||||
if (is_array($value)){
|
$method = "set" . ucfirst($key);
|
||||||
$campo = strtolower($key);
|
if (method_exists($this, $method)) {
|
||||||
$method = "set" . ucfirst($campo);
|
$this->$method($value);
|
||||||
if (method_exists($this, $method)) {
|
} else {
|
||||||
$this->$method($value);
|
if (property_exists(get_class($this), $key)) {
|
||||||
|
$this->$key = $value;
|
||||||
}
|
}
|
||||||
} else{
|
|
||||||
$this->{$key} = $value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,10 +10,17 @@ use Illuminate\Database\Eloquent\Builder;
|
|||||||
class FilterQueryBuilder extends EntityJson implements IFilterBuilder
|
class FilterQueryBuilder extends EntityJson implements IFilterBuilder
|
||||||
{
|
{
|
||||||
|
|
||||||
|
protected int $limit = 10;
|
||||||
|
|
||||||
|
protected int $offset = 0;
|
||||||
|
|
||||||
protected array $filters = [];
|
protected array $filters = [];
|
||||||
|
|
||||||
protected array $order = [];
|
protected array $order = [];
|
||||||
|
|
||||||
|
protected array $fields = [];
|
||||||
|
|
||||||
|
|
||||||
public function applyFilter(Builder $builder): Builder
|
public function applyFilter(Builder $builder): Builder
|
||||||
{
|
{
|
||||||
if (!empty($this->getFilters())) {
|
if (!empty($this->getFilters())) {
|
||||||
@ -36,6 +43,22 @@ class FilterQueryBuilder extends EntityJson implements IFilterBuilder
|
|||||||
return $builder;
|
return $builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getFields(): array
|
||||||
|
{
|
||||||
|
return $this->fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array $fields
|
||||||
|
*/
|
||||||
|
public function setFields(array $fields): void
|
||||||
|
{
|
||||||
|
$this->fields = $fields;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
@ -68,6 +91,36 @@ class FilterQueryBuilder extends EntityJson implements IFilterBuilder
|
|||||||
$this->order = $this->arrayObjectCast($order,OrderItem::class);
|
$this->order = $this->arrayObjectCast($order,OrderItem::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getLimit(): int
|
||||||
|
{
|
||||||
|
return $this->limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $limit
|
||||||
|
*/
|
||||||
|
public function setLimit(int $limit): void
|
||||||
|
{
|
||||||
|
$this->limit = $limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getOffset(): int
|
||||||
|
{
|
||||||
|
return $this->offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $offset
|
||||||
|
*/
|
||||||
|
public function setOffset(int $offset): void
|
||||||
|
{
|
||||||
|
$this->offset = $offset;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -34,14 +34,17 @@ class FilterType
|
|||||||
"not_null"
|
"not_null"
|
||||||
];
|
];
|
||||||
|
|
||||||
public static function filter(Builder $builder, FilterItem $filter) : Builder
|
public static function filter(Builder $builder, FilterItem $filter): Builder
|
||||||
{
|
{
|
||||||
|
|
||||||
if (in_array($filter->getType(), self::WHERE_FILTER))
|
if (in_array($filter->getType(), self::WHERE_FILTER)) {
|
||||||
{
|
|
||||||
return static::makeWhereFilter($builder, $filter);
|
return static::makeWhereFilter($builder, $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in_array($filter->getType(), self::BETWEEN_FILTER)) {
|
||||||
|
return static::makeBetweenFilter($builder, $filter);
|
||||||
|
}
|
||||||
|
|
||||||
return $builder;
|
return $builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,5 +62,16 @@ class FilterType
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function makeBetweenFilter(Builder $builder, FilterItem $filter): Builder
|
||||||
|
{
|
||||||
|
if ($filter->getType() === "between") {
|
||||||
|
return $builder->whereBetween($filter->getField(), $filter->getValue());
|
||||||
|
} elseif ($filter->getType() === "not_between") {
|
||||||
|
return $builder->whereNotBetween($filter->getField(), $filter->getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -26,7 +26,12 @@ Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
|||||||
Route::post('pld/daily', [\App\Http\Controllers\PldController::class, 'consumptionByDaily']);
|
Route::post('pld/daily', [\App\Http\Controllers\PldController::class, 'consumptionByDaily']);
|
||||||
Route::post('pld/schedule', [\App\Http\Controllers\PldController::class, 'consumptionBySchedule']);
|
Route::post('pld/schedule', [\App\Http\Controllers\PldController::class, 'consumptionBySchedule']);
|
||||||
|
|
||||||
Route::post('economy', \App\Http\Controllers\EconomyController::class);
|
Route::post('economy/gross', [\App\Http\Controllers\EconomyController::class, 'grossEconomy']);
|
||||||
|
Route::post('economy/accumulated', [\App\Http\Controllers\EconomyController::class, 'accumulatedEconomy']);
|
||||||
|
Route::post('economy/estimates', [\App\Http\Controllers\EconomyController::class, 'costEstimatesEconomy']);
|
||||||
|
Route::post('economy/MWh', [\App\Http\Controllers\EconomyController::class, 'costMWhEconomy']);
|
||||||
|
|
||||||
|
Route::post('operation', [\App\Http\Controllers\OperationController::class, 'operationSummary']);
|
||||||
|
|
||||||
Route::apiResource('user', \App\Http\Controllers\UserController::class);
|
Route::apiResource('user', \App\Http\Controllers\UserController::class);
|
||||||
Route::apiResource('notification', \App\Http\Controllers\NotificationController::class);
|
Route::apiResource('notification', \App\Http\Controllers\NotificationController::class);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user