OnlineCardStudentMatcher.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  1. #include "stdafx.h"
  2. #include "OnlineCardStudentMatcher.h"
  3. #include "basic_struct.h"
  4. #include "ServerConfig.h"
  5. #include "rapidjson/document.h"
  6. #include "../EvaluationUtil/HttpClient.h"
  7. #include "UploadManager.h"
  8. int g_flagid; //判断是否使用id(0:不使用id,1:使用id)
  9. int g_schoolCardStatus; //
  10. extern UploadManager* g_upload_manager;
  11. std::string ascii2utf8(const string & ascii);
  12. std::string utf82ascii(const string & utf8);
  13. COnlineCardStudentMatcher::COnlineCardStudentMatcher()
  14. {
  15. url_strcode.Format(_T("%s/coachio/iointerface_v2/getPaperStudentInfo"), CServerConfig::server_url);
  16. }
  17. COnlineCardStudentMatcher::~COnlineCardStudentMatcher()
  18. {
  19. }
  20. ServiceState COnlineCardStudentMatcher::OnStarting(void)
  21. {
  22. return __super::OnStarting();
  23. }
  24. void COnlineCardStudentMatcher::updatefile(CppSQLite3DB* bantch_db, long student_paper_id, const std::string & norimg_dir, const std::string & excimg_dir){
  25. char sql5[512];
  26. sprintf_s(sql5, "select * from student_paper sp where sp.student_paper_id =%d", student_paper_id);
  27. CppSQLite3Query query_s = bantch_db->execQuery(sql5);
  28. if (!query_s.eof()){
  29. long paper_state = query_s.getInt64Field("paper_state");
  30. const char * student_code = query_s.getStringField("student_code");
  31. sprintf_s(sql5, "select * from page p where p.student_paper_id =%d", student_paper_id);
  32. CppSQLite3Query query_p = bantch_db->execQuery(sql5);
  33. CppSQLite3Statement stmt = bantch_db->compileStatement("update page set img_path =:img_path where page_id =:page_id");
  34. while (!query_p.eof()){
  35. std::string img_path = query_p.getStringField("img_path");
  36. int page_id = query_p.getIntField("page_id");
  37. int phy_number = atoi(query_p.getStringField("phy_number"));
  38. int page_index = query_p.getIntField("page_index");
  39. int index_dirspeator = img_path.find_last_of('\\');
  40. int index_dot = img_path.find_last_of('.');
  41. std::string dir = img_path.substr(0, index_dirspeator);
  42. std::string filename = img_path.substr(index_dirspeator, img_path.length() - index_dirspeator);
  43. std::string extname = index_dot > index_dirspeator ? img_path.substr(index_dot, img_path.length() - index_dot) : ".jpg";
  44. std::string dir_new = (paper_state&(MEX_YICHANG)) ? excimg_dir : norimg_dir;
  45. char filename_new[512];
  46. if (paper_state&(MEX_YICHANG)){
  47. sprintf_s(filename_new, "%06d%s", phy_number, extname.c_str());
  48. }
  49. else{
  50. sprintf_s(filename_new, "%s_%01d_%06d%s", student_code, page_index, phy_number, extname.c_str());
  51. }
  52. std::string img_path_new = dir_new + "\\" + filename_new;
  53. if (dir != dir_new){
  54. CopyFile(CString(img_path.c_str()), CString(img_path_new.c_str()),FALSE);
  55. stmt.bind(":img_path", img_path_new.c_str());
  56. stmt.bind(":page_id", page_id);
  57. stmt.execDML();
  58. }
  59. else if (filename != filename_new){
  60. rename(img_path.c_str(), img_path_new.c_str());
  61. stmt.bind(":img_path", img_path_new.c_str());
  62. stmt.bind(":page_id", page_id);
  63. stmt.execDML();
  64. }
  65. query_p.nextRow();
  66. }
  67. }
  68. }
  69. ServiceState COnlineCardStudentMatcher::OnRunning(void)
  70. {
  71. ServiceState nextState = IService::OnRunning();
  72. if (nextState == pausing) return nextState;
  73. char sql5[512];
  74. sprintf_s(sql5, "SELECT sp.student_paper_id, sp.student_id, sp.student_code, sp.paper_code FROM student_paper sp WHERE (sp.paper_state & %d) = %d", EX_KAOHAODAIPIPEI, EX_KAOHAODAIPIPEI);
  75. CppSQLite3Query query = bantch_db->execQuery(sql5);
  76. if (!query.eof()){
  77. if (g_flagid != 0)
  78. {
  79. // 使用id流程
  80. std::string response;
  81. CString postData;
  82. std::string strStuCode = query.getStringField("student_code");
  83. CString strPaperId; readPaperId(strPaperId);
  84. int studentCount = 0;
  85. std::map<std::string, vector<int>> code_id_map;
  86. Json::Value json;
  87. Json::Value json_array(Json::arrayValue);
  88. while (!query.eof()){
  89. Json::Value item;
  90. auto student_id = query.getStringField("student_id");
  91. auto student_paper_id = query.getIntField("student_paper_id");
  92. code_id_map[student_id].push_back(student_paper_id);
  93. //code_id_map["26541648372577028"].push_back(student_paper_id);
  94. item["studentCode"] = student_id;
  95. //item["studentCode"] = "26541648372577028";
  96. item["paperCode"] = query.getStringField("paper_code");
  97. //item["paperCode"] = "704606657776021504";
  98. json_array.append(item);
  99. query.nextRow();
  100. studentCount++;
  101. }
  102. postData = _T("json_str=");
  103. json["studentandpaper"] = json_array;
  104. if (m_nOnlineScanType == 0)
  105. {
  106. json["is_magic_word_card"] = 1;
  107. }
  108. Json::FastWriter writer;
  109. std::string json_str = writer.write(json);
  110. postData += CString(json_str.c_str());
  111. CHttpClient httpClient;
  112. httpClient.SetSendHeader(MarkHttpHeaderData());
  113. httpClient.HttpPost(url_strcode, postData, response);
  114. rapidjson::Document root;
  115. root.Parse(response.c_str());
  116. EnterCriticalSection(db_lock);
  117. bantch_db->execDML("begin transaction");
  118. if (root.IsObject() && root.HasMember("success") &&
  119. root["success"].IsInt() && root["success"].GetInt()){
  120. rapidjson::Value& rows = root["object"];
  121. std::map<std::string, rapidjson::Value> code_obj_map;
  122. if (rows.IsArray()){
  123. for (int i = 0; i < rows.Size(); i++)
  124. {
  125. if (rows[i].HasMember("studentCode") &&
  126. rows[i]["studentCode"].IsString())
  127. code_obj_map[utf82ascii(rows[i]["studentCode"].GetString())] = rows[i];
  128. }
  129. }
  130. std::map<string, vector<int>>::iterator it;
  131. char * sql = "INSERT INTO student ( student_id, student_code, class_name, school_id, grade_name, student_name, class_id, score_total ,studentCard,schoolStudentCard ) SELECT t.student_id, t.student_code, t.class_name, t.school_id, t.grade_name, t.student_name, t.class_id, t.score_total,t.studentCard ,t.schoolStudentCard FROM ( SELECT :student_id student_id, :student_code student_code, :class_name class_name, :school_id school_id, :grade_name grade_name, :student_name student_name, :class_id class_id, :score_total score_total, :studentCard studentCard , :schoolStudentCard schoolStudentCard ) t LEFT JOIN student s ON s.student_id = t.student_id WHERE s.student_id IS NULL";
  132. CppSQLite3Statement statement = bantch_db->compileStatement(sql);
  133. for (it = code_id_map.begin(); it != code_id_map.end(); ++it)
  134. {
  135. std::map<std::string, rapidjson::Value>::iterator it2 = code_obj_map.find(it->first);
  136. bool bUpload = true;
  137. for (int m = 0; m<it->second.size(); m++)
  138. {
  139. if (it2 == code_obj_map.end()){
  140. // 考号不存在
  141. sprintf_s(sql5, "update student_paper set paper_state =paper_state -%d +%d where student_paper_id =%d", EX_KAOHAODAIPIPEI, EX_KAOHAOBUCUNZAI, it->second[m]);
  142. bantch_db->execDML(sql5);
  143. bUpload = false;
  144. }
  145. else{
  146. //检查是否有考号冲突的试卷
  147. sprintf_s(sql5, "select sp.student_paper_id,sp.paper_state,sp.student_id from student_paper sp where sp.student_id = '%s' and sp.student_paper_id!=%d and (sp.paper_state & %d) != %d ",
  148. utf82ascii(it2->second["studentCode"].GetString()).c_str(), it->second[m], EX_KAOHAODAIPIPEI, EX_KAOHAODAIPIPEI);
  149. CppSQLite3Query q2 = bantch_db->execQuery(sql5);
  150. vector<int> all_conflict_ids;
  151. vector<int> conflict_ids;
  152. while (!q2.eof()){
  153. long paper_state_t = q2.getInt64Field("paper_state");
  154. all_conflict_ids.push_back(q2.getIntField("student_paper_id"));
  155. if (!(paper_state_t&EX_KAOHAOCHONGTU))
  156. conflict_ids.push_back(q2.getIntField("student_paper_id"));
  157. q2.nextRow();
  158. }
  159. bUpload = all_conflict_ids.empty();
  160. if (!all_conflict_ids.empty()){
  161. CppSQLite3Statement stmt3 = bantch_db->compileStatement("insert into exception (exception_type ,exception_name,page_id,student_paper_id) values(:exception_type ,:exception_name,:page_id,:student_paper_id)");
  162. for (int m = 0; m < conflict_ids.size(); m++){//将与之冲突的试卷标记为考号冲突
  163. sprintf_s(sql5, "update student_paper set paper_state =paper_state|%d ,Is_Covered=0 where student_paper_id=%d", EX_KAOHAOCHONGTU, conflict_ids[m]);
  164. bantch_db->execDML(sql5);
  165. stmt3.bind(":student_paper_id", conflict_ids[m]);
  166. stmt3.bind(":exception_type", SHIFT_KAOHAOCHONGTU);
  167. stmt3.bind(":exception_name", "考号冲突");
  168. stmt3.execDML();
  169. CppSQLite3Statement stmt4 = bantch_db->compileStatement("insert INTO message (student_paper_id , message_type) VALUES (:student_paper_id,:message_type)");
  170. stmt4.bind(":student_paper_id", conflict_ids[m]);
  171. stmt4.bind(":message_type", WM_IDENTIFOR_PAPER_STATE_CHAGED);
  172. stmt4.execDML();
  173. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)conflict_ids[m]);
  174. if (g_upload_manager&&g_upload_manager->IsEanble()){
  175. g_upload_manager->UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_DEL_UPLOAD_REPORT, std::to_string(conflict_ids[m]).c_str());
  176. }
  177. }
  178. stmt3.bind(":student_paper_id", it->second[m]);
  179. stmt3.bind(":exception_type", SHIFT_KAOHAOCHONGTU);
  180. stmt3.bind(":exception_name", "考号冲突");
  181. stmt3.execDML();
  182. }
  183. sprintf_s(sql5, "update student_paper set paper_state =paper_state -%d+%d,student_id ='%s',student_code ='%s' ,Is_Covered=0 where student_paper_id =%d",
  184. EX_KAOHAODAIPIPEI,
  185. all_conflict_ids.empty() ? 0 : EX_KAOHAOCHONGTU,
  186. utf82ascii(it2->second["studentCode"].GetString()).c_str(),
  187. utf82ascii(it2->second["studentCard"].GetString()).c_str(),
  188. it->second[m]);
  189. bantch_db->execDML(sql5);
  190. statement.bind(":student_id", it2->second["studentCode"].GetString());
  191. statement.bind(":student_code", it2->second["studentCard"].GetString());
  192. auto name = it2->second["studentName"].GetString();
  193. statement.bind(":class_name", it2->second["className"].GetString());
  194. statement.bind(":grade_name", it2->second["gradeName"].GetString());
  195. statement.bind(":student_name", it2->second["studentName"].GetString());
  196. statement.bind(":class_id", it2->second["clazzId"].GetString());
  197. statement.bind(":score_total", 0);
  198. statement.bind(":school_id", 1);
  199. statement.bind(":studentCard", strStuCode.c_str());
  200. statement.bind(":schoolStudentCard", it2->second["schoolStudentCard"].GetString());
  201. statement.execDML();
  202. }
  203. //updatefile(bantch_db, it->second[m], m_norimg_dir, m_excimg_dir);
  204. CppSQLite3Statement stmt4 = bantch_db->compileStatement("insert INTO message (student_paper_id , message_type) VALUES (:student_paper_id,:message_type)");
  205. stmt4.bind(":student_paper_id", it->second[m]);
  206. stmt4.bind(":message_type", WM_IDENTIFOR_PAPER_STATE_CHAGED);
  207. stmt4.execDML();
  208. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)it->second[m]);
  209. if (g_upload_manager&&bUpload){
  210. std::string paper_state_qry_sql = "select paper_state from student_paper where student_paper_id=";
  211. paper_state_qry_sql += std::to_string(it->second[m]);
  212. auto paper_state_qry = bantch_db->execQuery(paper_state_qry_sql.c_str());
  213. if (!paper_state_qry.eof() &&
  214. paper_state_qry.getIntField("paper_state") == 0 && !m_bUseQr){
  215. g_upload_manager->UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_UPLOAD_SUCCESSSJUAN, std::to_string(it->second[m]).c_str());
  216. }
  217. }
  218. LOGFMTI("WM_IDENTIFOR_PAPER_STATE_CHAGED match paper_id :%d\n", it->second[m]);
  219. }
  220. }
  221. }
  222. else{
  223. // 考号不存在
  224. for (auto it = code_id_map.begin(); it != code_id_map.end(); ++it){
  225. for (std::size_t m = 0; m<it->second.size(); m++){
  226. sprintf_s(sql5, "update student_paper set paper_state =paper_state -%d +%d where student_paper_id =%d", EX_KAOHAODAIPIPEI, EX_KAOHAOBUCUNZAI, it->second[m]);
  227. bantch_db->execDML(sql5);
  228. CppSQLite3Statement stmt4 = bantch_db->compileStatement("insert INTO message (student_paper_id , message_type) VALUES (:student_paper_id,:message_type)");
  229. stmt4.bind(":student_paper_id", it->second[m]);
  230. stmt4.bind(":message_type", WM_IDENTIFOR_PAPER_STATE_CHAGED);
  231. stmt4.execDML();
  232. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)it->second[m]);
  233. }
  234. }
  235. }
  236. bantch_db->execDML("commit transaction");
  237. LeaveCriticalSection(db_lock);
  238. }
  239. else
  240. {
  241. // 使用考号流程(学校准考证号、系统准考证号)
  242. string response;
  243. CString postData;
  244. string strStuCode;
  245. m_examId = 16;
  246. CString strPaperId;
  247. readPaperId(strPaperId);
  248. postData.Format(_T("exam_group_id="));
  249. postData += strPaperId;
  250. postData += "&studentCard=";
  251. int studentCount = 0;
  252. std::map<std::string, vector<int>> code_id_map;
  253. while (!query.eof()){
  254. code_id_map[query.getStringField("student_code")].push_back(query.getIntField("student_paper_id"));
  255. if (studentCount>0){ postData.Append(_T(",")); }
  256. postData.Append(CString(query.getStringField("student_code")));
  257. strStuCode = query.getStringField("student_code");
  258. query.nextRow();
  259. studentCount++;
  260. }
  261. postData.Append(CString("&cardStatus=0"));
  262. CString strBarcodeFlag, strBar;
  263. strBarcodeFlag.Format(_T("%d"), g_schoolCardStatus);
  264. strBar = "&barcodeFlag=";
  265. strBar = strBar + strBarcodeFlag;
  266. postData.Append(strBar);
  267. CHttpClient httpClient;
  268. httpClient.SetSendHeader(MarkHttpHeaderData());
  269. httpClient.HttpPost(url_str, postData, response);
  270. rapidjson::Document root;
  271. root.Parse(ascii2utf8(response).c_str());
  272. Sleep(1000);//休眠1秒
  273. EnterCriticalSection(db_lock);
  274. bantch_db->execDML("begin transaction");
  275. if (root.IsObject() && root["success"].IsInt() && root["success"].GetInt()){
  276. rapidjson::Value& rows = root["object"];
  277. std::map<std::string, rapidjson::Value> code_obj_map;
  278. //string strT;
  279. //strT = rows[0]["examineeCode"].GetString();
  280. for (int i = 0; i<rows.Size(); i++)
  281. {
  282. code_obj_map[utf82ascii(rows[i]["examineeCode"].GetString())] = rows[i];
  283. }
  284. std::map<string, vector<int>>::iterator it;
  285. char * sql = "INSERT INTO student ( student_id, student_code, class_name, school_id, grade_name, student_name, class_id, score_total ,studentCard,schoolStudentCard ) SELECT t.student_id, t.student_code, t.class_name, t.school_id, t.grade_name, t.student_name, t.class_id, t.score_total,t.studentCard ,t.schoolStudentCard FROM ( SELECT :student_id student_id, :student_code student_code, :class_name class_name, :school_id school_id, :grade_name grade_name, :student_name student_name, :class_id class_id, :score_total score_total, :studentCard studentCard , :schoolStudentCard schoolStudentCard ) t LEFT JOIN student s ON s.student_id = t.student_id WHERE s.student_id IS NULL";
  286. CppSQLite3Statement statement = bantch_db->compileStatement(sql);
  287. for (it = code_id_map.begin(); it != code_id_map.end(); ++it)
  288. {
  289. bool bUpload = true;
  290. std::map<std::string, rapidjson::Value>::iterator it2 = code_obj_map.find(it->first);
  291. for (int m = 0; m<it->second.size(); m++)
  292. {
  293. if (it2 == code_obj_map.end()){//不存在该考生
  294. //if (it2 != code_obj_map.end()){//不存在该考生
  295. // LOG4CPLUS_INFO_FMT(pTestLogger, LOG4CPLUS_TEXT("没有找到考号为%s的考生"), CString(it->first.c_str()));
  296. sprintf_s(sql5, "update student_paper set paper_state =paper_state -%d +%d where student_paper_id =%d", EX_KAOHAODAIPIPEI, EX_KAOHAOBUCUNZAI, it->second[m]);
  297. bantch_db->execDML(sql5);
  298. bUpload = false;
  299. }
  300. else{
  301. //检查是否有考号冲突的试卷
  302. sprintf_s(sql5, "select sp.student_paper_id,sp.paper_state,sp.student_id from student_paper sp where sp.student_id = '%s' and sp.student_paper_id!=%d ", utf82ascii(it2->second["studentId"].GetString()).c_str(), it->second[m]);
  303. CppSQLite3Query q2 = bantch_db->execQuery(sql5);
  304. vector<int> all_conflict_ids;
  305. vector<int> conflict_ids;
  306. while (!q2.eof()){
  307. long paper_state_t = q2.getInt64Field("paper_state");
  308. all_conflict_ids.push_back(q2.getIntField("student_paper_id"));
  309. if (!(paper_state_t&EX_KAOHAOCHONGTU))
  310. conflict_ids.push_back(q2.getIntField("student_paper_id"));
  311. q2.nextRow();
  312. }
  313. bUpload = all_conflict_ids.empty();
  314. if (!all_conflict_ids.empty()){
  315. CppSQLite3Statement stmt3 = bantch_db->compileStatement("insert into exception (exception_type ,exception_name,page_id,student_paper_id) values(:exception_type ,:exception_name,:page_id,:student_paper_id)");
  316. for (int m = 0; m<conflict_ids.size(); m++){//将与之冲突的试卷标记为考号冲突
  317. sprintf_s(sql5, "update student_paper set paper_state =paper_state|%d ,Is_Covered=0 where student_paper_id=%d", EX_KAOHAOCHONGTU, conflict_ids[m]);
  318. bantch_db->execDML(sql5);
  319. stmt3.bind(":student_paper_id", conflict_ids[m]);
  320. stmt3.bind(":exception_type", SHIFT_KAOHAOCHONGTU);
  321. stmt3.bind(":exception_name", "考号冲突");
  322. stmt3.execDML();
  323. CppSQLite3Statement stmt4 = bantch_db->compileStatement("insert INTO message (student_paper_id , message_type) VALUES (:student_paper_id,:message_type)");
  324. stmt4.bind(":student_paper_id", conflict_ids[m]);
  325. stmt4.bind(":message_type", WM_IDENTIFOR_PAPER_STATE_CHAGED);
  326. stmt4.execDML();
  327. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)conflict_ids[m]);
  328. if (g_upload_manager&&g_upload_manager->IsEanble()){
  329. g_upload_manager->UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_DEL_UPLOAD_REPORT, std::to_string(conflict_ids[m]).c_str());
  330. }
  331. }
  332. stmt3.bind(":student_paper_id", it->second[m]);
  333. stmt3.bind(":exception_type", SHIFT_KAOHAOCHONGTU);
  334. stmt3.bind(":exception_name", "考号冲突");
  335. stmt3.execDML();
  336. }
  337. sprintf_s(sql5, "update student_paper set paper_state =paper_state -%d+%d,student_id ='%s' ,Is_Covered=0 where student_paper_id =%d",
  338. EX_KAOHAODAIPIPEI,
  339. all_conflict_ids.empty() ? 0 : EX_KAOHAOCHONGTU,
  340. utf82ascii(it2->second["studentId"].GetString()).c_str(),
  341. it->second[m]);
  342. bantch_db->execDML(sql5);
  343. statement.bind(":student_id", utf82ascii(it2->second["studentId"].GetString()).c_str());
  344. statement.bind(":student_code", utf82ascii(it2->second["examineeCode"].GetString()).c_str());
  345. statement.bind(":class_name", utf82ascii(it2->second["clazzName"].GetString()).c_str());
  346. statement.bind(":school_id", it2->second["schoolId"].GetInt());
  347. statement.bind(":grade_name", utf82ascii(it2->second["gradeName"].GetString()).c_str());
  348. statement.bind(":student_name", utf82ascii(it2->second["studentName"].GetString()).c_str());
  349. statement.bind(":class_id", (long long)it2->second["clazzId"].GetInt64());
  350. statement.bind(":score_total", 0);
  351. statement.bind(":studentCard", it2->second["studentCard"].GetString());
  352. statement.bind(":schoolStudentCard", it2->second["schoolStudentCard"].GetString());
  353. statement.execDML();
  354. }
  355. CppSQLite3Statement stmt4 = bantch_db->compileStatement("insert INTO message (student_paper_id , message_type) VALUES (:student_paper_id,:message_type)");
  356. stmt4.bind(":student_paper_id", it->second[m]);
  357. stmt4.bind(":message_type", WM_IDENTIFOR_PAPER_STATE_CHAGED);
  358. stmt4.execDML();
  359. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)it->second[m]);
  360. if (g_upload_manager&&bUpload){
  361. std::string paper_state_qry_sql = "select paper_state from student_paper where student_paper_id=";
  362. paper_state_qry_sql += std::to_string(it->second[m]);
  363. auto paper_state_qry = bantch_db->execQuery(paper_state_qry_sql.c_str());
  364. if (!paper_state_qry.eof() &&
  365. paper_state_qry.getIntField("paper_state") == 0 && !m_bUseQr){
  366. g_upload_manager->UploadOnScanCmd(UPLOAD_ON_SCAN_CMD::CMD_UPLOAD_SUCCESSSJUAN, std::to_string(it->second[m]).c_str());
  367. }
  368. }
  369. printf("WM_IDENTIFOR_PAPER_STATE_CHAGED match paper_id :%d\n", it->second[m]);
  370. }
  371. }
  372. }
  373. else{
  374. std::map<string, vector<int>>::iterator it;
  375. for (it = code_id_map.begin(); it != code_id_map.end(); ++it)
  376. {
  377. for (int m = 0; m<it->second.size(); m++)
  378. {
  379. sprintf_s(sql5, "update student_paper set paper_state =paper_state -%d +%d where student_paper_id =%d", EX_KAOHAODAIPIPEI, EX_KAOHAOBUCUNZAI, it->second[m]);
  380. bantch_db->execDML(sql5);
  381. CppSQLite3Statement stmt4 = bantch_db->compileStatement("insert INTO message (student_paper_id , message_type) VALUES (:student_paper_id,:message_type)");
  382. stmt4.bind(":student_paper_id", it->second[m]);
  383. stmt4.bind(":message_type", WM_IDENTIFOR_PAPER_STATE_CHAGED);
  384. stmt4.execDML();
  385. if (m_hwnd != NULL)::PostMessage(m_hwnd, WM_IDENTIFOR_PAPER_STATE_CHAGED, (WPARAM)NULL, (LPARAM)it->second[m]);
  386. }
  387. }
  388. }
  389. bantch_db->execDML("commit transaction");
  390. LeaveCriticalSection(db_lock);
  391. }
  392. }
  393. else if (m_resultHandler->GetServiceSate() == stoped){
  394. return stoping;
  395. }
  396. //休息5秒
  397. Sleep(2 * 1000);
  398. return running;
  399. }