diff --git a/app/Controllers/CLI/DBMigration/DBMigration.php b/app/Controllers/CLI/DBMigration/DBMigration.php index e1ac9b2..a3d6940 100644 --- a/app/Controllers/CLI/DBMigration/DBMigration.php +++ b/app/Controllers/CLI/DBMigration/DBMigration.php @@ -17,6 +17,7 @@ abstract class DBMigration extends BaseController } abstract protected function getSourceDB(): BaseConnection; abstract protected function getClient(): array; + abstract protected function getLine(): array; final protected function getTargetDB(): BaseConnection { if ($this->_targetDB === null) { @@ -25,7 +26,7 @@ abstract class DBMigration extends BaseController return $this->_targetDB; } - protected function client_process(mixed $row): array + protected function client_process(mixed $row, int $cnt): void { $temps = []; $temps['code'] = $row['Client_Code']; @@ -47,7 +48,11 @@ abstract class DBMigration extends BaseController if (!empty($row['Client_Receive_date'])) { $temps['created_at'] = $row['Client_Receive_date'];; } - return $temps; + //신규DB에 삽입 + if (!$this->getTargetDB()->table('clientinfo')->insert($temps)) { + throw new \Exception($this->getTargetDB()->error()['message']); + } + echo "{$cnt} -> {$temps['name']} 고객완료.\n"; } final public function client(): void @@ -57,11 +62,55 @@ abstract class DBMigration extends BaseController try { $cnt = 1; foreach ($this->getClient() as $row) { - $datas = $this->client_process($row); - if (!$this->getTargetDB()->table('clientinfo')->insert($datas)) { - throw new \Exception($this->getTargetDB()->error()['message']); - } - echo "{$cnt} -> {$datas['name']} 고객완료.\n"; + $this->client_process($row, $cnt); + $cnt++; + } + echo __FUNCTION__ . " 작업을 완료하였습니다."; + $this->getTargetDB()->transCommit(); + } catch (\Exception $e) { + //Transaction Rollback + $this->getTargetDB()->transRollback(); + echo __FUNCTION__ . " 작업을 실패하였습니다.\n--------------\n" . $e->getMessage() . "\n--------------\n"; + } + } + + protected function line_process(mixed $row, int $cnt): void + { + $temps = []; + $temps['code'] = $row['Client_Code']; + $temps['role'] = $row['Client_Reseller'] == 30 ? "reseller" : "user"; + $temps['name'] = $row['Client_Name']; + $temps['phone'] = empty($row['Client_Phone1']) ? "" : $row['Client_Phone1']; + if (empty($temps['phone'])) { + $temps['phone'] = empty($row['Client_Phone2']) ? "" : $row['Client_Phone2']; + } + $temps['email'] = empty($row['Client_EMail1']) ? "" : $row['Client_EMail1']; + if (empty($temps['email'])) { + $temps['email'] = empty($row['Client_EMail2']) ? "" : $row['Client_EMail2']; + } + $temps['account_balance'] = intval($row['Client_Money']); + $temps['coupon_balance'] = 0; + $temps['point_balance'] = 0; + $temps['status'] = 'default'; + $temps['updated_at'] = empty($row['Client_Renew_date']) ? NULL : $row['Client_Renew_date'];; + if (!empty($row['Client_Receive_date'])) { + $temps['created_at'] = $row['Client_Receive_date'];; + } + //신규DB에 삽입 + if (!$this->getTargetDB()->table('lineinfo')->insert($temps)) { + throw new \Exception($this->getTargetDB()->error()['message']); + } + echo "{$cnt} -> {$temps['name']} Line완료.\n"; + } + + final public function line(): void + { + //Transaction Start + $this->getTargetDB()->transStart(); + try { + $cnt = 1; + foreach ($this->getClient() as $row) { + $this->line_process($row, $cnt); $cnt++; } echo __FUNCTION__ . " 작업을 완료하였습니다."; diff --git a/app/Controllers/CLI/DBMigration/SourceDB.php b/app/Controllers/CLI/DBMigration/SourceDB.php index af5760d..c51af2b 100644 --- a/app/Controllers/CLI/DBMigration/SourceDB.php +++ b/app/Controllers/CLI/DBMigration/SourceDB.php @@ -46,4 +46,8 @@ class SourceDB extends DBMigration { return $this->getSourceDB()->query('SELECT * FROM clientdb')->getResultArray(); } + protected function getLine(): array + { + return $this->getSourceDB()->query('select Line_code,line_case,Line_ip,line_client_name,line_gateway,line_id,line_pass,line_name,line_haveip,line_phone,line_mainip from linedb;select Line_code,line_case,Line_ip,line_client_name,line_gateway,line_id,line_pass,line_name,line_haveip,line_phone,line_mainip from linedb')->getResultArray(); + } } diff --git a/app/Database/erp2_2.vuerd.json b/app/Database/erp2_2.vuerd.json index 158d685..dd8618a 100644 --- a/app/Database/erp2_2.vuerd.json +++ b/app/Database/erp2_2.vuerd.json @@ -4,13 +4,13 @@ "settings": { "width": 3000, "height": 3000, - "scrollTop": -1064.2363, - "scrollLeft": -958.7592, + "scrollTop": -1288.5696, + "scrollLeft": -826, "zoomLevel": 0.76, "show": 511, "database": 4, "databaseName": "", - "canvasType": "@dineug/erd-editor/builtin-schema-sql", + "canvasType": "ERD", "language": 1, "tableNameCase": 4, "columnNameCase": 2,