EditBillExcutor.cs 9.6 KB

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