CreatPrdPfExcutor.cs 13 KB

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