Commit 3ec9a878 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Ajout des colonnes clés supplémentaires

parent 49c5a0d1
Loading
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -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,
+31 −0
Original line number Diff line number Diff line
@@ -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
     */
+15 −1
Original line number Diff line number Diff line
@@ -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;
    }
+8 −3
Original line number Diff line number Diff line
@@ -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))
+3 −2
Original line number Diff line number Diff line
@@ -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';
Loading