mainwidget_service.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. #include "mainwidget.h"
  2. #include "exceptionbatchitem.h"
  3. #include "bindschoolinfo.h"
  4. #include "../Util/Util.h"
  5. #include "../Util/typedef_struct.h"
  6. #include <QFileDialog>
  7. #include <QMessageBox>
  8. #include <QDateTime>
  9. #include <QFileDialog>
  10. #include <QTimer>
  11. #include "../ZLibWrapLib/ZLibWrapLib.h"
  12. #include <QNetworkRequest>
  13. #include <QNetworkReply>
  14. #include <QJsonObject>
  15. #include <QJsonParseError>
  16. #include <QJsonArray>
  17. #include <QSettings>
  18. #include "updatedlg.h"
  19. #include <QProcess>
  20. extern wstring g_strConfigPath;
  21. #define qrcodeunmatch L"二维码不匹配(%1)"
  22. #define locationexception L"定位点异常(%1)"
  23. #define uploadfail L"上传失败(%1)"
  24. #define scan_paper_normal L"识别"
  25. #define scan_paper_identi L"识别中..."
  26. #define scan_batch_normal L"批量识别"
  27. #define scan_batch_identi L"批量识别中..."
  28. #define alert_delete(){ QString msg = QString::fromLocal8Bit("确定执行该删除操作吗?"); \
  29. QMessageBox::StandardButton result = QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), msg, QMessageBox::Yes | QMessageBox::No); \
  30. if (result != QMessageBox::Yes) \
  31. { \
  32. return; \
  33. }} \
  34. void MainWidget::bind_signlslot()
  35. {
  36. connect(ui.pushButton_bindschool, SIGNAL(clicked()), this, SLOT(slots_bindschool()));
  37. connect(ui.pushButton_head_modify_school, SIGNAL(clicked()), this, SLOT(slots_bindschool()));
  38. connect(ui.pushButton_batch_unzipfail, SIGNAL(clicked()), this, SLOT(slots_handleclick()));
  39. connect(ui.pushButton_batch_picwrong, SIGNAL(clicked()), this, SLOT(slots_handleclick()));
  40. connect(ui.pushButton_batch_qrcodeinvalid, SIGNAL(clicked()), this, SLOT(slots_handleclick()));
  41. connect(ui.pushButton_batch_pagermissing, SIGNAL(clicked()), this, SLOT(slots_handleclick()));
  42. connect(ui.pushButton_paper_qrcodeunmatch, SIGNAL(clicked()), this, SLOT(slots_handleclick()));
  43. connect(ui.pushButton_paper_locationexception, SIGNAL(clicked()), this, SLOT(slots_handleclick()));
  44. connect(ui.pushButton_paper_uploadfail, SIGNAL(clicked()), this, SLOT(slots_handleclick()));
  45. connect(ui.pushButton_paper_exportimg, SIGNAL(clicked()), this, SLOT(slots_handleclick()));
  46. connect(ui.pushButton_paper_deleteall, SIGNAL(clicked()), this, SLOT(slots_handleclick()));
  47. connect(ui.pushButton_reload_unhandle, SIGNAL(clicked()), this, SLOT(slots_bindUnHandle()));
  48. connect(ui.listWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(slots_listclick(QListWidgetItem*)));
  49. connect(ui.listWidget, SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*)), this, SLOT(slots_listchange(QListWidgetItem*, QListWidgetItem*)));
  50. connect(ui.pushButton_page_unhandle_batch_picwrong_check, SIGNAL(clicked()), this, SLOT(slots_pageclick()));
  51. connect(ui.pushButton_page_unhandle_batch_picwrong_scan, SIGNAL(clicked()), this, SLOT(slots_pageclick()));
  52. connect(ui.pushButton_page_unhandle_batch_unzipfail_extract, SIGNAL(clicked()), this, SLOT(slots_pageclick()));
  53. connect(ui.pushButton_page_unhandle_batch_unzipfail_scan, SIGNAL(clicked()), this, SLOT(slots_pageclick()));
  54. connect(ui.pushButton_page_unhandle_batch_papermissing_check, SIGNAL(clicked()), this, SLOT(slots_pageclick()));
  55. connect(ui.pushButton_page_unhandle_batch_papermissing_scan, SIGNAL(clicked()), this, SLOT(slots_pageclick()));
  56. connect(ui.pushButton_locationexception_rescan, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  57. connect(ui.pushButton_qrcodeinvalid_delete_paper, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  58. connect(ui.pushButton_qrcodeunmatch_delete_paper, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  59. connect(ui.pushButton_locationexception_delete_paper, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  60. connect(ui.pushButton_qrcodeunmatch_rescan, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  61. connect(ui.pushButton_qrcodeinvalid_batch_rescan, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  62. connect(ui.pushButton_qrcodeunmatch_delete_all, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  63. connect(ui.pushButton_locationexception_delete_all, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  64. connect(ui.pushButton_uploadfail_delete_all, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  65. connect(ui.pushButton_reupload, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  66. connect(ui.pushButton_page_unhandle_batch_unzipfail_delete, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  67. connect(ui.pushButton_page_unhandle_batch_picwrong_delete, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  68. connect(ui.pushButton_page_unhandle_batch_papermissing_delete, SIGNAL(clicked()), this, SLOT(slots_scanclick()));
  69. connect(ui.toolButton_checkUpdate, SIGNAL(clicked()), this, SLOT(slots_checkUpdateclick()));
  70. }
  71. void MainWidget::slots_bindUnHandle()
  72. {
  73. ui.listWidget->clear();
  74. vector<batch_info> vct = m_dataBaseService.GetFailedBatch();
  75. for (int i = 0; i < vct.size(); i++)
  76. {
  77. CExceptionBatchItem* bt = new CExceptionBatchItem();
  78. bt->SetBatchInfo(vct[i]);
  79. QListWidgetItem* pListWidgetItem = new QListWidgetItem;
  80. pListWidgetItem->setSizeHint(QSize(230, 56));
  81. ui.listWidget->addItem(pListWidgetItem);
  82. ui.listWidget->setItemWidget(pListWidgetItem, bt);
  83. }
  84. ui.label_left_unhandle_batchs->setText(QString::number(vct.size()));
  85. ui.label_page_unhandle_batchs->setText(QString::number(vct.size()));
  86. ui.stackedWidget_exception->setCurrentWidget(ui.page_wellcome);
  87. }
  88. void MainWidget::slots_listclick(QListWidgetItem* item)
  89. {
  90. ui.stackedWidget_exception->setCurrentWidget(ui.page_unhandle);
  91. CExceptionBatchItem* batch_item = (CExceptionBatchItem*)ui.listWidget->itemWidget(item);
  92. batch_item->GetBatchInfo(m_curBatch);
  93. load_exception();
  94. }
  95. void MainWidget::load_exception()
  96. {
  97. ui.pushButton_batch_unzipfail->hide();
  98. ui.pushButton_batch_picwrong->hide();
  99. ui.pushButton_batch_qrcodeinvalid->hide();
  100. ui.pushButton_batch_pagermissing->hide();
  101. ui.pushButton_paper_qrcodeunmatch->hide();
  102. ui.pushButton_paper_locationexception->hide();
  103. ui.pushButton_paper_uploadfail->hide();
  104. ui.pushButton_paper_deleteall->show();
  105. ui.label_qrcodeinvalid_tip->hide();
  106. ui.label_qrcodeunmatch_tip->hide();
  107. m_dataBaseService.GetBatchInfo(m_curBatch);
  108. if (m_curBatch.state == -1)
  109. {
  110. slots_bindUnHandle();
  111. return;
  112. }
  113. ParsePapers();
  114. if (batch_exc_unzip == m_curBatch.state)
  115. {
  116. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_unzipfail);
  117. ui.pushButton_batch_unzipfail->show();
  118. ui.pushButton_batch_unzipfail->setChecked(true);
  119. ui.pushButton_paper_deleteall->hide();
  120. }
  121. else if (batch_exc_multiple == m_curBatch.state)
  122. {
  123. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_picwrong);
  124. ui.pushButton_batch_picwrong->show();
  125. ui.pushButton_batch_picwrong->setChecked(true);
  126. ui.label_zip_paper_count->setText(QString::number(m_curBatch.zipfile_cnt));
  127. ui.pushButton_paper_deleteall->hide();
  128. }
  129. else if (batch_exc_pages_missed == m_curBatch.state)
  130. {
  131. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_pagermissing);
  132. ui.pushButton_batch_pagermissing->show();
  133. ui.pushButton_batch_pagermissing->setChecked(true);
  134. ui.pushButton_paper_deleteall->hide();
  135. }
  136. else if (batch_exc_invalid_qrcode == m_curBatch.state)
  137. {
  138. if (m_mapPapers.size() == 0) // 没有试卷了
  139. {
  140. m_dataBaseService.DeleteIndex(m_curBatch.id);
  141. slots_bindUnHandle();
  142. return;
  143. }
  144. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_qrcodeinvalid);
  145. ui.pushButton_batch_qrcodeinvalid->show();
  146. ui.pushButton_batch_qrcodeinvalid->setChecked(true);
  147. ui.widget_qrcodeinvalid_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers.begin()->second); // ui.widget_qrcodeinvalid_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_ori]);
  148. }
  149. else if (batch_exc_scan_excption == m_curBatch.state)
  150. {
  151. bool _exist_exception(false); // 是否还在有异常信息
  152. for (auto& iter : m_mapPapers)
  153. {
  154. if (iter.first > 0 && iter.second.size() > 0)
  155. {
  156. _exist_exception = true;
  157. }
  158. }
  159. if (!_exist_exception)
  160. {
  161. m_dataBaseService.DeleteIndex(m_curBatch.id);
  162. slots_bindUnHandle();
  163. return;
  164. }
  165. bool _bclicked(false);
  166. int _count = m_mapPapers[paper_exc_qrcode_unmatch].size();
  167. if (_count > 0)
  168. {
  169. ui.pushButton_paper_qrcodeunmatch->show();
  170. ui.pushButton_paper_qrcodeunmatch->setText(QString::fromStdWString(qrcodeunmatch).arg(_count));
  171. ui.pushButton_paper_qrcodeunmatch->click();
  172. ui.widget_qrcodeunmatch_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_qrcode_unmatch]);
  173. _bclicked = true;
  174. }
  175. _count = m_mapPapers[paper_exc_locate].size();
  176. if (_count > 0)
  177. {
  178. ui.pushButton_paper_locationexception->show();
  179. ui.pushButton_paper_locationexception->setText(QString::fromStdWString(locationexception).arg(_count));
  180. if (!_bclicked)
  181. {
  182. ui.pushButton_paper_locationexception->click();
  183. ui.widget_locationexception_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_locate]);
  184. _bclicked = true;
  185. }
  186. }
  187. _count = m_mapPapers[paper_exc_upload].size();
  188. if (_count > 0)
  189. {
  190. ui.pushButton_paper_uploadfail->show();
  191. ui.pushButton_paper_uploadfail->setText(QString::fromStdWString(uploadfail).arg(_count));
  192. if (!_bclicked)
  193. {
  194. ui.pushButton_paper_uploadfail->click();
  195. _bclicked = true;
  196. bind_unloadfaild(m_mapPapers[paper_exc_upload]);
  197. }
  198. }
  199. }
  200. }
  201. void MainWidget::bind_unloadfaild(vector<paper_info>& vct)
  202. {
  203. if (vct.size() == 0)
  204. {
  205. return;
  206. }
  207. m_batchpaperList.clear();
  208. //每次重新插入数据前释放Item的内存
  209. ui.tableWidget_uploadfail->clearContents();
  210. ui.tableWidget_uploadfail->horizontalHeader()->setVisible(true);
  211. ui.tableWidget_uploadfail->verticalHeader()->setVisible(false);
  212. QStringList header;
  213. header << QString::fromLocal8Bit("序号") << QString::fromLocal8Bit("二维码ID") << QString::fromLocal8Bit("作业名称")
  214. << QString::fromLocal8Bit("学科") << QString::fromLocal8Bit("学号") << QString::fromLocal8Bit("扫描时间") << QString::fromLocal8Bit("失败原因") << QString::fromLocal8Bit("状态");;
  215. ui.tableWidget_uploadfail->setHorizontalHeaderLabels(header);
  216. ui.tableWidget_uploadfail->setEditTriggers(QAbstractItemView::NoEditTriggers);
  217. ui.tableWidget_uploadfail->setSelectionMode(QAbstractItemView::NoSelection);
  218. ui.tableWidget_uploadfail->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); //x先自适应宽度
  219. ui.tableWidget_uploadfail->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); //然后设置要根据内容使用宽度的列
  220. ui.tableWidget_uploadfail->horizontalHeader()->setStyleSheet("border:1px solid rgb(216,216,216)");
  221. ui.tableWidget_uploadfail->setRowCount(vct.size());
  222. for (int i = 0; i < vct.size(); i++)
  223. {
  224. QDateTime scan_time = QDateTime::fromTime_t(vct[i].scan_time);
  225. ui.tableWidget_uploadfail->setItem(i, 0, new QTableWidgetItem(QString::number(i + 1)));
  226. ui.tableWidget_uploadfail->item(i, 0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  227. ui.tableWidget_uploadfail->setItem(i, 1, new QTableWidgetItem(vct[i].qr_code));
  228. ui.tableWidget_uploadfail->item(i, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  229. ui.tableWidget_uploadfail->setItem(i, 2, new QTableWidgetItem(QString::fromLocal8Bit(vct[i].exam_name)));
  230. ui.tableWidget_uploadfail->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  231. ui.tableWidget_uploadfail->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit(vct[i].subject_name)));
  232. ui.tableWidget_uploadfail->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  233. ui.tableWidget_uploadfail->setItem(i, 4, new QTableWidgetItem(vct[i].student_id));
  234. ui.tableWidget_uploadfail->item(i, 4)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  235. ui.tableWidget_uploadfail->setItem(i, 5, new QTableWidgetItem(scan_time.toString("yyyy-MM-dd hh:mm:ss")));
  236. ui.tableWidget_uploadfail->item(i, 5)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  237. QString err_msg = QString::fromLocal8Bit("网络异常");
  238. if (strlen(vct[i].err_msg) > 0)
  239. {
  240. err_msg = QString::fromLocal8Bit(vct[i].err_msg);
  241. }
  242. ui.tableWidget_uploadfail->setItem(i, 6, new QTableWidgetItem(err_msg));
  243. ui.tableWidget_uploadfail->item(i, 6)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  244. QString strIndex = QString("%1,%2").arg(m_curBatch.id).arg(vct[i].id);
  245. QString strShownText = QString::fromLocal8Bit("上传失败");
  246. int nStatus = m_mapUploadItemsStatus.value(strIndex);
  247. if (nStatus == 1)
  248. strShownText = QString::fromLocal8Bit("上传中");
  249. else if (nStatus == 2)
  250. strShownText = QString::fromLocal8Bit("上传完成");
  251. ui.tableWidget_uploadfail->setItem(i, 7, new QTableWidgetItem(strShownText));
  252. ui.tableWidget_uploadfail->item(i, 7)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  253. if (nStatus != 2)
  254. {
  255. m_mapUploadItemsStatus[strIndex] = nStatus;
  256. m_batchpaperList.push_back(strIndex);
  257. }
  258. }
  259. }
  260. void MainWidget::slots_listchange(QListWidgetItem* current, QListWidgetItem* pre)
  261. {
  262. }
  263. void MainWidget::slots_bindschool()
  264. {
  265. CBindSchoolInfo info(this);
  266. int rlt = info.exec();
  267. if (rlt == QDialog::Accepted)
  268. {
  269. ui.stackedWidget_init->setCurrentWidget(ui.page_main);
  270. load_schoolinfo();
  271. }
  272. }
  273. void MainWidget::slots_handleclick()
  274. {
  275. QObject* send = this->sender();
  276. if (send == ui.pushButton_batch_unzipfail)
  277. {
  278. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_unzipfail);
  279. }
  280. else if (send == ui.pushButton_batch_picwrong)
  281. {
  282. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_picwrong);
  283. }
  284. else if (send == ui.pushButton_batch_qrcodeinvalid)
  285. {
  286. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_qrcodeinvalid);
  287. }
  288. else if (send == ui.pushButton_paper_qrcodeunmatch)
  289. {
  290. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_paper_qrcodeunmatch);
  291. ui.widget_qrcodeunmatch_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_qrcode_unmatch]);
  292. }
  293. else if (send == ui.pushButton_paper_locationexception)
  294. {
  295. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_paper_locationexception);
  296. ui.widget_locationexception_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_locate]);
  297. }
  298. else if (send == ui.pushButton_batch_pagermissing)
  299. {
  300. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_pagermissing);
  301. }
  302. else if (send == ui.pushButton_paper_uploadfail)
  303. {
  304. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_paper_uploadfail);
  305. bind_unloadfaild(m_mapPapers[paper_exc_upload]);
  306. }
  307. else if (send == ui.pushButton_paper_exportimg)
  308. {
  309. Save_FileAs();
  310. }
  311. else if (send == ui.pushButton_paper_deleteall)
  312. {
  313. QString msg = QString::fromLocal8Bit("确定删除该批次吗?");
  314. QMessageBox::StandardButton result = QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), msg, QMessageBox::Yes | QMessageBox::No);
  315. if (result == QMessageBox::Yes)
  316. {
  317. m_dataBaseService.DeleteIndex(m_curBatch.id);
  318. slots_bindUnHandle();
  319. }
  320. }
  321. //QWidget* _page = ui.stackedWidget_unhandle_page->currentWidget();
  322. //QSize _size = _page->size();
  323. //_page->resize(_size - QSize(1, 1));
  324. //_page->resize(_size + QSize(1, 1));
  325. }
  326. void MainWidget::slots_pageclick()
  327. {
  328. QObject* send = this->sender();
  329. if (send == ui.pushButton_page_unhandle_batch_unzipfail_extract)
  330. {
  331. wstring _papersdir = GB2312ToUnicode(UtfToGbk(m_curBatch.work_dir).c_str());
  332. ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL);
  333. }
  334. else if (send == ui.pushButton_page_unhandle_batch_picwrong_check)
  335. {
  336. wstring _papersdir = GB2312ToUnicode(UtfToGbk(m_curBatch.work_dir).c_str());
  337. _papersdir.append(L"papers");
  338. ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL);
  339. }
  340. else if (send == ui.pushButton_page_unhandle_batch_papermissing_check)
  341. {
  342. wstring _papersdir = GB2312ToUnicode(UtfToGbk(m_curBatch.work_dir).c_str());
  343. _papersdir.append(L"papers");
  344. ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL);
  345. }
  346. else if (send == ui.pushButton_page_unhandle_batch_picwrong_scan || // 已手动解压完成去识别 与 已检查完成去识别不同点是一个是更新index.db3,一个是插件index.db3
  347. send == ui.pushButton_page_unhandle_batch_unzipfail_scan ||
  348. send == ui.pushButton_page_unhandle_batch_papermissing_scan)
  349. {
  350. wstring _papersdir = GB2312ToUnicode(UtfToGbk(m_curBatch.work_dir).c_str());
  351. _papersdir.append(L"papers");
  352. vector<string> _listPapers;
  353. DetectDirectory(_papersdir, _listPapers);
  354. if (_listPapers.size() == 0 || _listPapers.size() % 2 == 1)
  355. {
  356. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("试卷非偶数倍(仅支持JPG格式的图片)"), QMessageBox::Ok);
  357. return;
  358. }
  359. HWND hWndUnzip = NULL;
  360. HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, NULL, SHARE_MEMORY_NAME);
  361. if (hMapFile)
  362. {
  363. LPVOID lpBase = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
  364. share_memory_block* _data_block = (share_memory_block*)lpBase;
  365. hWndUnzip = (HWND)strtol(_data_block->unzip_handle, 0, 16);
  366. UnmapViewOfFile(lpBase);
  367. CloseHandle(hMapFile);
  368. }
  369. if (!IsWindow(hWndUnzip))
  370. {
  371. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("监控程序未开启"), QMessageBox::Ok);
  372. return;
  373. }
  374. wstring _batchpath = GB2312ToUnicode(UtfToGbk(m_curBatch.work_dir).c_str());
  375. _batchpath.append(L"batch.db3");
  376. bool rlt_batch = m_dataBaseService.InsertPapers(_batchpath, _listPapers);
  377. if (rlt_batch)
  378. {
  379. bool rlt_index = m_dataBaseService.UpdateIndexPicWrong(_listPapers.size() / 2, m_curBatch.id);
  380. if (rlt_index)
  381. {
  382. HWND local_hwnd = (HWND)this->winId();
  383. char buf[128] = { 0 };
  384. sprintf(buf, "%s:%d", UNHANDL_RESCAN, m_curBatch.id);
  385. COPYDATASTRUCT cpd;
  386. cpd.dwData = strlen(buf) + sizeof(COPYDATASTRUCT);
  387. cpd.cbData = strlen(buf);
  388. cpd.lpData = (void*)buf;
  389. ::SendMessage(hWndUnzip, WM_COPYDATA, (WPARAM)local_hwnd, (LPARAM)&cpd);
  390. slots_bindUnHandle();
  391. }
  392. else
  393. {
  394. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新batch.db3失败"), QMessageBox::Ok);
  395. }
  396. }
  397. else
  398. {
  399. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新index.db3失败"), QMessageBox::Ok);
  400. }
  401. }
  402. }
  403. void MainWidget::slots_scanclick()
  404. {
  405. QObject* send = this->sender();
  406. if (send == ui.pushButton_qrcodeinvalid_delete_paper)
  407. {
  408. alert_delete();
  409. paper_info _paper;
  410. ui.widget_qrcodeinvalid_edithandle->GetCurrentPaper(_paper);
  411. m_dataBaseService.DeletePaper(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id);
  412. load_exception();
  413. }
  414. else if(send == ui.pushButton_qrcodeunmatch_delete_paper)
  415. {
  416. alert_delete();
  417. paper_info _paper;
  418. ui.widget_qrcodeunmatch_edithandle->GetCurrentPaper(_paper);
  419. m_dataBaseService.DeletePaper(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id);
  420. load_exception();
  421. }
  422. else if(send == ui.pushButton_locationexception_delete_paper)
  423. {
  424. alert_delete();
  425. paper_info _paper;
  426. ui.widget_locationexception_edithandle->GetCurrentPaper(_paper);
  427. m_dataBaseService.DeletePaper(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id);
  428. load_exception();
  429. }
  430. else if (send == ui.pushButton_qrcodeinvalid_batch_rescan)
  431. {
  432. QString _qrcode = ui.lineEdit_qrcodeinvalid_batch_qrcode->text();
  433. _qrcode = _qrcode.trimmed();
  434. if (_qrcode.length() == 0)
  435. {
  436. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("未输入批次二维码ID"), QMessageBox::Ok);
  437. return;
  438. }
  439. ui.pushButton_qrcodeinvalid_batch_rescan->setText(QString::fromStdWString(scan_batch_identi));
  440. ui.pushButton_qrcodeinvalid_batch_rescan->setEnabled(false);
  441. QTimer::singleShot(50, this, [&, _qrcode](){
  442. ReBatchScan(m_curBatch.id, _qrcode.toStdString());
  443. load_exception();
  444. ui.pushButton_qrcodeinvalid_batch_rescan->setText(QString::fromStdWString(scan_batch_normal));
  445. ui.pushButton_qrcodeinvalid_batch_rescan->setEnabled(true);
  446. });
  447. }
  448. else if (send == ui.pushButton_qrcodeunmatch_rescan)
  449. {
  450. QString _qrcode = ui.lineEdit_qrcodeunmatch_qrcode->text();
  451. _qrcode = _qrcode.trimmed();
  452. if (_qrcode.length() == 0)
  453. {
  454. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("输入二维码ID"), QMessageBox::Ok);
  455. return;
  456. }
  457. ui.pushButton_qrcodeunmatch_rescan->setText(QString::fromStdWString(scan_paper_identi));
  458. ui.pushButton_qrcodeunmatch_rescan->setEnabled(false);
  459. QTimer::singleShot(50, this, [&, _qrcode](){
  460. paper_info _paper;
  461. ui.widget_qrcodeunmatch_edithandle->GetCurrentPaper(_paper);
  462. ReScan(m_curBatch.id, _paper.id, _paper.page0_path, _paper.page1_path, _qrcode.toStdString());
  463. m_dataBaseService.UpdatePapersPath(GB2312ToUnicode(m_curBatch.batchdb_path), _paper);
  464. load_exception();
  465. m_dataBaseService.GetPaperByID(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id, _paper);
  466. if ((_paper.state & paper_exc_qrcode_unmatch) == paper_exc_qrcode_unmatch)
  467. {
  468. ui.label_qrcodeunmatch_tip->show();
  469. }
  470. ui.pushButton_qrcodeunmatch_rescan->setText(QString::fromStdWString(scan_paper_normal));
  471. ui.pushButton_qrcodeunmatch_rescan->setEnabled(true);
  472. });
  473. }
  474. else if (send == ui.pushButton_locationexception_rescan)
  475. {
  476. ui.pushButton_locationexception_rescan->setText(QString::fromStdWString(scan_paper_identi));
  477. ui.pushButton_locationexception_rescan->setEnabled(false);
  478. QTimer::singleShot(50, this, [&](){
  479. paper_info _paper;
  480. ui.widget_locationexception_edithandle->GetCurrentPaper(_paper);
  481. ReScan(m_curBatch.id, _paper.id, _paper.page0_path, _paper.page1_path);
  482. m_dataBaseService.UpdatePapersPath(GB2312ToUnicode(m_curBatch.batchdb_path), _paper);
  483. load_exception();
  484. ui.pushButton_locationexception_rescan->setText(QString::fromStdWString(scan_paper_normal));
  485. ui.pushButton_locationexception_rescan->setEnabled(true);
  486. });
  487. }
  488. else if (send == ui.pushButton_qrcodeunmatch_delete_all || send == ui.pushButton_locationexception_delete_all || send == ui.pushButton_uploadfail_delete_all)
  489. {
  490. alert_delete();
  491. int state = -1;
  492. if (ui.pushButton_paper_qrcodeunmatch->isChecked())
  493. {
  494. state = paper_exc_qrcode_unmatch;
  495. }
  496. else if (ui.pushButton_paper_locationexception->isChecked())
  497. {
  498. state = paper_exc_locate;
  499. }
  500. else
  501. {
  502. state = paper_exc_upload;
  503. }
  504. m_dataBaseService.DeletePaperAll(GB2312ToUnicode(m_curBatch.batchdb_path), state);
  505. load_exception();
  506. }
  507. else if (send == ui.pushButton_reupload)
  508. {
  509. ReUploadAllFailed();
  510. //将所有上传失败项置为上传中状态
  511. for (auto strIndex : m_batchpaperList)
  512. {
  513. //非上传完成状态的项才需置为上传中状态
  514. if (m_mapUploadItemsStatus[strIndex] != 2)
  515. m_mapUploadItemsStatus[strIndex] = 1;
  516. }
  517. bind_unloadfaild(m_mapPapers[paper_exc_upload]);
  518. //slots_bindUnHandle();
  519. }
  520. else if (send == ui.pushButton_page_unhandle_batch_unzipfail_delete || send == ui.pushButton_page_unhandle_batch_picwrong_delete || send == ui.pushButton_page_unhandle_batch_papermissing_delete)
  521. {
  522. QString msg = QString::fromLocal8Bit("确定删除该批次吗?");
  523. QMessageBox::StandardButton result = QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), msg, QMessageBox::Yes | QMessageBox::No);
  524. if (result == QMessageBox::Yes)
  525. {
  526. m_dataBaseService.DeleteIndex(m_curBatch.id);
  527. slots_bindUnHandle();
  528. }
  529. }
  530. }
  531. void MainWidget::load_schoolinfo()
  532. {
  533. WCHAR school_name[MAX_PATH] = { 0 };
  534. GetPrivateProfileString(_T("USER"), _T("school_name"), _T(""), school_name, MAX_PATH, g_strConfigPath.c_str());
  535. if (_tcsclen(school_name) == 0)
  536. {
  537. return;
  538. }
  539. ui.label_top_school->setText(QString::fromStdWString(school_name));
  540. ui.label_main_school->setText(QString::fromStdWString(school_name));
  541. ui.stackedWidget_init->setCurrentWidget(ui.page_main);
  542. ui.label_top_school_static->show();
  543. ui.label_top_school->show();
  544. ui.widget_index_page->show();
  545. clear_cache();
  546. slots_bindUnHandle();
  547. }
  548. DWORD WINAPI ThreadDeleteDir(LPVOID lpThreadParameter)
  549. {
  550. vector<wstring>* pVctBath = (vector<wstring>*)lpThreadParameter;
  551. vector<wstring> vct = *pVctBath;
  552. delete pVctBath;
  553. for (auto& iter : vct )
  554. {
  555. DeleteDirectory(iter);
  556. }
  557. return 0;
  558. }
  559. void MainWidget::clear_cache()
  560. {
  561. vector<wstring> vctBatch = m_dataBaseService.GetCashBatch();
  562. if (vctBatch.size() == 0)
  563. {
  564. return;
  565. }
  566. vector<wstring>* pVctBath = new vector<wstring>(vctBatch);
  567. CreateThread(NULL, 0, ThreadDeleteDir, pVctBath, 0, NULL);
  568. }
  569. void MainWidget::Save_FileAs() //另存为
  570. {
  571. QString dirpath = QFileDialog::getExistingDirectory(this, QString::fromLocal8Bit("选择文件存放路径"), "./", QFileDialog::ShowDirsOnly);
  572. if (dirpath.size() == 0)
  573. {
  574. return;
  575. }
  576. QString export_image_path = QString("%1/exception_image_%2.zip").arg(dirpath).arg(GetTickCount());
  577. if (m_curBatch.state == batch_exc_invalid_qrcode || m_curBatch.state == batch_exc_multiple || m_curBatch.state == batch_exc_unzip)
  578. {
  579. string _zip_path = UtfToGbk(m_curBatch.work_dir);
  580. _zip_path.append(UtfToGbk(m_curBatch.zipfile_name));
  581. _zip_path.append(".zip");
  582. BOOL rlt = CopyFileA(_zip_path.c_str(), export_image_path.toStdString().c_str(), FALSE);
  583. if (rlt)
  584. {
  585. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出成功,路径:%1").arg(export_image_path), QMessageBox::Ok);
  586. }
  587. else
  588. {
  589. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出失败"), QMessageBox::Ok);
  590. }
  591. return;
  592. }
  593. char _paper_export[MAX_PATH] = { 0 };
  594. sprintf(_paper_export, "%sexport_tmp_%d/", UtfToGbk(m_curBatch.work_dir), GetTickCount());
  595. ::CreateDirectoryA(_paper_export, 0);
  596. auto create_path = [&](const char* path){
  597. string _source = path;
  598. string _file_name = _source.substr(_source.rfind('/')+1);
  599. string _path = _paper_export;
  600. _path.append(_file_name);
  601. return _path;
  602. };
  603. auto stringReplace = [](std::wstring& strContent, std::wstring strReplace, std::wstring strDest)
  604. {
  605. while (true)
  606. {
  607. size_t pos = strContent.find(strReplace);
  608. if (pos != std::wstring::npos)
  609. {
  610. WCHAR pBuf[1] = { L'\0' };
  611. strContent.replace(pos, strReplace.length(), pBuf, 0);
  612. strContent.insert(pos, strDest);
  613. }
  614. else
  615. {
  616. break;
  617. }
  618. }
  619. return 0;
  620. };
  621. for (auto& iter : m_mapPapers)
  622. {
  623. if (iter.first > 0)
  624. {
  625. for (auto& file : iter.second)
  626. {
  627. string strPage0 = UtfToGbk(file.page0_path);
  628. string strPage1 = UtfToGbk(file.page1_path);
  629. string page0_path = create_path(strPage0.c_str());
  630. string page1_path = create_path(strPage1.c_str());
  631. CopyFileA(strPage0.c_str(), page0_path.c_str(), FALSE);
  632. CopyFileA(strPage1.c_str(), page1_path.c_str(), FALSE);
  633. }
  634. }
  635. }
  636. wstring _export_dir = GB2312ToUnicode(_paper_export);
  637. wstring _export_files = _export_dir + L"*.*";
  638. stringReplace(_export_files, L"/", L"\\");
  639. BOOL rlt = ZipCompress(_export_files.c_str(), export_image_path.toStdWString().c_str());
  640. if (rlt)
  641. {
  642. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出成功,路径:%1").arg(export_image_path), QMessageBox::Ok);
  643. }
  644. else
  645. {
  646. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出失败"), QMessageBox::Ok);
  647. }
  648. //ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL);
  649. }
  650. void MainWidget::ParsePapers()
  651. {
  652. m_mapPapers.clear();
  653. wstring _papersdir = GB2312ToUnicode(m_curBatch.batchdb_path);
  654. vector<paper_info> vctPapers;
  655. m_dataBaseService.GetBatchPapers(_papersdir, vctPapers);
  656. if (vctPapers.size() == 0)
  657. {
  658. return;
  659. }
  660. for (auto& iter : vctPapers)
  661. {
  662. m_mapPapers[iter.state].push_back(iter);
  663. }
  664. }
  665. void MainWidget::slots_checkUpdateclick() // 检查更新
  666. {
  667. WCHAR server_url[MAX_PATH] = { 0 };
  668. GetPrivateProfileString(L"USER", L"server_url", L"", server_url, MAX_PATH, g_strConfigPath.c_str());
  669. QString url(QString::fromStdWString(server_url));
  670. url.append("/teacher/third/get/latestVersion?appType=0");
  671. QNetworkRequest request;
  672. request.setUrl(url);
  673. request.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json;charset=utf-8"));
  674. request.setRawHeader("Authorization", "Basic ZnhiLXNoOmVDbGo0TlRoSHlMY05USE0wZWl3ZWpVUExCcGFlZQ==");//Authorization身份验证
  675. QNetworkAccessManager manager;
  676. manager.setNetworkAccessible(QNetworkAccessManager::Accessible);
  677. QNetworkReply* reply = manager.get(request);
  678. QEventLoop eventLoop;
  679. QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
  680. eventLoop.exec();
  681. QByteArray bytes = reply->readAll(); // bytes
  682. QString response = QString::fromUtf8(bytes);
  683. QJsonParseError json_error;
  684. QJsonDocument jsonDoc = QJsonDocument::fromJson(bytes, &json_error);
  685. QString message;
  686. if (jsonDoc.isObject())
  687. {
  688. QJsonObject json_obj = jsonDoc.object();
  689. if (json_obj.contains("code") && json_obj.value("code").toInt() == 200)
  690. {
  691. if (json_obj.contains("data"))
  692. {
  693. QJsonObject json_data = json_obj.value("data").toObject();
  694. QString version = json_data.value("versionNumber").toString();
  695. QString changeLog = json_data.value("changeLog").toString();
  696. QString fileUrl = json_data.value("fileUrl").toString();
  697. if (version.compare(m_localVersion) > 0)
  698. {
  699. ui.label_new->setText("new");
  700. vector<batch_info> vct = m_dataBaseService.GetFailedBatch();
  701. UpdateDlg *updateDlg = new UpdateDlg(changeLog, version, fileUrl, vct.size()>0?true:false);
  702. updateDlg->setAttribute(Qt::WA_ShowModal, true);
  703. updateDlg->show();
  704. int ret = updateDlg->exec();
  705. }
  706. else
  707. {
  708. ui.label_new->setText("");
  709. QMessageBox box(QMessageBox::Warning, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("当前已是最新版本"));
  710. box.setStandardButtons(QMessageBox::Ok);
  711. box.setButtonText(QMessageBox::Ok, QString::fromLocal8Bit("确定"));
  712. box.exec();
  713. }
  714. }
  715. }
  716. }
  717. }