Update DBPlan.cpp
This commit is contained in:
@@ -3,374 +3,568 @@
|
|||||||
DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) { };
|
DBPlan::DBPlan(std::string connStr) : DBHandler(connStr) { };
|
||||||
|
|
||||||
void DBPlan::vertretung(std::string tag, std::string stunde, std::string dauer) {
|
void DBPlan::vertretung(std::string tag, std::string stunde, std::string dauer) {
|
||||||
try {
|
try {
|
||||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||||
std::string cap = std::to_string(18 - std::stoi(dauer));
|
std::string cap = std::to_string(18 - std::stoi(dauer));
|
||||||
std::string nextStunde;
|
std::string nextStunde;
|
||||||
std::string nextTag = tag;
|
std::string nextTag = tag;
|
||||||
std::string prevTag = tag;
|
std::string prevTag = tag;
|
||||||
if (dauer == "4")
|
if (dauer == "4") {
|
||||||
nextStunde = std::to_string(std::stoi(stunde) + 2);
|
|
||||||
else
|
nextStunde = std::to_string(std::stoi(stunde) + 2);
|
||||||
nextStunde = std::to_string(std::stoi(stunde) + 1);
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
if (prevStunde == "0") {
|
if (prevStunde == "0") {
|
||||||
prevStunde = "5";
|
prevStunde = "5";
|
||||||
prevTag = std::to_string(std::stoi(tag) - 1);
|
prevTag = std::to_string(std::stoi(tag) - 1);
|
||||||
if (prevTag == "0")
|
if (prevTag == "0") {
|
||||||
prevTag = "5";
|
prevTag = "5";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (nextStunde == "6") {
|
if (nextStunde == "6") {
|
||||||
nextStunde = "1";
|
nextStunde = "1";
|
||||||
nextTag = std::to_string(std::stoi(tag) + 1);
|
nextTag = std::to_string(std::stoi(tag)+1);
|
||||||
if (nextTag == "6")
|
if (nextTag == "6") {
|
||||||
nextTag = "1";
|
nextTag = "1";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pqxx::work worker(connectionObject);
|
pqxx::work worker(connectionObject);
|
||||||
|
|
||||||
std::string query = R"(
|
|
||||||
UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID =
|
std::string query =
|
||||||
(SELECT ID FROM Veranstalter WHERE ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)
|
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = "
|
||||||
AND ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $3 AND tag = $4) LIMIT 1) WHERE uhrzeit_id = $5 AND tag = $6; )";
|
"(SELECT ID FROM Veranstalter WHERE ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2) "
|
||||||
|
"AND ID != (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $3 AND tag = $4) LIMIT 1) WHERE uhrzeit_id = $5 AND tag = $6; ";
|
||||||
|
|
||||||
|
|
||||||
worker.exec_params(query, prevStunde, prevTag, nextStunde, nextTag, stunde, tag);
|
pqxx::result response = worker.exec_params(query, prevStunde, prevTag, nextStunde, nextTag, stunde, tag);
|
||||||
worker.commit( );
|
|
||||||
}
|
worker.commit();
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::sucheVertretung(std::string tag, std::string stunde) {
|
void DBPlan::sucheVertretung(std::string tag, std::string stunde) {
|
||||||
std::string dauer = getDauer(tag, stunde);
|
std::string dauer = getDauer(tag, stunde);
|
||||||
vertretung(tag, stunde, dauer);
|
vertretung(tag, stunde, dauer);
|
||||||
incarbeitszeit(tag, stunde, dauer);
|
incarbeitszeit(tag, stunde, dauer);
|
||||||
|
|
||||||
|
if (dauer == "4") {
|
||||||
|
upperHour(tag, stunde);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (dauer == "4")
|
|
||||||
upperHour(tag, stunde);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::meldeKrank(std::string id, std::string tag, std::string stunde) {
|
void DBPlan::meldeKrank(std::string id, std::string tag, std::string stunde) {
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("UPDATE Veranstalter SET krank = TRUE WHERE ID = $1", id);
|
try {
|
||||||
worker.commit( );
|
|
||||||
|
pqxx::work worker(connectionObject);
|
||||||
|
std::string query =
|
||||||
|
"UPDATE Veranstalter SET krank = TRUE WHERE ID = $1;";
|
||||||
|
|
||||||
sucheVertretung(tag, stunde);
|
pqxx::result response = worker.exec_params(query, id);
|
||||||
meldeGesund(id);
|
worker.commit();
|
||||||
versendeEmails( );
|
|
||||||
}
|
sucheVertretung(tag, stunde);
|
||||||
catch (const std::exception& e) {
|
meldeGesund(id);
|
||||||
fmt::print(e.what( ));
|
versendeEmails();
|
||||||
}
|
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DBPlan::meldeGesund(std::string id) {
|
void DBPlan::meldeGesund(std::string id) {
|
||||||
try {
|
try {
|
||||||
pqxx::work worker(connectionObject);
|
pqxx::work worker(connectionObject);
|
||||||
|
std::string query =
|
||||||
|
"UPDATE Veranstalter SET krank = FALSE WHERE ID = $1;";
|
||||||
|
|
||||||
worker.exec_params("UPDATE Veranstalter SET krank = FALSE WHERE ID = $1", id);
|
pqxx::result response = worker.exec_params(query, id);
|
||||||
worker.commit( );
|
worker.commit();
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
fmt::print(e.what( ));
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::deleteVeranstalterForeign(std::string id) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = NULL WHERE Veranstalter_ID = $1;", id);
|
|
||||||
worker.commit( );
|
|
||||||
versendeEmails( );
|
void DBPlan::deleteVeranstalterForeign(std::string id) {
|
||||||
}
|
try {
|
||||||
catch (const std::exception& e) {
|
pqxx::work worker(connectionObject);
|
||||||
fmt::print(e.what( ));
|
std::string query =
|
||||||
}
|
"SELECT tag, uhrzeit_id FROM Veranstalter_Veranstaltung_Uhrzeit WHERE Veranstalter_ID = $1; ";
|
||||||
|
|
||||||
|
//get times where id in plan
|
||||||
|
//for each search vertretung
|
||||||
|
|
||||||
|
pqxx::result response = worker.exec_params(query, id);
|
||||||
|
worker.commit();
|
||||||
|
|
||||||
|
std::string tag, stunde;
|
||||||
|
|
||||||
|
for (int i = 0; i < response.affected_rows(); i++) {
|
||||||
|
tag = response[i][0].c_str();
|
||||||
|
stunde = response[i][1].c_str();
|
||||||
|
sucheVertretung(tag, stunde);
|
||||||
|
if (getDauer(tag, stunde) == "4")
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::deleteVeranstalter(std::string id) {
|
void DBPlan::deleteVeranstalter(std::string id) {
|
||||||
try {
|
|
||||||
deleteVeranstalterForeign(id);
|
|
||||||
|
|
||||||
pqxx::work worker(connectionObject);
|
deleteVeranstalterForeign(id);
|
||||||
|
|
||||||
|
try {
|
||||||
|
pqxx::work worker(connectionObject);
|
||||||
|
std::string query =
|
||||||
|
"DELETE FROM Veranstalter WHERE ID = $1;";
|
||||||
|
|
||||||
worker.exec_params("DELETE FROM Veranstalter WHERE ID = $1;", id);
|
pqxx::result response = worker.exec_params(query, id);
|
||||||
worker.commit( );
|
worker.commit();
|
||||||
}
|
versendeEmails();
|
||||||
catch (const std::exception& e) {
|
}
|
||||||
fmt::print(e.what( ));
|
catch (const std::exception& e) {
|
||||||
}
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::deleteVeranstaltungForeign(std::string name) {
|
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("DELETE FROM Veranstalter_Veranstaltung_Uhrzeit WHERE Veranstaltung_ID = (SELECT ID FROM Veranstaltung WHERE name = '$1');", name);
|
|
||||||
worker.commit( );
|
|
||||||
|
|
||||||
versendeEmails( );
|
|
||||||
}
|
void DBPlan::deleteVeranstaltung(std::string name) {
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
try {
|
||||||
}
|
pqxx::work worker(connectionObject);
|
||||||
|
std::string query =
|
||||||
|
"DELETE FROM Veranstaltung WHERE name = $1;";
|
||||||
|
|
||||||
|
pqxx::result response = worker.exec_params(query, name);
|
||||||
|
worker.commit();
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::deleteVeranstaltung(std::string id) {
|
|
||||||
try {
|
|
||||||
//deleteVeranstaltungForeign(id);
|
|
||||||
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("DELETE FROM Veranstaltung WHERE name = $1;", id);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DBPlan::hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum) {
|
void DBPlan::hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum) {
|
||||||
try {
|
try {
|
||||||
pqxx::work worker(connectionObject);
|
pqxx::work worker(connectionObject);
|
||||||
worker.exec_params("INSERT INTO Veranstaltung (name, dauer, ort, raum) VALUES ($1, $2, $3, $4);", name, dauer, ort, raum);
|
std::string query =
|
||||||
worker.commit( );
|
"INSERT INTO Veranstaltung (name, dauer, ort, raum) VALUES ($1, $2, $3, $4);";
|
||||||
}
|
pqxx::result response = worker.exec_params(query, name, dauer, ort, raum);
|
||||||
catch (const std::exception& e) {
|
worker.commit();
|
||||||
fmt::print(e.what( ));
|
}
|
||||||
}
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DBPlan::hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin) {
|
void DBPlan::hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin) {
|
||||||
try {
|
try {
|
||||||
pqxx::work worker(connectionObject);
|
pqxx::work worker(connectionObject);
|
||||||
|
std::string query =
|
||||||
|
"INSERT INTO Veranstaltung (email, name, pw, admin) VALUES ($1, $2, $3, $4);";
|
||||||
|
pqxx::result response = worker.exec_params(query, email, name, pw, admin);
|
||||||
|
worker.commit();
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
worker.exec_params("INSERT INTO Veranstalter (email, name, passwort, admin) VALUES ($1, $2, $3, $4);", email, name, pw, admin);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DBPlan::deleteStudent(std::string id) {
|
void DBPlan::deleteStudent(std::string id) {
|
||||||
try {
|
try {
|
||||||
pqxx::work worker(connectionObject);
|
pqxx::work worker(connectionObject);
|
||||||
|
std::string query =
|
||||||
|
"DELETE FROM studenten WHERE ID = $1;";
|
||||||
|
pqxx::result response = worker.exec_params(query, id);
|
||||||
|
worker.commit();
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
worker.exec_params("DELETE FROM studenten WHERE ID = $1;", id);
|
|
||||||
worker.commit( );
|
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DBPlan::hinzufuegenStudent(std::string email, std::string name, std::string pw) {
|
void DBPlan::hinzufuegenStudent(std::string email, std::string name, std::string pw) {
|
||||||
try {
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
worker.exec_params("INSERT INTO studenten (email, name, pw) VALUES ($1, $2, $3);", email, name, pw);
|
try {
|
||||||
worker.commit( );
|
pqxx::work worker(connectionObject);
|
||||||
}
|
std::string query =
|
||||||
catch (const std::exception& e) {
|
"INSERT INTO studenten (email, name, pw) VALUES ($1, $2, $3);";
|
||||||
fmt::print(e.what( ));
|
pqxx::result response = worker.exec_params(query, email, name, pw);
|
||||||
}
|
worker.commit();
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
std::string DBPlan::getDauer(std::string tag, std::string stunde) {
|
std::string DBPlan::getDauer(std::string tag, std::string stunde) {
|
||||||
try {
|
try {
|
||||||
pqxx::work worker(connectionObject);
|
pqxx::work worker(connectionObject);
|
||||||
|
std::string query =
|
||||||
pqxx::result response = worker.exec_params(
|
"SELECT dauer FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);";
|
||||||
"SELECT dauer FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);",
|
|
||||||
stunde,
|
pqxx::result response = worker.exec_params(query, stunde, tag);
|
||||||
tag
|
|
||||||
);
|
worker.commit();
|
||||||
|
|
||||||
worker.commit( );
|
|
||||||
return response[0][0].c_str( );
|
return response[0][0].c_str();
|
||||||
}
|
}
|
||||||
catch (const std::exception& e) {
|
catch (const std::exception& e) {
|
||||||
fmt::print(e.what( ));
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
}
|
}
|
||||||
return "0";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void DBPlan::addFirstOfDayTwo(std::string tag) {
|
void DBPlan::addFirstOfDayTwo(std::string tag) {
|
||||||
try {
|
try {
|
||||||
pqxx::work worker(connectionObject);
|
pqxx::work worker(connectionObject);
|
||||||
std::string query =
|
std::string query =
|
||||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 16 AND krank = FALSE LIMIT 1)
|
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 16 AND krank = FALSE LIMIT 1) "
|
||||||
WHERE uhrzeit_id = 1 AND tag = $1;)";
|
"WHERE uhrzeit_id = 1 AND tag = $1;";
|
||||||
worker.exec_params(query, tag);
|
pqxx::result response = worker.exec_params(query, tag);
|
||||||
worker.commit( );
|
worker.commit();
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
}
|
||||||
fmt::print(e.what( ));
|
catch (const std::exception& e) {
|
||||||
}
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::addTwoHour(std::string tag, std::string stunde) {
|
void DBPlan::addTwoHour(std::string tag, std::string stunde) {
|
||||||
try {
|
try {
|
||||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
|
||||||
|
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||||
|
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
std::string query =
|
pqxx::work worker(connectionObject);
|
||||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter
|
std::string query =
|
||||||
WHERE arbeitszeit <= 16 AND krank = FALSE
|
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter "
|
||||||
AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
"WHERE arbeitszeit <= 16 AND krank = FALSE "
|
||||||
AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
"AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||||
ORDER BY random() LIMIT 1)
|
"AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||||
WHERE uhrzeit_id = $3 AND tag = $4;)";
|
"ORDER BY random() LIMIT 1) "
|
||||||
worker.exec_params(query, prevStunde, tag, stunde, tag);
|
"WHERE uhrzeit_id = $3 AND tag = $4;";
|
||||||
worker.commit( );
|
pqxx::result response = worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||||
}
|
worker.commit();
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
}
|
||||||
}
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::addFirstOfDayFour(std::string tag) {
|
void DBPlan::addFirstOfDayFour(std::string tag) {
|
||||||
try {
|
try {
|
||||||
pqxx::work worker(connectionObject);
|
pqxx::work worker(connectionObject);
|
||||||
std::string query =
|
std::string query =
|
||||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 14 AND krank = FALSE LIMIT 1)
|
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT ID FROM Veranstalter WHERE arbeitszeit <= 14 AND krank = FALSE LIMIT 1) "
|
||||||
WHERE uhrzeit_id = 1 AND tag = $1;)";
|
"WHERE uhrzeit_id = 1 AND tag = $1;";
|
||||||
worker.exec_params(query, tag);
|
pqxx::result response = worker.exec_params(query, tag);
|
||||||
worker.commit( );
|
worker.commit();
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
}
|
||||||
fmt::print(e.what( ));
|
catch (const std::exception& e) {
|
||||||
}
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::addFourHour(std::string tag, std::string stunde) {
|
void DBPlan::addFourHour(std::string tag, std::string stunde) {
|
||||||
try {
|
try {
|
||||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
|
||||||
pqxx::work worker(connectionObject);
|
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||||
std::string query =
|
pqxx::work worker(connectionObject);
|
||||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter
|
std::string query =
|
||||||
WHERE arbeitszeit <= 14 AND krank = FALSE
|
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter "
|
||||||
AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
"WHERE arbeitszeit <= 14 AND krank = FALSE "
|
||||||
AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
"AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||||
ORDER BY random() LIMIT 1)
|
"AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||||
WHERE uhrzeit_id = $3 AND tag = $4;)";
|
"ORDER BY random() LIMIT 1) "
|
||||||
worker.exec_params(query, prevStunde, tag, stunde, tag);
|
"WHERE uhrzeit_id = $3 AND tag = $4;";
|
||||||
worker.commit( );
|
pqxx::result response = worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||||
}
|
worker.commit();
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
}
|
||||||
}
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::upperHour(std::string tag, std::string stunde) {
|
void DBPlan::upperHour(std::string tag, std::string stunde) {
|
||||||
try {
|
try {
|
||||||
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
|
||||||
|
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||||
|
|
||||||
pqxx::work worker(connectionObject);
|
pqxx::work worker(connectionObject);
|
||||||
std::string query =
|
std::string query =
|
||||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)
|
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)"
|
||||||
WHERE uhrzeit_id = $3 AND tag = $2;)";
|
"WHERE uhrzeit_id = $3 AND tag = $2;";
|
||||||
worker.exec_params(query, stunde, tag, nextStunde);
|
pqxx::result response = worker.exec_params(query, stunde, tag, nextStunde);
|
||||||
worker.commit( );
|
worker.commit();
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
}
|
||||||
fmt::print(e.what( ));
|
catch (const std::exception& e) {
|
||||||
}
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DBPlan::updateStandort(std::string tag, std::string stunde) {
|
void DBPlan::updateStandort(std::string tag, std::string stunde) {
|
||||||
try {
|
try {
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
std::string query =
|
|
||||||
"UPDATE Veranstalter SET standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) WHERE ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);";
|
pqxx::work worker(connectionObject);
|
||||||
worker.exec_params(query, stunde, tag);
|
std::string query =
|
||||||
worker.commit( );
|
"UPDATE Veranstalter SET standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) WHERE ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);";
|
||||||
}
|
pqxx::result response = worker.exec_params(query, stunde, tag);
|
||||||
catch (const std::exception& e) {
|
worker.commit();
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::incarbeitszeit(std::string tag, std::string stunde, std::string amount) {
|
void DBPlan::incarbeitszeit(std::string tag, std::string stunde, std::string amount) {
|
||||||
try {
|
try {
|
||||||
pqxx::work worker(connectionObject);
|
|
||||||
|
|
||||||
std::string query =
|
|
||||||
"UPDATE Veranstalter SET arbeitszeit = arbeitszeit + $1 WHERE ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $2 AND tag = $3);";
|
|
||||||
|
|
||||||
worker.exec_params(query, amount, stunde, tag);
|
pqxx::work worker(connectionObject);
|
||||||
worker.commit( );
|
|
||||||
}
|
std::string query =
|
||||||
catch (const std::exception& e) {
|
"UPDATE Veranstalter SET arbeitszeit = arbeitszeit + $1 WHERE ID = (SELECT Veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $2 AND tag = $3);";
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
pqxx::result response = worker.exec_params(query,amount, stunde, tag);
|
||||||
|
worker.commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::createPlan( ) {
|
|
||||||
try {
|
|
||||||
for (int tag = 1; tag < 6; tag++) {
|
|
||||||
std::string tagStr = std::to_string(tag);
|
|
||||||
for (int stunde = 1; stunde < 6; stunde++) {
|
|
||||||
std::string stundeStr = std::to_string(stunde);
|
|
||||||
|
|
||||||
if (std::stoi(getDauer(tagStr, stundeStr)) == 2) {
|
void DBPlan::insertVeranstaltungenIntoPlan(std::string cap, std::string tag, std::string stunde) {
|
||||||
stunde == 1 ? addFirstOfDayTwo(tagStr) : addTwoHour(tagStr, stundeStr);
|
try {
|
||||||
updateStandort(tagStr, stundeStr);
|
|
||||||
incarbeitszeit(tagStr, stundeStr, "2");
|
|
||||||
} else {
|
|
||||||
stunde == 1 ? addFirstOfDayFour(tagStr) : addFourHour(tagStr, stundeStr);
|
pqxx::work worker(connectionObject);
|
||||||
upperHour(tagStr, stundeStr);
|
std::string query =
|
||||||
incarbeitszeit(tagStr, stundeStr, "4");
|
R"(INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (Veranstaltung_ID, tag, uhrzeit_ID)
|
||||||
updateStandort(tagStr, stundeStr);
|
SELECT ID, $1, $2 FROM Veranstaltung WHERE dauer <= $3
|
||||||
stunde++;
|
ORDER BY used ASC
|
||||||
}
|
LIMIT 1;)";
|
||||||
}
|
|
||||||
}
|
worker.exec_params(query, tag, stunde, cap);
|
||||||
}
|
worker.commit();
|
||||||
catch (const std::exception& e) {
|
|
||||||
fmt::print(e.what( ));
|
std::string query2 =
|
||||||
}
|
R"(UPDATE Veranstaltung SET used = used+1 WHERE ID =
|
||||||
|
(SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE tag = $1 AND uhrzeit_id = $2); )";
|
||||||
|
|
||||||
|
worker.exec_params(query2, tag, stunde);
|
||||||
|
worker.commit();
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> DBPlan::getPlan( ) {
|
void DBPlan::insertAgain(std::string tag, std::string stunde) {
|
||||||
createPlan( );
|
try {
|
||||||
try {
|
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||||
std::vector<std::string> plan;
|
|
||||||
|
|
||||||
pqxx::work worker(connectionObject);
|
pqxx::work worker(connectionObject);
|
||||||
|
|
||||||
std::string query =
|
std::string query =
|
||||||
R"(SELECT tag, u.anfangszeit, u.endzeit, o.ort, o.name, v.name, o.raum, v.ID FROM Veranstalter_Veranstaltung_Uhrzeit
|
R"(INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (Veranstaltung_ID, tag, uhrzeit_ID)
|
||||||
|
SELECT Veranstaltung_ID, $1, $2 FROM Veranstalter_Veranstaltung_Uhrzeit WHERE tag = $3 AND uhrzeit_id = $4;)";
|
||||||
|
|
||||||
|
worker.exec_params(query, tag, nextStunde, tag, stunde);
|
||||||
|
worker.commit();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBPlan::insertVeranstaltungIntoPlanHandler() {
|
||||||
|
|
||||||
|
int timeDay;
|
||||||
|
for (int i = 1; i <= 5; i++) {
|
||||||
|
timeDay = 1;
|
||||||
|
|
||||||
|
while (timeDay <= 5) {
|
||||||
|
std::string tagStr = std::to_string(i);
|
||||||
|
std::string stundeStr = std::to_string(timeDay);
|
||||||
|
if (timeDay == 5) {
|
||||||
|
insertVeranstaltungenIntoPlan("2", tagStr, stundeStr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
insertVeranstaltungenIntoPlan("4", tagStr, stundeStr);
|
||||||
|
|
||||||
|
if (getDauer(tagStr, stundeStr) == "4") {
|
||||||
|
insertAgain(tagStr, stundeStr);
|
||||||
|
timeDay++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
timeDay++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void DBPlan::createPlan() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
insertVeranstaltungIntoPlanHandler();
|
||||||
|
for (int tag = 1; tag < 6; tag++) {
|
||||||
|
std::string tagStr = std::to_string(tag);
|
||||||
|
for (int stunde = 1; stunde < 6; stunde++) {
|
||||||
|
std::string stundeStr = std::to_string(stunde);
|
||||||
|
//get dauer of next class
|
||||||
|
|
||||||
|
if (std::stoi(getDauer(tagStr, stundeStr)) == 2) {
|
||||||
|
if (stunde == 1) {
|
||||||
|
addFirstOfDayTwo(tagStr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addTwoHour(tagStr, stundeStr);
|
||||||
|
}
|
||||||
|
updateStandort(tagStr, stundeStr);
|
||||||
|
incarbeitszeit(tagStr, stundeStr, "2");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (stunde == 1) {
|
||||||
|
addFirstOfDayFour(tagStr);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
addFourHour(tagStr, stundeStr);
|
||||||
|
}
|
||||||
|
upperHour(tagStr, stundeStr);
|
||||||
|
incarbeitszeit(tagStr, stundeStr, "4");
|
||||||
|
updateStandort(tagStr, stundeStr);
|
||||||
|
stunde++;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string DBPlan::checkPlanSize() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
|
||||||
|
pqxx::work worker(connectionObject);
|
||||||
|
|
||||||
|
std::string query =
|
||||||
|
"SELECT count(*) FROM Veranstalter_Veranstaltung_Uhrzeit;";
|
||||||
|
|
||||||
|
pqxx::result response = worker.exec(query);
|
||||||
|
worker.commit();
|
||||||
|
|
||||||
|
return response[0][0].c_str();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> DBPlan::getPlan() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (checkPlanSize() == "0")
|
||||||
|
createPlan();
|
||||||
|
|
||||||
|
std::vector<std::string> plan;
|
||||||
|
|
||||||
|
pqxx::work worker(connectionObject);
|
||||||
|
|
||||||
|
std::string query =
|
||||||
|
R"(SELECT tag, u.anfangszeit, u.endzeit, o.ort, o.name, v.name, o.raum, v.ID FROM Veranstalter_Veranstaltung_Uhrzeit
|
||||||
JOIN Veranstalter v ON Veranstalter_Veranstaltung_Uhrzeit.veranstalter_ID = v.ID
|
JOIN Veranstalter v ON Veranstalter_Veranstaltung_Uhrzeit.veranstalter_ID = v.ID
|
||||||
JOIN Uhrzeit u ON Veranstalter_Veranstaltung_Uhrzeit.uhrzeit_ID = u.ID
|
JOIN Uhrzeit u ON Veranstalter_Veranstaltung_Uhrzeit.uhrzeit_ID = u.ID
|
||||||
JOIN Veranstaltung o ON Veranstalter_Veranstaltung_Uhrzeit.veranstaltung_ID = o.ID
|
JOIN Veranstaltung o ON Veranstalter_Veranstaltung_Uhrzeit.veranstaltung_ID = o.ID
|
||||||
ORDER BY tag, uhrzeit_ID;)";
|
ORDER BY tag, uhrzeit_ID;)";
|
||||||
|
|
||||||
pqxx::result response = worker.exec(query);
|
pqxx::result response = worker.exec(query);
|
||||||
worker.commit( );
|
worker.commit();
|
||||||
|
|
||||||
for (const auto& row : response) {
|
for (const auto& row : response) {
|
||||||
std::string rowstring;
|
std::string rowstring;
|
||||||
for (const auto& col : row) {
|
for (const auto& col : row) {
|
||||||
rowstring.append(col.c_str( ));
|
rowstring.append(col.c_str());
|
||||||
rowstring.append(",");
|
rowstring.append(",");
|
||||||
}
|
}
|
||||||
plan.push_back(rowstring);
|
plan.push_back(rowstring);
|
||||||
}
|
|
||||||
return plan;
|
}
|
||||||
}
|
|
||||||
catch (const std::exception& e) {
|
return plan;
|
||||||
fmt::print(e.what( ));
|
|
||||||
}
|
|
||||||
return std::vector<std::string>{ "" };
|
}
|
||||||
|
catch (const std::exception& e) {
|
||||||
|
std::cerr << "Error: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DBPlan::versendeEmails( ) {
|
void DBPlan::versendeEmails() {
|
||||||
fmt::print("Der Einsatzplan wurde geändert");
|
//Email an alle Nutzer
|
||||||
|
std::cout << "Der Einsatzplan wurde geupdated" << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user