Skip to content

Commit

Permalink
Merge pull request #62 from csthenry/dev
Browse files Browse the repository at this point in the history
重构若干功能,优化若干流程。
  • Loading branch information
csthenry authored Mar 31, 2023
2 parents 73e77ca + 781f286 commit 94fa844
Show file tree
Hide file tree
Showing 25 changed files with 399 additions and 318 deletions.
6 changes: 3 additions & 3 deletions MagicLightAssistant.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,6 @@
<QtMoc Include="comboboxdelegate.h">
<Filter>Header Files</Filter>
</QtMoc>
<ClInclude Include="excelexport.h">
<Filter>Header Files</Filter>
</ClInclude>
<QtMoc Include="formlogin.h">
<Filter>Header Files</Filter>
</QtMoc>
Expand Down Expand Up @@ -456,6 +453,9 @@
<ClInclude Include="resource.h">
<Filter>Generated Files</Filter>
</ClInclude>
<ClInclude Include="excelexport.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="MagicLightAssistant.ico" />
Expand Down
4 changes: 2 additions & 2 deletions MagicLightAssistant.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<QtLastBackgroundBuild>2023-03-14T12:37:28.3943389Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2023-03-31T07:04:21.6303138Z</QtLastBackgroundBuild>
</PropertyGroup>
<PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<QtLastBackgroundBuild>2023-03-14T12:37:28.4952107Z</QtLastBackgroundBuild>
<QtLastBackgroundBuild>2023-03-31T07:04:21.8030684Z</QtLastBackgroundBuild>
</PropertyGroup>
</Project>
7 changes: 6 additions & 1 deletion activitymanagework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void ActivityManageWork::working()
tabModel->setHeaderData(tabModel->fieldIndex("editUid"), Qt::Horizontal, "发布者UID");
tabModel->setHeaderData(tabModel->fieldIndex("act_score"), Qt::Horizontal, "活动学时");
tabModel->select();
while(tabModel->canFetchMore())
tabModel->fetchMore(); //加载超过256的其余数据

memberTabModel->setTable("magic_activityMembers");
memberTabModel->setSort(memberTabModel->fieldIndex("actm_joinDate"), Qt::DescendingOrder);
Expand All @@ -54,6 +56,9 @@ void ActivityManageWork::working()
memberTabModel->setHeaderData(memberTabModel->fieldIndex("actm_joinDate"), Qt::Horizontal, "报名时间");
memberTabModel->setHeaderData(memberTabModel->fieldIndex("status"), Qt::Horizontal, "活动状态");
memberTabModel->select();
while (memberTabModel->canFetchMore())
memberTabModel->fetchMore(); //加载超过256的其余数据

if (type == 1)
updateActStatus(); //更新已报名活动状态并统计学时
emit activityManageWorkFinished(type);
Expand Down Expand Up @@ -86,7 +91,7 @@ void ActivityManageWork::updateActStatus()
}
memberTabModel->setFilter("actm_uid=" + uid);

qDebug() << "当前待新增的总学时:" + QString::number(curScore);
qDebug() << "当前待新增总学时:" + QString::number(curScore);
}

void ActivityManageWork::homeWorking()//已废弃
Expand Down
17 changes: 10 additions & 7 deletions approvalwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ void ApprovalWork::getUserPageApplyItems(const QString& uid)
{
DB.open();
QSqlQuery query(DB);
//获取可申请的项目
query.exec(QString("SELECT * FROM magic_applyItems WHERE isHide=0"));
applyItems.clear();
while (query.next()) {
Expand All @@ -143,9 +144,11 @@ void ApprovalWork::getUserPageApplyItems(const QString& uid)
}
}
query.clear();

//获取用户已提交的申请
applyForms.clear();
query.exec(QString("SELECT * FROM magic_apply WHERE uid=%1 ORDER BY apply_id DESC").arg(uid)); //id降序
DB_SECOND.open(); //调用getApplyProcess()前需打开该数据库
while(query.next())
{
QByteArray array;
Expand All @@ -166,8 +169,8 @@ void ApprovalWork::getUserPageApplyItems(const QString& uid)
}
}
query.clear();
DB.close();

DB_SECOND.close(); //关闭调用getApplyProcess()所需数据库连接
DB.close();
emit getUserPageApplyItemsFinished();
}

