Implemented api for soll ist time

This commit is contained in:
0xFEEDC0DE64
2018-05-25 20:17:48 +02:00
parent 660390afa9
commit a2a7d29b11
11 changed files with 196 additions and 30 deletions

View File

@@ -59,12 +59,12 @@ void GetAbsencesReply::requestFinished()
m_absences.append({ m_absences.append({
obj.value(QStringLiteral("altRepresentative")).toInt(), obj.value(QStringLiteral("altRepresentative")).toInt(),
obj.value(QStringLiteral("compositeId")).toString(), obj.value(QStringLiteral("compositeId")).toString(),
QDate::fromString(QString::number(obj.value(QStringLiteral("end")).toInt()), QStringLiteral("yyyyMMdd")), parseDate(obj.value(QStringLiteral("end"))),
obj.value(QStringLiteral("hourCategory")).toString(), obj.value(QStringLiteral("hourCategory")).toString(),
obj.value(QStringLiteral("openMarking")).toString(), obj.value(QStringLiteral("openMarking")).toString(),
obj.value(QStringLiteral("persNr")).toInt(), obj.value(QStringLiteral("persNr")).toInt(),
obj.value(QStringLiteral("representative")).toInt(), obj.value(QStringLiteral("representative")).toInt(),
QDate::fromString(QString::number(obj.value(QStringLiteral("start")).toInt()), QStringLiteral("yyyyMMdd")), parseDate(obj.value(QStringLiteral("start"))),
obj.value(QStringLiteral("text")).toString() obj.value(QStringLiteral("text")).toString()
}); });
} }

View File

@@ -57,9 +57,9 @@ void GetBookingsReply::requestFinished()
m_bookings.append({ m_bookings.append({
obj.value(QStringLiteral("bookingNr")).toInt(), obj.value(QStringLiteral("bookingNr")).toInt(),
QDate::fromString(QString::number(obj.value(QStringLiteral("bookingDate")).toInt()), QStringLiteral("yyyyMMdd")), parseDate(obj.value(QStringLiteral("bookingDate"))),
QTime::fromString(QStringLiteral("%0").arg(obj.value(QStringLiteral("bookingTime")).toInt(), 6, 10, QChar('0')), QStringLiteral("HHmmss")), parseTime(obj.value(QStringLiteral("bookingTime"))),
QTime::fromString(QStringLiteral("%0").arg(obj.value(QStringLiteral("bookingTimespan")).toInt(), 6, 10, QChar('0')), QStringLiteral("HHmmss")), parseTime(obj.value(QStringLiteral("bookingTimespan"))),
obj.value(QStringLiteral("bookingType")).toString(), obj.value(QStringLiteral("bookingType")).toString(),
obj.value(QStringLiteral("text")).toString() obj.value(QStringLiteral("text")).toString()
}); });

View File

@@ -0,0 +1,74 @@
#include "getdayinforeply.h"
#include <QDebug>
#include <QJsonParseError>
#include <QJsonDocument>
#include <QJsonArray>
#include <QJsonValue>
#include <QJsonObject>
#include "zeiterfassungapi.h"
GetDayinfoReply::GetDayinfoReply(std::unique_ptr<QNetworkReply> &&reply, ZeiterfassungApi *zeiterfassung) :
ZeiterfassungReply(zeiterfassung),
m_reply(std::move(reply))
{
connect(m_reply.get(), &QNetworkReply::finished, this, &GetDayinfoReply::requestFinished);
}
const QVector<GetDayinfoReply::Dayinfo> &GetDayinfoReply::dayinfos() const
{
return m_dayinfos;
}
void GetDayinfoReply::requestFinished()
{
if(m_reply->error() != QNetworkReply::NoError)
{
setSuccess(false);
setMessage(tr("Request error occured: %0").arg(m_reply->errorString()));
goto end;
}
{
QJsonParseError error;
QJsonDocument document = QJsonDocument::fromJson(m_reply->readAll(), &error);
if(error.error != QJsonParseError::NoError)
{
setSuccess(false);
setMessage(tr("Parsing JSON failed: %0").arg(error.errorString()));
goto end;
}
if(!document.isArray())
{
setSuccess(false);
setMessage(tr("JSON document is not an array!"));
goto end;
}
auto arr = document.array();
setSuccess(true);
m_dayinfos.clear();
m_dayinfos.reserve(arr.count());
for(const auto &val : arr)
{
auto obj = val.toObject();
m_dayinfos.append({
obj.value(QStringLiteral("className")).toString(),
obj.value(QStringLiteral("persNr")).toInt(),
parseDate(obj.value(QStringLiteral("date"))),
parseTime(obj.value(QStringLiteral("ist"))),
parseTime(obj.value(QStringLiteral("soll"))),
obj.value(QStringLiteral("compositeId")).toString()
});
}
}
end:
m_reply = Q_NULLPTR;
Q_EMIT finished();
}

