AuditDeptExcutor.cs 3.8 KB

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