InterfaceHelper.cs 80 KB

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