InterfaceHelper.cs 108 KB

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