readymqtt.2

This commit is contained in:
Gregor_Dutzler 2019-12-13 15:04:53 +01:00
parent 89426cfcee
commit 1ef61f13ab
4 changed files with 20 additions and 30 deletions

View File

@ -54,7 +54,7 @@ public class main {
mqtt m = new mqtt(); mqtt m = new mqtt();
m.notifymessage(); m.notifymessage();
} catch (Exception e) { } catch (Exception e) {
Log.debug("An error was happened in the class mqtt"); Log.error("An error occured in the class mqtt");
} }
} }
} }

View File

@ -1,4 +0,0 @@
package com.wasteinformationserver.mqtt;
public class Database {
}

View File

@ -31,7 +31,6 @@ public class mqtt {
MqttConnectOptions connOpts = new MqttConnectOptions(); MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true); connOpts.setCleanSession(true);
client.connect(connOpts); client.connect(connOpts);
} catch (MqttException e) { } catch (MqttException e) {
Log.error("Connection to the ESB was failed"); Log.error("Connection to the ESB was failed");
} }
@ -40,9 +39,7 @@ public class mqtt {
mr.addMessageReceivedListener(new ActionListener() { mr.addMessageReceivedListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String temp = e.getActionCommand(); String[] split = e.getActionCommand().split(",");
String[] split = temp.split(",");
String wastetyp = getTyp(Integer.parseInt(split[2])); String wastetyp = getTyp(Integer.parseInt(split[2]));
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])); 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]));
} }
@ -55,6 +52,7 @@ public class mqtt {
Log.debug(message); Log.debug(message);
Log.debug(wastetyp); Log.debug(wastetyp);
Log.debug(clientidentify); Log.debug(clientidentify);
JDCB Database = null; JDCB Database = null;
try { try {
Database = JDCB.getInstance(); Database = JDCB.getInstance();
@ -62,27 +60,18 @@ public class mqtt {
Log.error("No Connection to the databank"); Log.error("No Connection to the databank");
} }
int wastenumber = getIntTyp(wastetyp); int wastenumber = getIntTyp(wastetyp);
//new JDCB("placeuser", "eaL956R6yFItQVBl", "wasteinformation");
ResultSet result = Database.executeQuery(message); ResultSet result = Database.executeQuery(message);
try { try {
while (result.next()) { while (result.next()) {
String temptime = String.valueOf(result.getString("pickupdate")); String newDate = getDateDatabase(String.valueOf(result.getString("pickupdate")));
String currentDate = getcurrentDate();
String newDate = getDate(temptime);
GregorianCalendar now = new GregorianCalendar();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
String date = df.format(now.getTime());
String[] partstwo = date.split(",");
String Datetomorrow = nexDayDate(); String Datetomorrow = nexDayDate();
int abholtag; if (currentDate.equals(newDate) || currentDate.equals(Datetomorrow)) {
if (partstwo[0].equals(newDate) || partstwo[0].equals(Datetomorrow)) { transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + 1);
abholtag = 1;
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + abholtag);
} else { } else {
abholtag = 0; transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + 0);
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + abholtag);
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -110,8 +99,7 @@ public class mqtt {
String temp = dateFormat.format(currentDatePlusOne); String temp = dateFormat.format(currentDatePlusOne);
String split[] = temp.split("/"); String split[] = temp.split("/");
String newDate = split[2] + "." + split[1] + "." + split[0]; return split[2] + "." + split[1] + "." + split[0];
return newDate;
} }
private String getTyp(int number) { private String getTyp(int number) {
@ -141,13 +129,19 @@ public class mqtt {
return number; return number;
} }
private String getDate(String temptime) { private String getDateDatabase(String temptime) {
GregorianCalendar now = new GregorianCalendar();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
String[] parts = temptime.split("-"); String[] parts = temptime.split("-");
String tempyear = parts[0]; String tempyear = parts[0];
String[] yearsplit = tempyear.split("0"); String[] yearsplit = tempyear.split("0");
String tempyearnew = yearsplit[1]; String tempyearnew = yearsplit[1];
return parts[2] + "." + parts[1] + "." + tempyearnew; return parts[2] + "." + parts[1] + "." + tempyearnew;
} }
private String getcurrentDate() {
GregorianCalendar now = new GregorianCalendar();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
String date = df.format(now.getTime());
String[] partstwo = date.split(",");
return partstwo[0];
}
} }

View File

@ -41,7 +41,7 @@ public class mqttreceiver {
client.subscribe("TopicIn"); client.subscribe("TopicIn");
Log.debug("subscribed topic"); Log.debug("subscribed topic");
} catch (MqttException e) { } catch (MqttException e) {
Log.error("Connection to the ESB was failed"); Log.error("Connection to the ESB failed");
} }
return message; return message;
} }