InterfaceHelper.cs 78 KB

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