merge app api

This commit is contained in:
Schneider Roland
2023-01-19 17:43:10 +01:00
570 changed files with 81491 additions and 1263 deletions

View File

@@ -0,0 +1,68 @@
<?php
use yii\db\Migration;
/**
* Class m220213_134539_add_table_mobile_device
*/
class m220213_134539_add_table_mobile_device extends Migration
{
/**
* {@inheritdoc}
*/
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('{{%mobile_device}}', [
'id' => $this->primaryKey(),
'id_card' => $this->integer(11),
'status' => $this->string(20),
'device_identifier' => $this->string(255),
'activated_at' => $this->dateTime(),
'created_at' => $this->dateTime()->notNull(),
'updated_at' => $this->dateTime()->notNull(),
], $tableOptions);
$this->createTable('{{%virtual_key}}', [
'id' => $this->primaryKey(),
'id_card' => $this->integer(11),
'id_key' => $this->integer(11),
'valid_until' => $this->dateTime()->notNull(),
'direction_in_at' => $this->dateTime(),
'direction_out_at' => $this->dateTime(),
'created_at' => $this->dateTime()->notNull(),
'updated_at' => $this->dateTime()->notNull(),
], $tableOptions);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m220213_134539_add_table_mobile_device cannot be reverted.\n";
return false;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m220213_134539_add_table_mobile_device cannot be reverted.\n";
return false;
}
*/
}

View File

@@ -0,0 +1,43 @@
<?php
use yii\db\Migration;
/**
* Class m220218_192423_alter_table_mobile_device_add_column_device_name
*/
class m220218_192423_alter_table_mobile_device_add_column_device_name extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('mobile_device', 'device_name', $this->string() );
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m220218_192423_alter_table_mobile_device_add_column_device_name cannot be reverted.\n";
return false;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m220218_192423_alter_table_mobile_device_add_column_device_name cannot be reverted.\n";
return false;
}
*/
}

View File

@@ -0,0 +1,44 @@
<?php
use yii\db\Migration;
/**
* Class m220220_190302_add_virtual_key_field_for_card_key_assignment_table
*/
class m220220_190302_add_virtual_key_field_for_card_key_assignment_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('card_key_assignment','virtual_key', $this->string());
$this->addColumn('card_key_assignment','direction_in_at', 'datetime');
$this->addColumn('card_key_assignment','direction_out_at', 'datetime');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m220220_190302_add_virtual_key_field_for_card_key_assignment_table cannot be reverted.\n";
return false;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m220220_190302_add_virtual_key_field_for_card_key_assignment_table cannot be reverted.\n";
return false;
}
*/
}

View File

@@ -0,0 +1,42 @@
<?php
use yii\db\Migration;
/**
* Class m220803_190701_alter_table_door_log_add_version
*/
class m220803_190701_alter_table_door_log_add_version extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('door_log', 'version', $this->integer( )->notNull()->defaultValue(1) );
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m220803_190701_alter_table_door_log_add_version cannot be reverted.\n";
return false;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m220803_190701_alter_table_door_log_add_version cannot be reverted.\n";
return false;
}
*/
}

View File

