CreatPrdPfExcutor.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. ,ISNULL('[>0,<=5]={' + left(cast(u_mtrltype.dannum1_rate as char(10)),4) + '};[>5,<=10]={'+ + '[>0,<=100]={' + left(cast(u_mtrltype.dannum4_rate as char(10)),4) + '};[>10,<=200]={' + left(cast(u_mtrltype.dannum2_rate as char(10)),4) + '};[>200]={' + left(cast(u_mtrltype.dannum3_rate as char(10)),4) + '};', '') AS sonLossstr
  66. FROM u_mattress_interface_qd
  67. LEFT JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mattress_interface_qd.mtrlid
  68. LEFT JOIN u_mtrltype ON u_mtrltype.mtrltypeid = u_mtrl_price.mtrltype";
  69. 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,sonLossstr";
  70. DbSqlHelper.SelectJoin(cmd, selectStr, "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", mattressid } }, "printid", outputFields, 0, 0, mattress_interface_qd_list);
  71. var interfaceHelper = HelperBase.GetHelper<InterfaceHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
  72. var interfaceList = interfaceHelper.GetMattressInterfaceList(mattressid, 0);
  73. var ll_temp_dftwrkgrpid = 0;
  74. // var ErpMtrl = new erp_mtrldef() { mtrlid = mattress.erp_mtrlid };
  75. // if (DbSqlHelper.SelectOne(erp_cmd, ErpMtrl, "dftwrkgrpid") == 1)
  76. // {
  77. // ll_temp_dftwrkgrpid = ErpMtrl.dftwrkgrpid.Value;
  78. // }
  79. var pfcode = $"{mattress.erp_mtrlcode}_V2.0";
  80. var l1Req = new SavePrdPfRequest()
  81. {
  82. mtrl_pf = new u_mtrl_pf()
  83. {
  84. mtrlid = mattress.erp_mtrlid.Value,
  85. pfcode = pfcode,
  86. ifdft = 1,
  87. inuse = 1,
  88. opemp = tokendata.usercode,
  89. opdate = DateTime.Now,
  90. flag = 1,
  91. auditdate = DateTime.Now,
  92. auditemp = tokendata.usercode,
  93. wrkid = ll_temp_dftwrkgrpid
  94. },
  95. prdPfs = new List<u_PrdPF>()
  96. };
  97. var bcpNames = new Dictionary<string, string> { };
  98. var bcpDscrp = new Dictionary<string, string> { };
  99. // 上下、左右拼侧
  100. var bcpJoinNames = new Dictionary<string, string> { };
  101. var bcpJoinDscrp = new Dictionary<string, string> { };
  102. foreach (var mx in mattress_interface_qd_list)
  103. {
  104. var _name = mx.bj_pzname_mx_mx;
  105. var interfaceL = interfaceList.Where(o => _name == o.bj_namemx && mx.bj_pzname == o.bj_pzname).ToList();
  106. if (interfaceL.Count > 0)
  107. {
  108. _name = interfaceL[0].bj_namemx;
  109. if (!string.IsNullOrEmpty(interfaceL[0].actual_size)) _name += " + " + interfaceL[0].actual_size;
  110. if (!string.IsNullOrEmpty(interfaceL[0].sb_craft)) _name += " + " + interfaceL[0].sb_craft;
  111. if (!string.IsNullOrEmpty(interfaceL[0].actual_size_sb)) _name += " + " + interfaceL[0].actual_size_sb;
  112. if (interfaceL[0].ss_rate != null && interfaceL[0].ss_rate > 0) _name += " + " + interfaceL[0].ss_rate;
  113. if (interfaceL[0].ls_rate != null && interfaceL[0].ls_rate > 0) _name += " + " + interfaceL[0].ls_rate;
  114. }
  115. if (mx.bj_pzname.Contains("上下") || mx.bj_pzname.Contains("左右"))
  116. {
  117. if (!string.IsNullOrEmpty(mx.wip_type) && !string.IsNullOrEmpty(mx.bj_pzname_mx_mx) && !bcpJoinNames.ContainsKey(mx.wip_type + "&" + mx.bj_pzname))
  118. {
  119. bcpJoinNames.Add(mx.wip_type + "&" + mx.bj_pzname, _name);
  120. bcpJoinDscrp.Add(mx.wip_type + "&" + mx.bj_pzname, mx.bj_pzname_mx_mx);
  121. }
  122. }
  123. if (!string.IsNullOrEmpty(mx.wip_type) && !string.IsNullOrEmpty(mx.bj_pzname_mx_mx) && !bcpNames.ContainsKey(mx.wip_type))
  124. {
  125. bcpNames.Add(mx.wip_type, _name);
  126. bcpDscrp.Add(mx.wip_type, mx.bj_pzname_mx_mx);
  127. }
  128. }
  129. var i = 0;
  130. foreach (var mx in mattress_interface_qd_list)
  131. {
  132. var ls_temp_pfgroup = mx.itemname + '-' + mx.bj_pzname;
  133. var ll_cnt_temp = 0;
  134. for (var j = 0; j < i - 1; j++)
  135. {
  136. if (ls_temp_pfgroup == mattress_interface_qd_list[j].itemname + '-' + mattress_interface_qd_list[j].bj_pzname)
  137. {
  138. ll_cnt_temp++;
  139. }
  140. }
  141. if (ll_cnt_temp > 0)
  142. {
  143. ls_temp_pfgroup = ls_temp_pfgroup + (ll_cnt_temp).ToString();
  144. }
  145. var _name = mx.bj_pzname_mx_mx;
  146. if (!string.IsNullOrEmpty(mx.wip_type) && bcpNames.ContainsKey(mx.wip_type) && !string.IsNullOrEmpty(bcpNames[mx.wip_type]))
  147. {
  148. _name = bcpNames[mx.wip_type];
  149. List<string> _nameBjArr = new List<string> { };
  150. foreach(var bJitem in bcpJoinNames)
  151. {
  152. string[] bNames = bJitem.Key.Split('&');
  153. if (bNames[0] == mx.wip_type)
  154. {
  155. _nameBjArr.Add(bJitem.Value);
  156. }
  157. }
  158. if (_nameBjArr.Count > 0)
  159. {
  160. _name = string.Join(" + ", _nameBjArr);
  161. }
  162. }
  163. var _dscrp = mx.bj_pzname_mx_mx;
  164. if (!string.IsNullOrEmpty(mx.wip_type) && bcpDscrp.ContainsKey(mx.wip_type) && !string.IsNullOrEmpty(bcpDscrp[mx.wip_type]))
  165. {
  166. _dscrp = bcpDscrp[mx.wip_type];
  167. foreach (var bJitem in bcpJoinDscrp)
  168. {
  169. string[] bNames = bJitem.Key.Split('&');
  170. if (bNames[0] == mx.wip_type && bNames[1] == mx.bj_pzname)
  171. {
  172. _dscrp = bJitem.Value;
  173. break;
  174. }
  175. }
  176. }
  177. string ls_azcode = i.ToString("D3");
  178. var prdpf = new u_PrdPF()
  179. {
  180. mtrlid = mattress.erp_mtrlid.Value,
  181. pfcode = pfcode,
  182. pfgroup = ls_temp_pfgroup,
  183. SonMtrlid = mx.erp_mtrlid,
  184. wrkgrpid = mx.wrkgrpid,
  185. wrkgrpcode1 = mx.wrkgrpcode1,
  186. wrkgrpcode2 = mx.wrkgrpcode2,
  187. sonpfcode = "[常规]",
  188. dscrp = _dscrp,
  189. pfgroupqty = mx.qd_pfgroupqty,
  190. Sonscale = mx.actual_useqty,
  191. pfklmode = mx.qd_actual_size,
  192. printid = mx.printid,
  193. azcode = ls_azcode,
  194. promode = mx.ss_rate.ToString(),
  195. SonLossstr = mx.sonLossstr,
  196. SonLoss = mx.sh_rate,
  197. SonDECLosS = 0,
  198. wip_name = _name,
  199. wip_type = mx.wip_type
  200. };
  201. l1Req.prdPfs.Add(prdpf);
  202. i++;
  203. }
  204. l1Req.token = GlobalVar.ERP_TOKEN;
  205. var l1Helper = HelperBase.GetHelper<ERPHelper>(cmd);
  206. l1Helper.context = new HelperBase.Context() { tokendata = tokendata };
  207. l1Helper.CheckLogin();
  208. var l1Rslt = l1Helper.DoExecute("SavePrdPf", JObject.FromObject(l1Req));
  209. rslt.ErrMsg = $"{l1Rslt.GetValue("ErrMsg")}";
  210. if (string.IsNullOrEmpty(rslt.ErrMsg))
  211. {
  212. mattress.creatmtrlqd_flag = 1;
  213. mattress.mattressid = mattressid;
  214. DbSqlHelper.Update(cmd, mattress, "creatmtrlqd_flag");
  215. }
  216. }
  217. }
  218. }
  219. /// <summary>
  220. /// 保存物料清单请求参数,没有传入的参数按默认值
  221. /// </summary>
  222. private class SavePrdPfRequest
  223. {
  224. public string token { get; set; }
  225. /// <summary>
  226. /// 物料清单主表 mtrlid,pfcode,flag,affirmflag,Ifdft,inuse,wrkid
  227. /// </summary>
  228. public u_mtrl_pf mtrl_pf { get; set; }
  229. /// <summary>
  230. /// 物料清单明细表 mtrlid,pfcode,sonmtrlid,printid,wrkgrpid,sonpfcode,Sonscale,sonloss,sondecloss
  231. /// pfgroup,dscrp,pfgroupqty,pfklmode,azcode,promode
  232. /// </summary>
  233. public List<u_PrdPF> prdPfs { get; set; }
  234. }
  235. }
  236. }