BatchService.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #pragma once
  2. #include "scan_common.h"
  3. #include "basic_struct.h"
  4. #include "basic_struct_result.h"
  5. #include "..\Schema\schema_struct.h"
  6. #include "DataBaseManagerHolder.h"
  7. #include <vector>
  8. #include <boost/smart_ptr.hpp>
  9. #include "../Identifier/schema_struct_auto.h"
  10. #include "../Identifier/schema_struct.h"
  11. #include "../Identifier/OnLineCardSchemaStruct.h"
  12. #include "rapidjson/document.h"
  13. #include <thread>
  14. #include <atomic>
  15. #include <queue>
  16. #include <mutex>
  17. #include <condition_variable>
  18. #include <future>
  19. #include "ScoreCounter.h"
  20. using namespace std;
  21. class CImgUploader;
  22. class CResultUploader;
  23. class CIdentifyService;
  24. #include "UploadManager.h"
  25. #include "NetOperator.h"
  26. #ifdef _DEBUG
  27. #pragma comment(lib,"LibHJIPC_d.lib")
  28. #else
  29. #pragma comment(lib,"LibHJIPC.lib")
  30. #endif // DEBUG
  31. class CBatchService :public IService, public CDataBaseManagerHolder, public INetNotify
  32. {
  33. public:
  34. CBatchService(bool bOnlineCard, int nSubjectID, int nOnlineScanType);
  35. ~CBatchService(void);
  36. public:
  37. /************************************************************************/
  38. /* 注册窗口,识别模块遇到问题将向该窗口发送消息 */
  39. /************************************************************************/
  40. int SetHandlerWnd(HWND hwnd);
  41. /************************************************************************/
  42. /* 准备扫描 */
  43. /************************************************************************/
  44. int ReadyScan(FEEDER_TYPE feederType, const ScanParam & param);
  45. int PreErrorHandleRestoreSite(bool bcontinue, int scan_type, FEEDER_TYPE feederType, const ScanParam & param);
  46. int QueryExceptionPaper(const long exception_type, vector<STUDENT_INFO>& studentList);
  47. int QueryPaperDetail(const int paper_id, PAPER_DETAIL &paper_detail, vector<PAGE_DETAIL> &pageList, vector<GROUP_QUESTION> &questionList);
  48. 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);
  49. int ReIdentify(const int paper_id, const std::string& stu_code, const std::vector<img_param>& params);
  50. int loadDuXueFirstMode();
  51. string GetBatchCode();
  52. //清除数据
  53. int ClearDbTemp();
  54. //忽略试卷
  55. int IgnorePaper(const int paper_id);
  56. //忽略异常
  57. int IgnoreException(const long exceptions);
  58. // 覆盖试卷
  59. int ReplacePaper(const int paper_id, int &paper_id_ret);
  60. void CoverdAllKaohaochongtu();
  61. // 全部覆盖试卷
  62. int ReplaceAllKaoHaoChongTu(vector<int> &paper_id_List);
  63. //开始上传
  64. int StartUploadPaper(HWND hWnd, int student_paper_id = -1,bool bErrorPaper=false);
  65. //放弃本次扫描结果
  66. int GiveUpCurrentBatch();
  67. virtual BOOL SupportPause(void);
  68. /*从文件夹扫描继续扫描时设置扫描路径*/
  69. int SetFolderScanDir(const std::string& img_dir);
  70. virtual BOOL Stop(void);
  71. //查询异常卷总数
  72. int QueryExptionPaperCount(int & exc_count, int & total_count);
  73. //查询异常类型信息
  74. int QueryExptionTypeInfo(vector<EXCEPTION_TYPE_INFO> & infos);
  75. int LoadSchema(long long examId, std::string examName, long examCourseId, std::string courseName, std::string schemaPath, std::string rule = "");
  76. vector<int> GetAllConfictPaper(int student_paper_id, string student_id);//获取冲突试卷
  77. const boost::shared_ptr<const identify::schema::ISCH_Schema>& GeSchema(){ return m_schema; }
  78. int SetCookie(CString path, CString name, CString value);
  79. void saveQuestionStd(long long examId, std::string examName, long examCourseId, std::string courseName, std::vector<schema::SCHEMA_QUESTION> &questions,std::string rule = "");
  80. void Online_saveQuestionStd(long long examId, std::string examName, long examCourseId, std::string courseName, std::string rule = "");
  81. int QueryNormalPaper(vector<STUDENT_INFO> & studentList);
  82. int QueryMubanImgPath(int page_index, std::string& imgPath);
  83. int QueryMubanImgCount(int& page_count);
  84. int SetLocalServerCookie(CString name, CString value);
  85. const boost::shared_ptr<const HANDLE_INFO>& GetHandleInfo();
  86. void getCurScanExam(std::string exam_code, std::vector<std::vector<coverStu>> &stuInfo);
  87. void getCoverStuInfoByExamCode(std::string examCode, std::vector<coverStu> &stuInfo);
  88. void RestoreErrorHandleSite(const std::string& task_id, const std::string&type, const std::string& strPath);
  89. int UpateErrorStudentData(const std::string&task_id);
  90. void SetErrorHandle(bool bErrorHandle);
  91. void InitUploadManager(bool bEanble, bool bCountiue, bool bErrorHanle, bool bOnlineCard, IUploudNotify*pNotify);
  92. void OnScanListFilter(bool bsuccess, int nUploadState);
  93. int UploadOnScanCmd(int nCmd, const char*param, void*ret);
  94. void QuickHandle(bool bGetPath, char*path_nor, int nor_len, char*path_exc, int exc_len);
  95. int BatchServiceCmd(int cmd, void*param, void*ret);
  96. boost::shared_ptr<CResultUploader> GetRstUploaderPtr(){ return m_result_uploader; }
  97. HANDLE GetEventZXHXCreateDB(){ return m_eventZXHXCreateDB; }
  98. void leaveCurrentBatch();
  99. int ExamineThisScan(PAPER_DETAIL &paper_detail);
  100. int SetAbsentExam(PAPER_DETAIL &paper_detail, int absent);
  101. int QueryKeGuanTiYiChang(const int paper_id, std::vector<KEGUANTI_DETAIL>& keguantiList);
  102. int UpdateKeGuanTiYiChang(const int paper_id, std::vector<KEGUANTI_DETAIL>& keguantiList);
  103. private:
  104. // 返回 paper_id
  105. int RestoreStudentPaper(const std::string task_id,const std::string&task_type, rapidjson::Value&doc);
  106. void RestoreFile(int paper_id, const std::string&path,const std::string&path_ori);
  107. std::map<int,int> RestorePages(int paper_id,const std::string&path, rapidjson::Value&value);
  108. void RestoreResult(int paper_id, rapidjson::Value&value, const std::map<int, int>&mapPageID);
  109. void RestoreException(int paper_id, rapidjson::Value&value, const std::map<int, int>&mapPageID);
  110. void RestoreStudent(rapidjson::Value&value);
  111. protected:
  112. virtual ServiceState OnStarting( void );
  113. virtual ServiceState OnRunning( void );
  114. virtual ServiceState OnStoping(void);
  115. virtual ServiceState OnPausing(void);
  116. virtual ServiceState OnResuming(void);
  117. private:
  118. HANDLE m_eventZXHXCreateDB;
  119. boost::shared_ptr<CResultUploader> m_result_uploader;//成绩上传服务
  120. FEEDER_TYPE m_feeder_type;//当前图像送入器类型
  121. RTL_CRITICAL_SECTION bantch_db_lock;
  122. CppSQLite3DB bantch_db;
  123. HWND m_hwnd;
  124. //批次号
  125. CString m_bantch_code;
  126. //当前批次的数据库的ID
  127. int m_database_id;
  128. CString m_bantch_dir;
  129. //本次扫描原始图像存放目录
  130. CString m_norimg_dir;
  131. CString m_excimg_dir;
  132. CString m_img_clips_dir;
  133. CString m_img_alynasis_dir;
  134. CString m_img_alynasis_result_dir;
  135. CString m_img_down_load_dir;
  136. std::string m_muban_img_dir;
  137. bool m_bErrorHandle;
  138. //标记是否非正常关闭
  139. BOOL m_abnormal_stop;
  140. CString m_paper_code;
  141. boost::shared_ptr<const identify::schema::ISCH_Schema> m_schema;
  142. boost::shared_ptr<const HANDLE_INFO> m_handleInfo;
  143. //主任务
  144. boost::shared_ptr<CIdentifyService> mainService;
  145. vector<boost::shared_ptr<CIdentifyService>> subService;
  146. schema::SCHEMA m_schema0;
  147. OnLineCard::PaperTemplate* m_onlineCardTemplate;
  148. bool ParseTemplateFromJson(const std::string&fileName);
  149. bool ParseTemplateFromJsonAll(const std::string&fileName);//全学科在线答题卡
  150. long m_examCourseId;
  151. long long m_examId;
  152. std::string m_examName;
  153. std::string m_courseName;
  154. int m_bantch_state;
  155. char m_db_file_name[520];
  156. bool m_bOnlineCard;
  157. int m_nSubjectID;
  158. int m_nOnlineScanType;
  159. UploadManager m_upload_manager;
  160. std::future<int> m_coverd_all_kaohaochongtu;
  161. CScoreCounterEx m_scoreCounter;
  162. std::map<std::string, std::string> m_mapKeguantiNickName; // 客观题题号重模板中获取
  163. public:
  164. void getStdAnswerAndScore();
  165. CString MarkHttpHeaderData();
  166. bool readPaperId(CString& strPaperId);
  167. void logForDbg(string strLog);
  168. void recordBarcodeFlag(int nFlag);
  169. virtual void OnNetNotify(const char*data) override;
  170. };