InterfaceHelper.cs 94 KB

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