AuditWorkmanshipExcutor.cs 3.2 KB

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