lol
This commit is contained in:
parent
a240756042
commit
b71ee88449
14 changed files with 238 additions and 99 deletions
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
13
.idea/compiler.xml
generated
Normal file
13
.idea/compiler.xml
generated
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<module name="jdbc-konsolen-projekt" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
7
.idea/encodings.xml
generated
Normal file
7
.idea/encodings.xml
generated
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
|
||||||
|
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
20
.idea/jarRepositories.xml
generated
Normal file
20
.idea/jarRepositories.xml
generated
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RemoteRepositoriesConfiguration">
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Central Repository" />
|
||||||
|
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="central" />
|
||||||
|
<option name="name" value="Maven Central repository" />
|
||||||
|
<option name="url" value="https://repo1.maven.org/maven2" />
|
||||||
|
</remote-repository>
|
||||||
|
<remote-repository>
|
||||||
|
<option name="id" value="jboss.community" />
|
||||||
|
<option name="name" value="JBoss Community repository" />
|
||||||
|
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
|
||||||
|
</remote-repository>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
12
.idea/misc.xml
generated
Normal file
12
.idea/misc.xml
generated
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_24" default="true" project-jdk-name="openjdk-24" project-jdk-type="JavaSDK" />
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
|
|
@ -8,12 +8,10 @@ import de.antco.projekt.model.WorkOrderItem;
|
||||||
import de.antco.projekt.service.WorkshopService;
|
import de.antco.projekt.service.WorkshopService;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class ConsoleUi {
|
public class ConsoleUi {
|
||||||
|
|
||||||
private final WorkshopService service;
|
private final WorkshopService service;
|
||||||
private final Scanner scanner = new Scanner(System.in);
|
private final Scanner scanner = new Scanner(System.in);
|
||||||
|
|
||||||
|
|
@ -23,168 +21,235 @@ public class ConsoleUi {
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
boolean running = true;
|
boolean running = true;
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
printMenu();
|
showMenu();
|
||||||
String input = scanner.nextLine();
|
String choice = scanner.nextLine().trim();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (input) {
|
switch (choice) {
|
||||||
case "1" -> addPerson();
|
case "1" -> addPerson();
|
||||||
case "2" -> listPersons();
|
case "2" -> showPersons();
|
||||||
case "3" -> addVehicle();
|
case "3" -> addVehicle();
|
||||||
case "4" -> listVehiclesOfPerson();
|
case "4" -> showVehiclesOfPerson();
|
||||||
case "5" -> createWorkOrder();
|
case "5" -> createWorkOrder();
|
||||||
case "6" -> listWorkOrders();
|
case "6" -> showWorkOrders();
|
||||||
case "0" -> running = false;
|
case "0" -> running = false;
|
||||||
default -> System.out.println("Unbekannte Auswahl");
|
default -> System.out.println("Ungültige Eingabe.");
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
System.out.println("Fehler: " + e.getMessage());
|
System.out.println("Ein Fehler ist aufgetreten: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("Bis dann");
|
|
||||||
|
System.out.println("Programm beendet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void printMenu() {
|
private void showMenu() {
|
||||||
System.out.println();
|
System.out.println("\n=== Werkstatt Menü ===");
|
||||||
System.out.println("==== Werkstatt Menü ====");
|
|
||||||
System.out.println("1) Kunde anlegen");
|
System.out.println("1) Kunde anlegen");
|
||||||
System.out.println("2) Kunden anzeigen");
|
System.out.println("2) Kunden anzeigen");
|
||||||
System.out.println("3) Fahrzeug anlegen");
|
System.out.println("3) Fahrzeug anlegen");
|
||||||
System.out.println("4) Fahrzeuge einer Person");
|
System.out.println("4) Fahrzeuge einer Person anzeigen");
|
||||||
System.out.println("5) Werkstattvorgang anlegen");
|
System.out.println("5) Werkstattvorgang anlegen");
|
||||||
System.out.println("6) Vorgänge anzeigen");
|
System.out.println("6) Vorgänge anzeigen");
|
||||||
System.out.println("0) Ende");
|
System.out.println("0) Beenden");
|
||||||
System.out.print("Auswahl: ");
|
System.out.print("Auswahl: ");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPerson() throws SQLException {
|
private int readInt(String text) {
|
||||||
System.out.print("Name: ");
|
while (true) {
|
||||||
String name = scanner.nextLine();
|
System.out.print(text);
|
||||||
System.out.print("Telefon: ");
|
String input = scanner.nextLine();
|
||||||
String phone = scanner.nextLine();
|
|
||||||
Person person = service.createPerson(name, phone);
|
try {
|
||||||
System.out.println("Kunde gespeichert mit ID " + person.getId());
|
return Integer.parseInt(input.trim());
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println("Bitte eine gültige Zahl eingeben.");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void listPersons() throws SQLException {
|
private String readNonEmpty(String text) {
|
||||||
|
while (true) {
|
||||||
|
System.out.print(text);
|
||||||
|
String value = scanner.nextLine().trim();
|
||||||
|
|
||||||
|
if (!value.isEmpty()) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Eingabe darf nicht leer sein.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readValidName(String text) {
|
||||||
|
while (true) {
|
||||||
|
String name = readNonEmpty(text);
|
||||||
|
|
||||||
|
if (name.matches("[a-zA-ZäöüÄÖÜß ]+")) {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Der Name darf nur Buchstaben enthalten.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private String readPhoneNumber(String text) {
|
||||||
|
while (true) {
|
||||||
|
System.out.print(text);
|
||||||
|
String phone = scanner.nextLine().trim();
|
||||||
|
|
||||||
|
if (phone.matches("\\d+")) {
|
||||||
|
return phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Telefonnummer darf nur Zahlen enthalten.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addPerson() throws SQLException {
|
||||||
|
String name = readValidName("Name: ");
|
||||||
|
String phone = readPhoneNumber("Telefonnummer: ");
|
||||||
|
|
||||||
|
Person person = service.createPerson(name, phone);
|
||||||
|
System.out.println("Kunde gespeichert (ID: " + person.getId() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showPersons() throws SQLException {
|
||||||
List<Person> persons = service.listPersons();
|
List<Person> persons = service.listPersons();
|
||||||
|
|
||||||
if (persons.isEmpty()) {
|
if (persons.isEmpty()) {
|
||||||
System.out.println("Keine Personen da");
|
System.out.println("Keine Kunden vorhanden.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
persons.forEach(p -> System.out.println(p.toString()));
|
|
||||||
|
System.out.println("\n--- Kundenliste ---");
|
||||||
|
persons.forEach(System.out::println);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addVehicle() throws SQLException {
|
private void addVehicle() throws SQLException {
|
||||||
System.out.print("Personen ID: ");
|
int personId = readInt("Personen-ID: ");
|
||||||
int personId = parseInt(scanner.nextLine());
|
Person person = service.findPerson(personId);
|
||||||
Person owner = service.findPerson(personId);
|
|
||||||
if (owner == null) {
|
if (person == null) {
|
||||||
System.out.println("Person nicht gefunden");
|
System.out.println("Person wurde nicht gefunden.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.print("Hersteller: ");
|
|
||||||
String brand = scanner.nextLine();
|
String brand = readNonEmpty("Hersteller: ");
|
||||||
System.out.print("Modell: ");
|
String model = readNonEmpty("Modell: ");
|
||||||
String model = scanner.nextLine();
|
String plate = readNonEmpty("Kennzeichen: ");
|
||||||
System.out.print("Kennzeichen: ");
|
|
||||||
String plate = scanner.nextLine();
|
|
||||||
Vehicle vehicle = service.createVehicle(personId, brand, model, plate);
|
Vehicle vehicle = service.createVehicle(personId, brand, model, plate);
|
||||||
System.out.println("Fahrzeug gespeichert mit ID " + vehicle.getId());
|
System.out.println("Fahrzeug angelegt (ID: " + vehicle.getId() + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void listVehiclesOfPerson() throws SQLException {
|
private void showVehiclesOfPerson() throws SQLException {
|
||||||
System.out.print("Personen ID: ");
|
int personId = readInt("Personen-ID: ");
|
||||||
int personId = parseInt(scanner.nextLine());
|
Person person = service.findPerson(personId);
|
||||||
Person owner = service.findPerson(personId);
|
|
||||||
if (owner == null) {
|
if (person == null) {
|
||||||
System.out.println("Person nicht gefunden");
|
System.out.println("Person nicht gefunden.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Vehicle> vehicles = service.listVehicles(personId);
|
List<Vehicle> vehicles = service.listVehicles(personId);
|
||||||
System.out.println("Fahrzeuge von " + owner.getName() + ":");
|
|
||||||
|
System.out.println("Fahrzeuge von " + person.getName() + ":");
|
||||||
if (vehicles.isEmpty()) {
|
if (vehicles.isEmpty()) {
|
||||||
System.out.println("Keine Einträge");
|
System.out.println("Keine Fahrzeuge vorhanden.");
|
||||||
return;
|
} else {
|
||||||
|
vehicles.forEach(System.out::println);
|
||||||
}
|
}
|
||||||
vehicles.forEach(v -> System.out.println(v.toString()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createWorkOrder() throws SQLException {
|
private void createWorkOrder() throws SQLException {
|
||||||
System.out.print("Fahrzeug ID: ");
|
int vehicleId = readInt("Fahrzeug-ID: ");
|
||||||
int vehicleId = parseInt(scanner.nextLine());
|
|
||||||
Vehicle vehicle = service.findVehicle(vehicleId);
|
Vehicle vehicle = service.findVehicle(vehicleId);
|
||||||
|
|
||||||
if (vehicle == null) {
|
if (vehicle == null) {
|
||||||
System.out.println("Fahrzeug nicht gefunden");
|
System.out.println("Fahrzeug nicht gefunden.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
System.out.print("Notiz: ");
|
|
||||||
String note = scanner.nextLine();
|
String note = readNonEmpty("Notiz: ");
|
||||||
|
|
||||||
List<ServiceItem> catalog = service.listServiceItems();
|
List<ServiceItem> catalog = service.listServiceItems();
|
||||||
Map<Integer, Integer> selected = new LinkedHashMap<>();
|
Map<Integer, Integer> selectedItems = new LinkedHashMap<>();
|
||||||
boolean adding = true;
|
|
||||||
while (adding) {
|
while (true) {
|
||||||
showCatalog(catalog);
|
System.out.println("\n--- Service-Katalog ---");
|
||||||
System.out.print("Service ID (leer = fertig): ");
|
catalog.forEach(System.out::println);
|
||||||
String input = scanner.nextLine();
|
|
||||||
if (input.isBlank()) {
|
System.out.print("Service-ID (leer = fertig): ");
|
||||||
adding = false;
|
String input = scanner.nextLine().trim();
|
||||||
} else {
|
|
||||||
int serviceId = parseInt(input);
|
if (input.isEmpty()) {
|
||||||
ServiceItem item = catalog.stream().filter(s -> s.getId() == serviceId).findFirst().orElse(null);
|
break;
|
||||||
if (item == null) {
|
|
||||||
System.out.println("Service gibt es nicht");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
System.out.print("Menge: ");
|
|
||||||
int qty = parseInt(scanner.nextLine());
|
|
||||||
if (qty <= 0) {
|
|
||||||
System.out.println("Menge muss > 0 sein");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
selected.put(serviceId, selected.getOrDefault(serviceId, 0) + qty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int serviceId;
|
||||||
|
try {
|
||||||
|
serviceId = Integer.parseInt(input);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println("Bitte eine gültige ID eingeben.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceItem item = catalog.stream()
|
||||||
|
.filter(s -> s.getId() == serviceId)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(null);
|
||||||
|
|
||||||
|
if (item == null) {
|
||||||
|
System.out.println("Service nicht gefunden.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int qty = readInt("Menge: ");
|
||||||
|
if (qty <= 0) {
|
||||||
|
System.out.println("Menge muss größer als 0 sein.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
selectedItems.merge(serviceId, qty, Integer::sum);
|
||||||
}
|
}
|
||||||
if (selected.isEmpty()) {
|
|
||||||
System.out.println("Keine Positionen gespeichert");
|
if (selectedItems.isEmpty()) {
|
||||||
|
System.out.println("Keine Positionen ausgewählt.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int orderId = service.createWorkOrder(vehicleId, note, selected);
|
|
||||||
System.out.println("Vorgang angelegt mit ID " + orderId);
|
int orderId = service.createWorkOrder(vehicleId, note, selectedItems);
|
||||||
|
System.out.println("Vorgang wurde angelegt (ID: " + orderId + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showCatalog(List<ServiceItem> items) {
|
private void showWorkOrders() throws SQLException {
|
||||||
System.out.println("Katalog:");
|
|
||||||
items.forEach(item -> System.out.println(item.toString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void listWorkOrders() throws SQLException {
|
|
||||||
List<WorkOrderDetails> orders = service.listWorkOrders();
|
List<WorkOrderDetails> orders = service.listWorkOrders();
|
||||||
|
|
||||||
if (orders.isEmpty()) {
|
if (orders.isEmpty()) {
|
||||||
System.out.println("Keine Vorgänge gespeichert");
|
System.out.println("Keine Vorgänge vorhanden.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (WorkOrderDetails order : orders) {
|
for (WorkOrderDetails order : orders) {
|
||||||
System.out.println("--- Vorgang " + order.getOrderId() + " ---");
|
System.out.println("\n--- Vorgang " + order.getOrderId() + " ---");
|
||||||
System.out.println("Kunde: " + order.getPersonName());
|
System.out.println("Kunde: " + order.getPersonName());
|
||||||
System.out.println("Fahrzeug: " + order.getVehicleText());
|
System.out.println("Fahrzeug: " + order.getVehicleText());
|
||||||
System.out.println("Datum: " + order.getCreatedAt());
|
System.out.println("Datum: " + order.getCreatedAt());
|
||||||
|
|
||||||
if (order.getNote() != null && !order.getNote().isBlank()) {
|
if (order.getNote() != null && !order.getNote().isBlank()) {
|
||||||
System.out.println("Notiz: " + order.getNote());
|
System.out.println("Notiz: " + order.getNote());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (WorkOrderItem item : order.getItems()) {
|
for (WorkOrderItem item : order.getItems()) {
|
||||||
System.out.println(" * " + item.getServiceItem().getTitle() + " x" + item.getQuantity() +
|
System.out.println(" - " + item.getServiceItem().getTitle() +
|
||||||
|
" x" + item.getQuantity() +
|
||||||
" = " + item.getTotalPrice() + " €");
|
" = " + item.getTotalPrice() + " €");
|
||||||
}
|
}
|
||||||
System.out.println("Summe: " + order.getTotal() + " €");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private int parseInt(String input) {
|
System.out.println("Gesamtsumme: " + order.getTotal() + " €");
|
||||||
try {
|
|
||||||
return Integer.parseInt(input.trim());
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
4
src/main/java/de/antco/projekt/Exporters/IExporter.java
Normal file
4
src/main/java/de/antco/projekt/Exporters/IExporter.java
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
package de.antco.projekt.Exporters;
|
||||||
|
|
||||||
|
public interface IExporter {
|
||||||
|
}
|
||||||
4
src/main/java/de/antco/projekt/Importers/IImporter.java
Normal file
4
src/main/java/de/antco/projekt/Importers/IImporter.java
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
package de.antco.projekt.Importers;
|
||||||
|
|
||||||
|
public interface IImporter {
|
||||||
|
}
|
||||||
5
src/main/java/de/antco/projekt/loggers/ILogger.java
Normal file
5
src/main/java/de/antco/projekt/loggers/ILogger.java
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
package de.antco.projekt.loggers;
|
||||||
|
|
||||||
|
public interface ILogger {
|
||||||
|
void Log();
|
||||||
|
}
|
||||||
Binary file not shown.
BIN
target/classes/de/antco/projekt/Exporters/IExporter.class
Normal file
BIN
target/classes/de/antco/projekt/Exporters/IExporter.class
Normal file
Binary file not shown.
BIN
target/classes/de/antco/projekt/Importers/IImporter.class
Normal file
BIN
target/classes/de/antco/projekt/Importers/IImporter.class
Normal file
Binary file not shown.
BIN
target/classes/de/antco/projekt/loggers/ILogger.class
Normal file
BIN
target/classes/de/antco/projekt/loggers/ILogger.class
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue