InterfaceHelper.cs 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  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 extraSet = new HashSet<string>(new string[] { "采购小标", "打印小标", "合格证", "吊标", "斜标", "正标", "织唛", "织唛斜标", "客供标" });
  781. var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });
  782. foreach (var mx in fuliaoList)
  783. {
  784. if (mx.mtrlid > 0)
  785. {
  786. int cnt = Convert.ToInt32(Math.Abs(mx.qty.Value));
  787. var mtrldef = new u_mtrl_price() { mtrlid = mx.mtrlid };
  788. if (DbSqlHelper.SelectOne(cmd, mtrldef, "erp_mtrlid") == 1)
  789. {
  790. mx.erp_mtrlid = mtrldef.erp_mtrlid;
  791. }
  792. // 处理特殊辅料
  793. if (specialSet.Contains(mx.mtrlname))
  794. {
  795. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}", 1, new string[] { $"{cnt.ToString("#,##0.0#")}个" }));
  796. continue; // 跳过后续的处理
  797. }
  798. // 处理其他辅料
  799. if (nameSet.Contains(mx.mtrlname))
  800. {
  801. for (int i = 1; i <= cnt; i++)
  802. {
  803. // 添加辅料接口
  804. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}", 1, new string[] { "" }));
  805. // 如果是额外的辅料,添加位置接口
  806. if (extraSet.Contains(mx.mtrlname))
  807. {
  808. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}位置", 0, new string[] { "" }));
  809. }
  810. }
  811. }else if(mx.formulakind == 15 && !nameSet.Contains(mx.mtrlname))
  812. {
  813. for (int i = 1; i <= cnt; i++)
  814. {
  815. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}", 1, new string[] { "" }));
  816. interfaceList.Add(InserMattressInterfacePz("辅料", $"{mx.mtrlname}{i}位置", 0, new string[] { "" }));
  817. }
  818. }
  819. }
  820. }
  821. }
  822. private void AutoSetFormulaTypeThreePz(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  823. {
  824. // 筛选 formulatype 为 3 的物料
  825. var bzList = mxlist.Where(t => t.formulatype == 3).ToList();
  826. var chastrDict = new Dictionary<int, string>
  827. {
  828. {16, "PE袋"},
  829. {17, "外层PE"},
  830. {18, "PVC"},
  831. {19, "卷包包装"},
  832. {20, "牛皮纸袋"},
  833. {21, "蓝色PE护角"},
  834. {22, "无纺布袋"},
  835. {23, "牛皮袋护角"},
  836. {24, "编织袋"},
  837. {27, "拉手脚轮"},
  838. {201, "无纺布护角"}
  839. };
  840. // 判断是否多物料
  841. var formulaList = new List<u_mattress_formula>();
  842. DbSqlHelper.Select(cmd, "u_mattress_formula", "formulatype = 3 AND if_mtrl = 2",null, "formulakind", 0,0, formulaList, null, "formulakind");
  843. var countDict = new Dictionary<int, int>();
  844. foreach (var formula in formulaList)
  845. {
  846. if (!countDict.ContainsKey(formula.formulakind.Value)) countDict.Add(formula.formulakind.Value, 1);
  847. }
  848. // 外观
  849. interfaceList.Add(InserMattressInterfacePz("床垫", "包装方式", 1, new string[] { Enum.GetName(typeof(PackType), mattress.packtype) }));
  850. foreach (var mx in bzList)
  851. {
  852. if (mx.mtrlid > 0 && chastrDict.TryGetValue(mx.formulakind.GetValueOrDefault(), out var chastr))
  853. {
  854. var name_arr = new string[1];
  855. if (mx.qty.HasValue && mx.qty.Value > 1)
  856. {
  857. name_arr[0] = $"{mx.qty.Value.ToString("#,##0.0#")}个{mx.mtrlname}";
  858. }
  859. else
  860. {
  861. name_arr[0] = mx.mtrlname;
  862. }
  863. if (countDict.ContainsKey(mx.formulakind.Value))
  864. {
  865. chastr += countDict[mx.formulakind.Value]++;
  866. }
  867. // 添加包装信息
  868. interfaceList.Add(InserMattressInterfacePz("包装", chastr, 2, name_arr));
  869. }
  870. }
  871. // 压包数量
  872. interfaceList.Add(InserMattressInterfacePz("包装", "压包数量", 1, new string[] { $"{mattress.packqty.Value.ToString("#,##0.0#")}" }));
  873. // 包装说明
  874. interfaceList.Add(InserMattressInterfacePz("包装", "包装说明", 1, new string[] { "" }));
  875. // 压包说明
  876. if (mattress.packqty.HasValue && mattress.packqty.Value > 0) interfaceList.Add(InserMattressInterfacePz("包装", "压包说明", 1, new string[] { "" }));
  877. // 卷包说明
  878. if (mattress.diameter.HasValue && mattress.diameter.Value > 0) interfaceList.Add(InserMattressInterfacePz("包装", "卷包说明", 1, new string[] { "" }));
  879. }
  880. private void AutoSetFormulaType101Pz(u_mattress mattress, List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface> interfaceList)
  881. {
  882. var powerDict = new Dictionary<string, int[]>()
  883. {
  884. {"面裥绵",new int[] { 0, 40, 50, 60, 70 } },
  885. {"底裥绵",new int[] { 1, 41, 51, 61, 71 } },
  886. {"普通大侧",new int[] { 2, 42, 52, 62, 72 } }
  887. };
  888. var chastrDict = new Dictionary<string, string[]>()
  889. {
  890. {"面裥绵",new string[] { "内布套-面层裥棉", "内布套-面层裥棉裥棉图案" } },
  891. {"底裥绵",new string[] { "内布套-底层裥棉", "内布套-底层裥棉裥棉图案" } },
  892. {"普通大侧",new string[] { "内布套-大侧裥棉", "内布套-大侧裥棉裥棉图案" } }
  893. };
  894. foreach (var item in powerDict)
  895. {
  896. var name_arr = new string[5];
  897. foreach (var mx in mxlist)
  898. {
  899. SetFormulaTypeZeroPzName(mx, "内布套", item.Value, name_arr);
  900. }
  901. var sb = new StringBuilder();
  902. foreach (var name2 in name_arr)
  903. {
  904. sb.Append(name2);
  905. }
  906. if (sb.Length > 0)
  907. {
  908. interfaceList.Add(InserMattressInterfacePz("内布套", chastrDict[item.Key][0], 2, name_arr));
  909. interfaceList.Add(InserMattressInterfacePz("内布套", chastrDict[item.Key][1], 1, new string[] { "" }));
  910. }
  911. }
  912. // 内布套-围边边带 / 拉链
  913. foreach (var mx in mxlist)
  914. {
  915. if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 203)
  916. {
  917. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套-围边边带", 2, new string[] { $"{mx.thickness.Value.ToString("#,##0.0#")}条共{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  918. }
  919. else if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 202)
  920. {
  921. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套-拉链", 2, new string[] { $"{mx.thickness.Value.ToString("#,##0.0#")}条共{mx.qty.Value.ToString("#,##0.0#")}米{mx.mtrlname}" }));
  922. }
  923. }
  924. var butaostring = new string[] { };
  925. if (mattress.if_n_butao == 1)
  926. {
  927. 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" };
  928. interfaceList.Add(InserMattressInterfacePz("内布套", "内布套做法说明", 1, butaostring));
  929. }
  930. }
  931. #endregion
  932. #region 导入清单方法
  933. public List<u_mattress_interface_qd> RefreshMattressInterfaceQdList(int mattressid)
  934. {
  935. var qdList = new List<u_mattress_interface_qd>();
  936. ImportMattressInterfaceQdList(mattressid, qdList);
  937. MattressInterfaceFindERPPrdPf(qdList,null);
  938. return qdList;
  939. }
  940. /// <summary>
  941. /// wf_fine_erp_prdpf
  942. /// </summary>
  943. /// <param name="qdList"></param>
  944. /// <param name="interfaceList"></param>
  945. public void MattressInterfaceFindERPPrdPf(List<u_mattress_interface_qd> qdList,List<u_mattress_interface> interfaceList = null)
  946. {
  947. InterfaceFindERPPrdPf(qdList,interfaceList);
  948. }
  949. /// <summary>
  950. /// 导入产品清单
  951. /// </summary>
  952. /// <param name="mattressid"></param>
  953. /// <exception cref="LJCommonException"></exception>
  954. public void ImportMattressInterfaceQdList(int mattressid, List<u_mattress_interface_qd> qdList)
  955. {
  956. if (mattressid <= 0)
  957. {
  958. throw new LJCommonException("床垫id有误");
  959. }
  960. var mattressHelper = GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  961. var mattress = mattressHelper.GetMattress(mattressid);
  962. var mattress_type = new u_mattress_type() { mattresstypeid = mattress.mattresstypeid };
  963. DbSqlHelper.SelectOne(cmd, mattress_type, "typename");
  964. var mxlist = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype IN (0,1,2,3,99,104)" });
  965. var mxlist_103 = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype = 103" });
  966. var mxlist_101 = mattressHelper.GetMattressMxMtrl(mattressid, new List<string>() { "u_mattress_formula.formulatype = 101" });
  967. #region 面料类清单导入
  968. AutoSetFormulaTypeZeroPrdPf(mxlist, qdList);
  969. #endregion
  970. #region 垫层类清单导入
  971. AutoSetFormulaTypeOnePrdPf(mxlist, qdList);
  972. #endregion
  973. #region 辅料类清单导入
  974. AutoSetFormulaTypeTwoPrfPf(mxlist, qdList);
  975. #endregion
  976. #region 包装类清单导入
  977. AutoSetFormulaTypeThreePrdPf(mxlist, qdList);
  978. #endregion
  979. #region 内布套类清单导入
  980. AutoSetFormulaType101PrdPf(mxlist_103, qdList);
  981. #endregion
  982. // 最后初始化interfaceList的printid
  983. for (var i = 0; i < qdList.Count; i++)
  984. {
  985. qdList[i].printid = i + 1;
  986. }
  987. }
  988. /// <summary>
  989. /// 初始化清单信息
  990. /// </summary>
  991. /// <param name="itemname"></param>
  992. /// <param name="bj_pzname"></param>
  993. /// <param name="inputtype"></param>
  994. /// <param name="names"></param>
  995. /// <returns></returns>
  996. public u_mattress_interface_qd InserMattressInterfacePrdPf(string itemname, string bj_pzname, string namemx, int mtrlid, decimal useqty, int formulaid = 0)
  997. {
  998. var _bcpcompare = new u_bcpcompare() { pzname = bj_pzname };
  999. var _wip_type = "";
  1000. var _wrkgrpcode2 = "";
  1001. if (DbSqlHelper.SelectOne(cmd, _bcpcompare, "wip_type, wrkgrpcode2") == 1)
  1002. {
  1003. _wip_type = _bcpcompare.wip_type;
  1004. _wrkgrpcode2 = _bcpcompare.wrkgrpcode2;
  1005. }
  1006. var mattress_interface_qd = new u_mattress_interface_qd()
  1007. {
  1008. itemname = itemname,
  1009. bj_pzname = bj_pzname,
  1010. bj_pzname_mx = namemx,
  1011. mtrlid = mtrlid,
  1012. useqty = useqty,
  1013. formulaid = formulaid,
  1014. wip_type = _wip_type,
  1015. wrkgrpcode2 = _wrkgrpcode2
  1016. };
  1017. return mattress_interface_qd;
  1018. }
  1019. public u_mattress_interface_qd InserMattressInterfacePrdPf(string itemname, string bj_pzname, string namemx)
  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. };
  1027. return mattress_interface_qd;
  1028. }
  1029. private void AutoSetFormulaTypeZeroPrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1030. {
  1031. var powerDict = new Dictionary<string, int[]>()
  1032. {
  1033. {"面裥绵",new int[] { 0, 40, 50, 60, 70, 80 } },
  1034. {"底裥绵",new int[] { 1, 41, 51, 61, 71, 81 } },
  1035. {"顶布裥棉1",new int[] { 0, 40, 50, 60, 70, 80 } },
  1036. {"顶布裥棉2",new int[] { 0, 40, 50, 60, 70, 80 } },
  1037. {"普通大侧",new int[] { 2, 42, 52, 62, 72, 82 } },
  1038. {"上下拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  1039. {"上下拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  1040. {"上下拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  1041. {"左右拼侧1",new int[] { 2, 42, 52, 62, 72, 82 } },
  1042. {"左右拼侧2",new int[] { 2, 42, 52, 62, 72, 82 } },
  1043. {"左右拼侧3",new int[] { 2, 42, 52, 62, 72, 82 } },
  1044. {"小侧1_EMPTY",new int[] { 3, 43, 53, 63, 73, 83 } },
  1045. {"小侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  1046. {"小侧1-上下拼侧1",new int[] { 3, 43, 53, 63, 73, 83 } },
  1047. {"小侧1-上下拼侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  1048. {"小侧1-上下拼侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  1049. {"小侧2",new int[] { 3, 43, 53, 63, 73, 83 } },
  1050. {"小侧3",new int[] { 3, 43, 53, 63, 73, 83 } },
  1051. {"V侧1_EMPTY",new int[] { 4, 44, 54, 64, 74, 84 } },
  1052. {"V侧1",new int[] { 4, 44, 54, 64, 74, 84 } },
  1053. {"V侧2",new int[] { 4, 44, 54, 64, 74, 84 } },
  1054. {"V侧3",new int[] { 4, 44, 54, 64, 74, 84 } }
  1055. };
  1056. var chastrArrDict = new Dictionary<string, string[]>()
  1057. {
  1058. {"面裥绵",new string[] { "裥面", "面层裥棉", "面层裥面说明" } },
  1059. {"底裥绵",new string[] { "裥底", "底层裥棉", "底层裥棉说明" } },
  1060. {"顶布裥棉1",new string[] { "顶布裥棉", "顶布裥棉1" } },
  1061. {"顶布裥棉2",new string[] { "顶布裥棉", "顶布裥棉2" } },
  1062. {"普通大侧",new string[] { "大侧", "大侧裥棉"} },
  1063. {"上下拼侧1",new string[] {"大侧", "大侧-上下拼侧1"} },
  1064. {"上下拼侧2",new string[] { "大侧", "大侧-上下拼侧2" } },
  1065. {"上下拼侧3",new string[] { "大侧", "大侧-上下拼侧3" } },
  1066. {"左右拼侧1",new string[] { "大侧", "大侧-左右拼侧1"} },
  1067. {"左右拼侧2",new string[] { "大侧", "大侧-左右拼侧2"} },
  1068. {"左右拼侧3",new string[] { "大侧", "大侧-左右拼侧3" ,"大侧说明" } },
  1069. {"小侧1_EMPTY",new string[] { "小侧", "小侧1裥棉" } },
  1070. {"小侧1",new string[] { "小侧", "小侧1裥棉"} },
  1071. {"小侧1-上下拼侧1",new string[] { "小侧", "小侧1-上下拼侧1裥棉" } },
  1072. {"小侧1-上下拼侧2",new string[] { "小侧", "小侧1-上下拼侧2裥棉" } },
  1073. {"小侧1-上下拼侧3",new string[] { "小侧", "小侧1-上下拼侧3裥棉" } },
  1074. {"小侧2",new string[] { "小侧", "小侧2裥棉", "小侧2裥棉图案" } },
  1075. {"小侧3",new string[] { "小侧", "小侧3裥棉", "小侧3裥棉图案", "小侧说明" } },
  1076. {"V侧1_EMPTY",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  1077. {"V侧1",new string[] { "V侧", "V侧1裥棉", "V侧1裥棉图案" } },
  1078. {"V侧2",new string[] { "V侧", "V侧2裥棉", "V侧2裥棉图案" } },
  1079. {"V侧3",new string[] { "V侧", "V侧3裥棉", "V侧3裥棉图案", "V侧说明" } }
  1080. };
  1081. var extreDict = new HashSet<string>() { "小侧", "V侧" };
  1082. var jianmianList = mxlist.Where(t => t.formulatype == 0).ToList();
  1083. var isEnter = false;
  1084. #region wf_import_qingdan_prdpf
  1085. foreach (var item in powerDict)
  1086. {
  1087. // 保证清单列表类别一致,从面裥绵 -> V侧3
  1088. foreach (var mx in jianmianList)
  1089. {
  1090. if (mx.mtrlid > 0 && (item.Key.Equals(mx.chastr) || (string.IsNullOrEmpty(mx.chastr) && item.Key.Contains("_EMPTY"))) && item.Value.Contains(mx.formulakind.Value))
  1091. {
  1092. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3 || mx.formulakind == 4)
  1093. {
  1094. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "布料", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1095. }
  1096. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43 || mx.formulakind == 44)
  1097. {
  1098. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "喷胶棉", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1099. }
  1100. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53 || mx.formulakind == 54)
  1101. {
  1102. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "裥面海绵", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1103. }
  1104. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63 || mx.formulakind == 64)
  1105. {
  1106. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], chastrArrDict[item.Key][1], "无纺布", mx.mtrlid.Value, mx.useqty.Value, mx.formulaid.Value));
  1107. }
  1108. }
  1109. }
  1110. if(item.Key.Contains("小侧3") || item.Key.Contains("V侧3"))
  1111. {
  1112. var list = qdList.FindAll(t => extreDict.Contains(t.itemname)).ToList();
  1113. if(list.Any())
  1114. {
  1115. foreach (var name in chastrArrDict[item.Key])
  1116. {
  1117. if (name.Contains("说明"))
  1118. {
  1119. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], name, ""));
  1120. }
  1121. }
  1122. }
  1123. } else
  1124. {
  1125. foreach (var name in chastrArrDict[item.Key])
  1126. {
  1127. if (name.Contains("说明"))
  1128. {
  1129. qdList.Add(InserMattressInterfacePrdPf(chastrArrDict[item.Key][0], name, ""));
  1130. }
  1131. }
  1132. }
  1133. }
  1134. #endregion
  1135. #region wf_import_qingdan_next 面料部分
  1136. // 按照 formulakind 分组
  1137. var grouped = jianmianList
  1138. .Where(t => t.formulakind >= 5 && t.formulakind <= 10)
  1139. .GroupBy(t => t.formulakind);
  1140. // 需要处理的组的名称与编号映射
  1141. var groupNames = new Dictionary<int, string>
  1142. {
  1143. { 5, "拉手" },
  1144. { 6, "刺绣" },
  1145. { 7, "大侧压压布" },
  1146. { 8, "大侧压边带" },
  1147. { 9, "大侧压织带" },
  1148. { 10, "大侧压上下压线" }
  1149. };
  1150. // 处理每一组
  1151. foreach (var group in grouped)
  1152. {
  1153. var formulakind = group.Key.Value;
  1154. var name = groupNames.ContainsKey(formulakind) ? groupNames[formulakind] : "未知组";
  1155. foreach (var mx in group)
  1156. {
  1157. if (string.IsNullOrEmpty(mx.chastr) && mx.mtrlid > 0)
  1158. {
  1159. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺",$"{name}{group.ToList().IndexOf(mx) + 1}","",
  1160. mx.mtrlid.Value,
  1161. mx.useqty.Value
  1162. ));
  1163. }
  1164. }
  1165. }
  1166. // 统一添加固定项
  1167. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "拉手刺绣", ""));
  1168. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "拉手无纺布", ""));
  1169. qdList.Add(InserMattressInterfacePrdPf("拉手刺绣及其他工艺", "侧刺绣做法", ""));
  1170. #endregion
  1171. }
  1172. private void AutoSetFormulaTypeOnePrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1173. {
  1174. var diancengList = mxlist.Where(t => t.formulatype == 1).ToList();
  1175. var kindDict = new Dictionary<int, string>()
  1176. {
  1177. { 32,"垫层" },
  1178. { 12,"顶布" },
  1179. { 13,"毡类" },
  1180. { 14,"打底无纺布" },
  1181. { 29,"网面布料" },
  1182. { 999,"床网" },
  1183. {1201,"顶布裥棉" }
  1184. };
  1185. var chastrSet = new HashSet<string>() { "大侧", "小侧1", "小侧2", "小侧3", "V侧1", "V侧2", "V侧3" };
  1186. var countDict = new Dictionary<string, int>();
  1187. foreach (var cha in chastrSet)
  1188. {
  1189. foreach (var kind in kindDict)
  1190. {
  1191. countDict.Add($"{cha}-{kind.Value}", 0);
  1192. }
  1193. }
  1194. foreach (var mx in diancengList)
  1195. {
  1196. var key = $"{mx.chastr}-{kindDict[mx.formulakind.Value]}";
  1197. if (mx.mtrlid > 0 && new int[] { 32, 12, 13, 14, 29 }.Contains(mx.formulakind.Value))
  1198. {
  1199. this.ProcessWangMianBLPrdPf(mx, qdList, mx.chastr, kindDict[mx.formulakind.Value], ++countDict[key]);
  1200. } else if (mx.formulakind == 999)
  1201. {
  1202. this.ProcessChuangWangPrdPf(mx, qdList, mx.chastr, ++countDict[key]);
  1203. } else if(mx.formulakind == 1201)
  1204. {
  1205. // 不需要操作
  1206. }
  1207. }
  1208. // 顶布裥面说明
  1209. qdList.Add(InserMattressInterfacePrdPf("顶布裥棉", "顶布裥面说明1", ""));
  1210. qdList.Add(InserMattressInterfacePrdPf("顶布裥棉", "顶布裥面说明2", ""));
  1211. }
  1212. /// <summary>
  1213. /// 床网
  1214. /// </summary>
  1215. /// <param name="mx"></param>
  1216. /// <param name="interfaceList"></param>
  1217. /// <param name="chastr"></param>
  1218. /// <param name="count"></param>
  1219. private void ProcessChuangWangPrdPf(u_mattress_mx_mtrl mx, List<u_mattress_interface_qd> qdList, string chastr, int count)
  1220. {
  1221. var namepz = string.Empty;
  1222. int bednetid = 0;
  1223. cmd.CommandText = @"SELECT u_bednetmx.bednet_height,u_bednetmx.bednetid
  1224. FROM u_bednetmx
  1225. INNER JOIN (
  1226. SELECT mtrlid
  1227. FROM u_mattress_mx_mtrl
  1228. INNER JOIN u_mattress_formula ON u_mattress_formula.formulaid = u_mattress_mx_mtrl.formulaid
  1229. WHERE u_mattress_formula.formulakind = 99
  1230. AND u_mattress_mx_mtrl.mattressid = @mattressid
  1231. AND u_mattress_mx_mtrl.mtrlid > 0
  1232. ) v_mattress_mx_mtrl ON u_bednetmx.bednetid = v_mattress_mx_mtrl.mtrlid";
  1233. cmd.Parameters.Clear();
  1234. cmd.Parameters.AddWithValue("@mattressid", mx.mattressid);
  1235. using (var reader = cmd.ExecuteReader())
  1236. {
  1237. while (reader.Read())
  1238. {
  1239. decimal height = Convert.ToDecimal(reader["bednet_height"]);
  1240. if (height == mx.thickness) bednetid = Convert.ToInt32(reader["bednetid"]);
  1241. }
  1242. }
  1243. if (bednetid > 0)
  1244. {
  1245. // 获取床网清单
  1246. var bednetList = new List<u_bednetmx>();
  1247. if (bednetList.Any())
  1248. {
  1249. var bednetHelper = HelperBase.GetHelper<BedNetHelper>(cmd);
  1250. var bednetQdList = bednetHelper.GetBedNetQingDan(bednetid);
  1251. if (bednetQdList.Any())
  1252. {
  1253. namepz = bednetQdList[0].pznamemx;
  1254. }
  1255. }
  1256. }
  1257. qdList.Add(InserMattressInterfacePrdPf("垫层", $"{chastr}-床网{count}", namepz, mx.mtrlid.Value, mx.useqty.Value));
  1258. // 海绵条*4 2
  1259. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条1", ""));
  1260. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条2", ""));
  1261. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条3", ""));
  1262. qdList.Add(InserMattressInterfacePrdPf("垫层", "海绵条4", ""));
  1263. }
  1264. /// <summary>
  1265. /// 网面布料 / 打底无纺布 / 毡类 / 顶布 / 垫层
  1266. /// </summary>
  1267. /// <param name="mx"></param>
  1268. /// <param name="interfaceList"></param>
  1269. /// <param name="chastr"></param>
  1270. /// <param name="count"></param>
  1271. private void ProcessWangMianBLPrdPf(u_mattress_mx_mtrl mx, List<u_mattress_interface_qd> qdList, string chastr, string typename, int count)
  1272. {
  1273. var mtrlname_temp = mx.mtrlname;
  1274. if ((!mx.mtrlname.Contains("分") && mx.thickness > 0) || ("垫层".Equals(typename)))
  1275. {
  1276. mtrlname_temp = $"{mx.thickness.Value.ToString("#,##0.0#")}分{mx.mtrlname}";
  1277. }
  1278. qdList.Add(InserMattressInterfacePrdPf("垫层", $"{chastr}-{typename}{count}", "",mx.mtrlid.Value,mx.useqty.Value));
  1279. }
  1280. private void AutoSetFormulaTypeTwoPrfPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1281. {
  1282. var fuliaoList = mxlist.Where(t => t.formulatype == 2).ToList();
  1283. var nameSet = new HashSet<string>(new string[] {
  1284. "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "开箱说明+开箱刀", "吊标", "客供标",
  1285. "空白牛皮纸包角", "空白珍珠包角", "气钮","说明书","斜标","正标","织唛","织唛斜标"
  1286. });
  1287. var extraSet = new HashSet<string>(new string[] { "保用卡", "采购小标", "打钮钮扣", "打印小标", "合格证", "画纸", "开箱说明+开箱刀", "吊标", "客供标",
  1288. "空白牛皮纸包角", "空白珍珠包角", "气钮","说明书","斜标","正标","织唛","织唛斜标","角网+拉链","开箱刀+开箱说明" });
  1289. var specialSet = new HashSet<string>(new string[] { "打钮钮扣", "气钮" });
  1290. foreach (var mx in fuliaoList)
  1291. {
  1292. if (mx.mtrlid > 0)
  1293. {
  1294. int cnt = Convert.ToInt32(Math.Abs(mx.qty.Value));
  1295. // 处理特殊辅料
  1296. if (specialSet.Contains(mx.mtrlname))
  1297. {
  1298. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}", "", mx.mtrlid.Value, mx.useqty.Value));
  1299. continue; // 跳过后续的处理
  1300. }
  1301. // 处理其他辅料
  1302. if (nameSet.Contains(mx.mtrlname))
  1303. {
  1304. for (int i = 1; i <= cnt; i++)
  1305. {
  1306. // 添加辅料接口
  1307. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}", "",mx.mtrlid.Value,mx.useqty.Value));
  1308. }
  1309. } else if(mx.formulakind == 15 && !extraSet.Contains(mx.mtrlname))
  1310. {
  1311. for (int i = 1; i <= cnt; i++)
  1312. {
  1313. // 添加辅料接口
  1314. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}", "", mx.mtrlid.Value, mx.useqty.Value));
  1315. // 如果是额外的辅料,添加位置接口
  1316. qdList.Add(InserMattressInterfacePrdPf("辅料", $"{mx.mtrlname}{i}位置", "", mx.mtrlid.Value, mx.useqty.Value));
  1317. }
  1318. }
  1319. }
  1320. }
  1321. }
  1322. private void AutoSetFormulaTypeThreePrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1323. {
  1324. // 筛选 formulatype 为 3 的物料
  1325. var bzList = mxlist.Where(t => t.formulatype == 3).ToList();
  1326. var chastrDict = new Dictionary<int, string>
  1327. {
  1328. {16, "PE袋"},
  1329. {17, "外层PE"},
  1330. {18, "PVC"},
  1331. {19, "卷包包装"},
  1332. {20, "牛皮纸袋"},
  1333. {21, "蓝色PE护角"},
  1334. {22, "无纺布袋"},
  1335. {23, "牛皮袋护角"},
  1336. {24, "编织袋"},
  1337. {27, "拉手脚轮"},
  1338. {201, "无纺布护角"}
  1339. };
  1340. var countDict = new Dictionary<int, int>
  1341. {
  1342. {16, 0}
  1343. };
  1344. foreach (var mx in bzList)
  1345. {
  1346. if (mx.mtrlid > 0 && chastrDict.TryGetValue(mx.formulakind.GetValueOrDefault(), out var chastr))
  1347. {
  1348. var name_arr = new string[1];
  1349. if (mx.qty.HasValue && mx.qty.Value > 1)
  1350. {
  1351. name_arr[0] = $"{mx.qty.Value.ToString("#,##0.0#")}个{mx.mtrlname}";
  1352. }
  1353. else
  1354. {
  1355. name_arr[0] = mx.mtrlname;
  1356. }
  1357. if (countDict.ContainsKey(mx.formulakind.Value))
  1358. {
  1359. chastr += countDict[mx.formulakind.Value];
  1360. }
  1361. // 添加包装信息
  1362. qdList.Add(InserMattressInterfacePrdPf("包装", chastr,"",mx.mtrlid.Value,mx.useqty.Value));
  1363. }
  1364. }
  1365. // 包装说明
  1366. qdList.Add(InserMattressInterfacePrdPf("包装", "包装说明", ""));
  1367. // 车位说明
  1368. qdList.Add(InserMattressInterfacePrdPf("车位说明", "车位说明", ""));
  1369. }
  1370. private void AutoSetFormulaType101PrdPf(List<u_mattress_mx_mtrl> mxlist, List<u_mattress_interface_qd> qdList)
  1371. {
  1372. var powerDict = new Dictionary<string, int[]>()
  1373. {
  1374. {"面裥绵",new int[] { 0, 40, 50, 60, 70,80 } },
  1375. {"底裥绵",new int[] { 1, 41, 51, 61, 71 } },
  1376. {"普通大侧",new int[] { 2, 42, 52, 62, 72 } }
  1377. };
  1378. var chastrDict = new Dictionary<string, string[]>()
  1379. {
  1380. {"面裥绵",new string[] { "内布套-面层裥棉", "内布套-面层裥棉裥棉图案" } },
  1381. {"底裥绵",new string[] { "内布套-底层裥棉", "内布套-底层裥棉裥棉图案" } },
  1382. {"普通大侧",new string[] { "内布套-大侧裥棉", "内布套-大侧裥棉裥棉图案" } }
  1383. };
  1384. foreach (var item in powerDict)
  1385. {
  1386. var name_arr = new string[5];
  1387. foreach (var mx in mxlist)
  1388. {
  1389. if (mx.mtrlid > 0 && (item.Key.Equals(mx.chastr) || item.Key.Contains("_EMPTY")) && item.Value.Contains(mx.formulakind.Value))
  1390. {
  1391. if (mx.formulakind == 0 || mx.formulakind == 1 || mx.formulakind == 2 || mx.formulakind == 3)
  1392. {
  1393. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "布料", mx.mtrlid.Value, mx.useqty.Value));
  1394. }
  1395. if (mx.formulakind == 40 || mx.formulakind == 41 || mx.formulakind == 42 || mx.formulakind == 43)
  1396. {
  1397. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "喷胶棉", mx.mtrlid.Value, mx.useqty.Value));
  1398. }
  1399. if (mx.formulakind == 50 || mx.formulakind == 51 || mx.formulakind == 52 || mx.formulakind == 53)
  1400. {
  1401. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "裥面海绵", mx.mtrlid.Value, mx.useqty.Value));
  1402. }
  1403. if (mx.formulakind == 60 || mx.formulakind == 61 || mx.formulakind == 62 || mx.formulakind == 63)
  1404. {
  1405. qdList.Add(InserMattressInterfacePrdPf(chastrDict[item.Key][0], chastrDict[item.Key][1], "无纺布", mx.mtrlid.Value, mx.useqty.Value));
  1406. }
  1407. }
  1408. }
  1409. }
  1410. // 内布套-围边边带 / 拉链
  1411. foreach (var mx in mxlist)
  1412. {
  1413. if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 203)
  1414. {
  1415. qdList.Add(InserMattressInterfacePrdPf("内布套", "内布套-围边边带", "围边",mx.mtrlid.Value,mx.useqty.Value));
  1416. }
  1417. else if (mx.mtrlid > 0 && "内布套".Equals(mx.chastr) && mx.formulakind == 202)
  1418. {
  1419. qdList.Add(InserMattressInterfacePrdPf("内布套", "内布套-拉链", "拉链", mx.mtrlid.Value, mx.useqty.Value));
  1420. }
  1421. }
  1422. }
  1423. #endregion
  1424. #region 床网清单
  1425. /// <summary>
  1426. /// 床垫接口-保存
  1427. /// </summary>
  1428. /// <param name="mattress"></param>
  1429. /// <param name="mxlist"></param>
  1430. /// <param name="qdlist"></param>
  1431. /// <exception cref="LJCommonException"></exception>
  1432. public void SaveBedNetInterface(u_bednet bednet, List<u_bednet_interface> mxlist, List<u_bednet_interface_qd> qdlist)
  1433. {
  1434. if (bednet.bednetid <= 0)
  1435. {
  1436. throw new LJCommonException("错误的床网id");
  1437. }
  1438. if (bednet.erp_mtrltypeid == null || bednet.erp_mtrltypeid <= 0)
  1439. {
  1440. throw new LJCommonException("请选择物料类别!");
  1441. }
  1442. if (bednet.erp_configcodetype == null || bednet.erp_configcodetype <= 0)
  1443. {
  1444. throw new LJCommonException("请选择配置类型!");
  1445. }
  1446. DbSqlHelper.Update(cmd, bednet, "erp_mtrlid,erp_mtrltypeid,erp_mtrlcode,erp_mtrlname,erp_mtrlmode,erp_mtrltype,erp_mtrlunit,erp_mtrlengname,erp_configcodetype,old_mtrlname");
  1447. // 保存接口数据
  1448. var bednetHelper = GetHelper<BedNetHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1449. bednetHelper.SaveBedNetInterface(bednet.bednetid.Value, mxlist, qdlist);
  1450. }
  1451. public List<u_bednet_interface> GetBedNetInterfaceList(int bednetid)
  1452. {
  1453. var interfaceList = new List<u_bednet_interface>();
  1454. var selectStr = @"SELECT bednetid
  1455. ,printid
  1456. ,itemname
  1457. ,bj_pzname
  1458. ,bj_namemx
  1459. ,actual_size
  1460. ,erp_pzid
  1461. ,Space(200) AS erp_pzcode
  1462. ,Space(200) AS erp_pzname
  1463. ,bj_inputtype AS erp_inputtype
  1464. FROM u_bednet_interface";
  1465. 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);
  1466. if (interfaceList.Count <= 0)
  1467. {
  1468. interfaceList = RefreshBedNetInterfaceList(bednetid);
  1469. }
  1470. else
  1471. {
  1472. BedNetInterfaceFindERPPz(bednetid,interfaceList);
  1473. }
  1474. return interfaceList;
  1475. }
  1476. public List<u_bednet_interface> RefreshBedNetInterfaceList(int bednetid)
  1477. {
  1478. var interfaceList = new List<u_bednet_interface>();
  1479. // 导入配置
  1480. ImportBedNetInterfaceList(bednetid, interfaceList);
  1481. BedNetInterfaceFindERPPz(bednetid, interfaceList);
  1482. return interfaceList;
  1483. }
  1484. public List<u_bednet_interface> RefreshBedNetInterfaceList(int bednetid,int configcodetype)
  1485. {
  1486. var interfaceList = new List<u_bednet_interface>();
  1487. // 导入配置
  1488. ImportBedNetInterfaceList(bednetid, interfaceList);
  1489. InterfaceFindERPPz(configcodetype, interfaceList);
  1490. return interfaceList;
  1491. }
  1492. public void ImportBedNetInterfaceList(int bednetid, List<u_bednet_interface> interfaceList)
  1493. {
  1494. if (bednetid <= 0)
  1495. {
  1496. throw new LJCommonException("床网id有误");
  1497. }
  1498. var bednetHelper = GetHelper<BedNetHelper>(cmd, new HelperBase.Context() { tokendata = context.tokendata });
  1499. //var bednet = bednetHelper.GetBedNet(bednetid);
  1500. var qdlist = bednetHelper.GetBedNetQingDan(bednetid);
  1501. foreach(var qd in qdlist)
  1502. {
  1503. interfaceList.Add(InserBedNetInterfacePz("床网",qd.pzname,2,new string[] { qd.pznamemx }));
  1504. }
  1505. // 床网名称
  1506. // 床网类型 NOTES: 床网类型 袋装网需要区分x区
  1507. // 床网规格
  1508. // 床网排序
  1509. // 床网高度
  1510. // 弹簧线径/高度/口径/中心直径/圈数
  1511. // 多区弹簧1/线径/口径/中心直径/圈数
  1512. // 多区弹簧1排列数(长)
  1513. // 多区弹簧2/线径/口径/中心直径/圈数
  1514. // 多区弹簧2排列数(长)
  1515. // 多区弹簧3/线径/口径/中心直径/圈数
  1516. // 多区弹簧3排列数(长)
  1517. // 多区弹簧4/线径/口径/中心直径/圈数
  1518. // 多区弹簧4排列数(长)
  1519. // 多区弹簧5/线径/口径/中心直径/圈数
  1520. // 多区弹簧5排列数(长)
  1521. // 边铁条数
  1522. // 底面无纺布
  1523. // 入袋无纺布
  1524. // 上垫层物料
  1525. // 下垫层物料
  1526. // 四周加硬排数
  1527. // 四周加硬线径/高度/口径/中心直径/圈数
  1528. // 海绵包边物料
  1529. // 海绵包边物料厚度
  1530. // 填充海绵物料
  1531. // 填充包边物料厚度
  1532. // 封边物料
  1533. // 封边高度
  1534. // 胶条
  1535. // 包角
  1536. // 海绵打孔
  1537. // 加弹叉数量
  1538. // 15分布条
  1539. // 蛇线线径
  1540. // 四周口袋弹簧排数
  1541. // 四周口袋线径/高度/口径/中心直径/圈数
  1542. // 床网说明
  1543. // 包装方式
  1544. // 包装数量
  1545. // 包装材料
  1546. // 多区弹簧6/线径/口径/中心直径/圈数
  1547. // 多区弹簧7/线径/口径/中心直径/圈数
  1548. // 多区弹簧6排列数(长)
  1549. // 多区弹簧7排列数(长)
  1550. }
  1551. public void BedNetInterfaceFindERPPz(int bednetid, List<u_bednet_interface> interfaceList)
  1552. {
  1553. var bednet = new u_bednet() { bednetid = bednetid };
  1554. DbSqlHelper.SelectOne(cmd, bednet, "erp_configcodetype");
  1555. InterfaceFindERPPz(bednet.erp_configcodetype.Value, interfaceList);
  1556. }
  1557. public u_bednet_interface InserBedNetInterfacePz(string itemname, string bj_pzname, byte inputtype, string[] names)
  1558. {
  1559. return InserInterfacePz<u_bednet_interface>(itemname, bj_pzname, inputtype, names);
  1560. }
  1561. /// <summary>
  1562. /// 刷新床网产品配置清单
  1563. /// </summary>
  1564. /// <param name="bednetid"></param>
  1565. /// <returns></returns>
  1566. public List<u_bednet_interface_qd> RefreshBedNetInterfaceQdList(int bednetid)
  1567. {
  1568. var qdList = new List<u_bednet_interface_qd>();
  1569. ImportBedNetInterfaceQdList(bednetid, qdList);
  1570. InterfaceFindERPPrdPf<u_bednet_interface_qd, u_bednet_interface>(qdList);
  1571. return qdList;
  1572. }
  1573. /// <summary>
  1574. /// 导入产品清单
  1575. /// </summary>
  1576. /// <param name="bednetid"></param>
  1577. /// <exception cref="LJCommonException"></exception>
  1578. public void ImportBedNetInterfaceQdList(int bednetid, List<u_bednet_interface_qd> qdList)
  1579. {
  1580. if (bednetid <= 0)
  1581. {
  1582. throw new LJCommonException("床网id有误");
  1583. }
  1584. }
  1585. #endregion
  1586. #region 通用方法
  1587. /// <summary>
  1588. /// wf_fine_erp_prdpf
  1589. /// </summary>
  1590. /// <param name="qdList"></param>
  1591. /// <param name="interfaceList"></param>
  1592. public void InterfaceFindERPPrdPf<T, S>(List<T> qdList, List<S> interfaceList = null) where T : BaseInterfaceQd where S : BaseInterface
  1593. {
  1594. var mtrlidList = new List<int>();
  1595. foreach (var mx in qdList)
  1596. {
  1597. // 带出有设置 的erp_mtrlid
  1598. if (mx.erp_mtrlid == 0 && mx.mtrlid != null && mx.mtrlid > 0)
  1599. {
  1600. var mtrldef = new u_mtrl_price() { mtrlid = mx.mtrlid };
  1601. if (DbSqlHelper.SelectOne(cmd, mtrldef, "erp_mtrlid") == 1)
  1602. {
  1603. mx.erp_mtrlid = mtrldef.erp_mtrlid;
  1604. }
  1605. }
  1606. if (mx.erp_mtrlid > 0)
  1607. {
  1608. mtrlidList.Add(mx.erp_mtrlid.Value);
  1609. }
  1610. }
  1611. if (mtrlidList.Count > 0)
  1612. {
  1613. var erpHelper = HelperBase.GetHelper<ERPHelper>(null);
  1614. var total = 0;
  1615. var resultList = erpHelper.GetERPMtrldef(cmd, ref total, "", new L1Mtrldef(), 0, 0, 1, mtrlidList);
  1616. if (resultList != null && resultList.Any())
  1617. {
  1618. foreach (var mx in qdList)
  1619. {
  1620. var result = resultList.FirstOrDefault(o => o.mtrlid == mx.erp_mtrlid);
  1621. if (result != null)
  1622. {
  1623. mx.erp_mtrlcode = result.mtrlcode;
  1624. mx.erp_mtrlname = result.mtrlname;
  1625. mx.erp_mtrlmode = result.mtrlmode;
  1626. mx.erp_unit = result.unit;
  1627. mx.erp_mtrlengname = result.zxmtrlmode;
  1628. }
  1629. }
  1630. }
  1631. }
  1632. //更新 二级明细项目 需要产品配置列表,此部分由前端完成
  1633. if (interfaceList != null && interfaceList.Any())
  1634. {
  1635. // 使用 GroupBy 去重并选择第一个元素
  1636. var distinctList = interfaceList
  1637. .GroupBy(mb => mb.bj_pzname)
  1638. .Select(g => g.First())
  1639. .ToList();
  1640. Dictionary<string, S> interfaceDict = distinctList.ToDictionary(mb => mb.bj_pzname, mb => mb);
  1641. foreach (var mx in qdList)
  1642. {
  1643. if (interfaceDict.TryGetValue(mx.bj_pzname, out var mb))
  1644. {
  1645. mx.bj_pzname_mx_mx = mb.bj_namemx;
  1646. if (mx is u_mattress_interface_qd mattressMx && mb is u_mattress_interface mattressMx2)
  1647. {
  1648. if (mattressMx.ss_rate == 0) mattressMx.ss_rate = mattressMx2.ss_rate;
  1649. if (mattressMx.ls_rate == 0) mattressMx.ls_rate = mattressMx2.ls_rate;
  1650. }
  1651. }
  1652. }
  1653. }
  1654. }
  1655. /// <summary>
  1656. /// 初始化配置信息
  1657. /// </summary>
  1658. /// <param name="itemname"></param>
  1659. /// <param name="bj_pzname"></param>
  1660. /// <param name="inputtype"></param>
  1661. /// <param name="names"></param>
  1662. /// <returns></returns>
  1663. public T InserInterfacePz<T>(string itemname, string bj_pzname, byte inputtype, string[] names) where T : BaseInterface, new()
  1664. {
  1665. var mattress_interface = new T()
  1666. {
  1667. itemname = itemname,
  1668. bj_pzname = bj_pzname,
  1669. bj_inputtype = inputtype,
  1670. bj_namemx = names == null ? string.Empty : SetInterfacePzName(names)
  1671. };
  1672. return mattress_interface;
  1673. }
  1674. /// <summary>
  1675. /// 查询清单的配置
  1676. /// </summary>
  1677. /// <param name="configcodetype"></param>
  1678. /// <param name="interfaceList"></param>
  1679. public void InterfaceFindERPPz<T>(int configcodetype, List<T> interfaceList) where T : BaseInterface
  1680. {
  1681. var resultList = new List<erp_configure_code>();
  1682. var typeList = new List<erp_configure_code>();
  1683. // 特殊匹配林氏辅料
  1684. var ifLSAccessory = false;
  1685. foreach (var item in interfaceList)
  1686. {
  1687. typeList.Add(new erp_configure_code() { typeid = configcodetype, name = item.bj_pzname });
  1688. if (!ifLSAccessory && item.itemname == "辅料" && item.bj_pzname.Contains("林氏") && !item.bj_pzname.Contains("林氏定制正标"))
  1689. {
  1690. ifLSAccessory = true;
  1691. }
  1692. }
  1693. var configure_Type = new u_configure_type() { contfigtypeid = configcodetype };
  1694. if (DbSqlHelper.SelectOne(cmd, configure_Type, "contfigtypeid") == 1)
  1695. {
  1696. var names = new List<string>();
  1697. foreach (var item in typeList)
  1698. {
  1699. if (!names.Contains(item.name))
  1700. {
  1701. names.Add(item.name);
  1702. }
  1703. }
  1704. var whereStr = "";
  1705. if (ifLSAccessory)
  1706. {
  1707. whereStr = " OR u_configure_code.name like '%林氏辅料%' ";
  1708. }
  1709. // 查询核价系统的配置资料定义
  1710. cmd.CommandText = @"SELECT u_configure_code.pzid
  1711. ,u_configure_code.pzcode
  1712. ,u_configure_code.name
  1713. ,u_configure_code.inputtype
  1714. FROM u_configure_code
  1715. WHERE u_configure_code.typeid = @configcodetype
  1716. AND (u_configure_code.name IN " + ListEx.getString(names) + whereStr + " )";
  1717. cmd.Parameters.Clear();
  1718. cmd.Parameters.AddWithValue("@configcodetype", configcodetype);
  1719. using (var reader = cmd.ExecuteReader())
  1720. {
  1721. while (reader.Read())
  1722. {
  1723. var item = new erp_configure_code()
  1724. {
  1725. pzid = Convert.ToInt32(reader["pzid"]),
  1726. pzcode = Convert.ToString(reader["pzcode"]),
  1727. name = Convert.ToString(reader["name"]).Trim(),
  1728. inputtype = Convert.ToInt32(reader["inputtype"])
  1729. };
  1730. resultList.Add(item);
  1731. }
  1732. }
  1733. }
  1734. else
  1735. {
  1736. // 查询L1部件选配
  1737. var erpHelper = GetHelper<ERPHelper>(null);
  1738. var parameters = new JObject();
  1739. parameters.Add("typeList", JToken.FromObject(typeList));
  1740. resultList = erpHelper.GetERPList<erp_configure_code>("GetL1ConfigureCode", parameters);
  1741. }
  1742. var LSIndex = 0;
  1743. for (var i = 0; i < interfaceList.Count; i++)
  1744. {
  1745. interfaceList[i].printid = i + 1;
  1746. var matchState = false;
  1747. foreach (var result in resultList)
  1748. {
  1749. if (interfaceList[i].bj_pzname == result.name)
  1750. {
  1751. matchState = true;
  1752. if (result.pzid > 0)
  1753. {
  1754. interfaceList[i].erp_pzid = result.pzid;
  1755. interfaceList[i].erp_pzcode = result.pzcode;
  1756. interfaceList[i].erp_pzname = result.name;
  1757. }
  1758. if (interfaceList[i].bj_inputtype != 2) interfaceList[i].bj_inputtype = result.inputtype;
  1759. }
  1760. }
  1761. if (ifLSAccessory && !matchState && interfaceList[i].itemname == "辅料" && interfaceList[i].bj_pzname.Contains("林氏") && !interfaceList[i].bj_pzname.Contains("林氏定制正标"))
  1762. {
  1763. if (!interfaceList[i].bj_pzname.Contains("位置"))
  1764. {
  1765. LSIndex++;
  1766. }
  1767. foreach (var result in resultList)
  1768. {
  1769. var _pzname = string.Format("林氏辅料{0}{1}", LSIndex, interfaceList[i].bj_pzname.Contains("位置") ? "位置" : "");
  1770. if (result.name == _pzname)
  1771. {
  1772. matchState = true;
  1773. if (result.pzid > 0)
  1774. {
  1775. interfaceList[i].erp_pzid = result.pzid;
  1776. interfaceList[i].erp_pzcode = result.pzcode;
  1777. interfaceList[i].erp_pzname = result.name;
  1778. }
  1779. if (interfaceList[i].bj_inputtype != 2) interfaceList[i].bj_inputtype = result.inputtype;
  1780. }
  1781. }
  1782. }
  1783. }
  1784. }
  1785. /// <summary>
  1786. /// 用于 字符串 + 字符串格式
  1787. /// </summary>
  1788. /// <param name="currentString"></param>
  1789. /// <param name="newPart"></param>
  1790. /// <returns></returns>
  1791. private string AppendToString(string currentString, string newPart)
  1792. {
  1793. if (string.IsNullOrEmpty(currentString))
  1794. {
  1795. return newPart;
  1796. }
  1797. else
  1798. {
  1799. return currentString + " + " + newPart;
  1800. }
  1801. }
  1802. /// <summary>
  1803. /// 数量分割字符串
  1804. /// </summary>
  1805. /// <param name="name"></param>
  1806. /// <param name="qty"></param>
  1807. /// <returns></returns>
  1808. private string SplitNameCount(string name, int qty)
  1809. {
  1810. if (qty <= 1) return name;
  1811. var result = name;
  1812. result = AppendToString(result, SplitNameCount(name, --qty));
  1813. return result;
  1814. }
  1815. #endregion
  1816. #region 全局变量
  1817. // 储存顶布裥棉数据
  1818. private string[,] DingBuLianMian = new string[4,5];
  1819. private enum PackType
  1820. {
  1821. 压包 = 0,
  1822. 卷包,
  1823. 国内
  1824. }
  1825. #endregion
  1826. }
  1827. }