InterfaceHelper.cs 76 KB

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