· 7 years ago · Feb 01, 2019, 05:38 PM
1create or replace package EAM_PROVISION is
2
3 -- Creación
4 -- Version : 1.0
5 -- Author : Lucas Turchet
6 -- Created : 09/11/18
7 -- Purpose : Disponibilización de Activos para Integración con EAM AGuas Primaria
8
9 -- Modificacion
10 -- Version : 1.0.1
11 -- Author : Lucas Turchet
12 -- Created : 12/11/18
13 -- Purpose : No se filtrava la empresa para buscara errores
14
15 -- Modificacion
16 -- Version : 1.1
17 -- Author : Lucas Turchet
18 -- Created : 22/11/18
19 -- Purpose : isponibilización de Activos para Integración con EAM Aguas Secundaria
20
21 -- Modificacion
22 -- Version : 1.2
23 -- Author : Lucas Turchet
24 -- Created : 20/11/18
25 -- Purpose : Manejo de Novedades y Retirados
26
27 -- Modificacion
28 -- Version : 1.2.1
29 -- Author : Lucas Turchet
30 -- Created : 03/01/19
31 -- Purpose : Ajustes Codigos de Activos
32
33 -- Modificacion
34 -- Version : 1.2.2
35 -- Author : Lucas Turchet
36 -- Created : 22/01/19
37 -- Purpose : Ajustes
38 -- 1. Activos duplicados por conexion doble en los datos
39 -- 2. Nivel superior de los activos no se requiere
40 -- 3. Generar error de subcircuitos con el mismo codigo
41
42 -- Modificacion
43 -- Version : 1.2.3
44 -- Author : Lucas Turchet
45 -- Created : 23/01/19
46 -- Purpose : Ajustes
47 -- 1. Subcircuitos no pueden tener el codigo igual al del circuito.
48
49
50 -- Modificacion
51 -- Version : 1.2.4
52 -- Author : Lucas Turchet
53 -- Created : 31/01/19
54 -- Purpose : Ajustes
55 -- 1. Tuberias con punto inicial fuera de circuitos
56 -- 2. Valvulas con disintas redes
57
58 -- Variables Globales
59 --Empresas
60 eam_empresas constant eam_empresa := eam_empresa('EPM',
61 'EMPRESAS PUBLICAS DE ORIENTE');
62
63 --Estados
64 eam_estados_ret constant eam_estado := eam_estado('RETIRADO',
65 'FUERA DE SERVICIO');
66
67 vFechaEjec date;
68
69 -- Ejecuta toda la taxonima de Aguas(Primaria y Secundaria)
70 procedure EAM_TAXONOMIA;
71
72 -- Ejecuta la taxonima de Aguas Primaria
73 procedure EAM_TAXONOMIA_PRIMARIA;
74
75 -- Ejecuta la taxonima de Aguas Secundaria
76 procedure EAM_TAXONOMIA_SECUNDARIA;
77
78 -- Limpar el contenido de las tablas:
79 -- EAM_ACTIVOS
80 -- EAM_ACTIVOS_RET
81 -- EAM_UBICACION
82 procedure EAM_LIMPIAR_TABLAS;
83
84 -- Crea tablas respaldo de las tablas:
85 -- EAM_ACTIVOS (EAM_ACTIVOS_BKP)
86 -- EAM_ACTIVOS_RET (EAM_ACTIVOS_RET_BKP)
87 -- EAM_UBICACION (EAM_UBICACION_BKP)
88 procedure EAM_RESPALDAR_TABLAS;
89
90 -- Manejo de la fecha de actualizacion
91 procedure EAM_MANEJO_NOVEDAD;
92
93 -- Manejo de la fecha de actualizacion
94 procedure EAM_MANEJO_RETIRADOS;
95
96 -- Verifica si un texto es numerico
97 function ES_NUMERICO(pTexto in varchar2) return number;
98
99 -- Calcula el hash de un valor
100 function EAM_HASH(pValor in varchar2, pMax in number) return varchar;
101
102 -- Crea una nueva geometria del tipo punto con la primer coordinada de la linea
103 function PuntoInicialLinea(pLinea in sdo_geometry) return sdo_geometry;
104
105end EAM_PROVISION;
106/
107create or replace package body EAM_PROVISION is
108
109 procedure EAM_TAXONOMIA is
110
111 begin
112
113 execute immediate 'TRUNCATE TABLE EAM_ACTIVOS_TEMP';
114 execute immediate 'TRUNCATE TABLE EAM_UBICACION_TEMP';
115 execute immediate 'TRUNCATE TABLE EAM_ERRORS';
116
117 EAM_TAXONOMIA_PRIMARIA();
118 EAM_TAXONOMIA_SECUNDARIA();
119
120 --Manejos
121 select sysdate into vFechaEjec from dual;
122 update eam_activos_temp set fecha_actualizacion = vFechaEjec;
123 commit;
124 update eam_ubicacion_temp set fecha_actualizacion = vFechaEjec;
125 commit;
126
127 EAM_MANEJO_NOVEDAD();
128 EAM_MANEJO_RETIRADOS();
129
130 end EAM_TAXONOMIA;
131
132 procedure EAM_TAXONOMIA_PRIMARIA is
133
134 --Variables
135 vUbicacion eam_ubicacion_temp%rowtype;
136 vActivo eam_activos_temp%rowtype;
137
138 --Configuraciones
139 vUbiCodCondu VARCHAR2(100);
140 vUbiDesCondu VARCHAR2(100);
141 vUbiCodSucc VARCHAR2(100);
142 vUbiCodImp VARCHAR2(100);
143 vUbiCodAdu VARCHAR2(100);
144 vUbiCodSCru VARCHAR2(100);
145 vUbiCodSImp VARCHAR2(100);
146 vUbiCodCan VARCHAR2(100);
147 vUbiDesCan VARCHAR2(100);
148 vUbiCodTun VARCHAR2(100);
149 vUbiDesTun VARCHAR2(100);
150 vUbiClaAdu VARCHAR2(100);
151 vUbiClaCondu VARCHAR2(100);
152 vUbiClaSucc VARCHAR2(100);
153 vUbiClaImpu VARCHAR2(100);
154 vUbiClaSucCru VARCHAR2(100);
155 vUbiClaImpCru VARCHAR2(100);
156 vUbiClaCanal VARCHAR2(100);
157 vUbiClaTunel VARCHAR2(100);
158 vUbiPadCondu VARCHAR2(100);
159 vUbiPadSucc VARCHAR2(100);
160 vUbiPadImp VARCHAR2(100);
161 vUbiPadAdu VARCHAR2(100);
162 vUbiPadSecCru VARCHAR2(100);
163 vUbiPadImpCru VARCHAR2(100);
164 vUbiPadCanal VARCHAR2(100);
165 vUbiPadTun VARCHAR2(100);
166 vActClaObraCivil VARCHAR2(100);
167 vActClaValvulas VARCHAR2(100);
168 vActClaSegmento VARCHAR2(100);
169 vActClaSegmentoCanal VARCHAR2(100);
170 vActClaSegmentoTunel VARCHAR2(100);
171
172 --Tipo Red
173 vTipoRed varchar2(50) := 'PRIMARIA';
174
175 --Nivel 5, Ubicacion
176 --Conduccion
177 --Succion
178 --Impulsion
179 --Aduccion
180 --Succion Cruda
181 --Impulsio Cruda
182 cursor cTuberiasPriUbicacion(pTipoRed VARCHAR2, pTipoAgua VARCHAR2) is
183 select min(c.g3e_fno) as g3e_fno,
184 min(c.g3e_fid) as g3e_fid,
185 c.nombre_operacion
186 from atub_prm_at tub
187 inner join ccomun c
188 on c.g3e_fid = tub.g3e_fid
189 and c.g3e_fno = tub.g3e_fno
190 inner join cconectividad_a conn
191 on conn.g3e_fid = tub.g3e_fid
192 and conn.g3e_fno = tub.g3e_fno
193 where tub.tipo_red = pTipoRed
194 and conn.tipo_agua = pTipoAgua
195 and c.nombre_operacion is not null
196 and c.empresa in (select column_value from table(eam_empresas))
197 and c.estado in (select column_value from table(eam_estados_ret))
198 group by c.nombre_operacion
199 union all
200 select min(c.g3e_fno) as g3e_fno,
201 min(c.g3e_fid) as g3e_fid,
202 c.nombre_operacion
203 from atub_prm_at tub
204 inner join ccomun c
205 on c.g3e_fid = tub.g3e_fid
206 and c.g3e_fno = tub.g3e_fno
207 inner join cconectividad_a conn
208 on conn.g3e_fid = tub.g3e_fid
209 and conn.g3e_fno = tub.g3e_fno
210 where tub.tipo_red = pTipoRed
211 and conn.tipo_agua = pTipoAgua
212 and c.nombre_operacion is not null
213 and c.empresa in (select column_value from table(eam_empresas))
214 and c.estado in (select column_value from table(eam_estados_ret))
215 and c.nombre_operacion not in
216 (select c.nombre_operacion
217 from atub_prm_at tub
218 inner join ccomun c
219 on c.g3e_fid = tub.g3e_fid
220 and c.g3e_fno = tub.g3e_fno
221 inner join cconectividad_a conn
222 on conn.g3e_fid = tub.g3e_fid
223 and conn.g3e_fno = tub.g3e_fno
224 where tub.tipo_red = pTipoRed
225 and conn.tipo_agua = pTipoAgua
226 and c.nombre_operacion is not null
227 and c.empresa in
228 (select column_value from table(eam_empresas))
229 and c.estado in
230 (select column_value from table(eam_estados_ret))
231 group by c.nombre_operacion)
232 group by c.nombre_operacion;
233
234 --Nivel 5, Ubicacion
235 --Canal
236 cursor cCanalesUbicacion is
237 select min(c.g3e_fno) as g3e_fno,
238 min(c.g3e_fid) as g3e_fid,
239 can.nombre
240 from acanal_at can
241 inner join ccomun c
242 on c.g3e_fid = can.g3e_fid
243 and c.g3e_fno = can.g3e_fno
244 inner join cconectividad_a conn
245 on conn.g3e_fid = can.g3e_fid
246 and conn.g3e_fno = can.g3e_fno
247 where can.nombre is not null
248 and c.empresa in (select column_value from table(eam_empresas))
249 and c.estado not in
250 (select column_value from table(eam_estados_ret))
251 group by can.nombre
252 union all
253 select min(c.g3e_fno) as g3e_fno,
254 min(c.g3e_fid) as g3e_fid,
255 can.nombre
256 from acanal_at can
257 inner join ccomun c
258 on c.g3e_fid = can.g3e_fid
259 and c.g3e_fno = can.g3e_fno
260 inner join cconectividad_a conn
261 on conn.g3e_fid = can.g3e_fid
262 and conn.g3e_fno = can.g3e_fno
263 where can.nombre is not null
264 and c.empresa in (select column_value from table(eam_empresas))
265 and c.estado in (select column_value from table(eam_estados_ret))
266 and can.nombre not in
267 (select can.nombre
268 from acanal_at can
269 inner join ccomun c
270 on c.g3e_fid = can.g3e_fid
271 and c.g3e_fno = can.g3e_fno
272 inner join cconectividad_a conn
273 on conn.g3e_fid = can.g3e_fid
274 and conn.g3e_fno = can.g3e_fno
275 where can.nombre is not null
276 and c.empresa in
277 (select column_value from table(eam_empresas))
278 and c.estado not in
279 (select column_value from table(eam_estados_ret))
280 group by can.nombre)
281 group by can.nombre;
282
283 --Nivel 5, Ubicacion
284 --Tunel
285 cursor cTunelesUbicacion is
286 select min(c.g3e_fno) as g3e_fno,
287 min(c.g3e_fid) as g3e_fid,
288 can.nombre
289 from atunel_at can
290 inner join ccomun c
291 on c.g3e_fid = can.g3e_fid
292 and c.g3e_fno = can.g3e_fno
293 inner join cconectividad_a conn
294 on conn.g3e_fid = can.g3e_fid
295 and conn.g3e_fno = can.g3e_fno
296 where can.nombre is not null
297 and c.empresa in (select column_value from table(eam_empresas))
298 and c.estado not in
299 (select column_value from table(eam_estados_ret))
300 group by can.nombre
301 union all
302 select min(c.g3e_fno) as g3e_fno,
303 min(c.g3e_fid) as g3e_fid,
304 can.nombre
305 from atunel_at can
306 inner join ccomun c
307 on c.g3e_fid = can.g3e_fid
308 and c.g3e_fno = can.g3e_fno
309 inner join cconectividad_a conn
310 on conn.g3e_fid = can.g3e_fid
311 and conn.g3e_fno = can.g3e_fno
312 where can.nombre is not null
313 and c.empresa in (select column_value from table(eam_empresas))
314 and c.estado in (select column_value from table(eam_estados_ret))
315 and can.nombre not in
316 (select can.nombre
317 from atunel_at can
318 inner join ccomun c
319 on c.g3e_fid = can.g3e_fid
320 and c.g3e_fno = can.g3e_fno
321 inner join cconectividad_a conn
322 on conn.g3e_fid = can.g3e_fid
323 and conn.g3e_fno = can.g3e_fno
324 where can.nombre is not null
325 and c.empresa in
326 (select column_value from table(eam_empresas))
327 and c.estado not in
328 (select column_value from table(eam_estados_ret))
329 group by can.nombre)
330 group by can.nombre;
331
332 --Nivel 6, Activo
333 --Valvulas
334 cursor cActValvulas is
335 select c.g3e_fno, c.g3e_fid
336 from AVAL_PRM_AT val
337 inner join ccomun c
338 on c.g3e_fid = val.g3e_fid
339 and c.g3e_fno = val.g3e_fno
340 where c.empresa in (select column_value from table(eam_empresas));
341
342 --Apoyo para Activos, Valvulas
343 cursor cValvulaConTuberias(pFidValvula NUMBER) is
344 select min(g3e_fid) g3e_fid,
345 g3e_fno,
346 nombre_operacion,
347 cod,
348 count(1) over() as rowc
349 from (select c1.g3e_fid,
350 c1.g3e_fno,
351 cm.nombre_operacion,
352 eam_hash(cm.nombre_operacion, 999999) cod
353 from cconectividad_a c
354 inner join cconectividad_a c1
355 on (c1.nodo1_id = c.nodo1_id or c1.nodo2_id = c.nodo1_id)
356 inner join ccomun cm
357 on cm.g3e_fid = c1.g3e_fid
358 where c.g3e_fid = pFidValvula
359 and c1.g3e_fno = 11700
360 and c.nodo1_id > 0
361 and cm.empresa in
362 (select column_value from table(eam_empresas))
363 union all
364 select c1.g3e_fid,
365 c1.g3e_fno,
366 cm.nombre_operacion,
367 eam_hash(cm.nombre_operacion, 999999) cod
368 from cconectividad_a c
369 inner join cconectividad_a c1
370 on (c1.nodo1_id = c.nodo2_id or c1.nodo2_id = c.nodo2_id)
371 inner join ccomun cm
372 on cm.g3e_fid = c1.g3e_fid
373 where c.g3e_fid = pFidValvula
374 and c1.g3e_fno = 11700
375 and c.nodo2_id > 0
376 and cm.empresa in
377 (select column_value from table(eam_empresas)))
378 group by g3e_fno, nombre_operacion, cod
379 order by cod asc;
380
381 --Nivel 6, Activos
382 --Tuberias
383 cursor cActTubPri(pNombreOperacion VARCHAR2) is
384 select c.g3e_fno, c.g3e_fid, c.nombre_operacion
385 from atub_prm_at tub
386 inner join ccomun c
387 on c.g3e_fid = tub.g3e_fid
388 and c.g3e_fno = tub.g3e_fno
389 inner join cconectividad_a conn
390 on conn.g3e_fid = tub.g3e_fid
391 and conn.g3e_fno = tub.g3e_fno
392 where c.nombre_operacion = pNombreOperacion
393 and c.empresa in (select column_value from table(eam_empresas))
394 order by c.g3e_fid;
395
396 --Nivel 6 Activos
397 --Canales
398 cursor cActCanal(pNombre VARCHAR2) is
399 select c.g3e_fno, c.g3e_fid, can.nombre
400 from acanal_at can
401 inner join ccomun c
402 on c.g3e_fid = can.g3e_fid
403 and c.g3e_fno = can.g3e_fno
404 where can.nombre = pNombre
405 and c.empresa in (select column_value from table(eam_empresas))
406 order by c.g3e_fid;
407
408 --Nivel 6, Activos
409 --Tuneles
410 cursor cActTunel(pNombre VARCHAR2) is
411 select c.g3e_fno, c.g3e_fid, tun.nombre
412 from atunel_at tun
413 inner join ccomun c
414 on c.g3e_fid = tun.g3e_fid
415 and c.g3e_fno = tun.g3e_fno
416 where tun.nombre = pNombre
417 and c.empresa in (select column_value from table(eam_empresas))
418 order by c.g3e_fid;
419
420 begin
421
422 --Carga Configuración
423 select valor
424 into vUbiCodCondu
425 from eam_config
426 where descripcion = 'UbiCodCondu';
427 select valor
428 into vUbiDesCondu
429 from eam_config
430 where descripcion = 'UbiDesCondu';
431 select valor
432 into vUbiCodSucc
433 from eam_config
434 where descripcion = 'UbiCodSucc';
435 select valor
436 into vUbiCodImp
437 from eam_config
438 where descripcion = 'UbiCodImp';
439 select valor
440 into vUbiCodAdu
441 from eam_config
442 where descripcion = 'UbiCodAdu';
443 select valor
444 into vUbiCodSCru
445 from eam_config
446 where descripcion = 'UbiCodSCru';
447 select valor
448 into vUbiCodSImp
449 from eam_config
450 where descripcion = 'UbiCodSImp';
451 select valor
452 into vUbiCodCan
453 from eam_config
454 where descripcion = 'UbiCodCan';
455 select valor
456 into vUbiDesCan
457 from eam_config
458 where descripcion = 'UbiDesCan';
459 select valor
460 into vUbiCodTun
461 from eam_config
462 where descripcion = 'UbiCodTun';
463 select valor
464 into vUbiDesTun
465 from eam_config
466 where descripcion = 'UbiDesTun';
467 select valor
468 into vUbiClaAdu
469 from eam_config
470 where descripcion = 'UbiClaAdu';
471 select valor
472 into vUbiClaCondu
473 from eam_config
474 where descripcion = 'UbiClaCondu';
475 select valor
476 into vUbiClaSucc
477 from eam_config
478 where descripcion = 'UbiClaSucc';
479 select valor
480 into vUbiClaImpu
481 from eam_config
482 where descripcion = 'UbiClaImpu';
483 select valor
484 into vUbiClaSucCru
485 from eam_config
486 where descripcion = 'UbiClaSucCru';
487 select valor
488 into vUbiClaImpCru
489 from eam_config
490 where descripcion = 'UbiClaImpCru';
491 select valor
492 into vUbiClaCanal
493 from eam_config
494 where descripcion = 'UbiClaCanal';
495 select valor
496 into vUbiClaTunel
497 from eam_config
498 where descripcion = 'UbiClaTunel';
499 select valor
500 into vUbiPadCondu
501 from eam_config
502 where descripcion = 'UbiPadCondu';
503 select valor
504 into vUbiPadSucc
505 from eam_config
506 where descripcion = 'UbiPadSucc';
507 select valor
508 into vUbiPadImp
509 from eam_config
510 where descripcion = 'UbiPadImp';
511 select valor
512 into vUbiPadAdu
513 from eam_config
514 where descripcion = 'UbiPadAdu';
515 select valor
516 into vUbiPadSecCru
517 from eam_config
518 where descripcion = 'UbiPadSecCru';
519 select valor
520 into vUbiPadImpCru
521 from eam_config
522 where descripcion = 'UbiPadImpCru';
523 select valor
524 into vUbiPadCanal
525 from eam_config
526 where descripcion = 'UbiPadCanal';
527 select valor
528 into vUbiPadTun
529 from eam_config
530 where descripcion = 'UbiPadTun';
531 select valor
532 into vActClaObraCivil
533 from eam_config
534 where descripcion = 'ActClaObraCivil';
535 select valor
536 into vActClaValvulas
537 from eam_config
538 where descripcion = 'ActClaValvulas';
539 select valor
540 into vActClaSegmento
541 from eam_config
542 where descripcion = 'ActClaSegmento';
543 select valor
544 into vActClaSegmentoCanal
545 from eam_config
546 where descripcion = 'ActClaSegmentoCanal';
547 select valor
548 into vActClaSegmentoTunel
549 from eam_config
550 where descripcion = 'ActClaSegmentoTunel';
551
552 --Errores de las ubicaciones:
553 --Conduccion
554 --Succion
555 --Impulsion
556 --Aduccion
557 --Succion Cruda
558 --Impulsio Cruda
559 insert into eam_errors
560 select vTipoRed,
561 g3e_fid,
562 g3e_fno,
563 sysdate,
564 'Tuberia Primaria sin Nombre Operacion'
565 from CCOMUN
566 where g3e_fno = 11700
567 and nombre_operacion is null
568 and empresa in (select column_value from table(eam_empresas));
569 commit;
570
571 --Ubicación: Conducción
572 --Activos: Obra Civil
573 for c in cTuberiasPriUbicacion('CONDUCCION', 'POTABLE') loop
574
575 vUbicacion := null;
576 vUbicacion.g3e_fno := c.g3e_fno;
577 vUbicacion.g3e_fid := c.g3e_fid;
578 vUbicacion.tipo_red := vTipoRed;
579 vUbicacion.nombre_red := c.nombre_operacion;
580 vUbicacion.clase := vUbiClaCondu;
581 vUbicacion.nivel := 5;
582 vUbicacion.codigo := null;
583 vUbicacion.codigo_ubicacion := vUbiCodCondu ||
584 eam_hash(c.nombre_operacion, 999999);
585 vUbicacion.nivel_superior := vUbiPadCondu;
586 vUbicacion.descripcion := vUbiDesCondu || c.nombre_operacion;
587 vUbicacion.fecha_actualizacion := sysdate;
588
589 insert into eam_ubicacion_temp values vUbicacion;
590
591 vActivo := null;
592 vActivo.g3e_fno := c.g3e_fno;
593 vActivo.g3e_fid := c.g3e_fid;
594 vActivo.tipo_red := vUbiClaCondu;
595 vActivo.nombre_red := c.nombre_operacion;
596 vActivo.clase := vActClaObraCivil;
597 vActivo.nivel := 6;
598 vActivo.codigo_activo := null;
599 vActivo.ubicacion := vUbiCodCondu ||
600 eam_hash(c.nombre_operacion, 999999);
601 vActivo.fid_padre := c.g3e_fid;
602 vActivo.nivel_superior := null;
603 vActivo.agrupamiento := null;
604 vActivo.ordem := null;
605 vActivo.descripcion := null;
606 vActivo.fecha_actualizacion := sysdate;
607 vActivo.novedad := null;
608
609 insert into eam_activos_temp values vActivo;
610
611 end loop;
612 commit;
613
614 --Ubicación: Succión
615 --Activos: Obra Civil
616 for c in cTuberiasPriUbicacion('SUCCION', 'POTABLE') loop
617
618 vUbicacion := null;
619 vUbicacion.g3e_fno := c.g3e_fno;
620 vUbicacion.g3e_fid := c.g3e_fid;
621 vUbicacion.tipo_red := vTipoRed;
622 vUbicacion.nombre_red := c.nombre_operacion;
623 vUbicacion.clase := vUbiClaSucc;
624 vUbicacion.nivel := 5;
625 vUbicacion.codigo := null;
626 vUbicacion.codigo_ubicacion := vUbiCodSucc ||
627 eam_hash(c.nombre_operacion, 999999);
628 vUbicacion.nivel_superior := vUbiPadSucc;
629 vUbicacion.descripcion := c.nombre_operacion;
630 vUbicacion.fecha_actualizacion := sysdate;
631
632 insert into eam_ubicacion_temp values vUbicacion;
633
634 vActivo := null;
635 vActivo.g3e_fno := c.g3e_fno;
636 vActivo.g3e_fid := c.g3e_fid;
637 vActivo.tipo_red := vUbiClaSucc;
638 vActivo.nombre_red := c.nombre_operacion;
639 vActivo.clase := vActClaObraCivil;
640 vActivo.nivel := 6;
641 vActivo.codigo_activo := null;
642 vActivo.ubicacion := vUbiCodSucc ||
643 eam_hash(c.nombre_operacion, 999999);
644 vActivo.fid_padre := c.g3e_fid;
645 vActivo.nivel_superior := null;
646 vActivo.agrupamiento := null;
647 vActivo.ordem := null;
648 vActivo.descripcion := null;
649 vActivo.fecha_actualizacion := sysdate;
650 vActivo.novedad := null;
651
652 insert into eam_activos_temp values vActivo;
653
654 end loop;
655 commit;
656
657 --Ubicacion: Impulsión
658 --Activos: Obra Civil
659 for c in cTuberiasPriUbicacion('IMPULSION', 'POTABLE') loop
660
661 vUbicacion := null;
662 vUbicacion.g3e_fno := c.g3e_fno;
663 vUbicacion.g3e_fid := c.g3e_fid;
664 vUbicacion.tipo_red := vTipoRed;
665 vUbicacion.nombre_red := c.nombre_operacion;
666 vUbicacion.clase := vUbiClaImpu;
667 vUbicacion.nivel := 5;
668 vUbicacion.codigo := null;
669 vUbicacion.codigo_ubicacion := vUbiCodImp ||
670 eam_hash(c.nombre_operacion, 999999);
671 vUbicacion.nivel_superior := vUbiPadImp;
672 vUbicacion.descripcion := c.nombre_operacion;
673 vUbicacion.fecha_actualizacion := sysdate;
674
675 insert into eam_ubicacion_temp values vUbicacion;
676
677 vActivo := null;
678 vActivo.g3e_fno := c.g3e_fno;
679 vActivo.g3e_fid := c.g3e_fid;
680 vActivo.tipo_red := vUbiClaImpu;
681 vActivo.nombre_red := c.nombre_operacion;
682 vActivo.clase := vActClaObraCivil;
683 vActivo.nivel := 6;
684 vActivo.codigo_activo := null;
685 vActivo.ubicacion := vUbiCodImp ||
686 eam_hash(c.nombre_operacion, 999999);
687 vActivo.fid_padre := c.g3e_fid;
688 vActivo.nivel_superior := null;
689 vActivo.agrupamiento := null;
690 vActivo.ordem := null;
691 vActivo.descripcion := null;
692 vActivo.fecha_actualizacion := sysdate;
693 vActivo.novedad := null;
694
695 insert into eam_activos_temp values vActivo;
696
697 end loop;
698 commit;
699
700 --Ubicacion: Adducion,
701 --Activos: Obra Civil
702 for c in cTuberiasPriUbicacion('CONDUCCION', 'CRUDA') loop
703
704 vUbicacion := null;
705 vUbicacion.g3e_fno := c.g3e_fno;
706 vUbicacion.g3e_fid := c.g3e_fid;
707 vUbicacion.tipo_red := vTipoRed;
708 vUbicacion.nombre_red := c.nombre_operacion;
709 vUbicacion.clase := vUbiClaAdu;
710 vUbicacion.nivel := 5;
711 vUbicacion.codigo := null;
712 vUbicacion.codigo_ubicacion := vUbiCodAdu ||
713 eam_hash(c.nombre_operacion, 999999);
714 vUbicacion.nivel_superior := vUbiPadAdu;
715 vUbicacion.descripcion := c.nombre_operacion;
716 vUbicacion.fecha_actualizacion := sysdate;
717
718 insert into eam_ubicacion_temp values vUbicacion;
719
720 vActivo := null;
721 vActivo.g3e_fno := c.g3e_fno;
722 vActivo.g3e_fid := c.g3e_fid;
723 vActivo.tipo_red := vUbiClaAdu;
724 vActivo.nombre_red := c.nombre_operacion;
725 vActivo.clase := vActClaObraCivil;
726 vActivo.nivel := 6;
727 vActivo.codigo_activo := null;
728 vActivo.ubicacion := vUbiCodAdu ||
729 eam_hash(c.nombre_operacion, 999999);
730 vActivo.fid_padre := c.g3e_fid;
731 vActivo.nivel_superior := null;
732 vActivo.agrupamiento := null;
733 vActivo.ordem := null;
734 vActivo.descripcion := null;
735 vActivo.fecha_actualizacion := sysdate;
736 vActivo.novedad := null;
737
738 insert into eam_activos_temp values vActivo;
739
740 end loop;
741 commit;
742
743 --Ubicación: Succión Cruda
744 --Activos: Obra Civil
745 for c in cTuberiasPriUbicacion('SUCCION', 'CRUDA') loop
746
747 vUbicacion := null;
748 vUbicacion.g3e_fno := c.g3e_fno;
749 vUbicacion.g3e_fid := c.g3e_fid;
750 vUbicacion.tipo_red := vTipoRed;
751 vUbicacion.nombre_red := c.nombre_operacion;
752 vUbicacion.clase := vUbiClaSucCru;
753 vUbicacion.nivel := 5;
754 vUbicacion.codigo := null;
755 vUbicacion.codigo_ubicacion := vUbiCodSCru ||
756 eam_hash(c.nombre_operacion, 999999);
757 vUbicacion.nivel_superior := vUbiPadSecCru;
758 vUbicacion.descripcion := c.nombre_operacion;
759 vUbicacion.fecha_actualizacion := sysdate;
760
761 insert into eam_ubicacion_temp values vUbicacion;
762
763 vActivo := null;
764 vActivo.g3e_fno := c.g3e_fno;
765 vActivo.g3e_fid := c.g3e_fid;
766 vActivo.tipo_red := vUbiClaSucCru;
767 vActivo.nombre_red := c.nombre_operacion;
768 vActivo.clase := vActClaObraCivil;
769 vActivo.nivel := 6;
770 vActivo.codigo_activo := null;
771 vActivo.ubicacion := vUbiCodSCru ||
772 eam_hash(c.nombre_operacion, 999999);
773 vActivo.fid_padre := c.g3e_fid;
774 vActivo.nivel_superior := null;
775 vActivo.agrupamiento := null;
776 vActivo.ordem := null;
777 vActivo.descripcion := null;
778 vActivo.fecha_actualizacion := sysdate;
779 vActivo.novedad := null;
780
781 insert into eam_activos_temp values vActivo;
782
783 end loop;
784 commit;
785
786 --Ubicación: Impulsion Cruda
787 --Activos: Obra Civil
788 for c in cTuberiasPriUbicacion('IMPULSION', 'CRUDA') loop
789
790 vUbicacion := null;
791 vUbicacion.g3e_fno := c.g3e_fno;
792 vUbicacion.g3e_fid := c.g3e_fid;
793 vUbicacion.tipo_red := vTipoRed;
794 vUbicacion.nombre_red := c.nombre_operacion;
795 vUbicacion.clase := vUbiClaImpCru;
796 vUbicacion.nivel := 5;
797 vUbicacion.codigo := null;
798 vUbicacion.codigo_ubicacion := vUbiCodSImp ||
799 eam_hash(c.nombre_operacion, 999999);
800 vUbicacion.nivel_superior := vUbiPadImpCru;
801 vUbicacion.descripcion := c.nombre_operacion;
802 vUbicacion.fecha_actualizacion := sysdate;
803
804 insert into eam_ubicacion_temp values vUbicacion;
805
806 vActivo := null;
807 vActivo.g3e_fno := c.g3e_fno;
808 vActivo.g3e_fid := c.g3e_fid;
809 vActivo.tipo_red := vUbiClaImpCru;
810 vActivo.nombre_red := c.nombre_operacion;
811 vActivo.clase := vActClaObraCivil;
812 vActivo.nivel := 6;
813 vActivo.codigo_activo := null;
814 vActivo.ubicacion := vUbiCodSImp ||
815 eam_hash(c.nombre_operacion, 999999);
816 vActivo.fid_padre := c.g3e_fid;
817 vActivo.nivel_superior := null;
818 vActivo.agrupamiento := null;
819 vActivo.ordem := null;
820 vActivo.descripcion := null;
821 vActivo.fecha_actualizacion := sysdate;
822 vActivo.novedad := null;
823
824 insert into eam_activos_temp values vActivo;
825
826 end loop;
827 commit;
828
829 --Errores de las ubicaciones:
830 --Canal
831 insert into eam_errors
832 select vTipoRed, g3e_fid, g3e_fno, sysdate, 'Canal sin Nombre'
833 from ACANAL_AT
834 where nombre is null;
835 commit;
836
837 --Ubicación, Canal
838 for c in cCanalesUbicacion loop
839
840 vUbicacion := null;
841 vUbicacion.g3e_fno := c.g3e_fno;
842 vUbicacion.g3e_fid := c.g3e_fid;
843 vUbicacion.tipo_red := vTipoRed;
844 vUbicacion.nombre_red := c.nombre;
845 vUbicacion.clase := vUbiClaCanal;
846 vUbicacion.nivel := 5;
847 vUbicacion.codigo := null;
848 vUbicacion.codigo_ubicacion := vUbiCodCan ||
849 eam_hash(c.nombre, 999999);
850 vUbicacion.nivel_superior := vUbiPadCanal;
851 vUbicacion.descripcion := vUbiDesCan || c.nombre;
852 vUbicacion.fecha_actualizacion := sysdate;
853
854 insert into eam_ubicacion_temp values vUbicacion;
855 commit;
856 end loop;
857 commit;
858
859 --Errores de las ubicaciones:
860 --Tunel
861 insert into eam_errors
862 select vTipoRed, g3e_fid, g3e_fno, sysdate, 'Cana sin Nombre'
863 from ATUNEL_AT
864 where nombre is null;
865 commit;
866
867 --Ubicación, Tunel
868 for c in cTunelesUbicacion loop
869
870 vUbicacion := null;
871 vUbicacion.g3e_fno := c.g3e_fno;
872 vUbicacion.g3e_fid := c.g3e_fid;
873 vUbicacion.tipo_red := vTipoRed;
874 vUbicacion.nombre_red := c.nombre;
875 vUbicacion.clase := vUbiClaTunel;
876 vUbicacion.nivel := 5;
877 vUbicacion.codigo := null;
878 vUbicacion.codigo_ubicacion := vUbiCodTun ||
879 eam_hash(c.nombre, 999999);
880 vUbicacion.nivel_superior := vUbiPadTun;
881 vUbicacion.descripcion := vUbiDesTun || c.nombre;
882 vUbicacion.fecha_actualizacion := sysdate;
883
884 insert into eam_ubicacion_temp values vUbicacion;
885
886 end loop;
887 commit;
888
889 --Activos, Valvulas
890 for c in cActValvulas loop
891
892 for tub in cValvulaConTuberias(c.g3e_fid) loop
893 /*
894 if tub.rowc > 1 then
895
896 insert into eam_errors
897 values
898 (vTipoRed,
899 c.g3e_fid,
900 c.g3e_fno,
901 sysdate,
902 'La valvula esta conectada con tuberias de redes distintas');
903 commit;
904 continue;
905
906 end if;
907 */
908 if tub.nombre_operacion is null then
909
910 insert into eam_errors
911 values
912 (vTipoRed,
913 c.g3e_fid,
914 c.g3e_fno,
915 sysdate,
916 'La valvula esta conectada con una tuberias sin nombre de operacion');
917 commit;
918 continue;
919
920 end if;
921
922 begin
923 select *
924 into vUbicacion
925 from eam_ubicacion_temp
926 where nombre_red = tub.nombre_operacion;
927 exception
928 when others then
929 insert into eam_errors
930 values
931 (vTipoRed,
932 c.g3e_fid,
933 c.g3e_fno,
934 sysdate,
935 'No fue posbile buscar la tuberia de la misma red de la valvula');
936 commit;
937 end;
938
939 vActivo := null;
940 vActivo.g3e_fno := c.g3e_fno;
941 vActivo.g3e_fid := c.g3e_fid;
942 vActivo.tipo_red := vUbicacion.Clase;
943 vActivo.nombre_red := tub.nombre_operacion;
944 vActivo.clase := vActClaValvulas;
945 vActivo.nivel := 6;
946 vActivo.codigo_activo := null;
947 vActivo.ubicacion := vUbicacion.Codigo_Ubicacion;
948 vActivo.fid_padre := vUbicacion.g3e_fid;
949 vActivo.nivel_superior := null;
950 vActivo.agrupamiento := null;
951 vActivo.ordem := null;
952 vActivo.descripcion := null;
953 vActivo.fecha_actualizacion := sysdate;
954 vActivo.novedad := null;
955
956 insert into eam_activos_temp values vActivo;
957 commit;
958
959 --Se inserta solo el primer registro porque es lo cual tiene el menor codigo
960 continue;
961
962 end loop;
963
964 end loop;
965 commit;
966
967 --Activos, Segmentos
968 for ubi in (select *
969 from eam_ubicacion_temp
970 where clase in (vUbiClaAdu,
971 vUbiClaCondu,
972 vUbiClaSucc,
973 vUbiClaImpu,
974 vUbiClaSucCru,
975 vUbiClaImpCru)) loop
976
977 for c in cActTubPri(ubi.nombre_red) loop
978
979 vActivo := null;
980 vActivo.g3e_fno := c.g3e_fno;
981 vActivo.g3e_fid := c.g3e_fid;
982 vActivo.tipo_red := ubi.Clase;
983 vActivo.nombre_red := c.nombre_operacion;
984 vActivo.clase := vActClaSegmento;
985 vActivo.nivel := 6;
986 vActivo.codigo_activo := null;
987 vActivo.ubicacion := ubi.Codigo_Ubicacion;
988 vActivo.fid_padre := ubi.g3e_fid;
989 vActivo.nivel_superior := null;
990 vActivo.agrupamiento := null;
991 vActivo.ordem := null;
992 vActivo.descripcion := null;
993 vActivo.fecha_actualizacion := sysdate;
994 vActivo.novedad := null;
995
996 insert into eam_activos_temp values vActivo;
997
998 end loop;
999 end loop;
1000 commit;
1001
1002 --Activos, Canales
1003 for ubi in (select *
1004 from eam_ubicacion_temp
1005 where clase in (vUbiClaCanal)) loop
1006
1007 for c in cActCanal(ubi.nombre_red) loop
1008
1009 vActivo := null;
1010 vActivo.g3e_fno := c.g3e_fno;
1011 vActivo.g3e_fid := c.g3e_fid;
1012 vActivo.tipo_red := ubi.Clase;
1013 vActivo.nombre_red := c.nombre;
1014 vActivo.clase := vActClaSegmentoCanal;
1015 vActivo.nivel := 6;
1016 vActivo.codigo_activo := null;
1017 vActivo.ubicacion := ubi.Codigo_Ubicacion;
1018 vActivo.fid_padre := ubi.g3e_fid;
1019 vActivo.nivel_superior := null;
1020 vActivo.agrupamiento := null;
1021 vActivo.ordem := null;
1022 vActivo.descripcion := null;
1023 vActivo.fecha_actualizacion := sysdate;
1024 vActivo.novedad := null;
1025
1026 insert into eam_activos_temp values vActivo;
1027 commit;
1028
1029 end loop;
1030 end loop;
1031 commit;
1032
1033 --Activos, Tuneles
1034 for ubi in (select *
1035 from eam_ubicacion_temp
1036 where clase in (vUbiClaTunel)) loop
1037
1038 for c in cActTunel(ubi.nombre_red) loop
1039
1040 vActivo := null;
1041 vActivo.g3e_fno := c.g3e_fno;
1042 vActivo.g3e_fid := c.g3e_fid;
1043 vActivo.tipo_red := ubi.Clase;
1044 vActivo.nombre_red := c.nombre;
1045 vActivo.clase := vActClaSegmentoTunel;
1046 vActivo.nivel := 6;
1047 vActivo.codigo_activo := null;
1048 vActivo.ubicacion := ubi.Codigo_Ubicacion;
1049 vActivo.fid_padre := ubi.g3e_fid;
1050 vActivo.nivel_superior := null;
1051 vActivo.agrupamiento := null;
1052 vActivo.ordem := null;
1053 vActivo.descripcion := null;
1054 vActivo.fecha_actualizacion := sysdate;
1055 vActivo.novedad := null;
1056
1057 insert into eam_activos_temp values vActivo;
1058 commit;
1059 end loop;
1060 end loop;
1061 commit;
1062
1063 --Ajustar elemntos duplicadors por coneccixon doble
1064 --Elegir el que tiene menor ubicacion
1065
1066 for ubiDup in (select g3e_fid, clase, max(ubicacion) ubicacion
1067 from eam_activos_temp
1068 group by g3e_fid, clase
1069 having count(1) > 1) loop
1070
1071 delete from eam_activos_temp
1072 where g3e_fid = ubiDup.g3e_fid
1073 and clase = ubiDup.clase
1074 and ubicacion = ubiDup.Ubicacion;
1075 commit;
1076 end loop;
1077
1078 end EAM_TAXONOMIA_PRIMARIA;
1079
1080 procedure EAM_TAXONOMIA_SECUNDARIA is
1081
1082 --Variables
1083 vUbicacion eam_ubicacion_temp%rowtype;
1084 vActivo eam_activos_temp%rowtype;
1085 vError eam_errors%rowtype;
1086 vGeom sdo_geometry;
1087 vCount number;
1088
1089 --Configuraciones
1090 vUbiSecCircuitoDesc VARCHAR2(100);
1091 vUbiSecSubCIrcuitoDesc VARCHAR2(100);
1092 vUbiSecERPCod VARCHAR2(100);
1093 vUbiSecERPDesc VARCHAR2(100);
1094 vUbiSecTuberiasCod VARCHAR2(100);
1095 vUbiSecTuberiasDesc VARCHAR2(100);
1096 vUbiSecValvulasCod VARCHAR2(100);
1097 vUbiSecValvulasDesc VARCHAR2(100);
1098 vUbiSecHidranteCod VARCHAR2(100);
1099 vUbiSecHidranteDesc VARCHAR2(100);
1100 vUbiSecPuntosCod VARCHAR2(100);
1101 vUbiSecPuntosDesc VARCHAR2(100);
1102 vUbiSecCircuitoClase VARCHAR2(100);
1103 vUbiSecSubCircuitoClase VARCHAR2(100);
1104 vUbiSecHidranteClase VARCHAR2(100);
1105 vUbiSecValvulasClase VARCHAR2(100);
1106 vUbiSecPuntosClase VARCHAR2(100);
1107 vUbiSecTuberiasClase VARCHAR2(100);
1108 vUbiSecERPClase VARCHAR2(100);
1109 vUbiSecCircuitoSuperior VARCHAR2(100);
1110 vActSecHidranteClase VARCHAR2(100);
1111 vActSecObraCivilClase VARCHAR2(100);
1112 vActSecValvulaClase VARCHAR2(100);
1113 vActSecPuntoClase VARCHAR2(100);
1114 vActSecERPClase VARCHAR2(100);
1115 vActSecTuberiaClase VARCHAR2(100);
1116
1117 --Tipo Red
1118 vTipoRed varchar2(50) := 'CIRCUITO';
1119
1120 --Ubicacion, Nivel 3
1121 --Circuitos
1122 cursor cUbiCircuitos is
1123 select a.g3e_fid, a.g3e_fno, a.circuito, a.nombre, a.codigo_circuito
1124 from acircuit_at a
1125 inner join ccomun c
1126 on c.g3e_fid = a.g3e_fid
1127 and c.g3e_fno = a.g3e_fno
1128 where a.tipo_area = 'CIRCUITO'
1129 and c.empresa in (select column_value from table(eam_empresas))
1130 and a.codigo_circuito is not null
1131 and es_numerico(a.codigo_circuito) > 0;
1132
1133 --Ubicacion, Nivel 3
1134 --Circuitos Errores
1135 cursor cUbiCircuitosErr is
1136 select a.g3e_fid, a.g3e_fno, a.circuito, a.nombre, a.codigo_circuito
1137 from acircuit_at a
1138 inner join ccomun c
1139 on c.g3e_fid = a.g3e_fid
1140 and c.g3e_fno = a.g3e_fno
1141 where a.tipo_area = 'CIRCUITO'
1142 and c.empresa in (select column_value from table(eam_empresas))
1143 and (a.codigo_circuito is null or
1144 es_numerico(a.codigo_circuito) = 0);
1145
1146 --Ubicacion, Nivel 4 y Nivel 5
1147 --SubCircuitos
1148 --ERPS
1149 --Tuberias
1150 --Valvulas
1151 --Hidrantes
1152 --Puntos de Muestro
1153 cursor cUbiSubCircuitos is
1154 select a.g3e_fid,
1155 a.g3e_fno,
1156 a.circuito,
1157 a.nombre,
1158 a.codigo_circuito,
1159 a.codigo_subcircuito,
1160 a.subcircuito_padre
1161 from acircuit_at a
1162 inner join ccomun c
1163 on c.g3e_fid = a.g3e_fid
1164 and c.g3e_fno = a.g3e_fno
1165 where a.tipo_area = 'SUBCIRCUITO'
1166 and c.empresa in (select column_value from table(eam_empresas))
1167 and a.codigo_subcircuito is not null
1168 and es_numerico(a.codigo_subcircuito) > 0
1169 and a.codigo_subcircuito not in
1170 (select a.codigo_subcircuito
1171 from acircuit_at a
1172 inner join ccomun c
1173 on c.g3e_fid = a.g3e_fid
1174 and c.g3e_fno = a.g3e_fno
1175 where a.tipo_area = 'SUBCIRCUITO'
1176 and c.empresa in
1177 (select column_value from table(eam_empresas))
1178 and a.codigo_subcircuito is not null
1179 and es_numerico(a.codigo_subcircuito) > 0
1180 group by a.codigo_subcircuito
1181 having count(1) > 1)
1182 and a.g3e_fid not in
1183 (select a.g3e_fid
1184 from acircuit_at a
1185 inner join ccomun c
1186 on c.g3e_fid = a.g3e_fid
1187 and c.g3e_fno = a.g3e_fno
1188 where a.tipo_area = 'SUBCIRCUITO'
1189 and a.codigo_subcircuito is not null
1190 and a.codigo_subcircuito = a.codigo_circuito
1191 and c.empresa in
1192 (select column_value from table(eam_empresas))
1193 and es_numerico(a.codigo_subcircuito) > 0);
1194
1195 --Ubicacion, Nivel 4
1196 --Errores
1197 cursor cUbiSubCircuitosErr is
1198 select a.g3e_fid,
1199 a.g3e_fno,
1200 a.circuito,
1201 a.nombre,
1202 a.codigo_circuito,
1203 a.codigo_subcircuito,
1204 a.subcircuito_padre
1205 from acircuit_at a
1206 inner join ccomun c
1207 on c.g3e_fid = a.g3e_fid
1208 and c.g3e_fno = a.g3e_fno
1209 where a.tipo_area = 'SUBCIRCUITO'
1210 and c.empresa in (select column_value from table(eam_empresas))
1211 and (a.codigo_subcircuito is not null or
1212 es_numerico(a.codigo_subcircuito) > 0);
1213
1214 --Ubicacion, Nivel 4
1215 --Errores
1216 cursor cUbiSubCircuitosErr2 is
1217 select a.g3e_fid,
1218 a.g3e_fno,
1219 a.circuito,
1220 a.nombre,
1221 a.codigo_circuito,
1222 a.codigo_subcircuito,
1223 a.subcircuito_padre
1224 from acircuit_at a
1225 inner join ccomun c
1226 on c.g3e_fid = a.g3e_fid
1227 and c.g3e_fno = a.g3e_fno
1228 where a.tipo_area = 'SUBCIRCUITO'
1229 and c.empresa in (select column_value from table(eam_empresas))
1230 and a.codigo_subcircuito is not null
1231 and es_numerico(a.codigo_subcircuito) > 0
1232 and a.codigo_subcircuito in
1233 (select a.codigo_subcircuito
1234 from acircuit_at a
1235 inner join ccomun c
1236 on c.g3e_fid = a.g3e_fid
1237 and c.g3e_fno = a.g3e_fno
1238 where a.tipo_area = 'SUBCIRCUITO'
1239 and c.empresa in
1240 (select column_value from table(eam_empresas))
1241 and a.codigo_subcircuito is not null
1242 and es_numerico(a.codigo_subcircuito) > 0
1243 group by a.codigo_subcircuito
1244 having count(1) > 1);
1245
1246 cursor cUbiSubCircuitosErr3 is
1247 select a.g3e_fid,
1248 a.g3e_fno,
1249 a.circuito,
1250 a.nombre,
1251 a.codigo_circuito,
1252 a.codigo_subcircuito,
1253 a.subcircuito_padre
1254 from acircuit_at a
1255 inner join ccomun c
1256 on c.g3e_fid = a.g3e_fid
1257 and c.g3e_fno = a.g3e_fno
1258 where a.tipo_area = 'SUBCIRCUITO'
1259 and a.codigo_subcircuito is not null
1260 and a.codigo_subcircuito = a.codigo_circuito
1261 and c.empresa in (select column_value from table(eam_empresas))
1262 and es_numerico(a.codigo_subcircuito) > 0;
1263
1264 --Activos, Nivel 6
1265 --Hidrantes
1266 cursor cActHidrantes(pSubCircuito SDO_GEOMETRY) is
1267 select g.g3e_fid, g.g3e_fno, g.g3e_geometry
1268 from ahidrant_pt g
1269 inner join ahidrant_at a
1270 on a.g3e_fid = g.g3e_fid
1271 and a.g3e_fno = g.g3e_fno
1272 inner join ccomun c
1273 on c.g3e_fid = g.g3e_fid
1274 and c.g3e_fno = g.g3e_fno
1275 where c.empresa in (select column_value from table(eam_empresas))
1276 and sdo_relate(g.g3e_geometry,
1277 pSubCircuito,
1278 'mask=INSIDE+CONVERDBY') = 'TRUE';
1279
1280 --Activos, Nivel 6
1281 --Valvulas Secundaria
1282 cursor cActValvulasSec(pSubCircuito SDO_GEOMETRY) is
1283 select g.g3e_fid, g.g3e_fno, g.g3e_geometry
1284 from aval_scn_pt g
1285 inner join aval_scn_at a
1286 on a.g3e_fid = g.g3e_fid
1287 and a.g3e_fno = g.g3e_fno
1288 inner join ccomun c
1289 on c.g3e_fid = g.g3e_fid
1290 and c.g3e_fno = g.g3e_fno
1291 where c.empresa in (select column_value from table(eam_empresas))
1292 and sdo_relate(g.g3e_geometry,
1293 pSubCircuito,
1294 'mask=INSIDE+CONVERDBY') = 'TRUE';
1295
1296 --Activos, Nivel 6
1297 --Puntos Muestro
1298 cursor cActPuntos(pSubCircuito SDO_GEOMETRY) is
1299 select g.g3e_fid, g.g3e_fno, g.g3e_geometry
1300 from amedidor_pt g
1301 inner join amedidor_at a
1302 on a.g3e_fid = g.g3e_fid
1303 and a.g3e_fno = g.g3e_fno
1304 inner join ccomun c
1305 on c.g3e_fid = g.g3e_fid
1306 and c.g3e_fno = g.g3e_fno
1307 where c.empresa in (select column_value from table(eam_empresas))
1308 and a.tipo_medidor = 'CALIDAD DE AGUA POTABLE Y PRESION'
1309 and sdo_relate(g.g3e_geometry,
1310 pSubCircuito,
1311 'mask=INSIDE+CONVERDBY') = 'TRUE';
1312
1313 --Activos, Nivel 6
1314 --ERP/SCN
1315 cursor cActERP(pSubCircuito SDO_GEOMETRY) is
1316 select g.g3e_fid, g.g3e_fno, g.g3e_geometry
1317 from asis_cnt_pt g
1318 inner join asis_cnt_at a
1319 on a.g3e_fid = g.g3e_fid
1320 and a.g3e_fno = g.g3e_fno
1321 inner join ccomun c
1322 on c.g3e_fid = g.g3e_fid
1323 and c.g3e_fno = g.g3e_fno
1324 where c.empresa in (select column_value from table(eam_empresas))
1325 and sdo_relate(g.g3e_geometry,
1326 pSubCircuito,
1327 'mask=INSIDE+CONVERDBY') = 'TRUE';
1328
1329 --Activos, Nivel 6
1330 --Obra Civil
1331 cursor cActObraCivil(pSubCircuito SDO_GEOMETRY) is
1332 select g.g3e_fid, g.g3e_fno, g.g3e_geometry, a.codigo_sistema_cnt
1333 from asis_cnt_pt g
1334 inner join asis_cnt_at a
1335 on a.g3e_fid = g.g3e_fid
1336 and a.g3e_fno = g.g3e_fno
1337 inner join ccomun c
1338 on c.g3e_fid = g.g3e_fid
1339 and c.g3e_fno = g.g3e_fno
1340 where c.empresa in (select column_value from table(eam_empresas))
1341 and sdo_relate(g.g3e_geometry,
1342 pSubCircuito,
1343 'mask=INSIDE+CONVERDBY') = 'TRUE'
1344 order by a.codigo_sistema_cnt;
1345
1346 --Activos, Nivel 6
1347 --Tuberia Secundaria
1348 cursor cActTuberiaSecundaria(pSubCircuito SDO_GEOMETRY) is
1349 select g.g3e_fid, g.g3e_fno, g.g3e_geometry
1350 from atub_scn_ln g
1351 inner join atub_scn_at a
1352 on a.g3e_fid = g.g3e_fid
1353 and a.g3e_fno = g.g3e_fno
1354 inner join ccomun c
1355 on c.g3e_fid = g.g3e_fid
1356 and c.g3e_fno = g.g3e_fno
1357 where c.empresa in (select column_value from table(eam_empresas))
1358 and sdo_relate(g.g3e_geometry,
1359 pSubCircuito,
1360 'mask=INSIDE+CONVERDBY+TOUCHES') = 'TRUE';
1361
1362 --Activos Duplicados
1363 cursor cActDup is
1364 select g3e_fid, clase
1365 from eam_activos_temp
1366 group by g3e_fid, clase
1367 having count(1) > 1;
1368
1369 --Busca los Circuitos (y su Area) Asisgandos a un elemento
1370 cursor cAreaCircuitos(pFidHijo NUMBER) is
1371 select g3e_fid, sdo_geom.sdo_area(g3e_geometry, 0.005)
1372 from acircuit_ar
1373 where g3e_fid in (select fid_padre
1374 from eam_activos_temp
1375 where g3e_fid = pFidHijo)
1376 order by 2 asc;
1377
1378 --Busca los circuitos que contiene el primer punto de la linea
1379 cursor cCirTubPuntoInicial(pGeomTub SDO_GEOMETRY) is
1380 select g.g3e_fid, sdo_geom.sdo_area(g.g3e_geometry, 0.005)
1381 from acircuit_ar g
1382 where sdo_relate(g.g3e_geometry,
1383 PuntoInicialLinea(pGeomTub),
1384 'mask=CONTAINS+COVERS') = 'TRUE'
1385 order by 2 asc;
1386
1387 begin
1388 --Carga Configuración
1389 select valor
1390 into vUbiSecCircuitoDesc
1391 from eam_config
1392 where descripcion = 'UbiSecCircuitoDesc';
1393 select valor
1394 into vUbiSecSubCIrcuitoDesc
1395 from eam_config
1396 where descripcion = 'UbiSecSubCIrcuitoDesc';
1397 select valor
1398 into vUbiSecERPCod
1399 from eam_config
1400 where descripcion = 'UbiSecERPCod';
1401 select valor
1402 into vUbiSecERPDesc
1403 from eam_config
1404 where descripcion = 'UbiSecERPDesc';
1405 select valor
1406 into vUbiSecTuberiasCod
1407 from eam_config
1408 where descripcion = 'UbiSecTuberiasCod';
1409 select valor
1410 into vUbiSecTuberiasDesc
1411 from eam_config
1412 where descripcion = 'UbiSecTuberiasDesc';
1413 select valor
1414 into vUbiSecValvulasCod
1415 from eam_config
1416 where descripcion = 'UbiSecValvulasCod';
1417 select valor
1418 into vUbiSecValvulasDesc
1419 from eam_config
1420 where descripcion = 'UbiSecValvulasDesc';
1421 select valor
1422 into vUbiSecHidranteCod
1423 from eam_config
1424 where descripcion = 'UbiSecHidranteCod';
1425 select valor
1426 into vUbiSecHidranteDesc
1427 from eam_config
1428 where descripcion = 'UbiSecHidranteDesc';
1429 select valor
1430 into vUbiSecPuntosCod
1431 from eam_config
1432 where descripcion = 'UbiSecPuntosCod';
1433 select valor
1434 into vUbiSecPuntosDesc
1435 from eam_config
1436 where descripcion = 'UbiSecPuntosDesc';
1437 select valor
1438 into vUbiSecCircuitoClase
1439 from eam_config
1440 where descripcion = 'UbiSecCircuitoClase';
1441 select valor
1442 into vUbiSecSubCircuitoClase
1443 from eam_config
1444 where descripcion = 'UbiSecSubCircuitoClase';
1445 select valor
1446 into vUbiSecHidranteClase
1447 from eam_config
1448 where descripcion = 'UbiSecHidranteClase';
1449 select valor
1450 into vUbiSecValvulasClase
1451 from eam_config
1452 where descripcion = 'UbiSecValvulasClase';
1453 select valor
1454 into vUbiSecPuntosClase
1455 from eam_config
1456 where descripcion = 'UbiSecPuntosClase';
1457 select valor
1458 into vUbiSecTuberiasClase
1459 from eam_config
1460 where descripcion = 'UbiSecTuberiasClase';
1461 select valor
1462 into vUbiSecERPClase
1463 from eam_config
1464 where descripcion = 'UbiSecERPClase';
1465 select valor
1466 into vUbiSecCircuitoSuperior
1467 from eam_config
1468 where descripcion = 'UbiSecCircuitoSuperior';
1469 select valor
1470 into vActSecHidranteClase
1471 from eam_config
1472 where descripcion = 'ActSecHidranteClase';
1473 select valor
1474 into vActSecObraCivilClase
1475 from eam_config
1476 where descripcion = 'ActSecObraCivilClase';
1477 select valor
1478 into vActSecValvulaClase
1479 from eam_config
1480 where descripcion = 'ActSecValvulaClase';
1481 select valor
1482 into vActSecPuntoClase
1483 from eam_config
1484 where descripcion = 'ActSecPuntoClase';
1485 select valor
1486 into vActSecERPClase
1487 from eam_config
1488 where descripcion = 'ActSecERPClase';
1489 select valor
1490 into vActSecTuberiaClase
1491 from eam_config
1492 where descripcion = 'ActSecTuberiaClase';
1493
1494 --Ubicacion, Nivel 3
1495 --Circuitos
1496 for c in cUbiCircuitos loop
1497 vUbicacion := null;
1498 vUbicacion.g3e_fno := c.g3e_fno;
1499 vUbicacion.g3e_fid := c.g3e_fid;
1500 vUbicacion.tipo_red := vTipoRed;
1501 vUbicacion.nombre_red := c.circuito;
1502 vUbicacion.clase := vUbiSecCircuitoClase;
1503 vUbicacion.codigo_ubicacion := c.codigo_circuito;
1504 vUbicacion.nivel := 3;
1505 vUbicacion.nivel_superior := vUbiSecCircuitoSuperior;
1506 vUbicacion.descripcion := vUbiSecCircuitoDesc || c.circuito;
1507 vUbicacion.fecha_actualizacion := sysdate;
1508
1509 insert into EAM_UBICACION_TEMP values vUbicacion;
1510 commit;
1511 end loop;
1512
1513 --Ubicacion, Nivel 3
1514 --Circuitos Errores
1515 for c in cUbiCircuitosErr loop
1516 vError := null;
1517 vError.g3e_fno := c.g3e_fno;
1518 vError.g3e_fid := c.g3e_fid;
1519 vError.fecha := sysdate;
1520 vError.circuito := 'CIRCUITO SECUNDARIA';
1521 vError.descripcion := 'Circuito con código malo';
1522
1523 insert into EAM_ERRORS values vError;
1524 commit;
1525 end loop;
1526
1527 --Ubicacion, Nivel 4 y Nivel 5
1528 --SubCircuitos
1529 --ERPS
1530 --Tuberias
1531 --Valvulas
1532 --Hidrantes
1533 --Puntos de Muestro
1534 for c in cUbiSubCircuitos loop
1535 --SubCircuitos
1536 vUbicacion := null;
1537 vUbicacion.g3e_fno := c.g3e_fno;
1538 vUbicacion.g3e_fid := c.g3e_fid;
1539 vUbicacion.tipo_red := vTipoRed;
1540 vUbicacion.nombre_red := c.circuito;
1541 vUbicacion.clase := vUbiSecSubCircuitoClase;
1542 vUbicacion.codigo_ubicacion := c.codigo_subcircuito;
1543 vUbicacion.nivel := 4;
1544 vUbicacion.nivel_superior := c.codigo_circuito;
1545 vUbicacion.descripcion := vUbiSecSubCircuitoDesc ||
1546 c.codigo_subcircuito || ' ' ||
1547 c.circuito;
1548 vUbicacion.fecha_actualizacion := sysdate;
1549
1550 insert into EAM_UBICACION_TEMP values vUbicacion;
1551 commit;
1552
1553 --ERPS
1554 vUbicacion := null;
1555 vUbicacion.g3e_fno := c.g3e_fno;
1556 vUbicacion.g3e_fid := c.g3e_fid;
1557 vUbicacion.tipo_red := vTipoRed;
1558 vUbicacion.nombre_red := c.circuito;
1559 vUbicacion.clase := vUbiSecERPClase;
1560 vUbicacion.codigo_ubicacion := vUbiSecERPCod ||
1561 c.codigo_subcircuito;
1562 vUbicacion.nivel := 5;
1563 vUbicacion.nivel_superior := c.codigo_subcircuito;
1564 vUbicacion.descripcion := vUbiSecERPDesc || ' ' ||
1565 vUbiSecSubCircuitoDesc ||
1566 c.codigo_subcircuito || ' ' ||
1567 c.circuito;
1568 vUbicacion.fecha_actualizacion := sysdate;
1569
1570 insert into EAM_UBICACION_TEMP values vUbicacion;
1571 commit;
1572
1573 --Hidrantes
1574 vUbicacion := null;
1575 vUbicacion.g3e_fno := c.g3e_fno;
1576 vUbicacion.g3e_fid := c.g3e_fid;
1577 vUbicacion.tipo_red := vTipoRed;
1578 vUbicacion.nombre_red := c.circuito;
1579 vUbicacion.clase := vUbiSecHidranteClase;
1580 vUbicacion.codigo_ubicacion := vUbiSecHidranteCod ||
1581 c.codigo_subcircuito;
1582 vUbicacion.nivel := 5;
1583 vUbicacion.nivel_superior := c.codigo_subcircuito;
1584 vUbicacion.descripcion := vUbiSecHidranteDesc || ' ' ||
1585 vUbiSecSubCircuitoDesc ||
1586 c.codigo_subcircuito || ' ' ||
1587 c.circuito;
1588 vUbicacion.fecha_actualizacion := sysdate;
1589
1590 insert into EAM_UBICACION_TEMP values vUbicacion;
1591 commit;
1592
1593 --Valvulas
1594 vUbicacion := null;
1595 vUbicacion.g3e_fno := c.g3e_fno;
1596 vUbicacion.g3e_fid := c.g3e_fid;
1597 vUbicacion.tipo_red := vTipoRed;
1598 vUbicacion.nombre_red := c.circuito;
1599 vUbicacion.clase := vUbiSecValvulasClase;
1600 vUbicacion.codigo_ubicacion := vUbiSecValvulasCod ||
1601 c.codigo_subcircuito;
1602 vUbicacion.nivel := 5;
1603 vUbicacion.nivel_superior := c.codigo_subcircuito;
1604 vUbicacion.descripcion := vUbiSecValvulasDesc || ' ' ||
1605 vUbiSecSubCircuitoDesc ||
1606 c.codigo_subcircuito || ' ' ||
1607 c.circuito;
1608 vUbicacion.fecha_actualizacion := sysdate;
1609
1610 insert into EAM_UBICACION_TEMP values vUbicacion;
1611 commit;
1612
1613 --Puntos Muestro
1614 vUbicacion := null;
1615 vUbicacion.g3e_fno := c.g3e_fno;
1616 vUbicacion.g3e_fid := c.g3e_fid;
1617 vUbicacion.tipo_red := vTipoRed;
1618 vUbicacion.nombre_red := c.circuito;
1619 vUbicacion.clase := vUbiSecPuntosClase;
1620 vUbicacion.codigo_ubicacion := vUbiSecPuntosCod ||
1621 c.codigo_subcircuito;
1622 vUbicacion.nivel := 5;
1623 vUbicacion.nivel_superior := c.codigo_subcircuito;
1624 vUbicacion.descripcion := vUbiSecPuntosDesc || ' ' ||
1625 vUbiSecSubCircuitoDesc ||
1626 c.codigo_subcircuito || ' ' ||
1627 c.circuito;
1628 vUbicacion.fecha_actualizacion := sysdate;
1629
1630 insert into EAM_UBICACION_TEMP values vUbicacion;
1631 commit;
1632
1633 --Tuberias
1634 vUbicacion := null;
1635 vUbicacion.g3e_fno := c.g3e_fno;
1636 vUbicacion.g3e_fid := c.g3e_fid;
1637 vUbicacion.tipo_red := vTipoRed;
1638 vUbicacion.nombre_red := c.circuito;
1639 vUbicacion.clase := vUbiSecTuberiasClase;
1640 vUbicacion.codigo_ubicacion := vUbiSecTuberiasCod ||
1641 c.codigo_subcircuito;
1642 vUbicacion.nivel := 5;
1643 vUbicacion.nivel_superior := c.codigo_subcircuito;
1644 vUbicacion.descripcion := vUbiSecTuberiasDesc || ' ' ||
1645 vUbiSecSubCircuitoDesc ||
1646 c.codigo_subcircuito || ' ' ||
1647 c.circuito;
1648 vUbicacion.fecha_actualizacion := sysdate;
1649
1650 insert into EAM_UBICACION_TEMP values vUbicacion;
1651 commit;
1652
1653 end loop;
1654
1655 --Ubicacion, Nivel 4
1656 --SubCircuitos Errores
1657 for c in cUbiSubCircuitosErr loop
1658 vError := null;
1659 vError.g3e_fno := c.g3e_fno;
1660 vError.g3e_fid := c.g3e_fid;
1661 vError.circuito := 'SUBCIRCUITO SECUNDARIA';
1662 vError.fecha := sysdate;
1663 vError.descripcion := 'SubCircuito con código malo';
1664
1665 insert into EAM_ERRORS values vError;
1666 commit;
1667 end loop;
1668
1669 for c in cUbiSubCircuitosErr2 loop
1670
1671 vError := null;
1672 vError.g3e_fno := c.g3e_fno;
1673 vError.g3e_fid := c.g3e_fid;
1674 vError.fecha := sysdate;
1675 vError.circuito := 'SUBCIRCUITO SECUNDARIA';
1676 vError.descripcion := 'Mismo codigo de subcircuito para FIDs distintos';
1677
1678 insert into EAM_ERRORS values vError;
1679 commit;
1680 end loop;
1681
1682 for c in cUbiSubCircuitosErr3 loop
1683
1684 vError := null;
1685 vError.g3e_fno := c.g3e_fno;
1686 vError.g3e_fid := c.g3e_fid;
1687 vError.fecha := sysdate;
1688 vError.circuito := 'SUBCIRCUITO SECUNDARIA';
1689 vError.descripcion := 'Mismo codigo del SubCircuito y del Circuito';
1690
1691 insert into EAM_ERRORS values vError;
1692 commit;
1693 end loop;
1694
1695 --Activos, NÃvel 6
1696 for c in (select * from eam_ubicacion_temp where clase = 'SUBCIRCUITO') loop
1697
1698 begin
1699 select g3e_geometry
1700 into vGeom
1701 from acircuit_ar
1702 where g3e_fid = c.g3e_fid;
1703 exception
1704 when others then
1705 continue;
1706 end;
1707
1708 --Hidrantes
1709 for hid in cActHidrantes(vGeom) loop
1710 vActivo := null;
1711
1712 vActivo.g3e_fno := hid.g3e_fno;
1713 vActivo.g3e_fid := hid.g3e_fid;
1714 vActivo.tipo_red := vTipoRed;
1715 vActivo.nivel := 6;
1716 vActivo.fid_padre := c.g3e_fid;
1717 vActivo.nivel_superior := null;
1718 vActivo.nombre_red := c.nombre_red;
1719 vActivo.clase := vActSecHidranteClase;
1720 vActivo.ubicacion := vUbiSecHidranteCod ||
1721 c.codigo_ubicacion;
1722 vActivo.fecha_actualizacion := sysdate;
1723
1724 insert into eam_activos_temp values vActivo;
1725 commit;
1726
1727 end loop;
1728
1729 --Valvulas
1730 for val in cActValvulasSec(vGeom) loop
1731 vActivo := null;
1732
1733 vActivo.g3e_fno := val.g3e_fno;
1734 vActivo.g3e_fid := val.g3e_fid;
1735 vActivo.tipo_red := vTipoRed;
1736 vActivo.nivel := 6;
1737 vActivo.fid_padre := c.g3e_fid;
1738 vActivo.nivel_superior := null;
1739 vActivo.nombre_red := c.nombre_red;
1740 vActivo.clase := vActSecValvulaClase;
1741 vActivo.ubicacion := vUbiSecValvulasCod ||
1742 c.codigo_ubicacion;
1743 vActivo.fecha_actualizacion := sysdate;
1744
1745 insert into eam_activos_temp values vActivo;
1746 commit;
1747
1748 end loop;
1749
1750 --Punto de Muetro
1751 for pnt in cActPuntos(vGeom) loop
1752 vActivo := null;
1753
1754 vActivo.g3e_fno := pnt.g3e_fno;
1755 vActivo.g3e_fid := pnt.g3e_fid;
1756 vActivo.tipo_red := vTipoRed;
1757 vActivo.nivel := 6;
1758 vActivo.fid_padre := c.g3e_fid;
1759 vActivo.nombre_red := c.nombre_red;
1760 vActivo.nivel_superior := null;
1761 vActivo.clase := vActSecPuntoClase;
1762 vActivo.ubicacion := vUbiSecPuntosCod ||
1763 c.codigo_ubicacion;
1764 vActivo.fecha_actualizacion := sysdate;
1765
1766 insert into eam_activos_temp values vActivo;
1767 commit;
1768
1769 end loop;
1770
1771 --ERPS/SCN
1772 for erp in cActERP(vGeom) loop
1773 vActivo := null;
1774
1775 vActivo.g3e_fno := erp.g3e_fno;
1776 vActivo.g3e_fid := erp.g3e_fid;
1777 vActivo.tipo_red := vTipoRed;
1778 vActivo.nivel := 6;
1779 vActivo.fid_padre := c.g3e_fid;
1780 vActivo.nivel_superior := null;
1781 vActivo.nombre_red := c.nombre_red;
1782 vActivo.clase := vActSecERPClase;
1783 vActivo.ubicacion := vUbiSecERPCod || c.codigo_ubicacion;
1784 vActivo.fecha_actualizacion := sysdate;
1785
1786 insert into eam_activos_temp values vActivo;
1787 commit;
1788
1789 end loop;
1790
1791 --Obra Civil
1792 for obr in cActObraCivil(vGeom) loop
1793
1794 if obr.codigo_sistema_cnt is null or
1795 length(obr.codigo_sistema_cnt) < 5 or
1796 instr(obr.codigo_sistema_cnt, ' ') > 0 or
1797 es_numerico(substr(obr.codigo_sistema_cnt, 1, 1)) = 0 then
1798
1799 vError := null;
1800 vError.g3e_fno := obr.g3e_fno;
1801 vError.g3e_fid := obr.g3e_fid;
1802 vError.circuito := c.nombre_red;
1803 vError.fecha := sysdate;
1804 vError.descripcion := 'SCN con Codigo Sistema CNT malo';
1805
1806 insert into EAM_ERRORS values vError;
1807 commit;
1808 end if;
1809
1810 if length(obr.codigo_sistema_cnt) = 5 then
1811
1812 vActivo := null;
1813
1814 vActivo.g3e_fno := obr.g3e_fno;
1815 vActivo.g3e_fid := obr.g3e_fid;
1816 vActivo.tipo_red := vTipoRed;
1817 vActivo.nivel := 6;
1818 vActivo.fid_padre := c.g3e_fid;
1819 vActivo.nivel_superior := null;
1820 vActivo.nombre_red := c.nombre_red;
1821 vActivo.clase := vActSecObraCivilClase;
1822 vActivo.ubicacion := vUbiSecERPCod ||
1823 c.codigo_ubicacion;
1824 vActivo.fecha_actualizacion := sysdate;
1825 elsif substr(obr.codigo_sistema_cnt,
1826 length(obr.codigo_sistema_cnt),
1827 1) in ('1', 'A') then
1828
1829 vActivo := null;
1830
1831 vActivo.g3e_fno := obr.g3e_fno;
1832 vActivo.g3e_fid := obr.g3e_fid;
1833 vActivo.tipo_red := vTipoRed;
1834 vActivo.nivel := 6;
1835 vActivo.fid_padre := c.g3e_fid;
1836 vActivo.nivel_superior := null;
1837 vActivo.nombre_red := c.nombre_red;
1838 vActivo.clase := vActSecObraCivilClase;
1839 vActivo.ubicacion := vUbiSecERPCod ||
1840 c.codigo_ubicacion;
1841 vActivo.fecha_actualizacion := sysdate;
1842 else
1843 continue;
1844 end if;
1845
1846 insert into eam_activos_temp values vActivo;
1847 commit;
1848
1849 end loop;
1850
1851 --Tuberia Secundaria
1852 for tub in cActTuberiaSecundaria(vGeom) loop
1853 vActivo := null;
1854
1855 vActivo.g3e_fno := tub.g3e_fno;
1856 vActivo.g3e_fid := tub.g3e_fid;
1857 vActivo.tipo_red := vTipoRed;
1858 vActivo.nivel := 6;
1859 vActivo.fid_padre := c.g3e_fid;
1860 vActivo.nivel_superior := null;
1861 vActivo.nombre_red := c.nombre_red;
1862 vActivo.clase := vActSecTuberiaClase;
1863 vActivo.ubicacion := vUbiSecTuberiasCod ||
1864 c.codigo_ubicacion;
1865 vActivo.fecha_actualizacion := sysdate;
1866
1867 insert into eam_activos_temp values vActivo;
1868 commit;
1869
1870 end loop;
1871
1872 end loop;
1873
1874 --Ajustar los activos duplicados
1875 for dup in cActDup loop
1876
1877 if dup.clase != vActSecTuberiaClase then
1878
1879 for cir in cAreaCircuitos(dup.g3e_fid) loop
1880 --El primer resultado es el subcircuito con menor area
1881 delete from eam_activos_temp
1882 where g3e_fid = dup.g3e_fid
1883 and fid_padre != cir.g3e_fid;
1884 commit;
1885 exit;
1886 end loop;
1887
1888 else
1889
1890 select g3e_geometry
1891 into vGeom
1892 from atub_scn_ln
1893 where g3e_fid = dup.g3e_fid;
1894
1895 vCount := 0;
1896 for cir in cCirTubPuntoInicial(vGeom) loop
1897 --El primer resultado es el subcircuito con menor area
1898 vCount := vCount + 1;
1899 delete from eam_activos_temp
1900 where g3e_fid = dup.g3e_fid
1901 and fid_padre != cir.g3e_fid;
1902 commit;
1903 exit;
1904 end loop;
1905
1906 if vCount = 0 then
1907 --El punto inicial de la linea no esta dentro de ninguna area
1908 delete from eam_activos_temp where g3e_fid = dup.g3e_fid;
1909 commit;
1910
1911 vError := null;
1912 vError.g3e_fno := 11800;
1913 vError.g3e_fid := dup.g3e_fid;
1914 vError.circuito := dup.Clase;
1915 vError.fecha := sysdate;
1916 vError.descripcion := 'El punto inicial de la linea no esta contenido por ningun ciruito';
1917
1918 insert into EAM_ERRORS values vError;
1919 commit;
1920 end if;
1921 end if;
1922 end loop;
1923
1924 end EAM_TAXONOMIA_SECUNDARIA;
1925
1926 procedure EAM_LIMPIAR_TABLAS is
1927 begin
1928 execute immediate 'TRUNCATE TABLE EAM_UBICACION';
1929 execute immediate 'TRUNCATE TABLE EAM_ACTIVOS_TEMP';
1930 execute immediate 'TRUNCATE TABLE EAM_UBICACION_TEMP';
1931 execute immediate 'TRUNCATE TABLE EAM_ACTIVOS_ALL';
1932 execute immediate 'TRUNCATE TABLE EAM_ERRORS';
1933 end;
1934
1935 procedure EAM_RESPALDAR_TABLAS is
1936 begin
1937
1938 begin
1939 execute immediate 'DROP TABLE EAM_ACTIVOS_TEMP_BKP';
1940 exception
1941 when others then
1942 null;
1943 end;
1944
1945 begin
1946 execute immediate 'DROP TABLE EAM_UBICACION_BKP';
1947 exception
1948 when others then
1949 null;
1950 end;
1951
1952 begin
1953 execute immediate 'DROP TABLE EAM_UBICACION_TEMP_BKP';
1954 exception
1955 when others then
1956 null;
1957 end;
1958
1959 begin
1960 execute immediate 'DROP TABLE EAM_ACTIVOS_ALL_BKP';
1961 exception
1962 when others then
1963 null;
1964 end;
1965
1966 begin
1967 execute immediate 'DROP TABLE EAM_ERRORS_BKP';
1968 exception
1969 when others then
1970 null;
1971 end;
1972
1973 execute immediate 'CREATE TABLE EAM_ACTIVOS_TEMP_BKP AS SELECT * FROM EAM_ACTIVOS_TEMP';
1974 execute immediate 'CREATE TABLE EAM_ACTIVOS_ALL_BKP AS SELECT * FROM EAM_ACTIVOS_ALL';
1975 execute immediate 'CREATE TABLE EAM_UBICACION_BKP AS SELECT * FROM EAM_UBICACION';
1976 execute immediate 'CREATE TABLE EAM_UBICACION_TEMP_BKP AS SELECT * FROM EAM_UBICACION_TEMP';
1977 execute immediate 'CREATE TABLE EAM_ERRORS_BKP AS SELECT * FROM EAM_ERRORS_TEMP';
1978
1979 end EAM_RESPALDAR_TABLAS;
1980
1981 procedure EAM_MANEJO_NOVEDAD is
1982
1983 begin
1984
1985 update eam_activos_temp set novedad = 'CREACION';
1986 commit;
1987
1988 merge into eam_activos_temp nuevo
1989 using eam_activos_all viejo
1990 on (viejo.g3e_fid = nuevo.g3e_fid and viejo.clase = nuevo.clase)
1991 when matched then
1992 update
1993 set nuevo.fecha_actualizacion = viejo.fecha_actualizacion,
1994 nuevo.novedad = 'ACTUALIZACION'
1995 where (nvl(nuevo.codigo_activo, 0) = nvl(viejo.codigo_activo, 0) and
1996 nvl(nuevo.ubicacion, 0) = nvl(viejo.ubicacion, 0) and
1997 nvl(nuevo.fid_padre, 0) = nvl(viejo.fid_padre, 0) and
1998 nvl(nuevo.nivel_superior, 0) = nvl(viejo.nivel_superior, 0))
1999 and nuevo.clase = viejo.clase
2000 and nuevo.g3e_fno = viejo.g3e_fno;
2001 commit;
2002
2003 merge into eam_ubicacion_temp nuevo
2004 using eam_ubicacion viejo
2005 on (viejo.codigo_ubicacion = nuevo.codigo_ubicacion)
2006 when matched then
2007 update
2008 set nuevo.fecha_actualizacion = viejo.fecha_actualizacion
2009 where (nvl(nuevo.codigo, 0) = nvl(viejo.codigo, 0) and
2010 nvl(nuevo.codigo_ubicacion, 0) =
2011 nvl(viejo.codigo_ubicacion, 0) and
2012 nvl(nuevo.nivel_superior, 0) = nvl(viejo.nivel_superior, 0))
2013 and nuevo.clase = viejo.clase
2014 and nuevo.g3e_fno = viejo.g3e_fno;
2015 commit;
2016
2017 execute immediate 'TRUNCATE TABLE EAM_UBICACION';
2018 insert into eam_ubicacion
2019 select * from eam_ubicacion_temp;
2020 commit;
2021
2022 execute immediate 'TRUNCATE TABLE EAM_ACTIVOS_ALL';
2023 insert into eam_activos_all
2024 select * from eam_activos_temp;
2025 commit;
2026
2027 end EAM_MANEJO_NOVEDAD;
2028
2029 procedure EAM_MANEJO_RETIRADOS is
2030
2031 begin
2032 --Manejo de los retirados
2033 update eam_activos_all a
2034 set a.novedad = 'RETIRADO'
2035 where exists
2036 (select 1
2037 from ccomun c
2038 where c.g3e_fid = a.g3e_fid
2039 and c.g3e_fno = a.g3e_fno
2040 and c.estado in
2041 (select column_value from table(eam_estados_ret))
2042 and c.empresa in
2043 (select column_value from table(eam_empresas)));
2044 commit;
2045 end EAM_MANEJO_RETIRADOS;
2046
2047 function EAM_HASH(pValor in varchar2, pMax in number) return varchar is
2048 vHash NUMBER;
2049 begin
2050
2051 select ora_hash(pValor, pMax) into vHash from dual;
2052
2053 return to_char(vHash, 'FM000000');
2054
2055 end;
2056
2057 function ES_NUMERICO(pTexto in varchar2) return number is
2058 v_new_num number;
2059 begin
2060 v_new_num := TO_NUMBER(pTexto);
2061 return 1;
2062 exception
2063 when VALUE_ERROR then
2064 return 0;
2065 end ES_NUMERICO;
2066
2067 function PuntoInicialLinea(pLinea in sdo_geometry) return sdo_geometry is
2068 vPunto sdo_geometry;
2069 xInicial number;
2070 yInicial number;
2071 begin
2072
2073 select l.x, l.y
2074 into xInicial, yInicial
2075 from table(sdo_util.GetVertices(pLinea)) l
2076 where l.id =
2077 (select min(j.id) from table(sdo_util.GetVertices(pLinea)) j);
2078
2079 vPunto := SDO_GEOMETRY(2001,
2080 4326,
2081 null,
2082 SDO_ELEM_INFO_ARRAY(1, 1, 1),
2083 SDO_ORDINATE_ARRAY(xInicial, yInicial));
2084
2085 return vPunto;
2086
2087 end;
2088
2089end EAM_PROVISION;
2090/