SmartEvaluationLogicDLL.cpp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  1. #include "stdafx.h"
  2. #include "SmartEvaluationLogicDLL.h"
  3. #include "SmartEvaluationService.h"
  4. #include <vector>
  5. #include "ServerConfig.h"
  6. #include "IdentifyEngine.h"
  7. #include "ImgUploadManager.h"
  8. #include "BatchManager.h"
  9. #include "Bantch.h"
  10. //#include "Log4cplusInitalizer.h"
  11. #include "..\Identifier\CrossDetector.h"
  12. #include "DnowLoadImg.h"
  13. #include "CMyHttpClient.h"
  14. #include <io.h>
  15. #include <chrono>
  16. #include <ctime>
  17. #include <tuple>
  18. extern int g_my_scan_type;
  19. extern int g_my_continue_scan;
  20. //督学卡学校id
  21. extern std::string g_strShoolId;
  22. extern int g_myindex;
  23. extern bool g_isAllSubject;//是否是全学科
  24. /*全局设置相关*/
  25. SMARTEVALUATIONLOGIC_API int SetCookie(std::string path, std::string name, std::string value)
  26. {
  27. return CIdentifyEngine::GetInstance()->SetCookie(path, name, value);
  28. }
  29. SMARTEVALUATIONLOGIC_API int SetLocalServerCookie(std::string name, std::string value)
  30. {
  31. return CIdentifyEngine::GetInstance()->SetLocalServerCookie(name, value);
  32. }
  33. SMARTEVALUATIONLOGIC_API int SetServerUrl(std::string server_url)
  34. {
  35. return CIdentifyEngine::GetInstance()->SetServerUrl(server_url);
  36. }
  37. SMARTEVALUATIONLOGIC_API int InitalizeScan(bool bOnlineCard, int subjectid, int nOnlineScanType)
  38. {
  39. CBatchManager::Get()->initalize(bOnlineCard, subjectid, nOnlineScanType);
  40. return TRUE;
  41. }
  42. SMARTEVALUATIONLOGIC_API int SetScanConfig(std::string app_data_dir, std::string scan_data_dir)
  43. {
  44. return CIdentifyEngine::GetInstance()->SetScanConfig(app_data_dir, scan_data_dir);
  45. }
  46. /*扫描仪相关*/
  47. int GetScannerList(vector<SCANNER_INFO> & scannerList)
  48. {
  49. return CSeparateThreadTwainFeeder::Get()->GetScannerList(scannerList);
  50. }
  51. int GetDefaultScannerInfo(SCANNER_INFO &scannerInfo)
  52. {
  53. return CSeparateThreadTwainFeeder::Get()->GetDefaultScannerInfo(scannerInfo);
  54. }
  55. int ConnectScanner(const int nIndex)
  56. {
  57. return CSeparateThreadTwainFeeder::Get()->ConnectScanner(nIndex);
  58. }
  59. int ShowScannerSetting(const unsigned int nId)
  60. {
  61. return CSeparateThreadTwainFeeder::Get()->ShowScannerSetting(nId);
  62. }
  63. SMARTEVALUATIONLOGIC_API int DisconnectScanner()
  64. {
  65. return CSeparateThreadTwainFeeder::Get()->DisconnectScanner();
  66. }
  67. /*图片上传相关*/
  68. int SetHandlerWndForImg(HWND hwnd){
  69. return CImgUploadManager::GetInstance()->SetHandlerWndForImg(hwnd);
  70. }
  71. SMARTEVALUATIONLOGIC_API int StartUploadePaperImg()
  72. {
  73. // Log4cplusInitalizer::initalize();
  74. return CImgUploadManager::GetInstance()->StartUploadePaperImg();
  75. }
  76. SMARTEVALUATIONLOGIC_API int QueryUploadePaperImg(vector<IMG_UPLOAD_TASK>& tasks)
  77. {
  78. return CImgUploadManager::GetInstance()->QueryUploadePaperImg(tasks);
  79. }
  80. SMARTEVALUATIONLOGIC_API int ClearUploadedPaperImg()
  81. {
  82. return CImgUploadManager::GetInstance()->ClearUploadedPaperImg();
  83. }
  84. SMARTEVALUATIONLOGIC_API int GetCurrentUploadTaskInfo(IMG_UPLOAD_TASK& task)
  85. {
  86. return CImgUploadManager::GetInstance()->GetCurrentUploadTaskInfo(task);
  87. }
  88. SMARTEVALUATIONLOGIC_API int StopUploadePaperImg()
  89. {
  90. return CImgUploadManager::GetInstance()->StopUploadePaperImg();
  91. }
  92. /*扫描相关*/
  93. SMARTEVALUATIONLOGIC_API int ReadyScanEX(FEEDER_TYPE feederType, const ScanParam & param)
  94. {
  95. if (g_my_scan_type == 0)
  96. setRunFlag(_T("1"));
  97. else
  98. setRunFlag(_T("0"));
  99. if (g_my_scan_type == 0)
  100. setRunUploadFlag(_T("1"));
  101. else
  102. setRunUploadFlag(_T("0"));
  103. return CBatchManager::Get()->GetCurrentBatch()->ReadyScanEX(feederType, param);
  104. }
  105. bool DeleteDirectory(CString sDirName);
  106. int Start(){
  107. g_myindex = 1;
  108. return CBatchManager::Get()->GetCurrentBatch()->OnBnClickedButtonStartScan();
  109. }
  110. int Pause()
  111. {
  112. return CBatchManager::Get()->GetCurrentBatch()->Pause();
  113. }
  114. int Resume()
  115. {
  116. return CBatchManager::Get()->GetCurrentBatch()->Resume();
  117. }
  118. int Stop()
  119. {
  120. g_myindex = MAX_STRUENTS_NUM;
  121. return CBatchManager::Get()->GetCurrentBatch()->Stop();
  122. }
  123. int SetHandlerWnd(HWND hwnd)
  124. {
  125. boost::shared_ptr<CBatch> batch = CBatchManager::Get()->createNewBatch();
  126. return CBatchManager::Get()->GetCurrentBatch()->SetHandlerWnd(hwnd);
  127. }
  128. static std::string getTimeStamp()
  129. {
  130. auto tp = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
  131. auto tmp = std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch());
  132. std::time_t timestamp = tmp.count();
  133. return std::move(std::to_string(timestamp));
  134. }
  135. bool DeleteDirectory(CString sDirName);
  136. SMARTEVALUATIONLOGIC_API int ReIdentify(const int paper_id, const std::string& stu_code, std::vector<img_param> params)
  137. {
  138. std::string img_path = CServerConfig::app_data_dir_string + "\\ErrorHandleImgTmp\\";
  139. // if (_access(img_path.c_str(), 0) == 0){
  140. // DeleteDirectory(_T("D:\\ErrorHandleImgTmp"));
  141. // }
  142. if (_access(img_path.c_str(), 0) != 0){
  143. CreateDirectoryA(img_path.c_str(), NULL);
  144. }
  145. for (auto& it : params){
  146. std::string new_path = img_path + getTimeStamp() + ".jpg";
  147. CopyFileA(it.img_path, new_path.c_str(), false);
  148. strcpy(it.img_path, new_path.c_str());
  149. // printf("重新扫描老路径:%s\n", it.img_path);
  150. // printf("重新扫描新路径:%s\n", new_path.c_str());
  151. Sleep(300);
  152. }
  153. return CBatchManager::Get()->GetCurrentBatch()->ReIdentify(paper_id, stu_code, params);
  154. }
  155. SMARTEVALUATIONLOGIC_API int QueryExceptionPaper(const long exception_type, vector<STUDENT_INFO> &studengList)
  156. {
  157. return CBatchManager::Get()->GetCurrentBatch()->QueryExceptionPaper(exception_type, studengList);
  158. }
  159. SMARTEVALUATIONLOGIC_API int QueryPaperDetail(const int paper_id, PAPER_DETAIL &paper_detail, vector<PAGE_DETAIL> &pageList, vector<GROUP_QUESTION> &questionList)
  160. {
  161. return CBatchManager::Get()->GetCurrentBatch()->QueryPaperDetail(paper_id, paper_detail, pageList, questionList);
  162. }
  163. SMARTEVALUATIONLOGIC_API int UpdatePaperStudent(const int paper_id, const std::string examinee_id, const std::string student_code, const std::string studentName, const long schoolId, const std::string stuCode, const std::string stuSchoolCode, const std::string className, const std::string gradeName, bool bReIdentify /*= false*/)
  164. {
  165. return CBatchManager::Get()->GetCurrentBatch()->UpdatePaperStudent(paper_id, examinee_id, student_code, studentName, schoolId, stuCode, stuSchoolCode, className, gradeName, bReIdentify);
  166. }
  167. int IgnorePaper(const int paper_id)
  168. {
  169. return CBatchManager::Get()->GetCurrentBatch()->IgnorePaper(paper_id);
  170. }
  171. int ReplacePaper(const int paper_id, int &paper_id_ret)
  172. {
  173. return CBatchManager::Get()->GetCurrentBatch()->ReplacePaper(paper_id, paper_id_ret);
  174. }
  175. int ReplaceAllKaoHaoChongTu(vector<int> &paper_id_List)
  176. {
  177. return CBatchManager::Get()->GetCurrentBatch()->ReplaceAllKaoHaoChongTu(paper_id_List);
  178. }
  179. int IgnoreException(const long exceptions)
  180. {
  181. return CBatchManager::Get()->GetCurrentBatch()->IgnoreException(exceptions);
  182. }
  183. SMARTEVALUATIONLOGIC_API int StartUploadPaper(HWND hWnd)
  184. {
  185. return CBatchManager::Get()->GetCurrentBatch()->StartUploadPaper(hWnd);
  186. }
  187. SMARTEVALUATIONLOGIC_API int ClearDbTemp()
  188. {
  189. return CBatchManager::Get()->GetCurrentBatch()->ClearDbTemp();
  190. }
  191. SMARTEVALUATIONLOGIC_API int GiveUpCurrentBatch()
  192. {
  193. return CBatchManager::Get()->GiveUpCurrentBatch();
  194. }
  195. SMARTEVALUATIONLOGIC_API int SetFolderScanDir(const std::string img_dir)
  196. {
  197. return CBatchManager::Get()->GetCurrentBatch()->SetFolderScanDir(img_dir);
  198. }
  199. SMARTEVALUATIONLOGIC_API int QueryExptionPaperCount(int & exc_count, int & total_count)
  200. {
  201. return CBatchManager::Get()->GetCurrentBatch()->QueryExptionPaperCount(exc_count,total_count);
  202. }
  203. SMARTEVALUATIONLOGIC_API int QueryExptionTypeInfo(vector<EXCEPTION_TYPE_INFO> & infos)
  204. {
  205. return CBatchManager::Get()->GetCurrentBatch()->QueryExptionTypeInfo(infos);
  206. }
  207. SMARTEVALUATIONLOGIC_API string GetBatchCode()
  208. {
  209. return CBatchManager::Get()->GetCurrentBatch()->GetBatchCode();
  210. }
  211. SMARTEVALUATIONLOGIC_API int LoadSchema(long long examId, std::string examName, long examCourseId, std::string courseName, const std::string schemaPath, std::string rule/* = ""*/)
  212. {
  213. return CBatchManager::Get()->GetCurrentBatch()->LoadSchema(examId, examName, examCourseId, courseName, schemaPath,rule);
  214. }
  215. SMARTEVALUATIONLOGIC_API int QueryNormalPaper(vector<STUDENT_INFO> &studengList)
  216. {
  217. return CBatchManager::Get()->GetCurrentBatch()->QueryNormalPaper(studengList);
  218. }
  219. SMARTEVALUATIONLOGIC_API int QueryMubanImgPath(int page_index, std::string& imgPath)
  220. {
  221. return CBatchManager::Get()->GetCurrentBatch()->QueryMubanImgPath(page_index, imgPath);
  222. }
  223. SMARTEVALUATIONLOGIC_API int GetServiceSate()
  224. {
  225. return CBatchManager::Get()->GetCurrentBatch()->GetServiceSate();
  226. }
  227. SMARTEVALUATIONLOGIC_API int QueryMubanImgCount(int& page_count)
  228. {
  229. return CBatchManager::Get()->GetCurrentBatch()->QueryMubanImgCount(page_count);
  230. }
  231. SMARTEVALUATIONLOGIC_API int DetectCross(const IplImage * img, int detect_x, int detect_y, int detect_w, int detect_h, std::vector<Cross>& crosss)
  232. {
  233. IplImage t;
  234. cvInitImageHeader(&t, cvSize(img->width, img->height), img->depth, img->nChannels, img->origin, img->align);
  235. cvSetData(&t, img->imageData, img->widthStep);
  236. IplImage * img_ = &t;
  237. int left0 = detect_x;
  238. int top0 = detect_y;
  239. int right0 = detect_x + detect_w - 1;
  240. int bottom0 = detect_y + detect_h - 1;
  241. int left = max(left0 - 20, 0);
  242. int top = max(top0 - 20, 0);
  243. int right = min(right0 + 20, img_->width - 1);
  244. int bottom = min(bottom0 + 20, img_->height - 1);
  245. CvRect roi = cvRect(left, top, right - left + 1, bottom-top+1);
  246. cvSetImageROI(img_, roi);
  247. CCrossDetector detector;
  248. std::vector<CvCross> cross_;
  249. detector.Detect(img_, cross_);
  250. for (int i = 0; i < cross_.size();i++)
  251. {
  252. if (cross_[i].x >= left0&&cross_[i].x <= right0&&cross_[i].y >= top0&&cross_[i].y <= bottom0){
  253. Cross c;
  254. c.x = cross_[i].x;
  255. c.y = cross_[i].y;
  256. c.signal = cross_[i].sign;
  257. c.angle = cross_[i].arg;
  258. crosss.push_back(c);
  259. }
  260. }
  261. return 0;
  262. }
  263. SMARTEVALUATIONLOGIC_API int leaveCurrentBatch()
  264. {
  265. return CBatchManager::Get()->leaveCurrentBatch();
  266. }
  267. SMARTEVALUATIONLOGIC_API int AiReadImgPaper(const int subject, int id, std::vector<questionAi> aiVec, const vector<std::wstring> imgPath, vector<vector<AI_RET_RECT2>> &retList)
  268. {
  269. std::vector<CString> path;
  270. for (int i = 0; i < imgPath.size(); i++)
  271. {
  272. path.push_back((CString)imgPath[i].c_str());
  273. }
  274. return CImgUploadManager::GetInstance()->AiReadImgPaper(subject, id, aiVec, path, retList);
  275. }
  276. SMARTEVALUATIONLOGIC_API int SetScanInspector(int ntype, std::string strShoolID)
  277. {
  278. g_my_scan_type = ntype;
  279. g_strShoolId = strShoolID;
  280. g_myindex = 1;
  281. return 0;
  282. }
  283. SMARTEVALUATIONLOGIC_API int DownLoadImg(HWND hWnd, std::string strExamId, int type)
  284. {
  285. int flag = 0;
  286. CDnowLoadImg::GetInstance()->SetHandlerWnd(hWnd);
  287. CDnowLoadImg::GetInstance()->SetExamId(strExamId);
  288. CDnowLoadImg::GetInstance()->SetType(type);
  289. CDnowLoadImg::GetInstance()->Start();
  290. return flag;
  291. }
  292. SMARTEVALUATIONLOGIC_API int HttpDownloadTemplate(std::string from, std::string fileName)
  293. {
  294. int len;
  295. int slength = (int)from.length() + 1;
  296. len = MultiByteToWideChar(CP_ACP, 0, from.c_str(), slength, 0, 0);
  297. wchar_t* buf = new wchar_t[len];
  298. MultiByteToWideChar(CP_ACP, 0, from.c_str(), slength, buf, len);
  299. std::wstring r(buf);
  300. delete[] buf;
  301. std::vector<char> data;
  302. CMyHttpClient::GetInstance()->HttpDownload(r.c_str(), NULL, data);
  303. slength = (int)fileName.length() + 1;
  304. len = MultiByteToWideChar(CP_ACP, 0, fileName.c_str(), slength, 0, 0);
  305. wchar_t* buf2 = new wchar_t[len];
  306. MultiByteToWideChar(CP_ACP, 0, fileName.c_str(), slength, buf2, len);
  307. std::wstring r2(buf2);
  308. CFile file;
  309. if (file.Open(r2.c_str(), CFile::modeCreate | CFile::modeWrite))
  310. {
  311. file.Write(data.data(), data.size());
  312. file.Close();
  313. delete[] buf2;
  314. return data.size();
  315. }
  316. file.Close();
  317. delete[] buf2;
  318. return 0;
  319. }
  320. SMARTEVALUATIONLOGIC_API int CloseContineScan()
  321. {
  322. g_my_continue_scan = 0;
  323. setRunFlag(_T("0"));
  324. setRunUploadFlag(_T("0"));
  325. return 0;
  326. }
  327. SMARTEVALUATIONLOGIC_API int StartContiuneScan()
  328. {
  329. g_my_continue_scan = 1;
  330. return 0;
  331. }
  332. SMARTEVALUATIONLOGIC_API void getCurScanExam(std::string exam_code, std::vector<std::vector<coverStu>> &stuInfo)
  333. {
  334. CBatchManager::Get()->GetCurrentBatch()->getCurScanExam(exam_code, stuInfo);
  335. }
  336. SMARTEVALUATIONLOGIC_API void getCoverStuInfoByExamCode(std::string examCode, std::vector<coverStu> &stuInfo)
  337. {
  338. CBatchManager::Get()->GetCurrentBatch()->getCoverStuInfoByExamCode(examCode, stuInfo);
  339. }
  340. #include "excel/ExcelFormat.h"
  341. using namespace ExcelFormat;
  342. SMARTEVALUATIONLOGIC_API void writeToexcel(std::string path, std::vector<std::vector<coverStu>> &stuInfo, std::vector<coverStu> &stuInfo2, bool flag1, bool flag2, bool flag3)
  343. {
  344. BasicExcel xls;
  345. try
  346. {
  347. xls.New(1);
  348. XLSFormatManager fmt_mgr(xls);
  349. //CellFormat fmt(fmt_mgr);
  350. CellFormat format(fmt_mgr);
  351. format.set_format_string(XLS_FORMAT_INTEGER);
  352. if (xls.GetTotalWorkSheets() > 0)
  353. {
  354. int j = 0;
  355. BasicExcelWorksheet* sheet = xls.GetWorksheet(j);
  356. if (sheet)
  357. {
  358. if (flag1)
  359. {
  360. sheet->SetColWidth(2, 5000);
  361. sheet->SetColWidth(3, 5000);
  362. sheet->Rename(_T("未上传学生名单"));
  363. BasicExcelCell* cell = sheet->Cell(0, 0);
  364. cell->Set(_T("序号"));
  365. cell = sheet->Cell(0, 1);
  366. cell->Set(_T("学生姓名"));
  367. cell = sheet->Cell(0, 2);
  368. cell->Set(_T("系统准考证号"));
  369. cell = sheet->Cell(0, 3);
  370. cell->Set(_T("学校准考证号"));
  371. cell = sheet->Cell(0, 4);
  372. cell->Set(_T("班级"));
  373. cell = sheet->Cell(0, 5);
  374. cell->Set(_T("年级"));
  375. cell = sheet->Cell(0, 6);
  376. cell->Set(_T("状态"));
  377. std::vector<coverStu> info;
  378. if (stuInfo.size() > 0)
  379. info = stuInfo[0];
  380. for (int i = 0; i < info.size(); i++)
  381. {
  382. BasicExcelCell* cell = sheet->Cell(i + 1, 0);
  383. CString strNO;
  384. strNO.Format(_T("%d"), i + 1);
  385. cell->Set(strNO);
  386. CString stStuName(info[i].stu_name.data());
  387. cell = sheet->Cell(i + 1, 1);
  388. cell->Set(stStuName);
  389. CString stStuCode1(info[i].stu_code1.data());
  390. cell = sheet->Cell(i + 1, 2);
  391. cell->Set(stStuCode1);
  392. CString stStuCode2(info[i].stu_code2.data());
  393. cell = sheet->Cell(i + 1, 3);
  394. cell->Set(stStuCode2);
  395. CString stStuClass(info[i].stu_class.data());
  396. cell = sheet->Cell(i + 1, 4);
  397. cell->Set(stStuClass);
  398. CString stStuGrade(info[i].stu_grade.data());
  399. cell = sheet->Cell(i + 1, 5);
  400. cell->Set(stStuGrade);
  401. cell = sheet->Cell(i + 1, 6);
  402. cell->Set(_T("未上传"));
  403. // cell->SetFormat(format);
  404. }
  405. //writeTosheetMy(sheet,examID*2,0);
  406. j++;
  407. }
  408. if (flag2)
  409. {
  410. sheet = xls.AddWorksheet(j);
  411. if (sheet)
  412. {
  413. sheet->SetColWidth(2, 5000);
  414. sheet->SetColWidth(3, 5000);
  415. sheet->Rename(_T("标记缺考学生名单"));
  416. BasicExcelCell* cell = sheet->Cell(0, 0);
  417. cell->Set(_T("序号"));
  418. cell = sheet->Cell(0, 1);
  419. cell->Set(_T("学生姓名"));
  420. cell = sheet->Cell(0, 2);
  421. cell->Set(_T("系统准考证号"));
  422. cell = sheet->Cell(0, 3);
  423. cell->Set(_T("学校准考证号"));
  424. cell = sheet->Cell(0, 4);
  425. cell->Set(_T("班级"));
  426. cell = sheet->Cell(0, 5);
  427. cell->Set(_T("年级"));
  428. cell = sheet->Cell(0, 6);
  429. cell->Set(_T("状态"));
  430. std::vector<coverStu> info;
  431. if (stuInfo.size() > 1)
  432. info = stuInfo[1];
  433. for (int i = 0; i < info.size(); i++)
  434. {
  435. BasicExcelCell* cell = sheet->Cell(i + 1, 0);
  436. CString strNO;
  437. strNO.Format(_T("%d"), i + 1);
  438. cell->Set(strNO);
  439. CString stStuName(info[i].stu_name.data());
  440. cell = sheet->Cell(i + 1, 1);
  441. cell->Set(stStuName);
  442. CString stStuCode1(info[i].stu_code1.data());
  443. cell = sheet->Cell(i + 1, 2);
  444. cell->Set(stStuCode1);
  445. CString stStuCode2(info[i].stu_code2.data());
  446. cell = sheet->Cell(i + 1, 3);
  447. cell->Set(stStuCode2);
  448. CString stStuClass(info[i].stu_class.data());
  449. cell = sheet->Cell(i + 1, 4);
  450. cell->Set(stStuClass);
  451. CString stStuGrade(info[i].stu_grade.data());
  452. cell = sheet->Cell(i + 1, 5);
  453. cell->Set(stStuGrade);
  454. cell = sheet->Cell(i + 1, 6);
  455. cell->Set(_T("缺考"));
  456. }
  457. //writeTosheetMy(sheet,examID*2,0);
  458. j++;
  459. }
  460. }
  461. if (flag3)
  462. {
  463. sheet = xls.AddWorksheet(j);
  464. if (sheet)
  465. {
  466. sheet->SetColWidth(2, 5000);
  467. sheet->SetColWidth(3, 5000);
  468. sheet->Rename(_T("覆盖学生名单"));
  469. BasicExcelCell* cell = sheet->Cell(0, 0);
  470. cell->Set(_T("序号"));
  471. cell = sheet->Cell(0, 1);
  472. cell->Set(_T("学生姓名"));
  473. cell = sheet->Cell(0, 2);
  474. cell->Set(_T("系统准考证号"));
  475. cell = sheet->Cell(0, 3);
  476. cell->Set(_T("学校准考证号"));
  477. cell = sheet->Cell(0, 4);
  478. cell->Set(_T("班级"));
  479. cell = sheet->Cell(0, 5);
  480. cell->Set(_T("年级"));
  481. cell = sheet->Cell(0, 6);
  482. cell->Set(_T("状态"));
  483. std::vector<coverStu> info;
  484. info = stuInfo2;
  485. for (int i = 0; i < info.size(); i++)
  486. {
  487. BasicExcelCell* cell = sheet->Cell(i + 1, 0);
  488. CString strNO;
  489. strNO.Format(_T("%d"), i + 1);
  490. cell->Set(strNO);
  491. CString stStuName(info[i].stu_name.data());
  492. cell = sheet->Cell(i + 1, 1);
  493. cell->Set(stStuName);
  494. CString stStuCode1(info[i].stu_code1.data());
  495. cell = sheet->Cell(i + 1, 2);
  496. cell->Set(stStuCode1);
  497. CString stStuCode2(info[i].stu_code2.data());
  498. cell = sheet->Cell(i + 1, 3);
  499. cell->Set(stStuCode2);
  500. CString stStuClass(info[i].stu_class.data());
  501. cell = sheet->Cell(i + 1, 4);
  502. cell->Set(stStuClass);
  503. CString stStuGrade(info[i].stu_grade.data());
  504. cell = sheet->Cell(i + 1, 5);
  505. cell->Set(stStuGrade);
  506. cell = sheet->Cell(i + 1, 6);
  507. cell->Set(_T("覆盖"));
  508. }
  509. //writeTosheetMy(sheet,examID*2,0);
  510. j++;
  511. }
  512. }
  513. wstring result;
  514. int len = MultiByteToWideChar(CP_ACP, 0, path.c_str(), path.size(), NULL, 0);
  515. TCHAR* buffer = new TCHAR[len + 1];
  516. //多字节编码转换成宽字节编码
  517. MultiByteToWideChar(CP_ACP, 0, path.c_str(), path.size(), buffer, len);
  518. buffer[len] = '\0'; //添加字符串结尾
  519. result.append(buffer);
  520. xls.SaveAs(result.c_str());
  521. delete[] buffer;
  522. }
  523. }
  524. }
  525. catch (...)
  526. {
  527. }
  528. }
  529. #include "../lib/ucloud/include/api.h"
  530. #ifdef _DEBUG
  531. #pragma comment(lib,"..\\lib\\ucloud\\debug\\UCloudSDK.lib")
  532. #else
  533. #pragma comment(lib,"..\\lib\\ucloud\\Release\\UCloudSDK.lib")
  534. #endif
  535. std::string UnicodeToAnsi(const CString& str)
  536. {
  537. std::string ret;
  538. int nLen = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, NULL, NULL);
  539. if (nLen == 0){
  540. return ret;
  541. }
  542. char* pResult = new char[nLen];
  543. WideCharToMultiByte(CP_ACP, 0, str, -1, pResult, nLen, NULL, NULL);
  544. ret = pResult;
  545. delete[] pResult;
  546. return ret;
  547. }
  548. CString AnsiToUnicode(const std::string& str)
  549. {
  550. CString strRet;
  551. int nLen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.c_str(), -1, NULL, 0);
  552. if (nLen == 0){
  553. return strRet;
  554. }
  555. wchar_t* pResult = new wchar_t[nLen];
  556. MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.c_str(), -1, pResult, nLen);
  557. strRet = pResult;
  558. delete[]pResult;
  559. return strRet;
  560. }
  561. void RecursiveDirectory(CString cstrDir) // 递归创建目录
  562. {
  563. if (cstrDir.GetLength() <= 3)//是根目录,无需创建目录
  564. {
  565. return;
  566. }
  567. if (cstrDir[cstrDir.GetLength() - 1] == '\\') // 将路径改为目录
  568. {
  569. cstrDir.Delete(cstrDir.GetLength() - 1, 1);
  570. }
  571. // 修改文件属性
  572. WIN32_FIND_DATA wfd;
  573. HANDLE hFind = FindFirstFile(cstrDir, &wfd); // 查找
  574. if (hFind != INVALID_HANDLE_VALUE)
  575. {
  576. FindClose(hFind);
  577. if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
  578. return;
  579. }
  580. // 创建当前目录的地目录失败
  581. if (CreateDirectory(cstrDir, NULL) == false)
  582. {// 退到上一级目录
  583. CString wstrNewDir = cstrDir;
  584. int n = wstrNewDir.ReverseFind('\\');
  585. wstrNewDir = cstrDir.Left(n);
  586. // 递归进入
  587. RecursiveDirectory(wstrNewDir); // 递归本函数,再创建目录
  588. // 递归退出后创建之前失败的目录
  589. CreateDirectory(cstrDir, NULL); // 递归返回,在存在的目录上再建目录
  590. }// 多级目录创建成功
  591. }
  592. bool InitCloud(const char*path)
  593. {
  594. char FilePath[MAX_PATH] = { 0 };
  595. GetModuleFileNameA(NULL, FilePath, MAX_PATH);
  596. strchr(FilePath, '\\')[1] = 0;
  597. strcat(FilePath, "config.ini");
  598. char public_key[128] = { 0 };
  599. GetPrivateProfileStringA("UCLOUD", "public_key", "ucloudyunkaopei@outlook.com13615403931104805307", public_key, sizeof(public_key) / sizeof(char), FilePath);
  600. char private_key[128] = { 0 };
  601. GetPrivateProfileStringA("UCLOUD", "private_key", "bcfd5bb66ca527c9be9fd7f3e784fbfc90c4bba5", private_key, sizeof(private_key) / sizeof(char), FilePath);
  602. char bucket_host[128] = { 0 };
  603. GetPrivateProfileStringA("UCLOUD", "bucket_host", "api.ucloud.cn", bucket_host, sizeof(bucket_host) / sizeof(char), FilePath);
  604. char file_host[128] = { 0 };
  605. GetPrivateProfileStringA("UCLOUD", "file_host", "cn-bj.ufileos.com", file_host, sizeof(file_host) / sizeof(char), FilePath);
  606. ufile_config cfg;
  607. cfg.public_key = public_key;
  608. cfg.private_key = private_key;
  609. cfg.bucket_host = bucket_host;
  610. cfg.file_host = file_host;
  611. ufile_error error;
  612. error = ufile_sdk_initialize(cfg, 0);
  613. if (UFILE_HAS_ERROR(error.code)){
  614. return false;
  615. }
  616. std::string img_path = CServerConfig::app_data_dir_string + "\\exception_tmp\\";
  617. if (_access(img_path.c_str(), 0) == 0){
  618. DeleteDirectory(CServerConfig::app_data_dir + _T("\\exception_tmp"));
  619. }
  620. img_path = CServerConfig::app_data_dir_string + "\\temp_ucloud_path\\";
  621. if (_access(img_path.c_str(), 0) == 0){
  622. DeleteDirectory(CServerConfig::app_data_dir + _T("\\temp_ucloud_path"));
  623. }
  624. CreateDirectory(CServerConfig::app_data_dir + _T("\\temp_ucloud_path\\"), NULL);
  625. CreateDirectory(CServerConfig::app_data_dir + _T("\\exception_tmp\\"), NULL);
  626. RecursiveDirectory(AnsiToUnicode(path));
  627. return true;
  628. }
  629. #include "../ZLibWrapLib/ZLibWrapLib.h"
  630. #include <thread>
  631. #include <mutex>
  632. #include <condition_variable>
  633. #include <atomic>
  634. std::thread thread_get_paper_from_cloud;
  635. std::thread thread_error_handle_restore_site;
  636. std::mutex _mtx_queue;
  637. std::queue<std::tuple<std::string,std::string,std::string> > _work_queue;
  638. std::atomic<bool> _thread_exit;
  639. std::condition_variable _cn_thread;
  640. int g_nTotal = 0;
  641. int g_nCurProcess = 0;
  642. void ReportDowndProcess(int nTotal, int nCurProcess);
  643. static bool readFile(string & file, string & str)
  644. {
  645. ifstream in;
  646. string line;
  647. in.open(file, ifstream::in);
  648. if (!in.is_open())
  649. return false;
  650. while (getline(in, line))
  651. {
  652. str.append(line + "\n");
  653. }
  654. in.close();
  655. return true;
  656. }
  657. ISmartLogicNotify*g_pNotify = NULL;
  658. void error_handle_restore_site()
  659. {
  660. while (!_thread_exit){
  661. std::queue<std::tuple<std::string, std::string, std::string> > _que_w;
  662. {
  663. std::unique_lock<std::mutex> _lock(_mtx_queue);
  664. _cn_thread.wait(_lock, [](){ return !_work_queue.empty(); });
  665. _que_w = _work_queue;
  666. _work_queue = std::queue<std::tuple<std::string, std::string, std::string> >();
  667. }
  668. if (!_que_w.empty() && !_thread_exit){
  669. while (!_que_w.empty()){
  670. auto it = _que_w.front();
  671. _que_w.pop();
  672. std::string id = std::get<0>(it);
  673. std::string type = std::get<1>(it);
  674. std::string path = std::get<2>(it);
  675. if (!path.empty())
  676. CBatchManager::Get()->GetCurrentBatch()->RestoreErrorHandleSite(id,type,path);
  677. g_nCurProcess++;
  678. if (g_nCurProcess >= g_nTotal){
  679. if (g_pNotify){
  680. g_pNotify->OnNotify(LOAD_CLOUD_FILE_END, "云端下载结束");
  681. }
  682. }
  683. else{
  684. if (g_pNotify){
  685. std::string tip_msg = std::string("正在下载: ") + std::to_string(g_nCurProcess) + "/" + std::to_string(g_nTotal);
  686. g_pNotify->OnNotify(LOAD_ERROR_LIST_BEGIN, tip_msg.c_str());
  687. }
  688. }
  689. }
  690. }
  691. }
  692. }
  693. void RestoreErrorHandleSite(const std::string& task_id, const std::string&type, const std::string& strPath)
  694. {
  695. std::lock_guard<std::mutex> _lock(_mtx_queue);
  696. _work_queue.push(std::make_tuple(task_id, type, strPath));
  697. _cn_thread.notify_all();
  698. }
  699. #include "..\EvaluationUtil\HttpClient.h"
  700. struct error_info{
  701. std::string task_id;
  702. std::string task_type;
  703. std::string cloud_key;
  704. };
  705. void get_paper_from_cloud(const std::string&strUrl, const std::string&session,const std::string&exam_id, const std::string&destDir, ISmartLogicNotify*pNotify)
  706. {
  707. RecursiveDirectory(AnsiToUnicode(destDir + "\\Download\\"));
  708. // 获取异常列表
  709. std::vector<error_info> _vctErrorList;
  710. if (pNotify){
  711. g_pNotify = pNotify;
  712. pNotify->OnNotify(LOAD_ERROR_LIST_BEGIN, "开始获取异常列表");
  713. }
  714. std::string response;
  715. CString postData; postData.Format(_T("examGroupId=%s"), AnsiToUnicode(exam_id));
  716. CHttpClient httpClient;
  717. httpClient.SetSendHeader(AnsiToUnicode(session));
  718. httpClient.HttpPost(AnsiToUnicode(strUrl), postData, response);
  719. //printf("get_paper_from_cloud url %s \n", strUrl.c_str());
  720. //printf("get_paper_from_cloud: post_data %s \n",UnicodeToAnsi(postData).c_str());
  721. //printf("get_paper_from_cloud rst= %s \n", response.c_str());
  722. if (!response.empty()){
  723. Json::Features features;
  724. Json::Reader re(features);
  725. Json::Value root;
  726. re.parse(response, root);
  727. if (root["success"].asInt() == 1){
  728. Json::Value data = root["data"];
  729. Json::Value name = data["examName"];
  730. if (pNotify){
  731. pNotify->OnNotify(LOAD_ERROR_EXAM_NAME, name.asString().c_str());
  732. }
  733. if (data.isObject()){
  734. Json::Value list = data["list"];
  735. g_nTotal = list.size();
  736. for (int i = 0; i < g_nTotal; i++)
  737. {
  738. Json::Value row = list[i];
  739. error_info info;
  740. std::string task_id = row["task_id"].asString();
  741. std::string cloud_key = row["data"].asString();
  742. std::string task_type = row["task_type"].asString();
  743. info.task_id = task_id;
  744. info.cloud_key = cloud_key;
  745. info.task_type = task_type;
  746. _vctErrorList.push_back(info);
  747. if (i == 0){
  748. if (pNotify){
  749. pNotify->OnNotify(LOAD_PAPER_TYPE, info.task_type.c_str());
  750. }
  751. }
  752. }
  753. }
  754. }
  755. else{
  756. if (pNotify){
  757. pNotify->OnNotify(LOAD_ERROR_FAILED, root["message"].asString().c_str());
  758. }
  759. }
  760. }
  761. if (pNotify){
  762. pNotify->OnNotify(LOAD_ERROR_LIST_END, "获取异常列表结束");
  763. }
  764. // 从云端下载文件
  765. if (pNotify){
  766. std::string tip_msg = std::string("正在下载: ") + std::to_string(g_nCurProcess) + "/" + std::to_string(g_nTotal);
  767. pNotify->OnNotify(LOAD_CLOUD_FILE_BEGIN, tip_msg.c_str());
  768. }
  769. int i = 0;
  770. if (_vctErrorList.empty()){
  771. if (pNotify){
  772. pNotify->OnNotify(LOAD_CLOUD_FILE_END, "云端异常没有异常");
  773. }
  774. }
  775. else{
  776. TCHAR exeFullPath[MAX_PATH];
  777. CString strPath;
  778. int nSubjectId;
  779. GetModuleFileName(NULL, exeFullPath, MAX_PATH);
  780. strPath = (CString)exeFullPath;
  781. int position = strPath.ReverseFind('\\');
  782. strPath = strPath.Left(position + 1);
  783. TCHAR FilePath[MAX_PATH];
  784. GetModuleFileName(NULL, FilePath, MAX_PATH);
  785. (_tcsrchr(FilePath, '\\'))[1] = 0;
  786. lstrcat(FilePath, _T("config.ini"));
  787. WCHAR szbucket_name[512];
  788. GetPrivateProfileString(_T("GLOBAL"), _T("bucket_name"), _T("zxhx-test"), szbucket_name, 512, FilePath);
  789. std::string bucket_name = UnicodeToAnsi(szbucket_name);
  790. for (auto it : _vctErrorList){
  791. std::string cloud_key = it.cloud_key;
  792. cloud_key = cloud_key.substr(1, cloud_key.size() - 2);
  793. ++i;
  794. std::string dst_path = destDir + std::to_string(i) + ".zip";
  795. // 下载文件。
  796. FILE *fpDown = fopen(dst_path.c_str(), "wb");
  797. if (fpDown){
  798. auto error = ufile_download(bucket_name.c_str(), cloud_key.c_str(), fpDown, NULL);
  799. if UFILE_HAS_ERROR(error.code){
  800. }
  801. else{
  802. fclose(fpDown);
  803. std::string ex_path = destDir + "Download\\" + std::to_string(i) + "\\";
  804. ZipExtract(AnsiToUnicode(dst_path), AnsiToUnicode(ex_path));
  805. if (pNotify){
  806. //
  807. pNotify->OnNotify(LOAD_CLOUD_FILE, ex_path.c_str());
  808. }
  809. RestoreErrorHandleSite(it.task_id, it.task_type, ex_path);
  810. }
  811. }
  812. }
  813. }
  814. }
  815. bool ExitCloud()
  816. {
  817. ufile_sdk_cleanup();
  818. return true;
  819. }
  820. class ThreadGuard{
  821. public:
  822. void set(std::thread &t){ _t = std::move(t); }
  823. ~ThreadGuard(){ if (_t.joinable()) _t.join(); }
  824. private:
  825. std::thread _t;
  826. };
  827. ThreadGuard _t_guard;
  828. void exit_thread_error_handle_restore_site()
  829. {
  830. if (thread_error_handle_restore_site.joinable()){
  831. {
  832. _thread_exit = true;
  833. std::lock_guard<std::mutex> _lock(_mtx_queue);
  834. _work_queue.push(std::tuple<std::string, std::string, std::string>());
  835. _cn_thread.notify_all();
  836. }
  837. thread_error_handle_restore_site.join();
  838. }
  839. }
  840. void ReportDowndProcess(int nTotal, int nCurProcess)
  841. {
  842. CWnd *pWnd = CWnd::FindWindow(NULL, _T("知心慧学学管系统"));
  843. if (pWnd == NULL){
  844. return;
  845. }
  846. //发送消息
  847. MY_DB_INFO fff;
  848. fff.nmode = 2;
  849. fff.total_error = nTotal;
  850. fff.cur_process_error = nCurProcess;
  851. COPYDATASTRUCT cpd; // 给COPYDATASTRUCT结构赋值
  852. cpd.dwData = 0;
  853. cpd.cbData = sizeof(MY_DB_INFO);
  854. cpd.lpData = (&fff);
  855. int ret = pWnd->SendMessage(WM_COPYDATA, NULL, (LPARAM)&cpd); // 发送
  856. }
  857. int PreErrorHandleRestoreSite(bool bcontinue, int scan_type, const ScanParam&scanparam)
  858. {
  859. CBatchManager::Get()->GetCurrentBatch()->PreErrorHandleRestoreSite(bcontinue,scan_type, FEEDER_TYPE::Folder, scanparam);
  860. return 0;
  861. }
  862. void SetErrorHandle(bool bErrorHandle)
  863. {
  864. CBatchManager::Get()->GetCurrentBatch()->SetErrorHandle(bErrorHandle);
  865. }
  866. int ParseErrorPaperFromCloud(const std::string&strUrl, const std::string&session, const std::string&exam_id, const std::string&destDir, ISmartLogicNotify*pNotify /*= NULL*/)
  867. {
  868. g_nTotal = 0;
  869. g_nCurProcess = 0;
  870. exit_thread_error_handle_restore_site();
  871. thread_error_handle_restore_site = std::thread(error_handle_restore_site);
  872. if (thread_get_paper_from_cloud.joinable())
  873. {
  874. thread_get_paper_from_cloud.join();
  875. }
  876. thread_get_paper_from_cloud = std::thread(get_paper_from_cloud, strUrl, session, exam_id,destDir, pNotify);
  877. _t_guard.set(thread_get_paper_from_cloud);
  878. return 0;
  879. }
  880. #if _DEBUG
  881. #pragma comment(lib,"../Win32/Debug/client_interactive_api_d.lib")
  882. #else
  883. #pragma comment(lib,"../Win32/Release/client_interactive_api.lib")
  884. #endif
  885. __declspec(dllimport) int api_init();
  886. __declspec(dllimport) void api_free();
  887. SMARTEVALUATIONLOGIC_API int InitIdentiferDllAlgorithm()
  888. {
  889. int ret = api_init();
  890. LOGFMTI("api_init ret = %d", ret);
  891. return ret;
  892. }
  893. SMARTEVALUATIONLOGIC_API void FreeIdentiferDllAlgorithm()
  894. {
  895. api_free();
  896. }
  897. void InitUploadManager(bool bEanble, bool bCountiue, bool bErrorHanle, bool bOnlineCard, IUploudNotify*pNotify)
  898. {
  899. CBatchManager::Get()->GetCurrentBatch()->InitUploadManager(bEanble, bCountiue,bErrorHanle, bOnlineCard,pNotify);
  900. }
  901. void OnScanListFilter(bool bsuccess, int nUploadState)
  902. {
  903. CBatchManager::Get()->GetCurrentBatch()->OnScanListFilter(bsuccess, nUploadState);
  904. }
  905. int UploadOnScanCmd(int nCmd, const char*param, void*ret /*= nullptr*/)
  906. {
  907. if (CBatchManager::Get() && CBatchManager::Get()->GetCurrentBatch()){
  908. return CBatchManager::Get()->GetCurrentBatch()->UploadOnScanCmd(nCmd, param, ret);
  909. }
  910. return -1;
  911. }
  912. void QuickHandle(bool bGetPath, char*path_nor, int nor_len, char*path_exc, int exc_len)
  913. {
  914. CBatchManager::Get()->GetCurrentBatch()->QuickHandle(bGetPath, path_nor, nor_len, path_exc, exc_len);
  915. }
  916. int BatchServiceCmd(int cmd, void*param, void*ret)
  917. {
  918. if (cmd == BS_CMD_DEL_REDIFY_TMP_IMG)
  919. {
  920. std::string img_path = CServerConfig::app_data_dir_string + "\\ErrorHandleImgTmp\\";
  921. if (_access(img_path.c_str(), 0) == 0){
  922. DeleteDirectory(CServerConfig::app_data_dir + _T("\\ErrorHandleImgTmp"));
  923. }
  924. return 0;
  925. }
  926. int nRet = -1;
  927. if (CBatchManager::Get() && CBatchManager::Get()->GetCurrentBatch()){
  928. nRet = CBatchManager::Get()->GetCurrentBatch()->BatchServiceCmd(cmd, param, ret);
  929. }
  930. return nRet;
  931. }
  932. void SetExamName(const wchar_t * name)
  933. {
  934. TCHAR pathFile[MAX_PATH];
  935. GetModuleFileName(NULL, pathFile, MAX_PATH);
  936. (_tcsrchr(pathFile, '\\'))[1] = 0;
  937. _tcscat(pathFile, L"config.ini");
  938. WritePrivateProfileString(L"THIRD", L"exam_name", name, pathFile);
  939. }
  940. SMARTEVALUATIONLOGIC_API vector<int> GetAllConfictPaper(int student_paper_id, string student_id)
  941. {
  942. return CBatchManager::Get()->GetCurrentBatch()->GetAllConfictPaper(student_paper_id, student_id);
  943. }
  944. SMARTEVALUATIONLOGIC_API int ExamineThisScan(PAPER_DETAIL& paper_detail)
  945. {
  946. return CBatchManager::Get()->GetCurrentBatch()->ExamineThisScan(paper_detail);
  947. }
  948. SMARTEVALUATIONLOGIC_API int SetAbsentExam(PAPER_DETAIL& paper_detail, int absent)
  949. {
  950. return CBatchManager::Get()->GetCurrentBatch()->SetAbsentExam(paper_detail, absent);
  951. }
  952. SMARTEVALUATIONLOGIC_API int QueryKeGuanTiYiChang(const int paper_id, std::vector<KEGUANTI_DETAIL>& keguantiList)
  953. {
  954. return CBatchManager::Get()->GetCurrentBatch()->QueryKeGuanTiYiChang(paper_id, keguantiList);
  955. }
  956. SMARTEVALUATIONLOGIC_API int UpdateKeGuanTiYiChang(const int paper_id, std::vector<KEGUANTI_DETAIL>& keguantiList)
  957. {
  958. return CBatchManager::Get()->GetCurrentBatch()->UpdateKeGuanTiYiChang(paper_id, keguantiList);
  959. }
  960. SMARTEVALUATIONLOGIC_API void SetAllSubject(bool all )
  961. {
  962. g_isAllSubject = all;
  963. }