CreatPrdPfExcutor.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Linq;
  7. using JLHHJSvr.BLL;
  8. using JLHHJSvr.Com;
  9. using JLHHJSvr.Com.Model;
  10. using JLHHJSvr.Helper;
  11. using JLHHJSvr.LJException;
  12. using LJLib.DAL.SQL;
  13. using LJLib.Net.SPI.Server;
  14. using LJLib.SQLEX;
  15. using Newtonsoft.Json.Linq;
  16. namespace JLHHJSvr.Excutor
  17. {
  18. internal sealed class CreatPrdPfExcutor : ExcutorBase<CreatPrdPfRequest, CreatPrdPfResponse>
  19. {
  20. Dictionary<string, object> replacements = new Dictionary<string, object>();
  21. protected override void ExcuteInternal(CreatPrdPfRequest request, object state, CreatPrdPfResponse rslt)
  22. {
  23. var tokendata = BllHelper.GetToken(request.token);
  24. if (request.list.Count <= 0)
  25. {
  26. rslt.ErrMsg = "床垫id参数为空!";
  27. return;
  28. }
  29. using (var con = GlobalVar.ConnectionString.NewSqlConnection())
  30. using (var cmd = con.CreateCommand())
  31. {
  32. con.Open();
  33. foreach (var mattressid in request.list)
  34. {
  35. if (LockHelper.CheckIsLock(cmd, MattressHelper.BillKeyWord, mattressid, tokendata.username, out string arg_msg)) throw new LJCommonException(arg_msg);
  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. //
  74. interfaceHelper.MattressInterfaceFindERPPrdPf(mattress_interface_qd_list, interfaceList);
  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. if (!string.IsNullOrEmpty(prdpf.wip_type)) prdpf.wip_type += $"|{mattress.erp_mtrlmode}";
  210. l1Req.prdPfs.Add(prdpf);
  211. i++;
  212. }
  213. l1Req.token = GlobalVar.ERP_TOKEN;
  214. var l1Helper = HelperBase.GetHelper<ERPHelper>(cmd);
  215. l1Helper.context = new HelperBase.Context() { tokendata = tokendata };
  216. l1Helper.CheckLogin();
  217. var l1Rslt = l1Helper.DoExecute("SavePrdPf", JObject.FromObject(l1Req));
  218. rslt.ErrMsg = $"{l1Rslt.GetValue("ErrMsg")}";
  219. if (string.IsNullOrEmpty(rslt.ErrMsg))
  220. {
  221. mattress.creatmtrlqd_flag = 1;
  222. mattress.creatmtrlqd_auditingdate = DateTime.Now;
  223. mattress.creatmtrlqd_auditingrep = tokendata.username;
  224. mattress.mattressid = mattressid;
  225. DbSqlHelper.Update(cmd, mattress, "creatmtrlqd_flag,creatmtrlqd_auditingdate,creatmtrlqd_auditingrep");
  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. }