EditBillExcutor.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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 EditBillExcutor : ExcutorBase<EditBillRequest, EditBillResponse>
  15. {
  16. protected override void ExcuteInternal(EditBillRequest request, object state, EditBillResponse 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.billid == null || request.billInfo.billid == 0)
  30. {
  31. rslt.ErrMsg = "数据异常,获取单号失败";
  32. return;
  33. }
  34. if (request.billInfo.flag == 1)
  35. {
  36. if (request.billInfo.roadid == null || request.billInfo.roadid == 0)
  37. {
  38. rslt.ErrMsg = "未选择路段";
  39. return;
  40. }
  41. if (string.IsNullOrEmpty(request.billInfo.carnum))
  42. {
  43. rslt.ErrMsg = "请先填写车牌号码";
  44. return;
  45. }
  46. request.billInfo.carnum = request.billInfo.carnum.ToUpper();
  47. if (request.billInfo.dscrp == null)
  48. {
  49. rslt.ErrMsg = "备注信息接收异常,请重试";
  50. return;
  51. }
  52. if (string.IsNullOrEmpty(request.billInfo.owner))
  53. {
  54. rslt.ErrMsg = "车主姓名不能为空";
  55. return;
  56. }
  57. if (string.IsNullOrEmpty(request.billInfo.owner_tel))
  58. {
  59. rslt.ErrMsg = "车主电话不能为空";
  60. return;
  61. }
  62. if (request.billInfo.paytype == null || request.billInfo.paytype == 0)
  63. {
  64. rslt.ErrMsg = "支付方式未选择";
  65. return;
  66. }
  67. if (request.billInfo.auditdate == null)
  68. {
  69. request.billInfo.auditdate = DateTime.Now;
  70. }
  71. if (request.billInfo.payamt == null)
  72. {
  73. rslt.ErrMsg = "未填写金额";
  74. return;
  75. }
  76. if (request.billInfo.pictureList == null || request.billInfo.pictureList.Count == 0)
  77. {
  78. rslt.ErrMsg = "图片信息接收异常";
  79. return;
  80. }
  81. foreach (var fileInfo in request.billInfo.pictureList)
  82. {
  83. if (string.IsNullOrEmpty(fileInfo.base64))
  84. {
  85. rslt.ErrMsg = "文件数据获取失败,请重新选择";
  86. return;
  87. }
  88. if (string.IsNullOrEmpty(fileInfo.fileType))
  89. {
  90. rslt.ErrMsg = "文件类型获取失败,请重新选择";
  91. return;
  92. }
  93. }
  94. }
  95. else if (request.billInfo.flag == 2)
  96. {
  97. }
  98. else
  99. {
  100. rslt.ErrMsg = "所提交的状态未定义";
  101. return;
  102. }
  103. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  104. using (var cmd = con.CreateCommand())
  105. {
  106. con.Open();
  107. var stBill = new st_bill
  108. {
  109. billid = request.billInfo.billid
  110. };
  111. if (DbSqlHelper.SelectOne(cmd,stBill,"flag") != 1)
  112. {
  113. rslt.ErrMsg = "未查找到所提交的违停记录,可能已被删除";
  114. return;
  115. }
  116. if (stBill.flag != 0)
  117. {
  118. rslt.ErrMsg = "该单据已处理,不能重复进行处理";
  119. return;
  120. }
  121. using (cmd.Transaction = con.BeginTransaction())
  122. {
  123. try
  124. {
  125. if (request.billInfo.flag == 2)
  126. {
  127. //撤销
  128. stBill = new st_bill
  129. {
  130. billid = request.billInfo.billid,
  131. flag = request.billInfo.flag,
  132. auditdate = DateTime.Now,
  133. auditemp = tokendata.username
  134. };
  135. DbSqlHelper.Update(cmd, stBill, "flag,auditdate,auditemp");
  136. }
  137. else
  138. {
  139. //处理保存
  140. stBill = new st_bill
  141. {
  142. billid = request.billInfo.billid,
  143. flag = request.billInfo.flag,
  144. auditdate = request.billInfo.auditdate,
  145. auditemp = tokendata.username,
  146. moddate = DateTime.Now,
  147. modemp = tokendata.username,
  148. roadid = request.billInfo.roadid,
  149. carnum = request.billInfo.carnum,
  150. dscrp = request.billInfo.dscrp,
  151. owner = request.billInfo.owner,
  152. owner_tel = request.billInfo.owner_tel,
  153. paytype = request.billInfo.paytype,
  154. payamt = request.billInfo.payamt
  155. };
  156. DbSqlHelper.Update(cmd, stBill,
  157. "flag,auditdate,auditemp,moddate,modemp,roadid,carnum,dscrp,owner,owner_tel,paytype,payamt");
  158. //保存图片
  159. //附件明细
  160. MD5 md5 = new MD5();
  161. var printid = 2;
  162. cmd.CommandText = @"SELECT MAX(printid) AS maxPrintid FROM st_bill_mx WHERE billid = @billid";
  163. cmd.Parameters.Clear();
  164. cmd.Parameters.AddWithValue("@billid", stBill.billid);
  165. using (var reader = cmd.ExecuteReader())
  166. {
  167. if (reader.Read())
  168. {
  169. var maxPrint = Convert.ToInt32(reader["maxPrintid"]);
  170. if (maxPrint > 2)
  171. {
  172. printid = maxPrint;
  173. }
  174. }
  175. }
  176. foreach (var file in request.billInfo.pictureList)
  177. {
  178. printid++;
  179. // 格式为data:image/jpeg;base64,AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  180. if (file.base64 == null || !file.base64.StartsWith("data"))
  181. {
  182. rslt.ErrMsg = "获取图片数据失败,请刷新后重试";
  183. return;
  184. }
  185. // 插入新附件
  186. var base64 = file.base64;
  187. var typeEndIndex = base64.IndexOf(";base64");
  188. if (typeEndIndex <= 0)
  189. {
  190. rslt.ErrMsg = "图片格式异常,请重新上传";
  191. return;
  192. }
  193. var fileData = Convert.FromBase64String(base64.Substring(typeEndIndex + 8));
  194. var filemd5 = md5.GetMD5(fileData);
  195. var filemap = new st_file { filemd5 = filemd5 };
  196. if (DbSqlHelper.SelectOne(cmd, filemap, "filemd5") != 1)
  197. {
  198. filemap.filedata = fileData;
  199. filemap.fileType = file.fileType;
  200. DbSqlHelper.Insert(cmd, filemap, "filemd5, filedata, fileType");
  201. }
  202. var billmx = new st_bill_mx
  203. {
  204. billid = stBill.billid,
  205. printid = printid,
  206. filemd5 = filemd5
  207. };
  208. DbSqlHelper.Insert(cmd, billmx, "billid,printid,filemd5");
  209. }
  210. }
  211. cmd.Transaction.Commit();
  212. }
  213. catch (Exception e)
  214. {
  215. cmd.Transaction.Rollback();
  216. rslt.ErrMsg = e.ToString();
  217. }
  218. }
  219. }
  220. }
  221. }
  222. }