Update DBPlan.cpp
This commit is contained in:
@@ -9,37 +9,50 @@ void DBPlan::vertretung(std::string tag, std::string stunde, std::string dauer)
|
||||
std::string nextStunde;
|
||||
std::string nextTag = tag;
|
||||
std::string prevTag = tag;
|
||||
if (dauer == "4")
|
||||
if (dauer == "4") {
|
||||
|
||||
nextStunde = std::to_string(std::stoi(stunde) + 2);
|
||||
else
|
||||
|
||||
}
|
||||
else {
|
||||
nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
|
||||
}
|
||||
|
||||
if (prevStunde == "0") {
|
||||
prevStunde = "5";
|
||||
prevTag = std::to_string(std::stoi(tag) - 1);
|
||||
if (prevTag == "0")
|
||||
if (prevTag == "0") {
|
||||
prevTag = "5";
|
||||
}
|
||||
}
|
||||
|
||||
if (nextStunde == "6") {
|
||||
nextStunde = "1";
|
||||
nextTag = std::to_string(std::stoi(tag) + 1);
|
||||
if (nextTag == "6")
|
||||
nextTag = std::to_string(std::stoi(tag)+1);
|
||||
if (nextTag == "6") {
|
||||
nextTag = "1";
|
||||
}
|
||||
}
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query = R"(
|
||||
UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID =
|
||||
(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);
|
||||
worker.commit( );
|
||||
std::string query =
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = "
|
||||
"(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; ";
|
||||
|
||||
|
||||
pqxx::result response = worker.exec_params(query, prevStunde, prevTag, nextStunde, nextTag, stunde, tag);
|
||||
|
||||
worker.commit();
|
||||
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,190 +61,238 @@ void DBPlan::sucheVertretung(std::string tag, std::string stunde) {
|
||||
vertretung(tag, stunde, dauer);
|
||||
incarbeitszeit(tag, stunde, dauer);
|
||||
|
||||
if (dauer == "4")
|
||||
if (dauer == "4") {
|
||||
upperHour(tag, 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);
|
||||
worker.commit( );
|
||||
try {
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"UPDATE Veranstalter SET krank = TRUE WHERE ID = $1;";
|
||||
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
|
||||
sucheVertretung(tag, stunde);
|
||||
meldeGesund(id);
|
||||
versendeEmails( );
|
||||
versendeEmails();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::meldeGesund(std::string id) {
|
||||
try {
|
||||
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);
|
||||
worker.commit( );
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
}
|
||||
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);
|
||||
std::string query =
|
||||
"SELECT tag, uhrzeit_id FROM Veranstalter_Veranstaltung_Uhrzeit WHERE Veranstalter_ID = $1; ";
|
||||
|
||||
worker.exec_params("UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_ID = NULL WHERE Veranstalter_ID = $1;", id);
|
||||
worker.commit( );
|
||||
versendeEmails( );
|
||||
//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) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::deleteVeranstalter(std::string id) {
|
||||
try {
|
||||
|
||||
deleteVeranstalterForeign(id);
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("DELETE FROM Veranstalter WHERE ID = $1;", id);
|
||||
worker.commit( );
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::deleteVeranstaltungForeign(std::string name) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"DELETE FROM Veranstalter WHERE ID = $1;";
|
||||
|
||||
worker.exec_params("DELETE FROM Veranstalter_Veranstaltung_Uhrzeit WHERE Veranstaltung_ID = (SELECT ID FROM Veranstaltung WHERE name = '$1');", name);
|
||||
worker.commit( );
|
||||
|
||||
versendeEmails( );
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
versendeEmails();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::deleteVeranstaltung(std::string id) {
|
||||
|
||||
|
||||
|
||||
void DBPlan::deleteVeranstaltung(std::string name) {
|
||||
|
||||
try {
|
||||
//deleteVeranstaltungForeign(id);
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"DELETE FROM Veranstaltung WHERE name = $1;";
|
||||
|
||||
worker.exec_params("DELETE FROM Veranstaltung WHERE name = $1;", id);
|
||||
worker.commit( );
|
||||
pqxx::result response = worker.exec_params(query, name);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::hinzufuegenVeranstaltung(std::string name, std::string dauer, std::string ort, std::string raum) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
worker.exec_params("INSERT INTO Veranstaltung (name, dauer, ort, raum) VALUES ($1, $2, $3, $4);", name, dauer, ort, raum);
|
||||
worker.commit( );
|
||||
std::string query =
|
||||
"INSERT INTO Veranstaltung (name, dauer, ort, raum) VALUES ($1, $2, $3, $4);";
|
||||
pqxx::result response = worker.exec_params(query, name, dauer, ort, raum);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::hinzufuegenVeranstalter(std::string email, std::string name, std::string pw, std::string admin) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("INSERT INTO Veranstalter (email, name, passwort, admin) VALUES ($1, $2, $3, $4);", email, name, pw, admin);
|
||||
worker.commit( );
|
||||
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) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::deleteStudent(std::string id) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
worker.exec_params("DELETE FROM studenten WHERE ID = $1;", id);
|
||||
worker.commit( );
|
||||
std::string query =
|
||||
"DELETE FROM studenten WHERE ID = $1;";
|
||||
pqxx::result response = worker.exec_params(query, id);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
worker.commit( );
|
||||
std::string query =
|
||||
"INSERT INTO studenten (email, name, pw) VALUES ($1, $2, $3);";
|
||||
pqxx::result response = worker.exec_params(query, email, name, pw);
|
||||
worker.commit();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string DBPlan::getDauer(std::string tag, std::string stunde) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
"SELECT dauer FROM Veranstaltung WHERE ID = (SELECT Veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2);";
|
||||
|
||||
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);",
|
||||
stunde,
|
||||
tag
|
||||
);
|
||||
pqxx::result response = worker.exec_params(query, stunde, tag);
|
||||
|
||||
worker.commit( );
|
||||
return response[0][0].c_str( );
|
||||
worker.commit();
|
||||
|
||||
|
||||
return response[0][0].c_str();
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void DBPlan::addFirstOfDayTwo(std::string tag) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(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;)";
|
||||
worker.exec_params(query, tag);
|
||||
worker.commit( );
|
||||
"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;";
|
||||
pqxx::result response = worker.exec_params(query, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::addTwoHour(std::string tag, std::string stunde) {
|
||||
try {
|
||||
|
||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter
|
||||
WHERE arbeitszeit <= 16 AND krank = FALSE
|
||||
AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
||||
AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
||||
ORDER BY random() LIMIT 1)
|
||||
WHERE uhrzeit_id = $3 AND tag = $4;)";
|
||||
worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||
worker.commit( );
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter "
|
||||
"WHERE arbeitszeit <= 16 AND krank = FALSE "
|
||||
"AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||
"AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||
"ORDER BY random() LIMIT 1) "
|
||||
"WHERE uhrzeit_id = $3 AND tag = $4;";
|
||||
pqxx::result response = worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,108 +300,237 @@ void DBPlan::addFirstOfDayFour(std::string tag) {
|
||||
try {
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(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;)";
|
||||
worker.exec_params(query, tag);
|
||||
worker.commit( );
|
||||
"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;";
|
||||
pqxx::result response = worker.exec_params(query, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::addFourHour(std::string tag, std::string stunde) {
|
||||
try {
|
||||
|
||||
std::string prevStunde = std::to_string(std::stoi(stunde) - 1);
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter
|
||||
WHERE arbeitszeit <= 14 AND krank = FALSE
|
||||
AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
||||
AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2))
|
||||
ORDER BY random() LIMIT 1)
|
||||
WHERE uhrzeit_id = $3 AND tag = $4;)";
|
||||
worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||
worker.commit( );
|
||||
"UPDATE Veranstalter_Veranstaltung_Uhrzeit SET Veranstalter_id = (SELECT ID FROM Veranstalter "
|
||||
"WHERE arbeitszeit <= 14 AND krank = FALSE "
|
||||
"AND(standort = (SELECT ort FROM Veranstaltung WHERE ID = (SELECT veranstaltung_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||
"AND ID != (SELECT veranstalter_ID FROM Veranstalter_Veranstaltung_Uhrzeit WHERE uhrzeit_id = $1 AND tag = $2)) "
|
||||
"ORDER BY random() LIMIT 1) "
|
||||
"WHERE uhrzeit_id = $3 AND tag = $4;";
|
||||
pqxx::result response = worker.exec_params(query, prevStunde, tag, stunde, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::upperHour(std::string tag, std::string stunde) {
|
||||
try {
|
||||
|
||||
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
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)
|
||||
WHERE uhrzeit_id = $3 AND tag = $2;)";
|
||||
worker.exec_params(query, stunde, tag, nextStunde);
|
||||
worker.commit( );
|
||||
"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;";
|
||||
pqxx::result response = worker.exec_params(query, stunde, tag, nextStunde);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DBPlan::updateStandort(std::string tag, std::string stunde) {
|
||||
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);";
|
||||
worker.exec_params(query, stunde, tag);
|
||||
worker.commit( );
|
||||
pqxx::result response = worker.exec_params(query, stunde, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::incarbeitszeit(std::string tag, std::string stunde, std::string amount) {
|
||||
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);
|
||||
worker.commit( );
|
||||
pqxx::result response = worker.exec_params(query,amount, stunde, tag);
|
||||
worker.commit();
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::createPlan( ) {
|
||||
|
||||
void DBPlan::insertVeranstaltungenIntoPlan(std::string cap, std::string tag, std::string stunde) {
|
||||
try {
|
||||
|
||||
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
std::string query =
|
||||
R"(INSERT INTO Veranstalter_Veranstaltung_Uhrzeit (Veranstaltung_ID, tag, uhrzeit_ID)
|
||||
SELECT ID, $1, $2 FROM Veranstaltung WHERE dauer <= $3
|
||||
ORDER BY used ASC
|
||||
LIMIT 1;)";
|
||||
|
||||
worker.exec_params(query, tag, stunde, cap);
|
||||
worker.commit();
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void DBPlan::insertAgain(std::string tag, std::string stunde) {
|
||||
try {
|
||||
std::string nextStunde = std::to_string(std::stoi(stunde) + 1);
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
|
||||
std::string query =
|
||||
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) {
|
||||
stunde == 1 ? addFirstOfDayTwo(tagStr) : addTwoHour(tagStr, stundeStr);
|
||||
if (stunde == 1) {
|
||||
addFirstOfDayTwo(tagStr);
|
||||
}
|
||||
else {
|
||||
addTwoHour(tagStr, stundeStr);
|
||||
}
|
||||
updateStandort(tagStr, stundeStr);
|
||||
incarbeitszeit(tagStr, stundeStr, "2");
|
||||
} else {
|
||||
stunde == 1 ? addFirstOfDayFour(tagStr) : addFourHour(tagStr, stundeStr);
|
||||
}
|
||||
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) {
|
||||
fmt::print(e.what( ));
|
||||
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( ) {
|
||||
createPlan( );
|
||||
std::vector<std::string> DBPlan::getPlan() {
|
||||
try {
|
||||
|
||||
if (checkPlanSize() == "0")
|
||||
createPlan();
|
||||
|
||||
std::vector<std::string> plan;
|
||||
|
||||
pqxx::work worker(connectionObject);
|
||||
@@ -353,24 +543,28 @@ std::vector<std::string> DBPlan::getPlan( ) {
|
||||
ORDER BY tag, uhrzeit_ID;)";
|
||||
|
||||
pqxx::result response = worker.exec(query);
|
||||
worker.commit( );
|
||||
worker.commit();
|
||||
|
||||
for (const auto& row : response) {
|
||||
std::string rowstring;
|
||||
for (const auto& col : row) {
|
||||
rowstring.append(col.c_str( ));
|
||||
rowstring.append(col.c_str());
|
||||
rowstring.append(",");
|
||||
}
|
||||
plan.push_back(rowstring);
|
||||
|
||||
}
|
||||
|
||||
return plan;
|
||||
|
||||
|
||||
}
|
||||
catch (const std::exception& e) {
|
||||
fmt::print(e.what( ));
|
||||
std::cerr << "Error: " << e.what() << std::endl;
|
||||
}
|
||||
return std::vector<std::string>{ "" };
|
||||
}
|
||||
|
||||
void DBPlan::versendeEmails( ) {
|
||||
fmt::print("Der Einsatzplan wurde geändert");
|
||||
void DBPlan::versendeEmails() {
|
||||
//Email an alle Nutzer
|
||||
std::cout << "Der Einsatzplan wurde geupdated" << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user