GetMattressImportDW2Excutor.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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. #region 导入其他额外费用和特殊工艺
  220. selectStr = @"
  221. SELECT
  222. extraid
  223. ,extratypename
  224. ,extraname
  225. ,typeid
  226. ,price
  227. ,dscrp
  228. ,inuse
  229. ,inputtype
  230. ,ifinit
  231. From u_mattress_extra";
  232. outFields = "extraid,extratypename,extraname,typeid,price,dscrp,inuse,inputtype,ifinit";
  233. whereList = new List<string>();
  234. whereList.Add("u_mattress_extra.ifinit = 1");
  235. param = new Dictionary<string, object>();
  236. // 导入 0-通用类型 的公式
  237. var mattressExtra = new List<u_mattress_extra>();
  238. DbSqlHelper.SelectJoin(cmd, selectStr, ListEx.GetWhereStr(whereList), param, "typeid, extraid", outFields, 0, 0, mattressExtra);
  239. rslt.extraMx = new List<u_mattress_mx_extra>();
  240. foreach (var mx in mattressExtra)
  241. {
  242. u_mattress_mx_extra mxItem = new u_mattress_mx_extra
  243. {
  244. mattressid = 0,
  245. mattressmxid = 0,
  246. extraid = mx.extraid,
  247. extraname = mx.extraname,
  248. dscrp = mx.dscrp,
  249. price = mx.price
  250. };
  251. rslt.extraMx.Add(mxItem);
  252. }
  253. #endregion
  254. }
  255. }
  256. }
  257. }
  258. private void wf_add_side(SqlCommand cmd, int[] formulakindList, string arg_name, ref List<u_mattress_mx_mtrl> dw_2)
  259. {
  260. foreach(int ll_formulakind in formulakindList)
  261. {
  262. cmd.CommandText = @"SELECT TOP 1
  263. formulatype,
  264. formulaid,
  265. sortcode,
  266. formula,
  267. if_mtrl,
  268. useformula,
  269. gydscrp
  270. FROM u_mattress_formula
  271. WHERE formulakind = @formulakind
  272. AND u_mattress_formula.formulatype in (0,1,2,3)";
  273. cmd.Parameters.Clear();
  274. cmd.Parameters.AddWithValue("@formulakind", ll_formulakind);
  275. using (var reader = cmd.ExecuteReader())
  276. {
  277. if (reader.Read())
  278. {
  279. var newDw2 = new u_mattress_mx_mtrl();
  280. AutoInit.AutoInitS(newDw2);
  281. if (Convert.ToInt32(reader["if_mtrl"]) > 1)
  282. {
  283. newDw2.addmx = "+";
  284. newDw2.delmx = "-";
  285. }
  286. newDw2.formulatype = Convert.ToInt32(reader["formulatype"]);
  287. newDw2.if_mtrl = Convert.ToInt32(reader["if_mtrl"]);
  288. newDw2.formulaid = Convert.ToInt32(reader["formulaid"]);
  289. newDw2.sortcode = arg_name;
  290. newDw2.formulakind = ll_formulakind;
  291. newDw2.formula = Convert.ToString(reader["formula"]);
  292. newDw2.chastr = arg_name;
  293. newDw2.useformula = Convert.ToString(reader["useformula"]);
  294. newDw2.gydscrp = Convert.ToString(reader["gydscrp"]);
  295. dw_2.Add(newDw2);
  296. }
  297. }
  298. }
  299. }
  300. private void wf_add_dianceng_bytype(SqlCommand cmd, string dianceng_sort, ref List<u_mattress_mx_mtrl> dw_2)
  301. {
  302. var arg_dianceng_sort = dianceng_sort.Replace(",", " , ");
  303. arg_dianceng_sort = arg_dianceng_sort.Replace("~r~n", "");
  304. arg_dianceng_sort = arg_dianceng_sort.Replace("~r", "");
  305. arg_dianceng_sort = arg_dianceng_sort.Replace("~n", "");
  306. //var ls_pzsplitstr_arr = f_pb_split(arg_dianceng_sort, "/");
  307. var ls_pzsplitstr_arr = arg_dianceng_sort.Split('/');
  308. string arg_left_str, arg_right_str;
  309. int ll_formulakind;
  310. int index = 0;
  311. foreach (var ls_pzsplitstr in ls_pzsplitstr_arr)
  312. {
  313. index++;
  314. arg_left_str = "";
  315. arg_right_str = "";
  316. wf_get_str(ls_pzsplitstr, ref arg_left_str, ref arg_right_str);
  317. switch(arg_left_str)
  318. {
  319. case "垫层":
  320. ll_formulakind = 32;
  321. break;
  322. case "床网":
  323. ll_formulakind = 999;
  324. break;
  325. case "顶布":
  326. ll_formulakind = 12;
  327. break;
  328. case "毡类":
  329. ll_formulakind = 13;
  330. break;
  331. case "打底无纺布":
  332. ll_formulakind = 14;
  333. break;
  334. case "网面布料":
  335. ll_formulakind = 29;
  336. break;
  337. default:
  338. ll_formulakind = -1;
  339. break;
  340. }
  341. if (ll_formulakind == -1) continue;
  342. cmd.CommandText = @"SELECT TOP 1
  343. formulatype,
  344. formulaid,
  345. sortcode,
  346. formula,
  347. if_mtrl,
  348. useformula,
  349. gydscrp
  350. FROM u_mattress_formula
  351. WHERE formulakind = @formulakind
  352. AND u_mattress_formula.formulatype in (0,1,2,3)";
  353. cmd.Parameters.Clear();
  354. cmd.Parameters.AddWithValue("@formulakind", ll_formulakind);
  355. using (var reader = cmd.ExecuteReader())
  356. {
  357. if (reader.Read())
  358. {
  359. var newDw2 = new u_mattress_mx_mtrl();
  360. AutoInit.AutoInitS(newDw2);
  361. if (Convert.ToInt32(reader["if_mtrl"]) > 1)
  362. {
  363. newDw2.addmx = "+";
  364. newDw2.delmx = "-";
  365. }
  366. newDw2.formulatype = Convert.ToInt32(reader["formulatype"]);
  367. newDw2.if_mtrl = 2;
  368. newDw2.formulaid = Convert.ToInt32(reader["formulaid"]);
  369. newDw2.sortcode = Convert.ToString(reader["sortcode"]);
  370. newDw2.formulakind = ll_formulakind;
  371. newDw2.formula = Convert.ToString(reader["formula"]);
  372. newDw2.chastr = wf_set_area_text(arg_right_str);
  373. newDw2.qty = 1;
  374. newDw2.xu = index;
  375. newDw2.useformula = Convert.ToString(reader["useformula"]);
  376. newDw2.gydscrp = Convert.ToString(reader["gydscrp"]);
  377. dw_2.Add(newDw2);
  378. }
  379. }
  380. }
  381. }
  382. private void wf_get_str(string arg_source, ref string arg_left_str, ref string arg_right_str)
  383. {
  384. if (string.IsNullOrEmpty(arg_source)) return;
  385. int commaPosition = arg_source.IndexOf(',');
  386. if (commaPosition > 0)
  387. {
  388. arg_left_str = arg_source.Substring(0, commaPosition).Trim();
  389. arg_right_str = arg_source.Substring(commaPosition + 1).Trim();
  390. }
  391. else
  392. {
  393. arg_left_str = arg_source.Trim();
  394. arg_right_str = "";
  395. }
  396. }
  397. private string wf_set_area_text(string arg_str)
  398. {
  399. string ls_rtn = "";
  400. // V侧1
  401. // V侧2
  402. // V侧3
  403. // 小侧1
  404. // 小侧2
  405. // 小侧3
  406. // 大侧
  407. if (arg_str.IndexOf("大侧") >= 0)
  408. {
  409. ls_rtn = "大侧";
  410. }
  411. else if (arg_str.IndexOf("小侧1") >= 0)
  412. {
  413. ls_rtn = "小侧1";
  414. }
  415. else if (arg_str.IndexOf("小侧2") >= 0)
  416. {
  417. ls_rtn = "小侧2";
  418. }
  419. else if (arg_str.IndexOf("小侧3") >= 0)
  420. {
  421. ls_rtn = "小侧3";
  422. }
  423. else if (arg_str.IndexOf("V侧1") >= 0)
  424. {
  425. ls_rtn = "V侧1";
  426. }
  427. else if (arg_str.IndexOf("V侧2") >= 0)
  428. {
  429. ls_rtn = "V侧2";
  430. }
  431. else if (arg_str.IndexOf("V侧3") >= 0)
  432. {
  433. ls_rtn = "V侧3";
  434. }
  435. else
  436. {
  437. ls_rtn = "";
  438. }
  439. return ls_rtn;
  440. }
  441. private List<replacement> wf_add_dianceng_area_bytype(SqlCommand cmd, string dianceng_area)
  442. {
  443. string ls_dianceng_area = dianceng_area;
  444. var diancengarea = new List<replacement>();
  445. // 替换中文逗号和其他特殊字符
  446. ls_dianceng_area = ls_dianceng_area.Replace(',', ',');
  447. ls_dianceng_area = ls_dianceng_area.Replace("\r\n", "");
  448. ls_dianceng_area = ls_dianceng_area.Replace("\r", "");
  449. ls_dianceng_area = ls_dianceng_area.Replace("\n", "");
  450. // 分割字符串
  451. string[] ls_pzsplitstr_arr = ls_dianceng_area.Split(',');
  452. for (int ll_i = 0; ll_i < ls_pzsplitstr_arr.Length; ll_i++)
  453. {
  454. string trimmedStr = ls_pzsplitstr_arr[ll_i].Trim();
  455. if (string.IsNullOrEmpty(trimmedStr)) continue;
  456. var child = new replacement()
  457. {
  458. label = wf_set_area_text(trimmedStr.Trim()),
  459. value = wf_set_area_text(trimmedStr.Trim())
  460. };
  461. diancengarea.Add(child);
  462. }
  463. return diancengarea;
  464. }
  465. }
  466. }