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"> <component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" /> <option name="languageLevel" value="ES6" />
</component> </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" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -5,6 +5,7 @@ import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDCB; import com.wasteinformationserver.db.JDCB;
import com.wasteinformationserver.mqtt.mqtt; import com.wasteinformationserver.mqtt.mqtt;
import com.wasteinformationserver.website.Webserver; import com.wasteinformationserver.website.Webserver;
import java.io.IOException; import java.io.IOException;
public class main { public class main {
@ -26,15 +27,15 @@ public class main {
})); }));
Info.init(); Info.init();
Log.info("Server version: "+Info.getVersion()); Log.info("Server version: " + Info.getVersion());
Log.debug("Build date: "+Info.getBuilddate()); Log.debug("Build date: " + Info.getBuilddate());
//initial connect to db //initial connect to db
Log.message("initial login to db"); Log.message("initial login to db");
new Thread(() -> { new Thread(() -> {
try { try {
JDCB.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306); //JDCB.init("users", "admin0", "wasteinformation", "192.168.65.15", 1883);
//JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306); JDCB.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
} catch (IOException e) { } catch (IOException e) {
//e.printStackTrace(); //e.printStackTrace();
Log.error("no connection to db"); Log.error("no connection to db");

View File

@ -43,7 +43,8 @@ public class mqtt {
String temp = e.getActionCommand(); String temp = e.getActionCommand();
String[] split = temp.split(","); 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(); mr.getmessage();
@ -52,49 +53,41 @@ public class mqtt {
public void getDatabasedata(String message, String wastetyp, int clientidentify) { public void getDatabasedata(String message, String wastetyp, int clientidentify) {
Log.debug(message); Log.debug(message);
Log.debug(wastetyp);
Log.debug(clientidentify);
JDCB Database = null; JDCB Database = null;
try { try {
Database = JDCB.getInstance(); Database = JDCB.getInstance();
} catch (IOException e) { } catch (IOException e) {
Log.error("No Connection to the databank"); Log.error("No Connection to the databank");
} }
int wastenumber = getIntTyp(wastetyp);
//new JDCB("placeuser", "eaL956R6yFItQVBl", "wasteinformation"); //new JDCB("placeuser", "eaL956R6yFItQVBl", "wasteinformation");
ResultSet result = Database.executeQuery(message); ResultSet result = Database.executeQuery(message);
try { try {
if (!result.isBeforeFirst()) { while (result.next()) {
int abholtag = 0; String temptime = String.valueOf(result.getString("pickupdate"));
transmitmessageAbfallart(clientidentify + "," + wastetyp + "," + abholtag);
} else {
while (result.next()) {
String temptime = String.valueOf(result.getString("pickupdate"));
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 Datetomorrow = nexDayDate();
int abholtag; String newDate = getDate(temptime);
if (partstwo[0].contains(newDate) || partstwo[0].contains(Datetomorrow)) { GregorianCalendar now = new GregorianCalendar();
abholtag = 1; DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
transmitmessageAbfallart(clientidentify + "," + wastetyp + "," + abholtag); String date = df.format(now.getTime());
} else { String[] partstwo = date.split(",");
abholtag = 0; String Datetomorrow = nexDayDate();
transmitmessageAbfallart(clientidentify + "," + wastetyp + "," + abholtag);
}
int abholtag;
if (partstwo[0].equals(newDate) || partstwo[0].equals(Datetomorrow)) {
abholtag = 1;
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + abholtag);
} else {
abholtag = 0;
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + abholtag);
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
Log.error("No data from database"); Log.error("No data from database");
} }
} }
@ -120,4 +113,41 @@ public class mqtt {
String newDate = split[2] + "." + split[1] + "." + split[0]; String newDate = split[2] + "." + split[1] + "." + split[0];
return newDate; 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;
}
} }