InterfaceHelper.cs 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025
  1. using DirectService.Tools;
  2. using JLHHJSvr.BLL;
  3. using JLHHJSvr.Com;
  4. using JLHHJSvr.Com.Model;
  5. using JLHHJSvr.LJException;
  6. using JLHHJSvr.Tools;
  7. using LJLib.DAL.SQL;
  8. using Microsoft.SqlServer.Server;
  9. using Newtonsoft.Json.Linq;
  10. using NPOI.SS.Formula.Functions;
  11. using System;
  12. using System.Collections;
  13. using System.Collections.Generic;
  14. using System.Data.SqlClient;
  15. using System.Diagnostics;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Text.RegularExpressions;
  19. using System.Threading.Tasks;
  20. using System.Web;
  21. using System.Xml.Linq;
  22. namespace JLHHJSvr.Helper
  23. {
  24. internal class InterfaceHelper : HelperBase
  25. {
  26. /// <summary>
  27. /// 床垫接口-保存
  28. /// </summary>
  29. /// <param name="mattress"></param>
  30. /// <param name="mxlist"></param>
  31. /// <param name="qdlist"></param>
  32. /// <exception cref="LJCommonException"></exception>
  33. public void SaveMattressInterface(u_mattress mattress, List<u_mattress_interface> mxlist, List<u_mattress_interface_qd> qdlist)
  34. {
  35. if (mattress.mattressid <= 0)
  36. {
  37. throw new LJCommonException("错误的床垫id");
  38. }
  39. DbSqlHelper.Update(cmd, mattress, "erp_mtrlid,erp_mtrltypeid,erp_mtrlcode,erp_mtrlname,erp_mtrlmode,erp_mtrltype,erp_mtrlunit,erp_mtrlengname,erp_configcodetype,old_mtrlname");
  40. //
  41. var caller = new StackTrace().GetFrame(1).GetMethod();
  42. Trace.Write($"Called By {caller.DeclaringType?.Name}.{caller.Name},INFOS:erp_mtrlid = {mattress.erp_mtrlid},erp_mtrlcod = {mattress.erp_mtrlcode},mattressid = {mattress.mattressid}");
  43. // 保存接口数据
  44. var mattressHelper = GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  45. mattressHelper.SaveMattressInterface(mattress.mattressid, mxlist, qdlist);
  46. }
  47. public void AutoSetMtrlName(u_mattress mattress, List<u_mattress_interface> mxlist)
  48. {
  49. string mtrltypename = string.Empty, mtrltypecode = string.Empty;
  50. string mattresstypename = string.Empty, mattresstypecode = string.Empty;
  51. string packtypename = string.Empty, packtypecode = string.Empty;
  52. var materialCodes = new Dictionary<string, string>
  53. {
  54. { "两边单层", "21" },
  55. { "两边直出", "23" },
  56. { "三边加顶", "32" },
  57. { "三边直出", "33" },
  58. { "假三边", "34" },
  59. { "拉假边", "3C" },
  60. { "假三边加顶", "42" },
  61. { "上下假三边", "44" },
  62. { "四边双顶", "45" },
  63. { "四边顶上顶", "46" },
  64. { "四边假分体", "47" }
  65. };
  66. var mattressTypeCodes = new Dictionary<string, string>
  67. {
  68. { "袋装网", "P" },
  69. { "拉丝网", "C" },
  70. { "圆网", "B" }
  71. };
  72. var packTypeCodes = new Dictionary<string, string>
  73. {
  74. { "平压", "A" },
  75. { "卷包", "B" }
  76. };
  77. foreach (var mx in mxlist)
  78. {
  79. if (mx.bj_pzname.IndexOf("床垫类别") > -1)
  80. {
  81. mtrltypename = mx.bj_namemx;
  82. break;
  83. }
  84. }
  85. foreach (var mx in mxlist)
  86. {
  87. if (mx.bj_pzname.IndexOf("床网") > -1)
  88. {
  89. mattresstypename = mx.bj_namemx;
  90. break;
  91. }
  92. }
  93. foreach (var mx in mxlist)
  94. {
  95. if (mx.bj_pzname.IndexOf("包装方式") > -1)
  96. {
  97. packtypename = mx.bj_namemx;
  98. break;
  99. }
  100. }
  101. mtrltypecode = materialCodes.ContainsKey(mtrltypename) ? materialCodes[mtrltypename] : "99";
  102. mattresstypecode = mattressTypeCodes.ContainsKey(mtrltypename) ? mattressTypeCodes[mtrltypename] : "Z";
  103. packtypecode = packTypeCodes.ContainsKey(mtrltypename) ? packTypeCodes[mtrltypename] : "J";
  104. // 获取mxlist最后一项
  105. if (mattress.mattressid > 0)
  106. {
  107. mattress.erp_mtrlname = new StringBuilder().Append(mtrltypecode).Append(mattresstypecode).Append(packtypecode).ToString();
  108. }
  109. }
  110. public List<u_mattress_interface> GetMattressInterfaceList(int mattressid, int? configuretype)
  111. {
  112. var interfaceList = new List<u_mattress_interface>();
  113. var selectStr = @"SELECT mattressid
  114. ,printid
  115. ,itemname
  116. ,bj_pzname
  117. ,bj_namemx
  118. ,actual_size
  119. ,sb_craft
  120. ,actual_size_sb
  121. ,erp_pzid
  122. ,ss_rate
  123. ,ls_rate
  124. ,bj_inputtype
  125. FROM u_mattress_interface";
  126. DbSqlHelper.SelectJoin(cmd, selectStr, "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", mattressid } }, "printid", "mattressid,printid,itemname,bj_pzname,bj_namemx,actual_size,sb_craft,actual_size_sb,erp_pzid,ss_rate,ls_rate,bj_inputtype", 0, 0, interfaceList);
  127. if(interfaceList.Count <= 0)
  128. {
  129. interfaceList = RefreshMattressInterfaceList(mattressid, configuretype);
  130. foreach (var itm in interfaceList)
  131. {
  132. itm.mattressid = mattressid;
  133. itm.actual_size = itm.actual_size ?? "";
  134. itm.actual_size_sb = itm.actual_size_sb ?? "";
  135. itm.sb_craft = itm.sb_craft ?? "";
  136. itm.ss_rate = itm.ss_rate ?? 0;
  137. itm.ls_rate = itm.ls_rate ?? 0;
  138. }
  139. } else
  140. {
  141. MattressInterfaceFindERPPz(mattressid, interfaceList, configuretype);
  142. }
  143. return interfaceList;
  144. }
  145. public List<u_mattress_interface_qd> GetMattressInterfaceQdList(int mattressid)
  146. {
  147. var qdList = new List<u_mattress_interface_qd>();
  148. var selectStr = @"SELECT u_mattress_interface_qd.mattressid
  149. ,u_mattress_interface_qd.printid
  150. ,u_mattress_interface_qd.itemname
  151. ,u_mattress_interface_qd.bj_pzname
  152. ,u_mattress_interface_qd.bj_pzname_mx
  153. ,u_mattress_interface_qd.bj_pzname_mx_mx
  154. ,u_mattress_interface_qd.wip_type
  155. ,u_mattress_interface_qd.mtrlid
  156. ,u_mattress_interface_qd.erp_mtrlid
  157. ,u_mattress_interface_qd.useqty
  158. ,u_mattress_interface_qd.dscrp
  159. ,u_mtrl_price.name AS mtrlname
  160. ,u_mattress_interface_qd.actual_useqty
  161. ,u_mattress_interface_qd.qd_actual_size
  162. ,u_mattress_interface_qd.qd_pfgroupqty
  163. ,u_mattress_interface_qd.wrkgrpid
  164. ,u_mattress_interface_qd.wrkgrpcode1
  165. ,u_mattress_interface_qd.wrkgrpcode2
  166. ,u_mattress_interface_qd.wrkgrpid2
  167. ,u_mattress_interface_qd.ss_rate
  168. ,u_mattress_interface_qd.ls_rate
  169. ,u_mattress_interface_qd.sh_rate
  170. ,u_mattress_interface_qd.formulaid
  171. FROM u_mattress_interface_qd
  172. LEFT JOIN u_mtrl_price ON u_mtrl_price.mtrlid = u_mattress_interface_qd.mtrlid";
  173. 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";
  174. DbSqlHelper.SelectJoin(cmd, selectStr, "mattressid = @mattressid", new Dictionary<string, object>() { { "@mattressid", mattressid } }, "printid", outputFields, 0, 0, qdList);
  175. if (qdList.Count <= 0)
  176. {
  177. qdList = RefreshMattressInterfaceQdList(mattressid);
  178. }
  179. return qdList;
  180. }
  181. #region 导入配置方法
  182. /// <summary>
  183. /// 刷新带出配置
  184. /// </summary>
  185. /// <param name="mattressid"></param>
  186. /// <returns></returns>
  187. public List<u_mattress_interface> RefreshMattressInterfaceList(int mattressid, int? configcodetype = 0)
  188. {
  189. var interfaceList = new List<u_mattress_interface>();
  190. // 导入配置
  191. ImportMattressInterfaceList(mattressid, interfaceList);
  192. MattressInterfaceFindERPPz(mattressid, interfaceList, configcodetype);
  193. return interfaceList;
  194. }
  195. /// <summary>
  196. /// 导入产品配置
  197. /// </summary>
  198. /// <param name="mattressid"></param>
  199. /// <exception cref="LJCommonException"></exception>
  200. public void ImportMattressInterfaceList(int mattressid, List<u_mattress_interface> interfaceList)
  201. {
  202. if (mattressid <= 0)
  203. {
  204. throw new LJCommonException("床垫id有误");
  205. }
  206. var mattressHelper = GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  207. var mattress = mattressHelper.GetMattress(mattressid);
  208. var mattress_type = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  209. DbSqlHelper.SelectOne(cmd, mattress_type, "typename");
  210. var mxlist_all = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype IN (0,1,2,3,99,101,104,103)" });
  211. mattressHelper.wf_sort_mx(ref mxlist_all);
  212. var mxlist = mxlist_all.Where(t => new[]{ 0, 1, 2, 3, 99, 104, 103 }.Contains(t.formulatype.Value)).ToList();
  213. var mxlist_103 = mxlist_all.Where(t => t.formulatype == 103).ToList();
  214. var mxlist_101 = mxlist_all.Where(t => t.formulatype == 101).ToList();
  215. // 高度
  216. interfaceList.Add(InserMattressInterfacePz("床垫", "高度", 2, new string[] { $"{mattress.mattress_height}" }));
  217. // 参考外观
  218. interfaceList.Add(InserMattressInterfacePz("床垫", "参考外观", 1, new string[] { "" }));
  219. // 尺寸
  220. mattress.erp_mtrlcode = $"{mattress.mattress_width}*{mattress.mattress_length}*{mattress.mattress_height}";
  221. interfaceList.Add(InserMattressInterfacePz("床垫", "尺寸", 2, new string[] { mattress.erp_mtrlcode }));
  222. // 床垫类别
  223. interfaceList.Add(InserMattressInterfacePz("床垫", "床垫类别", 2, new string[] { mattress_type.typename }));
  224. // 拆装类型
  225. var name_arr = new string[1];
  226. name_arr[0] = string.Empty;
  227. if (mattress.if_m_chai == 1) name_arr[0] = AppendToString(name_arr[0], "面拆");
  228. if (mattress.if_z_chai == 1) name_arr[0] = AppendToString(name_arr[0], "中拆");
  229. if (mattress.if_d_chai == 1) name_arr[0] = AppendToString(name_arr[0], "底拆");
  230. interfaceList.Add(InserMattressInterfacePz("床垫", "拆装类型", 1, name_arr));
  231. // 床垫分类
  232. name_arr[0] = string.Empty;
  233. if (mattress.if_haimian_type == 1) name_arr[0] = AppendToString(name_arr[0], "海绵床垫");
  234. else name_arr[0] = AppendToString(name_arr[0], "弹簧床垫");
  235. if (mattress.if_zhedie_type == 1) name_arr[0] = AppendToString(name_arr[0], "折叠床垫");
  236. interfaceList.Add(InserMattressInterfacePz("床垫", "床垫分类", 1, name_arr));
  237. // 外观布套做法
  238. name_arr[0] = string.Empty;
  239. if (mattress.if_m_wbutao_way == 1) name_arr[0] = AppendToString(name_arr[0], $"面层向大侧覆盖{mattress.s_m_cover_qty}CM、大侧向底层覆盖{mattress.z_m_cover_qty}CM、底层向大侧覆盖{mattress.x_m_cover_qty}CM");
  240. interfaceList.Add(InserMattressInterfacePz("床垫", "外观布套做法", 1, name_arr));
  241. // 边带
  242. name_arr[0] = string.Empty;
  243. interfaceList.Add(InserMattressInterfacePz("床垫", "边带", 0, name_arr));
  244. #region 面料类清单导入 AutoSetFormulaTypeZeroPz()需要优化
  245. AutoSetFormulaTypeZeroPz(mxlist, interfaceList);
  246. interfaceList.Add(InserMattressInterfacePz("车位说明", "车位说明", 1, name_arr));
  247. #endregion
  248. #region 垫层类清单导入
  249. AutoSetFormulaTypeOnePz(mxlist, interfaceList);
  250. #endregion
  251. #region 辅料类清单导入
  252. AutoSetFormulaTypeTwoPz(mxlist, interfaceList);
  253. #endregion
  254. #region 包装类清单导入
  255. AutoSetFormulaTypeThreePz(mattress, mxlist, interfaceList);
  256. #endregion
  257. #region 内布套类清单导入
  258. AutoSetFormulaType101Pz(mattress, mxlist_101, interfaceList);
  259. #endregion
  260. #region 自定义配置导入
  261. if(mattress.erp_configcodetype != null && mattress.erp_configcodetype > 0)
  262. {
  263. var erpHelper = HelperBase.GetHelper<ERPHelper>(null);
  264. var parameters = new JObject();
  265. parameters.Add("dsname", "web_configure_code_list");
  266. var queryparams = new JObject();
  267. queryparams.Add("arg_configcodetype", mattress.erp_configcodetype);
  268. queryparams.Add("arg_ifpack", 1);
  269. parameters.Add("queryparams", queryparams);
  270. var resultList = erpHelper.GetERPList<erp_configure_code>("CommonDynamicSelect", parameters);
  271. foreach(var result in resultList)
  272. {
  273. var pzname = result.name;
  274. interfaceList.Add(InserMattressInterfacePz("自定义", pzname, 1, new string[] { "" }));
  275. }
  276. }
  277. #endregion
  278. }
  279. public void MattressInterfaceFindERPPz(int mattressid, List<u_mattress_interface> interfaceList, int? configcodetype = 0)
  280. {
  281. var mattress = new u_mattress() { mattressid = mattressid };
  282. if (configcodetype != 0)
  283. {
  284. mattress.erp_configcodetype = configcodetype;
  285. } else
  286. {
  287. DbSqlHelper.SelectOne(cmd, mattress, "erp_configcodetype");
  288. }
  289. MattressInterfaceFindERPPz(mattress, interfaceList);
  290. }
  291. public void MattressInterfaceFindERPPz(u_mattress mattress,List<u_mattress_interface> interfaceList)
  292. {
  293. InterfaceFindERPPz(mattress.erp_configcodetype.Value, interfaceList);
  294. }
  295. public u_mattress_interface InserMattressInterfacePz(string itemname, string bj_pzname, byte inputtype, string[] names)
  296. {
  297. return InserInterfacePz<u_mattress_interface>(itemname,bj_pzname,inputtype,names);
  298. }
  299. private string SetInterfacePzName(string[] names)
  300. {
  301. var result = string.Empty;
  302. foreach (var name in names)
  303. {
  304. if (string.IsNullOrEmpty(name)) continue;
  305. result = AppendToString(result, name);
  306. }
  307. return result;
  308. }
  309. private void AutoSetFormulaTypeZeroPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  310. {
  311. var powerDict = new Dictionary<string, int[]>()
  312. {
  313. {"面裥绵",new int[] { 0, 40, 50, 60, 70, 80 } },
  314. {"底裥绵",new int[] { 1, 41, 51, 61, 71, 81 } },
  315. {"顶布裥棉1",new int[] { 0, 40, 50, 60, 70, 80 } },
  316. {"顶布裥棉2",new int[] { 0, 40, 50, 60, 70, 80 } },
  317. {"顶布裥棉3",new int[] { 0, 40, 50, 60, 70, 80 } },
  318. {"顶布裥棉4",new int[] { 0, 40, 50, 60, 70, 80 } },
  319. {"普通大侧",new int[] { 2, 42, 52, 62, 72, 82 } },
  320. {"上下拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  321. {"上下拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  322. {"上下拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  323. {"左右拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  324. {"左右拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  325. {"左右拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  326. {"小侧1_EMPTY",new int[] { 3, 43, 53, 63, 73, 83 } },
  327. {"小侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  328. {"小侧1-上下拼侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  329. {"小侧1-上下拼侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  330. {"小侧1-上下拼侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  331. {"小侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  332. {"小侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  333. {"V侧1_EMPTY",new int[] { 4, 44, 54, 64, 74, 84 } },
  334. {"V侧1",new int[] { 4, 44, 54, 64, 74, 84 } },
  335. {"V侧2",new int[] { 4, 44, 54, 64, 74, 84 } },
  336. {"V侧3",new int[] { 4, 44, 54, 64, 74, 84 } }
  337. };
  338. var chastrArrDict = new Dictionary<string, string[]>()
  339. {
  340. {"面裥绵",new string[] { "裥面", "面层裥棉", "面层裥棉图案", "面层裥面说明" } },
  341. {"底裥绵",new string[] { "裥底", "底层裥棉", "底层裥棉图案", "底层裥棉说明" } },
  342. {"顶布裥棉1",new string[] { "顶布裥棉", "", "顶布裥棉1图案", "顶布裥棉1说明" } },
  343. {"顶布裥棉2",new string[] { "顶布裥棉", "", "顶布裥棉2图案", "顶布裥棉2说明" } },
  344. {"顶布裥棉3",new string[] { "顶布裥棉", "", "顶布裥棉3图案", "顶布裥棉3说明" } },
  345. {"顶布裥棉4",new string[] { "顶布裥棉","", "顶布裥棉4图案", "顶布裥棉4说明" } },
  346. {"普通大侧",new string[] { "大侧", "大侧裥棉", "大侧裥棉图案" } },
  347. {"上下拼侧1",new string[] {"大侧", "大侧-上下拼侧1", "大侧-上下拼侧1裥棉图案", "大侧-上下拼侧1高度"} },
  348. {"上下拼侧2",new string[] { "大侧", "大侧-上下拼侧2", "大侧-上下拼侧2裥棉图案", "大侧-上下拼侧2高度" } },
  349. {"上下拼侧3",new string[] { "大侧", "大侧-上下拼侧3", "大侧-上下拼侧3裥棉图案", "大侧-上下拼侧3高度" } },
  350. {"左右拼侧1",new string[] { "大侧", "大侧-左右拼侧1", "大侧-左右拼侧1裥棉图案", "大侧-左右拼侧1长度" } },
  351. {"左右拼侧2",new string[] { "大侧", "大侧-左右拼侧2", "大侧-左右拼侧2裥棉图案", "大侧-左右拼侧2长度" } },
  352. {"左右拼侧3",new string[] { "大侧", "大侧-左右拼侧3", "大侧-左右拼侧3裥棉图案", "大侧-左右拼侧3长度", "大侧说明" } },
  353. {"小侧1_EMPTY",new string[] { "小侧", "小侧1裥棉", "小侧1裥棉图案" } },
  354. {"小侧1",new string[] { "小侧", "小侧1裥棉", "小侧1裥棉图案" } },
  355. {"小侧1-上下拼侧1",new string[] { "小侧", "小侧1-上下拼侧1裥棉", "小侧1-上下拼侧1裥棉图案" } },
  356. {"小侧1-上下拼侧2",new string[] { "小侧", "小侧1-上下拼侧2裥棉", "小侧1-上下拼侧2裥棉图案" } },
  357. {"小侧1-上下拼侧3",new string[] { "小侧", "小侧1-上下拼侧3裥棉", "小侧1-上下拼侧3裥棉图案" } },
  358. {"小侧2",new string[] { "小侧", "小侧2裥棉", "小侧2裥棉图案" } },
  359. {"小侧3",new string[] { "小侧", "小侧3裥棉", "小侧3裥棉图案", "小侧说明" } },
  360. {"V侧1_EMPTY",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  361. {"V侧1",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  362. {"V侧2",new string[] { "V侧", "V侧2裥棉", "V侧2裥棉图案" } },
  363. {"V侧3",new string[] { "V侧", "V侧3裥棉", "V侧3裥棉图案", "V侧说明" } }
  364. };
  365. var jianmianList = mxlist.Where(t => t.formulatype == 0).ToList();
  366. var dingbuList = mxlist.Where(t => t.formulatype == 103).ToList();
  367. #region wf_import_qingdan + wf_import_qingdan_1 面料部分
  368. foreach (var item in powerDict)
  369. {
  370. if(item.Key.Contains("顶布裥棉")) SetFormulaTypeZeroPz(dingbuList, interfaceList, item.Value, item.Key, chastrArrDict[item.Key]);
  371. else SetFormulaTypeZeroPz(jianmianList, interfaceList, item.Value, item.Key, chastrArrDict[item.Key]);
  372. }
  373. #endregion
  374. #region wf_import_qingdan_next 面料部分
  375. // 拉手
  376. var lashouList = jianmianList.Where(t => t.formulakind == 5).ToList();
  377. for (int i = 0; i < lashouList.Count; i++)
  378. {
  379. var mx = lashouList[i];
  380. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  381. {
  382. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"拉手{i + 1}做法", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}只{mx.mtrlname}" }));
  383. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"拉手{i + 1}刺绣", 0, new string[] { "" }));
  384. }
  385. }
  386. // 刺绣
  387. var cixiuList = jianmianList.Where(t => t.formulakind == 6).ToList();
  388. var ls_temp_cnt = 0;
  389. for (int i = 0; i < cixiuList.Count; i++)
  390. {
  391. var mx = cixiuList[i];
  392. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  393. {
  394. for (int k = 0; k < mx.qty; k++)
  395. {
  396. ls_temp_cnt++;
  397. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"侧刺绣{ls_temp_cnt}做法", 1, new string[] { "" }));
  398. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"侧刺绣{ls_temp_cnt}位置", 0, new string[] { "" }));
  399. }
  400. }
  401. }
  402. // 大侧压压布
  403. var dcyybList = jianmianList.Where(t => t.formulakind == 7).ToList();
  404. for (int i = 0; i < dcyybList.Count; i++)
  405. {
  406. var mx = dcyybList[i];
  407. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  408. {
  409. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压压布{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  410. }
  411. }
  412. // 大侧压边带
  413. var dcybdList = jianmianList.Where(t => t.formulakind == 8).ToList();
  414. for (int i = 0; i < dcybdList.Count; i++)
  415. {
  416. var mx = dcybdList[i];
  417. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  418. {
  419. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压边带{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  420. }
  421. }
  422. // 大侧压织带
  423. var dcyzdList = jianmianList.Where(t => t.formulakind == 9).ToList();
  424. for (int i = 0; i < dcyzdList.Count; i++)
  425. {
  426. var mx = dcyzdList[i];
  427. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  428. {
  429. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压织带{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  430. }
  431. }
  432. // 大侧压上下压线
  433. var dcysxyxList = jianmianList.Where(t => t.formulakind == 10).ToList();
  434. for (int i = 0; i < dcysxyxList.Count; i++)
  435. {
  436. var mx = dcysxyxList[i];
  437. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  438. {
  439. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", $"大侧压上下压线{i + 1}", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  440. }
  441. }
  442. // 车花边
  443. var chbList = jianmianList.Where(t => t.formulakind == 205).ToList();
  444. for (int i = 0; i < chbList.Count; i++)
  445. {
  446. var mx = chbList[i];
  447. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  448. {
  449. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "车花边", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  450. }
  451. }
  452. // 防火线
  453. var fhxList = jianmianList.Where(t => t.formulakind == 30).ToList();
  454. for (int i = 0; i < fhxList.Count; i++)
  455. {
  456. var mx = fhxList[i];
  457. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  458. {
  459. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "防火线", 1, new string[] { mx.mtrlname }));
  460. }
  461. }
  462. // 拉链
  463. var llList = jianmianList.Where(t => t.formulakind == 202 && string.IsNullOrEmpty(t.chastr) && t.mtrlid > 0).ToList();
  464. for (int i = 0; i < llList.Count; i++)
  465. {
  466. var mx = llList[i];
  467. if (llList.Count > 1)
  468. {
  469. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "拉链" + (i+1), 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  470. }
  471. else
  472. {
  473. interfaceList.Add(InserMattressInterfacePz("拉手刺绣及其他工艺", "拉链", 1, new string[] { $"{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  474. }
  475. }
  476. #endregion
  477. }
  478. private void SetFormulaTypeZeroPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList, int[] powerArr, string key, string[] chastrArr)
  479. {
  480. var mianList1 = new HashSet<string> { "面裥绵", "底裥绵" };
  481. var mianList2 = new string[4] { "顶布裥棉1", "顶布裥棉2", "顶布裥棉3", "顶布裥棉4" };
  482. var mianList3 = new HashSet<string> { "普通大侧", "上下拼侧1", "上下拼侧2", "上下拼侧3", "左右拼侧1", "左右拼侧2", "左右拼侧3", "小侧1", "小侧2", "小侧3" };
  483. //var mianList4 = new HashSet<string> { "小侧1", "小侧2", "小侧3" };
  484. var name_arr = new string[5];
  485. foreach (var mx in mxlist)
  486. {
  487. SetFormulaTypeZeroPzName(mx, key, powerArr, name_arr);
  488. }
  489. if (mianList2.Contains(key))
  490. {
  491. for (int i = 0; i < mianList2.Length; i++)
  492. {
  493. DingBuLianMian.SetValue(name_arr[i], Array.IndexOf(mianList2, key),i );
  494. }
  495. }
  496. //if (mianList4.Contains(key))
  497. //{
  498. // var _index = 0;
  499. // Regex regex = new Regex(@"\d+");
  500. // Match match = regex.Match(key);
  501. // _index = Convert.ToInt32(match.Value) - 1;
  502. // for (int i = 0; i < mianList4.Count; i++)
  503. // {
  504. // XiaoCePeizhi.SetValue(name_arr[i], i, _index);
  505. // }
  506. //}
  507. var sb = new StringBuilder();
  508. foreach (var name2 in name_arr)
  509. {
  510. sb.Append(name2);
  511. }
  512. bool ifchastr3 = false;
  513. if (sb.Length > 0)
  514. {
  515. if (!string.IsNullOrEmpty(chastrArr[1])) interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[1], 2, name_arr));
  516. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[2], 1, new string[] { "" }));
  517. if (chastrArr.Length > 3)
  518. {
  519. if (chastrArr[3].Contains("说明")) ifchastr3 = true;
  520. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], chastrArr[3], 1, new string[] { "" }));
  521. }
  522. }
  523. foreach (var name in chastrArr)
  524. {
  525. if (string.IsNullOrEmpty(name)) continue;
  526. if (name.Contains("说明") && !ifchastr3)
  527. {
  528. interfaceList.Add(InserMattressInterfacePz(chastrArr[0], name, 1, new string[] { "" }));
  529. }
  530. }
  531. }
  532. private void SetFormulaTypeZeroPzName(u_mattress_mx_mtrl mx, string key, int[] powerArr, string[] name_arr)
  533. {
  534. if (key.Contains("_EMPTY")) key = "";
  535. if (mx.mtrlid > 0 && key.Equals(mx.chastr) && powerArr.Contains(mx.formulakind.Value))
  536. {
  537. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3 || mx.formulakind == 4)
  538. {
  539. name_arr[0] = AppendToString(name_arr[0], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  540. }
  541. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43 || mx.formulakind == 44)
  542. {
  543. name_arr[1] = AppendToString(name_arr[1], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  544. }
  545. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53 || mx.formulakind == 54)
  546. {
  547. var mtrlname_temp = mx.mtrlname;
  548. if (!(mx.mtrlname.IndexOf("分") > -1 && mx.thickness == 0 || mx.if_inputqty == 1))
  549. {
  550. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  551. }
  552. name_arr[2] = AppendToString(name_arr[2], SplitNameCount(mtrlname_temp, Convert.ToInt32(mx.qty.Value)));
  553. }
  554. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63 || mx.formulakind == 64)
  555. {
  556. name_arr[3] = AppendToString(name_arr[3], SplitNameCount(mx.mtrlname, Convert.ToInt32(mx.qty.Value)));
  557. }
  558. if (mx.formulakind == 80 || mx.formulakind == 81 || mx.formulakind == 82 || mx.formulakind == 83 || mx.formulakind == 84)
  559. {
  560. name_arr[0] = string.Format("{0}({1})", name_arr[0], mx.mtrlname);
  561. }
  562. }
  563. }
  564. public void AutoSetFormulaTypeOnePz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  565. {
  566. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  567. var kindDict = new Dictionary<int, string>()
  568. {
  569. { 32,"垫层" },
  570. { 12,"顶布" },
  571. { 13,"毡类" },
  572. { 14,"打底无纺布" },
  573. { 29,"网面布料" },
  574. { 999,"床网" },
  575. { 1201,"顶布裥棉" },
  576. };
  577. var chastrSet = new HashSet<string>() { "大侧", "小侧1", "小侧2", "小侧3", "V侧1", "V侧2", "V侧3" };
  578. var countDict = new Dictionary<string, int>();
  579. foreach (var cha in chastrSet)
  580. {
  581. foreach (var kind in kindDict)
  582. {
  583. countDict.Add($"{cha}-{kind.Value}", 0);
  584. }
  585. }
  586. foreach (var mx in diancengList)
  587. {
  588. var key = $"{mx.chastr}-{kindDict[mx.formulakind.Value]}";
  589. if (mx.formulakind == 999)
  590. {
  591. this.ProcessChuangWangPz(mx, interfaceList, mx.chastr, ++countDict[key]);
  592. }
  593. else if (mx.mtrlid > 0 && mx.formulakind == 1201)
  594. {
  595. this.ProcessDingbuLianMianPz(mx, interfaceList, mx.chastr, ++countDict[key]);
  596. }
  597. else if (mx.mtrlid > 0 && new int[] { 32, 12, 13, 14, 29 }.Contains(mx.formulakind.Value))
  598. {
  599. this.ProcessWangMianBLPz(mx, interfaceList, mx.chastr, kindDict[mx.formulakind.Value], ++countDict[key]);
  600. }
  601. }
  602. if (countDict["大侧-垫层"] > 0)
  603. {
  604. interfaceList.Add(InserMattressInterfacePz("垫层", "大侧垫层生产说明", 1, new string[1]));
  605. }
  606. if (countDict["小侧1-垫层"] > 0)
  607. {
  608. interfaceList.Add(InserMattressInterfacePz("垫层", "小侧垫层生产说明", 1, new string[1]));
  609. }
  610. if (countDict["V侧1-垫层"] > 0)
  611. {
  612. interfaceList.Add(InserMattressInterfacePz("垫层", "V侧垫层生产说明", 1, new string[1]));
  613. }
  614. }
  615. /// <summary>
  616. /// 床网
  617. /// </summary>
  618. /// <param name="mx"></param>
  619. /// <param name="interfaceList"></param>
  620. /// <param name="chastr"></param>
  621. /// <param name="count"></param>
  622. private void ProcessChuangWangPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, int count)
  623. {
  624. var name_arr = new string[5];
  625. int bednetid = 0;
  626. int spongeMtrlid = 0; // 是否有海绵包边物料
  627. int spongeTcMtrlid = 0; // 是否有海绵填充物料
  628. cmd.CommandText = @"SELECT u_bednetmx.bednet_height,u_bednetmx.bednetid,u_bednet.sponge_mtrlid,u_bednet.sponge_tc_mtrlid
  629. FROM u_bednetmx
  630. INNER JOIN u_bednet ON u_bednet.bednetid = u_bednetmx.bednetid
  631. INNER JOIN (
  632. SELECT mtrlid
  633. FROM u_mattress_mx_mtrl
  634. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  635. WHERE u_mattress_formula.formulakind = 99
  636. AND u_mattress_mx_mtrl.mattressid = @mattressid
  637. AND u_mattress_mx_mtrl.mtrlid > 0
  638. ) v_mattress_mx_mtrl ON u_bednetmx.bednetid = v_mattress_mx_mtrl.mtrlid";
  639. cmd.Parameters.Clear();
  640. cmd.Parameters.AddWithValue("@mattressid", mx.mattressid);
  641. using (var reader = cmd.ExecuteReader())
  642. {
  643. while (reader.Read())
  644. {
  645. decimal height = Convert.ToDecimal(reader["bednet_height"]);
  646. if (height == mx.thickness)
  647. {
  648. bednetid = Convert.ToInt32(reader["bednetid"]);
  649. spongeMtrlid = Convert.ToInt32(reader["sponge_mtrlid"]);
  650. spongeTcMtrlid = Convert.ToInt32(reader["sponge_tc_mtrlid"]);
  651. }
  652. }
  653. }
  654. if (bednetid > 0)
  655. {
  656. var bednetHelper = HelperBase.GetHelper<BedNetHelper>(cmd);
  657. var bednetQdList = bednetHelper.GetBedNetQingDan(bednetid);
  658. if (bednetQdList.Any())
  659. {
  660. name_arr[0] = bednetQdList[0].pznamemx;
  661. name_arr[0] += "丨erp编码:";
  662. cmd.CommandText = @"SELECT u_mattress.erp_mtrlcode
  663. FROM u_mattress_mx_mtrl
  664. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  665. INNER JOIN u_mattress ON u_mattress.mattressid = u_mattress_mx_mtrl.mattressid
  666. WHERE u_mattress_formula.formulakind = 99
  667. AND u_mattress.bcptypeid <> 0
  668. AND u_mattress_mx_mtrl.mtrlid = @bednetid";
  669. cmd.Parameters.Clear();
  670. cmd.Parameters.AddWithValue("@bednetid", bednetid);
  671. using(var reader = cmd.ExecuteReader())
  672. {
  673. if (reader.Read())
  674. {
  675. name_arr[0] += Convert.ToString(reader["erp_mtrlcode"]);
  676. }
  677. }
  678. }
  679. }
  680. if (FuncPowerHelper.CheckFuncPower(cmd, context.tokendata.userid, 98) && "super".Equals(context.tokendata.username.ToLower()))
  681. {
  682. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}", 2, name_arr));
  683. }
  684. else
  685. {
  686. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}", 1, name_arr));
  687. }
  688. interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}生产说明", 1, new string[] { "" }));
  689. if (spongeMtrlid > 0) interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}包边海绵条", 1, new string[] { "" }));
  690. if (spongeTcMtrlid > 0) interfaceList.Add(InserMattressInterfacePz("垫层", $"{chastr}-床网{count}填充海绵条", 1, new string[] { "" }));
  691. }
  692. /// <summary>
  693. /// 网面布料 / 打底无纺布 / 毡类 / 顶布 / 垫层
  694. /// </summary>
  695. /// <param name="mx"></param>
  696. /// <param name="interfaceList"></param>
  697. /// <param name="chastr"></param>
  698. /// <param name="count"></param>
  699. private void ProcessWangMianBLPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, string typename, int count)
  700. {
  701. var name_arr = new string[5];
  702. var mtrlname_temp = mx.mtrlname;
  703. var chastr_temp = string.Empty;
  704. if ("顶布".Equals(typename) && count <= 1)
  705. {
  706. chastr_temp = $"{chastr}-{typename}";
  707. }
  708. else
  709. {
  710. chastr_temp = $"{chastr}-{typename}{count}";
  711. }
  712. if ((!mx.mtrlname.Contains("分") && mx.thickness > 0) || ("垫层".Equals(typename)))
  713. {
  714. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  715. }
  716. name_arr[0] = mtrlname_temp;
  717. interfaceList.Add(InserMattressInterfacePz("垫层", chastr_temp, 2, name_arr));
  718. }
  719. /// <summary>
  720. /// 顶布裥棉
  721. /// </summary>
  722. /// <param name="mx"></param>
  723. /// <param name="interfaceList"></param>
  724. /// <param name="count"></param>
  725. private void ProcessDingbuLianMianPz(u_mattress_mx_mtrl mx, List<u_mattress_interface> interfaceList, string chastr, int count)
  726. {
  727. string chastr_temp = string.Empty;
  728. string ls_temp = "";
  729. string[] name_arr = new string[5];
  730. if ("顶布裥棉1".Equals(mx.mtrlname))
  731. {
  732. chastr_temp = $"{chastr}-顶布裥棉";
  733. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  734. {
  735. name_arr[i] = DingBuLianMian[0, i];
  736. }
  737. }
  738. else if ("顶布裥棉2".Equals(mx.mtrlname))
  739. {
  740. chastr_temp = $"{chastr}-顶布裥棉2";
  741. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  742. {
  743. name_arr[i] = DingBuLianMian[1, i];
  744. }
  745. }
  746. else if ("顶布裥棉3".Equals(mx.mtrlname))
  747. {
  748. chastr_temp = $"{chastr}-顶布裥棉3";
  749. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  750. {
  751. name_arr[i] = DingBuLianMian[2, i];
  752. }
  753. }
  754. else if ("顶布裥棉4".Equals(mx.mtrlname))
  755. {
  756. chastr_temp = $"{chastr}-顶布裥棉4";
  757. for (int i = 0; i < DingBuLianMian.GetLength(0); i++)
  758. {
  759. name_arr[i] = DingBuLianMian[3, i];
  760. }
  761. }
  762. interfaceList.Add(InserMattressInterfacePz("垫层", chastr_temp, 2, name_arr));
  763. }
  764. private void AutoSetFormulaTypeTwoPz(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  765. {
  766. var nameSet = new HashSet<string>(new string[] {
  767. "白色无字包角", "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "角网+拉链",
  768. "开箱刀+开箱说明", "开箱说明+开箱刀", "气钮", "吊标", "说明书", "斜标", "正标", "织唛",
  769. "织唛斜标", "客供标", "空白牛皮纸包角", "空白珍珠包角"
  770. });
  771. // 按照nameSet排序
  772. Dictionary<string, int> orderDict = nameSet.Select((name, index) => new { Name = name, Index = index }).ToDictionary(x => x.Name, x => x.Index);
  773. //var fuliaoList = mxlist.Where(t => t.formulatype == 2).OrderBy(t => orderDict.ContainsKey(t.mtrlname) ? orderDict[t.mtrlname] : int.MaxValue).ThenBy(t => !orderDict.ContainsKey(t.mtrlname) ? t.mtrlname : null).ToList();
  774. var resultDict = new Dictionary<int, u_mattress_mx_mtrl>();
  775. foreach (var item in mxlist.Where(t => t.formulatype == 2))
  776. {
  777. if (!resultDict.ContainsKey(item.mtrlid.Value))
  778. {
  779. resultDict.Add(item.mtrlid.Value, item);
  780. }
  781. else
  782. {
  783. resultDict[item.mtrlid.Value].qty += item.qty.Value;
  784. }
  785. }
  786. var fuliaoList = new List<u_mattress_mx_mtrl>();
  787. foreach (var kvp in resultDict)
  788. {
  789. fuliaoList.Add(kvp.Value);
  790. }
  791. fuliaoList = fuliaoList.OrderBy(t => orderDict.ContainsKey(t.mtrlname) ? orderDict[t.mtrlname] : int.MaxValue)
  792. .ThenBy(t => !orderDict.ContainsKey(t.mtrlname) ? t.mtrlname : null)
  793. .ToList();
  794. var extraSet = new HashSet<string>(new string[] { "采购小标", "打印小标", "合格证", "吊标", "斜标", "正标", "织唛", "织唛斜标", "客供标" });
  795. var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });
  796. foreach (var mx in fuliaoList)
  797. {
  798. if (mx.mtrlid > 0)
  799. {
  800. int cnt = Convert.ToInt32(Math.Abs(mx.qty.Value));
  801. var mtrldef = new u_mtrl_price() { mtrlid = mx.mtrlid };
  802. if (DbSqlHelper.SelectOne(cmd, mtrldef, "erp_mtrlid") == 1)
  803. {
  804. mx.erp_mtrlid = mtrldef.erp_mtrlid;
  805. }
  806. // 处理特殊辅料
  807. if (specialSet.Contains(mx.mtrlname))
  808. {
  809. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}", 1, new string[] { $"{cnt.ToString("#,##0.0#")}个" }));
  810. continue; // 跳过后续的处理
  811. }
  812. // 处理其他辅料
  813. if (nameSet.Contains(mx.mtrlname))
  814. {
  815. for (int i = 1; i <= cnt; i++)
  816. {
  817. // 添加辅料接口
  818. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}", 1, new string[] { "" }));
  819. // 如果是额外的辅料,添加位置接口
  820. if (extraSet.Contains(mx.mtrlname))
  821. {
  822. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}位置", 0, new string[] { "" }));
  823. }
  824. }
  825. }else if(mx.formulakind == 15 && !nameSet.Contains(mx.mtrlname))
  826. {
  827. for (int i = 1; i <= cnt; i++)
  828. {
  829. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}", 1, new string[] { "" }));
  830. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}位置", 0, new string[] { "" }));
  831. }
  832. }
  833. }
  834. }
  835. }
  836. private void AutoSetFormulaTypeThreePz(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  837. {
  838. // 筛选 formulatype 为 3 的物料
  839. var bzList = mxlist.Where(t => t.formulatype == 3).ToList();
  840. var chastrDict = new Dictionary<int, string>
  841. {
  842. {16, "PE袋"},
  843. {17, "外层PE"},
  844. {18, "PVC"},
  845. {19, "卷包包装"},
  846. {20, "牛皮纸袋"},
  847. {21, "蓝色PE护角"},
  848. {22, "无纺布袋"},
  849. {23, "牛皮袋护角"},
  850. {24, "编织袋"},
  851. {27, "拉手脚轮"},
  852. {201, "无纺布护角"}
  853. };
  854. // 判断是否多物料
  855. var formulaList = new List<u_mattress_formula>();
  856. DbSqlHelper.Select(cmd, "u_mattress_formula", "formulatype = 3 AND if_mtrl = 2",null, "formulakind", 0,0, formulaList, null, "formulakind");
  857. var countDict = new Dictionary<int, int>();
  858. foreach (var formula in formulaList)
  859. {
  860. if (!countDict.ContainsKey(formula.formulakind.Value)) countDict.Add(formula.formulakind.Value, 1);
  861. }
  862. // 外观
  863. interfaceList.Add(InserMattressInterfacePz("床垫", "包装方式", 1, new string[] { Enum.GetName(typeof(PackType), mattress.packtype) }));
  864. foreach (var mx in bzList)
  865. {
  866. if (mx.mtrlid > 0 && chastrDict.TryGetValue(mx.formulakind.GetValueOrDefault(), out var chastr))
  867. {
  868. var name_arr = new string[1];
  869. if (mx.qty.HasValue && mx.qty.Value > 1)
  870. {
  871. name_arr[0] = $"{mx.qty.Value.ToString("#,##0.0#")}个{mx.mtrlname}";
  872. }
  873. else
  874. {
  875. name_arr[0] = mx.mtrlname;
  876. }
  877. if (countDict.ContainsKey(mx.formulakind.Value))
  878. {
  879. chastr += countDict[mx.formulakind.Value]++;
  880. }
  881. // 添加包装信息
  882. interfaceList.Add(InserMattressInterfacePz("包装", chastr, 2, name_arr));
  883. }
  884. }
  885. // 压包数量
  886. interfaceList.Add(InserMattressInterfacePz("包装", "压包数量", 1, new string[] { $"{mattress.packqty.Value.ToString("#,##0.0#")}" }));
  887. // 包装说明
  888. interfaceList.Add(InserMattressInterfacePz("包装", "包装说明", 1, new string[] { "" }));
  889. // 压包说明
  890. if (mattress.packqty.HasValue && mattress.packqty.Value > 0) interfaceList.Add(InserMattressInterfacePz("包装", "压包说明", 1, new string[] { "" }));
  891. // 卷包说明
  892. if (mattress.diameter.HasValue && mattress.diameter.Value > 0) interfaceList.Add(InserMattressInterfacePz("包装", "卷包说明", 1, new string[] { "" }));
  893. }
  894. private void AutoSetFormulaType101Pz(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  895. {
  896. var powerDict = new Dictionary<string, int[]>()
  897. {
  898. {"面裥绵",new int[] { 0, 40, 50, 60, 70 } },
  899. {"底裥绵",new int[] { 1, 41, 51, 61, 71 } },
  900. {"普通大侧",new int[] { 2, 42, 52, 62, 72 } }
  901. };
  902. var chastrDict = new Dictionary<string, string[]>()
  903. {
  904. {"面裥绵",new string[] { "内布套-面层裥棉", "内布套-面层裥棉裥棉图案" } },
  905. {"底裥绵",new string[] { "内布套-底层裥棉", "内布套-底层裥棉裥棉图案" } },
  906. {"普通大侧",new string[] { "内布套-大侧裥棉", "内布套-大侧裥棉裥棉图案" } }
  907. };
  908. foreach (var item in powerDict)
  909. {
  910. var name_arr = new string[5];
  911. foreach (var mx in mxlist)
  912. {
  913. SetFormulaTypeZeroPzName(mx, "内布套", item.Value, name_arr);
  914. }
  915. var sb = new StringBuilder();
  916. foreach (var name2 in name_arr)
  917. {
  918. sb.Append(name2);
  919. }
  920. if (sb.Length > 0)
  921. {
  922. interfaceList.Add(InserMattressInterfacePz("内布套", chastrDict[item.Key][0], 2, name_arr));
  923. interfaceList.Add(InserMattressInterfacePz("内布套", chastrDict[item.Key][1], 1, new string[] { "" }));
  924. }
  925. }
  926. // 内布套-围边边带 / 拉链
  927. foreach (var mx in mxlist)
  928. {
  929. if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 203)
  930. {
  931. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套-围边边带", 2, new string[] { $"{mx.thickness.Value.ToString("#,##0.0#")}条共{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  932. }
  933. else if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 202)
  934. {
  935. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套-拉链", 2, new string[] { $"{mx.thickness.Value.ToString("#,##0.0#")}条共{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  936. }
  937. }
  938. var butaostring = new string[] { };
  939. if (mattress.if_n_butao == 1)
  940. {
  941. butaostring = new string[] { $"内布套面层向大侧覆盖{mattress.s_cover_qty.Value.ToString("#,##0.0#")}CM、内布套大侧向底层覆盖{mattress.z_cover_qty.Value.ToString("#,##0.0#")}CM、内布套底层向大侧覆盖{mattress.x_cover_qty.Value.ToString("#,##0.0#")}CM" };
  942. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套做法说明", 1, butaostring));
  943. }
  944. }
  945. #endregion
  946. #region 导入清单方法
  947. public List<u_mattress_interface_qd> RefreshMattressInterfaceQdList(int mattressid)
  948. {
  949. var qdList = new List<u_mattress_interface_qd>();
  950. ImportMattressInterfaceQdList(mattressid, qdList);
  951. MattressInterfaceFindERPPrdPf(qdList,null);
  952. return qdList;
  953. }
  954. /// <summary>
  955. /// wf_fine_erp_prdpf
  956. /// </summary>
  957. /// <param name="qdList"></param>
  958. /// <param name="interfaceList"></param>
  959. public void MattressInterfaceFindERPPrdPf(List<u_mattress_interface_qd> qdList,List<u_mattress_interface> interfaceList = null)
  960. {
  961. InterfaceFindERPPrdPf(qdList,interfaceList);
  962. }
  963. /// <summary>
  964. /// 导入产品清单
  965. /// </summary>
  966. /// <param name="mattressid"></param>
  967. /// <exception cref="LJCommonException"></exception>
  968. public void ImportMattressInterfaceQdList(int mattressid, List<u_mattress_interface_qd> qdList)
  969. {
  970. if (mattressid <= 0)
  971. {
  972. throw new LJCommonException("床垫id有误");
  973. }
  974. var mattressHelper = GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  975. var mattress = mattressHelper.GetMattress(mattressid);
  976. var mattress_type = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  977. DbSqlHelper.SelectOne(cmd, mattress_type, "typename");
  978. var mxlist = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype IN (0,1,2,3,99,104)" });
  979. var mxlist_103 = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype = 103" });
  980. var mxlist_101 = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype = 101" });
  981. #region 面料类清单导入
  982. AutoSetFormulaTypeZeroPrdPf(mxlist, qdList);
  983. #endregion
  984. #region 垫层类清单导入
  985. AutoSetFormulaTypeOnePrdPf(mxlist, qdList);
  986. #endregion
  987. #region 辅料类清单导入
  988. AutoSetFormulaTypeTwoPrfPf(mxlist, qdList);
  989. #endregion
  990. #region 包装类清单导入
  991. AutoSetFormulaTypeThreePrdPf(mxlist, qdList);
  992. #endregion
  993. #region 内布套类清单导入
  994. AutoSetFormulaType101PrdPf(mxlist_103, qdList);
  995. #endregion
  996. // 最后初始化interfaceList的printid
  997. for (var i = 0; i < qdList.Count; i++)
  998. {
  999. qdList[i].printid = i + 1;
  1000. }
  1001. }
  1002. /// <summary>
  1003. /// 初始化清单信息
  1004. /// </summary>
  1005. /// <param name="itemname"></param>
  1006. /// <param name="bj_pzname"></param>
  1007. /// <param name="inputtype"></param>
  1008. /// <param name="names"></param>
  1009. /// <returns></returns>
  1010. public u_mattress_interface_qd InserMattressInterfacePrdPf(string itemname, string bj_pzname, string namemx, int mtrlid, decimal useqty, int formulaid = 0)
  1011. {
  1012. var _bcpcompare = new u_bcpcompare() { pzname = bj_pzname };
  1013. var _wip_type = "";
  1014. var _wrkgrpcode2 = "";
  1015. if (DbSqlHelper.SelectOne(cmd, _bcpcompare, "wip_type, wrkgrpcode2") == 1)
  1016. {
  1017. _wip_type = _bcpcompare.wip_type;
  1018. _wrkgrpcode2 = _bcpcompare.wrkgrpcode2;
  1019. }
  1020. var mattress_interface_qd = new u_mattress_interface_qd()
  1021. {
  1022. itemname = itemname,
  1023. bj_pzname = bj_pzname,
  1024. bj_pzname_mx = namemx,
  1025. mtrlid = mtrlid,
  1026. useqty = useqty,
  1027. formulaid = formulaid,
  1028. wip_type = _wip_type,
  1029. wrkgrpcode2 = _wrkgrpcode2
  1030. };
  1031. return mattress_interface_qd;
  1032. }
  1033. public u_mattress_interface_qd InserMattressInterfacePrdPf(string itemname, string bj_pzname, string namemx)
  1034. {
  1035. var mattress_interface_qd = new u_mattress_interface_qd()
  1036. {
  1037. itemname = itemname,
  1038. bj_pzname = bj_pzname,
  1039. bj_pzname_mx = namemx
  1040. };
  1041. return mattress_interface_qd;
  1042. }
  1043. private void AutoSetFormulaTypeZeroPrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1044. {
  1045. var powerDict = new Dictionary<string, int[]>()
  1046. {
  1047. {"面裥绵",new int[] { 0, 40, 50, 60, 70, 80 } },
  1048. {"底裥绵",new int[] { 1, 41, 51, 61, 71, 81 } },
  1049. {"顶布裥棉1",new int[] { 0, 40, 50, 60, 70, 80 } },
  1050. {"顶布裥棉2",new int[] { 0, 40, 50, 60, 70, 80 } },
  1051. {"普通大侧",new int[] { 2, 42, 52, 62, 72, 82 } },
  1052. {"上下拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  1053. {"上下拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  1054. {"上下拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  1055. {"左右拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  1056. {"左右拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  1057. {"左右拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  1058. {"小侧1_EMPTY",new int[] { 3, 43, 53, 63, 73, 83 } },
  1059. {"小侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  1060. {"小侧1-上下拼侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  1061. {"小侧1-上下拼侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  1062. {"小侧1-上下拼侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  1063. {"小侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  1064. {"小侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  1065. {"V侧1_EMPTY",new int[] { 4, 44, 54, 64, 74, 84 } },
  1066. {"V侧1",new int[] { 4, 44, 54, 64, 74, 84 } },
  1067. {"V侧2",new int[] { 4, 44, 54, 64, 74, 84 } },
  1068. {"V侧3",new int[] { 4, 44, 54, 64, 74, 84 } }
  1069. };
  1070. var chastrArrDict = new Dictionary<string, string[]>()
  1071. {
  1072. {"面裥绵",new string[] { "裥面", "面层裥棉", "面层裥面说明" } },
  1073. {"底裥绵",new string[] { "裥底", "底层裥棉", "底层裥棉说明" } },
  1074. {"顶布裥棉1",new string[] { "顶布裥棉", "顶布裥棉1" } },
  1075. {"顶布裥棉2",new string[] { "顶布裥棉", "顶布裥棉2" } },
  1076. {"普通大侧",new string[] { "大侧", "大侧裥棉"} },
  1077. {"上下拼侧1",new string[] {"大侧", "大侧-上下拼侧1"} },
  1078. {"上下拼侧2",new string[] { "大侧", "大侧-上下拼侧2" } },
  1079. {"上下拼侧3",new string[] { "大侧", "大侧-上下拼侧3" } },
  1080. {"左右拼侧1",new string[] { "大侧", "大侧-左右拼侧1"} },
  1081. {"左右拼侧2",new string[] { "大侧", "大侧-左右拼侧2"} },
  1082. {"左右拼侧3",new string[] { "大侧", "大侧-左右拼侧3" ,"大侧说明" } },
  1083. {"小侧1_EMPTY",new string[] { "小侧", "小侧1裥棉" } },
  1084. {"小侧1",new string[] { "小侧", "小侧1裥棉"} },
  1085. {"小侧1-上下拼侧1",new string[] { "小侧", "小侧1-上下拼侧1裥棉" } },
  1086. {"小侧1-上下拼侧2",new string[] { "小侧", "小侧1-上下拼侧2裥棉" } },
  1087. {"小侧1-上下拼侧3",new string[] { "小侧", "小侧1-上下拼侧3裥棉" } },
  1088. {"小侧2",new string[] { "小侧", "小侧2裥棉", "小侧2裥棉图案" } },
  1089. {"小侧3",new string[] { "小侧", "小侧3裥棉", "小侧3裥棉图案", "小侧说明" } },
  1090. {"V侧1_EMPTY",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  1091. {"V侧1",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  1092. {"V侧2",new string[] { "V侧", "V侧2裥棉", "V侧2裥棉图案" } },
  1093. {"V侧3",new string[] { "V侧", "V侧3裥棉", "V侧3裥棉图案", "V侧说明" } }
  1094. };
  1095. var extreDict = new HashSet<string>() { "小侧", "V侧" };
  1096. var jianmianList = mxlist.Where(t => t.formulatype == 0).ToList();
  1097. var isEnter = false;
  1098. #region wf_import_qingdan_prdpf
  1099. foreach (var item in powerDict)
  1100. {
  1101. // 保证清单列表类别一致,从面裥绵 -> V侧3
  1102. foreach (var mx in jianmianList)
  1103. {
  1104. if (mx.mtrlid > 0 && (item.Key.Equals(mx.chastr) || (string.IsNullOrEmpty(mx.chastr) && item.Key.Contains("_EMPTY"))) && item.Value.Contains(mx.formulakind.Value))
  1105. {
  1106. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3 || mx.formulakind == 4)
  1107. {
  1108. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "布料", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1109. }
  1110. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43 || mx.formulakind == 44)
  1111. {
  1112. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "喷胶棉", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1113. }
  1114. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53 || mx.formulakind == 54)
  1115. {
  1116. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "裥面海绵", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1117. }
  1118. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63 || mx.formulakind == 64)
  1119. {
  1120. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "无纺布", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1121. }
  1122. }
  1123. }
  1124. if(item.Key.Contains("小侧3") || item.Key.Contains("V侧3"))
  1125. {
  1126. var list = qdList.FindAll(t => extreDict.Contains(t.itemname)).ToList();
  1127. if(list.Any())
  1128. {
  1129. foreach (var name in chastrArrDict[item.Key])
  1130. {
  1131. if (name.Contains("说明"))
  1132. {
  1133. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], name, ""));
  1134. }
  1135. }
  1136. }
  1137. } else
  1138. {
  1139. foreach (var name in chastrArrDict[item.Key])
  1140. {
  1141. if (name.Contains("说明"))
  1142. {
  1143. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], name, ""));
  1144. }
  1145. }
  1146. }
  1147. }
  1148. #endregion
  1149. #region wf_import_qingdan_next 面料部分
  1150. // 按照 formulakind 分组
  1151. var grouped = jianmianList
  1152. .Where(t => t.formulakind >= 5 && t.formulakind <= 10)
  1153. .GroupBy(t => t.formulakind);
  1154. // 需要处理的组的名称与编号映射
  1155. var groupNames = new Dictionary<int, string>
  1156. {
  1157. { 5, "拉手" },
  1158. { 6, "刺绣" },
  1159. { 7, "大侧压压布" },
  1160. { 8, "大侧压边带" },
  1161. { 9, "大侧压织带" },
  1162. { 10, "大侧压上下压线" }
  1163. };
  1164. // 处理每一组
  1165. foreach (var group in grouped)
  1166. {
  1167. var formulakind = group.Key.Value;
  1168. var name = groupNames.ContainsKey(formulakind) ? groupNames[formulakind] : "未知组";
  1169. foreach (var mx in group)
  1170. {
  1171. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  1172. {
  1173. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺",$"{name}{group.ToList().IndexOf(mx) + 1}","",
  1174. mx.mtrlid.Value,
  1175. mx.useqty.Value
  1176. ));
  1177. }
  1178. }
  1179. }
  1180. // 统一添加固定项
  1181. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "拉手刺绣", ""));
  1182. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "拉手无纺布", ""));
  1183. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "侧刺绣做法", ""));
  1184. #endregion
  1185. }
  1186. private void AutoSetFormulaTypeOnePrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1187. {
  1188. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  1189. var kindDict = new Dictionary<int, string>()
  1190. {
  1191. { 32,"垫层" },
  1192. { 12,"顶布" },
  1193. { 13,"毡类" },
  1194. { 14,"打底无纺布" },
  1195. { 29,"网面布料" },
  1196. { 999,"床网" },
  1197. {1201,"顶布裥棉" }
  1198. };
  1199. var chastrSet = new HashSet<string>() { "大侧", "小侧1", "小侧2", "小侧3", "V侧1", "V侧2", "V侧3" };
  1200. var countDict = new Dictionary<string, int>();
  1201. foreach (var cha in chastrSet)
  1202. {
  1203. foreach (var kind in kindDict)
  1204. {
  1205. countDict.Add($"{cha}-{kind.Value}", 0);
  1206. }
  1207. }
  1208. foreach (var mx in diancengList)
  1209. {
  1210. var key = $"{mx.chastr}-{kindDict[mx.formulakind.Value]}";
  1211. if (mx.mtrlid > 0 && new int[] { 32, 12, 13, 14, 29 }.Contains(mx.formulakind.Value))
  1212. {
  1213. this.ProcessWangMianBLPrdPf(mx, qdList, mx.chastr, kindDict[mx.formulakind.Value], ++countDict[key]);
  1214. } else if (mx.formulakind == 999)
  1215. {
  1216. this.ProcessChuangWangPrdPf(mx, qdList, mx.chastr, ++countDict[key]);
  1217. } else if(mx.formulakind == 1201)
  1218. {
  1219. // 不需要操作
  1220. }
  1221. }
  1222. // 顶布裥面说明
  1223. qdList.Add(InserMattressInterfacePrdPf("顶布裥棉", "顶布裥面说明1", ""));
  1224. qdList.Add(InserMattressInterfacePrdPf("顶布裥棉", "顶布裥面说明2", ""));
  1225. }
  1226. /// <summary>
  1227. /// 床网
  1228. /// </summary>
  1229. /// <param name="mx"></param>
  1230. /// <param name="interfaceList"></param>
  1231. /// <param name="chastr"></param>
  1232. /// <param name="count"></param>
  1233. private void ProcessChuangWangPrdPf(u_mattress_mx_mtrl mx, List<u_mattress_interface_qd> qdList, string chastr, int count)
  1234. {
  1235. var namepz = string.Empty;
  1236. int bednetid = 0;
  1237. cmd.CommandText = @"SELECT u_bednetmx.bednet_height,u_bednetmx.bednetid
  1238. FROM u_bednetmx
  1239. INNER JOIN (
  1240. SELECT mtrlid
  1241. FROM u_mattress_mx_mtrl
  1242. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1243. WHERE u_mattress_formula.formulakind = 99
  1244. AND u_mattress_mx_mtrl.mattressid = @mattressid
  1245. AND u_mattress_mx_mtrl.mtrlid > 0
  1246. ) v_mattress_mx_mtrl ON u_bednetmx.bednetid = v_mattress_mx_mtrl.mtrlid";
  1247. cmd.Parameters.Clear();
  1248. cmd.Parameters.AddWithValue("@mattressid", mx.mattressid);
  1249. using (var reader = cmd.ExecuteReader())
  1250. {
  1251. while (reader.Read())
  1252. {
  1253. decimal height = Convert.ToDecimal(reader["bednet_height"]);
  1254. if (height == mx.thickness) bednetid = Convert.ToInt32(reader["bednetid"]);
  1255. }
  1256. }
  1257. if (bednetid > 0)
  1258. {
  1259. // 获取床网清单
  1260. var bednetList = new List<u_bednetmx>();
  1261. if (bednetList.Any())
  1262. {
  1263. var bednetHelper = HelperBase.GetHelper<BedNetHelper>(cmd);
  1264. var bednetQdList = bednetHelper.GetBedNetQingDan(bednetid);
  1265. if (bednetQdList.Any())
  1266. {
  1267. namepz = bednetQdList[0].pznamemx;
  1268. }
  1269. }
  1270. }
  1271. qdList.Add(InserMattressInterfacePrdPf("垫层", $"{chastr}-床网{count}", namepz, mx.mtrlid.Value, mx.useqty.Value));
  1272. // 海绵条*4 2
  1273. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条1", ""));
  1274. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条2", ""));
  1275. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条3", ""));
  1276. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条4", ""));
  1277. }
  1278. /// <summary>
  1279. /// 网面布料 / 打底无纺布 / 毡类 / 顶布 / 垫层
  1280. /// </summary>
  1281. /// <param name="mx"></param>
  1282. /// <param name="interfaceList"></param>
  1283. /// <param name="chastr"></param>
  1284. /// <param name="count"></param>
  1285. private void ProcessWangMianBLPrdPf(u_mattress_mx_mtrl mx, List<u_mattress_interface_qd> qdList, string chastr, string typename, int count)
  1286. {
  1287. var mtrlname_temp = mx.mtrlname;
  1288. if ((!mx.mtrlname.Contains("分") && mx.thickness > 0) || ("垫层".Equals(typename)))
  1289. {
  1290. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  1291. }
  1292. qdList.Add(InserMattressInterfacePrdPf("垫层", $"{chastr}-{typename}{count}", "",mx.mtrlid.Value,mx.useqty.Value));
  1293. }
  1294. private void AutoSetFormulaTypeTwoPrfPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1295. {
  1296. var fuliaoList = mxlist.Where(t => t.formulatype == 2).ToList();
  1297. var nameSet = new HashSet<string>(new string[] {
  1298. "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "开箱说明+开箱刀", "吊标", "客供标",
  1299. "空白牛皮纸包角", "空白珍珠包角", "气钮","说明书","斜标","正标","织唛","织唛斜标"
  1300. });
  1301. var extraSet = new HashSet<string>(new string[] { "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "开箱说明+开箱刀", "吊标", "客供标",
  1302. "空白牛皮纸包角", "空白珍珠包角", "气钮","说明书","斜标","正标","织唛","织唛斜标","角网+拉链","开箱刀+开箱说明" });
  1303. var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });
  1304. foreach (var mx in fuliaoList)
  1305. {
  1306. if (mx.mtrlid > 0)
  1307. {
  1308. int cnt = Convert.ToInt32(Math.Abs(mx.qty.Value));
  1309. // 处理特殊辅料
  1310. if (specialSet.Contains(mx.mtrlname))
  1311. {
  1312. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}", "", mx.mtrlid.Value, mx.useqty.Value));
  1313. continue; // 跳过后续的处理
  1314. }
  1315. // 处理其他辅料
  1316. if (nameSet.Contains(mx.mtrlname))
  1317. {
  1318. for (int i = 1; i <= cnt; i++)
  1319. {
  1320. // 添加辅料接口
  1321. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}", "",mx.mtrlid.Value,mx.useqty.Value));
  1322. }
  1323. } else if(mx.formulakind == 15 && !extraSet.Contains(mx.mtrlname))
  1324. {
  1325. for (int i = 1; i <= cnt; i++)
  1326. {
  1327. // 添加辅料接口
  1328. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}", "", mx.mtrlid.Value, mx.useqty.Value));
  1329. // 如果是额外的辅料,添加位置接口
  1330. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}位置", "", mx.mtrlid.Value, mx.useqty.Value));
  1331. }
  1332. }
  1333. }
  1334. }
  1335. }
  1336. private void AutoSetFormulaTypeThreePrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1337. {
  1338. // 筛选 formulatype 为 3 的物料
  1339. var bzList = mxlist.Where(t => t.formulatype == 3).ToList();
  1340. var chastrDict = new Dictionary<int, string>
  1341. {
  1342. {16, "PE袋"},
  1343. {17, "外层PE"},
  1344. {18, "PVC"},
  1345. {19, "卷包包装"},
  1346. {20, "牛皮纸袋"},
  1347. {21, "蓝色PE护角"},
  1348. {22, "无纺布袋"},
  1349. {23, "牛皮袋护角"},
  1350. {24, "编织袋"},
  1351. {27, "拉手脚轮"},
  1352. {201, "无纺布护角"}
  1353. };
  1354. var countDict = new Dictionary<int, int>
  1355. {
  1356. {16, 0}
  1357. };
  1358. foreach (var mx in bzList)
  1359. {
  1360. if (mx.mtrlid > 0 && chastrDict.TryGetValue(mx.formulakind.GetValueOrDefault(), out var chastr))
  1361. {
  1362. var name_arr = new string[1];
  1363. if (mx.qty.HasValue && mx.qty.Value > 1)
  1364. {
  1365. name_arr[0] = $"{mx.qty.Value.ToString("#,##0.0#")}个{mx.mtrlname}";
  1366. }
  1367. else
  1368. {
  1369. name_arr[0] = mx.mtrlname;
  1370. }
  1371. if (countDict.ContainsKey(mx.formulakind.Value))
  1372. {
  1373. chastr += countDict[mx.formulakind.Value];
  1374. }
  1375. // 添加包装信息
  1376. qdList.Add(InserMattressInterfacePrdPf("包装", chastr,"",mx.mtrlid.Value,mx.useqty.Value));
  1377. }
  1378. }
  1379. // 包装说明
  1380. qdList.Add(InserMattressInterfacePrdPf("包装", "包装说明", ""));
  1381. // 车位说明
  1382. qdList.Add(InserMattressInterfacePrdPf("车位说明", "车位说明", ""));
  1383. }
  1384. private void AutoSetFormulaType101PrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1385. {
  1386. var powerDict = new Dictionary<string, int[]>()
  1387. {
  1388. {"面裥绵",new int[] { 0, 40, 50, 60, 70,80 } },
  1389. {"底裥绵",new int[] { 1, 41, 51, 61, 71 } },
  1390. {"普通大侧",new int[] { 2, 42, 52, 62, 72 } }
  1391. };
  1392. var chastrDict = new Dictionary<string, string[]>()
  1393. {
  1394. {"面裥绵",new string[] { "内布套-面层裥棉", "内布套-面层裥棉裥棉图案" } },
  1395. {"底裥绵",new string[] { "内布套-底层裥棉", "内布套-底层裥棉裥棉图案" } },
  1396. {"普通大侧",new string[] { "内布套-大侧裥棉", "内布套-大侧裥棉裥棉图案" } }
  1397. };
  1398. foreach (var item in powerDict)
  1399. {
  1400. var name_arr = new string[5];
  1401. foreach (var mx in mxlist)
  1402. {
  1403. if (mx.mtrlid > 0 && (item.Key.Equals(mx.chastr) || item.Key.Contains("_EMPTY")) && item.Value.Contains(mx.formulakind.Value))
  1404. {
  1405. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3)
  1406. {
  1407. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "布料", mx.mtrlid.Value, mx.useqty.Value));
  1408. }
  1409. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43)
  1410. {
  1411. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "喷胶棉", mx.mtrlid.Value, mx.useqty.Value));
  1412. }
  1413. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53)
  1414. {
  1415. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "裥面海绵", mx.mtrlid.Value, mx.useqty.Value));
  1416. }
  1417. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63)
  1418. {
  1419. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "无纺布", mx.mtrlid.Value, mx.useqty.Value));
  1420. }
  1421. }
  1422. }
  1423. }
  1424. // 内布套-围边边带 / 拉链
  1425. foreach (var mx in mxlist)
  1426. {
  1427. if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 203)
  1428. {
  1429. qdList.Add(InserMattressInterfacePrdPf("内布套", "内布套-围边边带", "围边",mx.mtrlid.Value,mx.useqty.Value));
  1430. }
  1431. else if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 202)
  1432. {
  1433. qdList.Add(InserMattressInterfacePrdPf("内布套", "内布套-拉链", "拉链", mx.mtrlid.Value, mx.useqty.Value));
  1434. }
  1435. }
  1436. }
  1437. #endregion
  1438. #region 床网清单
  1439. /// <summary>
  1440. /// 床垫接口-保存
  1441. /// </summary>
  1442. /// <param name="mattress"></param>
  1443. /// <param name="mxlist"></param>
  1444. /// <param name="qdlist"></param>
  1445. /// <exception cref="LJCommonException"></exception>
  1446. public void SaveBedNetInterface(u_bednet bednet, List<u_bednet_interface> mxlist, List<u_bednet_interface_qd> qdlist)
  1447. {
  1448. if (bednet.bednetid <= 0)
  1449. {
  1450. throw new LJCommonException("错误的床网id");
  1451. }
  1452. if (bednet.erp_mtrltypeid == null || bednet.erp_mtrltypeid <= 0)
  1453. {
  1454. throw new LJCommonException("请选择物料类别!");
  1455. }
  1456. if (bednet.erp_configcodetype == null || bednet.erp_configcodetype <= 0)
  1457. {
  1458. throw new LJCommonException("请选择配置类型!");
  1459. }
  1460. DbSqlHelper.Update(cmd, bednet, "erp_mtrlid,erp_mtrltypeid,erp_mtrlcode,erp_mtrlname,erp_mtrlmode,erp_mtrltype,erp_mtrlunit,erp_mtrlengname,erp_configcodetype,old_mtrlname");
  1461. // 保存接口数据
  1462. var bednetHelper = GetHelper<BedNetHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1463. bednetHelper.SaveBedNetInterface(bednet.bednetid.Value, mxlist, qdlist);
  1464. }
  1465. public List<u_bednet_interface> GetBedNetInterfaceList(int bednetid)
  1466. {
  1467. var interfaceList = new List<u_bednet_interface>();
  1468. var selectStr = @"SELECT bednetid
  1469. ,printid
  1470. ,itemname
  1471. ,bj_pzname
  1472. ,bj_namemx
  1473. ,actual_size
  1474. ,erp_pzid
  1475. ,Space(200) AS erp_pzcode
  1476. ,Space(200) AS erp_pzname
  1477. ,bj_inputtype AS erp_inputtype
  1478. FROM u_bednet_interface";
  1479. DbSqlHelper.SelectJoin(cmd, selectStr, "bednetid = @bednetid", new Dictionary<string, object>() { { "@bednetid", bednetid } }, "printid", "bednetid,printid,itemname,bj_pzname,bj_namemx,actual_size,erp_pzid,ss_rate,ls_rate,bj_inputtype", 0, 0, interfaceList);
  1480. if (interfaceList.Count <= 0)
  1481. {
  1482. interfaceList = RefreshBedNetInterfaceList(bednetid);
  1483. }
  1484. else
  1485. {
  1486. BedNetInterfaceFindERPPz(bednetid,interfaceList);
  1487. }
  1488. return interfaceList;
  1489. }
  1490. public List<u_bednet_interface> RefreshBedNetInterfaceList(int bednetid)
  1491. {
  1492. var interfaceList = new List<u_bednet_interface>();
  1493. // 导入配置
  1494. ImportBedNetInterfaceList(bednetid, interfaceList);
  1495. BedNetInterfaceFindERPPz(bednetid, interfaceList);
  1496. return interfaceList;
  1497. }
  1498. public List<u_bednet_interface> RefreshBedNetInterfaceList(int bednetid,int configcodetype)
  1499. {
  1500. var interfaceList = new List<u_bednet_interface>();
  1501. // 导入配置
  1502. ImportBedNetInterfaceList(bednetid, interfaceList);
  1503. InterfaceFindERPPz(configcodetype, interfaceList);
  1504. return interfaceList;
  1505. }
  1506. public void ImportBedNetInterfaceList(int bednetid, List<u_bednet_interface> interfaceList)
  1507. {
  1508. if (bednetid <= 0)
  1509. {
  1510. throw new LJCommonException("床网id有误");
  1511. }
  1512. var bednetHelper = GetHelper<BedNetHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1513. //var bednet = bednetHelper.GetBedNet(bednetid);
  1514. var qdlist = bednetHelper.GetBedNetQingDan(bednetid);
  1515. foreach(var qd in qdlist)
  1516. {
  1517. interfaceList.Add(InserBedNetInterfacePz("床网",qd.pzname,2,new string[] { qd.pznamemx }));
  1518. }
  1519. // 床网名称
  1520. // 床网类型 NOTES: 床网类型 袋装网需要区分x区
  1521. // 床网规格
  1522. // 床网排序
  1523. // 床网高度
  1524. // 弹簧线径/高度/口径/中心直径/圈数
  1525. // 多区弹簧1/线径/口径/中心直径/圈数
  1526. // 多区弹簧1排列数(长)
  1527. // 多区弹簧2/线径/口径/中心直径/圈数
  1528. // 多区弹簧2排列数(长)
  1529. // 多区弹簧3/线径/口径/中心直径/圈数
  1530. // 多区弹簧3排列数(长)
  1531. // 多区弹簧4/线径/口径/中心直径/圈数
  1532. // 多区弹簧4排列数(长)
  1533. // 多区弹簧5/线径/口径/中心直径/圈数
  1534. // 多区弹簧5排列数(长)
  1535. // 边铁条数
  1536. // 底面无纺布
  1537. // 入袋无纺布
  1538. // 上垫层物料
  1539. // 下垫层物料
  1540. // 四周加硬排数
  1541. // 四周加硬线径/高度/口径/中心直径/圈数
  1542. // 海绵包边物料
  1543. // 海绵包边物料厚度
  1544. // 填充海绵物料
  1545. // 填充包边物料厚度
  1546. // 封边物料
  1547. // 封边高度
  1548. // 胶条
  1549. // 包角
  1550. // 海绵打孔
  1551. // 加弹叉数量
  1552. // 15分布条
  1553. // 蛇线线径
  1554. // 四周口袋弹簧排数
  1555. // 四周口袋线径/高度/口径/中心直径/圈数
  1556. // 床网说明
  1557. // 包装方式
  1558. // 包装数量
  1559. // 包装材料
  1560. // 多区弹簧6/线径/口径/中心直径/圈数
  1561. // 多区弹簧7/线径/口径/中心直径/圈数
  1562. // 多区弹簧6排列数(长)
  1563. // 多区弹簧7排列数(长)
  1564. }
  1565. public void BedNetInterfaceFindERPPz(int bednetid, List<u_bednet_interface> interfaceList)
  1566. {
  1567. var bednet = new u_bednet() { bednetid = bednetid };
  1568. DbSqlHelper.SelectOne(cmd, bednet, "erp_configcodetype");
  1569. InterfaceFindERPPz(bednet.erp_configcodetype.Value, interfaceList);
  1570. }
  1571. public u_bednet_interface InserBedNetInterfacePz(string itemname, string bj_pzname, byte inputtype, string[] names)
  1572. {
  1573. return InserInterfacePz<u_bednet_interface>(itemname, bj_pzname, inputtype, names);
  1574. }
  1575. /// <summary>
  1576. /// 刷新床网产品配置清单
  1577. /// </summary>
  1578. /// <param name="bednetid"></param>
  1579. /// <returns></returns>
  1580. public List<u_bednet_interface_qd> RefreshBedNetInterfaceQdList(int bednetid)
  1581. {
  1582. var qdList = new List<u_bednet_interface_qd>();
  1583. ImportBedNetInterfaceQdList(bednetid, qdList);
  1584. InterfaceFindERPPrdPf<u_bednet_interface_qd, u_bednet_interface>(qdList);
  1585. return qdList;
  1586. }
  1587. /// <summary>
  1588. /// 导入产品清单
  1589. /// </summary>
  1590. /// <param name="bednetid"></param>
  1591. /// <exception cref="LJCommonException"></exception>
  1592. public void ImportBedNetInterfaceQdList(int bednetid, List<u_bednet_interface_qd> qdList)
  1593. {
  1594. if (bednetid <= 0)
  1595. {
  1596. throw new LJCommonException("床网id有误");
  1597. }
  1598. }
  1599. #endregion
  1600. #region 通用方法
  1601. /// <summary>
  1602. /// wf_fine_erp_prdpf
  1603. /// </summary>
  1604. /// <param name="qdList"></param>
  1605. /// <param name="interfaceList"></param>
  1606. public void InterfaceFindERPPrdPf<T, S>(List<T> qdList, List<S> interfaceList = null) where T : BaseInterfaceQd where S : BaseInterface
  1607. {
  1608. var mtrlidList = new List<int>();
  1609. foreach (var mx in qdList)
  1610. {
  1611. // 带出有设置 的erp_mtrlid
  1612. if (mx.erp_mtrlid == 0 && mx.mtrlid != null && mx.mtrlid > 0)
  1613. {
  1614. var mtrldef = new u_mtrl_price() { mtrlid = mx.mtrlid };
  1615. if (DbSqlHelper.SelectOne(cmd, mtrldef, "erp_mtrlid") == 1)
  1616. {
  1617. mx.erp_mtrlid = mtrldef.erp_mtrlid;
  1618. }
  1619. }
  1620. if (mx.erp_mtrlid > 0)
  1621. {
  1622. mtrlidList.Add(mx.erp_mtrlid.Value);
  1623. }
  1624. }
  1625. if (mtrlidList.Count > 0)
  1626. {
  1627. var erpHelper = HelperBase.GetHelper<ERPHelper>(null);
  1628. var total = 0;
  1629. var resultList = erpHelper.GetERPMtrldef(cmd, ref total, "", new L1Mtrldef(), 0, 0, 1, mtrlidList);
  1630. if (resultList != null && resultList.Any())
  1631. {
  1632. foreach (var mx in qdList)
  1633. {
  1634. var result = resultList.FirstOrDefault(o => o.mtrlid == mx.erp_mtrlid);
  1635. if (result != null)
  1636. {
  1637. mx.erp_mtrlcode = result.mtrlcode;
  1638. mx.erp_mtrlname = result.mtrlname;
  1639. mx.erp_mtrlmode = result.mtrlmode;
  1640. mx.erp_unit = result.unit;
  1641. mx.erp_mtrlengname = result.zxmtrlmode;
  1642. }
  1643. }
  1644. }
  1645. }
  1646. //更新 二级明细项目 需要产品配置列表,此部分由前端完成
  1647. if (interfaceList != null && interfaceList.Any())
  1648. {
  1649. // 使用 GroupBy 去重并选择第一个元素
  1650. var distinctList = interfaceList
  1651. .GroupBy(mb => mb.bj_pzname)
  1652. .Select(g => g.First())
  1653. .ToList();
  1654. Dictionary<string, S> interfaceDict = distinctList.ToDictionary(mb => mb.bj_pzname, mb => mb);
  1655. foreach (var mx in qdList)
  1656. {
  1657. if (interfaceDict.TryGetValue(mx.bj_pzname, out var mb))
  1658. {
  1659. mx.bj_pzname_mx_mx = mb.bj_namemx;
  1660. if (mx is u_mattress_interface_qd mattressMx && mb is u_mattress_interface mattressMx2)
  1661. {
  1662. if (mattressMx.ss_rate == 0) mattressMx.ss_rate = mattressMx2.ss_rate;
  1663. if (mattressMx.ls_rate == 0) mattressMx.ls_rate = mattressMx2.ls_rate;
  1664. }
  1665. }
  1666. }
  1667. }
  1668. }
  1669. /// <summary>
  1670. /// 初始化配置信息
  1671. /// </summary>
  1672. /// <param name="itemname"></param>
  1673. /// <param name="bj_pzname"></param>
  1674. /// <param name="inputtype"></param>
  1675. /// <param name="names"></param>
  1676. /// <returns></returns>
  1677. public T InserInterfacePz<T>(string itemname, string bj_pzname, byte inputtype, string[] names) where T : BaseInterface, new()
  1678. {
  1679. var mattress_interface = new T()
  1680. {
  1681. itemname = itemname,
  1682. bj_pzname = bj_pzname,
  1683. bj_inputtype = inputtype,
  1684. bj_namemx = names == null ? string.Empty : SetInterfacePzName(names)
  1685. };
  1686. return mattress_interface;
  1687. }
  1688. /// <summary>
  1689. /// 查询清单的配置
  1690. /// </summary>
  1691. /// <param name="configcodetype"></param>
  1692. /// <param name="interfaceList"></param>
  1693. public void InterfaceFindERPPz<T>(int configcodetype, List<T> interfaceList) where T : BaseInterface
  1694. {
  1695. var resultList = new List<erp_configure_code>();
  1696. var typeList = new List<erp_configure_code>();
  1697. // 特殊匹配林氏辅料
  1698. var ifLSAccessory = false;
  1699. foreach (var item in interfaceList)
  1700. {
  1701. typeList.Add(new erp_configure_code() { typeid = configcodetype, name = item.bj_pzname });
  1702. if (!ifLSAccessory && item.itemname == "辅料" && item.bj_pzname.Contains("林氏") && !item.bj_pzname.Contains("林氏定制正标"))
  1703. {
  1704. ifLSAccessory = true;
  1705. }
  1706. }
  1707. var configure_Type = new u_configure_type() { contfigtypeid = configcodetype };
  1708. if (DbSqlHelper.SelectOne(cmd, configure_Type, "contfigtypeid") == 1)
  1709. {
  1710. var names = new List<string>();
  1711. foreach (var item in typeList)
  1712. {
  1713. if (!names.Contains(item.name))
  1714. {
  1715. names.Add(item.name);
  1716. }
  1717. }
  1718. var whereStr = "";
  1719. if (ifLSAccessory)
  1720. {
  1721. whereStr = " OR u_configure_code.name like '%林氏辅料%' ";
  1722. }
  1723. // 查询核价系统的配置资料定义
  1724. cmd.CommandText = @"SELECT u_configure_code.pzid
  1725. ,u_configure_code.pzcode
  1726. ,u_configure_code.name
  1727. ,u_configure_code.inputtype
  1728. FROM u_configure_code
  1729. WHERE u_configure_code.typeid = @configcodetype
  1730. AND (u_configure_code.name IN " + ListEx.getString(names) + whereStr + " )";
  1731. cmd.Parameters.Clear();
  1732. cmd.Parameters.AddWithValue("@configcodetype", configcodetype);
  1733. using (var reader = cmd.ExecuteReader())
  1734. {
  1735. while (reader.Read())
  1736. {
  1737. var item = new erp_configure_code()
  1738. {
  1739. pzid = Convert.ToInt32(reader["pzid"]),
  1740. pzcode = Convert.ToString(reader["pzcode"]),
  1741. name = Convert.ToString(reader["name"]).Trim(),
  1742. inputtype = Convert.ToInt32(reader["inputtype"])
  1743. };
  1744. resultList.Add(item);
  1745. }
  1746. }
  1747. }
  1748. else
  1749. {
  1750. // 查询L1部件选配
  1751. var erpHelper = GetHelper<ERPHelper>(null);
  1752. var parameters = new JObject();
  1753. parameters.Add("typeList", JToken.FromObject(typeList));
  1754. resultList = erpHelper.GetERPList<erp_configure_code>("GetL1ConfigureCode", parameters);
  1755. }
  1756. var LSIndex = 0;
  1757. for (var i = 0; i < interfaceList.Count; i++)
  1758. {
  1759. interfaceList[i].printid = i + 1;
  1760. var matchState = false;
  1761. foreach (var result in resultList)
  1762. {
  1763. if (interfaceList[i].bj_pzname == result.name)
  1764. {
  1765. matchState = true;
  1766. if (result.pzid > 0)
  1767. {
  1768. interfaceList[i].erp_pzid = result.pzid;
  1769. interfaceList[i].erp_pzcode = result.pzcode;
  1770. interfaceList[i].erp_pzname = result.name;
  1771. }
  1772. //if (interfaceList[i].bj_inputtype != 2)
  1773. interfaceList[i].bj_inputtype = result.inputtype;
  1774. }
  1775. }
  1776. if (ifLSAccessory && !matchState && interfaceList[i].itemname == "辅料" && interfaceList[i].bj_pzname.Contains("林氏") && !interfaceList[i].bj_pzname.Contains("林氏定制正标"))
  1777. {
  1778. if (!interfaceList[i].bj_pzname.Contains("位置"))
  1779. {
  1780. LSIndex++;
  1781. }
  1782. foreach (var result in resultList)
  1783. {
  1784. var _pzname = string.Format("林氏辅料{0}{1}", LSIndex, interfaceList[i].bj_pzname.Contains("位置") ? "位置" : "");
  1785. if (result.name == _pzname)
  1786. {
  1787. matchState = true;
  1788. if (result.pzid > 0)
  1789. {
  1790. interfaceList[i].erp_pzid = result.pzid;
  1791. interfaceList[i].erp_pzcode = result.pzcode;
  1792. interfaceList[i].erp_pzname = result.name;
  1793. }
  1794. if (interfaceList[i].bj_inputtype != 2) interfaceList[i].bj_inputtype = result.inputtype;
  1795. }
  1796. }
  1797. }
  1798. }
  1799. }
  1800. /// <summary>
  1801. /// 用于 字符串 + 字符串格式
  1802. /// </summary>
  1803. /// <param name="currentString"></param>
  1804. /// <param name="newPart"></param>
  1805. /// <returns></returns>
  1806. private string AppendToString(string currentString, string newPart)
  1807. {
  1808. if (string.IsNullOrEmpty(currentString))
  1809. {
  1810. return newPart;
  1811. }
  1812. else
  1813. {
  1814. return currentString + " + " + newPart;
  1815. }
  1816. }
  1817. /// <summary>
  1818. /// 数量分割字符串
  1819. /// </summary>
  1820. /// <param name="name"></param>
  1821. /// <param name="qty"></param>
  1822. /// <returns></returns>
  1823. private string SplitNameCount(string name, int qty)
  1824. {
  1825. if (qty <= 1) return name;
  1826. var result = name;
  1827. result = AppendToString(result, SplitNameCount(name, --qty));
  1828. return result;
  1829. }
  1830. #endregion
  1831. #region 全局变量
  1832. // 储存顶布裥棉数据
  1833. private string[,] DingBuLianMian = new string[4,5];
  1834. private enum PackType
  1835. {
  1836. 压包 = 0,
  1837. 卷包,
  1838. 国内
  1839. }
  1840. #endregion
  1841. }
  1842. }