http_manager.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net;
  7. using System.IO;
  8. using System.Collections.Specialized;
  9. using System.Threading;
  10. using System.Collections.Concurrent;
  11. using System.Diagnostics;
  12. using SqlSugar;
  13. using Newtonsoft.Json;
  14. using HXX.Scanner.Database;
  15. using HXX.Scanner.Common;
  16. using HXX.Scanner.Biz.Socket;
  17. namespace HXX.Scanner.Biz
  18. {
  19. /// <summary>
  20. /// 文件上传类
  21. /// </summary>
  22. public class upf
  23. {
  24. /// <summary>
  25. /// 文件基本信息,来自数据库
  26. /// </summary>
  27. public tb_file_info entity { get; set; }
  28. /// <summary>
  29. /// 文件当初状态,判断是否允许做上传的动作
  30. /// </summary>
  31. public ResponseEntity<response_http_uploadImg2> result { get; set; }
  32. /// <summary>
  33. /// seqNumber
  34. /// </summary>
  35. //public int seqNumber { get; set; }
  36. /// <summary>
  37. /// upload type
  38. /// </summary>
  39. public upload_type_enum upload_type { get; set; }
  40. }
  41. /// <summary>
  42. /// 文件上传业务
  43. /// </summary>
  44. public class http_manager
  45. {
  46. public http_manager()
  47. {
  48. ////测试状态禁止上传
  49. //if (config_environment.scan_type == ScanType.Test_Panel_1_Side || config_environment.scan_type == ScanType.Test_Panel_2_Sides)
  50. //{
  51. // return;
  52. //}
  53. //else
  54. //{
  55. // url_upload = config_environment.web_parameter.uploadUrl + config_manager.Get("uploadFileUrl");
  56. //}
  57. url_upload = config_environment.web_parameter.uploadUrl;
  58. }
  59. /// <summary>
  60. /// url
  61. /// </summary>
  62. private string url_upload;
  63. /// <summary>
  64. /// 上传失败的处理方法
  65. /// </summary>
  66. public static del_on_net_broken on_net_broken;
  67. /// <summary>
  68. /// 上传结果通知
  69. /// </summary>
  70. public static del_http_notify on_http_notify;
  71. /// <summary>
  72. /// 上传结果通知2
  73. /// </summary>
  74. public static del_http_notify2 on_http_notify2;
  75. /// <summary>
  76. /// 文件上传队列
  77. /// </summary>
  78. private static ConcurrentQueue<upf> queue = new ConcurrentQueue<upf>();
  79. //public void Upload(tb_file_info _entity, ResponseEntity<response_http_uploadImg> _result)
  80. //{
  81. // var e_q = new upf() { entity = _entity, result = _result, seqNumber = 0 };
  82. // queue.Enqueue(e_q);
  83. //}
  84. private static readonly object lockObj = new object();
  85. public static List<long> ready_list = new List<long>();
  86. /// <summary>
  87. /// 检查队列是否为空
  88. /// </summary>
  89. /// <returns></returns>
  90. public static bool check_is_queue_empty()
  91. {
  92. //return false;
  93. return queue.IsEmpty;
  94. }
  95. /// <summary>
  96. /// 进上传队列
  97. /// </summary>
  98. /// <param name="e_q"></param>
  99. public void Upload(upf e_q)
  100. {
  101. queue.Enqueue(e_q);
  102. }
  103. //public static void start_http_upload()
  104. //{
  105. // Task.Run(() =>
  106. // {
  107. // while (true)
  108. // {
  109. // if (!queue.IsEmpty)
  110. // {
  111. // queue.TryDequeue(out upf eq);
  112. // if (eq != null)
  113. // {
  114. // new http_manager().Upload_1(eq.entity, eq.result, eq.seqNumber);
  115. // }
  116. // }
  117. // else
  118. // {
  119. // Thread.Sleep(100);
  120. // }
  121. // }
  122. // });
  123. //}
  124. /// <summary>
  125. /// 队列上传线程
  126. /// </summary>
  127. public static void start_http_upload()
  128. {
  129. Task.Run(() =>
  130. {
  131. while (true)
  132. {
  133. if (!queue.IsEmpty)
  134. {
  135. //队列不空,取一个待上传实体
  136. queue.TryDequeue(out upf eq);
  137. if (eq != null)
  138. {
  139. //真实上传业务
  140. //开始计时
  141. Stopwatch sw = new Stopwatch();
  142. sw.Start();
  143. while (true)
  144. {
  145. //判断图片转换和保存数据库操作是否完成
  146. if ((eq.upload_type == upload_type_enum.normal && eq.result != null && eq.result.Status == 1)
  147. || eq.upload_type == upload_type_enum.reUpload)
  148. {
  149. //告诉网页端开始上传
  150. //if (eq.entity.fi_zipId == 1)
  151. //{
  152. // var response = new response_uploading() { batchNumber = eq.entity.fi_batchSeq, subjectCode = eq.entity.fi_subjectCode };
  153. // on_http_notify2(JsonConvert.SerializeObject(response));
  154. //}
  155. //http上传
  156. eq.result = new http_manager().Upload_1(eq);
  157. break;
  158. }
  159. else
  160. {
  161. //数据操作超时
  162. if (sw.ElapsedMilliseconds > 10000)
  163. {
  164. eq.result.Status = 0;
  165. eq.result.Message = "保存图片超时";
  166. sw.Stop();
  167. break;
  168. }
  169. else
  170. {
  171. Thread.Sleep(100);
  172. }
  173. }
  174. }
  175. //真实上传业务
  176. //test
  177. //if (testflag)
  178. //{
  179. // eq.result.Status = 1;
  180. //}
  181. //else
  182. //{
  183. // eq.result.Status = 0;
  184. //}
  185. //testflag = !testflag;
  186. //test
  187. //AfterUpload(eq);
  188. }
  189. }
  190. else
  191. {
  192. Thread.Sleep(100);
  193. }
  194. }
  195. });
  196. }
  197. private static void AfterUpload(upf eq)
  198. {
  199. //Thread.Sleep(1000);
  200. try
  201. {
  202. if (eq.result.Status == 1 || eq.result.Status == 200 )
  203. {
  204. entity_server_upload server_response = null;
  205. try
  206. {
  207. server_response = JsonConvert.DeserializeObject<entity_server_upload>(eq.result.Data.data_string);
  208. }
  209. catch (Exception ee)
  210. {
  211. LogManager_Lock.WriteLog(ee.Message);
  212. }
  213. var db_list = new biz_db().get_by_sn(eq.entity.fi_SN);
  214. foreach (var entity in db_list)
  215. {
  216. var fileName = Path.GetFileName(entity.fi_full_name);
  217. var path = Path.GetDirectoryName(entity.fi_full_name);
  218. path = path.Replace("ready", "complete");
  219. fileName = Path.Combine(path, fileName);
  220. try
  221. {
  222. if (File.Exists(fileName))
  223. {
  224. File.Delete(fileName);
  225. }
  226. //把上传成功的文件,从ready移动到complete中
  227. File.Move(entity.fi_full_name, fileName);
  228. }
  229. catch (Exception e1)
  230. {
  231. LogManager_Lock.WriteLog(e1.Message);
  232. response_error error = new response_error(e1.Message);
  233. on_http_notify2(JsonConvert.SerializeObject(error));
  234. }
  235. var url = get_url_from_server_response(entity, server_response);
  236. //上传成功,更新数据库标志
  237. new biz_db().update_upload_flag_by_id(entity.fi_id, 1, url);
  238. new biz_db().update_file_name(entity.fi_id, fileName);
  239. }
  240. }
  241. else if (eq.result.Status == -1)
  242. {
  243. return;
  244. }
  245. else
  246. {
  247. new biz_db().update_upload_flag_by_SN(eq.entity.fi_SN.Value, -1);
  248. }
  249. //socket发送结果
  250. if (eq.upload_type == upload_type_enum.normal)
  251. {
  252. notify_nomral(eq);
  253. }
  254. else
  255. {
  256. notify_reUpload(eq);
  257. }
  258. }
  259. catch (Exception ee)
  260. {
  261. LogManager_Lock.WriteLog(eq.result.Message);
  262. response_error error = new response_error(ee.Message);
  263. on_http_notify2(JsonConvert.SerializeObject(error));
  264. }
  265. }
  266. private static string get_url_from_server_response(tb_file_info db_entity, entity_server_upload server_response)
  267. {
  268. string result = string.Empty;
  269. try
  270. {
  271. var data = server_response.data.Where(x => x.Contains("_" + db_entity.fi_zipId + ".")).FirstOrDefault();
  272. if (!string.IsNullOrEmpty(data))
  273. {
  274. result = data;
  275. }
  276. }
  277. catch (Exception ee)
  278. {
  279. LogManager.WriteLog(ee.Message);
  280. }
  281. return result;
  282. }
  283. private static void notify_nomral(upf eq)
  284. {
  285. var entity = eq.entity;
  286. var qty = new biz_db().get_upload_count_by_batchNumber(eq.entity.fi_batchSeq, eq.entity.fi_subjectCode);
  287. var response1 = new response_uploadNumber() { number = qty.qty_success, batchNumber = eq.entity.fi_batchSeq };
  288. //var response2 = new response_fainNumber() { number = qty.qty_fail, batchNumber = eq.entity.fi_batchSeq };
  289. on_http_notify(eq);
  290. on_http_notify2(JsonConvert.SerializeObject(response1));
  291. //on_http_notify2(JsonConvert.SerializeObject(response2));
  292. //if (queue.IsEmpty)
  293. //{
  294. // var response_finish = new response_uploadFinish() { subjectCode = entity.fi_subjectCode, batchNumber = entity.fi_batchSeq };
  295. // var upload_count = new biz_db().get_upload_count_by_batchNumber(entity.fi_batchSeq, entity.fi_subjectCode);
  296. // response_finish.scanNumber = new biz_db().get_count_by_batchNumber(entity.fi_batchSeq, entity.fi_subjectCode);
  297. // response_finish.uploadNumber = upload_count.qty_success;
  298. // response_finish.failedNumber = upload_count.qty_fail;
  299. // on_http_notify2(JsonConvert.SerializeObject(response_finish));
  300. //}
  301. }
  302. public static void notify_scan_finish()
  303. {
  304. Task.Run(() =>
  305. {
  306. if (config_environment.scan_type2 == ScanType.Formal)
  307. {
  308. while (!queue.IsEmpty)
  309. {
  310. Thread.Sleep(100);
  311. }
  312. var response_finish = new response_uploadFinish();
  313. try
  314. {
  315. response_finish.subjectCode = config_environment.web_parameter.subjectCode;
  316. response_finish.batchNumber = config_environment.web_parameter.batchNumber;
  317. var upload_count = new biz_db().get_upload_count_by_batchNumber(config_environment.web_parameter.batchNumber, config_environment.web_parameter.subjectCode);
  318. response_finish.scanNumber = new biz_db().get_count_by_batchNumber(config_environment.web_parameter.batchNumber, config_environment.web_parameter.subjectCode);
  319. response_finish.uploadNumber = upload_count.qty_success;
  320. response_finish.failedNumber = upload_count.qty_fail;
  321. }
  322. catch (Exception ee)
  323. {
  324. response_finish.code = 500;
  325. response_finish.msg = ee.Message;
  326. LogManager.WriteLog(ee.Message);
  327. }
  328. on_http_notify2(JsonConvert.SerializeObject(response_finish));
  329. }
  330. });
  331. }
  332. private static void notify_reUpload(upf eq)
  333. {
  334. var response1 = new response_reUpload_single_finish();
  335. response1.fileIndex = get_ids_whenUpload(eq.entity.fi_SN);
  336. response1.batchNumber = eq.entity.fi_batchSeq;
  337. response1.subjectCode = eq.entity.fi_subjectCode;
  338. if (eq.result.Status == 1 || eq.result.Status == -1 || eq.result.Status == 200)
  339. {
  340. response1.uploadState = 0;
  341. }
  342. else
  343. {
  344. response1.uploadState = 1;
  345. }
  346. on_http_notify2(JsonConvert.SerializeObject(response1));
  347. if (queue.IsEmpty)
  348. {
  349. var response_finish = new response_reUpload_all_finish() { subjectCode = eq.entity.fi_subjectCode, batchNumber = eq.entity.fi_batchSeq, number = biz_reUpload.current_list.Count(x => x.fi_side == 1) };
  350. string id_list = string.Empty;
  351. foreach (var record in biz_reUpload.current_list)
  352. {
  353. id_list += "," + record.fi_id;
  354. }
  355. if (id_list.Length > 0)
  356. {
  357. id_list = id_list.Substring(1);
  358. }
  359. response_finish.failedNumber = new biz_db().get_not_upload_status(id_list);
  360. on_http_notify(eq);
  361. on_http_notify2(JsonConvert.SerializeObject(response_finish));
  362. }
  363. }
  364. /// <summary>
  365. /// 单任务上传
  366. /// </summary>
  367. /// <param name="entity"></param>
  368. /// <param name="result"></param>
  369. /// <param name="seqNumber"></param>
  370. /// <returns></returns>
  371. //private ResponseEntity<response_http_uploadImg2> Upload_1(tb_file_info entity, ResponseEntity<response_http_uploadImg2> result, int seqNumber)
  372. private ResponseEntity<response_http_uploadImg2> Upload_1(upf eq)
  373. {
  374. if (eq.entity != null)
  375. {
  376. if (eq.upload_type == upload_type_enum.normal && eq.result.Status == 1)
  377. {
  378. try
  379. {
  380. //根据实体获取json
  381. var content = get_json(eq.entity);
  382. eq.result = content.Item1;
  383. if (eq.result.Status == 1)
  384. {
  385. //多线程上传防重复数据
  386. if (!ready_list.Exists(x => x == eq.entity.fi_SN.Value))
  387. {
  388. ready_list.Add(eq.entity.fi_SN.Value);
  389. eq.result = upload_try(eq, eq.result.Message, content.Item2);
  390. }
  391. }
  392. else if (eq.result.Status == -1)
  393. {
  394. //双面的第一面,等待第二面到来再传
  395. return eq.result;
  396. }
  397. }
  398. catch (Exception ee)
  399. {
  400. eq.result.Status = 0;
  401. eq.result.Message = ee.Message;
  402. }
  403. //biz_scanFinish.Work(eq.entity, eq.result);
  404. }
  405. else if (eq.upload_type == upload_type_enum.reUpload)
  406. {
  407. try
  408. {
  409. //根据实体获取json
  410. var content = get_json(eq.entity);
  411. eq.result = content.Item1;
  412. if (eq.result.Status == 1)
  413. {
  414. eq.result = upload_try(eq, eq.result.Message, content.Item2);
  415. }
  416. else if (eq.result.Status == -1)
  417. {
  418. //双面的第一面,等待第二面到来再传
  419. return eq.result;
  420. }
  421. else
  422. {
  423. var response3 = new response_reUpload_error()
  424. {
  425. batchNumber = eq.entity.fi_batchSeq,
  426. subjectCode = eq.entity.fi_subjectCode,
  427. code = 500,
  428. msg = eq.result.Message,
  429. };
  430. on_http_notify2(JsonConvert.SerializeObject(response3));
  431. }
  432. }
  433. catch (Exception ee)
  434. {
  435. eq.result.Status = 0;
  436. eq.result.Message = ee.Message;
  437. LogManager.WriteLog(ee.Message);
  438. }
  439. }
  440. }
  441. return eq.result;
  442. }
  443. private string get_seqNumbers_whenUpload(long? sn)
  444. {
  445. string result = "";
  446. var list = new biz_db().get_by_sn(sn);
  447. if (list[0].fi_schema != list.Count)
  448. {
  449. throw new Exception("Paper Schema does not match Paper Count");
  450. }
  451. foreach (var record in list)
  452. {
  453. result += "," + record.fi_zipId;
  454. }
  455. if (result.Length > 0)
  456. {
  457. result = result.Substring(1);
  458. }
  459. return result;
  460. }
  461. private static string get_ids_whenUpload(long? sn)
  462. {
  463. string result = "";
  464. var list = new biz_db().get_by_sn(sn);
  465. foreach (var record in list)
  466. {
  467. result += "," + record.fi_id;
  468. }
  469. if (result.Length > 0)
  470. {
  471. result = result.Substring(1);
  472. }
  473. return result;
  474. }
  475. /// <summary>
  476. /// 3次上传尝试
  477. /// </summary>
  478. /// <param name="json"></param>
  479. /// <param name="file_list"></param>
  480. /// <returns></returns>
  481. private ResponseEntity<response_http_uploadImg2> upload_try(upf eq, string json, List<string> file_list)
  482. {
  483. var result = new ResponseEntity<response_http_uploadImg2>();
  484. //////////
  485. var entity = JsonConvert.DeserializeObject<request_http_uploadImg>(json);
  486. /////////
  487. NameValueCollection param_list = new NameValueCollection();
  488. //new
  489. param_list.Add("seqNumbers", get_seqNumbers_whenUpload(eq.entity.fi_SN));
  490. param_list.Add("paperSchema", eq.entity.fi_schema.ToString());
  491. //new
  492. //old
  493. param_list.Add("seqNumber", eq.entity.fi_zipId.ToString());
  494. param_list.Add("schema", eq.entity.fi_schema.ToString());
  495. //old
  496. param_list.Add("jsonParam", config_environment.web_parameter.jsonParam);
  497. //修改为多线程上传
  498. ThreadPool_manager.EnqueueTask(new Action(() =>
  499. {
  500. upload_thread(eq, param_list, file_list);
  501. }));
  502. result.Status = 1;
  503. result.Message = "ok";
  504. return result;
  505. }
  506. private void upload_thread(upf eq, NameValueCollection param_list, List<string> file_list)
  507. {
  508. try
  509. {
  510. int try_count = 0;
  511. Stopwatch sw = new Stopwatch();
  512. while (try_count < 3)
  513. {
  514. try_count++;
  515. sw.Restart();
  516. eq.result = upload_try2(param_list, file_list);
  517. sw.Stop();
  518. write_operation_log(try_count, sw, file_list, eq.result);
  519. if (eq.result.Status == 1)
  520. {
  521. break;
  522. }
  523. else
  524. {
  525. Thread.Sleep(100);
  526. }
  527. }
  528. //lock (lockObj)
  529. {
  530. AfterUpload(eq);
  531. }
  532. }
  533. catch (Exception ee)
  534. {
  535. LogManager_Lock.WriteLog(ee);
  536. }
  537. }
  538. private void write_operation_log(int try_count, Stopwatch sw, List<string> file_list, ResponseEntity<response_http_uploadImg2> result)
  539. {
  540. StringBuilder sb = new StringBuilder();
  541. sb.Append("第" + try_count + "次上传" + Environment.NewLine);
  542. sb.Append("服务器返回:" + result.Status + Environment.NewLine);
  543. sb.Append("花费时间: " + sw.ElapsedMilliseconds + "ms" + Environment.NewLine + Environment.NewLine);
  544. sb.Append("文件列表:" + Environment.NewLine);
  545. foreach (var f in file_list)
  546. {
  547. sb.Append(f + Environment.NewLine);
  548. }
  549. LogManager_Lock.WriteLog(sb.ToString());
  550. }
  551. /// <summary>
  552. /// 具体上传逻辑
  553. /// </summary>
  554. /// <param name="param_list"></param>
  555. /// <param name="file_list"></param>
  556. /// <returns></returns>
  557. private ResponseEntity<response_http_uploadImg2> upload_try2(NameValueCollection param_list, List<string> file_list)
  558. {
  559. ResponseEntity<response_http_uploadImg2> result = new ResponseEntity<response_http_uploadImg2>();
  560. try
  561. {
  562. var response_string = http_helper.HttpUploadFile2(url_upload, file_list, "files", "multipart/form-data", config_environment.web_parameter.token, param_list);
  563. try
  564. {
  565. result.Data = JsonConvert.DeserializeObject<response_http_uploadImg2>(response_string);
  566. }
  567. catch (Exception ee2)
  568. {
  569. if (ee2.Message.StartsWith("Unexpected character"))
  570. {
  571. result.Data = new response_http_uploadImg2() { code = 200 };
  572. }
  573. else
  574. {
  575. throw ee2;
  576. }
  577. }
  578. result.Data.data_string = response_string;
  579. if (result.Data.code == 200)
  580. {
  581. result.Status = 1;
  582. result.Message = "ok";
  583. }
  584. else
  585. {
  586. result.Status = result.Data.code;
  587. result.Message = result.Data.msg;
  588. LogManager_Lock.WriteLog(response_string);
  589. }
  590. }
  591. catch (Exception ee)
  592. {
  593. LogManager_Lock.WriteLog(ee);
  594. if (ee.Message.Contains("未能解析此远程名称"))
  595. {
  596. on_net_broken();
  597. }
  598. else if (ee.Message.Contains("超时") || ee.Message.Contains("timeout"))
  599. {
  600. result.Status = -2;
  601. result.Message = "http上传超时";
  602. }
  603. else
  604. {
  605. result.Status = 0;
  606. result.Message = "http上传文件失败:" + ee.Message;
  607. }
  608. }
  609. return result;
  610. }
  611. /// <summary>
  612. /// 根据实体获取json
  613. /// </summary>
  614. /// <param name="entity"></param>
  615. /// <param name="seqNumber"></param>
  616. /// <returns></returns>
  617. private Tuple<ResponseEntity<response_http_uploadImg2>, List<string>> get_json(tb_file_info entity)
  618. {
  619. ResponseEntity<response_http_uploadImg2> result_entity = new ResponseEntity<response_http_uploadImg2>();
  620. List<string> result_path = new List<string>();
  621. try
  622. {
  623. List<tb_file_info> file_list = new List<tb_file_info>();
  624. //单面
  625. if (entity.fi_schema == 1)
  626. {
  627. file_list.Add(entity);
  628. }
  629. //双面
  630. else
  631. {
  632. file_list = new biz_db().get_by_sn(entity.fi_SN);
  633. if (file_list.Count < 2)
  634. {
  635. var ss = entity.fi_side;
  636. var ss2 = entity.fi_full_name;
  637. result_entity.Status = -1;
  638. result_entity.Message = "第1面,等待第2面再传";
  639. return new Tuple<ResponseEntity<response_http_uploadImg2>, List<string>>(result_entity, result_path);
  640. }
  641. if (file_list.Count(x => x.fi_upload_flag == 1) == file_list.Count)
  642. {
  643. result_entity.Status = -1;
  644. result_entity.Message = "已全部上传";
  645. return new Tuple<ResponseEntity<response_http_uploadImg2>, List<string>>(result_entity, result_path);
  646. }
  647. }
  648. if (file_list.Count == 1 || file_list.Count == 2)
  649. {
  650. bool flag = true;
  651. foreach (var f in file_list)
  652. {
  653. if (!File.Exists(f.fi_full_name))
  654. {
  655. flag = false;
  656. break;
  657. }
  658. }
  659. if (flag)
  660. {
  661. var req = new request_http_uploadImg();
  662. req.token = config_environment.web_parameter.token;
  663. req.fileCount = file_list.Count;
  664. req.isTest = file_list[0].fi_isTest;
  665. req.fileMetaInfo = new List<subRequest_http_uploadImg>();
  666. req.zipId = file_list[0].fi_zipId;
  667. req.examId = file_list[0].fi_examId;
  668. req.examPaperId = file_list[0].fi_examPaperId;
  669. //req.seqNumber = file_list[0].fi_schema;
  670. //req.seqNumber = file_manager.get_seqNumber();
  671. //req.seqNumber = seqNumber;
  672. req.schoolId = config_environment.web_parameter.schoolId;
  673. req.accountId = file_list[0].fi_accountId.ToString();
  674. //req.completedAmount = new biz_db().get_count_by_seq(config_environment.web_parameter.batchNumber, req.zipId);
  675. req.completedAmount = new biz_db().get_count_by_seq(file_list[0].fi_batchSeq, req.zipId, config_environment.web_parameter.paperSchema);
  676. //req.batchNumber = file_list[0].fi_batchNumber;
  677. req.batchNumber = entity.fi_batchSeq;
  678. req.schema = entity.fi_schema == null ? "1" : entity.fi_schema.ToString();
  679. foreach (var f in file_list)
  680. {
  681. var sub = new subRequest_http_uploadImg();
  682. sub.fileName = f.fi_name;
  683. req.fileMetaInfo.Add(sub);
  684. result_path.Add(f.fi_full_name);
  685. }
  686. result_entity.Status = 1;
  687. result_entity.Message = JsonConvert.SerializeObject(req);
  688. }
  689. else
  690. {
  691. result_entity.Status = 0;
  692. result_entity.Message = "未能找到用于上传的文件";
  693. }
  694. }
  695. else
  696. {
  697. result_entity.Status = 0;
  698. result_entity.Message = "db错误,未能找到用于上传的文件记录";
  699. }
  700. }
  701. catch (Exception ee)
  702. {
  703. LogManager.WriteLog(ee);
  704. result_entity.Status = 0;
  705. result_entity.Message = ee.Message;
  706. }
  707. return new Tuple<ResponseEntity<response_http_uploadImg2>, List<string>>(result_entity, result_path);
  708. }
  709. }
  710. }