Pārlūkot izejas kodu

Copiar parser a bruto. Cambiar metodologia para insertar cada nodo de golpe con los nuevos campos id_ajena_licitacion y id_compuesta

Nermosis 3 gadus atpakaļ
vecāks
revīzija
5ea9461cb7

+ 1 - 0
.gitignore Parādīt failu

@@ -34,3 +34,4 @@ open-placsp-1.1.1
34 34
 Beyond Compare 4
35 35
 uploads/
36 36
 application/config/database.php
37
+application/libraries/ParserDatabaseBruto1.php

+ 136 - 141
application/libraries/ParserDatabaseBruto.php Parādīt failu

@@ -24,154 +24,191 @@ class ParserDatabaseBruto
24 24
             foreach ($arrayDatosSucios as $nombreArchivo => $datosArchivo) {
25 25
                 guardar_log($this->nombreLog, "ARCHIVO ---" . $nombreArchivo, false);
26 26
 
27
-                foreach ($datosArchivo as $row) {
28
-                    $idLicitacion = $this->setInicioLicitacion($row['general']);
27
+                $this->setDatosMultiples($datosArchivo, "general", "bruto_datos_iniciales", "DatosIniciales");
29 28
 
30
-                    if ($idLicitacion['result']) {
31
-                        $this->idLicitacion = $idLicitacion['id'];
29
+                $this->setDatosMultiples($datosArchivo, "contractInfo", "BRUTO_contract_folder", "ContractInfo");
32 30
 
33
-                        $this->setDatosSingular($row, "contractInfo", "BRUTO_contract_folder", $this->idLicitacion, "ContractInfo", "id_ajena_licitacion");
31
+                $this->setDatosMultiples($datosArchivo, "tenderingProcess", "BRUTO_tendering_process", "TenderingProcess");
34 32
 
35
-                        $this->setDatosSingular($row, "tenderingProcess", "BRUTO_tendering_process", $this->idLicitacion, "TenderingProcess", "id_ajena_licitacion");
33
+                $this->setProcurementProjectArray($datosArchivo);
36 34
 
37
-                        $this->setProcurementProject($row['procurementProject']);
35
+                /*$this->setDatosMultiples($datosArchivo, "tenderingTerms", "bruto_tendering_terms", "TenderingTerms");
38 36
 
39
-                        $this->setProcurementProjectLot($row['procurementProjectLot']);
37
+                $this->setDatosMultiples($datosArchivo['tenderingTerms'], 1, "bruto_tendering_terms", "TenderingTerms");
40 38
 
41
-                        $this->setTenderingTerms($row['tenderingTerms']);
39
+                $this->setDatosMultiples($datosArchivo['tenderingTerms'], 2, "bruto_tendering_terms", "TenderingTerms");
42 40
 
43
-                        $this->setLocatedContractingParty($row['locatedContractingParty']);
41
+                $this->setDatosMultiples($datosArchivo['tenderingTerms'], 3, "bruto_tendering_terms", "TenderingTerms");
44 42
 
45
-                        $this->setParty($row['party']);
43
+                $this->setDatosMultiples($datosArchivo['tenderingTerms'], 4, "bruto_tendering_terms", "TenderingTerms");*/
46 44
 
47
-                        $this->setValidNoticeInfo($row['validNoticeInfo']);
45
+                $this->setLocatedContractingParty($datosArchivo); //, "locatedContractingParty", "BRUTO_located_contracting_party", "locatedContractingParty");
48 46
 
49
-                        $this->setDatosMultiples($row, "tenderingResult", "BRUTO_tender_result", $this->idLicitacion, "TenderResult", "id_ajena_licitacion");
47
+                $this->setParty($datosArchivo);
50 48
 
51
-                        $this->setDatosMultiples($row, "legalDocs", "BRUTO_legal_documents", $this->idLicitacion, "LegalDocs", 'id_ajena_licitacion');
49
+                /*$this->setDatosMultiples($datosArchivo, "validNoticeInfo", "BRUTO_valid_notice_info", "ValideNoticeInfo");
52 50
 
53
-                        $this->setDatosMultiples($row, "technicalDocs", "BRUTO_technical_documents", $this->idLicitacion, "TechnicalDocs", "id_ajena_licitacion");
51
+                $this->setDatosMultiples($datosArchivo['validNoticeInfo'], "documento", "BRUTO_valid_notice_info_documento", "validNoticeInfoDocumento");
54 52
 
55
-                        $this->setDatosMultiples($row, "generalDocs", "BRUTO_general_documents", $this->idLicitacion, "GeneralDocs", "id_ajena_licitacion");
53
+                $this->setDatosMultiples($datosArchivo['validNoticeInfo'], "fechas", "BRUTO_valid_notice_info_fecha", "validNoticeInfoFechas");
56 54
 
57
-                        $this->setDatosMultiples($row, "additionalDocs", "BRUTO_additional_documents", $this->idLicitacion, "AdditionalDocs", "id_ajena_licitacion");
58
-                    }
59
-                }
55
+                $this->setDatosMultiples($datosArchivo, "tenderingResult", "BRUTO_tender_result", "TenderResult");*/
56
+
57
+                $this->setDocumentos($datosArchivo, "legalDocs", ["BRUTO_legal_documents", "mapa_nivel_legal_docs"], "legalDocs");
58
+
59
+                $this->setDocumentos($datosArchivo, "technicalDocs", ["BRUTO_technical_documents", "mapa_nivel_technical_docs"], "TechnicalDocs");
60
+
61
+                $this->setDocumentos($datosArchivo, "generalDocs", ["BRUTO_general_documents", "mapa_nivel_general_docs"], "GeneralDocs");
62
+
63
+                $this->setDocumentos($datosArchivo, "additionalDocs", ["BRUTO_additional_documents", "mapa_nivel_additional_docs"], "additionalDocs");
60 64
             }
61 65
         }
62 66
 
63 67
         return;
64 68
     }
