InterfaceHelper.cs 94 KB

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