SaveBillExcutor.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using JLHHJSvr.BLL;
  7. using JLHHJSvr.Com.APP;
  8. using JLHHJSvr.DBA.DBModle;
  9. using LJLib.DAL.SQL;
  10. using LJLib.Net.SPI.Server;
  11. using LJLib.Tools.Encry;
  12. namespace JLHHJSvr.Excutor.APP
  13. {
  14. internal sealed class SaveBillExcutor : ExcutorBase<SaveBillRequest, SaveBillResponse>
  15. {
  16. protected override void ExcuteInternal(SaveBillRequest request, object state, SaveBillResponse rslt)
  17. {
  18. var tokendata = BllHelper.GetToken(request.token);
  19. if (tokendata == null)
  20. {
  21. rslt.ErrMsg = "会话已经中断,请重新登录";
  22. return;
  23. }
  24. if (request.billInfo == null)
  25. {
  26. rslt.ErrMsg = "信息接收异常,请重试";
  27. return;
  28. }
  29. if (request.billInfo.roadid == null || request.billInfo.roadid == 0)
  30. {
  31. rslt.ErrMsg = "未选择路段";
  32. return;
  33. }
  34. if (string.IsNullOrEmpty(request.billInfo.carnum))
  35. {
  36. rslt.ErrMsg = "请先填写车牌号码";
  37. return;
  38. }
  39. request.billInfo.carnum = request.billInfo.carnum.ToUpper();
  40. if (request.billInfo.dscrp == null)
  41. {
  42. rslt.ErrMsg = "备注信息接收异常,请重试";
  43. return;
  44. }
  45. if (request.billInfo.pictureList == null || request.billInfo.pictureList.Count == 0)
  46. {
  47. rslt.ErrMsg = "图片信息接收异常";
  48. return;
  49. }
  50. if (request.billInfo.pictureList.Count < 2)
  51. {
  52. rslt.ErrMsg = "需要上传近景、远景两张图片";
  53. return;
  54. }
  55. foreach (var fileInfo in request.billInfo.pictureList)
  56. {
  57. if (string.IsNullOrEmpty(fileInfo.base64))
  58. {
  59. rslt.ErrMsg = "文件数据获取失败,请重新选择";
  60. return;
  61. }
  62. if (string.IsNullOrEmpty(fileInfo.fileType))
  63. {
  64. rslt.ErrMsg = "文件类型获取失败,请重新选择";
  65. return;
  66. }
  67. }
  68. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  69. using (var cmd = con.CreateCommand())
  70. {
  71. con.Open();
  72. var carInfo = new st_car {carnum = request.billInfo.carnum};
  73. if (DbSqlHelper.SelectOne(cmd,carInfo,"owner, owner_tel") != 1)
  74. {
  75. carInfo.owner = string.Empty;
  76. carInfo.owner_tel = string.Empty;
  77. }
  78. using (cmd.Transaction = con.BeginTransaction())
  79. {
  80. try
  81. {
  82. //主表
  83. var stBill = new st_bill
  84. {
  85. billid = BllHelper.GetID(cmd, "st_bill"),
  86. roadid = request.billInfo.roadid,
  87. carnum = carInfo.carnum,
  88. owner = carInfo.owner,
  89. owner_tel = carInfo.owner_tel,
  90. dscrp = request.billInfo.dscrp,
  91. flag = 0,
  92. opemp = tokendata.username,
  93. opdate = DateTime.Now
  94. };
  95. DbSqlHelper.Insert(cmd, stBill,
  96. "billid,roadid,roadname,carnum,owner,owner_tel,dscrp,flag,opemp,opdate");
  97. //附件明细
  98. MD5 md5 = new MD5();
  99. var printid = 0;
  100. foreach (var file in request.billInfo.pictureList)
  101. {
  102. printid++;
  103. // 格式为data:image/jpeg;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  104. if (file.base64 == null || !file.base64.StartsWith("data"))
  105. {
  106. rslt.ErrMsg = "获取图片数据失败,请刷新后重试";
  107. return;
  108. }
  109. // 插入新附件
  110. var base64 = file.base64;
  111. var typeEndIndex = base64.IndexOf(";base64");
  112. if (typeEndIndex <= 0)
  113. {
  114. rslt.ErrMsg = "图片格式异常,请重新上传";
  115. return;
  116. }
  117. var fileData = Convert.FromBase64String(base64.Substring(typeEndIndex + 8));
  118. var filemd5 = md5.GetMD5(fileData);
  119. var filemap = new st_file { filemd5 = filemd5 };
  120. if (DbSqlHelper.SelectOne(cmd, filemap, "filemd5") != 1)
  121. {
  122. filemap.filedata = fileData;
  123. filemap.fileType = file.fileType;
  124. DbSqlHelper.Insert(cmd, filemap, "filemd5, filedata, fileType");
  125. }
  126. var billmx = new st_bill_mx
  127. {
  128. billid = stBill.billid,
  129. printid = printid,
  130. filemd5 = filemd5
  131. };
  132. DbSqlHelper.Insert(cmd, billmx, "billid,printid,filemd5");
  133. }
  134. cmd.Transaction.Commit();
  135. }
  136. catch (Exception e)
  137. {
  138. cmd.Transaction.Rollback();
  139. rslt.ErrMsg = e.ToString();
  140. return;
  141. }
  142. }
  143. }
  144. }
  145. }
  146. }