GetMattressImportDW2Excutor.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  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. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  28. using (var cmd = con.CreateCommand())
  29. {
  30. con.Open();
  31. // 初始化属性
  32. //foreach (var mx in request.mattressMx)
  33. //{
  34. // AutoInit.AutoInitS(cmd, mx);
  35. //}
  36. using (cmd.Transaction = con.BeginTransaction())
  37. {
  38. if (request.mattresstypeid == 0)
  39. {
  40. if (request.mattressid == 0)
  41. {
  42. rslt.ErrMsg = "床垫类别不能为0";
  43. return;
  44. }
  45. else
  46. {
  47. // 床垫报价修改时,获取相关数据
  48. var matterss = new u_mattress() { mattressid = request.mattressid };
  49. DbSqlHelper.SelectOne(cmd, matterss, "mattresstypeid");
  50. var mattersstype = new u_mattress_type() { mattresstypeid = matterss.mattresstypeid };
  51. 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");
  52. rslt.diancengarea = new List<replacement>();
  53. if (!string.IsNullOrEmpty(mattersstype.dianceng_area))
  54. {
  55. rslt.diancengarea = wf_add_dianceng_area_bytype(cmd, mattersstype.dianceng_area);
  56. }
  57. var selectStr = @"
  58. SELECT
  59. extraid
  60. ,extratypename
  61. ,extraname
  62. ,typeid
  63. ,price
  64. ,dscrp
  65. ,inuse
  66. ,inputtype
  67. ,ifinit
  68. From u_mattress_extra";
  69. var outFields = "extraid,extratypename,extraname,typeid,price,dscrp,inuse,inputtype,ifinit";
  70. var whereList = new List<string>();
  71. whereList.Add("u_mattress_extra.inuse = 0");
  72. var param = new Dictionary<string, object>();
  73. var mattressExtra = new List<u_mattress_extra>();
  74. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "typeid, extraid", outFields, 0, 0, mattressExtra);
  75. rslt.extraEnum = mattressExtra;
  76. }
  77. }
  78. else
  79. {
  80. var mattersstype = new u_mattress_type() { mattresstypeid = request.mattresstypeid };
  81. 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");
  82. rslt.biandai_qty = mattersstype.biandaiqty;
  83. AutoInit.AutoInitS(cmd, mattersstype);
  84. var helper = HelperBase.GetHelper<MattressHelper>(cmd, new HelperBase.Context() { tokendata = tokendata });
  85. var selectStr = @"
  86. SELECT formulaid
  87. ,formulakind
  88. ,formulatype
  89. ,sortcode
  90. ,if_mtrl
  91. ,formula
  92. ,usetype
  93. ,if_packtype0
  94. ,if_packtype1
  95. ,if_packtype2
  96. ,default_mtrlid
  97. ,createtime
  98. ,createby
  99. ,useformula
  100. ,gydscrp
  101. ,mtrltype
  102. FROM u_mattress_formula";
  103. var outFields = "formulaid, formulakind, formulatype, sortcode, if_mtrl, formula, usetype, if_packtype0, if_packtype1, if_packtype2, default_mtrlid, createtime, createby, useformula, gydscrp, mtrltype";
  104. var whereList = new List<string>();
  105. whereList.Add("u_mattress_formula.formulatype IN (0, 1, 2, 3, 99, 104)");
  106. whereList.Add("u_mattress_formula.usetype = @usetype");
  107. var param = new Dictionary<string, object>();
  108. // 导入 0-通用类型 的公式
  109. param.Add("@usetype", 0);
  110. var mattressFormulaList0 = new List<u_mattress_formula>();
  111. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "formulatype, sortcode", outFields, 0, 0, mattressFormulaList0);
  112. var dw_2 = new List<u_mattress_mx_mtrl>();
  113. foreach (var mx in mattressFormulaList0)
  114. {
  115. if (new[] { 11, 12, 32, 33, 13, 14, 29, 999, 1201 }.Contains(mx.formulakind.Value)) continue;
  116. var newDw2 = new u_mattress_mx_mtrl();
  117. AutoInit.AutoInitS(newDw2);
  118. if (mx.if_mtrl > 1)
  119. {
  120. newDw2.addmx = "+";
  121. newDw2.delmx = "-";
  122. }
  123. newDw2.formulatype = mx.formulatype;
  124. newDw2.if_mtrl = mx.if_mtrl;
  125. newDw2.formulaid = mx.formulaid;
  126. newDw2.sortcode = mx.sortcode;
  127. newDw2.formulakind = mx.formulakind;
  128. newDw2.formula = mx.formula;
  129. newDw2.useformula = mx.useformula;
  130. newDw2.gydscrp = mx.gydscrp;
  131. dw_2.Add(newDw2);
  132. }
  133. // 导入 1-按床垫类别 的公式
  134. var mattressFormulaList1 = new List<u_mattress_formula>();
  135. param.Clear();
  136. param.Add("@usetype", 1);
  137. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "formulatype, sortcode", outFields, 0, 0, mattressFormulaList1);
  138. foreach (var mx in mattressFormulaList1)
  139. {
  140. var ls_chastr = "";
  141. if (request.ifbcptype == 1)
  142. {
  143. 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))
  144. {
  145. continue;
  146. }
  147. }
  148. if (new[] { 0, 40, 50, 60, 70, 80 }.Contains(mx.formulakind.Value))
  149. {
  150. ls_chastr = "面裥绵";
  151. if (mattersstype.if_top_side == 0) continue;
  152. }
  153. if (new[] { 1, 41, 51, 61, 71, 81 }.Contains(mx.formulakind.Value))
  154. {
  155. ls_chastr = "底裥绵";
  156. if (mattersstype.if_button_sdie == 0) continue;
  157. }
  158. if (new[] { 2, 42, 52, 62, 72, 82 }.Contains(mx.formulakind.Value))
  159. {
  160. ls_chastr = "普通大侧";
  161. if (mattersstype.if_big_side == 0) continue;
  162. }
  163. if (new[] { 3, 43, 53, 63, 73, 83 }.Contains(mx.formulakind.Value))
  164. {
  165. ls_chastr = "小侧1";
  166. if (mattersstype.if_small_side == 0) continue;
  167. }
  168. if (new[] { 4, 44, 54, 64, 74, 84 }.Contains(mx.formulakind.Value))
  169. {
  170. ls_chastr = "V侧1";
  171. if (mattersstype.if_v_side == 0) continue;
  172. }
  173. if (new[] { 101, 102, 103, 104, 105, 106 }.Contains(mx.formulakind.Value))
  174. {
  175. if (mattersstype.if_in_cloth_cover == 0) continue;
  176. }
  177. if (new[] { 111, 112, 113, 114, 115, 116 }.Contains(mx.formulakind.Value))
  178. {
  179. if (mattersstype.if_out_cloth_cover == 0) continue;
  180. }
  181. var newDw2 = new u_mattress_mx_mtrl();
  182. AutoInit.AutoInitS(newDw2);
  183. if (mx.if_mtrl > 1)
  184. {
  185. newDw2.addmx = "+";
  186. newDw2.delmx = "-";
  187. }
  188. newDw2.formulatype = mx.formulatype;
  189. newDw2.if_mtrl = mx.if_mtrl;
  190. newDw2.formulaid = mx.formulaid;
  191. newDw2.sortcode = mx.sortcode;
  192. newDw2.formulakind = mx.formulakind;
  193. newDw2.formula = mx.formula;
  194. newDw2.chastr = ls_chastr;
  195. newDw2.useformula = mx.useformula;
  196. newDw2.gydscrp = mx.gydscrp;
  197. dw_2.Add(newDw2);
  198. }
  199. // 导入 2-按包装方式 的公式
  200. helper.wf_import_bz(request.packtype, ref dw_2);
  201. //加多一个 小侧2
  202. if (mattersstype.if_small_side2 == 1 && request.ifbcptype == 0)
  203. {
  204. wf_add_side(cmd, new[] { 3, 83, 43, 53, 63, 73 }, "小侧2", ref dw_2);
  205. }
  206. //加多一个 小侧3
  207. if (mattersstype.if_small_side3 == 1 && request.ifbcptype == 0)
  208. {
  209. wf_add_side(cmd, new[] { 3, 83, 43, 53, 63, 73 }, "小侧3", ref dw_2);
  210. }
  211. //加多一个 V侧2
  212. if (mattersstype.if_v_side2 == 1 && request.ifbcptype == 0)
  213. {
  214. wf_add_side(cmd, new[] { 4, 84, 44, 54, 64, 74 }, "V侧2", ref dw_2);
  215. }
  216. //加多一个 V侧3
  217. if (mattersstype.if_v_side3 == 1 && request.ifbcptype == 0)
  218. {
  219. wf_add_side(cmd, new[] { 4, 84, 44, 54, 64, 74 }, "V侧3", ref dw_2);
  220. }
  221. // 在 床垫类型 定义里面 按垫层默认配置 自动带出 垫层配置 和 垫层可选项
  222. if (!string.IsNullOrEmpty(mattersstype.dianceng_sort))
  223. {
  224. wf_add_dianceng_bytype(cmd, mattersstype.dianceng_sort, ref dw_2);
  225. }
  226. rslt.diancengarea = new List<replacement>();
  227. if (!string.IsNullOrEmpty(mattersstype.dianceng_area))
  228. {
  229. rslt.diancengarea = wf_add_dianceng_area_bytype(cmd, mattersstype.dianceng_area);
  230. }
  231. // 明细排序
  232. helper.wf_sort_mx(ref dw_2);
  233. if (request.mattressid == 0)
  234. {
  235. helper.wf_default_mtrlid(request.pricelistid, ref dw_2);
  236. helper.wf_default_mtrlid_notbz(request.pricelistid, ref dw_2);
  237. }
  238. rslt.mattressMx = dw_2;
  239. #region 导入其他额外费用和特殊工艺
  240. selectStr = @"
  241. SELECT
  242. extraid
  243. ,extratypename
  244. ,extraname
  245. ,typeid
  246. ,price
  247. ,dscrp
  248. ,inuse
  249. ,inputtype
  250. ,ifinit
  251. From u_mattress_extra";
  252. outFields = "extraid,extratypename,extraname,typeid,price,dscrp,inuse,inputtype,ifinit";
  253. whereList = new List<string>();
  254. whereList.Add("u_mattress_extra.inuse = 0");
  255. param = new Dictionary<string, object>();
  256. var mattressExtra = new List<u_mattress_extra>();
  257. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "typeid, extraid", outFields, 0, 0, mattressExtra);
  258. rslt.extraEnum = mattressExtra;
  259. rslt.extraProcessesMx = new List<u_mattress_mx_extra>();
  260. var processesMx = mattressExtra.Where(item => item.ifinit == 1 && item.typeid == 1).ToArray();
  261. var costsMx = mattressExtra.Where(item => item.ifinit == 1 && item.typeid == 2).ToArray();
  262. foreach (var mx in processesMx)
  263. {
  264. u_mattress_mx_extra mxItem = new u_mattress_mx_extra
  265. {
  266. mattressid = 0,
  267. mattressmxid = 0,
  268. extraid = mx.extraid,
  269. extraname = mx.extraname,
  270. dscrp = mx.dscrp,
  271. price = mx.price,
  272. typeid = mx.typeid
  273. };
  274. rslt.extraProcessesMx.Add(mxItem);
  275. }
  276. foreach (var mx in costsMx)
  277. {
  278. u_mattress_mx_extra mxItem = new u_mattress_mx_extra
  279. {
  280. mattressid = 0,
  281. mattressmxid = 0,
  282. extraid = mx.extraid,
  283. extraname = mx.extraname,
  284. dscrp = mx.dscrp,
  285. price = mx.price,
  286. typeid = mx.typeid
  287. };
  288. rslt.extraCostsMx.Add(mxItem);
  289. }
  290. #endregion
  291. }
  292. }
  293. }
  294. }
  295. private void wf_add_side(SqlCommand cmd, int[] formulakindList, string arg_name, ref List<u_mattress_mx_mtrl> dw_2)
  296. {
  297. foreach(int ll_formulakind in formulakindList)
  298. {
  299. cmd.CommandText = @"SELECT TOP 1
  300. formulatype,
  301. formulaid,
  302. sortcode,
  303. formula,
  304. if_mtrl,
  305. useformula,
  306. gydscrp
  307. FROM u_mattress_formula
  308. WHERE formulakind = @formulakind
  309. AND u_mattress_formula.formulatype in (0,1,2,3)";
  310. cmd.Parameters.Clear();
  311. cmd.Parameters.AddWithValue("@formulakind", ll_formulakind);
  312. using (var reader = cmd.ExecuteReader())
  313. {
  314. if (reader.Read())
  315. {
  316. var newDw2 = new u_mattress_mx_mtrl();
  317. AutoInit.AutoInitS(newDw2);
  318. if (Convert.ToInt32(reader["if_mtrl"]) > 1)
  319. {
  320. newDw2.addmx = "+";
  321. newDw2.delmx = "-";
  322. }
  323. newDw2.formulatype = Convert.ToInt32(reader["formulatype"]);
  324. newDw2.if_mtrl = Convert.ToInt32(reader["if_mtrl"]);
  325. newDw2.formulaid = Convert.ToInt32(reader["formulaid"]);
  326. newDw2.sortcode = arg_name;
  327. newDw2.formulakind = ll_formulakind;
  328. newDw2.formula = Convert.ToString(reader["formula"]);
  329. newDw2.chastr = arg_name;
  330. newDw2.useformula = Convert.ToString(reader["useformula"]);
  331. newDw2.gydscrp = Convert.ToString(reader["gydscrp"]);
  332. dw_2.Add(newDw2);
  333. }
  334. }
  335. }
  336. }
  337. private void wf_add_dianceng_bytype(SqlCommand cmd, string dianceng_sort, ref List<u_mattress_mx_mtrl> dw_2)
  338. {
  339. var arg_dianceng_sort = dianceng_sort.Replace(",", " , ");
  340. arg_dianceng_sort = arg_dianceng_sort.Replace("~r~n", "");
  341. arg_dianceng_sort = arg_dianceng_sort.Replace("~r", "");
  342. arg_dianceng_sort = arg_dianceng_sort.Replace("~n", "");
  343. //var ls_pzsplitstr_arr = f_pb_split(arg_dianceng_sort, "/");
  344. var ls_pzsplitstr_arr = arg_dianceng_sort.Split('/');
  345. string arg_left_str, arg_right_str;
  346. int ll_formulakind;
  347. int index = 0;
  348. foreach (var ls_pzsplitstr in ls_pzsplitstr_arr)
  349. {
  350. index++;
  351. arg_left_str = "";
  352. arg_right_str = "";
  353. wf_get_str(ls_pzsplitstr, ref arg_left_str, ref arg_right_str);
  354. switch(arg_left_str)
  355. {
  356. case "垫层":
  357. ll_formulakind = 32;
  358. break;
  359. case "床网":
  360. ll_formulakind = 999;
  361. break;
  362. case "顶布":
  363. ll_formulakind = 12;
  364. break;
  365. case "毡类":
  366. ll_formulakind = 13;
  367. break;
  368. case "打底无纺布":
  369. ll_formulakind = 14;
  370. break;
  371. case "网面布料":
  372. ll_formulakind = 29;
  373. break;
  374. default:
  375. ll_formulakind = -1;
  376. break;
  377. }
  378. if (ll_formulakind == -1) continue;
  379. cmd.CommandText = @"SELECT TOP 1
  380. formulatype,
  381. formulaid,
  382. sortcode,
  383. formula,
  384. if_mtrl,
  385. useformula,
  386. gydscrp
  387. FROM u_mattress_formula
  388. WHERE formulakind = @formulakind
  389. AND u_mattress_formula.formulatype in (0,1,2,3)";
  390. cmd.Parameters.Clear();
  391. cmd.Parameters.AddWithValue("@formulakind", ll_formulakind);
  392. using (var reader = cmd.ExecuteReader())
  393. {
  394. if (reader.Read())
  395. {
  396. var newDw2 = new u_mattress_mx_mtrl();
  397. AutoInit.AutoInitS(newDw2);
  398. if (Convert.ToInt32(reader["if_mtrl"]) > 1)
  399. {
  400. newDw2.addmx = "+";
  401. newDw2.delmx = "-";
  402. }
  403. newDw2.formulatype = Convert.ToInt32(reader["formulatype"]);
  404. newDw2.if_mtrl = 2;
  405. newDw2.formulaid = Convert.ToInt32(reader["formulaid"]);
  406. newDw2.sortcode = Convert.ToString(reader["sortcode"]);
  407. newDw2.formulakind = ll_formulakind;
  408. newDw2.formula = Convert.ToString(reader["formula"]);
  409. newDw2.chastr = wf_set_area_text(arg_right_str);
  410. newDw2.qty = 1;
  411. newDw2.xu = index;
  412. newDw2.useformula = Convert.ToString(reader["useformula"]);
  413. newDw2.gydscrp = Convert.ToString(reader["gydscrp"]);
  414. dw_2.Add(newDw2);
  415. }
  416. }
  417. }
  418. }
  419. private void wf_get_str(string arg_source, ref string arg_left_str, ref string arg_right_str)
  420. {
  421. if (string.IsNullOrEmpty(arg_source)) return;
  422. int commaPosition = arg_source.IndexOf(',');
  423. if (commaPosition > 0)
  424. {
  425. arg_left_str = arg_source.Substring(0, commaPosition).Trim();
  426. arg_right_str = arg_source.Substring(commaPosition + 1).Trim();
  427. }
  428. else
  429. {
  430. arg_left_str = arg_source.Trim();
  431. arg_right_str = "";
  432. }
  433. }
  434. private string wf_set_area_text(string arg_str)
  435. {
  436. string ls_rtn = "";
  437. // V侧1
  438. // V侧2
  439. // V侧3
  440. // 小侧1
  441. // 小侧2
  442. // 小侧3
  443. // 大侧
  444. if (arg_str.IndexOf("大侧") >= 0)
  445. {
  446. ls_rtn = "大侧";
  447. }
  448. else if (arg_str.IndexOf("小侧1") >= 0)
  449. {
  450. ls_rtn = "小侧1";
  451. }
  452. else if (arg_str.IndexOf("小侧2") >= 0)
  453. {
  454. ls_rtn = "小侧2";
  455. }
  456. else if (arg_str.IndexOf("小侧3") >= 0)
  457. {
  458. ls_rtn = "小侧3";
  459. }
  460. else if (arg_str.IndexOf("V侧1") >= 0)
  461. {
  462. ls_rtn = "V侧1";
  463. }
  464. else if (arg_str.IndexOf("V侧2") >= 0)
  465. {
  466. ls_rtn = "V侧2";
  467. }
  468. else if (arg_str.IndexOf("V侧3") >= 0)
  469. {
  470. ls_rtn = "V侧3";
  471. }
  472. else
  473. {
  474. ls_rtn = "";
  475. }
  476. return ls_rtn;
  477. }
  478. private List<replacement> wf_add_dianceng_area_bytype(SqlCommand cmd, string dianceng_area)
  479. {
  480. string ls_dianceng_area = dianceng_area;
  481. var diancengarea = new List<replacement>();
  482. // 替换中文逗号和其他特殊字符
  483. ls_dianceng_area = ls_dianceng_area.Replace(',', ',');
  484. ls_dianceng_area = ls_dianceng_area.Replace("\r\n", "");
  485. ls_dianceng_area = ls_dianceng_area.Replace("\r", "");
  486. ls_dianceng_area = ls_dianceng_area.Replace("\n", "");
  487. // 分割字符串
  488. string[] ls_pzsplitstr_arr = ls_dianceng_area.Split(',');
  489. for (int ll_i = 0; ll_i < ls_pzsplitstr_arr.Length; ll_i++)
  490. {
  491. string trimmedStr = ls_pzsplitstr_arr[ll_i].Trim();
  492. if (string.IsNullOrEmpty(trimmedStr)) continue;
  493. var child = new replacement()
  494. {
  495. label = wf_set_area_text(trimmedStr.Trim()),
  496. value = wf_set_area_text(trimmedStr.Trim())
  497. };
  498. diancengarea.Add(child);
  499. }
  500. return diancengarea;
  501. }
  502. }
  503. }