GetMattressImportDW2Excutor.cs 19 KB

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