RefreshMattressInterfaceQdExcutor.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.Com.Model;
  8. using JLHHJSvr.Helper;
  9. using JLHHJSvr.LJException;
  10. using LJLib.DAL.SQL;
  11. using LJLib.Net.SPI.Server;
  12. namespace JLHHJSvr.Excutor
  13. {
  14. internal sealed class RefreshMattressInterfaceQdExcutor : ExcutorBase<RefreshMattressInterfaceQdRequest, RefreshMattressInterfaceQdResponse>
  15. {
  16. protected override void ExcuteInternal(RefreshMattressInterfaceQdRequest request, object state, RefreshMattressInterfaceQdResponse rslt)
  17. {
  18. var tokendata = BllHelper.GetToken(request.token);
  19. if (tokendata == null)
  20. {
  21. rslt.ErrMsg = "会话已经中断,请重新登录";
  22. return;
  23. }
  24. if (request.mattressid == null || request.mattressid <= 0)
  25. {
  26. rslt.ErrMsg = "床垫id有误,请检查!";
  27. return;
  28. }
  29. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  30. using (var cmd = con.CreateCommand())
  31. {
  32. con.Open();
  33. var mattress = new u_mattress() { mattressid = request.mattressid.Value };
  34. DbSqlHelper.SelectOne(cmd, mattress, "js2_flag");
  35. if (request.isCheck == 1 && mattress.js2_flag == 1)
  36. {
  37. throw new LJCommonException("床垫已技术2审核,不能重新生成!");
  38. }
  39. var copy_list = new List<u_mattress_interface_qd>();
  40. var selectStr = @"SELECT u_mattress_interface_qd.mattressid
  41. ,u_mattress_interface_qd.printid
  42. ,u_mattress_interface_qd.itemname
  43. ,u_mattress_interface_qd.bj_pzname
  44. ,u_mattress_interface_qd.bj_pzname_mx
  45. ,u_mattress_interface_qd.bj_pzname_mx_mx
  46. ,u_mattress_interface_qd.mtrlid
  47. ,u_mattress_interface_qd.erp_mtrlid
  48. ,u_mattress_interface_qd.useqty
  49. ,u_mattress_interface_qd.dscrp
  50. ,u_mtrl_price.name AS mtrlname
  51. ,u_mattress_interface_qd.actual_useqty
  52. ,u_mattress_interface_qd.qd_actual_size
  53. ,u_mattress_interface_qd.qd_pfgroupqty
  54. ,u_mattress_interface_qd.wrkgrpid
  55. ,u_mattress_interface_qd.ss_rate
  56. ,u_mattress_interface_qd.ls_rate
  57. ,u_mattress_interface_qd.sh_rate
  58. ,ISNULL(u_mattress_interface_qd.formulaid, 0) AS formulaid
  59. FROM u_mattress_interface_qd
  60. LEFT JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mattress_interface_qd.mtrlid";
  61. var outputFields = "mattressid,printid,itemname,bj_pzname,bj_pzname_mx,bj_pzname_mx_mx,mtrlid,erp_mtrlid,useqty,dscrp,mtrlname,actual_useqty,qd_actual_size,qd_pfgroupqty,wrkgrpid,ss_rate,ls_rate,sh_rate,formulaid";
  62. DbSqlHelper.SelectJoin(cmd, selectStr, "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", request.mattressid } }, "printid", outputFields, 0, 0, copy_list);
  63. var interfaceHelper = HelperBase.GetHelper<InterfaceHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
  64. var qdList = interfaceHelper.RefreshMattressInterfaceQdList(request.mattressid.Value);
  65. if (request.isPz != null && request.isPz == 1)
  66. {
  67. var copyDict = new Dictionary<Tuple<string, string, string>, u_mattress_interface_qd>();
  68. foreach (var mx2 in copy_list)
  69. {
  70. var key = Tuple.Create(mx2.itemname, mx2.bj_pzname, mx2.bj_pzname_mx);
  71. if (!copyDict.ContainsKey(key))
  72. {
  73. copyDict[key] = mx2;
  74. }
  75. }
  76. // 遍历qdList
  77. foreach (var mx in qdList)
  78. {
  79. var key = Tuple.Create(mx.itemname, mx.bj_pzname, mx.bj_pzname_mx); // 创建复合键
  80. if (copyDict.TryGetValue(key, out var mx2)) // 高效查找对应的mx2
  81. {
  82. // 更新mx属性
  83. mx.erp_mtrlid = mx2.erp_mtrlid;
  84. mx.erp_mtrlcode = mx2.erp_mtrlcode;
  85. mx.erp_mtrlname = mx2.erp_mtrlname;
  86. mx.erp_mtrlmode = mx2.erp_mtrlmode;
  87. mx.erp_unit = mx2.erp_unit;
  88. mx.useqty = mx2.useqty;
  89. mx.actual_useqty = mx2.actual_useqty;
  90. mx.wrkgrpid = mx2.wrkgrpid;
  91. mx.qd_actual_size = mx2.qd_actual_size;
  92. mx.qd_pfgroupqty = mx2.qd_pfgroupqty;
  93. mx.dscrp = mx2.dscrp;
  94. }
  95. }
  96. }
  97. interfaceHelper.MattressInterfaceFindERPPrdPf(qdList);
  98. rslt.mxList = qdList;
  99. }
  100. }
  101. }
  102. }