create service and command for sending reports
This commit is contained in:
32
app/Console/Commands/SendCallStatsReportCommand.php
Normal file
32
app/Console/Commands/SendCallStatsReportCommand.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Services\Commands\SendCallStatsReportService;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class SendCallStatsReportCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'report:send-call-stats';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'gather all call stats report and send them to the center';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle(SendCallStatsReportService $service): void
|
||||||
|
{
|
||||||
|
$service->execute();
|
||||||
|
$this->info('Done!');
|
||||||
|
}
|
||||||
|
}
|
||||||
32
app/Console/Commands/SendPeopleMessageStatsCommand.php
Normal file
32
app/Console/Commands/SendPeopleMessageStatsCommand.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Services\Commands\SendPeopleMessageStatsService;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class SendPeopleMessageStatsCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'report:send-people-message-stats';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'gather all people message stats report and send them to the center';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle(SendPeopleMessageStatsService $service): void
|
||||||
|
{
|
||||||
|
$service->execute();
|
||||||
|
$this->info('Done!');
|
||||||
|
}
|
||||||
|
}
|
||||||
32
app/Console/Commands/SendSystemMessageStatsCommand.php
Normal file
32
app/Console/Commands/SendSystemMessageStatsCommand.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use App\Services\Commands\SendSystemMessageStatsService;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class SendSystemMessageStatsCommand extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'report:send-system-message-stats';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'gather all system message stats report and send them to the center';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle(SendSystemMessageStatsService $service): void
|
||||||
|
{
|
||||||
|
$service->execute();
|
||||||
|
$this->info('Done!');
|
||||||
|
}
|
||||||
|
}
|
||||||
91
app/Services/Commands/SendCallStatsReportService.php
Normal file
91
app/Services/Commands/SendCallStatsReportService.php
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Commands;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
|
use Illuminate\Http\Client\RequestException;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class SendCallStatsReportService
|
||||||
|
{
|
||||||
|
private string $url;
|
||||||
|
private string $channelName;
|
||||||
|
private string $provinceId;
|
||||||
|
private string $provinceName;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->url = config('ProvinceInfo.center_ip');
|
||||||
|
$this->channelName = 'send_call_stats_report';
|
||||||
|
$this->provinceId = config('ProvinceInfo.id');
|
||||||
|
$this->provinceName = config('ProvinceInfo.name');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ConnectionException
|
||||||
|
* @throws RequestException
|
||||||
|
*/
|
||||||
|
public function execute(): void
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$data = $this->prepare();
|
||||||
|
Http::post($this->url, $data)->throw();
|
||||||
|
Log::channel($this->channelName)->info(SendCallStatsReportService::class, [$this->provinceName, array_sum($data), 'successful']);
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
Log::channel($this->channelName)->error(SendCallStatsReportService::class, [$e->getMessage()]);
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function prepare(): array
|
||||||
|
{
|
||||||
|
$query = "SELECT
|
||||||
|
{$this->provinceId} AS province_id,
|
||||||
|
'{$this->provinceName}' AS province_name,
|
||||||
|
date,
|
||||||
|
total,
|
||||||
|
route_to_teh4,
|
||||||
|
route_to_teh5,
|
||||||
|
route_to_os4,
|
||||||
|
route_to_os5,
|
||||||
|
answered,
|
||||||
|
missed,
|
||||||
|
answered_over10,
|
||||||
|
dnd,
|
||||||
|
transferred,
|
||||||
|
talked_to_operator,
|
||||||
|
c_agency,
|
||||||
|
c_agency_driver,
|
||||||
|
average_calls_time,
|
||||||
|
(talked_to_operator - (answered + missed) + c_agency + c_agency_driver) AS fails
|
||||||
|
FROM (
|
||||||
|
SELECT
|
||||||
|
DATE(calldate) AS date,
|
||||||
|
COUNT(CASE WHEN recordingfile = '' OR recordingfile LIKE 'q-%' THEN 1 END) AS total,
|
||||||
|
COUNT(CASE WHEN lastdata = 'IAX2/serverpeer/100' THEN 1 END) AS route_to_teh4,
|
||||||
|
COUNT(CASE WHEN lastdata = 'IAX2/serverpeer/200' THEN 1 END) AS route_to_teh5,
|
||||||
|
COUNT(CASE WHEN dst = '500' THEN 1 END) AS route_to_os4,
|
||||||
|
COUNT(CASE WHEN dst = '600' THEN 1 END) AS route_to_os5,
|
||||||
|
COUNT(CASE WHEN dcontext = 'from-internal' AND disposition = 'ANSWERED' AND dst BETWEEN 101 AND 104 THEN 1 END) AS answered,
|
||||||
|
COUNT(CASE WHEN dcontext = 'from-internal' AND disposition = 'NO ANSWER' AND dst BETWEEN 101 AND 104 AND duration > 14 THEN 1 END) AS missed,
|
||||||
|
COUNT(CASE WHEN dcontext = 'from-internal' AND disposition = 'ANSWERED' AND dst BETWEEN 101 AND 104 AND billsec > 9 THEN 1 END) AS answered_over10,
|
||||||
|
COUNT(CASE WHEN lastapp = 'Busy' THEN 1 END) AS dnd,
|
||||||
|
COUNT(CASE WHEN dst BETWEEN 502 AND 599 THEN 1 END) AS transferred,
|
||||||
|
COUNT(CASE WHEN disposition <> 'BUSY' AND dst BETWEEN 101 AND 105 THEN 1 END) AS talked_to_operator,
|
||||||
|
COUNT(CASE WHEN lastdata LIKE '%custom/agency%' THEN 1 END) AS c_agency,
|
||||||
|
COUNT(CASE WHEN lastdata LIKE '%custom/agency-driver%' THEN 1 END) AS c_agency_driver,
|
||||||
|
AVG(CASE WHEN dcontext = 'from-internal' AND disposition = 'ANSWERED' THEN billsec END) AS average_calls_time
|
||||||
|
FROM asteriskcdrdb.cdr
|
||||||
|
WHERE calldate >= NOW() - INTERVAL 3 DAY
|
||||||
|
GROUP BY date
|
||||||
|
)
|
||||||
|
WHERE date >= DATE(NOW() - INTERVAL 3 DAY)";
|
||||||
|
|
||||||
|
return DB::select($query);
|
||||||
|
}
|
||||||
|
}
|
||||||
59
app/Services/Commands/SendKeypressStatsService.php
Normal file
59
app/Services/Commands/SendKeypressStatsService.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Commands;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
|
use Illuminate\Http\Client\RequestException;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class SendKeypressStatsService
|
||||||
|
{
|
||||||
|
private string $url;
|
||||||
|
private string $channelName;
|
||||||
|
private string $provinceId;
|
||||||
|
private string $provinceName;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->url = config('ProvinceInfo.center_ip');
|
||||||
|
$this->channelName = 'send_keypress_stats_report';
|
||||||
|
$this->provinceId = config('ProvinceInfo.id');
|
||||||
|
$this->provinceName = config('ProvinceInfo.name');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ConnectionException
|
||||||
|
* @throws RequestException
|
||||||
|
*/
|
||||||
|
public function execute(): void
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$data = $this->prepare();
|
||||||
|
Http::post($this->url, $data)->throw();
|
||||||
|
Log::channel($this->channelName)->info(SendKeypressStatsService::class, [$this->provinceName, array_sum($data), 'successful']);
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
Log::channel($this->channelName)->error(SendKeypressStatsService::class, [$e->getMessage()]);
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function prepare(): array
|
||||||
|
{
|
||||||
|
$query = "SELECT
|
||||||
|
{$this->provinceId} AS province_id,
|
||||||
|
'{$this->provinceName}' AS province_name,
|
||||||
|
date,
|
||||||
|
COUNT(CASE WHEN message_quality=1 THEN 1 END) AS message_quality_ok,
|
||||||
|
COUNT(CASE WHEN message_quality=0 THEN 1 END) AS message_quality_nok,
|
||||||
|
COUNT(CASE WHEN format_quality=1 THEN 1 END) AS message_format_ok,
|
||||||
|
COUNT(CASE WHEN format_quality=0 THEN 1 END) AS message_format_nok,
|
||||||
|
FROM system_messages GROUP BY date ORDER BY date DESC LIMIT 5";
|
||||||
|
|
||||||
|
return DB::select($query);
|
||||||
|
}
|
||||||
|
}
|
||||||
64
app/Services/Commands/SendPeopleMessageStatsService.php
Normal file
64
app/Services/Commands/SendPeopleMessageStatsService.php
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Commands;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
|
use Illuminate\Http\Client\RequestException;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class SendPeopleMessageStatsService
|
||||||
|
{
|
||||||
|
private string $url;
|
||||||
|
private string $channelName;
|
||||||
|
private string $provinceId;
|
||||||
|
private string $provinceName;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->url = config('ProvinceInfo.center_ip');
|
||||||
|
$this->channelName = 'send_people_message_stats_report';
|
||||||
|
$this->provinceId = config('ProvinceInfo.id');
|
||||||
|
$this->provinceName = config('ProvinceInfo.name');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ConnectionException
|
||||||
|
* @throws RequestException
|
||||||
|
*/
|
||||||
|
public function execute(): void
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$data = $this->prepare();
|
||||||
|
Http::post($this->url, $data)->throw();
|
||||||
|
Log::channel($this->channelName)->info(SendPeopleMessageStatsService::class, [$this->provinceName, array_sum($data), 'successful']);
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
Log::channel($this->channelName)->error(SendPeopleMessageStatsService::class, [$e->getMessage()]);
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function prepare(): array
|
||||||
|
{
|
||||||
|
$query = "SELECT
|
||||||
|
{$this->provinceId} AS province_id,
|
||||||
|
'{$this->provinceName}' AS province_name,
|
||||||
|
date,
|
||||||
|
COUNT(CASE WHEN action_id=1 THEN 1 END) AS action1,
|
||||||
|
COUNT(CASE WHEN action_id=2 THEN 1 END) AS action2,
|
||||||
|
COUNT(CASE WHEN action_id=3 THEN 1 END) AS action3,
|
||||||
|
COUNT(CASE WHEN action_id=4 THEN 1 END) AS action4,
|
||||||
|
COUNT(CASE WHEN action_id=5 THEN 1 END) AS action5,
|
||||||
|
COUNT(CASE WHEN is_listen=1 THEN 1 END) AS listens,
|
||||||
|
COUNT(CASE WHEN is_listen=0 THEN 1 END) AS not_listens,
|
||||||
|
COUNT(*) AS total,
|
||||||
|
AVG(review_duration) as review_average
|
||||||
|
FROM system_messages GROUP BY date ORDER BY date DESC LIMIT 3";
|
||||||
|
|
||||||
|
return DB::select($query);
|
||||||
|
}
|
||||||
|
}
|
||||||
59
app/Services/Commands/SendSystemMessageStatsService.php
Normal file
59
app/Services/Commands/SendSystemMessageStatsService.php
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Commands;
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
use Illuminate\Http\Client\ConnectionException;
|
||||||
|
use Illuminate\Http\Client\RequestException;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class SendSystemMessageStatsService
|
||||||
|
{
|
||||||
|
private string $url;
|
||||||
|
private string $channelName;
|
||||||
|
private string $provinceId;
|
||||||
|
private string $provinceName;
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->url = config('ProvinceInfo.center_ip');
|
||||||
|
$this->channelName = 'send_system_message_stats_report';
|
||||||
|
$this->provinceId = config('ProvinceInfo.id');
|
||||||
|
$this->provinceName = config('ProvinceInfo.name');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ConnectionException
|
||||||
|
* @throws RequestException
|
||||||
|
*/
|
||||||
|
public function execute(): void
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
$data = $this->prepare();
|
||||||
|
Http::post($this->url, $data)->throw();
|
||||||
|
Log::channel($this->channelName)->info(SendSystemMessageStatsService::class, [$this->provinceName, array_sum($data), 'successful']);
|
||||||
|
}
|
||||||
|
catch (Exception $e)
|
||||||
|
{
|
||||||
|
Log::channel($this->channelName)->error(SendSystemMessageStatsService::class, [$e->getMessage()]);
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function prepare(): array
|
||||||
|
{
|
||||||
|
$query = "SELECT
|
||||||
|
{$this->provinceId} AS province_id,
|
||||||
|
'{$this->provinceName}' AS province_name,
|
||||||
|
date,
|
||||||
|
COUNT(CASE WHEN message_quality=1 THEN 1 END) AS message_quality_ok,
|
||||||
|
COUNT(CASE WHEN message_quality=0 THEN 1 END) AS message_quality_nok,
|
||||||
|
COUNT(CASE WHEN format_quality=1 THEN 1 END) AS message_format_ok,
|
||||||
|
COUNT(CASE WHEN format_quality=0 THEN 1 END) AS message_format_nok,
|
||||||
|
FROM system_messages GROUP BY date ORDER BY date DESC LIMIT 5";
|
||||||
|
|
||||||
|
return DB::select($query);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
config/ProvinceInfo.php
Normal file
8
config/ProvinceInfo.php
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'ip' => env('PROVINCE_INFO_IP'),
|
||||||
|
'name' => env('PROVINCE_INFO_NAME'),
|
||||||
|
'id' => env('PROVINCE_INFO_ID'),
|
||||||
|
'center_ip' => env('PROVINCE_INFO_CENTER_IP'),
|
||||||
|
];
|
||||||
@@ -127,6 +127,29 @@ return [
|
|||||||
'path' => storage_path('logs/laravel.log'),
|
'path' => storage_path('logs/laravel.log'),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
'send_call_stats_report' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/send_call_stats_report.log'),
|
||||||
|
'level' => 'debug',
|
||||||
|
],
|
||||||
|
|
||||||
|
'send_keypress_stats_report' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/send_keypress_stats_report.log'),
|
||||||
|
'level' => 'debug',
|
||||||
|
],
|
||||||
|
|
||||||
|
'send_people_message_stats_report' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/send_people_message_stats_report.log'),
|
||||||
|
'level' => 'debug',
|
||||||
|
],
|
||||||
|
|
||||||
|
'send_system_message_stats_report' => [
|
||||||
|
'driver' => 'single',
|
||||||
|
'path' => storage_path('logs/send_system_message_stats_report.log'),
|
||||||
|
'level' => 'debug',
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user