From e4f9d88cda836f6939f2214426a71b0789cc15cf Mon Sep 17 00:00:00 2001 From: Gregor_Dutzler Date: Fri, 13 Dec 2019 11:36:26 +0100 Subject: [PATCH] asdf --- .idea/misc.xml | 2 +- src/java/com/wasteinformationserver/main.java | 4 +- .../com/wasteinformationserver/mqtt/mqtt.java | 52 ++++++++++++++----- 3 files changed, 43 insertions(+), 15 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 6619eb6..5cd2caa 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,7 +4,7 @@ - + \ No newline at end of file diff --git a/src/java/com/wasteinformationserver/main.java b/src/java/com/wasteinformationserver/main.java index 10cd3c9..b220f02 100644 --- a/src/java/com/wasteinformationserver/main.java +++ b/src/java/com/wasteinformationserver/main.java @@ -33,8 +33,8 @@ public class main { Log.message("initial login to db"); new Thread(() -> { try { - JDCB.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306); - //JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306); + //JDCB.init("users", "admin0", "wasteinformation", "192.168.65.15", 1883); + JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306); } catch (IOException e) { //e.printStackTrace(); Log.error("no connection to db"); diff --git a/src/java/com/wasteinformationserver/mqtt/mqtt.java b/src/java/com/wasteinformationserver/mqtt/mqtt.java index b016eb0..ae8ba09 100644 --- a/src/java/com/wasteinformationserver/mqtt/mqtt.java +++ b/src/java/com/wasteinformationserver/mqtt/mqtt.java @@ -43,7 +43,9 @@ public class mqtt { String temp = e.getActionCommand(); String[] split = temp.split(","); - getDatabasedata("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=(SELECT cities.zone FROM cities WHERE cities.name='" + split[1] + "' AND cities.wastetype='" + split[2] + "' AND cities.zone=" + split[3] + ")", split[2], Integer.parseInt(split[0])); + String wastetyp = getTyp(Integer.parseInt(split[2])); + System.out.println(wastetyp); + getDatabasedata("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=(SELECT cities.zone FROM cities WHERE cities.name='" + split[1] + "' AND cities.wastetype='" + wastetyp + "' AND cities.zone=" + split[3] + ")", wastetyp, Integer.parseInt(split[0])); } }); mr.getmessage(); @@ -51,21 +53,22 @@ public class mqtt { public void getDatabasedata(String message, String wastetyp, int clientidentify) { + System.out.println("message"); Log.debug(message); + Log.debug(wastetyp); + Log.debug(clientidentify); JDCB Database = null; try { Database = JDCB.getInstance(); } catch (IOException e) { Log.error("No Connection to the databank"); } + int wastenumber = getIntTyp(wastetyp); + System.out.println("wastenumber" + wastenumber); //new JDCB("placeuser", "eaL956R6yFItQVBl", "wasteinformation"); ResultSet result = Database.executeQuery(message); try { - if (!result.isBeforeFirst()) { - int abholtag = 0; - transmitmessageAbfallart(clientidentify + "," + wastetyp + "," + abholtag); - } else { - while (result.next()) { + while (result.next()) { String temptime = String.valueOf(result.getString("pickupdate")); GregorianCalendar now = new GregorianCalendar(); @@ -81,20 +84,18 @@ public class mqtt { int abholtag; - if (partstwo[0].contains(newDate) || partstwo[0].contains(Datetomorrow)) { + if (partstwo[0].equals(newDate) || partstwo[0].equals(Datetomorrow)) { abholtag = 1; - transmitmessageAbfallart(clientidentify + "," + wastetyp + "," + abholtag); + transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + abholtag); } else { abholtag = 0; - transmitmessageAbfallart(clientidentify + "," + wastetyp + "," + abholtag); + transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + abholtag); } - } - } + } catch (SQLException e) { Log.error("No data from database"); } - } @@ -120,4 +121,31 @@ public class mqtt { String newDate = split[2] + "." + split[1] + "." + split[0]; return newDate; } + + private String getTyp(int number) { + if (number == 1) { + return "Plastic"; + } else if (number == 2) { + return "Metal"; + } else if (number == 3) { + return "Residual waste"; + } else if (number == 4) { + return "Biowaste"; + } + return null; + } + + private int getIntTyp(String temp) { + int number = 0; + if (temp.equals("Plastic")) { + number = 1; + } else if (temp.equals("Metal")) { + number = 2; + } else if (temp.equals("Residual waste")) { + number = 3; + } else if (temp.equals("Biowaste")) { + number = 4; + } + return number; + } } \ No newline at end of file