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