migration piano logistico rrule
This commit is contained in:
@@ -0,0 +1,47 @@
|
|||||||
|
package it.integry.ems.migration.model;
|
||||||
|
|
||||||
|
import it.integry.ems.migration._base.BaseMigration;
|
||||||
|
import it.integry.ems.migration._base.MigrationModelInterface;
|
||||||
|
|
||||||
|
public class Migration_20250403152113 extends BaseMigration implements MigrationModelInterface {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void up() throws Exception {
|
||||||
|
if (isHistoryDB())
|
||||||
|
return;
|
||||||
|
|
||||||
|
|
||||||
|
createOrUpdateFunction("getPianoLogistico", "CREATE FUNCTION [dbo].[getPianoLogistico] ( @codAlis varchar(5), @dataValidita datetime, @codMdep varchar(5), @ggOrd integer ) \n" +
|
||||||
|
"\n" +
|
||||||
|
"RETURNS TABLE \n" +
|
||||||
|
"AS\n" +
|
||||||
|
"RETURN \n" +
|
||||||
|
"( \n" +
|
||||||
|
"with last_piano as (\n" +
|
||||||
|
"select id_piano, \n" +
|
||||||
|
" cod_alis,\n" +
|
||||||
|
" data_validita, lead(data_validita, 1, null) over (partition by cod_alis order by cod_alis, data_validitA) as data_validita_next\n" +
|
||||||
|
"from atb_piano_logistico \n" +
|
||||||
|
"WHERE (@codAlis is null OR atb_piano_logistico.cod_alis = @codAlis) AND\n" +
|
||||||
|
"atb_piano_logistico.data_validita <= IsNull(@dataValidita, cAST(GETdATE() AS DATE)) )\n" +
|
||||||
|
"\n" +
|
||||||
|
"select last_piano.cod_alis, \n" +
|
||||||
|
" last_piano.data_validita,\n" +
|
||||||
|
" atb_piano_logistico_det.cod_mdep,\n" +
|
||||||
|
" atb_piano_logistico_det.gg_ord,\n" +
|
||||||
|
" atb_piano_logistico_det.gg_cons,\n" +
|
||||||
|
" atb_piano_logistico_det.ora_max_ord,\n" +
|
||||||
|
" atb_piano_logistico_det.ora_scarico\n" +
|
||||||
|
"from last_piano inner join atb_piano_logistico_det on last_piano.id_piano = atb_piano_logistico_det.id_piano \n" +
|
||||||
|
"where data_validita_next is null\n" +
|
||||||
|
"AND (@codMdep is null OR atb_piano_logistico_det.cod_mdep = @codMdep) \n" +
|
||||||
|
"AND (@ggOrd is null or atb_piano_logistico_det.gg_ord = @ggOrd ) \n" +
|
||||||
|
")");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void down() throws Exception {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package it.integry.ems.activity.service;
|
||||||
|
|
||||||
|
public class RRuleGenerator {
|
||||||
|
/**
|
||||||
|
* Genera una stringa RRule basata sui parametri specificati
|
||||||
|
*
|
||||||
|
* @param frequency La frequenza dell'evento (DAILY, WEEKLY, MONTHLY, YEARLY)
|
||||||
|
* @param interval Intervallo tra le occorrenze (es. ogni 2 settimane)
|
||||||
|
* @param count Il numero di occorrenze (opzionale, -1 per ignorare)
|
||||||
|
* @param until Data di termine della ricorrenza (opzionale, null per ignorare)
|
||||||
|
* @param byDay Giorni della settimana (es. "MO,WE,FR", opzionale)
|
||||||
|
* @param byMonthDay Giorni del mese (es. "1,15", opzionale)
|
||||||
|
* @param byMonth Mesi dell'anno (es. "1,6,12", opzionale)
|
||||||
|
* @return Una stringa nel formato RRule
|
||||||
|
*/
|
||||||
|
public static String generateRRule(
|
||||||
|
String frequency,
|
||||||
|
int interval,
|
||||||
|
int count,
|
||||||
|
String until,
|
||||||
|
String byDay,
|
||||||
|
String byMonthDay,
|
||||||
|
String byMonth) {
|
||||||
|
StringBuilder rrule = new StringBuilder("RRULE:");
|
||||||
|
// Aggiungi la frequenza (obbligatoria)
|
||||||
|
rrule.append("FREQ=").append(frequency);
|
||||||
|
// Aggiungi l'intervallo se maggiore di 1
|
||||||
|
if (interval > 1) {
|
||||||
|
rrule.append(";INTERVAL=").append(interval);
|
||||||
|
}
|
||||||
|
// Aggiungi il numero di occorrenze se specificato
|
||||||
|
if (count > 0) {
|
||||||
|
rrule.append(";COUNT=").append(count);
|
||||||
|
}
|
||||||
|
// Aggiungi la data di termine se specificata
|
||||||
|
if (until != null && !until.isEmpty()) {
|
||||||
|
rrule.append(";UNTIL=").append(until);
|
||||||
|
}
|
||||||
|
// Aggiungi i giorni della settimana se specificati
|
||||||
|
if (byDay != null && !byDay.isEmpty()) {
|
||||||
|
rrule.append(";BYDAY=").append(byDay);
|
||||||
|
}
|
||||||
|
// Aggiungi i giorni del mese se specificati
|
||||||
|
if (byMonthDay != null && !byMonthDay.isEmpty()) {
|
||||||
|
rrule.append(";BYMONTHDAY=").append(byMonthDay);
|
||||||
|
}
|
||||||
|
// Aggiungi i mesi se specificati
|
||||||
|
if (byMonth != null && !byMonth.isEmpty()) {
|
||||||
|
rrule.append(";BYMONTH=").append(byMonth);
|
||||||
|
}
|
||||||
|
return rrule.toString();
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Esempio di utilizzo della funzione generateRRule
|
||||||
|
*/
|
||||||
|
// public static void main(String[] args) {
|
||||||
|
// // Esempio 1: Ogni lunedì e mercoledì per 10 volte
|
||||||
|
// String rrule1 = generateRRule("WEEKLY", 1, 10, null, "MO,WE", null, null);
|
||||||
|
// System.out.println(rrule1);
|
||||||
|
// // Esempio 2: Ogni due mesi, il giorno 15, fino al 31 dicembre 2025
|
||||||
|
// String rrule2 = generateRRule("MONTHLY", 2, -1, "20251231T235959Z", null, "15", null);
|
||||||
|
// System.out.println(rrule2);
|
||||||
|
// // Esempio 3: Annualmente il 1° gennaio e il 25 dicembre
|
||||||
|
// String rrule3 = generateRRule("YEARLY", 1, -1, null, null, "1,25", "1,12");
|
||||||
|
// System.out.println(rrule3);
|
||||||
|
// }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user