View File

@@ -0,0 +1,40 @@
#pragma once
#include <memory>
#include <QString>
#include <QDate>
#include <QNetworkReply>
#include <QVector>
#include "zeiterfassungcorelib_global.h"
#include "zeiterfassungreply.h"
class ZeiterfassungApi;
class ZEITERFASSUNGCORELIBSHARED_EXPORT GetDayinfoReply : public ZeiterfassungReply
{
Q_OBJECT
public:
explicit GetDayinfoReply(std::unique_ptr<QNetworkReply> &&reply, ZeiterfassungApi *zeiterfassung);
struct Dayinfo
{
QString className;
int userId;
QDate date;
QTime ist;
QTime soll;
QString compositeId;
};
const QVector<Dayinfo> &dayinfos() const;
private Q_SLOTS:
void requestFinished();
private:
std::unique_ptr<QNetworkReply> m_reply;
QVector<Dayinfo> m_dayinfos;
};

View File

@@ -60,9 +60,9 @@ void GetTimeAssignmentsReply::requestFinished()
m_timeAssignments.append({ m_timeAssignments.append({
obj.value(QStringLiteral("bookingNr")).toInt(), obj.value(QStringLiteral("bookingNr")).toInt(),
QDate::fromString(QString::number(obj.value(QStringLiteral("bookingDate")).toInt()), QStringLiteral("yyyyMMdd")), parseDate(obj.value(QStringLiteral("bookingDate"))),
QTime::fromString(QStringLiteral("%0").arg(obj.value(QStringLiteral("bookingTime")).toInt(), 6, 10, QChar('0')), QStringLiteral("HHmmss")), parseTime(obj.value(QStringLiteral("bookingTime"))),
QTime::fromString(QStringLiteral("%0").arg(obj.value(QStringLiteral("bookingTimespan")).toInt(), 6, 10, QChar('0')), QStringLiteral("HHmmss")), parseTime(obj.value(QStringLiteral("bookingTimespan"))),
obj.value(QStringLiteral("text")).toString(), obj.value(QStringLiteral("text")).toString(),
koWertList.at(0).toObject().value(QStringLiteral("value")).toString(), koWertList.at(0).toObject().value(QStringLiteral("value")).toString(),
koWertList.at(1).toObject().value(QStringLiteral("value")).toString(), koWertList.at(1).toObject().value(QStringLiteral("value")).toString(),

View File

@@ -150,8 +150,8 @@ void GetUserInfoReply::request1Finished()
m_userInfo.street = obj.value(QStringLiteral("gemeinde")).toString(); m_userInfo.street = obj.value(QStringLiteral("gemeinde")).toString();
m_userInfo.city = obj.value(QStringLiteral("ort")).toString(); m_userInfo.city = obj.value(QStringLiteral("ort")).toString();
m_userInfo.employedSince = QDate::fromString(QString::number(obj.value(QStringLiteral("angFrom")).toInt()), QStringLiteral("yyyyMMdd")); m_userInfo.employedSince = parseDate(obj.value(QStringLiteral("angFrom")));
m_userInfo.employedTill = QDate::fromString(QString::number(obj.value(QStringLiteral("angTill")).toInt()), QStringLiteral("yyyyMMdd")); m_userInfo.employedTill = parseDate(obj.value(QStringLiteral("angTill")));
m_userInfo.placeOfBirth = obj.value(QStringLiteral("gebOrt")).toString(); m_userInfo.placeOfBirth = obj.value(QStringLiteral("gebOrt")).toString();
m_userInfo.zipcode = obj.value(QStringLiteral("plz")).toString(); m_userInfo.zipcode = obj.value(QStringLiteral("plz")).toString();
m_userInfo.religion = obj.value(QStringLiteral("religion")).toString(); m_userInfo.religion = obj.value(QStringLiteral("religion")).toString();

View File

@@ -1,6 +1,7 @@
#include "zeiterfassungreply.h" #include "zeiterfassungreply.h"
#include <QEventLoop> #include <QEventLoop>
#include <QJsonValue>
#include "zeiterfassungapi.h" #include "zeiterfassungapi.h"
@@ -29,6 +30,22 @@ void ZeiterfassungReply::waitForFinished()
eventLoop.exec(); eventLoop.exec();
} }
QDate ZeiterfassungReply::parseDate(const QJsonValue &value)
{
if(value.isNull())
return QDate();
return QDate::fromString(QString::number(value.toInt()), QStringLiteral("yyyyMMdd"));
}
QTime ZeiterfassungReply::parseTime(const QJsonValue &value)
{
if(value.isNull())
return QTime();
return QTime::fromString(QStringLiteral("%0").arg(value.toInt(), 6, 10, QChar('0')), QStringLiteral("HHmmss"));
}
ZeiterfassungApi *ZeiterfassungReply::zeiterfassung() const ZeiterfassungApi *ZeiterfassungReply::zeiterfassung() const
{ {
return m_zeiterfassung; return m_zeiterfassung;

View File

@@ -4,6 +4,8 @@
#include "zeiterfassungcorelib_global.h" #include "zeiterfassungcorelib_global.h"
class QJsonValue;
class ZeiterfassungApi; class ZeiterfassungApi;
class ZEITERFASSUNGCORELIBSHARED_EXPORT ZeiterfassungReply : public QObject class ZEITERFASSUNGCORELIBSHARED_EXPORT ZeiterfassungReply : public QObject
@@ -18,6 +20,9 @@ public:
void waitForFinished(); void waitForFinished();
static QDate parseDate(const QJsonValue &value);
static QTime parseTime(const QJsonValue &value);
Q_SIGNALS: Q_SIGNALS:
void finished(); void finished();

View File

@@ -24,6 +24,7 @@
#include "replies/getreportreply.h" #include "replies/getreportreply.h"
#include "replies/getpresencestatusreply.h" #include "replies/getpresencestatusreply.h"
#include "replies/getabsencesreply.h" #include "replies/getabsencesreply.h"
#include "replies/getdayinforeply.h"
//add support for pre cpp14 compilers //add support for pre cpp14 compilers
#include "cpp14polyfills.h" #include "cpp14polyfills.h"
@@ -84,8 +85,8 @@ std::unique_ptr<GetBookingsReply> ZeiterfassungApi::doGetBookings(int userId, co
{ {
QNetworkRequest request(QUrl(QStringLiteral("%0json/bookings?start=%1&end=%2&pnrLst=%3") QNetworkRequest request(QUrl(QStringLiteral("%0json/bookings?start=%1&end=%2&pnrLst=%3")
.arg(m_url.toString()) .arg(m_url.toString())
.arg(start.toString(QStringLiteral("yyyyMMdd"))) .arg(formatDate(start))
.arg(end.toString(QStringLiteral("yyyyMMdd"))) .arg(formatDate(end))
.arg(userId))); .arg(userId)));
request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar"));
@@ -101,9 +102,9 @@ std::unique_ptr<CreateBookingReply> ZeiterfassungApi::doCreateBooking(int userId
QJsonObject obj; QJsonObject obj;
obj[QStringLiteral("persNr")] = userId; obj[QStringLiteral("persNr")] = userId;
obj[QStringLiteral("bookingDate")] = date.toString(QStringLiteral("yyyyMMdd")).toInt(); obj[QStringLiteral("bookingDate")] = formatDate(date).toInt();
obj[QStringLiteral("bookingTime")] = time.toString(QStringLiteral("Hmmss")).toInt(); obj[QStringLiteral("bookingTime")] = formatTime(time).toInt();
obj[QStringLiteral("bookingTimespan")] = timespan.toString(QStringLiteral("Hmmss")).toInt(); obj[QStringLiteral("bookingTimespan")] = formatTime(timespan).toInt();
obj[QStringLiteral("bookingType")] = type; obj[QStringLiteral("bookingType")] = type;
obj[QStringLiteral("hourCategory")] = QStringLiteral(""); obj[QStringLiteral("hourCategory")] = QStringLiteral("");
obj[QStringLiteral("empfEinh")] = QStringLiteral(""); obj[QStringLiteral("empfEinh")] = QStringLiteral("");
@@ -125,9 +126,9 @@ std::unique_ptr<UpdateBookingReply> ZeiterfassungApi::doUpdateBooking(int bookin
QJsonObject obj; QJsonObject obj;
obj[QStringLiteral("bookingNr")] = bookingId; obj[QStringLiteral("bookingNr")] = bookingId;
obj[QStringLiteral("persNr")] = userId; obj[QStringLiteral("persNr")] = userId;
obj[QStringLiteral("bookingDate")] = date.toString(QStringLiteral("yyyyMMdd")).toInt(); obj[QStringLiteral("bookingDate")] = formatDate(date).toInt();
obj[QStringLiteral("bookingTime")] = time.toString(QStringLiteral("Hmmss")).toInt(); obj[QStringLiteral("bookingTime")] = formatTime(time).toInt();
obj[QStringLiteral("bookingTimespan")] = timespan.toString(QStringLiteral("Hmmss")).toInt(); obj[QStringLiteral("bookingTimespan")] = formatTime(timespan).toInt();
obj[QStringLiteral("bookingType")] = type; obj[QStringLiteral("bookingType")] = type;
obj[QStringLiteral("hourCategory")] = QStringLiteral(""); obj[QStringLiteral("hourCategory")] = QStringLiteral("");
obj[QStringLiteral("empfEinh")] = QStringLiteral(""); obj[QStringLiteral("empfEinh")] = QStringLiteral("");
@@ -153,8 +154,8 @@ std::unique_ptr<GetTimeAssignmentsReply> ZeiterfassungApi::doGetTimeAssignments(
{ {
QNetworkRequest request(QUrl(QStringLiteral("%0json/azebooking?start=%1&end=%2&pnrLst=%3") QNetworkRequest request(QUrl(QStringLiteral("%0json/azebooking?start=%1&end=%2&pnrLst=%3")
.arg(m_url.toString()) .arg(m_url.toString())
.arg(start.toString(QStringLiteral("yyyyMMdd"))) .arg(formatDate(start))
.arg(end.toString(QStringLiteral("yyyyMMdd"))) .arg(formatDate(end))
.arg(userId))); .arg(userId)));
request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar"));
@@ -173,9 +174,9 @@ std::unique_ptr<CreateTimeAssignmentReply> ZeiterfassungApi::doCreateTimeAssignm
QJsonObject obj; QJsonObject obj;
obj[QStringLiteral("bookingNr")] = QJsonValue::Null; obj[QStringLiteral("bookingNr")] = QJsonValue::Null;
obj[QStringLiteral("persNr")] = userId; obj[QStringLiteral("persNr")] = userId;
obj[QStringLiteral("bookingDate")] = date.toString(QStringLiteral("yyyyMMdd")).toInt(); obj[QStringLiteral("bookingDate")] = formatDate(date).toInt();
obj[QStringLiteral("bookingTime")] = time.toString(QStringLiteral("Hmmss")).toInt(); obj[QStringLiteral("bookingTime")] = formatTime(time).toInt();
obj[QStringLiteral("bookingTimespan")] = timespan.toString(QStringLiteral("Hmmss")).toInt(); obj[QStringLiteral("bookingTimespan")] = formatTime(timespan).toInt();
obj[QStringLiteral("text")] = text; obj[QStringLiteral("text")] = text;
{ {
QJsonArray koWertList; QJsonArray koWertList;
@@ -214,9 +215,9 @@ std::unique_ptr<UpdateTimeAssignmentReply> ZeiterfassungApi::doUpdateTimeAssignm
QJsonObject obj; QJsonObject obj;
obj[QStringLiteral("bookingNr")] = timeAssignmentId; obj[QStringLiteral("bookingNr")] = timeAssignmentId;
obj[QStringLiteral("persNr")] = userId; obj[QStringLiteral("persNr")] = userId;
obj[QStringLiteral("bookingDate")] = date.toString(QStringLiteral("yyyyMMdd")).toInt(); obj[QStringLiteral("bookingDate")] = formatDate(date).toInt();
obj[QStringLiteral("bookingTime")] = time.toString(QStringLiteral("Hmmss")).toInt(); obj[QStringLiteral("bookingTime")] = formatTime(time).toInt();
obj[QStringLiteral("bookingTimespan")] = timespan.toString(QStringLiteral("Hmmss")).toInt(); obj[QStringLiteral("bookingTimespan")] = formatTime(timespan).toInt();
obj[QStringLiteral("bookingType")] = QJsonValue::Null; obj[QStringLiteral("bookingType")] = QJsonValue::Null;
obj[QStringLiteral("hourCategory")] = QJsonValue::Null; obj[QStringLiteral("hourCategory")] = QJsonValue::Null;
obj[QStringLiteral("bewEinh")] = QJsonValue::Null; obj[QStringLiteral("bewEinh")] = QJsonValue::Null;
@@ -263,7 +264,7 @@ std::unique_ptr<GetProjectsReply> ZeiterfassungApi::doGetProjects(int userId, co
QNetworkRequest request(QUrl(QStringLiteral("%0json/combobox?persnr=%1&date=%2&dqkey=KOST&kowert0=&kowert1=&kowert2=&term=") QNetworkRequest request(QUrl(QStringLiteral("%0json/combobox?persnr=%1&date=%2&dqkey=KOST&kowert0=&kowert1=&kowert2=&term=")
.arg(m_url.toString()) .arg(m_url.toString())
.arg(userId) .arg(userId)
.arg(date.toString(QStringLiteral("yyyyMMdd"))))); .arg(formatDate(date))));
request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar"));
return std::make_unique<GetProjectsReply>(std::unique_ptr<QNetworkReply>(m_manager->get(request)), this); return std::make_unique<GetProjectsReply>(std::unique_ptr<QNetworkReply>(m_manager->get(request)), this);
@@ -274,7 +275,7 @@ std::unique_ptr<GetReportReply> ZeiterfassungApi::doGetReport(int userId, const
QNetworkRequest request(QUrl(QStringLiteral("%0json/auswertung/month?persNr=%1&date=%2") QNetworkRequest request(QUrl(QStringLiteral("%0json/auswertung/month?persNr=%1&date=%2")
.arg(m_url.toString()) .arg(m_url.toString())
.arg(userId) .arg(userId)
.arg(date.toString(QStringLiteral("yyyyMMdd"))))); .arg(formatDate(date))));
request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar"));
return std::make_unique<GetReportReply>(std::unique_ptr<QNetworkReply>(m_manager->get(request)), this); return std::make_unique<GetReportReply>(std::unique_ptr<QNetworkReply>(m_manager->get(request)), this);
@@ -292,10 +293,32 @@ std::unique_ptr<GetAbsencesReply> ZeiterfassungApi::doGetAbsences(int userId, co
{ {
QNetworkRequest request(QUrl(QStringLiteral("%0json/fulldayAbsences?start=%1&end=%2&pnrLst=%3") QNetworkRequest request(QUrl(QStringLiteral("%0json/fulldayAbsences?start=%1&end=%2&pnrLst=%3")
.arg(m_url.toString()) .arg(m_url.toString())
.arg(start.toString(QStringLiteral("yyyyMMdd"))) .arg(formatDate(start))
.arg(end.toString(QStringLiteral("yyyyMMdd"))) .arg(formatDate(end))
.arg(userId))); .arg(userId)));
request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar")); request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar"));
return std::make_unique<GetAbsencesReply>(std::unique_ptr<QNetworkReply>(m_manager->get(request)), this); return std::make_unique<GetAbsencesReply>(std::unique_ptr<QNetworkReply>(m_manager->get(request)), this);
} }
std::unique_ptr<GetDayinfoReply> ZeiterfassungApi::doGetDayinfo(int userId, const QDate &start, const QDate &end)
{
QNetworkRequest request(QUrl(QStringLiteral("%0json/dayinfo?start=%1&end=%2&pnrLst=%3")
.arg(m_url.toString())
.arg(formatDate(start))
.arg(formatDate(end))
.arg(userId)));
request.setRawHeader(QByteArrayLiteral("sisAppName"), QByteArrayLiteral("bookingCalendar"));
return std::make_unique<GetDayinfoReply>(std::unique_ptr<QNetworkReply>(m_manager->get(request)), this);
}
QString ZeiterfassungApi::formatDate(const QDate &date)
{
return date.toString(QStringLiteral("yyyyMMdd"));
}
QString ZeiterfassungApi::formatTime(const QTime &time)
{
return time.toString(QStringLiteral("Hmmss"));
}

View File

@@ -27,6 +27,7 @@ class GetProjectsReply;
class GetReportReply; class GetReportReply;
class GetPresenceStatusReply; class GetPresenceStatusReply;
class GetAbsencesReply; class GetAbsencesReply;
class GetDayinfoReply;
class ZEITERFASSUNGCORELIBSHARED_EXPORT ZeiterfassungApi : public QObject class ZEITERFASSUNGCORELIBSHARED_EXPORT ZeiterfassungApi : public QObject
{ {
@@ -66,8 +67,12 @@ public:
std::unique_ptr<GetReportReply> doGetReport(int userId, const QDate &date); std::unique_ptr<GetReportReply> doGetReport(int userId, const QDate &date);
std::unique_ptr<GetPresenceStatusReply> doGetPresenceStatus(); std::unique_ptr<GetPresenceStatusReply> doGetPresenceStatus();
std::unique_ptr<GetAbsencesReply> doGetAbsences(int userId, const QDate &start, const QDate &end); std::unique_ptr<GetAbsencesReply> doGetAbsences(int userId, const QDate &start, const QDate &end);
std::unique_ptr<GetDayinfoReply> doGetDayinfo(int userId, const QDate &start, const QDate &end);
private: private:
static QString formatDate(const QDate &date);
static QString formatTime(const QTime &time);
QUrl m_url; QUrl m_url;
QNetworkAccessManager *m_manager; QNetworkAccessManager *m_manager;
}; };

View File

@@ -17,6 +17,7 @@ SOURCES += timeutils.cpp \
replies/deletetimeassignmentreply.cpp \ replies/deletetimeassignmentreply.cpp \
replies/getabsencesreply.cpp \ replies/getabsencesreply.cpp \
replies/getbookingsreply.cpp \ replies/getbookingsreply.cpp \
replies/getdayinforeply.cpp \
replies/getpresencestatusreply.cpp \ replies/getpresencestatusreply.cpp \
replies/getprojectsreply.cpp \ replies/getprojectsreply.cpp \
replies/getreportreply.cpp \ replies/getreportreply.cpp \
@@ -39,6 +40,7 @@ HEADERS += cpp14polyfills.h \
replies/deletetimeassignmentreply.h \ replies/deletetimeassignmentreply.h \
replies/getabsencesreply.h \ replies/getabsencesreply.h \
replies/getbookingsreply.h \ replies/getbookingsreply.h \
replies/getdayinforeply.h \
replies/getpresencestatusreply.h \ replies/getpresencestatusreply.h \
replies/getprojectsreply.h \ replies/getprojectsreply.h \
replies/getreportreply.h \ replies/getreportreply.h \