mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
Начал реализовывать обмен запросами к БД
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 4.11.1, 2024-12-04T10:14:55. -->
|
||||
<!-- Written by QtCreator 4.11.1, 2024-12-06T11:14:24. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <QString>
|
||||
#include <QTcpSocket>
|
||||
#include "typesDataServerClient.h"
|
||||
|
||||
class Client
|
||||
{
|
||||
@@ -10,7 +11,8 @@ class Client
|
||||
public:
|
||||
Client(QString name, QString address, QString port,QObject *parent = nullptr):
|
||||
login(""),
|
||||
ready(false)
|
||||
ready(false),
|
||||
TypeClient(TypeClientAutorization::TYPE_SIMPLE)
|
||||
{
|
||||
this->name = name;
|
||||
this->address = address;
|
||||
@@ -59,6 +61,16 @@ public:
|
||||
{
|
||||
return isUnity;
|
||||
}
|
||||
|
||||
void setTypeClient(TypeClientAutorization TypeClient)
|
||||
{
|
||||
this->TypeClient = TypeClient;
|
||||
}
|
||||
TypeClientAutorization getTypeClient()
|
||||
{
|
||||
return TypeClient;
|
||||
}
|
||||
|
||||
void changePackageResponse()
|
||||
{
|
||||
isUnity = !isUnity;
|
||||
@@ -77,6 +89,8 @@ private:
|
||||
QString login;
|
||||
bool ready;
|
||||
bool isUnity = false;
|
||||
|
||||
TypeClientAutorization TypeClient;
|
||||
};
|
||||
|
||||
#endif // CLIENT_H
|
||||
|
||||
@@ -45,6 +45,8 @@ void DataParser::xmlParser(ClientHandler *client, QByteArray array)
|
||||
clientAutorization.Password = value;
|
||||
else if(name == "NumberOfScreen")
|
||||
clientAutorization.NumberOfScreen = value.toInt();
|
||||
else if(name == "TypeClient")
|
||||
clientAutorization.TypeClient = (TypeClientAutorization)value.toInt();
|
||||
}
|
||||
|
||||
processingSystem->processingClientAutorization(client, clientAutorization);
|
||||
@@ -67,6 +69,24 @@ void DataParser::xmlParser(ClientHandler *client, QByteArray array)
|
||||
|
||||
processingSystem->processingClientDeAutorization(client, clientDeAutorization);
|
||||
}
|
||||
else if(xmlReader.name() == "QueryToDB")
|
||||
{//Запрос к базе данных от клиента
|
||||
|
||||
ClientQueryToDB queryToDB;
|
||||
|
||||
/*Перебираем все атрибуты тега*/
|
||||
foreach(const QXmlStreamAttribute &attr, xmlReader.attributes())
|
||||
{
|
||||
QString name = attr.name().toString();
|
||||
QString value = attr.value().toString();
|
||||
//addTextToLogger(name + ": " + value);
|
||||
|
||||
if(name == "TypeQuery")
|
||||
queryToDB.typeQuery = (TypeQueryToDB)value.toInt();
|
||||
}
|
||||
|
||||
processingSystem->processingClientQueryToDB(client, queryToDB);
|
||||
}
|
||||
else if(xmlReader.name() == "ClientMessage")
|
||||
{//Сообщение от клиента
|
||||
|
||||
@@ -270,6 +290,28 @@ QByteArray DataParser::xmlAnswer_deAuthorization(bool result, QString login)
|
||||
return xmlAnswer(listTag);
|
||||
}
|
||||
|
||||
QByteArray DataParser::xmlAnswer_ClientQueryToDB(bool result, QList<Instructor> listInstructors)
|
||||
{
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
|
||||
for(Instructor instructor : listInstructors)
|
||||
{
|
||||
SAttribute attribute1 = {"instructor_id", QString::number(instructor.getID())};
|
||||
SAttribute attribute2 = {"name", instructor.getName()};
|
||||
SAttribute attribute3 = {"login", instructor.getLogin()};
|
||||
SAttribute attribute4 = {"password", instructor.getPassword()};
|
||||
SAttribute attribute5 = {"is_admin", instructor.getIsAdmin() ? "true" : "false"};
|
||||
SAttribute attribute6 = {"archived", instructor.getArchived() ? "true" : "false"};
|
||||
SAttribute attribute7 = {"logged_in", instructor.getLoggedIn() ? "true" : "false"};
|
||||
QList<SAttribute> listAttr = {attribute1, attribute2, attribute3, attribute4, attribute5, attribute6, attribute7};
|
||||
SXmlAnswerTag tag = {"Instructor", listAttr};
|
||||
|
||||
listTag.append(tag);
|
||||
}
|
||||
|
||||
return xmlAnswer(listTag, "ListInstructors");
|
||||
}
|
||||
|
||||
QByteArray DataParser::xmlAnswer_message(QString text)
|
||||
{
|
||||
QList<SXmlAnswerTag> listTag;
|
||||
|
||||
@@ -27,6 +27,9 @@ public:
|
||||
QByteArray xmlAnswer(QList<SXmlAnswerTag> listTag,QString elemUp1 = "", QString elemUp2 = "");
|
||||
QByteArray xmlAnswer_authorization(bool result, QString instructorName, QString clientName, QString accessType, QString login);
|
||||
QByteArray xmlAnswer_deAuthorization(bool result, QString login);
|
||||
|
||||
QByteArray xmlAnswer_ClientQueryToDB(bool result, QList<Instructor> listInstructors);
|
||||
|
||||
QByteArray xmlAnswer_message(QString text);
|
||||
QByteArray xmlAnswer_task(QString text);
|
||||
QByteArray xmlAnswer_notify(QString code);
|
||||
|
||||
@@ -48,6 +48,7 @@ void ProcessingSystem::processingClientAutorization(ClientHandler *client, Clien
|
||||
{//Авторизуется инструктор
|
||||
|
||||
client->getClient()->setLogin(clientAutorization.Login);
|
||||
client->getClient()->setTypeClient(clientAutorization.TypeClient);
|
||||
emit sigUpdateListClients();
|
||||
|
||||
instructorName = providerDBLMS->getNameInstructorByLogin(clientAutorization.Login);
|
||||
@@ -112,6 +113,24 @@ void ProcessingSystem::processingClientDeAutorization(ClientHandler *client, Cli
|
||||
emit sigAuthChanged();
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingClientQueryToDB(ClientHandler *client, ClientQueryToDB clientQueryToDB)
|
||||
{
|
||||
QByteArray arrayAnswer;
|
||||
|
||||
switch (clientQueryToDB.typeQuery)
|
||||
{
|
||||
case TypeQueryToDB::TYPE_QUERY_GET_LIST_INSTRUCTORS:
|
||||
QList<Instructor> listInstructors = providerDBLMS->GetListAllInstructors();
|
||||
arrayAnswer = dataParser->xmlAnswer_ClientQueryToDB(true, listInstructors);
|
||||
break;
|
||||
}
|
||||
|
||||
client->sendXmlAnswer(arrayAnswer);
|
||||
|
||||
//QString str = QString(arrayAnswer);
|
||||
//logger->addTextToLogger("To Client: " + str);
|
||||
}
|
||||
|
||||
void ProcessingSystem::processingClientMessage(ClientHandler *client, ClientMessage clientMessage)
|
||||
{
|
||||
QString peerAddress = client->getSocket()->peerAddress().toString();
|
||||
|
||||
@@ -25,6 +25,7 @@ public:
|
||||
void initialize(DataParser* dataParser,ServerLMSWidget *server);
|
||||
void processingClientAutorization(ClientHandler *client, ClientAutorization clientAutorization);
|
||||
void processingClientDeAutorization(ClientHandler *client, ClientDeAutorization clientDeAutorization);
|
||||
void processingClientQueryToDB(ClientHandler *client, ClientQueryToDB clientQueryToDB);
|
||||
void processingClientMessage(ClientHandler *client, ClientMessage clientMessage);
|
||||
void processingClientNotify(ClientHandler *client, ClientNotify clientNotify);
|
||||
|
||||
|
||||
@@ -30,7 +30,9 @@ enum PacketType
|
||||
TYPE_XMLANSWER = 8,
|
||||
TYPE_QT = 9,
|
||||
TYPE_DISABLE = 11,
|
||||
TYPE_FILESIZE = 20
|
||||
TYPE_FILESIZE = 20,
|
||||
|
||||
TYPE_GET_LIST_INSTRUCTORS = 100
|
||||
};
|
||||
|
||||
class Tools {
|
||||
|
||||
@@ -198,3 +198,21 @@ QString ProviderDBLMS::getNameInstructorByLogin(QString login)
|
||||
mtxAccess.unlock();
|
||||
return res;
|
||||
}
|
||||
|
||||
QList<Instructor> ProviderDBLMS::GetListAllInstructors()
|
||||
{
|
||||
QList<Instructor> listInstructors;
|
||||
|
||||
mtxAccess.lock();
|
||||
|
||||
if(! dbLMS->DBisConnected())
|
||||
{
|
||||
mtxAccess.unlock();
|
||||
return listInstructors;
|
||||
}
|
||||
|
||||
listInstructors = dbLMS->getListInstructors();
|
||||
|
||||
mtxAccess.unlock();
|
||||
return listInstructors;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ public:
|
||||
bool deAuthorizationInstructor(QString login);
|
||||
QString getNameInstructorByLogin(QString login);
|
||||
|
||||
//
|
||||
QList<Instructor> GetListAllInstructors();
|
||||
|
||||
Q_SIGNALS:
|
||||
//сигнал о блокировке авторизации
|
||||
void signal_BlockAutorization(bool block);
|
||||
|
||||
@@ -69,6 +69,8 @@ ServerLMSWidget::ServerLMSWidget(QWidget *parent) :
|
||||
connect(processingSystem,&ProcessingSystem::sigLogMessage,logger,&Logger::addTextToLogger);
|
||||
connect(this,&ServerLMSWidget::sigLog,logger,&Logger::addTextToLogger);
|
||||
|
||||
connect(processingSystem,&ProcessingSystem::sigAuthChanged,this, &ServerLMSWidget::slot_AuthChanged);
|
||||
|
||||
on_btnStartServer_clicked();
|
||||
|
||||
first = true;
|
||||
@@ -189,6 +191,21 @@ void ServerLMSWidget::slot_BlockAutorization(bool block)
|
||||
unBlockAutorization();
|
||||
}
|
||||
|
||||
void ServerLMSWidget::slot_AuthChanged()
|
||||
{
|
||||
//Проходим все открытые сокеты
|
||||
foreach(int idSocket, clientsMap.keys())
|
||||
{
|
||||
//Проверяем, есть ли клиенты TYPE_GUI
|
||||
if(clientsMap[idSocket]->getClient()->getTypeClient() == TypeClientAutorization::TYPE_GUI)
|
||||
{//Отправляем этому клиенту обновление списков
|
||||
ClientQueryToDB queryToDB;
|
||||
queryToDB.typeQuery = TypeQueryToDB::TYPE_QUERY_GET_LIST_INSTRUCTORS;
|
||||
processingSystem->processingClientQueryToDB(clientsMap[idSocket], queryToDB);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ServerLMSWidget::removeClient(int idSocket)
|
||||
{
|
||||
clientsMap.remove(idSocket);
|
||||
|
||||
@@ -59,6 +59,7 @@ public slots:
|
||||
void addClient(qintptr descriptor, ClientHandler *client);
|
||||
void slotUpdateListClients();
|
||||
void slot_BlockAutorization(bool block);
|
||||
void slot_AuthChanged();
|
||||
|
||||
private slots:
|
||||
//слот обработки сигнала о готовности нового сообщения на отправку клиенту от мессенджера
|
||||
|
||||
@@ -37,12 +37,18 @@ struct SXmlAnswerTag
|
||||
QList<SAttribute> attr;
|
||||
};
|
||||
|
||||
enum TypeClientAutorization{
|
||||
TYPE_SIMPLE = 0,
|
||||
TYPE_GUI = 10
|
||||
};
|
||||
|
||||
class ClientAutorization
|
||||
{
|
||||
public:
|
||||
QString Login;
|
||||
QString Password;
|
||||
int NumberOfScreen;
|
||||
TypeClientAutorization TypeClient;
|
||||
};
|
||||
class ClientDeAutorization
|
||||
{
|
||||
@@ -50,6 +56,15 @@ public:
|
||||
QString Login;
|
||||
};
|
||||
|
||||
enum TypeQueryToDB{
|
||||
TYPE_QUERY_GET_LIST_INSTRUCTORS
|
||||
};
|
||||
|
||||
class ClientQueryToDB{
|
||||
public:
|
||||
TypeQueryToDB typeQuery;
|
||||
};
|
||||
|
||||
class ServerMessage
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user