add door manager logs
This commit is contained in:
parent
b40d0ccf05
commit
7c610b50ab
@ -21,6 +21,7 @@ public $virtualKey;
|
||||
public $key;
|
||||
public $customer;
|
||||
public $ticket;
|
||||
public $increasedTicketUsageCount;
|
||||
|
||||
|
||||
public $kind;
|
||||
|
||||
@ -11,6 +11,7 @@ use common\models\Card;
|
||||
use common\models\CardKeyAssignment;
|
||||
use common\models\DoorLog;
|
||||
use common\models\DoorLogForTest;
|
||||
use common\models\DoorManagerLog;
|
||||
use common\models\Key;
|
||||
use common\models\Log;
|
||||
use common\models\Ticket;
|
||||
@ -138,6 +139,10 @@ class DoorManager extends BaseObject
|
||||
|
||||
$context->virtualKey = $virtualKey;
|
||||
$context->card = $card;
|
||||
$keyAssignment = CardKeyAssignment::findOne(['id_card' =>$card->id_card]);
|
||||
if ( isset($keyAssignment)){
|
||||
$context->key = Key::findOne($keyAssignment->id_key);
|
||||
}
|
||||
$context->cardNumber = $cardNumber;
|
||||
|
||||
\Yii::info("$requestId: Card number " . $card->number);
|
||||
@ -181,36 +186,67 @@ class DoorManager extends BaseObject
|
||||
function logContext($ctx){
|
||||
try{
|
||||
$result = [
|
||||
'requestId' => $ctx->requestId,
|
||||
//datetime $updated_at --
|
||||
//datetime $created_at --
|
||||
//string $ticket_usage
|
||||
//string $request_id
|
||||
'request_id' => $ctx->requestId,
|
||||
//string $identifier
|
||||
'identifier' => $ctx->identifier,
|
||||
'verifyOnly' => $ctx->verifyOnly,
|
||||
//bool $verify_only
|
||||
'verify_only' => $ctx->verifyOnly,
|
||||
//string $device
|
||||
'device' => $ctx->device,
|
||||
//string $direction
|
||||
'direction' => $ctx->direction,
|
||||
'originalDirection' => $ctx->originalDirection,
|
||||
'idCard' => isset($ctx->card)? $ctx->card->id_card : null,
|
||||
'cardNumber' => isset($ctx->card) ? $ctx->card->number : null,
|
||||
'idTicket' => isset($ctx->ticket) ? $ctx->ticket->id_ticket : null,
|
||||
'ticketType' => isset($ctx->ticket) ? $ctx->ticket->ticketType->name : null,
|
||||
'ticketUsageCount' => isset($ctx->ticket) ? $ctx->ticket->usage_count : null,
|
||||
'idCustomer' => isset($ctx->customer) ? $ctx->customer->id_customer : null,
|
||||
'customerName' => isset($ctx->customer) ? $ctx->customer->name : null,
|
||||
'customerEmail' => isset($ctx->customer) ? $ctx->customer->email : null,
|
||||
'key' => isset($ctx->key) ? $ctx->key->name : null,
|
||||
'idVirtualKey' => isset($ctx->virtualKey) ? $ctx->virtualKey->id : null,
|
||||
'kind' => $ctx->kind,
|
||||
'actions' => implode(",",$ctx->actions),
|
||||
//string $original_direction
|
||||
'original_direction' => $ctx->originalDirection,
|
||||
//integer $card_id_card
|
||||
'card_id_card' => isset($ctx->card)? $ctx->card->id_card : null,
|
||||
//string $card_number
|
||||
'card_number' => isset($ctx->card) ? $ctx->card->number : null,
|
||||
//string $ticket_id_ticket
|
||||
'ticket_id_ticket' => isset($ctx->ticket) ? $ctx->ticket->id_ticket : null,
|
||||
//string $ticket_type_name
|
||||
'ticket_type_name' => isset($ctx->ticket) ? $ctx->ticket->ticketType->name : null,
|
||||
//string $ticket_usage_count
|
||||
'ticket_usage_count' => isset($ctx->ticket) ? $ctx->ticket->usage_count : null,
|
||||
//string $customer_id_customer
|
||||
'customer_id_customer' => isset($ctx->customer) ? $ctx->customer->id_customer : null,
|
||||
//string $customer_name
|
||||
'customer_name' => isset($ctx->customer) ? $ctx->customer->name : null,
|
||||
//string $customer_email
|
||||
'customer_email' => isset($ctx->customer) ? $ctx->customer->email : null,
|
||||
//integer $key_id_key
|
||||
'key_id_key' => isset($ctx->key) ? $ctx->key->id_key : null,
|
||||
//string $key_number
|
||||
'key_number' => isset($ctx->key) ? $ctx->key->number : null,
|
||||
//integer $virtual_key_id
|
||||
'virtual_key_id' => isset($ctx->virtualKey) ? $ctx->virtualKey->id : null,
|
||||
//string $validation_kind
|
||||
'validation_kind' => $ctx->kind,
|
||||
//bool $error
|
||||
'error' => $ctx->error,
|
||||
'errorCode' => $ctx->errorCode,
|
||||
'ticketUsage' => 1,
|
||||
//string $error_code
|
||||
'error_code' => $ctx->errorCode,
|
||||
'ticket_usage' => $ctx->increasedTicketUsageCount,
|
||||
// 'actions' => implode(",",$ctx->actions),
|
||||
];
|
||||
|
||||
if ( $ctx->error === true ){
|
||||
if ( isset($ctx->exception )){
|
||||
$result['errorMessage'] = substr( $ctx->exception->getMessage(),0,100);
|
||||
// string $error_message
|
||||
$result['error_message'] = substr( $ctx->exception->getMessage(),0,100);
|
||||
}
|
||||
}
|
||||
|
||||
\Yii::info("door log: " . implode(";", $result));
|
||||
\Yii::info("door log: " . implode(";", $result));
|
||||
|
||||
\Yii::$app->db->beginTransaction();
|
||||
$log = new DoorManagerLog($result);
|
||||
$log->save(false);
|
||||
\Yii::$app->db->transaction->commit();
|
||||
|
||||
|
||||
}catch (\Exception $e){
|
||||
\Yii::error("Failed to log door context:". $e->getMessage());
|
||||
@ -444,6 +480,7 @@ class DoorManager extends BaseObject
|
||||
if ($countDoorLogsForTicketSince == 1) {
|
||||
// increase the ticket usage count with 1
|
||||
$usageCount = $ticket->usage_count;
|
||||
$ctx->increasedTicketUsageCount = true;
|
||||
$ticket->usage_count += 1;
|
||||
$ticket->save(false);
|
||||
\Yii::info("$ctx->requestId: First ticket usage today, increasing usage count for card: " . $ctx->card->id_card);
|
||||
@ -515,6 +552,7 @@ class DoorManager extends BaseObject
|
||||
$logCountInActiveInterval = count($activeInterval['logs']);
|
||||
|
||||
if ($logCountInActiveInterval == 1) {
|
||||
$ctx->increasedTicketUsageCount = true;
|
||||
$ticket->usage_count = $ticket->usage_count + 1;
|
||||
$ticket->save(false);
|
||||
\Yii::info("$ctx->requestId: Ticket usage count increased after first IN after first door_log in interval in sec " . $stopWatch->split());
|
||||
@ -558,6 +596,8 @@ class DoorManager extends BaseObject
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (isset($ctx->virtualKey)) {
|
||||
\Yii::info("Move OUT: Virtual key set");
|
||||
if (!isset($ctx->virtualKey->direction_in_at)) {
|
||||
|
||||
67
common/models/DoorManagerLog.php
Normal file
67
common/models/DoorManagerLog.php
Normal file
@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use common\components\Helper;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
/**
|
||||
* This is the model class for table "door_manager_log".
|
||||
*
|
||||
* @property string $request_id
|
||||
* @property string $identifier
|
||||
* @property string $device
|
||||
* @property string $direction
|
||||
* @property string $original_direction
|
||||
* @property bool $verify_only
|
||||
* @property datetime $created_at
|
||||
* @property integer $card_id_card
|
||||
* @property string $card_number
|
||||
* @property integer $virtual_key_id
|
||||
* @property integer $key_id_key
|
||||
* @property string $key_number
|
||||
* @property string $customer_id_customer
|
||||
* @property string $customer_name
|
||||
* @property string $customer_email
|
||||
* @property string $ticket_id_ticket
|
||||
* @property string $ticket_usage_count
|
||||
* @property string $ticket_usage
|
||||
* @property string $ticket_type_name
|
||||
* @property string $validation_kind
|
||||
* @property bool $error
|
||||
* @property string $error_code
|
||||
* @property string $error_message
|
||||
*
|
||||
*/
|
||||
class DoorManagerLog extends \yii\db\ActiveRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'door_manager_log';
|
||||
}
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return ArrayHelper::merge([
|
||||
[
|
||||
'class' => TimestampBehavior::className(),
|
||||
'value' => function ($event) {
|
||||
if ( isset($event->sender->created_at) ){
|
||||
return $event->sender->created_at;
|
||||
}
|
||||
return date('Y-m-d H:i:s');
|
||||
},
|
||||
'updatedAtAttribute' => false,
|
||||
]
|
||||
], parent::behaviors());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
/**
|
||||
* Class m230126_202055_create_table_door_card_pass
|
||||
*/
|
||||
class m230209_200020_create_table_door_manager_log extends Migration
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* string $request_id
|
||||
* string $identifier
|
||||
* string $device
|
||||
* string $direction
|
||||
* string $original_direction
|
||||
* bool $verify_only
|
||||
* datetime $created_at
|
||||
* integer $card_id_card
|
||||
* string $card_number
|
||||
* integer $virtual_key_id
|
||||
* integer $key_id_key
|
||||
* string $key_number
|
||||
* string $customer_id_customer
|
||||
* string $customer_name
|
||||
* string $customer_email
|
||||
* string $ticket_id_ticket
|
||||
* string $ticket_usage_count
|
||||
* string $ticket_usage
|
||||
* string $ticket_type_name
|
||||
* string $validation_kind
|
||||
* bool $error
|
||||
* string $error_code
|
||||
* string $error_message
|
||||
*/
|
||||
public function safeUp()
|
||||
{
|
||||
$tableOptions = null;
|
||||
if ($this->db->driverName === 'mysql') {
|
||||
// http://stackoverflow.com/questions/766809/whats-the-difference-between-utf8-general-ci-and-utf8-unicode-ci
|
||||
$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
|
||||
}
|
||||
|
||||
$this->createTable('door_manager_log', [
|
||||
'id_door_manager_log' => $this->primaryKey(),
|
||||
'created_at' => $this->datetime(),
|
||||
'updated_at' => $this->dateTime()->notNull(),
|
||||
'request_id' => $this->string(50),
|
||||
'identifier' => $this->string(100),
|
||||
'device' => $this->string(10),
|
||||
'direction' => $this->string(10),
|
||||
'original_direction' => $this->string(10),
|
||||
'verify_only' => $this->boolean(),
|
||||
'card_id_card' => $this->integer(),
|
||||
'card_number' => $this->string(50),
|
||||
'virtual_key_id' => $this->integer(),
|
||||
'key_id_key' => $this->integer(),
|
||||
'key_number' => $this->string(),
|
||||
'customer_id_customer' => $this->integer(),
|
||||
'customer_name' => $this->string(),
|
||||
'customer_email' => $this->string(),
|
||||
'ticket_id_ticket' => $this->string(),
|
||||
'ticket_usage_count' => $this->string(),
|
||||
'ticket_usage' => $this->integer(),
|
||||
'ticket_type_name' => $this->string(),
|
||||
'validation_kind' => $this->string(50),
|
||||
'error' => $this->boolean()->defaultValue(false),
|
||||
'error_code' => $this->string(50),
|
||||
'error_message' => $this->string(),
|
||||
],
|
||||
$tableOptions
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function safeDown()
|
||||
{
|
||||
echo "m230126_202055_create_table_door_card_pass cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
// Use up()/down() to run migration code without a transaction.
|
||||
public function up()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m230126_202055_create_table_door_card_pass cannot be reverted.\n";
|
||||
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
}
|
||||
@ -61,7 +61,7 @@ Authorization: Basic ZG9vcl9zeXN0ZW06ZG9vcnN5c3RlbTE=
|
||||
"cardNumber": "123456",
|
||||
"direction": "IN",
|
||||
"device": "C",
|
||||
"validateOnly": false
|
||||
"validateOnly": true
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
Loading…
Reference in New Issue
Block a user