GetMattressImportDW2Excutor.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using DirectService.Tools;
  7. using JLHHJSvr.BLL;
  8. using JLHHJSvr.Com;
  9. using JLHHJSvr.Com.Model;
  10. using JLHHJSvr.Helper;
  11. using JLHHJSvr.LJException;
  12. using JLHHJSvr.Tools;
  13. using LJLib.DAL.SQL;
  14. using LJLib.Net.SPI.Server;
  15. namespace JLHHJSvr.Excutor
  16. {
  17. internal sealed class GetMattressImportDW2Excutor : ExcutorBase<GetMattressImportDW2Request, GetMattressImportDW2Response>
  18. {
  19. protected override void ExcuteInternal(GetMattressImportDW2Request request, object state, GetMattressImportDW2Response rslt)
  20. {
  21. var tokendata = BllHelper.GetToken(request.token);
  22. if (tokendata == null)
  23. {
  24. rslt.ErrMsg = "会话已经中断,请重新登录";
  25. return;
  26. }
  27. if (request.mattresstypeid == 0)
  28. {
  29. rslt.ErrMsg = "床垫类别不能为0";
  30. return;
  31. }
  32. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  33. using (var cmd = con.CreateCommand())
  34. {
  35. con.Open();
  36. // 初始化属性
  37. //foreach (var mx in request.mattressMx)
  38. //{
  39. // AutoInit.AutoInitS(cmd, mx);
  40. //}
  41. using (cmd.Transaction = con.BeginTransaction())
  42. {
  43. var mattersstype = new u_mattress_type() { mattresstypeid = request.mattresstypeid };
  44. DbSqlHelper.SelectOne(cmd, mattersstype, "biandaiqty, if_top_side, if_button_sdie, if_big_side, if_small_side, if_v_side, if_in_cloth_cover, if_out_cloth_cover, if_small_side2, if_small_side3, if_v_side2, if_v_side3, dianceng_sort, dianceng_area");
  45. rslt.biandai_qty = mattersstype.biandaiqty;
  46. AutoInit.AutoInitS(cmd, mattersstype);
  47. var selectStr = @"
  48. SELECT formulaid
  49. ,formulakind
  50. ,formulatype
  51. ,sortcode
  52. ,if_mtrl
  53. ,formula
  54. ,usetype
  55. ,if_packtype0
  56. ,if_packtype1
  57. ,if_packtype2
  58. ,default_mtrlid
  59. ,createtime
  60. ,createby
  61. ,useformula
  62. ,gydscrp
  63. ,mtrltype
  64. FROM u_mattress_formula";
  65. var outFields = "formulaid, formulakind, formulatype, sortcode, if_mtrl, formula, usetype, if_packtype0, if_packtype1, if_packtype2, default_mtrlid, createtime, createby, useformula, gydscrp, mtrltype";
  66. var whereList = new List<string>();
  67. whereList.Add("u_mattress_formula.formulatype IN (0, 1, 2, 3, 99, 104)");
  68. whereList.Add("u_mattress_formula.usetype = @usetype");
  69. var param = new Dictionary<string, object>();
  70. // 导入 0-通用类型 的公式
  71. param.Add("@usetype", 0);
  72. var mattressFormulaList0 = new List<u_mattress_formula>();
  73. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "formulatype, sortcode", outFields, 0, 0, mattressFormulaList0);
  74. var dw_2 = new List<u_mattress_mx_mtrl>();
  75. foreach (var mx in mattressFormulaList0)
  76. {
  77. if (new[] { 11, 12, 32, 33, 13, 14, 29, 999, 1201 }.Contains(mx.formulakind.Value)) continue;
  78. var newDw2 = new u_mattress_mx_mtrl();
  79. AutoInit.AutoInitS(newDw2);
  80. if (mx.if_mtrl > 1)
  81. {
  82. newDw2.addmx = "+";
  83. newDw2.delmx = "-";
  84. }
  85. newDw2.formulatype = mx.formulatype;
  86. newDw2.if_mtrl = mx.if_mtrl;
  87. newDw2.formulaid = mx.formulaid;
  88. newDw2.sortcode = mx.sortcode;
  89. newDw2.formulakind = mx.formulakind;
  90. newDw2.formula = mx.formula;
  91. newDw2.useformula = mx.useformula;
  92. newDw2.gydscrp = mx.gydscrp;
  93. dw_2.Add(newDw2);
  94. }
  95. // 导入 1-按床垫类别 的公式
  96. var mattressFormulaList1 = new List<u_mattress_formula>();
  97. param.Clear();
  98. param.Add("@usetype", 1);
  99. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "formulatype, sortcode", outFields, 0, 0, mattressFormulaList1);
  100. foreach (var mx in mattressFormulaList1)
  101. {
  102. var ls_chastr = "";
  103. if (request.ifbcptype == 1)
  104. {
  105. if (new[] { 0, 40, 50, 60, 70, 80, 1, 41, 51, 61, 71, 81, 2, 42, 52, 62, 72, 82, 3, 43, 53, 63, 73, 83, 4, 44, 54, 64, 74, 84 }.Contains(mx.formulakind.Value))
  106. {
  107. continue;
  108. }
  109. }
  110. if (new[] { 0, 40, 50, 60, 70, 80 }.Contains(mx.formulakind.Value))
  111. {
  112. ls_chastr = "面裥绵";
  113. if (mattersstype.if_top_side == 0) continue;
  114. }
  115. if (new[] { 1, 41, 51, 61, 71, 81 }.Contains(mx.formulakind.Value))
  116. {
  117. ls_chastr = "底裥绵";
  118. if (mattersstype.if_button_sdie == 0) continue;
  119. }
  120. if (new[] { 2, 42, 52, 62, 72, 82 }.Contains(mx.formulakind.Value))
  121. {
  122. ls_chastr = "普通大侧";
  123. if (mattersstype.if_big_side == 0) continue;
  124. }
  125. if (new[] { 3, 43, 53, 63, 73, 83 }.Contains(mx.formulakind.Value))
  126. {
  127. ls_chastr = "小侧1";
  128. if (mattersstype.if_small_side == 0) continue;
  129. }
  130. if (new[] { 4, 44, 54, 64, 74, 84 }.Contains(mx.formulakind.Value))
  131. {
  132. ls_chastr = "V侧1";
  133. if (mattersstype.if_v_side == 0) continue;
  134. }
  135. if (new[] { 101, 102, 103, 104, 105, 106 }.Contains(mx.formulakind.Value))
  136. {
  137. if (mattersstype.if_in_cloth_cover == 0) continue;
  138. }
  139. if (new[] { 111, 112, 113, 114, 115, 116 }.Contains(mx.formulakind.Value))
  140. {
  141. if (mattersstype.if_out_cloth_cover == 0) continue;
  142. }
  143. var newDw2 = new u_mattress_mx_mtrl();
  144. AutoInit.AutoInitS(newDw2);
  145. if (mx.if_mtrl > 1)
  146. {
  147. newDw2.addmx = "+";
  148. newDw2.delmx = "-";
  149. }
  150. newDw2.formulatype = mx.formulatype;
  151. newDw2.if_mtrl = mx.if_mtrl;
  152. newDw2.formulaid = mx.formulaid;
  153. newDw2.sortcode = mx.sortcode;
  154. newDw2.formulakind = mx.formulakind;
  155. newDw2.formula = mx.formula;
  156. newDw2.chastr = ls_chastr;
  157. newDw2.useformula = mx.useformula;
  158. newDw2.gydscrp = mx.gydscrp;
  159. dw_2.Add(newDw2);
  160. }
  161. // 导入 2-按包装方式 的公式
  162. var mattressFormulaList2 = new List<u_mattress_formula>();
  163. param.Clear();
  164. param.Add("@usetype", 2);
  165. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "formulatype, sortcode", outFields, 0, 0, mattressFormulaList2);
  166. foreach (var mx in mattressFormulaList2)
  167. {
  168. if (request.packtype == 0 && mx.if_packtype0 != 1) continue;
  169. if (request.packtype == 1 && mx.if_packtype1 != 1) continue;
  170. if (request.packtype == 2 && mx.if_packtype2 != 1) continue;
  171. var newDw2 = new u_mattress_mx_mtrl();
  172. AutoInit.AutoInitS(newDw2);
  173. if (mx.if_mtrl > 1)
  174. {
  175. newDw2.addmx = "+";
  176. newDw2.delmx = "-";
  177. }
  178. newDw2.formulatype = mx.formulatype;
  179. newDw2.if_mtrl = mx.if_mtrl;
  180. newDw2.formulaid = mx.formulaid;
  181. newDw2.sortcode = mx.sortcode;
  182. newDw2.formulakind = mx.formulakind;
  183. newDw2.formula = mx.formula;
  184. newDw2.useformula = mx.useformula;
  185. newDw2.gydscrp = mx.gydscrp;
  186. dw_2.Add(newDw2);
  187. }
  188. //加多一个 小侧2
  189. if (mattersstype.if_small_side2 == 1 && request.ifbcptype == 0)
  190. {
  191. wf_add_side(cmd, new[] { 3, 83, 43, 53, 63, 73 }, "小侧2", ref dw_2);
  192. }
  193. //加多一个 小侧3
  194. if (mattersstype.if_small_side3 == 1 && request.ifbcptype == 0)
  195. {
  196. wf_add_side(cmd, new[] { 3, 83, 43, 53, 63, 73 }, "小侧3", ref dw_2);
  197. }
  198. //加多一个 V侧2
  199. if (mattersstype.if_v_side2 == 1 && request.ifbcptype == 0)
  200. {
  201. wf_add_side(cmd, new[] { 4, 84, 44, 54, 64, 74 }, "V侧2", ref dw_2);
  202. }
  203. //加多一个 V侧3
  204. if (mattersstype.if_v_side3 == 1 && request.ifbcptype == 0)
  205. {
  206. wf_add_side(cmd, new[] { 4, 84, 44, 54, 64, 74 }, "V侧3", ref dw_2);
  207. }
  208. // 在 床垫类型 定义里面 按垫层默认配置 自动带出 垫层配置 和 垫层可选项
  209. if (!string.IsNullOrEmpty(mattersstype.dianceng_sort))
  210. {
  211. wf_add_dianceng_bytype(cmd, mattersstype.dianceng_sort, ref dw_2);
  212. }
  213. rslt.diancengarea = new List<replacement>();
  214. if (!string.IsNullOrEmpty(mattersstype.dianceng_area))
  215. {
  216. rslt.diancengarea = wf_add_dianceng_area_bytype(cmd, mattersstype.dianceng_area);
  217. }
  218. // u_mattress_formula_formulatype A xu A u_mattress_formula_sortcode A u_mattress_mx_mtrl_formulaid A
  219. dw_2.Sort((a, b) =>
  220. {
  221. if (a.formulatype != b.formulatype)
  222. {
  223. return a.formulatype.Value.CompareTo(b.formulatype.Value);
  224. }
  225. if (a.xu != b.xu)
  226. {
  227. return a.xu.Value.CompareTo(b.xu.Value);
  228. }
  229. if (a.sortcode != b.sortcode)
  230. {
  231. return a.sortcode.CompareTo(b.sortcode);
  232. }
  233. return a.formulaid.Value.CompareTo(b.formulaid.Value);
  234. });
  235. rslt.mattressMx = dw_2;
  236. }
  237. }
  238. }
  239. private void wf_add_side(SqlCommand cmd, int[] formulakindList, string arg_name, ref List<u_mattress_mx_mtrl> dw_2)
  240. {
  241. foreach(int ll_formulakind in formulakindList)
  242. {
  243. cmd.CommandText = @"SELECT TOP 1
  244. formulatype,
  245. formulaid,
  246. sortcode,
  247. formula,
  248. if_mtrl,
  249. useformula,
  250. gydscrp
  251. FROM u_mattress_formula
  252. WHERE formulakind = @formulakind
  253. AND u_mattress_formula.formulatype in (0,1,2,3)";
  254. cmd.Parameters.Clear();
  255. cmd.Parameters.AddWithValue("@formulakind", ll_formulakind);
  256. using (var reader = cmd.ExecuteReader())
  257. {
  258. if (reader.Read())
  259. {
  260. var newDw2 = new u_mattress_mx_mtrl();
  261. AutoInit.AutoInitS(newDw2);
  262. if (Convert.ToInt32(reader["if_mtrl"]) > 1)
  263. {
  264. newDw2.addmx = "+";
  265. newDw2.delmx = "-";
  266. }
  267. newDw2.formulatype = Convert.ToInt32(reader["formulatype"]);
  268. newDw2.if_mtrl = Convert.ToInt32(reader["if_mtrl"]);
  269. newDw2.formulaid = Convert.ToInt32(reader["formulaid"]);
  270. newDw2.sortcode = arg_name;
  271. newDw2.formulakind = ll_formulakind;
  272. newDw2.formula = Convert.ToString(reader["formula"]);
  273. newDw2.chastr = arg_name;
  274. newDw2.useformula = Convert.ToString(reader["useformula"]);
  275. newDw2.gydscrp = Convert.ToString(reader["gydscrp"]);
  276. dw_2.Add(newDw2);
  277. }
  278. }
  279. }
  280. }
  281. private void wf_add_dianceng_bytype(SqlCommand cmd, string dianceng_sort, ref List<u_mattress_mx_mtrl> dw_2)
  282. {
  283. var arg_dianceng_sort = dianceng_sort.Replace(",", " , ");
  284. arg_dianceng_sort = arg_dianceng_sort.Replace("~r~n", "");
  285. arg_dianceng_sort = arg_dianceng_sort.Replace("~r", "");
  286. arg_dianceng_sort = arg_dianceng_sort.Replace("~n", "");
  287. //var ls_pzsplitstr_arr = f_pb_split(arg_dianceng_sort, "/");
  288. var ls_pzsplitstr_arr = arg_dianceng_sort.Split('/');
  289. string arg_left_str, arg_right_str;
  290. int ll_formulakind;
  291. int index = 0;
  292. foreach (var ls_pzsplitstr in ls_pzsplitstr_arr)
  293. {
  294. index++;
  295. arg_left_str = "";
  296. arg_right_str = "";
  297. wf_get_str(ls_pzsplitstr, ref arg_left_str, ref arg_right_str);
  298. switch(arg_left_str)
  299. {
  300. case "垫层":
  301. ll_formulakind = 32;
  302. break;
  303. case "床网":
  304. ll_formulakind = 999;
  305. break;
  306. case "顶布":
  307. ll_formulakind = 12;
  308. break;
  309. case "毡类":
  310. ll_formulakind = 13;
  311. break;
  312. case "打底无纺布":
  313. ll_formulakind = 14;
  314. break;
  315. case "网面布料":
  316. ll_formulakind = 29;
  317. break;
  318. default:
  319. ll_formulakind = -1;
  320. break;
  321. }
  322. if (ll_formulakind == -1) continue;
  323. cmd.CommandText = @"SELECT TOP 1
  324. formulatype,
  325. formulaid,
  326. sortcode,
  327. formula,
  328. if_mtrl,
  329. useformula,
  330. gydscrp
  331. FROM u_mattress_formula
  332. WHERE formulakind = @formulakind
  333. AND u_mattress_formula.formulatype in (0,1,2,3)";
  334. cmd.Parameters.Clear();
  335. cmd.Parameters.AddWithValue("@formulakind", ll_formulakind);
  336. using (var reader = cmd.ExecuteReader())
  337. {
  338. if (reader.Read())
  339. {
  340. var newDw2 = new u_mattress_mx_mtrl();
  341. AutoInit.AutoInitS(newDw2);
  342. if (Convert.ToInt32(reader["if_mtrl"]) > 1)
  343. {
  344. newDw2.addmx = "+";
  345. newDw2.delmx = "-";
  346. }
  347. newDw2.formulatype = Convert.ToInt32(reader["formulatype"]);
  348. newDw2.if_mtrl = 2;
  349. newDw2.formulaid = Convert.ToInt32(reader["formulaid"]);
  350. newDw2.sortcode = Convert.ToString(reader["sortcode"]);
  351. newDw2.formulakind = ll_formulakind;
  352. newDw2.formula = Convert.ToString(reader["formula"]);
  353. newDw2.chastr = wf_set_area_text(arg_right_str);
  354. newDw2.qty = 1;
  355. newDw2.xu = index;
  356. newDw2.useformula = Convert.ToString(reader["useformula"]);
  357. newDw2.gydscrp = Convert.ToString(reader["gydscrp"]);
  358. dw_2.Add(newDw2);
  359. }
  360. }
  361. }
  362. }
  363. private void wf_get_str(string arg_source, ref string arg_left_str, ref string arg_right_str)
  364. {
  365. if (string.IsNullOrEmpty(arg_source)) return;
  366. int commaPosition = arg_source.IndexOf(',');
  367. if (commaPosition > 0)
  368. {
  369. arg_left_str = arg_source.Substring(0, commaPosition).Trim();
  370. arg_right_str = arg_source.Substring(commaPosition + 1).Trim();
  371. }
  372. else
  373. {
  374. arg_left_str = arg_source.Trim();
  375. arg_right_str = "";
  376. }
  377. }
  378. private string wf_set_area_text(string arg_str)
  379. {
  380. string ls_rtn = "";
  381. // V侧1
  382. // V侧2
  383. // V侧3
  384. // 小侧1
  385. // 小侧2
  386. // 小侧3
  387. // 大侧
  388. if (arg_str.IndexOf("大侧") >= 0)
  389. {
  390. ls_rtn = "大侧";
  391. }
  392. else if (arg_str.IndexOf("小侧1") >= 0)
  393. {
  394. ls_rtn = "小侧1";
  395. }
  396. else if (arg_str.IndexOf("小侧2") >= 0)
  397. {
  398. ls_rtn = "小侧2";
  399. }
  400. else if (arg_str.IndexOf("小侧3") >= 0)
  401. {
  402. ls_rtn = "小侧3";
  403. }
  404. else if (arg_str.IndexOf("V侧1") >= 0)
  405. {
  406. ls_rtn = "V侧1";
  407. }
  408. else if (arg_str.IndexOf("V侧2") >= 0)
  409. {
  410. ls_rtn = "V侧2";
  411. }
  412. else if (arg_str.IndexOf("V侧3") >= 0)
  413. {
  414. ls_rtn = "V侧3";
  415. }
  416. else
  417. {
  418. ls_rtn = "";
  419. }
  420. return ls_rtn;
  421. }
  422. private List<replacement> wf_add_dianceng_area_bytype(SqlCommand cmd, string dianceng_area)
  423. {
  424. string ls_dianceng_area = dianceng_area;
  425. var diancengarea = new List<replacement>();
  426. // 替换中文逗号和其他特殊字符
  427. ls_dianceng_area = ls_dianceng_area.Replace(',', ',');
  428. ls_dianceng_area = ls_dianceng_area.Replace("\r\n", "");
  429. ls_dianceng_area = ls_dianceng_area.Replace("\r", "");
  430. ls_dianceng_area = ls_dianceng_area.Replace("\n", "");
  431. // 分割字符串
  432. //string[] ls_pzsplitstr_arr = f_pb_split(ls_dianceng_area, "/");
  433. var ls_pzsplitstr_arr = ls_dianceng_area.Split('/');
  434. for (int ll_i = 0; ll_i < ls_pzsplitstr_arr.Length; ll_i++)
  435. {
  436. string trimmedStr = ls_pzsplitstr_arr[ll_i].Trim();
  437. if (string.IsNullOrEmpty(trimmedStr)) continue;
  438. var child = new replacement()
  439. {
  440. label = wf_set_area_text(trimmedStr.Trim()),
  441. value = wf_set_area_text(trimmedStr.Trim())
  442. };
  443. diancengarea.Add(child);
  444. }
  445. return diancengarea;
  446. }
  447. }
  448. }