diff --git a/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20240321144750.java b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20240321144750.java new file mode 100644 index 0000000000..19e4ac4f28 --- /dev/null +++ b/ems-core/src/main/java/it/integry/ems/migration/model/Migration_20240321144750.java @@ -0,0 +1,82 @@ +package it.integry.ems.migration.model; + +import it.integry.ems.migration._base.BaseMigration; +import it.integry.ems.migration._base.IntegryCustomer; +import it.integry.ems.migration._base.IntegryCustomerDB; +import it.integry.ems.migration._base.MigrationModelInterface; +import it.integry.ems_model.entity.StbCalrOreGg; +import it.integry.ems_model.entity.StbCalt; +import it.integry.ems_model.types.OperationType; +import it.integry.ems_model.utility.UtilityDB; +import it.integry.ems_model.utility.UtilityLocalDate; + +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; + +public class Migration_20240321144750 extends BaseMigration implements MigrationModelInterface { + + @Override + public void up() throws Exception { + if (isHistoryDB()) return; + if (!isCustomer(IntegryCustomer.Tosca)) return; + + + String currentDbName = advancedDataSource.getDataSource().getDbName(); + IntegryCustomerDB db = Arrays.stream(IntegryCustomer.Tosca.getValues()).filter(x -> x.getValue().equalsIgnoreCase(currentDbName)).findFirst().orElse(null); + + LocalDate giorno = UtilityLocalDate.getNow(); + LocalTime ora; + switch (db) { + + case Tosca_Ce: + ora = LocalTime.of(7, 0); + + break; + case Tosca_Mi: + ora = LocalTime.of(6, 30); + break; + case Tosca_Fc: + ora = LocalTime.of(4, 0); + break; + case Tosca_Vr: + case Tosca_Cz: + case Tosca_Rg: + case Tosca_Rm: + case Tosca_Ba: + default: + ora = LocalTime.of(6, 0); + } + + String sql = "SELECT MAX(id_riga) from stb_calr_ore_gg where cod_Cal = 'DEFAULT'"; + Integer idRiga = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(advancedDataSource.getConnection(), sql); + + if (idRiga == null) { + throw new Exception("Calendario DEFAULT non configurato!"); + } + + StbCalt calendario = new StbCalt(); + calendario.setOperation(OperationType.NO_OP); + calendario.setCodCal("DEFAULT"); + calendario.setStbCalrOreGg(new ArrayList<>()); + StbCalrOreGg firstWorkingHour = new StbCalrOreGg(); + firstWorkingHour + .setCodCal("DEFAULT") + .setOra(Date.from(giorno.atTime(ora).atZone(ZoneId.systemDefault()).toInstant())) + .setFlagTipoOra("L") + .setIdRiga(idRiga + 1) + .setOperation(OperationType.INSERT); + calendario.getStbCalrOreGg().add(firstWorkingHour); + + calendario.manageWithParentConnection(advancedDataSource.getConnection()); + } + + @Override + public void down() throws Exception { + + } + +} diff --git a/ems-core/src/main/java/it/integry/ems_model/entity/JtbCalFasce.java b/ems-core/src/main/java/it/integry/ems_model/entity/JtbCalFasce.java new file mode 100644 index 0000000000..2098d0d220 --- /dev/null +++ b/ems-core/src/main/java/it/integry/ems_model/entity/JtbCalFasce.java @@ -0,0 +1,87 @@ +package it.integry.ems_model.entity; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import it.integry.ems_model.annotation.FK; +import it.integry.ems_model.annotation.PK; +import it.integry.ems_model.annotation.SqlField; +import it.integry.ems_model.annotation.Table; +import it.integry.ems_model.base.EntityBase; +import org.kie.api.definition.type.PropertyReactive; + +import java.util.Date; + +@PropertyReactive() +@Table(value = JtbCalFasce.ENTITY) +@JsonTypeName(value = JtbCalFasce.ENTITY) +public class JtbCalFasce extends EntityBase { + + public final static String ENTITY = "jtb_cal_fasce"; + + private final static long serialVersionUID = 1L; + + @PK() + @SqlField(value = "cod_jcal", maxLength = 5, nullable = false) + @FK(tableName = JtbCalendt.ENTITY, columnName = "cod_jcal") + @FK(tableName = JtbCalGgSet.ENTITY, columnName = "cod_jcal") + private String codJcal; + + @PK() + @SqlField(value = "gg_set", nullable = false) + @FK(tableName = JtbCalGgSet.ENTITY, columnName = "gg_set") + private Integer ggSet; + + @PK() + @SqlField(value = "da_ora", nullable = false) + private Date daOra; + + @SqlField(value = "a_ora", nullable = false) + private Date aOra; + + @SqlField(value = "fascia", maxLength = 40, nullable = false) + private String fascia; + + public String getCodJcal() { + return codJcal; + } + + public JtbCalFasce setCodJcal(String codJcal) { + this.codJcal = codJcal; + return this; + } + + public Integer getGgSet() { + return ggSet; + } + + public JtbCalFasce setGgSet(Integer ggSet) { + this.ggSet = ggSet; + return this; + } + + public Date getDaOra() { + return daOra; + } + + public JtbCalFasce setDaOra(Date daOra) { + this.daOra = daOra; + return this; + } + + public Date getAOra() { + return aOra; + } + + public JtbCalFasce setAOra(Date aOra) { + this.aOra = aOra; + return this; + } + + public String getFascia() { + return fascia; + } + + public JtbCalFasce setFascia(String fascia) { + this.fascia = fascia; + return this; + } +} diff --git a/ems-core/src/main/java/it/integry/ems_model/entity/JtbCalGgSet.java b/ems-core/src/main/java/it/integry/ems_model/entity/JtbCalGgSet.java new file mode 100644 index 0000000000..21852f3b91 --- /dev/null +++ b/ems-core/src/main/java/it/integry/ems_model/entity/JtbCalGgSet.java @@ -0,0 +1,69 @@ +package it.integry.ems_model.entity; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import it.integry.ems_model.annotation.*; +import it.integry.ems_model.base.EntityBase; +import org.kie.api.definition.type.PropertyReactive; + +import java.util.List; + +@PropertyReactive() +@Table(value = JtbCalGgSet.ENTITY) +@JsonTypeName(value = JtbCalGgSet.ENTITY) +public class JtbCalGgSet extends EntityBase { + + public final static String ENTITY = "jtb_cal_gg_set"; + + private final static long serialVersionUID = 1L; + + @PK() + @SqlField(value = "cod_jcal", maxLength = 5, nullable = false) + @FK(tableName = JtbCalendt.ENTITY, columnName = "cod_jcal") + private String codJcal; + + @PK() + @SqlField(value = "gg_set", nullable = false) + private Integer ggSet; + + @SqlField(value = "flag_lavorativo", maxLength = 1, nullable = false) + private String flagLavorativo; + + @EntityChild + private List jtbCalFasce; + + public String getCodJcal() { + return codJcal; + } + + public JtbCalGgSet setCodJcal(String codJcal) { + this.codJcal = codJcal; + return this; + } + + public Integer getGgSet() { + return ggSet; + } + + public JtbCalGgSet setGgSet(Integer ggSet) { + this.ggSet = ggSet; + return this; + } + + public String getFlagLavorativo() { + return flagLavorativo; + } + + public JtbCalGgSet setFlagLavorativo(String flagLavorativo) { + this.flagLavorativo = flagLavorativo; + return this; + } + + public List getJtbCalFasce() { + return jtbCalFasce; + } + + public JtbCalGgSet setJtbCalFasce(List jtbCalFasce) { + this.jtbCalFasce = jtbCalFasce; + return this; + } +} diff --git a/ems-core/src/main/java/it/integry/ems_model/entity/JtbCalendt.java b/ems-core/src/main/java/it/integry/ems_model/entity/JtbCalendt.java index 40340d4549..0b7f8e8270 100644 --- a/ems-core/src/main/java/it/integry/ems_model/entity/JtbCalendt.java +++ b/ems-core/src/main/java/it/integry/ems_model/entity/JtbCalendt.java @@ -1,13 +1,11 @@ package it.integry.ems_model.entity; import com.fasterxml.jackson.annotation.JsonTypeName; -import it.integry.ems_model.annotation.Master; -import it.integry.ems_model.annotation.PK; -import it.integry.ems_model.annotation.SqlField; -import it.integry.ems_model.annotation.Table; +import it.integry.ems_model.annotation.*; import it.integry.ems_model.base.EntityBase; import org.kie.api.definition.type.PropertyReactive; -import it.integry.ems_model.annotation.FK; + +import java.util.List; @Master @PropertyReactive @@ -29,6 +27,9 @@ public class JtbCalendt extends EntityBase { @SqlField(value = "flag_attivo", maxLength = 1, nullable = false) private String flagAttivo; + @EntityChild + private List jtbCalGgSet; + public JtbCalendt() { super(); } @@ -56,4 +57,13 @@ public class JtbCalendt extends EntityBase { public void setFlagAttivo(String flagAttivo) { this.flagAttivo = flagAttivo; } + + public List getJtbCalGgSet() { + return jtbCalGgSet; + } + + public JtbCalendt setJtbCalGgSet(List jtbCalGgSet) { + this.jtbCalGgSet = jtbCalGgSet; + return this; + } } diff --git a/ems-core/src/main/java/it/integry/ems_model/entity/StbCalrOreGg.java b/ems-core/src/main/java/it/integry/ems_model/entity/StbCalrOreGg.java new file mode 100644 index 0000000000..c285259b93 --- /dev/null +++ b/ems-core/src/main/java/it/integry/ems_model/entity/StbCalrOreGg.java @@ -0,0 +1,70 @@ +package it.integry.ems_model.entity; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import it.integry.ems_model.annotation.*; +import it.integry.ems_model.base.EntityBase; +import org.kie.api.definition.type.PropertyReactive; + +import java.util.Date; + +@PropertyReactive() +@Table(value = StbCalrOreGg.ENTITY) +@JsonTypeName(value = StbCalrOreGg.ENTITY) +public class StbCalrOreGg extends EntityBase { + + public final static String ENTITY = "stb_calr_ore_gg"; + + private final static long serialVersionUID = 1L; + + @PK() + @ImportFromParent + @SqlField(value = "cod_cal", maxLength = 20, nullable = false) + @FK(tableName = StbCalt.ENTITY, columnName = "cod_cal") + private String codCal; + + @PK() + @SqlField(value = "id_riga", nullable = false) + private Integer idRiga; + + @SqlField(value = "ora", nullable = false) + private Date ora; + + @SqlField(value = "flag_tipo_ora", maxLength = 1, nullable = false) + private String flagTipoOra; + + public String getCodCal() { + return codCal; + } + + public StbCalrOreGg setCodCal(String codCal) { + this.codCal = codCal; + return this; + } + + public Integer getIdRiga() { + return idRiga; + } + + public StbCalrOreGg setIdRiga(Integer idRiga) { + this.idRiga = idRiga; + return this; + } + + public Date getOra() { + return ora; + } + + public StbCalrOreGg setOra(Date ora) { + this.ora = ora; + return this; + } + + public String getFlagTipoOra() { + return flagTipoOra; + } + + public StbCalrOreGg setFlagTipoOra(String flagTipoOra) { + this.flagTipoOra = flagTipoOra; + return this; + } +} diff --git a/ems-core/src/main/java/it/integry/ems_model/entity/StbCalt.java b/ems-core/src/main/java/it/integry/ems_model/entity/StbCalt.java new file mode 100644 index 0000000000..0bd77cd4c5 --- /dev/null +++ b/ems-core/src/main/java/it/integry/ems_model/entity/StbCalt.java @@ -0,0 +1,78 @@ +package it.integry.ems_model.entity; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import it.integry.ems_model.annotation.*; +import it.integry.ems_model.base.EntityBase; +import org.kie.api.definition.type.PropertyReactive; + +import java.util.List; + +@Master() +@PropertyReactive() +@Table(value = StbCalt.ENTITY) +@JsonTypeName(value = StbCalt.ENTITY) +public class StbCalt extends EntityBase { + + public final static String ENTITY = "stb_calt"; + + private final static long serialVersionUID = 1L; + + @PK() + @SqlField(value = "cod_cal", maxLength = 20, nullable = false) + private String codCal; + + @SqlField(value = "descrizione", maxLength = 255, nullable = false) + private String descrizione; + + + @EntityChild + private List stbCalrOreGg; + + public String getCodCal() { + return codCal; + } + + public StbCalt setCodCal(String codCal) { + this.codCal = codCal; + return this; + } + + public String getDescrizione() { + return descrizione; + } + + public StbCalt setDescrizione(String descrizione) { + this.descrizione = descrizione; + return this; + } + + public List getStbCalrOreGg() { + return stbCalrOreGg; + } + + public StbCalt setStbCalrOreGg(List stbCalrOreGg) { + this.stbCalrOreGg = stbCalrOreGg; + return this; + } + + + @Override + protected void updateChilds() throws Exception { + insertChilds(); + } + + @Override + protected void insertChilds() throws Exception { + + for (StbCalrOreGg stbCalrOreGg : getStbCalrOreGg()) { + stbCalrOreGg.manageWithParentConnection(connection, stbCalrOreGg.getOperation(), dataCompleting, entityHolder); + } + } + + @Override + protected void deleteChilds() throws Exception { + StbCalrOreGg oreGg = new StbCalrOreGg(); + oreGg.deleteAllEntities(connection, this); + } + +}