CoverMattressInterfaceExcutor.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data.SqlClient;
  5. using System.Linq;
  6. using System.Text;
  7. using JLHHJSvr.BLL;
  8. using JLHHJSvr.Com;
  9. using JLHHJSvr.Com.Model;
  10. using JLHHJSvr.Helper;
  11. using JLHHJSvr.LJException;
  12. using JLHHJSvr.Tools;
  13. using LJLib.DAL.SQL;
  14. using LJLib.Net.SPI.Server;
  15. using NPOI.POIFS.Properties;
  16. using NPOI.SS.Formula.Functions;
  17. namespace JLHHJSvr.Excutor
  18. {
  19. internal sealed class CoverMattressInterfaceExcutor : ExcutorBase<CoverMattressInterfaceRequest, CoverMattressInterfaceResponse>
  20. {
  21. protected override void ExcuteInternal(CoverMattressInterfaceRequest request, object state, CoverMattressInterfaceResponse rslt)
  22. {
  23. var tokendata = BllHelper.GetToken(request.token);
  24. if (tokendata == null)
  25. {
  26. rslt.ErrMsg = "会话已经中断,请重新登录";
  27. return;
  28. }
  29. if (request.list == null)
  30. {
  31. rslt.ErrMsg = "提交缺少列表参数,请检查!";
  32. return;
  33. }
  34. if (!request.list.Any())
  35. {
  36. rslt.ErrMsg = "至少提交一条需要覆盖的记录";
  37. return;
  38. }
  39. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  40. using (var cmd = con.CreateCommand())
  41. {
  42. con.Open();
  43. var helper = HelperBase.GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
  44. var interfaceHelper = HelperBase.GetHelper<InterfaceHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
  45. var mainDict = new Dictionary<int, List<u_mattress_interface>> ();
  46. foreach(var mattress in request.list)
  47. {
  48. DbSqlHelper.SelectOne(cmd, mattress, "erp_configcodetype,parentid");
  49. if (!mainDict.ContainsKey(mattress.parentid.Value))
  50. {
  51. var interfacelist = new List<u_mattress_interface>();
  52. mainDict.Add(mattress.parentid.Value, interfacelist);
  53. // 获取主规格床垫的配置
  54. interfacelist = interfaceHelper.GetMattressInterfaceList(mattress.parentid.Value,0);
  55. }
  56. }
  57. using (cmd.Transaction = con.BeginTransaction())
  58. {
  59. try
  60. {
  61. foreach (var mattress in request.list)
  62. {
  63. var copy_list = new List<u_mattress_interface>();
  64. if (mainDict.TryGetValue(mattress.parentid.Value, out var parentlist))
  65. {
  66. // 获取副规格床垫的配置
  67. copy_list = interfaceHelper.GetMattressInterfaceList(mattress.mattressid, 0);
  68. var copyDict = parentlist.Where(mx2 => mx2.erp_pzid > 0)
  69. .ToDictionary(mx2 => mx2.erp_pzid, mx2 => mx2);
  70. bool isUpdate = DbSqlHelper.SelectCount(cmd, "u_mattress_interface", "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", mattress.mattressid } }) > 0;
  71. foreach (var mx in copy_list)
  72. {
  73. if (mx.bj_inputtype == null) mx.bj_inputtype = 0;
  74. if (mx.erp_pzid > 0 && copyDict.TryGetValue(mx.erp_pzid, out var mx2) && (mx.bj_inputtype == 1 || mx.bj_inputtype == 0))
  75. {
  76. mx.bj_namemx = mx2.bj_namemx;
  77. mx.bj_inputtype = mx2.bj_inputtype;
  78. }
  79. if(isUpdate)
  80. {
  81. DbSqlHelper.Update(cmd, mx, "bj_inputtype,bj_namemx");
  82. } else
  83. {
  84. DbSqlHelper.Insert(cmd, mx, "mattressid,printid,itemname,bj_pzname,bj_namemx,actual_size,sb_craft,actual_size_sb,erp_pzid,bj_inputtype,ss_rate,ls_rate");
  85. }
  86. }
  87. }
  88. }
  89. cmd.Transaction.Commit();
  90. }
  91. catch (Exception e)
  92. {
  93. cmd.Transaction.Rollback();
  94. rslt.ErrMsg = e.Message;
  95. }
  96. }
  97. }
  98. }
  99. }
  100. }