InterfaceHelper.cs 94 KB

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