GetMattressImportDW2Excutor.cs 21 KB

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