InterfaceHelper.cs 78 KB

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