ReCalculateNoAuditExcutor.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using JLHHJSvr.BLL;
  7. using JLHHJSvr.Com;
  8. using JLHHJSvr.Com.Model;
  9. using JLHHJSvr.Helper;
  10. using JLHHJSvr.LJException;
  11. using JLHHJSvr.Tools;
  12. using LJLib.DAL.SQL;
  13. using LJLib.Net.SPI.Server;
  14. namespace JLHHJSvr.Excutor
  15. {
  16. internal sealed class ReCalculateNoAuditExcutor : ExcutorBase<ReCalculateNoAuditRequest, ReCalculateNoAuditResponse>
  17. {
  18. protected override void ExcuteInternal(ReCalculateNoAuditRequest request, object state, ReCalculateNoAuditResponse rslt)
  19. {
  20. var tokendata = BllHelper.GetToken(request.token);
  21. if (tokendata == null)
  22. {
  23. rslt.ErrMsg = "会话已经中断,请重新登录";
  24. return;
  25. }
  26. if (request.list == null)
  27. {
  28. rslt.ErrMsg = "提交缺少列表参数,请检查!";
  29. return;
  30. }
  31. if (!request.list.Any())
  32. {
  33. rslt.ErrMsg = "至少提交一条需要重算的记录";
  34. return;
  35. }
  36. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  37. using (var cmd = con.CreateCommand())
  38. {
  39. con.Open();
  40. var helper = HelperBase.GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
  41. foreach (var mattress in request.list)
  42. {
  43. DbSqlHelper.SelectOne(cmd, mattress, "flag,deptid");
  44. if (mattress.flag == 1) throw new LJCommonException("存在报价单已审核,不能重算!");
  45. if (mattress.deptid <= 0) throw new LJCommonException("存在报价单部门id错误,不能重算!");
  46. var dept = new u_dept() { deptid = mattress.deptid.Value };
  47. DbSqlHelper.SelectOne(cmd, dept, "pricelistid");
  48. if (dept.pricelistid <= 0) throw new LJCommonException("存在报价单部门pricelistid错误,不能重算!");
  49. }
  50. using (cmd.Transaction = con.BeginTransaction())
  51. {
  52. try
  53. {
  54. foreach(var mattress in request.list)
  55. {
  56. var mattress_temp = helper.GetMattress(mattress.mattressid);
  57. var mxList = helper.GetMattressMxMtrl(mattress.mattressid);
  58. helper.CalCulateFormula(mattress_temp, mxList);
  59. helper.SaveMattress(mattress_temp, mxList);
  60. }
  61. cmd.Transaction.Commit();
  62. }
  63. catch (Exception e)
  64. {
  65. cmd.Transaction.Rollback();
  66. rslt.ErrMsg = e.Message;
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }