CreatPrdPfExcutor.cs 14 KB

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