Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VAS-1170] feat: Add station maintenance entity #48

Merged
merged 4 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package it.gov.pagopa.apiconfig.starter.entity;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import java.time.OffsetDateTime;

@Entity
@Table(name = "MANUTENZIONE_STAZIONE")
@Setter
@Getter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class StationMaintenance {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hibernate_sequence")
@SequenceGenerator(
name = "hibernate_sequence",
sequenceName = "hibernate_sequence",
allocationSize = 1)
@Column(name = "OBJ_ID", nullable = false)
private Long objId;

@Column(name = "DATA_ORA_INIZIO", nullable = false)
private OffsetDateTime startDateTime;

@Column(name = "DATA_ORA_FINE", nullable = false)
private OffsetDateTime endDateTime;

@Column(name = "STANDIN", nullable = false)
private Boolean standIn;

@ManyToOne(optional = false)
@JoinColumn(name = "FK_STAZIONE", nullable = false)
@ToString.Exclude
private Stazioni station;

@Column(name = "FK_STAZIONE", nullable = false, insertable = false, updatable = false)
private Long fkStation;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package it.gov.pagopa.apiconfig.starter.entity;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.time.OffsetDateTime;

@Entity
@Table(name = "MANUTENZIONE_STAZIONE_ESPANSA")
@Setter
@Getter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class StationMaintenanceExpandedView {

@Id
@Column(name = "ID", nullable = false)
private String id;

@Column(name = "DATA_ORA_INIZIO", nullable = false)
private OffsetDateTime startDateTime;

@Column(name = "DATA_ORA_FINE", nullable = false)
private OffsetDateTime endDateTime;

@Column(name = "INTERMEDIARIO_PA_CODICE_FISCALE", nullable = false)
private String brokerCode;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package it.gov.pagopa.apiconfig.starter.entity;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;

import javax.persistence.Column;
import java.io.Serializable;

@Setter
@Getter
@SuperBuilder
@NoArgsConstructor
@EqualsAndHashCode
public class StationMaintenanceSummaryId implements Serializable {

private static final long serialVersionUID = 7800783561114522190L;

@Column(name = "INTERMEDIARIO_PA_CODICE_FISCALE", nullable = false)
private String brokerCode;

@Column(name = "ANNO_MANUTENZIONE", nullable = false)
private String maintenanceYear;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package it.gov.pagopa.apiconfig.starter.entity;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;

@Entity
@Table(name = "MANUTENZIONE_STAZIONE_RIEPILOGO")
@IdClass(StationMaintenanceSummaryId.class)
@Setter
@Getter
@ToString
@Builder
@NoArgsConstructor
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class StationMaintenanceSummaryView {

@Id
@Column(name = "INTERMEDIARIO_PA_CODICE_FISCALE", nullable = false)
private String brokerCode;

@Id
@Column(name = "ANNO_MANUTENZIONE", nullable = false)
private String maintenanceYear;

@Column(name = "ORE_UTILIZZATE", nullable = false)
private Double usedHours;

@Column(name = "ORE_PROGRAMMATE", nullable = false)
private Double scheduledHours;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.gov.pagopa.apiconfig.starter.repository;

import it.gov.pagopa.apiconfig.starter.entity.StationMaintenanceExpandedView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@SuppressWarnings("java:S100")
// Disabled naming convention rule for method name to use Spring Data interface
@Repository
public interface StationMaintenanceExpandedViewRepository extends JpaRepository<StationMaintenanceExpandedView, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package it.gov.pagopa.apiconfig.starter.repository;

import it.gov.pagopa.apiconfig.starter.entity.StationMaintenance;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.OffsetDateTime;

@SuppressWarnings("java:S100")
// Disabled naming convention rule for method name to use Spring Data interface
@Repository
public interface StationMaintenanceRepository extends JpaRepository<StationMaintenance, Long> {

@Query(value =
"SELECT m " +
"FROM StationMaintenance m JOIN Stazioni s ON m.fkStation = s.objId JOIN IntermediariPa ipa ON s.fkIntermediarioPa = ipa.objId " +
"WHERE ipa.idIntermediarioPa = :brokerCode " +
"AND (:stationCode IS NULL OR UPPER(s.idStazione) LIKE CONCAT('%', UPPER(:stationCode), '%')) " +
"AND (:startDateTimeBefore IS NULL OR m.startDateTime < :startDateTimeBefore) " +
"AND (:startDateTimeAfter IS NULL OR m.startDateTime > :startDateTimeAfter) " +
"AND (:endDateTimeBefore IS NULL OR m.endDateTime < :endDateTimeBefore) " +
"AND (:endDateTimeAfter IS NULL OR m.endDateTime > :endDateTimeAfter)")
Page<StationMaintenance> findAllByFilters(
@Param("brokerCode") String brokerCode,
@Param("stationCode") String stationCode,
@Param("startDateTimeBefore") OffsetDateTime startDateTimeBefore,
@Param("startDateTimeAfter") OffsetDateTime startDateTimeAfter,
@Param("endDateTimeBefore") OffsetDateTime endDateTimeBefore,
@Param("endDateTimeAfter") OffsetDateTime endDateTimeAfter,
Pageable pageable
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package it.gov.pagopa.apiconfig.starter.repository;

import it.gov.pagopa.apiconfig.starter.entity.StationMaintenanceSummaryId;
import it.gov.pagopa.apiconfig.starter.entity.StationMaintenanceSummaryView;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@SuppressWarnings("java:S100")
// Disabled naming convention rule for method name to use Spring Data interface
@Repository
public interface StationMaintenanceSummaryViewRepository extends JpaRepository<StationMaintenanceSummaryView, StationMaintenanceSummaryId> {
}
Loading