AuditSpringExcutor.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using JLHHJSvr.BLL;
  6. using JLHHJSvr.Com;
  7. using JLHHJSvr.LJException;
  8. using LJLib.DAL.SQL;
  9. using LJLib.Net.SPI.Server;
  10. namespace JLHHJSvr.Excutor
  11. {
  12. internal sealed class AuditSpringExcutor : ExcutorBase<AuditSpringRequest, AuditSpringResponse>
  13. {
  14. protected override void ExcuteInternal(AuditSpringRequest request, object state, AuditSpringResponse rslt)
  15. {
  16. var tokendata = BllHelper.GetToken(request.token);
  17. if (tokendata == null)
  18. {
  19. rslt.ErrMsg = "会话已经中断,请重新登录";
  20. return;
  21. }
  22. if (!request.list.Any())
  23. {
  24. rslt.ErrMsg = "至少提交一条需要删除的记录";
  25. return;
  26. }
  27. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  28. using (var cmd = con.CreateCommand())
  29. {
  30. con.Open();
  31. var updateField = string.Empty;
  32. if(request.type < 2) // 审核
  33. {
  34. updateField = "flag";
  35. } else
  36. {
  37. updateField = "inuse";
  38. }
  39. foreach(var spring in request.list)
  40. {
  41. if(DbSqlHelper.SelectOne(cmd, spring, "flag,inuse") <= 0)
  42. {
  43. throw new LJCommonException("弹簧资料不存在或已审核,请检查!");
  44. }
  45. if(request.type == 0 && spring.flag == 1)
  46. {
  47. throw new LJCommonException("弹簧资料已审核,请检查!");
  48. }else if(request.type== 1 && spring.flag == 0)
  49. {
  50. throw new LJCommonException("弹簧资料未审核,请检查!");
  51. }else if(request.type == 2 && spring.inuse == 0)
  52. {
  53. throw new LJCommonException("弹簧资料未启用,请检查!");
  54. }else if(request.type == 3 && spring.inuse == 1)
  55. {
  56. throw new LJCommonException("弹簧资料已启用,请检查!");
  57. }
  58. }
  59. using (cmd.Transaction = con.BeginTransaction())
  60. {
  61. try
  62. {
  63. foreach (var spring in request.list)
  64. {
  65. switch(request.type)
  66. {
  67. case 0:
  68. spring.flag = 1;
  69. break;
  70. case 1:
  71. spring.flag = 0;
  72. break;
  73. case 2:
  74. spring.inuse = 0;
  75. break;
  76. case 3:
  77. spring.inuse = 1;
  78. break;
  79. }
  80. if (DbSqlHelper.Update(cmd, "u_spring", null, spring, "springid", updateField) <= 0)
  81. {
  82. throw new LJCommonException("弹簧资料更新失败!");
  83. }
  84. }
  85. cmd.Transaction.Commit();
  86. }
  87. catch (Exception e)
  88. {
  89. cmd.Transaction.Rollback();
  90. rslt.ErrMsg = e.ToString();
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }