Merge remote-tracking branch 'origin/master'

This commit is contained in:
lukas-heiligenbrunner 2019-12-13 14:58:13 +01:00
commit e26258c3cf
3 changed files with 63 additions and 32 deletions

View File

@ -4,7 +4,7 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" default="true" project-jdk-name="13" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -5,6 +5,7 @@ import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB;
import com.wasteinformationserver.mqtt.mqtt;
import com.wasteinformationserver.website.Webserver;
import java.io.IOException;
public class main {
@ -26,15 +27,15 @@ public class main {
}));
Info.init();
Log.info("Server version: "+Info.getVersion());
Log.debug("Build date: "+Info.getBuilddate());
Log.info("Server version: " + Info.getVersion());
Log.debug("Build date: " + Info.getBuilddate());
//initial connect to db
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");

View File

@ -43,7 +43,8 @@ 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]));
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();
@ -52,49 +53,41 @@ public class mqtt {
public void getDatabasedata(String message, String wastetyp, int clientidentify) {
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);
//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()) {
String temptime = String.valueOf(result.getString("pickupdate"));
String newDate = getDate(temptime);
GregorianCalendar now = new GregorianCalendar();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
String date = df.format(now.getTime());
String[] parts = temptime.split("-");
String tempyear = parts[0];
String[] yearsplit = tempyear.split("0");
String tempyearnew = yearsplit[1];
String newDate = parts[2] + "." + parts[1] + ".20" + tempyearnew;
String[] partstwo = date.split(" ");
String[] partstwo = date.split(",");
String Datetomorrow = nexDayDate();
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 +113,41 @@ 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;
}
private String getDate(String temptime) {
GregorianCalendar now = new GregorianCalendar();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
String[] parts = temptime.split("-");
String tempyear = parts[0];
String[] yearsplit = tempyear.split("0");
String tempyearnew = yearsplit[1];
return parts[2] + "." + parts[1] + "." + tempyearnew;
}
}