Expand Down Expand Up @@ -227,7 +230,7 @@ void ApprovalWork::autoExecuteSystemApplyItems()
DB_SECOND.close();
finishedNum++;
if(!mail.isEmpty())
service::sendMail(smtp_config, mail, "WePlanet 审批进度更新", QString("用户%1:\n你的【个人信息异动申请】现已完成审核,个人信息现已更新\n\n注:若异动信息有误,请联系管理员。").arg(record.value("uid").toString()));
service::sendMail(smtp_config, mail, "WePlanet 审批进度更新", QString("用户%1:\n你的【个人信息异动申请】现已完成审核,个人信息已更新\n\n注:若异动信息有误,请联系管理员。").arg(record.value("uid").toString()));
}
}
}
Expand Down Expand Up @@ -279,7 +282,7 @@ void ApprovalWork::autoExecuteSystemApplyItems()
DB_SECOND.close();
finishedNum++;
if (!mail.isEmpty())
service::sendMail(smtp_config, mail, "WePlanet 审批进度更新", QString("用户%1:\n你的【账号认证申请】现已完成审核,账号认证信息现已更新\n\n注:若认证信息有误,请联系管理员。").arg(record.value("uid").toString()));
service::sendMail(smtp_config, mail, "WePlanet 审批进度更新", QString("用户%1:\n你的【账号认证申请】现已完成审核,账号认证信息已更新\n\n注:若认证信息有误,请联系管理员。").arg(record.value("uid").toString()));
}
}
}
Expand All @@ -291,9 +294,9 @@ void ApprovalWork::autoExecuteSystemApplyItems()
emit autoExecuteSystemApplyItemsFinished(finishedNum);
}

