Corrections and minor adjustments in the api.
This commit is contained in:
parent
18cf6ddad5
commit
5cc94f4744
8
app/Helpers/CustomHelpers.php
Normal file
8
app/Helpers/CustomHelpers.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
if (!function_exists('checkUserId')) {
|
||||||
|
function checkUserId($client_id): bool
|
||||||
|
{
|
||||||
|
return \auth()->hasUser() && !is_null($client_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace App\Helper;
|
namespace App\Helpers;
|
||||||
|
|
||||||
class Helpers
|
class Helpers
|
||||||
{
|
{
|
||||||
@ -6,7 +6,7 @@
|
|||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Helper\Model;
|
namespace App\Helpers\Model;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of EntityJson
|
* Description of EntityJson
|
||||||
@ -6,7 +6,7 @@
|
|||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Helper\Model;
|
namespace App\Helpers\Model;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
@ -6,7 +6,7 @@
|
|||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Helper\Model;
|
namespace App\Helpers\Model;
|
||||||
|
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
namespace App\Helper\Model\filter;
|
namespace App\Helpers\Model\filter;
|
||||||
|
|
||||||
class FieldFilterBuilder extends FilterBuilder
|
class FieldFilterBuilder extends FilterBuilder
|
||||||
{
|
{
|
||||||
@ -6,9 +6,9 @@
|
|||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Helper\Model\filter;
|
namespace App\Helpers\Model\filter;
|
||||||
|
|
||||||
use App\Helper\Model\EntityJson;
|
use App\Helpers\Model\EntityJson;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Pagination\LengthAwarePaginator;
|
use Illuminate\Pagination\LengthAwarePaginator;
|
||||||
|
|
||||||
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Helper\Model\filter;
|
namespace App\Helpers\Model\filter;
|
||||||
|
|
||||||
class FilterBuilderFactory
|
class FilterBuilderFactory
|
||||||
{
|
{
|
||||||
@ -5,7 +5,7 @@
|
|||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
namespace App\Helper\Model\filter;
|
namespace App\Helpers\Model\filter;
|
||||||
|
|
||||||
class FilterBuilderResponse extends FilterBuilder
|
class FilterBuilderResponse extends FilterBuilder
|
||||||
{
|
{
|
||||||
@ -5,10 +5,10 @@
|
|||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
namespace App\Helper\Model\filter;
|
namespace App\Helpers\Model\filter;
|
||||||
|
|
||||||
|
|
||||||
use App\Helper\Model\EntityJson;
|
use App\Helpers\Model\EntityJson;
|
||||||
use Illuminate\Database\Query\Builder;
|
use Illuminate\Database\Query\Builder;
|
||||||
use Illuminate\Database\Query\Expression;
|
use Illuminate\Database\Query\Expression;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@ -6,7 +6,7 @@
|
|||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace App\Helper\Model\filter;
|
namespace App\Helpers\Model\filter;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
@ -5,7 +5,7 @@
|
|||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
namespace App\Helper\Model\filter;
|
namespace App\Helpers\Model\filter;
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
@ -5,7 +5,7 @@
|
|||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
* and open the template in the editor.
|
* and open the template in the editor.
|
||||||
*/
|
*/
|
||||||
namespace App\Helper\Model\filter;
|
namespace App\Helpers\Model\filter;
|
||||||
|
|
||||||
use App\Entity\EntityJson;
|
use App\Entity\EntityJson;
|
||||||
|
|
||||||
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Resources\EconomyResource;
|
||||||
use App\Repositories\Economy\EconomyContractInterface;
|
use App\Repositories\Economy\EconomyContractInterface;
|
||||||
use App\Traits\ApiResponse;
|
use App\Traits\ApiResponse;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
@ -20,30 +21,51 @@ class EconomyController extends Controller
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function grossEconomy(Request $request): JsonResponse
|
public function index(Request $request)
|
||||||
|
{
|
||||||
|
|
||||||
|
try {
|
||||||
|
$response = $this->economyContract->selectGlobal($request->all());
|
||||||
|
return (new EconomyResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
|
} catch (\Exception $ex) {
|
||||||
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function grossAnnualEconomy(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->economyContract->getGrossEconomy($request->all());
|
$response = $this->economyContract->getGrossAnnualEconomy($request->all());
|
||||||
|
return (new EconomyResource($response))
|
||||||
return $this->successResponse($response);
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function accumulatedEconomy(Request $request): JsonResponse
|
public function grossMonthlyEconomy(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->economyContract->getAccumulatedEconomy($request->all());
|
$response = $this->economyContract->getGrossMonthlyEconomy($request->all());
|
||||||
|
return (new EconomyResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function costEstimatesEconomy(Request $request): JsonResponse
|
public function captiveMonthlyEconomy(Request $request): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$this->economyContract->getCostEstimatesEconomy($request->all());
|
$response = $this->economyContract->getCaptiveMonthlyEconomy($request->all());
|
||||||
|
return (new EconomyResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
@ -53,45 +75,13 @@ class EconomyController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->economyContract->getCostMWhEconomy($request->all());
|
$response = $this->economyContract->getCostMWhEconomy($request->all());
|
||||||
return $this->successResponse($response);
|
return (new EconomyResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function __invoke(Request $request)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$this->economyContract->execute($request);
|
|
||||||
} catch (\Exception $exception) {
|
|
||||||
return \response()->json([], ResponseAlias::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// public function index(): JsonResponse
|
|
||||||
// {
|
|
||||||
//
|
|
||||||
// Economy::query()->select();
|
|
||||||
// abort_if(Gate::denies('teste-index'), ResponseAlias::HTTP_FORBIDDEN, '403 Forbidden');
|
|
||||||
//
|
|
||||||
// $result = DadosCadastrais::query()->limit(10)->get();
|
|
||||||
//
|
|
||||||
// return response()->json($result, 200);
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// public function teste(Request $request): JsonResponse
|
|
||||||
// {
|
|
||||||
// try {
|
|
||||||
// $data = (new EconomyRepository())->execute($request->all());
|
|
||||||
// return \response()->json($data, ResponseAlias::HTTP_OK);
|
|
||||||
// } catch (\Exception $exception) {
|
|
||||||
// return \response()->json([], ResponseAlias::HTTP_INTERNAL_SERVER_ERROR);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Resources\FaqResource;
|
||||||
use App\Repositories\Faqs\FaqContractInterface;
|
use App\Repositories\Faqs\FaqContractInterface;
|
||||||
use App\Traits\ApiResponse;
|
use App\Traits\ApiResponse;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
class FaqController extends Controller
|
class FaqController extends Controller
|
||||||
{
|
{
|
||||||
@ -19,9 +23,11 @@ class FaqController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->faq->all();
|
$response = $this->faq->all();
|
||||||
return response()->json($response, 200);
|
return (new FaqResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,9 +35,11 @@ class FaqController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->faq->create($notificationRequest->all());
|
$response = $this->faq->create($notificationRequest->all());
|
||||||
return response()->json($response, 200);
|
return (new FaqResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_CREATED);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,9 +47,11 @@ class FaqController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->faq->find($id);
|
$response = $this->faq->find($id);
|
||||||
return response()->json($response, 200);
|
return (new FaqResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,9 +59,11 @@ class FaqController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->faq->update($request->all(), $id);
|
$response = $this->faq->update($request->all(), $id);
|
||||||
return response()->json($response, 200);
|
return (new FaqResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_ACCEPTED);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,9 +71,9 @@ class FaqController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->faq->destroy($id);
|
$response = $this->faq->destroy($id);
|
||||||
return response()->json($response, 200);
|
return response()->json($response, Response::HTTP_NO_CONTENT);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Requests\StoreNotificationRequest;
|
use App\Http\Requests\StoreNotificationRequest;
|
||||||
@ -22,9 +24,11 @@ class NotificationController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->notification->all();
|
$response = $this->notification->all();
|
||||||
return response()->json($response, 200);
|
return (new NotificationResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,7 +42,7 @@ class NotificationController extends Controller
|
|||||||
->response()
|
->response()
|
||||||
->setStatusCode(Response::HTTP_CREATED);
|
->setStatusCode(Response::HTTP_CREATED);
|
||||||
} catch (\Exception $ex) {
|
} catch (\Exception $ex) {
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,9 +50,11 @@ class NotificationController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->notification->find($id);
|
$response = $this->notification->find($id);
|
||||||
return response()->json($response, 200);
|
return (new NotificationResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,9 +62,11 @@ class NotificationController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->notification->update($request->all(), $id);
|
$response = $this->notification->update($request->all(), $id);
|
||||||
return response()->json($response, 200);
|
return (new NotificationResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_ACCEPTED);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,9 +74,9 @@ class NotificationController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->notification->destroy($id);
|
$response = $this->notification->destroy($id);
|
||||||
return response()->json($response, 200);
|
return response()->json($response, Response::HTTP_NO_CONTENT);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Resources\OperationSummaryResource;
|
use App\Http\Resources\OperationSummaryResource;
|
||||||
@ -8,7 +10,7 @@ use App\Traits\ApiResponse;
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
class OperationController extends Controller
|
class OperationSummaryController extends Controller
|
||||||
{
|
{
|
||||||
use ApiResponse;
|
use ApiResponse;
|
||||||
|
|
||||||
@ -1,8 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Http\Resources\OverviewResource;
|
use App\Http\Resources\PldResource;
|
||||||
use App\Repositories\Pld\PldContractInterface;
|
use App\Repositories\Pld\PldContractInterface;
|
||||||
use App\Traits\ApiResponse;
|
use App\Traits\ApiResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@ -21,11 +23,11 @@ class PldController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->pldContract->getOverviewByRegion();
|
$response = $this->pldContract->getOverviewByRegion();
|
||||||
return (new OverviewResource($response))
|
return (new PldResource($response))
|
||||||
->response()
|
->response()
|
||||||
->setStatusCode(Response::HTTP_OK);
|
->setStatusCode(Response::HTTP_OK);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,9 +35,11 @@ class PldController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->pldContract->getListConsumption($request->all());
|
$response = $this->pldContract->getListConsumption($request->all());
|
||||||
return response()->json($response, 200);
|
return (new PldResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,9 +47,11 @@ class PldController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->pldContract->getConsumptionByDaily($request->all());
|
$response = $this->pldContract->getConsumptionByDaily($request->all());
|
||||||
return response()->json($response, 200);
|
return (new PldResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,9 +59,11 @@ class PldController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->pldContract->getConsumptionBySchedule($request->all());
|
$response = $this->pldContract->getConsumptionBySchedule($request->all());
|
||||||
return response()->json($response, 200);
|
return (new PldResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -28,10 +28,12 @@ class UserController extends Controller
|
|||||||
public function index(): JsonResponse
|
public function index(): JsonResponse
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$list = $this->user->withRelationsByAll('roles');
|
$response = $this->user->withRelationsByAll('roles');
|
||||||
return response()->json($list, 200);
|
return (new UserResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -46,12 +48,11 @@ class UserController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->user->create($request->all());
|
$response = $this->user->create($request->all());
|
||||||
|
|
||||||
return (new UserResource($response))
|
return (new UserResource($response))
|
||||||
->response()
|
->response()
|
||||||
->setStatusCode(Response::HTTP_CREATED);
|
->setStatusCode(Response::HTTP_CREATED);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,9 +66,11 @@ class UserController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->user->find($id);
|
$response = $this->user->find($id);
|
||||||
return response()->json($response, 200);
|
return (new UserResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_OK);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,9 +85,11 @@ class UserController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->user->update($request->all(), $id);
|
$response = $this->user->update($request->all(), $id);
|
||||||
return response()->json($response, 200);
|
return (new UserResource($response))
|
||||||
|
->response()
|
||||||
|
->setStatusCode(Response::HTTP_ACCEPTED);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,9 +103,9 @@ class UserController extends Controller
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$response = $this->user->destroy($id);
|
$response = $this->user->destroy($id);
|
||||||
return response()->json($response, 200);
|
return response()->json($response, Response::HTTP_NO_CONTENT);
|
||||||
}catch (\Exception $ex){
|
}catch (\Exception $ex){
|
||||||
return $this->errorResponse(false, $ex->getMessage(), 404);
|
return $this->errorResponse(false, $ex->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,7 +39,7 @@ class Kernel extends HttpKernel
|
|||||||
],
|
],
|
||||||
|
|
||||||
'api' => [
|
'api' => [
|
||||||
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
\Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
|
||||||
'throttle:api',
|
'throttle:api',
|
||||||
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
\Illuminate\Routing\Middleware\SubstituteBindings::class,
|
||||||
],
|
],
|
||||||
@ -63,5 +63,7 @@ class Kernel extends HttpKernel
|
|||||||
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
|
||||||
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
|
||||||
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
|
||||||
|
'abilities' => \Laravel\Sanctum\Http\Middleware\CheckAbilities::class,
|
||||||
|
'ability' => \Laravel\Sanctum\Http\Middleware\CheckForAnyAbility::class,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,8 +10,8 @@ namespace App\Http\Requests;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use App\Helper\Model\filter\FieldFilterBuilder;
|
use App\Helpers\Model\filter\FieldFilterBuilder;
|
||||||
use App\Helper\Model\filter\FilterBuilder;
|
use App\Helpers\Model\filter\FilterBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of AzuxRequest
|
* Description of AzuxRequest
|
||||||
|
|||||||
19
app/Http/Resources/EconomyResource.php
Normal file
19
app/Http/Resources/EconomyResource.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class EconomyResource 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Http/Resources/FaqResource.php
Normal file
19
app/Http/Resources/FaqResource.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class FaqResource 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
19
app/Http/Resources/PldResource.php
Normal file
19
app/Http/Resources/PldResource.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class PldResource 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -9,5 +9,6 @@ interface RepositoryInterfaces
|
|||||||
public function find(int $id);
|
public function find(int $id);
|
||||||
public function update(array $params, int $id);
|
public function update(array $params, int $id);
|
||||||
public function delete(int $id);
|
public function delete(int $id);
|
||||||
|
public function selectGlobal($params);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,6 @@ class DadosCadastrais extends Model implements Auditing
|
|||||||
|
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'created_at',
|
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Scopes\UserScope;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@ -33,7 +34,6 @@ class DadosTe extends Model implements Auditing
|
|||||||
|
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'created_at',
|
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -42,4 +42,9 @@ class DadosTe extends Model implements Auditing
|
|||||||
return $date->format('d/m/Y H:i:s');
|
return $date->format('d/m/Y H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function booted()
|
||||||
|
{
|
||||||
|
static::addGlobalScope(new UserScope());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Models\Scopes\UserScope;
|
||||||
use DateTimeInterface;
|
use DateTimeInterface;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@ -33,7 +34,6 @@ class Economy extends Model implements Auditing
|
|||||||
|
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'created_at',
|
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -42,4 +42,9 @@ class Economy extends Model implements Auditing
|
|||||||
return $date->format('d/m/Y H:i:s');
|
return $date->format('d/m/Y H:i:s');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static function booted()
|
||||||
|
{
|
||||||
|
static::addGlobalScope(new UserScope());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,6 @@ class Faq extends Model implements Auditing
|
|||||||
|
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'created_at',
|
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,6 @@ class Notifications extends Model
|
|||||||
|
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'created_at',
|
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -32,7 +32,6 @@ class Pld extends Model implements Auditing
|
|||||||
|
|
||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'created_at',
|
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,11 @@ class Role extends Model implements Auditing
|
|||||||
'deleted_at',
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected $hidden = [
|
||||||
|
'updated_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');
|
||||||
|
|||||||
33
app/Models/Scopes/UserScope.php
Normal file
33
app/Models/Scopes/UserScope.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Scopes;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Scope;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class UserScope implements Scope
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Apply the scope to a given Eloquent query builder.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Database\Eloquent\Builder $builder
|
||||||
|
* @param \Illuminate\Database\Eloquent\Model $model
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function apply(Builder $builder, Model $model)
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
|
||||||
|
if (checkUserId($user->client_id)) {
|
||||||
|
$builder->join(
|
||||||
|
"dados_cadastrais",
|
||||||
|
"dados_cadastrais.cod_smart_unidade",
|
||||||
|
"=",
|
||||||
|
$model->qualifyColumn("cod_smart_unidade"),
|
||||||
|
)->where('dados_cadastrais.cod_smart_cliente', '=', $user->client_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -32,7 +32,6 @@ class User extends Authenticatable implements Auditing
|
|||||||
protected $hidden = [
|
protected $hidden = [
|
||||||
'password',
|
'password',
|
||||||
'remember_token',
|
'remember_token',
|
||||||
'created_at',
|
|
||||||
'updated_at',
|
'updated_at',
|
||||||
'deleted_at',
|
'deleted_at',
|
||||||
];
|
];
|
||||||
|
|||||||
@ -10,4 +10,5 @@ interface ContractInterface
|
|||||||
public function update(array $params, $id);
|
public function update(array $params, $id);
|
||||||
public function destroy($id);
|
public function destroy($id);
|
||||||
public function withRelationsByAll($relations);
|
public function withRelationsByAll($relations);
|
||||||
|
public function selectGlobal($params);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,7 @@ use App\Repositories\AbstractRepository;
|
|||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
use Illuminate\Database\Eloquent\Collection;
|
||||||
use Illuminate\Support\Arr;
|
use Illuminate\Support\Arr;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
|
||||||
class DadosTeRepository extends AbstractRepository implements DadosTeContractInterface
|
class DadosTeRepository extends AbstractRepository implements DadosTeContractInterface
|
||||||
@ -23,7 +24,7 @@ class DadosTeRepository extends AbstractRepository implements DadosTeContractInt
|
|||||||
{
|
{
|
||||||
$query = $this->model
|
$query = $this->model
|
||||||
->select(
|
->select(
|
||||||
'dados_te.mes',
|
DB::raw("TO_CHAR(TO_DATE(dados_te.mes, 'YYMM'), 'MM/YYYY') as mes"),
|
||||||
'dados_te.cod_smart_unidade',
|
'dados_te.cod_smart_unidade',
|
||||||
'dados_te.operacao',
|
'dados_te.operacao',
|
||||||
'dados_te.tipo',
|
'dados_te.tipo',
|
||||||
@ -31,12 +32,6 @@ class DadosTeRepository extends AbstractRepository implements DadosTeContractInt
|
|||||||
'dados_te.montante_nf',
|
'dados_te.montante_nf',
|
||||||
'dados_te.preco_nf',
|
'dados_te.preco_nf',
|
||||||
'dados_te.nf_c_icms'
|
'dados_te.nf_c_icms'
|
||||||
)
|
|
||||||
->join(
|
|
||||||
"dados_cadastrais",
|
|
||||||
"dados_cadastrais.cod_smart_unidade",
|
|
||||||
"=",
|
|
||||||
"dados_te.cod_smart_unidade"
|
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!empty($params)) {
|
if (!empty($params)) {
|
||||||
|
|||||||
@ -6,10 +6,9 @@ use App\Repositories\ContractInterface;
|
|||||||
|
|
||||||
interface EconomyContractInterface extends ContractInterface
|
interface EconomyContractInterface extends ContractInterface
|
||||||
{
|
{
|
||||||
|
public function getGrossAnnualEconomy($params);
|
||||||
public function getGrossEconomy($params);
|
public function getGrossMonthlyEconomy($params);
|
||||||
public function getAccumulatedEconomy($params);
|
public function getCaptiveMonthlyEconomy($params);
|
||||||
public function getCostEstimatesEconomy($params);
|
|
||||||
public function getCostMWhEconomy($params);
|
public function getCostMWhEconomy($params);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -21,16 +21,7 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
public function execute($params, $field): Builder
|
public function execute($params, $field): Builder
|
||||||
{
|
{
|
||||||
|
|
||||||
$query = $this->model
|
$query = $this->model->select($field);
|
||||||
->select(
|
|
||||||
$field
|
|
||||||
)
|
|
||||||
->join(
|
|
||||||
"dados_cadastrais",
|
|
||||||
"dados_cadastrais.cod_smart_unidade",
|
|
||||||
"=",
|
|
||||||
"economia.cod_smart_unidade",
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!empty($params)) {
|
if (!empty($params)) {
|
||||||
$query = static::getFilterBuilder($params)->applyFilter($query);
|
$query = static::getFilterBuilder($params)->applyFilter($query);
|
||||||
@ -38,7 +29,24 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getGrossEconomy($params): Collection|array
|
public function getGrossAnnualEconomy($params): Collection|array
|
||||||
|
{
|
||||||
|
$field = [
|
||||||
|
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'YYYY') as ano"),
|
||||||
|
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 getGrossMonthlyEconomy($params)
|
||||||
{
|
{
|
||||||
$field = [
|
$field = [
|
||||||
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'MM/YYYY') as mes"),
|
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'MM/YYYY') as mes"),
|
||||||
@ -55,14 +63,26 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
->get();
|
->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAccumulatedEconomy($params)
|
public function getCaptiveMonthlyEconomy($params)
|
||||||
{
|
{
|
||||||
// TODO: Implement getAccumulatedEconomy() method.
|
$field = [
|
||||||
}
|
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'MM/YYYY') as mes"),
|
||||||
|
DB::raw("SUM(economia.custo_cativo) as custo_cativo"),
|
||||||
|
DB::raw("SUM(economia.custo_livre) as custo_livre"),
|
||||||
|
DB::raw("SUM(economia.economia_mensal) as economia_mensal"),
|
||||||
|
DB::raw("(SUM(economia_mensal)/SUM(custo_livre)) as econ_percentual"),
|
||||||
|
"economia.dad_estimado"
|
||||||
|
];
|
||||||
|
|
||||||
public function getCostEstimatesEconomy($params)
|
return $this->execute($params, $field)
|
||||||
{
|
->whereBetween(
|
||||||
// TODO: Implement getCostEstimatesEconomy() method.
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCostMWhEconomy($params)
|
public function getCostMWhEconomy($params)
|
||||||
@ -74,12 +94,12 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
];
|
];
|
||||||
|
|
||||||
return $this->execute($params, $field)
|
return $this->execute($params, $field)
|
||||||
->whereBetween(DB::raw("TO_DATE(economia.mes, 'YYMM')"),
|
->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-01-01'), 'YYYY-MM-DD') - interval '1' year"),
|
||||||
DB::raw("TO_DATE(TO_CHAR(current_date, 'YYYY-12-31'), 'YYYY-MM-DD') ")
|
DB::raw("TO_DATE(TO_CHAR(current_date, 'YYYY-12-31'), 'YYYY-MM-DD') ")
|
||||||
]
|
])
|
||||||
)
|
|
||||||
->groupBy(['mes', 'dad_estimado'])
|
->groupBy(['mes', 'dad_estimado'])
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
@ -89,9 +109,7 @@ class EconomyRepository extends AbstractRepository implements EconomyContractInt
|
|||||||
protected function where($query)
|
protected function where($query)
|
||||||
{
|
{
|
||||||
return $query->where(
|
return $query->where(
|
||||||
DB::raw(
|
DB::raw()
|
||||||
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -37,4 +37,15 @@ trait MethodsTrait
|
|||||||
{
|
{
|
||||||
return $this->model->with($relations)->get();
|
return $this->model->with($relations)->get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function selectGlobal($params)
|
||||||
|
{
|
||||||
|
$filter = static::getFilterBuilder($params);
|
||||||
|
|
||||||
|
$query = $this->model->select($filter->getFields());
|
||||||
|
|
||||||
|
$result = $filter->applyFilter($query)->get();
|
||||||
|
|
||||||
|
dd($result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,67 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Repository;
|
|
||||||
|
|
||||||
use App\Helper\Model\filter\FilterBuilder;
|
|
||||||
use Exception;
|
|
||||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
abstract class AbstractRepository
|
|
||||||
{
|
|
||||||
|
|
||||||
protected Model $model;
|
|
||||||
|
|
||||||
abstract protected function model();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws BindingResolutionException
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->model = $this->resolveModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getJsonObject($json, $className)
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
$jsonData = json_decode(json_encode($json), false);
|
|
||||||
|
|
||||||
$obj = new $className;
|
|
||||||
|
|
||||||
if (!isset($jsonData) && method_exists($obj, 'jsonToObject'))
|
|
||||||
{
|
|
||||||
throw new Exception("Request inválido");
|
|
||||||
}
|
|
||||||
|
|
||||||
$obj->jsonSetObject($jsonData);
|
|
||||||
|
|
||||||
return $obj;
|
|
||||||
|
|
||||||
} catch (Exception $ex) {
|
|
||||||
return $ex->getMessage();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __get($name)
|
|
||||||
{
|
|
||||||
return $this->model->{$name};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws BindingResolutionException
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
protected function resolveModel(): Model
|
|
||||||
{
|
|
||||||
$model = app()->make($this->model());
|
|
||||||
|
|
||||||
if (!$model instanceof Model) {
|
|
||||||
throw new Exception(
|
|
||||||
"Class {$this->model()} must be an instance of Illuminate\\Database\\Eloquent\\Model"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return $model;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Repository\Economy;
|
|
||||||
|
|
||||||
use App\Models\Economy;
|
|
||||||
use App\Repository\Repository;
|
|
||||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
|
|
||||||
class EconomyRepository extends Repository
|
|
||||||
{
|
|
||||||
public function execute($params): LengthAwarePaginator
|
|
||||||
{
|
|
||||||
$filter = $this->getFilterBuilder($params);
|
|
||||||
|
|
||||||
foreach ($filter->getFilters() as $filters)
|
|
||||||
{
|
|
||||||
if (!$filters->getRow())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$filters->setField(DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'MM/YYYY')"));
|
|
||||||
}
|
|
||||||
|
|
||||||
$field = collect($filter->getFields())->merge($this->getRowField())->all();
|
|
||||||
|
|
||||||
$query = $this->model->newQuery()
|
|
||||||
->select($field)
|
|
||||||
->join(
|
|
||||||
"dados_cadastrais",
|
|
||||||
"dados_cadastrais.cod_smart_unidade",
|
|
||||||
"=",
|
|
||||||
"economia.cod_smart_unidade",
|
|
||||||
);
|
|
||||||
|
|
||||||
$res = $filter->applyFilter($query);
|
|
||||||
|
|
||||||
return $res->paginate();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getRowField(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
DB::raw("TO_CHAR(TO_DATE(economia.mes, 'YYMM'), 'MM/YYYY') as mes"),
|
|
||||||
DB::raw("TRIM(TO_CHAR(economia.custo_cativo, '99999999.99')) as custo_cativo"),
|
|
||||||
DB::raw("TRIM(TO_CHAR(economia.custo_livre, '99999999.99')) as custo_livre"),
|
|
||||||
DB::raw("COALESCE(economia.economia_mensal / NULLIF(economia.custo_livre, 0), 0) as custo")
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function model(): string
|
|
||||||
{
|
|
||||||
return Economy::class;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Repository\Med5min;
|
|
||||||
|
|
||||||
use App\Models\Med5min;
|
|
||||||
use App\Repository\Repository;
|
|
||||||
|
|
||||||
class Med5minRepository extends Repository
|
|
||||||
{
|
|
||||||
|
|
||||||
protected function getModel(): string
|
|
||||||
{
|
|
||||||
return Med5min::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function model()
|
|
||||||
{
|
|
||||||
// TODO: Implement model() method.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Repository\Pld;
|
|
||||||
|
|
||||||
use App\Models\Pld;
|
|
||||||
use App\Repository\Repository;
|
|
||||||
|
|
||||||
class PldRepository extends Repository
|
|
||||||
{
|
|
||||||
|
|
||||||
protected function getModel(): string
|
|
||||||
{
|
|
||||||
return Pld::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function model()
|
|
||||||
{
|
|
||||||
// TODO: Implement model() method.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,54 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Repository;
|
|
||||||
|
|
||||||
use App\Helper\Model\filter\FilterBuilder;
|
|
||||||
use App\Interface\RepositoryInterfaces;
|
|
||||||
use Illuminate\Contracts\Container\BindingResolutionException;
|
|
||||||
use Illuminate\Database\Eloquent\Collection;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
|
|
||||||
abstract class Repository extends AbstractRepository implements RepositoryInterfaces
|
|
||||||
{
|
|
||||||
|
|
||||||
public function list(): Collection
|
|
||||||
{
|
|
||||||
return $this->model->all();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function create(array $params)
|
|
||||||
{
|
|
||||||
return $this->model->create($params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function find(int $id)
|
|
||||||
{
|
|
||||||
// TODO: Implement find() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public function update(array $params, int $id)
|
|
||||||
{
|
|
||||||
return $this->model->find($id)->update( $params);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function delete(int $id)
|
|
||||||
{
|
|
||||||
// TODO: Implement delete() method.
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getFilterBuilder($json): ?FilterBuilder
|
|
||||||
{
|
|
||||||
return $this->getJsonObject($json, FilterBuilder::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static function logQuery($query, $type = 'get')
|
|
||||||
{
|
|
||||||
DB::enableQueryLog();
|
|
||||||
$query->$type();
|
|
||||||
dd(DB::getQueryLog());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -41,6 +41,10 @@ class FilterType
|
|||||||
return static::makeWhereFilter($builder, $filter);
|
return static::makeWhereFilter($builder, $filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (in_array($filter->getType(), self::IN_FILTER)) {
|
||||||
|
return static::makeInFilter($builder, $filter);
|
||||||
|
}
|
||||||
|
|
||||||
if (in_array($filter->getType(), self::BETWEEN_FILTER)) {
|
if (in_array($filter->getType(), self::BETWEEN_FILTER)) {
|
||||||
return static::makeBetweenFilter($builder, $filter);
|
return static::makeBetweenFilter($builder, $filter);
|
||||||
}
|
}
|
||||||
@ -55,13 +59,22 @@ class FilterType
|
|||||||
if ($fType === 'not_like') {
|
if ($fType === 'not_like') {
|
||||||
$fType = 'not like';
|
$fType = 'not like';
|
||||||
}
|
}
|
||||||
|
|
||||||
$field = ($filter->getRow()) ? DB::raw($filter->getField()) : $filter->getField();
|
$field = ($filter->getRow()) ? DB::raw($filter->getField()) : $filter->getField();
|
||||||
|
|
||||||
return $builder->where($field, $fType, $filter->getValue());
|
return $builder->where($field, $fType, $filter->getValue());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function makeInFilter(Builder $builder, FilterItem $filter) : Builder
|
||||||
|
{
|
||||||
|
if ($filter->getType() === "in") {
|
||||||
|
return $builder->whereIn($filter->getField(), $filter->getValue());
|
||||||
|
} elseif ($filter->getType() === "not_in") {
|
||||||
|
return $builder->whereNotIn($filter->getField(), $filter->getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
return $builder;
|
||||||
|
}
|
||||||
|
|
||||||
private static function makeBetweenFilter(Builder $builder, FilterItem $filter): Builder
|
private static function makeBetweenFilter(Builder $builder, FilterItem $filter): Builder
|
||||||
{
|
{
|
||||||
if ($filter->getType() === "between") {
|
if ($filter->getType() === "between") {
|
||||||
|
|||||||
@ -26,7 +26,10 @@
|
|||||||
"App\\": "app/",
|
"App\\": "app/",
|
||||||
"Database\\Factories\\": "database/factories/",
|
"Database\\Factories\\": "database/factories/",
|
||||||
"Database\\Seeders\\": "database/seeders/"
|
"Database\\Seeders\\": "database/seeders/"
|
||||||
}
|
},
|
||||||
|
"files": [
|
||||||
|
"app/Helpers/CustomHelpers.php"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"autoload-dev": {
|
"autoload-dev": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
|
|||||||
598
composer.lock
generated
598
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -19,24 +19,25 @@ Route::prefix('auth')->group(function (){
|
|||||||
Route::post('logout', [\App\Http\Controllers\Auth\AuthController::class, 'logout']);
|
Route::post('logout', [\App\Http\Controllers\Auth\AuthController::class, 'logout']);
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::middleware(['auth:sanctum', 'verified'])->group(function () {
|
Route::middleware(['auth:sanctum', 'ability:Admin'])->group(function () {
|
||||||
|
Route::apiResource('user', \App\Http\Controllers\UserController::class);
|
||||||
|
Route::apiResource('notification', \App\Http\Controllers\NotificationController::class);
|
||||||
|
Route::apiResource('faq', \App\Http\Controllers\FaqController::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
Route::middleware(['auth:sanctum', 'ability:Client'])->group(function () {
|
||||||
Route::post('pld/overview', [\App\Http\Controllers\PldController::class, 'overviewByRegion']);
|
Route::post('pld/overview', [\App\Http\Controllers\PldController::class, 'overviewByRegion']);
|
||||||
Route::post('pld/list', [\App\Http\Controllers\PldController::class, 'listConsumption']);
|
Route::post('pld/list', [\App\Http\Controllers\PldController::class, 'listConsumption']);
|
||||||
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/gross', [\App\Http\Controllers\EconomyController::class, 'grossEconomy']);
|
Route::post('economy', [\App\Http\Controllers\EconomyController::class, 'index']);
|
||||||
Route::post('economy/accumulated', [\App\Http\Controllers\EconomyController::class, 'accumulatedEconomy']);
|
Route::post('economy/grossAnnual', [\App\Http\Controllers\EconomyController::class, 'grossAnnualEconomy']);
|
||||||
Route::post('economy/estimates', [\App\Http\Controllers\EconomyController::class, 'costEstimatesEconomy']);
|
Route::post('economy/grossMonthly', [\App\Http\Controllers\EconomyController::class, 'grossMonthlyEconomy']);
|
||||||
|
Route::post('economy/estimates', [\App\Http\Controllers\EconomyController::class, 'captiveMonthlyEconomy']);
|
||||||
Route::post('economy/MWh', [\App\Http\Controllers\EconomyController::class, 'costMWhEconomy']);
|
Route::post('economy/MWh', [\App\Http\Controllers\EconomyController::class, 'costMWhEconomy']);
|
||||||
|
|
||||||
Route::post('operation', [\App\Http\Controllers\OperationController::class, 'operationSummary']);
|
Route::post('operation', [\App\Http\Controllers\OperationSummaryController::class, 'operationSummary']);
|
||||||
|
|
||||||
Route::apiResource('user', \App\Http\Controllers\UserController::class);
|
|
||||||
Route::apiResource('notification', \App\Http\Controllers\NotificationController::class);
|
|
||||||
Route::apiResource('faq', \App\Http\Controllers\FaqController::class);
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user