InterfaceHelper.cs 108 KB

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