Commit 3ec9a878 authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Ajout des colonnes clés supplémentaires

parent 49c5a0d1
Pipeline #8871 failed with stage
in 6 seconds
......@@ -12,6 +12,7 @@ CREATE TABLE SYNC_LOG
CREATE TABLE IMPORT_TABLES
(
TABLE_NAME VARCHAR2(30 CHAR) NOT NULL
, KEY_COLUMNS VARCHAR2(1000 CHAR)
, SYNC_FILTRE VARCHAR2(2000 CHAR)
, SYNC_ENABLED NUMBER(1, 0) DEFAULT 0 NOT NULL
, SYNC_JOB VARCHAR2(40 CHAR)
......@@ -29,7 +30,7 @@ create sequence SYNC_LOG_ID_SEQ;
/
CREATE OR REPLACE VIEW "V_IMPORT_TAB_COLS" ("TABLE_NAME", "COLUMN_NAME", "DATA_TYPE", "LENGTH", "NULLABLE", "HAS_DEFAULT", "C_TABLE_NAME", "C_COLUMN_NAME", "IMPORT_ACTIF") AS
CREATE OR REPLACE VIEW V_IMPORT_TAB_COLS AS
WITH importable_tables (table_name )AS (
SELECT
t.table_name
......@@ -63,6 +64,7 @@ WHERE
SELECT
tc.table_name,
tc.column_name,
CASE WHEN ',' || it.key_columns || ',' LIKE '%,' || tc.column_name || ',%' THEN 1 ELSE 0 END is_key,
tc.data_type,
CASE WHEN tc.char_length = 0 THEN NULL ELSE tc.char_length END length,
CASE WHEN tc.nullable = 'Y' THEN 1 ELSE 0 END nullable,
......
......@@ -26,6 +26,11 @@ class Table
*/
protected $ordre;
/**
* @var string|null
*/
protected $keyColumns;
/**
* @var bool
* @ORM\Column(name="SYNC_ENABLED", type="boolean", nullable=false)
......@@ -106,6 +111,32 @@ class Table
/**
* @return string|null
*/
public function getKeyColumns(): ?string
{
return $this->keyColumns;
}
/**
* @param string|null $keyColumns
*
* @return Table
*/
public function setKeyColumns(?string $keyColumns): Table
{
$this->keyColumns = $keyColumns;
return $this;
}
/**
* @return bool
*/
......
......@@ -70,9 +70,23 @@ class Column
*/
public $importActif;
/**
* Si la colonne est une clé pour l'import ou non
*
* @var boolean
*/
public $isKey = false;
public function isCompleteKey()
{
return $this->isKey || $this->name == 'SOURCE_CODE' || ($this->importActif && $this->name == 'ANNEE_ID');
}
function __toString()
public function __toString()
{
return $this->name;
}
......
......@@ -429,14 +429,19 @@ class QueryGeneratorService extends AbstractService
{
// Pour l'annualisation :
$schema = $this->getServiceSchema()->getSchema($tableName);
$joinCond = '';
$joinCond = 'S.source_code = D.source_code';
$delCond = '';
$depJoin = '';
foreach ($schema as $columnName => $column) {
if ($column->isKey){
$joinCond .= ' AND S.' . $columnName . ' = d.' . $columnName;
}
}
if (array_key_exists(self::ANNEE_COLUMN_NAME, $schema)) {
// Si la table courante est annualisée ...
if ($this->getServiceSchema()->hasColumn('V_DIFF_' . $tableName, self::ANNEE_COLUMN_NAME)) {
// ... et que la source est également annualisée alors concordance nécessaire
$joinCond = ' AND S.' . self::ANNEE_COLUMN_NAME . ' = d.' . self::ANNEE_COLUMN_NAME;
$joinCond .= ' AND S.' . self::ANNEE_COLUMN_NAME . ' = d.' . self::ANNEE_COLUMN_NAME;
}
// destruction ssi dans l'année d'import courante
$delCond = ' AND d.' . self::ANNEE_COLUMN_NAME . ' >= ' . $this->getPackage() . '.get_current_annee';
......@@ -494,7 +499,7 @@ CASE
}, ",\n ") . "
FROM
$tableName D$depJoin
FULL JOIN SRC_$tableName S ON S.source_id = D.source_id AND S.source_code = D.source_code$joinCond
FULL JOIN SRC_$tableName S ON S.source_id = D.source_id AND $joinCond
WHERE
(S.source_code IS NOT NULL AND D.source_code IS NOT NULL AND D.histo_destruction IS NOT NULL AND D.histo_destruction <= SYSDATE)
OR (S.source_code IS NULL AND D.source_code IS NOT NULL AND (D.histo_destruction IS NULL OR D.histo_destruction > SYSDATE))
......
......@@ -60,6 +60,7 @@ class SchemaService extends AbstractService
$column = new Column;
$column->table = $col['TABLE_NAME'];
$column->name = $col['COLUMN_NAME'];
$column->isKey = $col['IS_KEY'] == '1';
$column->dataType = $col['DATA_TYPE'];
$column->length = (null === $col['LENGTH']) ? null : (integer)$col['LENGTH'];
$column->nullable = $col['NULLABLE'] == '1';
......@@ -214,7 +215,7 @@ class SchemaService extends AbstractService
/**
* Détecte si une propriété d'une classe est importable ou non
*
*
* @param string|\stdClass $className
* @param string $fieldName
*
......@@ -225,7 +226,7 @@ class SchemaService extends AbstractService
if (is_object($className)){
$className = get_class($className);
}
$metadata = $this->getEntityManager()->getClassMetadata($className);
$tableName = $metadata->getTableName();
......
......@@ -7,6 +7,7 @@
<div class="panel-heading"><strong><?= $tname ?></strong></div>
<table class="table table-striped table-bordered table-hover table-condensed">
<tr>
<th>Clé</th>
<th>Colonne</th>
<th>Type</th>
<th>Longueur</th>
......@@ -22,6 +23,7 @@
echo 'danger';
} elseif (!$column->importActif) echo 'warning';
?>">
<th><?php if ($column->isCompleteKey()): ?><span class="glyphicon glyphicon-wrench"></span><?php endif; ?></th>
<th><?= $cname ?></th>
<td><?= $column->dataType ?></td>
<td style="text-align:center"><?= $column->length ?></td>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment