Import of CSV-Data and data structure
This commit is contained in:
@@ -4,20 +4,29 @@ import java.time.Duration;
|
||||
import java.util.Date;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(fluent = true, chain = true)
|
||||
public class Appointment {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
@Column("GARAGE_ID")
|
||||
private AggregateReference<Garage, Long> garageId;
|
||||
|
||||
private String serviceCode;
|
||||
|
||||
private String serviceName;
|
||||
|
||||
private Date appointmentTime;
|
||||
|
||||
private Duration duration;
|
||||
private Integer slot = 1;
|
||||
|
||||
private Duration duration = Duration.ZERO;
|
||||
}
|
||||
|
||||
@@ -1,48 +1,63 @@
|
||||
package de.etecture.ga.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.time.Duration;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||
import org.springframework.data.relational.core.mapping.MappedCollection;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(fluent = true, chain = true)
|
||||
public class Garage {
|
||||
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String code;
|
||||
|
||||
private String name;
|
||||
|
||||
private List<Appointment> appointments;
|
||||
private Integer maxAppointments = 1;
|
||||
|
||||
private Set<GarageServices> garageServices;
|
||||
@MappedCollection(idColumn = "GARAGE_ID")
|
||||
private Set<Appointment> appointments = new HashSet<>();
|
||||
|
||||
@MappedCollection(idColumn = "GARAGE_ID")
|
||||
private Set<GarageServices> garageServices = new HashSet<>();
|
||||
|
||||
public Garage addAppointment(Appointment appointment) {
|
||||
|
||||
if (this.appointments == null) {
|
||||
this.appointments = new ArrayList<>();
|
||||
boolean added = this.appointments.add(appointment);
|
||||
if(!added) {
|
||||
appointment.slot(appointment.slot() + 1);
|
||||
this.addAppointment(appointment);
|
||||
}
|
||||
|
||||
this.appointments.add(appointment);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void addService(MDService service) {
|
||||
garageServices.add(createGarageService(service));
|
||||
public Garage addService(MDService service) {
|
||||
garageServices.add(createGarageService(service, null));
|
||||
return this;
|
||||
}
|
||||
|
||||
private GarageServices createGarageService(MDService service) {
|
||||
public void addService(MDService service, Duration duration) {
|
||||
garageServices.add(createGarageService(service, duration));
|
||||
}
|
||||
|
||||
private GarageServices createGarageService(MDService service, Duration duration) {
|
||||
|
||||
Assert.notNull(service, "Service must not be null");
|
||||
Assert.notNull(service.getId(), "Service id, must not be null");
|
||||
Assert.notNull(service.id(), "Service id, must not be null");
|
||||
|
||||
GarageServices garageService = new GarageServices();
|
||||
garageService.setMdService(service.getId());
|
||||
duration = duration == null ? service.duration() : duration;
|
||||
|
||||
return garageService;
|
||||
return new GarageServices().garageId(AggregateReference.to(this.id()))
|
||||
.serviceId(AggregateReference.to(service.id())).duration(duration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
package de.etecture.ga.model;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.springframework.data.jdbc.core.mapping.AggregateReference;
|
||||
import org.springframework.data.relational.core.mapping.Column;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(fluent = true, chain = true)
|
||||
public class GarageServices {
|
||||
|
||||
private Long mdService;
|
||||
@Column("GARAGE_ID")
|
||||
private AggregateReference<Garage, Long> garageId;
|
||||
|
||||
@Column("SERVICE_ID")
|
||||
private AggregateReference<MDService, Long> serviceId;
|
||||
|
||||
private Duration duration;
|
||||
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import java.time.Duration;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@Data
|
||||
@Accessors(fluent = true, chain = true)
|
||||
public class MDService {
|
||||
|
||||
@Id
|
||||
@@ -16,6 +18,6 @@ public class MDService {
|
||||
|
||||
private String name;
|
||||
|
||||
private Duration duration;
|
||||
private Duration duration = Duration.ZERO;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user