AuditDeptExcutor.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 AuditDeptExcutor : ExcutorBase<AuditDeptRequest, AuditDeptResponse>
  14. {
  15. protected override void ExcuteInternal(AuditDeptRequest request, object state, AuditDeptResponse 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. }
  37. else
  38. {
  39. updateField = "inuse";
  40. }
  41. foreach (var item in request.list)
  42. {
  43. if (DbSqlHelper.SelectOne(cmd, item, "flag,inuse") <= 0)
  44. {
  45. throw new LJCommonException("部门不存在或已审核,请检查!");
  46. }
  47. if (request.type == 0 && item.flag == 1)
  48. {
  49. throw new LJCommonException("部门已审核,请检查!");
  50. }
  51. else if (request.type == 1 && item.flag == 0)
  52. {
  53. throw new LJCommonException("部门未审核,请检查!");
  54. }
  55. else if (request.type == 2 && item.inuse == 0)
  56. {
  57. throw new LJCommonException("部门未禁用,请检查!");
  58. }
  59. else if (request.type == 3 && item.inuse == 1)
  60. {
  61. throw new LJCommonException("部门已禁用,请检查!");
  62. }
  63. }
  64. using (cmd.Transaction = con.BeginTransaction())
  65. {
  66. try
  67. {
  68. foreach (var item in request.list)
  69. {
  70. switch (request.type)
  71. {
  72. case 0:
  73. item.flag = 1;
  74. break;
  75. case 1:
  76. item.flag = 0;
  77. break;
  78. case 2:
  79. item.inuse = 0;
  80. break;
  81. case 3:
  82. item.inuse = 1;
  83. break;
  84. }
  85. if (DbSqlHelper.Update(cmd, "u_dept", null, item, "deptid", updateField) <= 0)
  86. {
  87. throw new LJCommonException("部门更新失败!");
  88. }
  89. }
  90. cmd.Transaction.Commit();
  91. }
  92. catch (Exception e)
  93. {
  94. cmd.Transaction.Rollback();
  95. rslt.ErrMsg = e.ToString();
  96. }
  97. }
  98. }
  99. }
  100. }
  101. }