improve cutlergyor move
This commit is contained in:
parent
0591f3780c
commit
0d7002b173
@ -29,7 +29,7 @@ use yii\web\ServerErrorHttpException;
|
|||||||
* Date: 2018.12.17.
|
* Date: 2018.12.17.
|
||||||
* Time: 6:12
|
* Time: 6:12
|
||||||
*/
|
*/
|
||||||
class DoorCardPassDoorManager extends BaseObject
|
class CutlerMovarDoorManager extends BaseObject
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -139,7 +139,9 @@ class DoorCardPassDoorManager extends BaseObject
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
\Yii::info("$requestId: card loaded in sec " . $stopWatch->split());
|
\Yii::info("$requestId: card loaded in sec " . $stopWatch->split());
|
||||||
$virtualKey = VirtualKey::findOne(['id_card' => $card->id_card]);
|
$virtualKey = VirtualKey::find()
|
||||||
|
->andWhere(['id_card' => $card->id_card])
|
||||||
|
->orderBy(['id' => SORT_DESC])->one();
|
||||||
\Yii::info("$requestId: virtual key for card loaded in sec " . $stopWatch->split());
|
\Yii::info("$requestId: virtual key for card loaded in sec " . $stopWatch->split());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -454,87 +456,18 @@ class DoorCardPassDoorManager extends BaseObject
|
|||||||
|
|
||||||
// detect if need to increase usage count for ticket
|
// detect if need to increase usage count for ticket
|
||||||
if (!$ctx->verifyOnly) {
|
if (!$ctx->verifyOnly) {
|
||||||
|
|
||||||
$ctx->virtualKey->direction_in_at = Helper::getDateTimeString();
|
$ctx->virtualKey->direction_in_at = Helper::getDateTimeString();
|
||||||
\Yii::info("$ctx->requestId: Setting virtual key direction_in_at");
|
\Yii::info("$ctx->requestId: Setting virtual key direction_in_at");
|
||||||
\Yii::info("$ctx->requestId: Updating virtual key");
|
\Yii::info("$ctx->requestId: Updating virtual key");
|
||||||
$ctx->virtualKey->save(false);
|
$ctx->virtualKey->save(false);
|
||||||
|
|
||||||
$allDoorLogToday = DoorManagerLog::findAllEntryForTicketFromTime($ctx->ticket->id_ticket);
|
|
||||||
$countDoorLogsForTicketSince = count($allDoorLogToday);
|
|
||||||
|
|
||||||
// if the current event is the first door log today
|
// if the current event is the first door log today
|
||||||
if ($countDoorLogsForTicketSince == 0) {
|
// increase the ticket usage count with 1
|
||||||
// increase the ticket usage count with 1
|
$usageCount = $ticket->usage_count;
|
||||||
$usageCount = $ticket->usage_count;
|
$ctx->increasedTicketUsageCount = true;
|
||||||
$ctx->increasedTicketUsageCount = true;
|
$ticket->usage_count += 1;
|
||||||
$ticket->usage_count += 1;
|
$ticket->save(false);
|
||||||
$ticket->save(false);
|
\Yii::info("$ctx->requestId: First ticket usage today, increasing usage count for card: " . $ctx->card->id_card);
|
||||||
\Yii::info("$ctx->requestId: First ticket usage today, increasing usage count for card: " . $ctx->card->id_card);
|
\Yii::info("$ctx->requestId: Ticket usage count increased after first doorlog of day in sec " . $stopWatch->split());
|
||||||
Log::log(
|
|
||||||
[
|
|
||||||
'type' => Log::$TYPE_TICKET_USAGE_FIRST,
|
|
||||||
'message' => 'Bérlet használat(előtte: ' . $usageCount . ' -> utána: ' . $ticket->usage_count,
|
|
||||||
'id_ticket' => $ticket->id_ticket,
|
|
||||||
'id_door_log' => $doorLog->id_door_log
|
|
||||||
]
|
|
||||||
);
|
|
||||||
\Yii::info("$ctx->requestId: Ticket usage count increased after first doorlog of day in sec " . $stopWatch->split());
|
|
||||||
$ctx->actions[] = "TICKET_FIRST_USAGE_TODAY";
|
|
||||||
|
|
||||||
} else {
|
|
||||||
\Yii::info("$ctx->requestId: more then one door log today for card: " . $ctx->card->id_card);
|
|
||||||
// we have already a door log for today, other than this
|
|
||||||
// Now we split the day into 3hour intervalls, starting with the createdAt value of the first event.
|
|
||||||
// If the actual event happens in an interval, in which still now doorlog event happend, we increase
|
|
||||||
// the usage count with 1
|
|
||||||
// 3 óránként 1-et levonunk
|
|
||||||
|
|
||||||
|
|
||||||
if (count($allDoorLogToday) == 0) {
|
|
||||||
throw new FitnessException(
|
|
||||||
"$ctx->requestId: Tried to inc ticket usage without prev entry: " . $ctx->identifier . '/' . $ctx->virtualKey->id_card,
|
|
||||||
FitnessException::TYPE_BAD_REQUEST,
|
|
||||||
"INVALID_TICKET_USAGE_INCREMENT",
|
|
||||||
$ctx
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$firstInToday = $allDoorLogToday[0];
|
|
||||||
\Yii::info("$ctx->requestId: first in today for card: " . $ctx->card->id_card . " was at " . $firstInToday->created_at);
|
|
||||||
$firstEntryDateTimeToday = DateUtil::parseDateTime($firstInToday->created_at);
|
|
||||||
$interval = \DateInterval::createFromDateString('3 hours');
|
|
||||||
$startOfTomorrow = DateUtil::tomorrowStart(clone $ctx->date);
|
|
||||||
$daterange = new \DatePeriod($firstEntryDateTimeToday, $interval, $startOfTomorrow);
|
|
||||||
|
|
||||||
$intervals = [];
|
|
||||||
$intervalStart = null;
|
|
||||||
foreach ($daterange as $intervalEnd) {
|
|
||||||
if (isset($intervalStart)) {
|
|
||||||
$intervals[] = $this->createTicketUsageInterval($intervalStart, $intervalEnd, $allDoorLogToday, $doorLog);
|
|
||||||
}
|
|
||||||
$intervalStart = clone $intervalEnd;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($intervalStart < $startOfTomorrow) {
|
|
||||||
$intervals[] = $this->createTicketUsageInterval($intervalStart, $startOfTomorrow, $allDoorLogToday, $doorLog);
|
|
||||||
}
|
|
||||||
|
|
||||||
$activeInterval = $this->getActiveInterval($intervals, $ctx->createdAt);
|
|
||||||
if (!isset($activeInterval)) {
|
|
||||||
throw new ServerErrorHttpException("$ctx->requestId: Active Interval not found");
|
|
||||||
}
|
|
||||||
|
|
||||||
$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());
|
|
||||||
$ctx->actions[] = "TICKET_INCREASE_USAGE";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$ctx->actions[] = "MOVE_IN";
|
$ctx->actions[] = "MOVE_IN";
|
||||||
}
|
}
|
||||||
@ -511,7 +511,7 @@ class KeyDoorManager extends BaseObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
// virtual_key: only one move out is allowed
|
// virtual_key: only one move out is allowed
|
||||||
if (!isset($ctx->virtualKey->direction_out_at)) {
|
if (isset($ctx->virtualKey->direction_out_at)) {
|
||||||
throw new FitnessException(
|
throw new FitnessException(
|
||||||
"$ctx->requestId: virtual key already out. Only one move out allowed.",
|
"$ctx->requestId: virtual key already out. Only one move out allowed.",
|
||||||
FitnessException::TYPE_BAD_REQUEST,
|
FitnessException::TYPE_BAD_REQUEST,
|
||||||
@ -559,6 +559,7 @@ class KeyDoorManager extends BaseObject
|
|||||||
(\Exception $e) {
|
(\Exception $e) {
|
||||||
$this->doRollback();
|
$this->doRollback();
|
||||||
Yii::info("$ctx->requestId: rollbacked");
|
Yii::info("$ctx->requestId: rollbacked");
|
||||||
|
Yii::error($e->getMessage());
|
||||||
throw new FitnessException(
|
throw new FitnessException(
|
||||||
"UNKNOWN_ERROR",
|
"UNKNOWN_ERROR",
|
||||||
FitnessException::UNKNOWN_ERROR,
|
FitnessException::UNKNOWN_ERROR,
|
||||||
|
|||||||
@ -74,7 +74,7 @@ class DoorManagerLog extends \yii\db\ActiveRecord
|
|||||||
|
|
||||||
static function findAllEntryForTicketFromTime($idTicket, $datetime = null){
|
static function findAllEntryForTicketFromTime($idTicket, $datetime = null){
|
||||||
return DoorManagerLog::find()
|
return DoorManagerLog::find()
|
||||||
->andWhere(['id_ticket' =>$idTicket])
|
->andWhere(['ticket_id_ticket' =>$idTicket])
|
||||||
->andWhere(['verify_only' => false])
|
->andWhere(['verify_only' => false])
|
||||||
->andWhere(['direction' => 'IN'])
|
->andWhere(['direction' => 'IN'])
|
||||||
->andWhere(['>=' ,'created_at', isset( $datetime ) ? $datetime : date('Y-m-d H:i:s')])
|
->andWhere(['>=' ,'created_at', isset( $datetime ) ? $datetime : date('Y-m-d H:i:s')])
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
FITNESS_REST_ALLOW_VERIFY_ONLY=true
|
FITNESS_REST_ALLOW_VERIFY_ONLY=true
|
||||||
DOOR_ENTRY_STRATEGY=door_pass
|
#DOOR_ENTRY_STRATEGY=door_pass
|
||||||
FITNESS_WORD_TYPED_LISTENER_ALLOWED_ONLY_FOR_EMPTY_CUSTOMER=0
|
FITNESS_WORD_TYPED_LISTENER_ALLOWED_ONLY_FOR_EMPTY_CUSTOMER=0
|
||||||
@ -30,7 +30,7 @@ Content-Type: application/json
|
|||||||
Authorization: Basic ZG9vcl9zeXN0ZW06ZG9vcnN5c3RlbTE=
|
Authorization: Basic ZG9vcl9zeXN0ZW06ZG9vcnN5c3RlbTE=
|
||||||
|
|
||||||
{
|
{
|
||||||
"cardNumber": "63f3e0cd399f55.53162649",
|
"cardNumber": "645d141791b4c0.80321051",
|
||||||
"direction": "IN",
|
"direction": "IN",
|
||||||
"device": "Q",
|
"device": "Q",
|
||||||
"validateOnly": false
|
"validateOnly": false
|
||||||
@ -44,7 +44,7 @@ Content-Type: application/json
|
|||||||
Authorization: Basic ZG9vcl9zeXN0ZW06ZG9vcnN5c3RlbTE=
|
Authorization: Basic ZG9vcl9zeXN0ZW06ZG9vcnN5c3RlbTE=
|
||||||
|
|
||||||
{
|
{
|
||||||
"cardNumber": "63f3e0cd399f55.53162649",
|
"cardNumber": "645d141791b4c0.80321051",
|
||||||
"direction": "OUT",
|
"direction": "OUT",
|
||||||
"device": "Q",
|
"device": "Q",
|
||||||
"validateOnly": false
|
"validateOnly": false
|
||||||
@ -58,7 +58,7 @@ Content-Type: application/json
|
|||||||
Authorization: Basic ZG9vcl9zeXN0ZW06ZG9vcnN5c3RlbTE=
|
Authorization: Basic ZG9vcl9zeXN0ZW06ZG9vcnN5c3RlbTE=
|
||||||
|
|
||||||
{
|
{
|
||||||
"cardNumber": "123456",
|
"cardNumber": "10WMVXMZ",
|
||||||
"direction": "IN",
|
"direction": "IN",
|
||||||
"device": "C",
|
"device": "C",
|
||||||
"validateOnly": false
|
"validateOnly": false
|
||||||
@ -72,7 +72,7 @@ Content-Type: application/json
|
|||||||
Authorization: Basic ZG9vcl9zeXN0ZW06ZG9vcnN5c3RlbTE=
|
Authorization: Basic ZG9vcl9zeXN0ZW06ZG9vcnN5c3RlbTE=
|
||||||
|
|
||||||
{
|
{
|
||||||
"cardNumber": "123456",
|
"cardNumber": "10WMVXMZ",
|
||||||
"direction": "OUT",
|
"direction": "OUT",
|
||||||
"device": "C",
|
"device": "C",
|
||||||
"validateOnly": false
|
"validateOnly": false
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace rest\controllers;
|
namespace rest\controllers;
|
||||||
|
|
||||||
use common\manager\DoorCardPassDoorManager;
|
use common\manager\CutlerMovarDoorManager;
|
||||||
use common\manager\KeyDoorManager;
|
use common\manager\KeyDoorManager;
|
||||||
use rest\models\DoorMoveForm;
|
use rest\models\DoorMoveForm;
|
||||||
use Yii;
|
use Yii;
|
||||||
@ -25,7 +25,7 @@ class DoorController extends RestController
|
|||||||
return $formModel;
|
return $formModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function actionMoveMovar()
|
public function actionMoveCutlerMovar()
|
||||||
{
|
{
|
||||||
$formModel = new DoorMoveForm();
|
$formModel = new DoorMoveForm();
|
||||||
if ($formModel->load(Yii::$app->request->post(),"") ) {
|
if ($formModel->load(Yii::$app->request->post(),"") ) {
|
||||||
@ -33,7 +33,7 @@ class DoorController extends RestController
|
|||||||
$keys = array_keys($formModel->getFirstErrors());
|
$keys = array_keys($formModel->getFirstErrors());
|
||||||
throw new BadRequestHttpException("Invalid move request:". $formModel->getFirstErrors()[$keys[0]]);
|
throw new BadRequestHttpException("Invalid move request:". $formModel->getFirstErrors()[$keys[0]]);
|
||||||
}
|
}
|
||||||
$doorManager = new DoorCardPassDoorManager();
|
$doorManager = new CutlerMovarDoorManager();
|
||||||
$doorManager->move($formModel->cardNumber,$formModel->device,$formModel->direction, $formModel->validateOnly, $formModel->createdAt, $formModel->date);
|
$doorManager->move($formModel->cardNumber,$formModel->device,$formModel->direction, $formModel->validateOnly, $formModel->createdAt, $formModel->date);
|
||||||
}
|
}
|
||||||
return $formModel;
|
return $formModel;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user