SaveMattressInterfaceExcutor.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Text;
  7. using DirectService.Tools;
  8. using JLHHJSvr.BLL;
  9. using JLHHJSvr.Com;
  10. using JLHHJSvr.Com.Model;
  11. using JLHHJSvr.Helper;
  12. using JLHHJSvr.LJException;
  13. using JLHHJSvr.LJFramework.Tools;
  14. using JLHHJSvr.Tools;
  15. using LJLib.DAL.SQL;
  16. using LJLib.Net.SPI.Server;
  17. namespace JLHHJSvr.Excutor
  18. {
  19. internal sealed class SaveMattressInterfaceExcutor : ExcutorBase<SaveMattressInterfaceRequest, SaveMattressInterfaceResponse>
  20. {
  21. Dictionary<string, object> replacements = new Dictionary<string, object>();
  22. protected override void ExcuteInternal(SaveMattressInterfaceRequest request, object state, SaveMattressInterfaceResponse rslt)
  23. {
  24. var tokendata = BllHelper.GetToken(request.token);
  25. if (tokendata == null)
  26. {
  27. rslt.ErrMsg = "会话已经中断,请重新登录";
  28. return;
  29. }
  30. if (request.mattress == null)
  31. {
  32. rslt.ErrMsg = "缺少主表信息";
  33. return;
  34. }
  35. if (request.interfaceList == null || !request.interfaceList.Any())
  36. {
  37. rslt.ErrMsg = "缺少产品配置明细";
  38. return;
  39. }
  40. if (request.qdList == null || !request.qdList.Any())
  41. {
  42. rslt.ErrMsg = "缺少产品清单明细";
  43. return;
  44. }
  45. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  46. using (var cmd = con.CreateCommand())
  47. {
  48. con.Open();
  49. // 初始化属性
  50. AutoInit.AutoInitS(cmd, request.mattress);
  51. foreach (var mx in request.interfaceList)
  52. {
  53. AutoInit.AutoInitS(cmd, mx);
  54. }
  55. foreach (var mx in request.qdList)
  56. {
  57. AutoInit.AutoInitS(cmd, mx);
  58. }
  59. var interfaceHelper = HelperBase.GetHelper<InterfaceHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
  60. using (cmd.Transaction = con.BeginTransaction())
  61. {
  62. try
  63. {
  64. Trace.Write($"SaveMattressInterface={request.mattress.mattressid},mattressid={request.mattress.ToString()}");
  65. interfaceHelper.SaveMattressInterface(request.mattress, request.interfaceList, request.qdList);
  66. cmd.Transaction.Commit();
  67. }
  68. catch (Exception e)
  69. {
  70. cmd.Transaction.Rollback();
  71. rslt.ErrMsg = e.ToString();
  72. }
  73. }
  74. }
  75. }
  76. }
  77. }