int ApprovalWork::getApplyProcess(const QString& apply_id, const QString& item_id)
int ApprovalWork::getApplyProcess(const QString& apply_id, const QString& item_id) //调用此函数前需打开数据库DB_SECOND连接
{
DB_SECOND.open();
//DB_SECOND.open();
QSqlQuery query(DB_SECOND);
currentProcess.clear();
int step = 0, apply_status = 0; //已成功通过的流程,申请表状态
Expand Down Expand Up @@ -329,7 +332,7 @@ int ApprovalWork::getApplyProcess(const QString& apply_id, const QString& item_i
applyFormsProcess.insert(apply_id, currentProcess); //将所有已审核的步骤存入对应id键值

query.clear();
DB_SECOND.close();
//DB_SECOND.close();
return apply_status;
}

Expand Down
6 changes: 3 additions & 3 deletions approvalwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ class ApprovalWork : public QObject
QList<QString> smtp_config;

public:
void getManagePageApplyItems(const QString& uid);
void getUserPageApplyItems(const QString& uid);
void getManagePageApplyItems(const QString& uid); //加载审批流程页面数据
void getUserPageApplyItems(const QString& uid); //加载用户申请页面数据
void getManagePageAuditorList(); //获取具有审核权限的人员列表
void getAllApplyFormList(const QString& uid); //获取审批队列供管理员审核
int getApplyProcess(const QString& apply_id, const QString& item_id); //返回最新申请表状态
int getApplyProcess(const QString& apply_id, const QString& item_id); //获取申请表流程,返回申请表状态(调用此函数前需打开数据库DB_SECOND连接)
void addOrModifyApplyItem(int type, QByteArray array); //0新增或1修改申请项 ByteArray 标题->选项->发布者->流程->isHide
QByteArray getSimpleApplyItems(const QString& item_id);
QList<QByteArray> getApplyFormList();
Expand Down
40 changes: 32 additions & 8 deletions attendmanagework.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ AttendManageWork::AttendManageWork(QObject *parent) : QObject(parent)
//DB.setConnectOptions("MYSQL_OPT_RECONNECT=1"); //超时重连
heartBeat = new QTimer(this);
connect(heartBeat, &QTimer::timeout, this, [=]() {
if (isDisplay)
if (isDisplay && userModel != nullptr && attendModel != nullptr)
{
userModel->select();
attendModel->select();
Expand All @@ -31,8 +31,13 @@ void AttendManageWork::working()
{
if (!DB.isOpen())
DB.open();

//使用relationalModel时,这数据库不能关闭,否则外键的映射就没办法操作了...早知道不用relationalModel了,数据库连接很难管理...
if(userModelQueue.count() >= 2)
delete userModelQueue.dequeue(); //仅保留前一个model
userModel = new QSqlRelationalTableModel(this, DB);
userModelQueue.enqueue(userModel);
isDisplay = true;
//使用relationalModel时,这数据库不能关闭,否则外键的映射就没办法操作了...早知道不用relationalModel了,数据库连接很难管理...
userModel->setTable("magic_users");
userModel->setSort(userModel->fieldIndex("uid"), Qt::AscendingOrder); //升序排列
userModel->setEditStrategy(QSqlTableModel::OnManualSubmit); //手动提交
Expand All @@ -51,6 +56,13 @@ void AttendManageWork::working()
userModel->setRelation(userModel->fieldIndex("user_group"), QSqlRelation("magic_group", "group_id", "group_name"));
userModel->setRelation(userModel->fieldIndex("user_dpt"), QSqlRelation("magic_department", "dpt_id", "dpt_name"));
userModel->select();
while (userModel->canFetchMore())
userModel->fetchMore(); //加载超过256的其余数据

if(attendModelQueue.count() >= 2)
delete attendModelQueue.dequeue();
attendModel = new QSqlRelationalTableModel(this, DB);
attendModelQueue.enqueue(attendModel);

attendModel->setTable("magic_attendance");
attendModel->setSort(attendModel->fieldIndex("today"), Qt::DescendingOrder); //时间降序排列
Expand All @@ -66,6 +78,8 @@ void AttendManageWork::working()
//建立外键关联
attendModel->setRelation(attendModel->fieldIndex("operator"), QSqlRelation("magic_users", "uid", "name"));
attendModel->select();
while (attendModel->canFetchMore())
attendModel->fetchMore(); //加载超过256的其余数据

//将未签退的考勤项签退,签退时间23:59:59
DB_SECOND.open();
Expand Down Expand Up @@ -154,19 +168,29 @@ void AttendManageWork::setCurAvatarUrl(const QString url)
avatarUrl = url;
}

void AttendManageWork::setUserModel(QSqlRelationalTableModel *relTableModel)
//void AttendManageWork::setUserModel(QSqlRelationalTableModel *relTableModel)
//{
// userModel = relTableModel;
//}
//
//void AttendManageWork::setAttendModel(QSqlRelationalTableModel *relTableModel)
//{
// attendModel = relTableModel;
//}

QSqlDatabase AttendManageWork::getDB()
{
userModel = relTableModel;
return DB;
}

void AttendManageWork::setAttendModel(QSqlRelationalTableModel *relTableModel)
QSqlRelationalTableModel* AttendManageWork::getUserModel()
{
attendModel = relTableModel;
return userModel;
}

QSqlDatabase AttendManageWork::getDB()
QSqlRelationalTableModel* AttendManageWork::getAttendModel()
{
return DB;
return attendModel;
}

void AttendManageWork::getComboxItems(QStringList& comboxItems_group, QStringList& comboxItems_department)
Expand Down
7 changes: 5 additions & 2 deletions attendmanagework.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class AttendManageWork : public QObject
bool isFirst = true; //是否为首次加载model
void working();
void setCurAvatarUrl(const QString url);
void setUserModel(QSqlRelationalTableModel *relTableModel);
void setAttendModel(QSqlRelationalTableModel *relTableModel);
//void setUserModel(QSqlRelationalTableModel *relTableModel);
//void setAttendModel(QSqlRelationalTableModel *relTableModel);
void getComboxItems(QStringList& comboxItems_group, QStringList& comboxItems_department); //已弃用
void submitAll(int type); //1补签 0退签
void loadAvatar();
Expand All @@ -27,6 +27,8 @@ class AttendManageWork : public QObject
void setFilter(int type, const QString& filter);
bool isDisplay = false;
QSqlDatabase getDB();
QSqlRelationalTableModel* getUserModel();
QSqlRelationalTableModel* getAttendModel();
private:
service db_service;
QComboBox *m_group, *m_department;
Expand All @@ -36,6 +38,7 @@ class AttendManageWork : public QObject
QStringList comboxItems_group, comboxItems_department;
QSqlRelationalTableModel *userModel, *attendModel;
QTimer* heartBeat;
QQueue<QSqlRelationalTableModel*> userModelQueue, attendModelQueue;
void getComboxItems();
signals:
void attendManageWorkFinished();
Expand Down
Loading

0 comments on commit 94fa844

Please sign in to comment.