65 69
 
66
-    private function setInicioLicitacion($datosInicioLicitacion): array
70
+    private function setProcurementProjectArray($procurementProjectData)
67 71
     {
68
-        $result = array("result" => false, "id" => 0);
69
-        $datosInicioLicitacion['fecha_creacion_log'] = $this->fechaInicioParser;
70
-        $insertLicitacion = $this->CI->Parser_model->setInicioLicitacion($datosInicioLicitacion);
72
+        $result = array();
73
+        $coleccionMapaProcProject = array();
74
+        $countColeccionProcProject = 0;
75
+        $mapaDatos = $this->CI->Parser_model->getMapaByTabla("mapa_nivel_procurement_project");
71 76
 
72
-        if ($insertLicitacion) {
73
-            $result = array("result" => true, "id" => $datosInicioLicitacion['id_licitacion']);
74
-            guardar_log($this->nombreLog, "Licitacion ID " . $datosInicioLicitacion['id_licitacion'] . " - BBDD Licitación ID " . $insertLicitacion, "false");
75
-        } else {
76
-            $result = array("result" => true, "id" => 0);
77
-            guardar_log($this->nombreLog, "Licitacion ID " . $datosInicioLicitacion['id_licitacion'], "false", 2);
77
+        foreach ($mapaDatos['datos'] as $dataField) {
78
+            $coleccionMapaProcProject[] = $dataField->campo_bbdd;
78 79
         }
80
+        $countColeccionProcProject = count($coleccionMapaProcProject);
81
+
82
+        foreach ($procurementProjectData['procurementProject'] as $rowData) {
83
+            $budget = $rowData['budget'];
84
+            if ($countColeccionProcProject > count($budget)) {
85
+                foreach ($coleccionMapaProcProject as $dataField) {
86
+                    if (!array_key_exists($dataField, $budget)) {
87
+                        $budget[$dataField] = "";
88
+                    }
89
+                }
90
+            }
79 91
 
80
-        return $result;
81
-    }
92
+            if (array_key_exists('itemClass', $rowData)) {
93
+                foreach ($rowData['itemClass'] as $itemClass) {
94
+                    $result['itemClass'][] = $itemClass;
95
+                }
96
+            }
82 97
 
83
-    private function setLocatedContractingParty($contractInfo): void
84
-    {
85
-        $locatedContractingPartyId = $this->setDatosSingular($contractInfo, "locatedContractingParty", "BRUTO_located_contracting_party", $this->idLicitacion, "locatedContractingParty", "id_ajena_licitacion");
98
+            $result['budget'][] = $budget;
99
+
100
+        }
86 101
 
87
-        $this->setDatosMultiples($contractInfo, "activity", "BRUTO_located_contracting_party_activity", $locatedContractingPartyId, "locatedContractingParty_Activity", "id_ajena_lcp");
102
+        $this->setDatosMultiples($result, "budget", "bruto_procurement_project", "ProcurementProject");
88 103
 
104
+        $this->setDatosMultiples($result, "itemClass", "bruto_procurement_project_itemclass", "ProcurementProject_ItemClass");
89 105
     }
90 106
 
91
-    private function setParty($partyInfo): void
107
+    private function setLocatedContractingParty($datosToSet)
92 108
     {
93
-        $partyId = $this->setDatosSingular($partyInfo, "party", "BRUTO_party", $this->idLicitacion, "PartyInfo", "id_ajena_licitacion");
109
+        $result = array();
110
+        $coleccionMapa = array();
111
+        $countColeccion = 0;
112
+        $mapaDatos = $this->CI->Parser_model->getMapaByTabla("mapa_nivel_located_contracting_party");
113
+
114
+        foreach ($mapaDatos['datos'] as $dataField) {
115
+            $coleccionMapa[] = $dataField->campo_bbdd;
116
+        }
117
+        $countColeccion = count($coleccionMapa);
118
+
119
+        foreach ($datosToSet['locatedContractingParty'] as $rowData) {
120
+            $locatedContractingParty = $rowData['locatedContractingParty'];
121
+            if ($countColeccion > count($locatedContractingParty)) {
122
+                foreach ($coleccionMapa as $dataField) {
123
+                    if (!array_key_exists($dataField, $locatedContractingParty)) {
124
+                        $locatedContractingParty[$dataField] = "";
125
+                    }
126
+                }
127
+            }
94 128
 
95
-        $this->setDatosMultiples($partyInfo, "partyIdentification", "BRUTO_party_party_idenfitication", $partyId, "PartyInfo_PartyIdentification", "id_ajena_party");
129
+            if (array_key_exists('activity', $rowData)) {
130
+                foreach ($rowData['activity'] as $itemClass) {
131
+                    $result['activity'][] = $itemClass;
132
+                }
133
+            }
96 134
 
97
-    }
135
+            $result['locatedContractingParty'][] = $locatedContractingParty;
98 136
 
99
-    private function setProcurementProject($procurementInfo): void
100
-    {
101
-        $procurementProjectId = $this->setDatosSingular($procurementInfo, "budget", "BRUTO_procurement_project", $this->idLicitacion, "ProcurementProject", "id_ajena_licitacion");
137
+        }
138
+
139
+        $this->setDatosMultiples($result, "locatedContractingParty", "bruto_located_contracting_party", "LocatedContractingParty");
102 140
 
103
-        $this->setDatosMultiples($procurementInfo, "itemClass", "BRUTO_procurement_project_itemClass", $procurementProjectId, "ProcurementProject_ItemClass", "id_ajena_pp");
141
+        $this->setDatosMultiples($result, "activity", "bruto_located_contracting_party_activity", "LocatedContractingParty_Activity");
104 142
     }
105 143
 
106
-    private function setProcurementProjectLot($procurementLotInfo): void
144
+    private function setParty($datosToSet)
107 145
     {
108
-        $resultInsert = 0;
109
-
110
-        if (!empty($procurementLotInfo)) {
111
-            $aux = 0;
112
-            foreach ($procurementLotInfo as $row) {
113
-                $setInsert = array();
114
-                $setInsert[$aux] = $row;
115
-                $setInsert[$aux]['id_ajena_licitacion'] = $this->idLicitacion;
116
-                $setInsert[$aux]["fecha_creacion_log"] = $this->fechaInicioParser;
117
-                unset($setInsert[$aux]['itemClassification']);
146
+        $result = array();
147
+        $coleccionMapa = array();
148
+        $countColeccion = 0;
149
+        $mapaDatos = $this->CI->Parser_model->getMapaByTabla("mapa_nivel_party");
118 150
 
119
-                if (!empty($setInsert)) {
120
-                    $resultInsert = insertBucle($setInsert, "BRUTO_procurement_project_lot", $this->nombreLog);
121
-                    if (array_key_exists('itemClassification', $row)) {
122
-                        $this->setDatosMultiples($row, "itemClassification", "BRUTO_procurement_project_lot_item", $resultInsert, "ProcurementLotItem", "id_ajena_ppl");
151
+        foreach ($mapaDatos['datos'] as $dataField) {
152
+            $coleccionMapa[] = $dataField->campo_bbdd;
153
+        }
154
+        $countColeccion = count($coleccionMapa);
155
+
156
+        foreach ($datosToSet['party'] as $rowData) {
157
+            $party = $rowData['party'];
158
+            if ($countColeccion > count($party)) {
159
+                foreach ($coleccionMapa as $dataField) {
160
+                    if (!array_key_exists($dataField, $party)) {
161
+                        $party[$dataField] = "";
123 162
                     }
124 163
                 }
125
-                $aux++;
126 164
             }
127 165
 
128
-            if ($resultInsert) {
129
-                $result = array("result" => true);
130
-                guardar_log($this->nombreLog, "ProcurementLot Finalizada Inserción", "false");
131
-            } else {
132
-                $result = array("result" => true, "id" => 0);
133
-                guardar_log($this->nombreLog, "ProcurementLot Fallida", "false", 2);
166
+            if (array_key_exists('partyIdentification', $rowData)) {
167
+                foreach ($rowData['partyIdentification'] as $itemClass) {
168
+                    $result['partyIdentification'][] = $itemClass;
169
+                }
134 170
             }
135
-        } else {
136
-            guardar_log($this->nombreLog, "ProcurementLot vacio", "false");
137
-        }
138
-    }
139
-
140
-    private function setTenderingTerms($tenderingTermsInfo): void
141
-    {
142 171
 
143
-        $resultInsert = 0;
172
+            $result['party'][] = $party;
144 173
 
145
-        if (!empty($tenderingTermsInfo)) {
174
+        }
146 175
 
147
-            $setInsert = array();
148
-            $setInsert['tenderingTerms'][0] = $tenderingTermsInfo[0];
149
-            $setInsert['tenderingTerms'][0]['id_ajena_licitacion'] = $this->idLicitacion;
176
+        $this->setDatosMultiples($result, "party", "bruto_party", "Party");
150 177
 
151
-            if (!empty($setInsert)) {
152
-                $resultInsert = insertBucle($setInsert['tenderingTerms'], "BRUTO_tendering_terms", $this->nombreLog);
178
+        $this->setDatosMultiples($result, "partyIdentification", "bruto_party_party_idenfitication", "Party_PartyIdentification");
179
+    }
153 180
 
154
-                if ($resultInsert > 0) {
155
-                    $this->setDatosMultiples($tenderingTermsInfo, 1, "BRUTO_tendering_terms_awarding_terms", $resultInsert, "TenderingTermsAwardingTerms", "id_ajena_tt");
181
+    private function setDocumentos($datosToSet, $arrayKey, $tablasMapa, $nombreLog)
182
+    {
183
+        if (array_key_exists($arrayKey, $datosToSet)) {
184
+            $result = array();
185
+            $coleccionMapa = array();
186
+            $countColeccion = 0;
187
+            $mapaDatos = $this->CI->Parser_model->getMapaByTabla($tablasMapa[1]);
188
+
189
+            foreach ($mapaDatos['datos'] as $dataField) {
190
+                $coleccionMapa[] = $dataField->campo_bbdd;
191
+            }
156 192
 
157
-                    $this->setDatosMultiples($tenderingTermsInfo, 2, "BRUTO_tendering_terms_qualification_request", $resultInsert, "TenderingTermsQualificationRequest", "id_ajena_tt");
193
+            foreach ($datosToSet[$arrayKey] as $rowData) {
158 194
 
159
-                    $this->setDatosMultiples($tenderingTermsInfo, 3, "BRUTO_tendering_terms_financial_evaluation", $resultInsert, "TenderingTermsFinancialEvaluation", "id_ajena_ttfe");
195
+                /* if ($countColeccion > count($resultFinal)) {
196
+                foreach ($coleccionMapa as $dataField) {
197
+                if (!array_key_exists($dataField, $resultFinal)) {
198
+                $resultFinal[$dataField] = "";
199
+                }
200
+                }
201
+                } */
160 202
 
161
-                    $this->setDatosMultiples($tenderingTermsInfo, 4, "BRUTO_tendering_terms_specific_terms", $resultInsert, "TenderingTermsSpecificRequirement", "id_ajena_tt");
203
+                foreach ($rowData as $documento) {
204
+                    $result[$arrayKey][] = $documento;
162 205
                 }
163
-            }
164 206
 
165
-            if ($resultInsert) {
166
-                $result = array("result" => true);
167
-                guardar_log($this->nombreLog, "TenderingTerms Finalizada Inserción", "false");
168
-            } else {
169
-                $result = array("result" => true, "id" => 0);
170
-                guardar_log($this->nombreLog, "TenderingTerms Fallida", "false", 2);
171 207
             }
172
-        } else {
173
-            guardar_log($this->nombreLog, "TenderingTerms vacio", "false");
208
+
209
+            $this->setDatosMultiples($result, $arrayKey, $tablasMapa[0], $nombreLog);
174 210
         }
211
+
175 212
     }
176 213
 
177 214
     private function setValidNoticeInfo($validNoticeInfo): void
@@ -181,9 +218,9 @@ class ParserDatabaseBruto
181 218
 
182 219
         if (!empty($validNoticeInfo)) {
183 220
             $aux = 0;
184
-            foreach ($validNoticeInfo as $row) {
221
+            foreach ($validNoticeInfo as $datosArchivo) {
185 222
                 $setInsert = array();
186
-                $setInsert[$aux] = $row;
223
+                $setInsert[$aux] = $datosArchivo;
187 224
                 $setInsert[$aux]['id_ajena_licitacion'] = $this->idLicitacion;
188 225
 
189 226
                 unset($setInsert[$aux]['documento']);
@@ -193,9 +230,9 @@ class ParserDatabaseBruto
193 230
                     $resultInsert = insertBucle($setInsert, "BRUTO_valid_notice_info", $this->nombreLog);
194 231
 
195 232
                     if ($resultInsert > 0) {
196
-                        $this->setDatosMultiples($row, "documento", "BRUTO_valid_notice_info_documento", $resultInsert, "validNoticeInfoFechas", "id_ajena_vni");
233
+                        $this->setDatosMultiples($datosArchivo, "documento", "BRUTO_valid_notice_info_documento", $resultInsert, "validNoticeInfoFechas", "id_ajena_vni");
197 234
 
198
-                        $this->setDatosMultiples($row, "fechas", "BRUTO_valid_notice_info_fecha", $resultInsert, "validNoticeInfoDocumento", "id_ajena_vni");
235
+                        $this->setDatosMultiples($datosArchivo, "fechas", "BRUTO_valid_notice_info_fecha", $resultInsert, "validNoticeInfoDocumento", "id_ajena_vni");
199 236
                     }
200 237
                 }
201 238
                 $aux++;
@@ -213,57 +250,15 @@ class ParserDatabaseBruto
213 250
         }
214 251
     }
215 252
 
216
-    private function setDatosSingular($arrayDatos, $arrayKey, $tabla, $idAjena = 0, $nodoLog, $txtIdAjena): int
217
-    {
218
-        $insertedId = 0;
219
-        if (!empty($arrayDatos) && array_key_exists($arrayKey, $arrayDatos)) {
220
-            $arrayInsertar = array();
221
-
222
-            $arrayInsertar[0] = $arrayDatos[$arrayKey];
223
-
224
-            if ($idAjena > 0) {
225
-                $arrayInsertar[0][$txtIdAjena] = $idAjena;
226
-                $arrayInsertar[0]["fecha_creacion_log"] = $this->fechaInicioParser;
227
-            }
228
-            unset($arrayInsertar[0]['id']);
229
-
230
-            $insertedId = insertBucle($arrayInsertar, $tabla, $this->nombreLog);
231
-
232
-            if ($insertedId == 0) {
233
-                guardar_log($this->nombreLog, $nodoLog . " Fallido", "false");
234
-            } else {
235
-                guardar_log($this->nombreLog, $nodoLog . " Finalizada Inserción", "false");
236
-            }
237
-        } else {
238
-            guardar_log($this->nombreLog, $nodoLog . " vacio", "false");
239
-        }
240
-
241
-        return $insertedId;
242
-    }
243
-
244
-    private function setDatosMultiples($arrayDatos, $arrayKey, $tabla, $idAjena = 0, $nodoLog, $txtIdAjena): void
253
+    private function setDatosMultiples($arrayDatos, $arrayKey, $tabla, $nodoLog): void
245 254
     {
246 255
         $setInsert = array();
247 256
         $resultInsert = 0;
248 257
 
249 258
         if (array_key_exists($arrayKey, $arrayDatos)) {
250 259
             if (!empty($arrayDatos[$arrayKey])) {
251
-                $aux = 0;
252
-                foreach ($arrayDatos[$arrayKey] as $row) {
253
-                    $setInsert[$aux] = $row;
254
-
255
-                    if ($idAjena > 0) {
256
-                        $setInsert[$aux][$txtIdAjena] = $idAjena;
257
-                        $setInsert[$aux]["fecha_creacion_log"] = $this->fechaInicioParser;
258
-                        unset($setInsert[$aux]['id']);
259
-                    }
260 260
 
261
-                    $aux++;
262
-                }
263
-
264
-                if (!empty($setInsert)) {
265
-                    $resultInsert = insertBucle($setInsert, $tabla, $this->nombreLog);
266
-                }
261
+                $resultInsert = insertBucleDuplicateOnKey($arrayDatos[$arrayKey], $tabla, $this->nombreLog);
267 262
 
268 263
                 if ($resultInsert) {
269 264
                     $result = array("result" => true);

+ 11 - 1
application/models/Parser_model.php Parādīt failu

@@ -42,7 +42,7 @@ class Parser_model extends CI_Model
42 42
         $data = array(
43 43
             'cron_ejecucion' => 0,
44 44
             "fecha_ejecucion" => date("Y-m-d h:i:s"),
45
-            
45
+
46 46
         );
47 47
 
48 48
         $this->db->where('id', 0);
@@ -91,6 +91,16 @@ class Parser_model extends CI_Model
91 91
         return $datos;
92 92
     }
93 93
 
94
+    public function getMapaByTabla($tabla)
95
+    {
96
+        $sql = "SELECT * FROM $tabla";
97
+        $result = $this->db->query($sql);
98
+        $datos['datos'] = $result->result();
99
+        $datos['num_rows'] = $result->num_rows();
100
+        return $datos;
101
+
102
+    }
103
+
94 104
 }
95 105
 
96 106
 /* End of file Parser_model.php */