CreatPrdPfExcutor.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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. var bcpDscrp = new Dictionary<string, string> { };
  97. foreach (var mx in mattress_interface_qd_list)
  98. {
  99. if (!string.IsNullOrEmpty(mx.wip_type) && !string.IsNullOrEmpty(mx.bj_pzname_mx_mx) && !bcpNames.ContainsKey(mx.wip_type))
  100. {
  101. var _name = mx.bj_pzname_mx_mx;
  102. var interfaceL = interfaceList.Where(o => _name == o.bj_namemx && mx.bj_pzname == o.bj_pzname).ToList();
  103. if (interfaceL.Count > 0)
  104. {
  105. _name = interfaceL[0].bj_namemx;
  106. if (!string.IsNullOrEmpty(interfaceL[0].actual_size)) _name += " + " + interfaceL[0].actual_size;
  107. if (!string.IsNullOrEmpty(interfaceL[0].sb_craft)) _name += " + " + interfaceL[0].sb_craft;
  108. if (!string.IsNullOrEmpty(interfaceL[0].actual_size_sb)) _name += " + " + interfaceL[0].actual_size_sb;
  109. if (interfaceL[0].ss_rate != null && interfaceL[0].ss_rate > 0) _name += " + " + interfaceL[0].ss_rate;
  110. if (interfaceL[0].ls_rate != null && interfaceL[0].ls_rate > 0) _name += " + " + interfaceL[0].ls_rate;
  111. }
  112. bcpNames.Add(mx.wip_type, _name);
  113. bcpDscrp.Add(mx.wip_type, mx.bj_pzname_mx_mx);
  114. }
  115. }
  116. var i = 0;
  117. foreach (var mx in mattress_interface_qd_list)
  118. {
  119. var ls_temp_pfgroup = mx.itemname + '-' + mx.bj_pzname;
  120. var ll_cnt_temp = 0;
  121. for (var j = 0; j < i - 1; j++)
  122. {
  123. if (ls_temp_pfgroup == mattress_interface_qd_list[j].itemname + '-' + mattress_interface_qd_list[j].bj_pzname)
  124. {
  125. ll_cnt_temp++;
  126. }
  127. }
  128. if (ll_cnt_temp > 0)
  129. {
  130. ls_temp_pfgroup = ls_temp_pfgroup + (ll_cnt_temp).ToString();
  131. }
  132. var _name = mx.bj_pzname_mx_mx;
  133. if (!string.IsNullOrEmpty(mx.wip_type) && bcpNames.ContainsKey(mx.wip_type) && !string.IsNullOrEmpty(bcpNames[mx.wip_type]))
  134. {
  135. _name = bcpNames[mx.wip_type];
  136. }
  137. var _dscrp = mx.bj_pzname_mx_mx;
  138. if (!string.IsNullOrEmpty(mx.wip_type) && bcpDscrp.ContainsKey(mx.wip_type) && !string.IsNullOrEmpty(bcpDscrp[mx.wip_type]))
  139. {
  140. _dscrp = bcpDscrp[mx.wip_type];
  141. }
  142. string ls_azcode = i.ToString("D3");
  143. var prdpf = new u_PrdPF()
  144. {
  145. mtrlid = mattress.erp_mtrlid.Value,
  146. pfcode = pfcode,
  147. pfgroup = ls_temp_pfgroup,
  148. SonMtrlid = mx.erp_mtrlid,
  149. wrkgrpid = mx.wrkgrpid,
  150. wrkgrpcode1 = mx.wrkgrpcode1,
  151. wrkgrpcode2 = mx.wrkgrpcode2,
  152. sonpfcode = "[常规]",
  153. dscrp = _dscrp,
  154. pfgroupqty = mx.qd_pfgroupqty,
  155. Sonscale = mx.actual_useqty,
  156. pfklmode = mx.qd_actual_size,
  157. printid = mx.printid,
  158. azcode = ls_azcode,
  159. promode = mx.ss_rate.ToString(),
  160. SonLoss = mx.sh_rate,
  161. SonDECLosS = 0,
  162. wip_name = _name,
  163. wip_type = mx.wip_type
  164. };
  165. l1Req.prdPfs.Add(prdpf);
  166. i++;
  167. }
  168. l1Req.token = GlobalVar.ERP_TOKEN;
  169. var l1Helper = HelperBase.GetHelper<ERPHelper>(cmd);
  170. l1Helper.context = new HelperBase.Context() { tokendata = tokendata };
  171. l1Helper.CheckLogin();
  172. var l1Rslt = l1Helper.DoExecute("SavePrdPf", JObject.FromObject(l1Req));
  173. rslt.ErrMsg = $"{l1Rslt.GetValue("ErrMsg")}";
  174. if (!string.IsNullOrEmpty(rslt.ErrMsg))
  175. {
  176. mattress.creatmtrlqd_flag = 1;
  177. mattress.mattressid = mattressid;
  178. DbSqlHelper.Update(cmd, mattress, "creatmtrlqd_flag");
  179. }
  180. }
  181. }
  182. }
  183. /// <summary>
  184. /// 保存物料清单请求参数,没有传入的参数按默认值
  185. /// </summary>
  186. private class SavePrdPfRequest
  187. {
  188. public string token { get; set; }
  189. /// <summary>
  190. /// 物料清单主表 mtrlid,pfcode,flag,affirmflag,Ifdft,inuse,wrkid
  191. /// </summary>
  192. public u_mtrl_pf mtrl_pf { get; set; }
  193. /// <summary>
  194. /// 物料清单明细表 mtrlid,pfcode,sonmtrlid,printid,wrkgrpid,sonpfcode,Sonscale,sonloss,sondecloss
  195. /// pfgroup,dscrp,pfgroupqty,pfklmode,azcode,promode
  196. /// </summary>
  197. public List<u_PrdPF> prdPfs { get; set; }
  198. }
  199. }
  200. }