AuditSpringExcutor.cs 3.7 KB

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