change some part of code
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Console\Commands;
|
||||
|
||||
use App\Enums\ActivityMachineType;
|
||||
use App\Models\Mission;
|
||||
use App\Models\DailyMoveMachine;
|
||||
use App\Models\AssignmentFails;
|
||||
use App\Services\CMMS\DailyMovingMachinesService;
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
@@ -31,7 +31,8 @@ class DailyMovingMachineCommand extends Command
|
||||
*/
|
||||
public function handle(DailyMovingMachinesService $dailyMovingMachines): void
|
||||
{
|
||||
$response = $dailyMovingMachines->run();
|
||||
$vehiclesInfo = $dailyMovingMachines->run();
|
||||
$response =$vehiclesInfo->get('vehiclesInfo', collect());
|
||||
|
||||
$date = now()->toDateString();
|
||||
|
||||
@@ -39,55 +40,38 @@ class DailyMovingMachineCommand extends Command
|
||||
->pluck('machineCode');
|
||||
|
||||
$mission = Mission::query()
|
||||
->whereDate('start_time',today())
|
||||
->whereDate('start_time',$date)
|
||||
->pluck('machine_code');
|
||||
|
||||
|
||||
$cmmsOnly = $cmms->diff($mission);
|
||||
$missionOnly = $mission->diff($cmms);
|
||||
$matching = $cmms->intersect($mission);
|
||||
|
||||
foreach ($matching as $code) {
|
||||
$cmm = (object) $response->firstWhere('machineCode', $code);
|
||||
$missionRecord = Mission::where('machine_code', $code)
|
||||
->whereDate('start_time', today())
|
||||
->first();
|
||||
|
||||
DailyMoveMachine::query()->create([
|
||||
'machine_code' => $code,
|
||||
'mission_id' => $missionRecord->id ,
|
||||
'type' => ActivityMachineType::MOTABEGAT->label(),
|
||||
'request_date' => $date,
|
||||
'mileage' => $cmm->mileage,
|
||||
'exit_time' => $cmm->exit_time,
|
||||
'enter_time' => $cmm->enter_time,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($cmmsOnly as $code) {
|
||||
$cmm = (object) $response->firstWhere('machineCode', $code);
|
||||
$cmm = $response->firstWhere('machineCode', $code);
|
||||
|
||||
DailyMoveMachine::query()->create([
|
||||
AssignmentFails::query()->create([
|
||||
'machine_code' => $code,
|
||||
'type' => ActivityMachineType::TEDADE_MACHINES_BISHTAR_AS_MISSION->label(),
|
||||
'type' => ActivityMachineType::KHOROJ_BEDONE_MOGAVEZ->label(),
|
||||
'request_date' => $date,
|
||||
'mileage' => $cmm->mileage,
|
||||
'exit_time' => $cmm->exit_time,
|
||||
'enter_time' => $cmm->enter_time,
|
||||
'mileage' => $cmm['mileageKM'],
|
||||
'exit_time' => $cmm['exit_time'],
|
||||
'enter_time' => $cmm['enter_time'],
|
||||
]);
|
||||
}
|
||||
|
||||
foreach ($missionOnly as $code) {
|
||||
DailyMoveMachine::create([
|
||||
$missionRecord = Mission::query()->where('machine_code', $code)
|
||||
->whereDate('start_time', today())
|
||||
->get();
|
||||
AssignmentFails::query()->create([
|
||||
'machine_code' => $code,
|
||||
'mission_id' => $mission->id,
|
||||
'type' => ActivityMachineType::TEDADE_MISSIONS_BISHTAR_AS_MACHINES->label(),
|
||||
'mission_id' => $missionRecord->id,
|
||||
'type' => ActivityMachineType::ADAM_TAHAROK->label(),
|
||||
'request_date' => $date,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$this->info('Diffs saved.');
|
||||
$this->info("ماشینهای متحرک بدون مأموریت: " . $cmmsOnly->count());
|
||||
$this->info("مأموریتهای بدون حرکت در CMMS: " . $missionOnly->count());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,17 +4,15 @@ namespace App\Enums;
|
||||
|
||||
enum ActivityMachineType: int
|
||||
{
|
||||
case MOTABEGAT = 1;
|
||||
case TEDADE_MACHINES_BISHTAR_AS_MISSION = 2;
|
||||
case TEDADE_MISSIONS_BISHTAR_AS_MACHINES = 3;
|
||||
case KHOROJ_BEDONE_MOGAVEZ = 1;
|
||||
case ADAM_TAHAROK = 2;
|
||||
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return match ($this) {
|
||||
self::MOTABEGAT => "مطابقت ",
|
||||
self::TEDADE_MACHINES_BISHTAR_AS_MISSION => " تعداد ماشین ها بیشتر از ماموریت ها",
|
||||
self::TEDADE_MISSIONS_BISHTAR_AS_MACHINES => "تغداد ماموریت ها بیشتر از ماشین ها ",
|
||||
self::KHOROJ_BEDONE_MOGAVEZ => "خروج بدون مجوز ",
|
||||
self::ADAM_TAHAROK => "عدم تحرک",
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class DailyMoveMachine extends Model
|
||||
class AssignmentFails extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $guarded =[];
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Services\CMMS;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -13,8 +14,6 @@ class DailyMovingMachinesService
|
||||
protected string $password;
|
||||
protected string $channelName;
|
||||
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->url = config('cmms_web_services.CHECK_ACTIVITY.url');
|
||||
@@ -26,12 +25,11 @@ class DailyMovingMachinesService
|
||||
/**
|
||||
* @throws Exception
|
||||
*/
|
||||
public function run(): array
|
||||
public function run(): Collection
|
||||
{
|
||||
try {
|
||||
return $this->sendRequest();
|
||||
}
|
||||
catch (Exception $e) {
|
||||
return collect( $this->sendRequest());
|
||||
} catch (Exception $e) {
|
||||
Log::channel($this->channelName)
|
||||
->error(get_class($this),
|
||||
[
|
||||
@@ -56,13 +54,11 @@ class DailyMovingMachinesService
|
||||
|
||||
private function makeInputParameters(): string
|
||||
{
|
||||
$inputData = array(
|
||||
"username" => $this->username,
|
||||
"password" => $this->password,
|
||||
"day" => today(),
|
||||
"minMileage" => 10,
|
||||
);
|
||||
|
||||
return json_encode($inputData);
|
||||
return json_encode([
|
||||
"username" => $this->username,
|
||||
"password" => $this->password,
|
||||
"day" => today(),
|
||||
"minMileage" => 10,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,20 +2,16 @@
|
||||
|
||||
namespace App\Services\Cartables\Mission;
|
||||
|
||||
use App\Exceptions\ProhibitedAction;
|
||||
use App\Facades\DataTable\DataTableFacade;
|
||||
use App\Models\DailyMoveMachine;
|
||||
use App\Models\Damage;
|
||||
use App\Models\SafetyAndPrivacy;
|
||||
use App\Models\AssignmentFails;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DailyMoveMachineService
|
||||
{
|
||||
public function dataTable(Request $request)
|
||||
{
|
||||
return DataTableFacade::run(
|
||||
DailyMoveMachine::query(),
|
||||
AssignmentFails::query(),
|
||||
$request,
|
||||
allowedFilters: ['*'],
|
||||
allowedSortings: ['*'],
|
||||
|
||||
Reference in New Issue
Block a user