InterfaceHelper.cs 78 KB

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