CreatPrdPfExcutor.cs 14 KB

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