@@ -0,0 +1,217 @@
<?php
use yii\db\Migration;
/**
* Class m220928_165551_update_trigger
*/
class m220928_165551_update_trigger extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$sql = "
drop trigger if exists trigger_inc_ticket_usage_count;
CREATE TRIGGER trigger_inc_ticket_usage_count
AFTER INSERT
ON `door_log`
FOR EACH ROW
begin
DECLARE p_count_all Integer;
DECLARE p_count_all_2 Integer;
DECLARE p_from DATETIME;
DECLARE p_usage_count Integer;
DECLARE p_max_usage_count Integer;
DECLARE p_mo_ticket_id Integer;
DECLARE p_mo_ticket_max_usage_count Integer;
DECLARE p_allow_multiple_enter boolean;
DECLARE p_allow_enter boolean;
delete from devlog;
IF NEW.version = 1
THEN
IF NEW.id_customer is not null and NEW.id_card is not null
THEN
IF (NEW.direction = 7 or New.direction = 3) and NEW.id_ticket_current is not null
then
INSERT INTO devlog (msg) values ('belepes feldoglozas indit');
select count(*)
into @p_count_all
from door_log
where created_at >= CURDATE()
and id_ticket_current = New.id_ticket_current
and (direction = 7 or direction = 3);
INSERT INTO devlog (msg) values (concat('count all', @p_count_all));
IF @p_count_all = 1
THEN
select usage_count, max_usage_count
into @p_usage_count ,@p_max_usage_count
from ticket
where id_ticket = NEW.id_ticket_current;
update ticket set usage_count = usage_count + 1 where id_ticket = NEW.id_ticket_current;
INSERT INTO log (type, message, app, id_ticket, id_door_log, created_at, updated_at)
values (30, concat('Bérlet használat (elotte: ', @p_usage_count, ' > utana: ', @p_usage_count + 1,
' max: ', @p_max_usage_count, ')'), ' trigger_inc_ticket', New.id_ticket_current,
New.id_door_log, now(), now());
else
select min(created_at) +
INTERVAL (3 * FLOOR(((HOUR(TIMEDIFF(min(created_at), now())) / 3)))) hour as last_date
into @p_from
from door_log
where created_at > CURDATE()
and id_customer is not null
and id_ticket_current = NEW.id_ticket_current
and (direction = 7 or direction = 3);
select count(*)
into @p_count_all_2
from door_log
where created_at >= @p_from
and id_ticket_current = New.id_ticket_current
and (direction = 7 or direction = 3);
INSERT INTO devlog (msg)
values (CONCAT('Belépések száma az aktuális 3 órás intervalumban: ', @p_count_all_2));
IF @p_count_all_2 = 1
THEN
INSERT INTO devlog (msg)
values ('Az aktuális intervallumban ez az első belépés, usage_count növelése');
select usage_count, max_usage_count
into @p_usage_count ,@p_max_usage_count
from ticket
where id_ticket = NEW.id_ticket_current;
update ticket set usage_count = usage_count + 1 where id_ticket = New.id_ticket_current;
INSERT INTO log (type, message, app, id_ticket, id_door_log, created_at, updated_at)
values (40, concat('Bérlet használat/egy nap tobbszori (elotte: ', @p_usage_count, ' > utana: ',
@p_usage_count + 1, ' max: ', @p_max_usage_count, ')'),
' trigger_inc_ticket', New.id_ticket_current, New.id_door_log, now(), now());
END IF;
END IF;
End IF;
IF NEW.direction = 5 or New.direction = 1
then
INSERT INTO devlog (msg) values ('Kilépés van folyamatban, kilépések számának beállítása');
update ticket set count_move_out = usage_count where id_ticket = NEW.id_ticket_current;
END IF;
INSERT INTO devlog (msg) values ('Kártya validáció módosítása');
UPDATE card as c1
left JOIN (select ticket.id_card as id_card, max(ticket.id_ticket) as id_ticket
from ticket
where ticket.start <= CURDATE()
and ticket.end >= curdate()
and ticket.status = 10
and ticket.count_move_out < ticket.max_usage_count
and ticket.id_card = New.id_card
group by id_card
order by id_card desc) as t
on t.id_card = c1.id_card
SET c1.validity = case
when t.id_card is null then (c1.validity | 1 << 0)
else (c1.validity & ~(1 << 0)) end
, c1.flag = case
when t.id_card is null then (c1.flag | 1 << 0)
else (c1.flag & ~(1 << 0)) end
, c1.id_ticket_current = case when t.id_ticket is null then null else t.id_ticket end
WHERE c1.type <> 50
and c1.id_card = New.id_card;
IF NEW.direction = 5 or New.direction = 1
then
select max(ticket.id_ticket)
into @p_mo_ticket_id
from ticket
where ticket.start <= CURDATE()
and ticket.end >= curdate()
and ticket.status = 10
and ticket.count_move_out < ticket.max_usage_count
and ticket.id_card = New.id_card
group by id_card
order by id_card desc;
set @p_allow_enter = true;
update card
set flag_out = (flag_out | 1 << 1),
flag = case when @p_allow_enter then (flag & ~(1 << 1)) else (flag | 1 << 1) end
WHERE type <> 50
and id_card = New.id_card;
END IF;
IF (NEW.direction = 7 or New.direction = 3) and NEW.id_ticket_current is not null
THEN
update card
set flag_out = (flag_out & ~(1 << 1)),
flag = (flag | 1 << 1)
WHERE type <> 50
and id_card = New.id_card;
END IF;
END IF;
END IF;
END
";
$this->execute($sql);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m220928_165551_update_trigger cannot be reverted.\n";
return true;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m220928_165551_update_trigger cannot be reverted.\n";
return false;
}
*/
}

View File

@@ -0,0 +1,43 @@
<?php
use yii\db\Migration;
/**
* Class m221023_173829_add_table_virtual_key
*/
class m221023_173829_add_table_virtual_key extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->dropColumn("virtual_key",'valid_until');
$this->dropColumn("virtual_key",'direction_out_at');
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m221023_173829_add_table_virtual_key cannot be reverted.\n";
return false;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m221023_173829_add_table_virtual_key cannot be reverted.\n";
return false;
}
*/
}

View File

@@ -0,0 +1,42 @@
<?php
use yii\db\Migration;
/**
* Class m221024_203742_alter_table_virtual_key_add_column_number
*/
class m221024_203742_alter_table_virtual_key_add_column_number extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn("virtual_key","number", $this->string(23));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m221024_203742_alter_table_virtual_key_add_column_number cannot be reverted.\n";
return false;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m221024_203742_alter_table_virtual_key_add_column_number cannot be reverted.\n";
return false;
}
*/
}

View File

@@ -0,0 +1,27 @@
<?php
use yii\db\Migration;
/**
* Class m221026_111439_alter_table_virtual_key_add_column_direction_out_at
*/
class m221026_111439_alter_table_virtual_key_add_column_direction_out_at extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn("virtual_key", "direction_out_at", $this->dateTime() );
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
echo "m221026_111439_alter_table_virtual_key_add_column_direction_out_at cannot be reverted.\n";
return false;
}
}