InterfaceHelper.cs 80 KB

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