mainwidget_service.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
  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. ui.tableWidget_uploadfail->horizontalHeader()->setVisible(true);
  208. ui.tableWidget_uploadfail->verticalHeader()->setVisible(false);
  209. QStringList header;
  210. header << QString::fromLocal8Bit("序号") << QString::fromLocal8Bit("二维码ID") << QString::fromLocal8Bit("作业名称")
  211. << QString::fromLocal8Bit("学科") << QString::fromLocal8Bit("学号") << QString::fromLocal8Bit("扫描时间") << QString::fromLocal8Bit("失败原因");
  212. ui.tableWidget_uploadfail->setHorizontalHeaderLabels(header);
  213. ui.tableWidget_uploadfail->setEditTriggers(QAbstractItemView::NoEditTriggers);
  214. ui.tableWidget_uploadfail->setSelectionMode(QAbstractItemView::NoSelection);
  215. ui.tableWidget_uploadfail->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); //x先自适应宽度
  216. ui.tableWidget_uploadfail->horizontalHeader()->setSectionResizeMode(0, QHeaderView::ResizeToContents); //然后设置要根据内容使用宽度的列
  217. ui.tableWidget_uploadfail->horizontalHeader()->setStyleSheet("border:1px solid rgb(216,216,216)");
  218. ui.tableWidget_uploadfail->setRowCount(vct.size());
  219. for (int i = 0; i < vct.size(); i++)
  220. {
  221. QDateTime scan_time = QDateTime::fromTime_t(vct[i].scan_time);
  222. ui.tableWidget_uploadfail->setItem(i, 0, new QTableWidgetItem(QString::number(i+1)));
  223. ui.tableWidget_uploadfail->item(i, 0)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  224. ui.tableWidget_uploadfail->setItem(i, 1, new QTableWidgetItem(vct[i].qr_code));
  225. ui.tableWidget_uploadfail->item(i, 1)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  226. ui.tableWidget_uploadfail->setItem(i, 2, new QTableWidgetItem(QString::fromLocal8Bit(vct[i].exam_name)));
  227. ui.tableWidget_uploadfail->item(i, 2)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  228. ui.tableWidget_uploadfail->setItem(i, 3, new QTableWidgetItem(QString::fromLocal8Bit(vct[i].subject_name)));
  229. ui.tableWidget_uploadfail->item(i, 3)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  230. ui.tableWidget_uploadfail->setItem(i, 4, new QTableWidgetItem(vct[i].student_id));
  231. ui.tableWidget_uploadfail->item(i, 4)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  232. ui.tableWidget_uploadfail->setItem(i, 5, new QTableWidgetItem(scan_time.toString("yyyy-MM-dd hh:mm:ss")));
  233. ui.tableWidget_uploadfail->item(i, 5)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  234. QString err_msg = QString::fromLocal8Bit("网络异常");
  235. if (strlen(vct[i].err_msg) > 0)
  236. {
  237. err_msg = QString::fromLocal8Bit(vct[i].err_msg);
  238. }
  239. ui.tableWidget_uploadfail->setItem(i, 6, new QTableWidgetItem(err_msg));
  240. ui.tableWidget_uploadfail->item(i, 6)->setTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
  241. }
  242. }
  243. void MainWidget::slots_listchange(QListWidgetItem* current, QListWidgetItem* pre)
  244. {
  245. }
  246. void MainWidget::slots_bindschool()
  247. {
  248. CBindSchoolInfo info(this);
  249. int rlt = info.exec();
  250. if (rlt == QDialog::Accepted)
  251. {
  252. ui.stackedWidget_init->setCurrentWidget(ui.page_main);
  253. load_schoolinfo();
  254. }
  255. }
  256. void MainWidget::slots_handleclick()
  257. {
  258. QObject* send = this->sender();
  259. if (send == ui.pushButton_batch_unzipfail)
  260. {
  261. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_unzipfail);
  262. }
  263. else if (send == ui.pushButton_batch_picwrong)
  264. {
  265. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_picwrong);
  266. }
  267. else if (send == ui.pushButton_batch_qrcodeinvalid)
  268. {
  269. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_qrcodeinvalid);
  270. }
  271. else if (send == ui.pushButton_paper_qrcodeunmatch)
  272. {
  273. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_paper_qrcodeunmatch);
  274. ui.widget_qrcodeunmatch_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_qrcode_unmatch]);
  275. }
  276. else if (send == ui.pushButton_paper_locationexception)
  277. {
  278. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_paper_locationexception);
  279. ui.widget_locationexception_edithandle->setCurrentBatch(&m_curBatch, &m_mapPapers[paper_exc_locate]);
  280. }
  281. else if (send == ui.pushButton_batch_pagermissing)
  282. {
  283. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_batch_pagermissing);
  284. }
  285. else if (send == ui.pushButton_paper_uploadfail)
  286. {
  287. ui.stackedWidget_unhandle_page->setCurrentWidget(ui.page_unhandle_paper_uploadfail);
  288. bind_unloadfaild(m_mapPapers[paper_exc_upload]);
  289. }
  290. else if (send == ui.pushButton_paper_exportimg)
  291. {
  292. Save_FileAs();
  293. }
  294. else if (send == ui.pushButton_paper_deleteall)
  295. {
  296. QString msg = QString::fromLocal8Bit("确定删除该批次吗?");
  297. QMessageBox::StandardButton result = QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), msg, QMessageBox::Yes | QMessageBox::No);
  298. if (result == QMessageBox::Yes)
  299. {
  300. m_dataBaseService.DeleteIndex(m_curBatch.id);
  301. slots_bindUnHandle();
  302. }
  303. }
  304. //QWidget* _page = ui.stackedWidget_unhandle_page->currentWidget();
  305. //QSize _size = _page->size();
  306. //_page->resize(_size - QSize(1, 1));
  307. //_page->resize(_size + QSize(1, 1));
  308. }
  309. void MainWidget::slots_pageclick()
  310. {
  311. QObject* send = this->sender();
  312. if (send == ui.pushButton_page_unhandle_batch_unzipfail_extract)
  313. {
  314. wstring _papersdir = GB2312ToUnicode(m_curBatch.work_dir);
  315. ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL);
  316. }
  317. else if (send == ui.pushButton_page_unhandle_batch_picwrong_check)
  318. {
  319. wstring _papersdir = GB2312ToUnicode(m_curBatch.work_dir);
  320. _papersdir.append(L"papers");
  321. ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL);
  322. }
  323. else if (send == ui.pushButton_page_unhandle_batch_papermissing_check)
  324. {
  325. wstring _papersdir = GB2312ToUnicode(m_curBatch.work_dir);
  326. _papersdir.append(L"papers");
  327. ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL);
  328. }
  329. else if (send == ui.pushButton_page_unhandle_batch_picwrong_scan || // 已手动解压完成去识别 与 已检查完成去识别不同点是一个是更新index.db3,一个是插件index.db3
  330. send == ui.pushButton_page_unhandle_batch_unzipfail_scan ||
  331. send == ui.pushButton_page_unhandle_batch_papermissing_scan)
  332. {
  333. wstring _papersdir = GB2312ToUnicode(m_curBatch.work_dir);
  334. _papersdir.append(L"papers");
  335. vector<string> _listPapers;
  336. DetectDirectory(_papersdir, _listPapers);
  337. if (_listPapers.size() == 0 || _listPapers.size() % 2 == 1)
  338. {
  339. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("试卷非偶数倍(仅支持JPG格式的图片)"), QMessageBox::Ok);
  340. return;
  341. }
  342. HWND hWndUnzip = NULL;
  343. HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS, NULL, SHARE_MEMORY_NAME);
  344. if (hMapFile)
  345. {
  346. LPVOID lpBase = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
  347. share_memory_block* _data_block = (share_memory_block*)lpBase;
  348. hWndUnzip = (HWND)strtol(_data_block->unzip_handle, 0, 16);
  349. UnmapViewOfFile(lpBase);
  350. CloseHandle(hMapFile);
  351. }
  352. if (!IsWindow(hWndUnzip))
  353. {
  354. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("监控程序未开启"), QMessageBox::Ok);
  355. return;
  356. }
  357. wstring _batchpath = GB2312ToUnicode(m_curBatch.work_dir);
  358. _batchpath.append(L"batch.db3");
  359. bool rlt_batch = m_dataBaseService.InsertPapers(_batchpath, _listPapers);
  360. if (rlt_batch)
  361. {
  362. bool rlt_index = m_dataBaseService.UpdateIndexPicWrong(_listPapers.size() / 2, m_curBatch.id);
  363. if (rlt_index)
  364. {
  365. HWND local_hwnd = (HWND)this->winId();
  366. char buf[128] = { 0 };
  367. sprintf(buf, "%s:%d", UNHANDL_RESCAN, m_curBatch.id);
  368. COPYDATASTRUCT cpd;
  369. cpd.dwData = strlen(buf) + sizeof(COPYDATASTRUCT);
  370. cpd.cbData = strlen(buf);
  371. cpd.lpData = (void*)buf;
  372. ::SendMessage(hWndUnzip, WM_COPYDATA, (WPARAM)local_hwnd, (LPARAM)&cpd);
  373. slots_bindUnHandle();
  374. }
  375. else
  376. {
  377. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新batch.db3失败"), QMessageBox::Ok);
  378. }
  379. }
  380. else
  381. {
  382. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("更新index.db3失败"), QMessageBox::Ok);
  383. }
  384. }
  385. }
  386. void MainWidget::slots_scanclick()
  387. {
  388. QObject* send = this->sender();
  389. if (send == ui.pushButton_qrcodeinvalid_delete_paper)
  390. {
  391. alert_delete();
  392. paper_info _paper;
  393. ui.widget_qrcodeinvalid_edithandle->GetCurrentPaper(_paper);
  394. m_dataBaseService.DeletePaper(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id);
  395. load_exception();
  396. }
  397. else if(send == ui.pushButton_qrcodeunmatch_delete_paper)
  398. {
  399. alert_delete();
  400. paper_info _paper;
  401. ui.widget_qrcodeunmatch_edithandle->GetCurrentPaper(_paper);
  402. m_dataBaseService.DeletePaper(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id);
  403. load_exception();
  404. }
  405. else if(send == ui.pushButton_locationexception_delete_paper)
  406. {
  407. alert_delete();
  408. paper_info _paper;
  409. ui.widget_locationexception_edithandle->GetCurrentPaper(_paper);
  410. m_dataBaseService.DeletePaper(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id);
  411. load_exception();
  412. }
  413. else if (send == ui.pushButton_qrcodeinvalid_batch_rescan)
  414. {
  415. QString _qrcode = ui.lineEdit_qrcodeinvalid_batch_qrcode->text();
  416. _qrcode = _qrcode.trimmed();
  417. if (_qrcode.length() == 0)
  418. {
  419. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("未输入批次二维码ID"), QMessageBox::Ok);
  420. return;
  421. }
  422. ui.pushButton_qrcodeinvalid_batch_rescan->setText(QString::fromStdWString(scan_batch_identi));
  423. ui.pushButton_qrcodeinvalid_batch_rescan->setEnabled(false);
  424. QTimer::singleShot(50, this, [&, _qrcode](){
  425. ReBatchScan(m_curBatch.id, _qrcode.toStdString());
  426. load_exception();
  427. ui.pushButton_qrcodeinvalid_batch_rescan->setText(QString::fromStdWString(scan_batch_normal));
  428. ui.pushButton_qrcodeinvalid_batch_rescan->setEnabled(true);
  429. });
  430. }
  431. else if (send == ui.pushButton_qrcodeunmatch_rescan)
  432. {
  433. QString _qrcode = ui.lineEdit_qrcodeunmatch_qrcode->text();
  434. _qrcode = _qrcode.trimmed();
  435. if (_qrcode.length() == 0)
  436. {
  437. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("输入二维码ID"), QMessageBox::Ok);
  438. return;
  439. }
  440. ui.pushButton_qrcodeunmatch_rescan->setText(QString::fromStdWString(scan_paper_identi));
  441. ui.pushButton_qrcodeunmatch_rescan->setEnabled(false);
  442. QTimer::singleShot(50, this, [&, _qrcode](){
  443. paper_info _paper;
  444. ui.widget_qrcodeunmatch_edithandle->GetCurrentPaper(_paper);
  445. ReScan(m_curBatch.id, _paper.id, _paper.page0_path, _paper.page1_path, _qrcode.toStdString());
  446. m_dataBaseService.UpdatePapersPath(GB2312ToUnicode(m_curBatch.batchdb_path), _paper);
  447. load_exception();
  448. m_dataBaseService.GetPaperByID(GB2312ToUnicode(m_curBatch.batchdb_path), _paper.id, _paper);
  449. if ((_paper.state & paper_exc_qrcode_unmatch) == paper_exc_qrcode_unmatch)
  450. {
  451. ui.label_qrcodeunmatch_tip->show();
  452. }
  453. ui.pushButton_qrcodeunmatch_rescan->setText(QString::fromStdWString(scan_paper_normal));
  454. ui.pushButton_qrcodeunmatch_rescan->setEnabled(true);
  455. });
  456. }
  457. else if (send == ui.pushButton_locationexception_rescan)
  458. {
  459. ui.pushButton_locationexception_rescan->setText(QString::fromStdWString(scan_paper_identi));
  460. ui.pushButton_locationexception_rescan->setEnabled(false);
  461. QTimer::singleShot(50, this, [&](){
  462. paper_info _paper;
  463. ui.widget_locationexception_edithandle->GetCurrentPaper(_paper);
  464. ReScan(m_curBatch.id, _paper.id, _paper.page0_path, _paper.page1_path);
  465. m_dataBaseService.UpdatePapersPath(GB2312ToUnicode(m_curBatch.batchdb_path), _paper);
  466. load_exception();
  467. ui.pushButton_locationexception_rescan->setText(QString::fromStdWString(scan_paper_normal));
  468. ui.pushButton_locationexception_rescan->setEnabled(true);
  469. });
  470. }
  471. else if (send == ui.pushButton_qrcodeunmatch_delete_all || send == ui.pushButton_locationexception_delete_all || send == ui.pushButton_uploadfail_delete_all)
  472. {
  473. alert_delete();
  474. int state = -1;
  475. if (ui.pushButton_paper_qrcodeunmatch->isChecked())
  476. {
  477. state = paper_exc_qrcode_unmatch;
  478. }
  479. else if (ui.pushButton_paper_locationexception->isChecked())
  480. {
  481. state = paper_exc_locate;
  482. }
  483. else
  484. {
  485. state = paper_exc_upload;
  486. }
  487. m_dataBaseService.DeletePaperAll(GB2312ToUnicode(m_curBatch.batchdb_path), state);
  488. load_exception();
  489. }
  490. else if (send == ui.pushButton_reupload)
  491. {
  492. ReUploadAllFailed();
  493. slots_bindUnHandle();
  494. }
  495. 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)
  496. {
  497. QString msg = QString::fromLocal8Bit("确定删除该批次吗?");
  498. QMessageBox::StandardButton result = QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), msg, QMessageBox::Yes | QMessageBox::No);
  499. if (result == QMessageBox::Yes)
  500. {
  501. m_dataBaseService.DeleteIndex(m_curBatch.id);
  502. slots_bindUnHandle();
  503. }
  504. }
  505. }
  506. void MainWidget::load_schoolinfo()
  507. {
  508. WCHAR school_name[MAX_PATH] = { 0 };
  509. GetPrivateProfileString(_T("USER"), _T("school_name"), _T(""), school_name, MAX_PATH, g_strConfigPath.c_str());
  510. if (_tcsclen(school_name) == 0)
  511. {
  512. return;
  513. }
  514. ui.label_top_school->setText(QString::fromStdWString(school_name));
  515. ui.label_main_school->setText(QString::fromStdWString(school_name));
  516. ui.stackedWidget_init->setCurrentWidget(ui.page_main);
  517. ui.label_top_school_static->show();
  518. ui.label_top_school->show();
  519. ui.widget_index_page->show();
  520. clear_cache();
  521. slots_bindUnHandle();
  522. }
  523. DWORD WINAPI ThreadDeleteDir(LPVOID lpThreadParameter)
  524. {
  525. vector<wstring>* pVctBath = (vector<wstring>*)lpThreadParameter;
  526. vector<wstring> vct = *pVctBath;
  527. delete pVctBath;
  528. for (auto& iter : vct )
  529. {
  530. DeleteDirectory(iter);
  531. }
  532. return 0;
  533. }
  534. void MainWidget::clear_cache()
  535. {
  536. vector<wstring> vctBatch = m_dataBaseService.GetCashBatch();
  537. if (vctBatch.size() == 0)
  538. {
  539. return;
  540. }
  541. vector<wstring>* pVctBath = new vector<wstring>(vctBatch);
  542. CreateThread(NULL, 0, ThreadDeleteDir, pVctBath, 0, NULL);
  543. }
  544. void MainWidget::Save_FileAs() //另存为
  545. {
  546. QString dirpath = QFileDialog::getExistingDirectory(this, QString::fromLocal8Bit("选择文件存放路径"), "./", QFileDialog::ShowDirsOnly);
  547. if (dirpath.size() == 0)
  548. {
  549. return;
  550. }
  551. QString export_image_path = QString("%1/exception_image_%2.zip").arg(dirpath).arg(GetTickCount());
  552. if (m_curBatch.state == batch_exc_invalid_qrcode || m_curBatch.state == batch_exc_multiple || m_curBatch.state == batch_exc_unzip)
  553. {
  554. string _zip_path = m_curBatch.work_dir;
  555. _zip_path.append(m_curBatch.zipfile_name);
  556. _zip_path.append(".zip");
  557. BOOL rlt = CopyFileA(_zip_path.c_str(), export_image_path.toStdString().c_str(), FALSE);
  558. if (rlt)
  559. {
  560. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出成功,路径:%1").arg(export_image_path), QMessageBox::Ok);
  561. }
  562. else
  563. {
  564. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出失败"), QMessageBox::Ok);
  565. }
  566. return;
  567. }
  568. char _paper_export[MAX_PATH] = { 0 };
  569. sprintf(_paper_export, "%sexport_tmp_%d/", m_curBatch.work_dir, GetTickCount());
  570. ::CreateDirectoryA(_paper_export, 0);
  571. auto create_path = [&](char* path){
  572. string _source = path;
  573. string _file_name = _source.substr(_source.rfind('/')+1);
  574. string _path = _paper_export;
  575. _path.append(_file_name);
  576. return _path;
  577. };
  578. auto stringReplace = [](std::wstring& strContent, std::wstring strReplace, std::wstring strDest)
  579. {
  580. while (true)
  581. {
  582. size_t pos = strContent.find(strReplace);
  583. if (pos != std::wstring::npos)
  584. {
  585. WCHAR pBuf[1] = { L'\0' };
  586. strContent.replace(pos, strReplace.length(), pBuf, 0);
  587. strContent.insert(pos, strDest);
  588. }
  589. else
  590. {
  591. break;
  592. }
  593. }
  594. return 0;
  595. };
  596. for (auto& iter : m_mapPapers)
  597. {
  598. if (iter.first > 0)
  599. {
  600. for (auto& file : iter.second)
  601. {
  602. string page0_path = create_path(file.page0_path);
  603. string page1_path = create_path(file.page1_path);
  604. CopyFileA(file.page0_path, page0_path.c_str(), FALSE);
  605. CopyFileA(file.page1_path, page1_path.c_str(), FALSE);
  606. }
  607. }
  608. }
  609. wstring _export_dir = GB2312ToUnicode(_paper_export);
  610. wstring _export_files = _export_dir + L"*.*";
  611. stringReplace(_export_files, L"/", L"\\");
  612. BOOL rlt = ZipCompress(_export_files.c_str(), export_image_path.toStdWString().c_str());
  613. if (rlt)
  614. {
  615. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出成功,路径:%1").arg(export_image_path), QMessageBox::Ok);
  616. }
  617. else
  618. {
  619. QMessageBox::information(NULL, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("异常图片导出失败"), QMessageBox::Ok);
  620. }
  621. //ShellExecute(NULL, L"open", NULL, NULL, _papersdir.c_str(), SW_SHOWNORMAL);
  622. }
  623. void MainWidget::ParsePapers()
  624. {
  625. m_mapPapers.clear();
  626. wstring _papersdir = GB2312ToUnicode(m_curBatch.batchdb_path);
  627. vector<paper_info> vctPapers;
  628. m_dataBaseService.GetBatchPapers(_papersdir, vctPapers);
  629. if (vctPapers.size() == 0)
  630. {
  631. return;
  632. }
  633. for (auto& iter : vctPapers)
  634. {
  635. m_mapPapers[iter.state].push_back(iter);
  636. }
  637. }
  638. void MainWidget::slots_checkUpdateclick() // 检查更新
  639. {
  640. WCHAR server_url[MAX_PATH] = { 0 };
  641. GetPrivateProfileString(L"USER", L"server_url", L"", server_url, MAX_PATH, g_strConfigPath.c_str());
  642. QString url(QString::fromStdWString(server_url));
  643. url.append("/teacher/third/get/latestVersion?appType=0");
  644. QNetworkRequest request;
  645. request.setUrl(url);
  646. request.setHeader(QNetworkRequest::ContentTypeHeader, QLatin1String("application/json;charset=utf-8"));
  647. request.setRawHeader("Authorization", "Basic ZnhiLXNoOmVDbGo0TlRoSHlMY05USE0wZWl3ZWpVUExCcGFlZQ==");//Authorization身份验证
  648. QNetworkAccessManager manager;
  649. manager.setNetworkAccessible(QNetworkAccessManager::Accessible);
  650. QNetworkReply* reply = manager.get(request);
  651. QEventLoop eventLoop;
  652. QObject::connect(&manager, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
  653. eventLoop.exec();
  654. QByteArray bytes = reply->readAll(); // bytes
  655. QString response = QString::fromUtf8(bytes);
  656. QJsonParseError json_error;
  657. QJsonDocument jsonDoc = QJsonDocument::fromJson(bytes, &json_error);
  658. QString message;
  659. if (jsonDoc.isObject())
  660. {
  661. QJsonObject json_obj = jsonDoc.object();
  662. if (json_obj.contains("code") && json_obj.value("code").toInt() == 200)
  663. {
  664. if (json_obj.contains("data"))
  665. {
  666. QJsonObject json_data = json_obj.value("data").toObject();
  667. QString version = json_data.value("versionNumber").toString();
  668. QString changeLog = json_data.value("changeLog").toString();
  669. QString fileUrl = json_data.value("fileUrl").toString();
  670. if (m_localVersion!=version)
  671. {
  672. ui.label_new->setText("new");
  673. vector<batch_info> vct = m_dataBaseService.GetFailedBatch();
  674. UpdateDlg *updateDlg = new UpdateDlg(changeLog, version, fileUrl, vct.size()>0?true:false);
  675. updateDlg->setAttribute(Qt::WA_ShowModal, true);
  676. updateDlg->show();
  677. int ret = updateDlg->exec();
  678. }
  679. else
  680. {
  681. ui.label_new->setText("");
  682. QMessageBox box(QMessageBox::Warning, QString::fromLocal8Bit("提示"), QString::fromLocal8Bit("当前已是最新版本"));
  683. box.setStandardButtons(QMessageBox::Ok);
  684. box.setButtonText(QMessageBox::Ok, QString::fromLocal8Bit("确定"));
  685. box.exec();
  686. }
  687. }
  688. }
  689. }
  690. }