InterfaceHelper.cs 78 KB

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