SaveBillExcutor.cs 6.0 KB

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