biz_db.cs 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using System.Configuration;
  8. using SqlSugar;
  9. using HXX.Scanner.Database;
  10. namespace HXX.Scanner.Biz
  11. {
  12. /// <summary>
  13. /// 数据库 业务类
  14. /// </summary>
  15. public class biz_db : biz_db_base
  16. {
  17. /// <summary>
  18. /// 向扫描数据表中增加一条记录
  19. /// </summary>
  20. /// <param name="file"></param>
  21. /// <returns></returns>
  22. public tb_file_info Add(file_info file)
  23. {
  24. tb_file_info entity = new tb_file_info();
  25. entity.fi_SN = file.SN;
  26. entity.fi_schema = file.paperSchema;
  27. entity.fi_side = file.current_side;
  28. entity.fi_paper_size = file.paperSize;
  29. entity.fi_name = file.file_name;
  30. entity.fi_full_name = file.file_full_name;
  31. entity.fi_ext = file.file_ext;
  32. entity.fi_size = 0;
  33. entity.fi_upload_flag = 0;
  34. entity.fi_createTime = DateTime.Now;
  35. entity.fi_accountId = file.accountId.ToString();
  36. entity.fi_examId = file.examId;
  37. entity.fi_examPaperId = file.examPaperId;
  38. entity.fi_zipId = file.zipId;
  39. entity.fi_batchSeq = file.batchNumber;
  40. entity.fi_isTest = file.isTest;
  41. entity.fi_token = file.token;
  42. entity.fi_server_url = ""; // file.uploadUrl;
  43. entity.fi_subjectCode = file.subjectCode;
  44. using (var db = SqlSugarHelper.GetClient())
  45. {
  46. db.Insertable<tb_file_info>(entity).ExecuteCommandIdentityIntoEntity();
  47. }
  48. return entity;
  49. }
  50. /// <summary>
  51. /// 获取本批次扫描数量
  52. /// </summary>
  53. /// <param name="batchNumber"></param>
  54. /// <param name="zipId"></param>
  55. /// <param name="ab">正反面</param>
  56. /// <returns></returns>
  57. public int get_count_by_seq(string batchNumber, int? zipId, int ab)
  58. {
  59. int result = 0;
  60. using (var db = SqlSugarHelper.GetClient())
  61. {
  62. result = db.Queryable<tb_file_info>().Count(x => x.fi_batchSeq == batchNumber && x.fi_zipId == zipId && x.fi_side == ab);
  63. }
  64. return result;
  65. }
  66. /// <summary>
  67. /// 根据sn获取记录组,相同一张纸,正反面拥有同一个sn
  68. /// </summary>
  69. /// <param name="SN"></param>
  70. /// <returns></returns>
  71. public List<tb_file_info> get_by_sn(long? SN)
  72. {
  73. List<tb_file_info> list;
  74. using (var db = SqlSugarHelper.GetClient())
  75. {
  76. list = db.Queryable<tb_file_info>().Where(x => x.fi_SN == SN).ToList();
  77. }
  78. return list;
  79. }
  80. /// <summary>
  81. ///
  82. /// </summary>
  83. /// <param name="subjectCode"></param>
  84. /// <param name="batchNumber"></param>
  85. /// <returns></returns>
  86. public List<tb_file_info> get_by_subjectCode_batchNumber(string subjectCode, string batchNumber)
  87. {
  88. List<tb_file_info> list;
  89. using (var db = SqlSugarHelper.GetClient())
  90. {
  91. list = db.Queryable<tb_file_info>().Where(x => x.fi_batchSeq == batchNumber && x.fi_subjectCode == subjectCode).ToList();
  92. }
  93. return list;
  94. }
  95. /// <summary>
  96. ///
  97. /// </summary>
  98. /// <param name="subjectCode"></param>
  99. /// <param name="batchNumber"></param>
  100. /// <returns></returns>
  101. public void deleteBatch(string subjectCode, string batchNumber)
  102. {
  103. using (var db = SqlSugarHelper.GetClient())
  104. {
  105. db.Deleteable<tb_file_info>(x => x.fi_batchSeq == batchNumber && x.fi_subjectCode == subjectCode).ExecuteCommand();
  106. }
  107. }
  108. //上传后,更新上传成功或失败标志
  109. public void update_upload_flag_by_id(int id, int status, string upload_url)
  110. {
  111. using (var db = SqlSugarHelper.GetClient())
  112. {
  113. var entity = db.Queryable<tb_file_info>().First(x => x.fi_id == id);
  114. if (entity != null)
  115. {
  116. entity.fi_upload_flag = status;
  117. entity.fi_server_url = upload_url;
  118. db.Updateable<tb_file_info>(entity).ExecuteCommand();
  119. }
  120. }
  121. }
  122. //上传后,更新上传成功或失败标志
  123. public void update_upload_flag_by_SN(long sn, int status)
  124. {
  125. using (var db = SqlSugarHelper.GetClient())
  126. {
  127. var list = db.Queryable<tb_file_info>().Where(x => x.fi_SN == sn).ToList();
  128. foreach(var entity in list)
  129. {
  130. entity.fi_upload_flag = status;
  131. db.Updateable<tb_file_info>(entity).ExecuteCommand();
  132. }
  133. }
  134. }
  135. //更新文件位置
  136. public void update_file_name(int id, string fileName)
  137. {
  138. using (var db = SqlSugarHelper.GetClient())
  139. {
  140. var entity = db.Queryable<tb_file_info>().First(x => x.fi_id == id);
  141. if (entity != null)
  142. {
  143. entity.fi_full_name = fileName;
  144. db.Updateable<tb_file_info>(entity).ExecuteCommand();
  145. }
  146. }
  147. }
  148. //获取某批次所有数量
  149. public int get_count_by_batchNumber(string batchNumber, string subjectCode)
  150. {
  151. int count = 0;
  152. using (var db = SqlSugarHelper.GetClient())
  153. {
  154. count = db.Queryable<tb_file_info>().Count(x => x.fi_batchSeq == batchNumber && x.fi_subjectCode == subjectCode && x.fi_side == 1);
  155. }
  156. return count;
  157. }
  158. //获取某批次上传成功的数量
  159. public qty_of_upload get_upload_count_by_batchNumber(string batchNumber, string subjectCode)
  160. {
  161. qty_of_upload qty = new qty_of_upload();
  162. using (var db = SqlSugarHelper.GetClient())
  163. {
  164. qty.qty_success = db.Queryable<tb_file_info>().Count(x => x.fi_batchSeq == batchNumber && x.fi_subjectCode == subjectCode && x.fi_upload_flag == 1 && x.fi_side == 1);
  165. qty.qty_fail = db.Queryable<tb_file_info>().Count(x => x.fi_batchSeq == batchNumber && x.fi_subjectCode == subjectCode && x.fi_upload_flag != 1 && x.fi_side == 1);
  166. }
  167. return qty;
  168. }
  169. //获取某批次所有未上传记录
  170. public List<tb_file_info> get_not_upload_list(string batchNumber, string subjectCode)
  171. {
  172. List<tb_file_info> result;
  173. using (var db = SqlSugarHelper.GetClient())
  174. {
  175. result = db.Queryable<tb_file_info>().Where(x => x.fi_batchSeq == batchNumber && x.fi_subjectCode == subjectCode && x.fi_upload_flag != 1).ToList();
  176. }
  177. return result;
  178. }
  179. //获取多批次所有未上传记录
  180. public List<tb_file_info> get_not_upload_list2(string[] batchList, string subjectCode)
  181. {
  182. List<tb_file_info> result;
  183. using (var db = SqlSugarHelper.GetClient())
  184. {
  185. result = db.Queryable<tb_file_info>().Where(x => batchList.Contains(x.fi_batchSeq) && x.fi_subjectCode == subjectCode && x.fi_upload_flag != 1).ToList();
  186. }
  187. return result;
  188. }
  189. //获取某些id的上传失败情况
  190. public int get_not_upload_status(string id_list)
  191. {
  192. int count = 0;
  193. using (var db = SqlSugarHelper.GetClient())
  194. {
  195. var sql = "select 1 from tb_file_info where fi_id in ({0}) and fi_upload_flag <> 1 and fi_side=1";
  196. sql = string.Format(sql, id_list);
  197. count = db.Ado.SqlQuery<tb_file_info>(sql).Count;
  198. }
  199. return count;
  200. }
  201. /// <summary>
  202. /// test
  203. /// </summary>
  204. /// <returns></returns>
  205. public List<tb_file_info> test()
  206. {
  207. List<tb_file_info> list;
  208. using (var db = SqlSugarHelper.GetClient())
  209. {
  210. list = db.Queryable<tb_file_info>().ToPageList(1, 10);
  211. }
  212. return list;
  213. }
  214. }
  215. }