AuditWorkmanshipExcutor.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 AuditWorkmanshipExcutor : ExcutorBase<AuditWorkmanshipRequest, AuditWorkmanshipResponse>
  13. {
  14. protected override void ExcuteInternal(AuditWorkmanshipRequest request, object state, AuditWorkmanshipResponse 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, "inuse") <= 0)
  43. {
  44. throw new LJCommonException("工艺加点设置不存在,请检查!");
  45. }
  46. if (request.type == 2 && item.inuse == 0)
  47. {
  48. throw new LJCommonException("工艺加点设置未禁用,请检查!");
  49. }
  50. else if (request.type == 3 && item.inuse == 1)
  51. {
  52. throw new LJCommonException("工艺加点设置已禁用,请检查!");
  53. }
  54. }
  55. using (cmd.Transaction = con.BeginTransaction())
  56. {
  57. try
  58. {
  59. foreach (var item in request.list)
  60. {
  61. switch (request.type)
  62. {
  63. case 2:
  64. item.inuse = 0;
  65. break;
  66. case 3:
  67. item.inuse = 1;
  68. break;
  69. }
  70. if (DbSqlHelper.Update(cmd, "u_workmanship_add", null, item, "workmanshipid", updateField) <= 0)
  71. {
  72. throw new LJCommonException("工艺加点设置更新失败!");
  73. }
  74. }
  75. cmd.Transaction.Commit();
  76. }
  77. catch (Exception e)
  78. {
  79. cmd.Transaction.Rollback();
  80. rslt.ErrMsg = e.ToString();
  81. }
  82. }
  83. }
  84. }
  85. }
  86. }