CreatPrdPfExcutor.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 LJLib.DAL.SQL;
  10. using LJLib.Net.SPI.Server;
  11. using Newtonsoft.Json.Linq;
  12. namespace JLHHJSvr.Excutor
  13. {
  14. internal sealed class CreatPrdPfExcutor : ExcutorBase<CreatPrdPfRequest, CreatPrdPfResponse>
  15. {
  16. Dictionary<string, object> replacements = new Dictionary<string, object>();
  17. protected override void ExcuteInternal(CreatPrdPfRequest request, object state, CreatPrdPfResponse rslt)
  18. {
  19. var tokendata = BllHelper.GetToken(request.token);
  20. if (tokendata == null)
  21. {
  22. rslt.ErrMsg = "会话已经中断,请重新登录";
  23. return;
  24. }
  25. if (request.list.Count <= 0)
  26. {
  27. rslt.ErrMsg = "床垫id参数为空!";
  28. return;
  29. }
  30. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  31. using (var cmd = con.CreateCommand())
  32. {
  33. con.Open();
  34. foreach (var mattressid in request.list)
  35. {
  36. var mattress = new u_mattress();
  37. if (DbSqlHelper.SelectOne(cmd, "u_mattress", "mattressid = @mattressid", new Dictionary<string, object>() { { "mattressid", mattressid } }, mattress, "erp_mtrlid,erp_mtrlcode, erp_mtrlname, erp_mtrlmode, erp_mtrltypeid, erp_mtrltype, erp_mtrlunit, erp_mtrlengname,nottax_factory_cost,dept_profitrate,dept_profitrate_rangli,commission,taxes,fob,extras_cost,mattresstypeid,erp_configcodetype") != 1)
  38. {
  39. rslt.ErrMsg = "床垫报价单匹配失败";
  40. return;
  41. }
  42. var mattress_interface_qd_list = new List<u_mattress_interface_qd>();
  43. var selectStr = @"SELECT u_mattress_interface_qd.mattressid
  44. ,u_mattress_interface_qd.printid
  45. ,u_mattress_interface_qd.itemname
  46. ,u_mattress_interface_qd.bj_pzname
  47. ,u_mattress_interface_qd.bj_pzname_mx
  48. ,u_mattress_interface_qd.bj_pzname_mx_mx
  49. ,u_mattress_interface_qd.wip_type
  50. ,u_mattress_interface_qd.mtrlid
  51. ,u_mattress_interface_qd.erp_mtrlid
  52. ,u_mattress_interface_qd.useqty
  53. ,u_mattress_interface_qd.dscrp
  54. ,u_mtrl_price.name AS mtrlname
  55. ,u_mattress_interface_qd.actual_useqty
  56. ,u_mattress_interface_qd.qd_actual_size
  57. ,u_mattress_interface_qd.qd_pfgroupqty
  58. ,u_mattress_interface_qd.wrkgrpid
  59. ,u_mattress_interface_qd.wrkgrpid2
  60. ,u_mattress_interface_qd.wrkgrpcode1
  61. ,u_mattress_interface_qd.wrkgrpcode2
  62. ,u_mattress_interface_qd.ss_rate
  63. ,u_mattress_interface_qd.ls_rate
  64. ,u_mattress_interface_qd.sh_rate
  65. FROM u_mattress_interface_qd
  66. LEFT JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mattress_interface_qd.mtrlid";
  67. var outputFields = "mattressid,printid,itemname,bj_pzname,bj_pzname_mx,bj_pzname_mx_mx,wip_type,mtrlid,erp_mtrlid,useqty,dscrp,mtrlname,actual_useqty,qd_actual_size,qd_pfgroupqty,wrkgrpid,wrkgrpid2,ss_rate,ls_rate,sh_rate,wrkgrpcode1,wrkgrpcode2";
  68. DbSqlHelper.SelectJoin(cmd, selectStr, "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", mattressid } }, "printid", outputFields, 0, 0, mattress_interface_qd_list);
  69. var interfaceHelper = HelperBase.GetHelper<InterfaceHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
  70. var interfaceList = interfaceHelper.GetMattressInterfaceList(mattressid, 0);
  71. var ll_temp_dftwrkgrpid = 0;
  72. // var ErpMtrl = new erp_mtrldef() { mtrlid = mattress.erp_mtrlid };
  73. // if (DbSqlHelper.SelectOne(erp_cmd, ErpMtrl, "dftwrkgrpid") == 1)
  74. // {
  75. // ll_temp_dftwrkgrpid = ErpMtrl.dftwrkgrpid.Value;
  76. // }
  77. var pfcode = $"{mattress.erp_mtrlcode}_V2.0";
  78. var l1Req = new SavePrdPfRequest()
  79. {
  80. mtrl_pf = new u_mtrl_pf()
  81. {
  82. mtrlid = mattress.erp_mtrlid.Value,
  83. pfcode = pfcode,
  84. ifdft = 1,
  85. inuse = 1,
  86. opemp = tokendata.usercode,
  87. opdate = DateTime.Now,
  88. flag = 1,
  89. auditdate = DateTime.Now,
  90. auditemp = tokendata.usercode,
  91. wrkid = ll_temp_dftwrkgrpid
  92. },
  93. prdPfs = new List<u_PrdPF>()
  94. };
  95. var bcpNames = new Dictionary<string, string> { };
  96. foreach (var mx in mattress_interface_qd_list)
  97. {
  98. if (!string.IsNullOrEmpty(mx.wip_type) && !string.IsNullOrEmpty(mx.bj_pzname_mx_mx) && mx.bj_pzname_mx_mx.Contains(" + ") && !bcpNames.ContainsKey(mx.wip_type))
  99. {
  100. bcpNames.Add(mx.wip_type, mx.bj_pzname_mx_mx);
  101. }
  102. }
  103. var i = 0;
  104. foreach (var mx in mattress_interface_qd_list)
  105. {
  106. var ls_temp_pfgroup = mx.itemname + '-' + mx.bj_pzname;
  107. var ll_cnt_temp = 0;
  108. for (var j = 0; j < i - 1; j++)
  109. {
  110. if (ls_temp_pfgroup == mattress_interface_qd_list[j].itemname + '-' + mattress_interface_qd_list[j].bj_pzname)
  111. {
  112. ll_cnt_temp++;
  113. }
  114. }
  115. if (ll_cnt_temp > 0)
  116. {
  117. ls_temp_pfgroup = ls_temp_pfgroup + (ll_cnt_temp).ToString();
  118. }
  119. var _dscrp = mx.bj_pzname_mx_mx;
  120. var interfaceL = interfaceList.Where(o => mx.bj_pzname_mx_mx == o.bj_namemx).ToList();
  121. if (interfaceL.Count > 0)
  122. {
  123. var item = interfaceL[0];
  124. _dscrp = item.bj_namemx;
  125. if (!string.IsNullOrEmpty(item.actual_size)) _dscrp += " + " + item.actual_size;
  126. if (!string.IsNullOrEmpty(item.sb_craft)) _dscrp += " + " + item.sb_craft;
  127. if (!string.IsNullOrEmpty(item.actual_size_sb)) _dscrp += " + " + item.actual_size_sb;
  128. if (item.ss_rate != null && item.ss_rate > 0) _dscrp += " + " + item.ss_rate;
  129. if (item.ls_rate != null && item.ls_rate > 0) _dscrp += " + " + item.ls_rate;
  130. }
  131. if (!string.IsNullOrEmpty(mx.wip_type) && !string.IsNullOrEmpty(bcpNames[mx.wip_type]))
  132. {
  133. _dscrp = bcpNames[mx.wip_type];
  134. }
  135. string ls_azcode = i.ToString("D3");
  136. var prdpf = new u_PrdPF()
  137. {
  138. mtrlid = mattress.erp_mtrlid.Value,
  139. pfcode = pfcode,
  140. pfgroup = ls_temp_pfgroup,
  141. SonMtrlid = mx.erp_mtrlid,
  142. wrkgrpid = mx.wrkgrpid,
  143. wrkgrpcode1 = mx.wrkgrpcode1,
  144. wrkgrpcode2 = mx.wrkgrpcode2,
  145. sonpfcode = "[常规]",
  146. dscrp = _dscrp,
  147. pfgroupqty = mx.qd_pfgroupqty,
  148. Sonscale = mx.actual_useqty,
  149. pfklmode = mx.qd_actual_size,
  150. printid = mx.printid,
  151. azcode = ls_azcode,
  152. promode = mx.ss_rate.ToString(),
  153. SonLoss = mx.sh_rate,
  154. SonDECLosS = 0,
  155. wip_type = mx.wip_type
  156. };
  157. l1Req.prdPfs.Add(prdpf);
  158. i++;
  159. }
  160. l1Req.token = GlobalVar.ERP_TOKEN;
  161. var l1Helper = HelperBase.GetHelper<ERPHelper>(cmd);
  162. l1Helper.context = new HelperBase.Context() { tokendata = tokendata };
  163. l1Helper.CheckLogin();
  164. var l1Rslt = l1Helper.DoExecute("SavePrdPf", JObject.FromObject(l1Req));
  165. rslt.ErrMsg = $"{l1Rslt.GetValue("ErrMsg")}";
  166. if (!string.IsNullOrEmpty(rslt.ErrMsg))
  167. {
  168. mattress.creatmtrlqd_flag = 1;
  169. mattress.mattressid = mattressid;
  170. DbSqlHelper.Update(cmd, mattress, "creatmtrlqd_flag");
  171. }
  172. }
  173. }
  174. }
  175. /// <summary>
  176. /// 保存物料清单请求参数,没有传入的参数按默认值
  177. /// </summary>
  178. private class SavePrdPfRequest
  179. {
  180. public string token { get; set; }
  181. /// <summary>
  182. /// 物料清单主表 mtrlid,pfcode,flag,affirmflag,Ifdft,inuse,wrkid
  183. /// </summary>
  184. public u_mtrl_pf mtrl_pf { get; set; }
  185. /// <summary>
  186. /// 物料清单明细表 mtrlid,pfcode,sonmtrlid,printid,wrkgrpid,sonpfcode,Sonscale,sonloss,sondecloss
  187. /// pfgroup,dscrp,pfgroupqty,pfklmode,azcode,promode
  188. /// </summary>
  189. public List<u_PrdPF> prdPfs { get; set; }
  190. }
  191. }
  192. }