Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*Creazione Manutenzione Automatica
- Possiamo supporre la manutenzione Automatica venga generata se non ci sono manutenzioni
- effettuate di una determinata tipologia per un periodo che diventa sempre più distante al diminuire
- dell'indice di manutenzione. La stima delle manutenzioni automatiche avviene anche in basse alle richieste
- di una determinata manutenzione che potrebbe essere stata ignorata nell'ultimo periodo.
- */
- drop event if exists Avviso_Manutenzioni;
- delimiter $$
- create event Avviso_Manutenzioni
- on schedule every 1 month
- do
- begin
- insert into Manutenzione_Automatica(Data_Scadenza, Tipo_Manutenzione, Cod_Scheda)
- select current_date + interval 1 month, ma.Tipo_Manutenzione, ma.Cod_Scheda
- from Manutenzione_Automatica ma
- where ma.Accettato=false and
- /*non deve esistere una manutenzione automatica, già accettata, riguardante lo stesso
- intervento sulla stessa pianta (già effettuata di recente) o da effettuare in un prossimo futuro*/
- not exists (
- select *
- from Manutenzione_Automatica ma2
- where ma2.Accettato=true and
- ma2.Tipo_Manutenzione=ma.Tipo_Manutenzione and
- ma2.Cod_Scheda=ma.Cod_Scheda and
- (ma2.Data is not null and
- ma2.Data > current_date - interval 1+1/Indice_Accrescimento(ma2.Cod_Scheda) month) or
- ma2.Data_Scadenza > current_date)
- and not exists(
- select *
- from Manutenzione_Programmata mp
- where mp.Tipo_Manutenzione=ma.Tipo_Manutenzione and
- mp.Cod_Scheda=ma.Cod_Scheda and
- (mp.Data is not null and
- mp.Data > current_date - interval 1+1/Indice_Accrescimento(mp.Cod_Scheda) month)
- -- or mp.Mese maggiore del mese in cui siamo month(current_date) classico problema 12 1
- )and not exists(
- select *
- from Manutenzione_Esterna me
- where me.Tipo_Manutenzione=ma.Tipo_Manutenzione and
- ma.Cod_Scheda=me.Cod_Scheda and
- me.Data > current_date - interval 1+1/Indice_Accrescimento(me.Cod_Scheda) month)
- and not exists(
- select *
- from Richiesta_Manutenzione rm
- where rm.Cod_Scheda=ma.Cod_Scheda and
- rm.Tipo_Manutenzione=ma.Tipo_Manutenzione and
- (rm.Data is not null and
- rm.Data > current_date - interval 1+1/Indice_Accrescimento(rm.Cod_Scheda) month) or
- rm.Data_Scadenza > current_date)
- group by ma.Cod_Scheda;
- insert into Manutenzione_Automatica(Data_Scadenza, Tipo_Manutenzione, Cod_Scheda)
- select current_date + interval 1 month, me.Tipo_Manutenzione, s.Cod_Scheda
- from Scheda s inner join Ordine o on s.Cod_Ordine=o.Codice
- inner join Pianta p on o.Nome_Pianta=p.Nome inner join
- Manutenzioni_Necessarie me on p.Nome=me.Nome_Pianta
- where me.Tipo_Manutenzione not in(
- select ma.Tipo_Manutenzione
- from Manutenzione_Automatica ma
- where ma.Cod_Scheda=s.Codice and
- ma.Data_Scadenza > current_date - interval 6+1/Indice_Accrescimento(s.Cod_Scheda) month)
- and me.Tipo_Manutenzione not in(
- select mext.Tipo_Manutenzione
- from Manutenzione_Esterna mext
- where mext.Cod_Scheda=s.Codice and
- mext.Data > current_date - interval 6+1/Indice_Accrescimento(s.Cod_Scheda) month)
- and me.Tipo_Manutenzione not in(
- select mp.Tipo_Manutenzione
- from Manutenzione_Programmata mp
- where mp.Cod_Scheda=s.Codice)
- and me.Tipo_Manutenzione not in(
- select rm.Tipo_Manutenzione
- from Richiesta_Manutenzione rm
- where rm.Cod_Scheda=s.Codice and
- rm.Data_Scadenza > current_date - interval 6+1/Indice_Accrescimento(s.Cod_Scheda) month);
- end $$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement